A technical support community for Apple Logic Pro users.

 
User avatar
Ploki
Topic Author
Posts: 4545
Joined: Tue Mar 04, 2008 2:59 am
Location: Slovenia
Contact:

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

Sat Aug 21, 2021 12:34 pm

credit goes to for the original script:
https://gist.github.com/edrd-f/f61f701c ... 0c9912a8a0

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();
}
<desktop pending> | 13" M1 Pro | Big Sur 11.1 | Logic 10.6.1
RME FireFace 800 / UFX+ | ROLI Seaboard RISE 25 | ROLI Blocks | nOb Control | StreamDeck