OSCFunc — a VERY newbie question

hi!

i’ve just barely started to learn SC and what can i say — i’m very excited!
i’m currently learning to use IANNIX to control an SC patch. i catch triggers via OSC with something like this:

OSCFunc({arg msg; if(msg[1]==11, {Synth.new(\bloop2, [\pitch, midicps(51)])})}, ‘\trigger’);

so it fires up a synth with a specific pitch in response to the specific trigger number.
the synth has an envelope with doneAction=2 so it disappears from the server as soon as the envelope is finished.
however, the issue is that when i reevaluate this with, for example, a different note number:

OSCFunc({arg msg; if(msg[1]==11, {Synth.new(\bloop2, [\pitch, midicps(55)])})}, ‘\trigger’);

i now hear BOTH notes firing up together.

so the question is — how i free, destroy or otherwise get rid of the OSCFunc when I need to? i couldn’t find a method.

thanks!

answering to myself — of course, i just need to do

o = OSCFunc({arg msg; if(msg[1]==11, {Synth.new(\bloop2, [\pitch, midicps(51)])})}, ‘\trigger’);

then i can do

o.free;

how stupid one can get lol

You can also define the OSCFunc with ‘oneShot’, see helpfile examples.

1 Like

Thanks! this way OSCFunc only fires once on the first trigger (which is entirely logical). I, however, need it to handle all the trigger events with the same ID (msg[1]) until i explicitly tell it to stop or change.

You could also try OSCdef instead of OSCFunc. Every time you re-run it with same key (the def’s “name”, first arg), it overwrites the previous definition.

1 Like

thanks! this works. can’t stop being amazed by SC’s flexibility and power. great community here, too.