How to play higher and lower octave key on midi key press? Note off event doesn't pause the engine.
-
Can someone explain to me what's wrong with the code below?
TheonNotePlay
andonNotePause
functions are hooked with theonNoteOn
andonNoteOff
callbacks.
I'm trying to play the note an octave up and an octave down, and it works when I press the key, butonNotePause
doesn't work even though it's being called correctly.Is there a better way to do it? I checked the
Engine.allNotesOff
, but it affects playing keys fast.function onNotePlay() { var note = Message.getNoteNumber(); var velocity = Message.getVelocity(); var higherNote = note + 12; var lowerNote = note - 12; if (octaveUp.getValue() && higherNote < HIGHEST_NOTE) Synth.playNote(higherNote, velocity); if (octaveDown.getValue() && lowerNote >= LOWEST_NOTE) Synth.playNote(lowerNote, velocity); } function onNotePause() { var note = Message.getNoteNumber(); Console.print("on note pause called - "+note); var higherNote = note + 12; var lowerNote = note - 12; if (octaveUp.getValue() && higherNote < HIGHEST_NOTE) Synth.noteOffByEventId(higherNote); if (octaveDown.getValue() && lowerNote >= LOWEST_NOTE) Synth.noteOffByEventId(lowerNot); }
-
@mrcurious said in How to play higher and lower octave key on midi key press? Note off event doesn't pause the engine.:
but onNotePause doesn't work even though it's being called correctly.
What is the behaviour you want?
-
The onNoteOff should turn off the note that's being played currently (or started playing in the onNoteOn callback). When the onNoteOff event is received, I try to turn off the note that has already been played.
The code above that I pasted is probably not correct. Even if I change my logic to use
noteOffByEventId
and pass the eventId inside this function by collecting the eventId returned by playNote function. It doesn't work. -
@mrcurious Ah ok I understand now.
Synth.playNote()
returns an eventId that you can store in a variable.Then when you call
Synth.noteOffByEventId()
you pass it theeventId
, rather than the note number. -
Yeah, now it works
Thank you!
I was doing some unnecessary logic with Synth.noteOffByEventId(eventId).