Jump to content

Script to get a CC's Value triggering Note On/Off


Monosock

Recommended Posts

Hi there

 

 

I've seen similar scripts on this forum so hopefully this shouldn't be too far off. Would it be possible to get an incoming Midi CC value.

lets say Breath (cc2) to control an specific note (lets say F2)

so when

CC2=127 You get F2=note on

CC2=0 you get F2 =note off

 

the tricky bit would be getting a drop down menu where you can actually choose the note to trigger (so it doesn't necessarily has to be F2) it can be any note.

 

 

As for the MIDI CC I wouldn't necessarily need a drop down menu as I could just add an instance of Modifier to get the scripts default CC (lets stick to Breath for now)

 

as for the Midi CC value to trigger the Note on/off doesn't necesarily can be 127 and 0 respectively, it could be

Note on < 64

note off > 64

 

 

 

any brave takers?

Link to comment
Share on other sites

Hi,

 

Here's a script that triggers the chosen Note with a CC like this:

 

CC2=127 You get F2=note on

CC2=0 you get F2 =note off

 

// This triggers Note events with a CC to control the LED's on an APC 40:
// A CC with a value of 127 triggers the Note On event. 
// The same CC with a value of 0 triggers the corresponding Note Off.
// All other events do not go through.

var nNames = MIDI._noteNames;
var ccNum = [];
var velNames = ["1 Static Green", "2 Green Blink", "3 Red", "4 Red Blink", "5 Orange", "6 Orange Blink"];
var title = "APC 40 LED's"
var author = "Script by Jordi Torres";

for (var i = 0; i < 128; i++) {
   ccNum[i] = String(i);
}

var PluginParameters = [{
   name: title,
   type: "text"
}, {
   name: "CC",
   type: "menu",
   valueStrings: ccNum,
   defaultValue: 1
}, {
   name: "Note",
   type: "menu",
   valueStrings: nNames,
   defaultValue: 0
}, {
   name: "Velocity",
   type: "menu",
   valueStrings: velNames,
   defaultValue: 0
}, {
   name: author,
   type: "text"
}];

function HandleMIDI(e) {
   if (e instanceof ControlChange && (e.number === GetParameter("CC") && e.value === 127)) {
       var on = new NoteOn();
       on.pitch = GetParameter("Note");
       on.velocity = GetParameter("Velocity") + 1;
       on.send();
   } else if (e instanceof ControlChange && (e.number === GetParameter("CC") && e.value === 0)) {
       var off = new NoteOff();
       off.pitch = GetParameter("Note");
       off.send();
   }
}

 

Both the CC and the Note are set with drop-down menus.

 

You didn't say anything about velocity so the default value of 100 is used for the triggered Note On event.

 

J.

Link to comment
Share on other sites

This is awesome Jordi, Thanks! The only thing I took off from your code is the Event send on your last Else. as It was sending all the values in between 1-126 which was undesirable.

 

AS for Velocity... I just found out I'd need to trigger between 1-6 fpr that value. I'm using this to light up the LED's of an APC 40 on mainstage so each velocity value lights up the pads in a different way.

 

1 (or >6) = Static Green

2 = Green Blink

3 = Red

4 = Red Blink

5 = orange

6 = orange blink.

 

In the ideal world you would be able to select the velocity (or LED colour) too on a drop menu.

 

Also.. I think I need to get into this Java stuff. I did Visual basic when I was doing my A levels at school and was pretty good at it (albeit that was more than 10 years ago) So i'm now refreshing my knowledge about all this programming language. Any books you'd recommend so I stop bothering people on this forum? and can start helping out at some point too?

Link to comment
Share on other sites

Hi,

 

This is awesome Jordi, Thanks!

 

You're welcome.

 

The only thing I took off from your code is the Event send on your last Else. as It was sending all the values in between 1-126 which was undesirable.

 

You didn't say so in your original post. By default I always let events not being used by the script to pass through.

 

AS for Velocity... I just found out I'd need to trigger between 1-6 fpr that value. I'm using this to light up the LED's of an APC 40 on mainstage so each velocity value lights up the pads in a different way.

 

1 (or >6) = Static Green

2 = Green Blink

3 = Red

4 = Red Blink

5 = orange

6 = orange blink.

 

In the ideal world you would be able to select the velocity (or LED colour) too on a drop menu.

 

I've updated the script with this new stuff.

 

Also.. I think I need to get into this Java stuff. I did Visual basic when I was doing my A levels at school and was pretty good at it (albeit that was more than 10 years ago) So i'm now refreshing my knowledge about all this programming language. Any books you'd recommend so I stop bothering people on this forum? and can start helping out at some point too?

 

Well, first thing to do is get the language's name right :) . This is JavaScript, not Java. They're different languages.

 

Since it seems you're interested in using it for creating Scripter plug-in scripts, I think your first stop should be Logic Pro X's "Effects" manual and its section on the Scripter API.

 

If you're interested in learning JavaScript beyond the Scripter API, there's plenty of good material available freely online.

 

Here's some resources you might want to check out:

 

http://eloquentjavascript.net/

 

https://developer.mozilla.org/en-US/Learn/JavaScript

 

https://www.codecademy.com/learn/javascript

 

J.

Link to comment
Share on other sites

This is perfect, thanks; Jordi.

 

 

Yeh ok, I meant javascript. Yeah not really keen on learning anything beyond this API stuff. As i'm a full time muso, can't think of any more uses for it, I think Kontakt has a javascript option too but not so sure.

 

Good shout about the manual, it was actually the first place I looked. As I mentioned, I'm relatively familiar with how algorithms work but not with the language for this API stuff. I looked into the manual and it gives you some of the parameters you can put down on the code but not everything.

 

This script for instance.. I was able to pull it off before I saw your reply (obviously mine was considerably more austere , no drop down menus, no text, etc) but I had to look into the code of other scripts to get to know the parameters this Scripter can take (like on.pitch or sendaftermiliseconds, etc) is this a standard MIDI java script language one can get on a book or is this something specific for logic?

 

Thanks for your time, once again!

Link to comment
Share on other sites

This is perfect, thanks; Jordi.

 

Cool.

 

I think Kontakt has a javascript option too but not so sure.

 

It uses its own scripting language called Kontakt Script.

 

I looked into the manual and it gives you some of the parameters you can put down on the code but not everything.

 

If you combine what's covered in the manual with some core javascript concepts such as variables, conditional statements, loops, functions, arrays, objects, etc you should be good to go.

 

is this a standard MIDI java script language one can get on a book or is this something specific for logic?

 

No, you won't find a book specifically on what we use within Scripter. However, like I said, if you get the basic JavaScript concepts down, then go over the material on the manual, you should be all set.

 

J.

Link to comment
Share on other sites

  • 3 years later...

Hi,

 

So how would you like to handle the CC (2nd data byte) values? Which values should be on and which should be off? And would these translate directly to the note velocities?

Or maybe you would like a fixed velocity for the resulting note and whichever value you decide to be the CC "off" would trigger the note off condition?

 

J.

Link to comment
Share on other sites

Hi,

 

Try this then and let me know if that's what you want:

 

var PluginParameters = [{
   name: 'CC to Note',
   type: 'text'
}, {
   name: 'CC',
   type: 'menu',
   valueStrings: ccNums(),
   defaultValue: 1
}, {
   name: 'Note',
   type: 'menu',
   valueStrings: MIDI._noteNames,
   defaultValue: 0
}, {
   name: 'Script by Jordi Torres',
   type: 'text'
}];

function ccNums() {
   const ccNum = Array.from({length: 128}, (cc, index) => String(index));    
   return ccNum;
}

function HandleMIDI(e) {
   const noteOn = new NoteOn();
   const noteOff = new NoteOff();
   if (e instanceof ControlChange && (e.number === GetParameter('CC') && e.value === 127)) {
       noteOn.pitch = GetParameter('Note');
       noteOn.velocity = e.value;
       noteOn.send();
   } else if (e instanceof ControlChange && (e.number === GetParameter('CC') && e.value === 0)) {
       noteOff.pitch = noteOn.pitch;
       noteOff.send();
   } else {
       e.send();
   }
}

 

Hopefully your version of macOS supports the ES6+ (modern JavasCript) stuff I'm using here. Otherwise I can modify it.

 

J.

Link to comment
Share on other sites

Hello,

 

Thank you for the modification. I tested it and kind of works.

 

When I enable the selected CC it does trigger the selected note but when I disable the CC (MIDI YY value) to off, the note does not shut off. It hangs.

 

As further modification, could you create the script to behave as such.

 

For example: When CC 103 sends value 127(on), convert that value to Note C2 on, when CC 103 sends a value of (off), it sends note off to C2 and turns on D2. When CC 103 selected, the reverse happens based on the menu selection for notes.

 

The idea is to use the selected CC as switch to toggle between to selected note values based on the state of the selected CC.

 

Based of selection

CC 103 On = C3 on, D2 Off

CC 103 Off = C3 Off, D2 On

 

The menu choices are:

-Selection CC

-Selection Note value for CC on

-Select Note Value for CC Off

 

From a musical standpoint, I am using a midi switch to toggle between to Keyswitches during a life performance.

 

Thank you. Your help is much appreciated.

 

Cheers.

Link to comment
Share on other sites

  • 1 month later...

I have modified the code to let notes through. Heads up, the note nomenclature within the plugin is an octave lower than some others, i.e., what some call A0 will be called A-1 by this plugin.

 

// This triggers Note events with a CC to control the LED's on an APC 40:
// A CC with a value of 127 triggers the Note On event. 
// The same CC with a value of 0 triggers the corresponding Note Off.
// Notes go through also
// For triggering Scarbee or similar Key Switches with Sustain/Mod Buttons on Korg Nanokey or similar

var nNames = MIDI._noteNames;
var ccNum = [];
var velNames = ["1 Static Green", "2 Green Blink", "3 Red", "4 Red Blink", "5 Orange", "6 Orange Blink"];
var title = "APC 40 LED's"
var author = "Script by Jordi Torres";

for (var i = 0; i < 128; i++) {
   ccNum[i] = String(i);
}

var PluginParameters = [{
   name: title,
   type: "text"
}, {
   name: "CC",
   type: "menu",
   valueStrings: ccNum,
   defaultValue: 1
}, {
   name: "Note",
   type: "menu",
   valueStrings: nNames,
   defaultValue: 0
}, {
   name: "Velocity",
   type: "menu",
   valueStrings: velNames,
   defaultValue: 0
}, {
   name: author,
   type: "text"
}];

function HandleMIDI(e) {
e.trace();
   if (e instanceof ControlChange && (e.number === GetParameter("CC") && e.value === 127)) {
       var on = new NoteOn();
       on.pitch = GetParameter("Note");
       on.velocity = GetParameter("Velocity") + 1;
       on.send();
   } else if (e instanceof ControlChange && (e.number === GetParameter("CC") && e.value === 0)) {
       var off = new NoteOff();
       off.pitch = GetParameter("Note");
       off.send();
       }
       else if (e instanceof Note);
       e.send();
   }

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...