The ‘==’ operator is somehow exceptional. If you look at the implementations of ‘<’, ‘>’, ‘<=’ and ‘>=’, you see that these operators (methods) are defined for UGens via the superclass AbstractFunction. For some reason this is not the case for ‘==’, so the operator’s implementation for AbstractFunction’s superclass Object is applied and you end up with a result, which is no UGen, which breaks the ‘if’ pseudo ugen:
if { arg trueUGen, falseUGen;
^(this * (trueUGen - falseUGen)) + falseUGen;
}
If you want to make such work, you can e.g. use the (not very handsome) syntax
(
{
var sevens = DC.kr(7);
Poll.kr(Impulse.kr(1), [
sevens,
if(BinaryOpUGen('==', sevens, 7), 1, 0),
if(sevens < 7, 1, 0),
if(sevens > 7, 1, 0),
if(sevens <= 7, 1, 0),
if(sevens >= 7, 1, 0),
])
}.play
)
By the way the analogue problem occurs with Pif and ‘==’, you can’t use this, instead replace with Pbinop(’==’ etc. This is fooling people since … decades, I feel There doesn’t seem to be an easy workaround though.
(
SynthDef(\help_sinegrain,
{ arg out=0, freq=440, sustain=0.05;
var env;
env = EnvGen.kr(Env.perc(0.01, sustain, 0.2), doneAction: Done.freeSelf);
Out.ar(out, SinOsc.ar(freq, 0, env))
}).add;
)
(
var a;
a = Pif(
Pfunc({ [0, 1].choose } == 0), // doesn't work
// Pfunc({ [0, 1].choose } < 1), // works
// Pbinop('==', Pfunc({ [0, 1].choose }), 0), // works
Pn(Pseries(0.5, 0.1, 10)), Pn(Pseries(6, -0.1, 10))
).asStream;
{
loop {
Synth(\help_sinegrain, [\freq, a.next * 600 + 300]);
0.2.wait;
}
}.fork;
)
And actually the original example of this help file is not ideal IMO, as it implements a syntax which leads to inexact timing, but this is another story:
http://doc.sccode.org/Guides/ServerTiming.html