Jump to content

Script needed: change note number after CC values


AlexBerty
 Share

Recommended Posts

Hello, I'm new to Logic and I need a Midi Plugin. Unfortunately I don't have any Scripter skills...

 

So my hope is that an expert here can help me out.

 

I need the following (for drum sampler hihat):

 

the two incoming midi notes 26 and 46 shall alter after CC4 values.

 

Example:

incoming CC4 value range 127 - 111 --> note 26 stays note 26 + note 46 stays note 46

incoming CC4 value range 110 - 91 --> note 26 becomes note 25 + note 46 becomes note 70

incoming CC4 value range 90 - 81 --> note 26 becomes note 24 + note 46 becomes note 71

incoming CC4 value range 80 - 71 --> note 26 becomes note 23 + note 46 becomes note 72

incoming CC4 value range 70 - 61 --> note 26 becomes note 22 + note 46 becomes note 73

incoming CC4 value range 60 - 41 --> note 26 becomes note 21 + note 46 becomes note 74

incoming CC4 value range 40 - 0 --> note 26 becomes note 20 + note 46 becomes note 75

 

All other note numbers that are not involved here (0 - 19 ; 27 - 45 ; 47 - 69 ; 76 - 127) shall get through without any changes and also other CC numbers (and their values) + polyphonic aftertouch.

And it is important that it works without adding latency (it is meant for real time drumming).

 

Is it possible for an expert to write such a script for me? If it works properly I will donate. Thanks in advance! AlexBerty :)

Link to comment
Share on other sites

Try this:

 

// pitch remap array
var remap = [];

// initialize the values
for(let i=0;i<=127;i++) {
   remap[i]=i;
}

// noteOn queue
var sustainingA = [];
var sustainingB = [];

function HandleMIDI(event) {

   if(event instanceof ControlChange && event.number == 4) {
   
       if(event.value <= 127 && event.value >= 111) {
           remap[26]=26;
           remap[46]=46;
       }
       else if(event.value <= 110 && event.value >= 91) {
           remap[26]=25;
           remap[46]=70;
       }
       else if(event.value <= 90 && event.value >= 81) {
           remap[26]=24;
           remap[46]=71;
       }
       else if(event.value <= 80 && event.value >= 71) {
           remap[26]=23;
           remap[46]=72;
       }
       else if(event.value <= 70 && event.value >= 61) {
           remap[26]=22;
           remap[46]=73;
       }
       else if(event.value <= 60 && event.value >= 41) {
           remap[26]=21;
           remap[46]=74;
       }
       else if(event.value <= 40) {
           remap[26]=20;
           remap[46]=75;
       }
       
       // event.send();  // send CC4 through?
       return;    
   }
   
   // NoteOn
   if(event instanceof NoteOn) {
       
       if(event.pitch == 26) {
          event.pitch = remap[event.pitch];
          sustainingA.push(event.pitch);
       }
       else if(event.pitch == 46) {
          event.pitch = remap[event.pitch];
          sustainingB.push(event.pitch);
       }
       
       event.send();
       return;
   }
   
   // NoteOff
   if(event instanceof NoteOff) {
   
       if(event.pitch == 26) {
           event.pitch = sustainingA.shift();
       }
       else if(event.pitch == 46) {
           event.pitch = sustainingB.shift();
       }
       
       event.send();
       return;
   }
       
   // All other events
   event.send();    
}
Edited by Dewdman42
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.   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.

 Share

×
×
  • Create New...