alienbeatpoet Posted December 24, 2015 Share Posted December 24, 2015 i'm trying to write a midi effects script in the scripture that would latch any notes pressed and hold it until i press the respective note is pressed again. simply: hit the key once = note on. hit it again = note off. i can latch the first note fine, but subsequent notes i want to latch as well have to hit twice for it to sound and latch. then when unlatching the first note to be unlatched comes off fine. but the subsequent notes to unlatch have to be hit twice (again) and the first hit actually sounds the note again. not at all desired. i'm probably very close, but i just can't seem to make it work. can anyone help me out? /* NoteLatcher */ var isActive = false; function HandleMIDI(event) { if (event instanceof NoteOn){ //latch note on if (isActive == false) { var on = new NoteOn; on.pitch = event.pitch; on.send(); isActive = true; } //latch note off else if (isActive == true) { var off = new NoteOff; off.pitch = event.pitch; off.send(); isActive = false; } } event.trace(); } Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted January 23, 2016 Share Posted January 23, 2016 I have a script that does this among other things. I am not sure if you want strict monophonic, monophonic or polyphonic. Here's one way to do a quick polyphonic hack - maybe it can help you: //CavemanLatch by LogicScripts 2016 var notes = []; for (var i = 0; i < 128; i++) { notes[i] = -1; } function HandleMIDI(e) { if (e instanceof Note) { if (e instanceof NoteOn) { notes[e.pitch] *= -1; e.killed = 0; } if (e instanceof NoteOn && notes[e.pitch] == -1) { f = new NoteOff(e); f.send(); e.killed = 1; } e.killed == 0 ? e.send() : false; } } 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.