[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] conditional statement in SynthDef
For more background, try examining the value of "high" when building the synthdef.
SynthDef("ifTest", {arg outBus = 0, high = 1;
var freq;
high.dump;
if(high == 1, {freq = 440}, {freq = 220});
Out.ar(outBus, SinOsc.ar(freq, 0, 0.5));
}).send(s);
<x-tad-smaller>Instance of OutputProxy { (054AB450, gc=68, fmt=00, flg=00, set=04)
instance variables [9]
synthDef : instance of SynthDef (05434770, size=10, set=4)
inputs : nil
rate : Symbol 'control'
synthIndex : Integer 0
specialIndex : Integer 0
antecedents : nil
descendants : nil
source : instance of Control (054A4E00, size=9, set=4)
outputIndex : Integer 1
}
</x-tad-smaller>
Also remember that the server knows nothing about the language. "if(high == 1)" is meaningless to the server (as is "freq = 220" in the if branch). The expressions are evaluated in the language once, when the synthdef is built, and the result is hardcoded into the synthdef structure. And, of course, anOutputProxy == 1 is always going to be false.
> and < comparisons should work, though. someUGen > someUGen produces a BinaryOpUGen that outputs 0 when false and 1 when true.
freq = if(high > 0, 440, 220);
Always trace your synth nodes if you're not sure what's going on... \n_trace, nodeID or mySynthObject.trace
hjh
: H. James Harkins
: jamshark70@xxxxxxxxxxxxxxxxx
: http://www.dewdrop-world.net
.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:
"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal." -- Whitman