onTimer: play a note, reset timer, repeat
-
It seemed a trivial thing to accomplish, but I am a bit stuck.
Objective: In a NoiseGenerator start a timer. When the timer reaches a particular value (eg. 3sec), play a note (noise), then reset the timer, so that the process can repeat indefinitely.
I've tried various strategies, but I am still not getting a note to play on timer. Here is the latest I've got that doesn't work.
**onInit** var t = Engine.createTimerObject(); t.startTimer(100); var qt = Synth.isTimerRunning(); **onNoteOn** function onNoteOn() { Message.ignoreEvent(true); // Isolate the synth by ignoring any MIDI notes coming in } **onTimer** function onTimer() { Console.print("Is timer running? " + qt); if (t > 3000) { Synth.playNote(38,127); Synth.addNoteOff(1,38,100000); t.resetCounter; } Console.print("Current timer: " + t); }Any help is much appreciated!
-
There are a few issues.
Firstly never use
varunless your life depends on it :p (almost).Your timer should be a
constisTimerRunning()lives in the moment. If you call that function withinon initthen it is only going to check if the timer is running duringon initand at no other time.Engine.createTimerObject()Creates a new timer, completely separate from the in-built synth timer. So starting that timer will not trigger the synth timer callback.I think this playlist is for you:
https://www.youtube.com/playlist?list=PLynv7CujPCfZBVsmtWsSZ68nPMXuIHwNL -
@d-healey Thanks, @d-healey . Your video was very helpful in understanding a few things. I created a looping timer that plays a note at random intervals. I specify a range for the random interval.
Here is my script, which I put on the main Container holding a child synth noise generator.
**onInit** Synth.startTimer(3); **onNoteOn** function onNoteOn() { Message.ignoreEvent(true); // Isolate the synth by ignoring any MIDI notes coming in } **onTimer** function onTimer() { var RT = Math.randInt(10,20); Synth.stopTimer(); Synth.startTimer(RT); local ti = Synth.getTimerInterval(); Synth.playNote(38,127); Synth.addNoteOff(1,38,100000); Console.print("Current timer: " + ti); }So, all of that works wonderfully for a single generator.
Here is the next challenge: I'd like to create several child synths in that main Container, each playing a different note and routed to a different matrix output. All notes should start and finish at the same time, thus getting the cue from the main Container timer.
How do I go about this, please?