I have found a simple solution with the MidiList object:
- When a Note On command comes in, then in a MidiList the index of the pressed key is set to the value of the note that is output. e.g. I press key 60 which is not active but only the next key so "60 -> 61" is stored in the MidiList.
- When a Note Off command comes in, before the Note Off command is sent, it is first checked whether another key also has this value
- If no key has this value, a Note Off command is sent for the note and the key is set to -1 in the MidiList.
- If one or more keys have this value, the NoteOff command is not sent
onInit()
reg midiKeyList = Engine.createMidiList();
onNoteOn()
const receivedNote = Message.getNoteNumber();
var outputNote = getOutputNoteBySnapMode(receivedNote);
midiKeyList.setValue(receivedNote, outputNote);
sendNoteToMidiOut(outputNote);
onNoteOff()
const receivedNote = Message.getNoteNumber();
var outputNote = getOutputNoteBySnapMode(receivedNote);
midiKeyList.setValue(receivedNote, -1); // set pressed Note in midiList to -1
if (midiKeyList.getValueAmount(outputNote) <= 0)
{
sendNoteToMidiOut(outputNote);
}
I hope you can understand it.
Thanks guys