antiabed Posted September 25, 2018 Share Posted September 25, 2018 Hi everybody! I've seen a bunch of scripts creating a last note priority, but I'm trying to make one that does the opposite, Play the first note you played, and not let any other note through until that first note is released. I modified one of the last note priority scripts I found, and it kinda works. But fast notes are sometimes ignored and sometimes it let's a new note through while another is still playing. Can someone help me make this more solid? Here is what I have now: var hold = []; function HandleMIDI(e) { var a = e instanceof NoteOn && e.velocity !=0; var b = e instanceof NoteOff; var c = e instanceof NoteOn && e.velocity ==0; if (a) { switch (hold.length) { case 0: hold.push(e.pitch); e.send(), e.trace(); break; case 1: if (hold[0] != e.pitch) { hold.pop(); hold.push(e.pitch); break; } } } if (b || c) { if (e.pitch != hold[0]) { e.send(), e.trace(); hold.pop(); } } if (!a && !b && !c) { e.send(), e.trace(); } } Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted September 25, 2018 Share Posted September 25, 2018 Try this instead: var gate = -1; function HandleMIDI(event) { // if first note, close gate until Noteoff if(event instanceof NoteOn) { if (gate < 0) { gate = event.pitch; event.send(); return; } else { return; // ignore until gate open again } } // if its the right note off, open the gate again if(event instanceof NoteOff) { if (event.pitch == gate) { event.send(); gate = -1; return; } else { return; // ignore until gate open again } } // all other event types, pass through event.send(); } Quote Link to comment Share on other sites More sharing options...
antiabed Posted September 29, 2018 Author Share Posted September 29, 2018 Perfect! Thank you so much for the smart solution Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.