I’m trying to use ==
in a SynthDef but it throws an error when attempting to compile it.
!=
also throws an error. >, <, >=, <=
all work fine.
(
SynthDef(\magTest, { |test = 0|
var less = (1 * (test < 0)) * SinOsc.ar(400);
var equal = (1 * (test == 0)) * SinOsc.ar(800);
var greater = (1 * (test > 0)) * SinOsc.ar(1200);
var sig = (less + equal + greater) * 0.1;
Out.ar(0, sig)
}).add
)
ERROR: binary operator '*' failed.
RECEIVER:
false
ARGS:
Integer 1
nil
PROTECTED CALL STACK:
Meta_MethodError:new 0x7fb418fcc800
arg this = BinaryOpFailureError
arg what = nil
arg receiver = false
Meta_DoesNotUnderstandError:new 0x7fb418fceb40
arg this = BinaryOpFailureError
arg receiver = false
arg selector = *
arg args = [ 1, nil ]
Object:performBinaryOpOnSomething 0x7fb3c8233e40
arg this = false
arg aSelector = *
arg thing = 1
arg adverb = nil
a FunctionDef 0x7fb41b637bb8
sourceCode = "{ |test = 0|
var less = (1 * (test < 0)) * SinOsc.ar(400);
var equal = (1 * (test == 0)) * SinOsc.ar(800);
var greater = (1 * (test > 0)) * SinOsc.ar(1200);
var sig = (less + equal + greater) * 0.1;
Out.ar(0, sig)
}"
arg test = an OutputProxy
var less = a BinaryOpUGen
var equal = nil
var greater = nil
var sig = nil
SynthDef:buildUgenGraph 0x7fb3f813c380
arg this = a SynthDef
arg func = a Function
arg rates = nil
arg prependArgs = [ ]
var result = nil
var saveControlNames = nil
a FunctionDef 0x7fb3f813a9c0
sourceCode = "<an open Function>"
Function:prTry 0x7fb41941f080
arg this = a Function
var result = nil
var thread = a Thread
var next = nil
var wasInProtectedFunc = false
CALL STACK:
DoesNotUnderstandError:reportError
arg this = <instance of BinaryOpFailureError>
Nil:handleError
arg this = nil
arg error = <instance of BinaryOpFailureError>
Thread:handleError
arg this = <instance of Thread>
arg error = <instance of BinaryOpFailureError>
Object:throw
arg this = <instance of BinaryOpFailureError>
Function:protect
arg this = <instance of Function>
arg handler = <instance of Function>
var result = <instance of BinaryOpFailureError>
SynthDef:build
arg this = <instance of SynthDef>
arg ugenGraphFunc = <instance of Function>
arg rates = nil
arg prependArgs = nil
< closed FunctionDef > (no arguments or variables)
Interpreter:interpretPrintCmdLine
arg this = <instance of Interpreter>
var res = nil
var func = <instance of Function>
var code = "SynthDef(\magTest, { |test =..."
var doc = nil
var ideClass = <instance of Meta_ScIDE>
Process:interpretPrintCmdLine
arg this = <instance of Main>
^^ ERROR: binary operator '*' failed.
RECEIVER: false
If I comment out the parts relevant to ==
I can get the SynthDef working, and setting the \test arg works as expected.
(
SynthDef(\magTest, { |test = 0|
var less = (1 * (test < 0)) * SinOsc.ar(400);
// var equal = (1 * (test == 0)) * SinOsc.ar(800);
var greater = (1 * (test > 0)) * SinOsc.ar(1200);
var sig = (less + /*equal +*/ greater) * 0.1;
Out.ar(0, sig)
}).add
)
a = Synth(\magTest)
a.set(\test, -1)
As a workaround I tried the following, which lets me compile the SynthDef, but doesn’t actually get ==
working:
(
SynthDef(\magTest, { |test = 0|
var less = (1 * (test < 0)) * SinOsc.ar(400);
var equal = (1 * (test == 0).asInteger) * SinOsc.ar(800);
var greater = (1 * (test > 0)) * SinOsc.ar(1200);
var sig = (less + equal + greater) * 0.1;
Out.ar(0, sig)
}).add
)
a = Synth(\magTest) // should hear 800hz sine
a.set(\test, -1) // evaluating this lets 400hz sine through
I’m on MacOS Big Sur, running 3.12.2, but it also did it on 3.12.1.
Seems like a bug?