Synth.startTimer not calling onTimer callback
-
Hello! I'm trying to setup a really basic tempo synced note repeater for each sampler, but for some reason nothing will start the onTimer callback. I'm probably missing something really obvious. Here's a WIP:
/* Basic tempo synced note repeater */ const var loopButton = Content.addButton("Loop", 0, 10); loopButton.set("text", "Loop"); var notes = []; notes.reserve(127); var heldNotes = []; inline function playAllHeldNotes() { for (var i = 0; i < heldNotes.length; i++) { Synth.playNote(heldNotes[i], 127); } } function onNoteOn() { local note = Message.getNoteNumber(); local eventId = Message.makeArtificial(); notes[note] = eventId; heldNotes.push(note); if (loopButton.getValue() == 1) { local interval = Engine.getMilliSecondsForQuarterBeats(1); // if first note on, start timer if (!Synth.isLegatoInterval()) { Synth.startTimer(interval); } } } function onNoteOff() { local note = Message.getNoteNumber(); Synth.noteOffByEventId(notes[note]); notes[note] = -1; heldNotes.remove(note); // if no notes are held, stop timer if (!Synth.isLegatoInterval()) { Synth.stopTimer(); } } function onTimer() { Console.print("TIMER!!!"); playAllHeldNotes(); } function onControl(number, value) { } function onController() { }
Would appreciate any suggestions! Thanks.
-
Post a snippet
-
Actually I see the problem. Synth.startTimer() doesn't take a value in milliseconds.
-
WOW! I knew it was something simple. Yes, that should do the trick. Thank you!
-
Also if you use an Engine.createTimer() type timer then the value IS in milliseconds :p
-
@d-healey said in Synth.startTimer not calling onTimer callback:
Also if you use an Engine.createTimer() type timer then the value IS in milliseconds
So I'm realizing haha