Jump to content

Use Scripter to change midi note channel


ninox_rufa

Recommended Posts

My aim is to create a script to change the channel number for a selectable range of notes. I can't even work out how to simply change the channel for all notes. Totally out of my depth here. I can make pretty much anything in the Environment but have no coding experience.

Have tried implementing the Event.channel(number) property several ways with no success. I don't understand the phrase in the manual "Note: Event.channel is an event property, rather than a method" and I can't find any simple example in the included scripts or online. I thought the attached code might work but obviously it's too simple. Not sure how to handle noff's either.

function HandleMIDI(event) {

   event.send();

   if (event instanceof Note) { 
   
       Event.channel(4);
   }
}

 

 

 

Note to mods:

Note sure whether to post here or in the MIDI FX forum. Is that forum only for file sharing or for asking questions too?

Link to comment
Share on other sites

Note to mods:

Note sure whether to post here or in the MIDI FX forum. Is that forum only for file sharing or for asking questions too?

I'm not sure either! :D But since you've posted it in the LPX forum and bumped it, I moved it to the Script forum, so that in case you still don't get an answer, it doesn't fall into the abyss of the LPX forum, and instead stays visible in the script forum, should some script enthusiasts visit our forum later.

 

I'll page ski who's done some scripting in LPX to see if he can help with your post as well.

Link to comment
Share on other sites

This script channelizes only notes between (and including) C3 and C4 to channel 4. The variable "chan" sets the MIDI channel. Everything else -- controls, pitch bend, etc. -- passes through on the original channel feeding into the Script.

 

 

function HandleMIDI(e) {

var chan = 4;

 

if (e instanceof Note) {

 

if (e.pitch >= 60 && e.pitch <=72) {

e.channel = chan;

e.send();

e.trace();

 

}else{

 

e.send();

e.trace();

 

}

 

}else{

e.send();

e.trace();

 

}

}

Edited by ski
Link to comment
Share on other sites

One more BTW...

 

The MIDI data path is:

 

MIDI (from your controller) ---> Logic Sequencer Input (environment) ---> Selected Track ---> Scripter ----> Plugin

 

What this shows is that MIDI from your controller will be recorded as-is on a track (as always). However, the MIDI feeding the plugin will be the modified MIDI data generated by the Script. So when you record something, and assuming that your controller transmits on channel 1, your MIDI region will contain only channel 1 information. However, when that data reaches your plugin, notes from C3 - C4 will be on channel 4.

Link to comment
Share on other sites

Thanks Ski! Can't wait to dissect it and try it out. Please ask me if you need any help with the Environment but I somehow doubt that you do. :)

 

However, when that data reaches your plugin, notes from C3 - C4 will be on channel 4.

 

Yep I'm counting on it! IMHO Apple somewhat dropped the ball re Apple Loops. I think I'd prefer to use the Environment for something like this but as I'm sure you know Apple Loops do not save multichannel midi data. All midi gets converted to channel 1.

Link to comment
Share on other sites

  • 2 weeks later...

Not intending to hijack Ski's work and merit, but here is a revamped version of his script allowing the selection of the note range via menus with note names (C3, D4#, etc...) and also allowing the selection of the MIDI channel destination via a slider selector.

 

//=============

/*

This script will redirect a selectable incoming MIDI notes range of

any MIDI channels to another selectable MIDI channel. No other events are affected.

 

Select the targetted note range to have the MIDI channel to be rerouted by selecting the

corresponding notes from the 'Minimum Pitch' and 'Maximum Pitch' menu lists.

Reversing those values does not work.

Select the MIDI Channel destination via the 'To MIDI Channel' selector.

*/

 

function HandleMIDI(e) {

var chan = GetParameter('To MIDI Channel')

 

if (e instanceof Note) {

 

if (e.pitch >= GetParameter('Minimum Pitch') && e.pitch <=GetParameter('Maximum Pitch')) {

e.channel = Math.min(Math.max(parseInt(chan), 1),16);

e.send();

e.trace();

 

}else{

 

e.send();

e.trace();

 

}

}

}

var PluginParameters = [

{name:'Minimum Pitch', type:"menu", unit:" note",

minValue:0,maxValue:127,numberOfSteps:128, defaultValue:60, valueStrings:MIDI._noteNames},

{name:'Maximum Pitch', type:"menu", unit:" note",

minValue:0,maxValue:127,numberOfSteps:128, defaultValue:72, valueStrings:MIDI._noteNames},

{name:'To MIDI Channel', type:'lin',

minValue:1, maxValue:16, numberOfSteps:15, defaultValue:4}

];

//=============

Link to comment
Share on other sites

  • 4 weeks later...
Atlas, I'm curious... why are you using the Math.min(....) thing for? Is that to somehow ensure that the MIDI channel doesn't end up being less than 1 or greater than 16 or something?

I found that sometimes numbers gets screwed up for reasons that I ignore, so I took the habit to use those kind of function() to prevent that... Could be useless but not harmful and potentially "vaccinating" the code...

Link to comment
Share on other sites

  • 5 years later...
This script channelizes only notes between (and including) C3 and C4 to channel 4. The variable "chan" sets the MIDI channel. Everything else -- controls, pitch bend, etc. -- passes through on the original channel feeding into the Script.

 

 

function HandleMIDI(e) {

var chan = 4;

 

if (e instanceof Note) {

 

if (e.pitch >= 60 && e.pitch <=72) {

e.channel = chan;

e.send();

e.trace();

 

}else{

 

e.send();

e.trace();

 

}

 

}else{

e.send();

e.trace();

 

}

}

 

I'm trying to route a range of pitches to a single channel. If I set a narrow range, for example: (e.pitch >= 10 && e.pitch <=15), I can still hear all 128 pitches when I play on any channel. (Each instrument slot in my plugin can be set to either play "all channels", or only one specific channel.)

Link to comment
Share on other sites

Most software instruments operate in omni mode. Which instrument are you trying to use?

 

It's an 8-bit videogame music plugin called Plogue Chipsounds, where one plugin can hold 8 program slots (ie. 8 "instruments"). In normal use each of these 8 instruments should not be set to omni mode. But I'm trying to map my USB drumkit to this software instrument.

Link to comment
Share on other sites

Does each slot have a parameter to set the midi channel it is listening to?

 

Do you have the logicpro midi track set to midi channel ALL (deferring midi channel assignment to scripter ) ??

 

Yes to both. If Logic Pro's midi track channel is set to All, then each instrument (=program slot) has to be set to omni. If Logic Pro's midi track channel is set to a specific channel, then of course it only listens to that channel.

Here is a picture of this plugin's channel settings with "omni" selected: https://www.kvraudio.com/product/chipsounds-by-plogue

Link to comment
Share on other sites

you need to make sure you are NOT using Omni mode in chip sounds. use the multi-timbral screen and specifically assign up to 8 midi channels to use.

 

All incoming signals all recorded to channel 10 which is the default channel for drums. (Apparently this can't be changed from the drumpad itself.) The scripter code has no influence on this. So, I'm trying to decide if I should try to alter the input channel to something other than 10, or if I should be doing something else.

Link to comment
Share on other sites

no, the scripter script is changing the midi channel on notes within a certain range.

 

Yes, that's what it should do. However, after I recorded some drum hits, all incoming notes (in multi-timbral track 1) are in channel 10, even after I tried changing them to some other channel with scripter. For example, with this simple code:

 

 

function HandleMIDI(e) {

var chan = 1;

 

if (e instanceof Note) {

 

if (e.pitch >= 1 && e.pitch <=127) {

e.channel = chan;

e.send();

e.trace();

 

}else{

 

e.send();

e.trace();

 

}

 

}else{

e.send();

e.trace();

 

}

}

Link to comment
Share on other sites

What I'm trying to accomplish is to use sounds generated by my plugin (Chipsounds), instead of drumkit designer, when playing freely on my USB drumpads. For example, so that snare plays channel1, kick plays channel2, and so on. (I also had the problem of the signal being too short to trigger the sound, but I found a work-around to that problem using the Modifier FX.)
Link to comment
Share on other sites

no, the scripter script is changing the midi channel on notes within a certain range.

 

Yes, that's what it should do. However, after I recorded some drum hits, all incoming notes (in multi-timbral track 1) are in channel 10, even after I tried changing them to some other channel with scripter. For example, with this simple code:

 

function HandleMIDI(e) {
   var chan = 1;

   if (e instanceof Note) {

       if (e.pitch >= 1 && e.pitch <= 127) {
           e.channel = chan;
           e.send();
           e.trace();

       }
       else {

           e.send();
           e.trace();

       }

   }
   else {
       e.send();
       e.trace();

   }
}

 

The code you posted above does exactly what its supposed to do on my system, it causes all midi events from pitch 1 to 127 to be sent on midi channel 1.

Link to comment
Share on other sites

The code you posted above does exactly what its supposed to do on my system, it causes all midi events from pitch 1 to 127 to be sent on midi channel 1.

For me, the code does exactly what is supposed to do when I plug the USB to my piano keyboard. However, the USB drumpad seems hard-wired to channel 10.

 

Ps. Not familiar with Drum Machine Designer. Will check it out.

Link to comment
Share on other sites

doesn't matter what your USB drummed is hard-wired to. Scripter intercepts all midi right before it hits the instrument.. unless you have some smart controls in action or something like that doing more then you realize. The Scripter script will absolutely change any midi event to whatever you have in the script.

 

So there is something about your setup you are not aware about or providing information here about now.

 

I would highly recommend you use DMD for this.

Link to comment
Share on other sites

Clearly my midi is not being intercepted by Scripter. Even when creating a non-multitimbral instrument, the channel is always that which the USB instrument tells it is. (I think I made a mistake claiming it was different with piano keyboard. For piano, I can only change the channel from the piano buttons itself. For drums, the channel is always ch10. No smart controls in action.)
Link to comment
Share on other sites

I don't know what to tell you, something is in your system that is not the norm. What I have said is how LogicPro works. Smart Controls and Controller configurations can intercept midi earlier and convert into plugin parameter data. That's the only thing I can think of, but there is no way the midi would somehow bypass scripter to get to the instrument.

 

I recommend you use DMD though... Please start another thread if you want help on how to do that, its not hard.

Link to comment
Share on other sites

Logic will record the MIDI events as it receives them, unless it is altered via the MIDI THRU settings.

If your drumpad emit all its MIDI events on channel 10, all the events will be recorded as channel 10's MIDI events.

The Scripter (and the other MIDI Fx) will convert on the fly those events before they reach the software instrument plugin.

IOW, the MIDI events route is the following:

drumpad (USB drumkit) -> MIDI THRU -> MIDI region -> MIDI Fx (scripter) -> Software instrument (Chipsounds).

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