Jump to content

trouble attempting script to latch notes on/off


alienbeatpoet

Recommended Posts

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();	
} 

Link to comment
Share on other sites

  • 5 weeks later...

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;
}
}

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...