Active notes check/Voice distribution
-
Is there any way to check exactly how many notes are being played?
I'm experimenting with triggering multiple single-voiced synths and need to find the best way to distribute the notes across them.
My hacky solution now KINDA works but quickly messes up the voice count, especially if you play it quicker than... Really slow.
I have a global in the interface script (I know, globals are the devil, don't remember why):
global activeNotes = 0;
And one script processor for each synth:
onInit reg eventId1 = -99; reg note = -99; onNoteOn function onNoteOn() { Message.ignoreEvent(true); if (activeNotes == 0) //== 1, 2, 3 etc. for other script processors { note = Message.getNoteNumber(); eventId1 = Synth.playNote(note, 127); activeNotes = activeNotes + 1; } } onNoteOff function onNoteOff() { if(Message.getNoteNumber() == note && Synth.isSustainPedalDown() == false) { Synth.noteOffByEventId(eventId1); eventId1 = -99; note = -99; activeNotes = activeNotes - 1; } }
Like I said it kinda works but loses count if you play multiple notes in rapid succession.
So if synth1 is already taking care of the first active note, synth2 plays the next one. Is there a more solid way to approach this?
-
Also, my solution sucks right now because it's not keeping track of which synths are free to play.. Synth1 will only play if no notes are playing, Synth2 will only play if one note is playing etc.
-
Is there any way to check exactly how many notes are being played?
What's wrong with
Synth.getNumPressedKeys()
? -
@d-healey Nothing wrong with it, I didn't know it existed :) I'm realizing it doesn't help with my problem of managing the voice distribution though.
-
@audiolyf Just so I understand. If you have 3 synths and you play a 3 note chord you want one note per synth? What about if you play 4 notes?
-
@d-healey Right now I have 6 synths, and that's a good question. Do you drop off the first note played, the last note played, or the note closest to the last note played...
I managed to solve it in another way by adding MIDI channel filters to each channel and managing the rest from the interface script. Maybe not the prettiest solution but it works!
onInit reg voice1play = -99; reg voice2play = -99; reg voice3play = -99; reg voice4play = -99; reg voice5play = -99; reg voice6play = -99; reg note = -99; reg lastNote = -99; reg lastVoice = -99; reg eventId0 = -99; reg eventId1 = -99; reg eventId2 = -99; reg eventId3 = -99; reg eventId4 = -99; reg eventId5 = -99; function onNoteOn() { Message.ignoreEvent(true); note = Message.getNoteNumber(); if(!Synth.isArtificialEventActive(eventId0) && Synth.getNumPressedKeys() < 7) { eventId0 = Synth.playNoteWithStartOffset(1, note, 127, 0); voice1play = note; lastVoice = 1; Console.print(Synth.isArtificialEventActive(eventId0)); } else if(!Synth.isArtificialEventActive(eventId1) && Synth.getNumPressedKeys() < 7) { eventId1 = Synth.playNoteWithStartOffset(2, note, 127, 0); voice2play = note; lastVoice = 2; } else if(!Synth.isArtificialEventActive(eventId2) && Synth.getNumPressedKeys() < 7) { eventId2 = Synth.playNoteWithStartOffset(3, note, 127, 0); voice3play = note; lastVoice = 3; } else if(!Synth.isArtificialEventActive(eventId3) && Synth.getNumPressedKeys() < 7) { eventId3 = Synth.playNoteWithStartOffset(4, note, 127, 0); voice4play = note; lastVoice = 4; } else if(!Synth.isArtificialEventActive(eventId4) && Synth.getNumPressedKeys() < 7) { eventId4 = Synth.playNoteWithStartOffset(5, note, 127, 0); voice5play = note; lastVoice = 5; } else if(!Synth.isArtificialEventActive(eventId5) && Synth.getNumPressedKeys() < 7) { eventId5 = Synth.playNoteWithStartOffset(6, note, 127, 0); voice6play = note; lastVoice = 6; } } function onNoteOff() { if(Message.getNoteNumber() == voice1play) { Synth.noteOffByEventId(eventId0); voice1play = -99; } if(Message.getNoteNumber() == voice2play) { Synth.noteOffByEventId(eventId1); voice2play = -99; } if(Message.getNoteNumber() == voice3play) { Synth.noteOffByEventId(eventId2); voice3play = -99; } if(Message.getNoteNumber() == voice4play) { Synth.noteOffByEventId(eventId3); voice4play = -99; } if(Message.getNoteNumber() == voice5play) { Synth.noteOffByEventId(eventId4); voice5play = -99; } if(Message.getNoteNumber() == voice6play) { Synth.noteOffByEventId(eventId5); voice6play = -99; } note = -99;
-
If you use arrays and switch statements you'll greatly simplify that code.
-
@d-healey Care to give a quick example? :)
-
@audiolyf A simple solution is to use a midiList which is made for this kind of stuff:
HiseSnippet 1405.3oc6Y0sTaaDEVx1hfMszj1j1dUm8h1YrGHDKSZZmgICFv1odBF7fHjdGyhzZ6cPZWWoUP8zoyza5aSeFZ4QnOB8QH20KaOqjLR1QPbbCzB09B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