void in_update_amplitude(TTPtr self) { WrappedModularInstancePtr x = (WrappedModularInstancePtr)self; TTInputPtr anInput = (TTInputPtr)x->wrappedObject; TTValue storedObject; TTObjectBasePtr anObject; TTErr err; if (anInput) { if (x->internals) { if (!x->internals->isEmpty()) { // get internal data object used to return amplitude err = x->internals->lookup(TTSymbol("amplitude"), storedObject); if (!err) { anObject = storedObject[0]; // set current meter value anObject->setAttributeValue(kTTSym_value, EXTRA->meter); } } } // restart the clock if (EXTRA->pollInterval) clock_delay(EXTRA->clock, EXTRA->pollInterval); } }
TTObjectBasePtr OSCSenderManager::add(TTSymbol applicationName, TTSymbol ip, TTUInt16 port) { TTValue v; TTObjectBasePtr anObject = NULL; TTErr err; err = TTObjectBaseInstantiate(TTSymbol("osc.send"), &anObject, kTTValNONE); if (!err) { anObject->setAttributeValue(TTSymbol("address"), ip); anObject->setAttributeValue(TTSymbol("port"), port); v.append(anObject); v.append(ip); v.append(port); mSenders->append(applicationName, v); } return anObject; }
TTErr TTAttribute::extendedSetter(const TTAttribute& attribute, TTValue& value) { TTObjectBasePtr anExtendedObject = (TTObjectBasePtr)attribute.setterObject; return anExtendedObject->setAttributeValue(attribute.name, value); }
TTErr ColorDataspace::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // Create dataspace object and set to angle TTObjectBasePtr myDataspace = NULL; TTErr err; err = TTObjectBaseInstantiate(TT("dataspace"), (TTObjectBasePtr*)&myDataspace, kTTValNONE); myDataspace->setAttributeValue(TT("dataspace"), TT("color")); TTValue v; TTValue expected; /************************************************/ /* */ /* Test conversions to neutral unit */ /* */ /************************************************/ // rgb => rgb myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb")); v.setSize(3); v.set(0, TTFloat64(124.2)); v.set(1, TTFloat64(162.9)); v.set(2, TTFloat64(13.163)); expected.setSize(3); expected.set(0, TTFloat64(124.2)); expected.set(1, TTFloat64(162.9)); expected.set(2, TTFloat64(13.163)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb to rgb", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // cmy => rgb myDataspace->setAttributeValue(TT("inputUnit"), TT("cmy")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb")); v.setSize(3); v.set(0, TTFloat64(255.)); v.set(1, TTFloat64(127.5)); v.set(2, TTFloat64(0.)); expected.setSize(3); expected.set(0, TTFloat64(0.)); expected.set(1, TTFloat64(0.5)); expected.set(2, TTFloat64(1.0)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("cmy to rgb", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // hsl => rgb myDataspace->setAttributeValue(TT("inputUnit"), TT("hsl")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb")); v.setSize(3); v.set(0, TTFloat64(120.)); v.set(1, TTFloat64(100.)); v.set(2, TTFloat64(50.)); expected.setSize(3); expected.set(0, TTFloat64(0.)); expected.set(1, TTFloat64(1.0)); expected.set(2, TTFloat64(0.)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("hsl to rgb", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // rgb8 => rgb myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb8")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb")); v.setSize(3); v.set(0, TTFloat64(255.)); v.set(1, TTFloat64(127.5)); v.set(2, TTFloat64(0.)); expected.setSize(3); expected.set(0, TTFloat64(1.)); expected.set(1, TTFloat64(0.5)); expected.set(2, TTFloat64(0.0)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb8 to rgb", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // hsv => rgb myDataspace->setAttributeValue(TT("inputUnit"), TT("hsv")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb")); v.setSize(3); v.set(0, TTFloat64(120.)); v.set(1, TTFloat64(100.)); v.set(2, TTFloat64(100.)); expected.setSize(3); expected.set(0, TTFloat64(0.)); expected.set(1, TTFloat64(1.0)); expected.set(2, TTFloat64(0.)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("hsv to rgb", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); /************************************************/ /* */ /* Test conversions from neutral unit */ /* */ /************************************************/ // rgb => cmy myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb")); myDataspace->setAttributeValue(TT("outputUnit"), TT("cmy")); v.setSize(3); v.set(0, TTFloat64(0.)); v.set(1, TTFloat64(0.5)); v.set(2, TTFloat64(1.)); expected.setSize(3); expected.set(0, TTFloat64(255.)); expected.set(1, TTFloat64(127.5)); expected.set(2, TTFloat64(0.0)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb to cmy", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // rgb => hsl myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb")); myDataspace->setAttributeValue(TT("outputUnit"), TT("hsl")); v.setSize(3); v.set(0, TTFloat64(0.)); v.set(1, TTFloat64(1.)); v.set(2, TTFloat64(0.)); expected.setSize(3); expected.set(0, TTFloat64(120.)); expected.set(1, TTFloat64(100.0)); expected.set(2, TTFloat64(50.)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb to hsl", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // rgb => rgb8 myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb")); myDataspace->setAttributeValue(TT("outputUnit"), TT("rgb8")); v.setSize(3); v.set(0, TTFloat64(1.)); v.set(1, TTFloat64(0.5)); v.set(2, TTFloat64(0.)); expected.setSize(3); expected.set(0, TTFloat64(255.)); expected.set(1, TTFloat64(127.5)); expected.set(2, TTFloat64(0.0)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb to rgb8", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); // rgb => hsv myDataspace->setAttributeValue(TT("inputUnit"), TT("rgb")); myDataspace->setAttributeValue(TT("outputUnit"), TT("hsv")); v.setSize(3); v.set(0, TTFloat64(0.)); v.set(1, TTFloat64(1.)); v.set(2, TTFloat64(0.)); expected.setSize(3); expected.set(0, TTFloat64(120.)); expected.set(1, TTFloat64(100.0)); expected.set(2, TTFloat64(100.)); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("rgb to hsv", TTTestFloat64ArrayEquivalence(v, expected), testAssertionCount, errorCount); return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TimeDataspace::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // Create dataspace object and set to time TTObjectBasePtr myDataspace = NULL; TTErr err; err = TTObjectBaseInstantiate(TT("dataspace"), (TTObjectBasePtr*)&myDataspace, kTTValNONE); myDataspace->setAttributeValue(TT("dataspace"), TT("time")); TTValue v; TTValue expected; /************************************************/ /* */ /* Test conversions to neutral unit */ /* */ /************************************************/ // Second to second myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(256.); expected = TTValue(256.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Millisecond => second myDataspace->setAttributeValue(TT("inputUnit"), TT("millisecond")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(1234.5); expected = TTValue(1.2345); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Millisecond to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Sample => second // We need to find the sample rate myDataspace->setAttributeValue(TT("inputUnit"), TT("sample")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); TTValue globalSampleRate; ttEnvironment->getAttributeValue(kTTSym_sampleRate, globalSampleRate); v = TTValue(1.23*TTFloat64(globalSampleRate)); expected = TTValue(1.23); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Sample to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Rate (Hz) => second myDataspace->setAttributeValue(TT("inputUnit"), TT("Hz")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(4.); expected = TTValue(0.25); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Frequency (Hz) to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Beats per minute => second myDataspace->setAttributeValue(TT("inputUnit"), TT("bpm")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(120.); expected = TTValue(0.5); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Beats per minute to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // MIDI => second (2 tests at MIDI notes 57 and 69) myDataspace->setAttributeValue(TT("inputUnit"), TT("midi")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(57.); expected = TTValue(1./220.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("MIDI note 57 to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(69.); expected = TTValue(1./440.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("MIDI note 69 to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // cents => second (2 tests at cents values 5700 and 6900) myDataspace->setAttributeValue(TT("inputUnit"), TT("cents")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(5700.); expected = TTValue(1./220.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Cent value 5700 to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(6900.); expected = TTValue(1./440.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Cent value 6900 to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Bark => second myDataspace->setAttributeValue(TT("inputUnit"), TT("bark")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(5.0); expected = TTValue(0.001785990780318596); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Bark to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Mel => second myDataspace->setAttributeValue(TT("inputUnit"), TT("mel")); myDataspace->setAttributeValue(TT("outputUnit"), TT("second")); v = TTValue(1000.0); expected = TTValue(0.0009999781840186604); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Mel to second", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // speed => seconds // Rather than checking this, there are tests for speed <=> midi further down /************************************************/ /* */ /* Test conversions from neutral unit */ /* */ /************************************************/ // Second => Millisecond myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("millisecond")); v = TTValue(1.2345); expected = TTValue(1234.5); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to millisecond", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => sample // We need to find the sample rate myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("sample")); ttEnvironment->getAttributeValue(kTTSym_sampleRate, globalSampleRate); v = TTValue(192000./TTFloat64(globalSampleRate)); expected = TTValue(192000.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to sample", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => rate (Hz) myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("Hz")); v = TTValue(0.25); expected = TTValue(4.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to frequency (Hz)", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => Beats per minute myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("bpm")); v = TTValue(0.5); expected = TTValue(120.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Seconds to beats per minute", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => MIDI (2 tests at MIDI notes 57 and 69) myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("midi")); v = TTValue(1./220.); expected = TTValue(57.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to MIDI note 57", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(1./440.); expected = TTValue(69.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to MIDI note 69", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => cents (2 tests at cent values 5700 and 6900) myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("cents")); v = TTValue(1./220.); expected = TTValue(5700.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to cent value 5700", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(1./440.); expected = TTValue(6900.); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Second to cent value 6900", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => Bark myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("bark")); v = TTValue(0.001785990780318596); expected = TTValue(5.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Seconds to bark scale", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => Mel myDataspace->setAttributeValue(TT("inputUnit"), TT("second")); myDataspace->setAttributeValue(TT("outputUnit"), TT("mel")); v = TTValue(0.001); expected = TTValue(999.9855371396243); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Seconds to mel scale", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Second => Speed // Rather than checking this, there are tests for speed <=> midi further down /************************************************/ /* */ /* Tests bypassing neutral unit */ /* - where this helps predict expected result */ /* */ /************************************************/ // Speed => MIDI (tests for Speed = 0.5, 1.0 and 2) myDataspace->setAttributeValue(TT("inputUnit"), TT("speed")); myDataspace->setAttributeValue(TT("outputUnit"), TT("midi")); v = TTValue(0.5); expected = TTValue(-12.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("0.5 speed to MIDI", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(1.0); expected = TTValue(0.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("1.0 speed to MIDI", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(2.0); expected = TTValue(12.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("2.0 speed to MIDI", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // MIDI => Speed (tests for Speed = 0.5, 1.0 and 2)*/ myDataspace->setAttributeValue(TT("inputUnit"), TT("midi")); myDataspace->setAttributeValue(TT("outputUnit"), TT("speed")); v = TTValue(-12.0); expected = TTValue(0.5); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("-12 MIDI to speed", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(0.0); expected = TTValue(1.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("0 MIDI to speed", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); v = TTValue(12.0); expected = TTValue(2.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("12 MIDI to speed", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Hz => Mel myDataspace->setAttributeValue(TT("inputUnit"), TT("Hz")); myDataspace->setAttributeValue(TT("outputUnit"), TT("mel")); v = TTValue(1000.0); expected = TTValue(999.9855371396243); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("Hz to mel scale", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Mel => Hz myDataspace->setAttributeValue(TT("inputUnit"), TT("mel")); myDataspace->setAttributeValue(TT("outputUnit"), TT("Hz")); v = TTValue(999.9855371396243); expected = TTValue(1000.0); myDataspace->sendMessage(TT("convert"), v, v); TTTestAssertion("mel scale to Hz", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }