Jump to content

Simple script that adds 0/127 CC to every other note


Ploki
 Share

Recommended Posts

credit goes to for the original script:

https://gist.github.com/edrd-f/f61f701cd3fdbd7e60cd8a0c9912a8a0

 

I just modified it so it passes all events through and adds a CC4 with alternating 0 and 127 to every other beat.

Makes it easy with modifier to assign plugin parameters for i.e. alternating autopan. :) (this was my case, to control pan knob of microtonic of hihat)

 

var notesOn = [];

function isNotePlaying(event) {
for (var i = 0; i < notesOn.length; i++) {
	if (notesOn[i] && notesOn[i].pitch == event.pitch) {
		return i;
	}
}

return false;
}

function sendNoteAlt(event) {
 var noteOffEvent = new NoteOn();
noteOffEvent.pitch = event.pitch;
noteOffEvent.channel = event.channel;
noteOffEvent.velocity = event.velocity;
noteOffEvent.send();
}
function sendCC(event) {
var sendCC = new ControlChange();
sendCC.number = 4;
sendCC.channel = event.channel;
sendCC.value = 0;
sendCC.send();
}

function sendCCAlt(event) {
var sendCCAlt = new ControlChange();
sendCCAlt.number = 4;
sendCCAlt.channel = event.channel;
sendCCAlt.value = 127;
sendCCAlt.send();
}
function HandleMIDI(event)
{
//event.trace();

if (event instanceof NoteOn) {
   var noteIndex = isNotePlaying(event)
	if (typeof noteIndex == 'number') {
		delete notesOn[noteIndex];
		sendNoteAlt(event);
		sendCC(event);
	} else {
		notesOn.push(event);
		event.send();
		sendCCAlt(event);
	}
	
	return;
}

if (event instanceof NoteOff) {

	return;
}

event.send();
}

| 13" M1 Pro | Big Sur 11.1 | Logic 10.6.1

RME FireFace 800 / UFX+ | ROLI Seaboard RISE 25 | ROLI Blocks | nOb Control | StreamDeck

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...