0

If i'm using OSCdef to listen for changes from a function, such as:

OSCdef('listen', {
    arg msg;

    ~trigger = msg[5]; // This value is 0 when off, 1 when on

    ~amp = msg[3].linexp(0.0, 1.0, 0.7, 0.8 );
    ~dur = msg[4].linexp(0.1, 1.0, 1.0, 0.01);
    ~pitch = msg[4].linlin(0.0, 1.0, 80, 800);
}, '/ctrl');

When ~trigger fires, the variable becomes 1. I want to play a synth or open an env to change the sound.

However, when ~trigger fires, it fires for 10 seconds randomly, so you'll have 1,1,0,1,0,0,0,1,0,01,01,01,01,1,01, etc for 10 seconds.

I want to know if it's possible to catch the first 1, play an event and ignore the remaining triggers for the next 10 seconds

Andrew Lazarus
  • 989
  • 2
  • 16
  • 25

1 Answers1

1

Worth looking at "suppressing triggers":

Passing or suppressing triggers: You might need to generate triggers continuously, but permit the triggers to take effect only when a condition is met. Multiplication handles this nicely: condition * trigger. Since the condition evaluates as 0 when false, the trigger will be replaced by 0 and nothing happens, as desired.\ \ For a simple case, let’s refine the mic amplitude example by suppressing triggers that occur within 1/4 second after the previous. var mic = In.ar(8, 1), amplitude = Amplitude.kr(mic), trig = amplitude > 0.2,
timer = Timer.kr(trig), // how long since the last trigger?
filteredTrig = (timer > 0.25) * trig;

SendTrig.kr(filteredTrig, 0, amplitude);

Source: https://supercollider.github.io/tutorials/If-statements-in-a-SynthDef.html

Andrew Lazarus
  • 989
  • 2
  • 16
  • 25