A technical support community for Apple Logic Pro users.

 
ninox_rufa
Topic Author
Posts: 143
Joined: Mon Sep 08, 2008 12:33 am
Location: Byron Bay, Australia

Use Scripter to change midi note channel

Sat Oct 04, 2014 9:29 pm

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?
Logic 10.2.0, 10.2.1 | OS 10.9.5 | 2012 MBP 2.3GHz i7 16GB | MOTU Ultralite mk3
 
ninox_rufa
Topic Author
Posts: 143
Joined: Mon Sep 08, 2008 12:33 am
Location: Byron Bay, Australia

Re: Use Scripter to change midi note channel

Tue Oct 07, 2014 2:20 pm

Bump. :)
Logic 10.2.0, 10.2.1 | OS 10.9.5 | 2012 MBP 2.3GHz i7 16GB | MOTU Ultralite mk3
 
User avatar
David Nahmani
Site Admin
Posts: 84011
Joined: Sat Mar 05, 2005 12:16 am
Contact:

Re: Use Scripter to change midi note channel

Tue Oct 07, 2014 3:20 pm

ninox_rufa wrote:
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.
David Nahmani
• My Logic Pro X 10.5 book (Apple Pro Training Series)
Contact me for Private Lessons
Logic Pro X 10.6.1
MacBook Air 1.3 GHz i5 — MacOS X 11.0.1 — 4 GB RAM
iMac 3.2 GHz Quad Core i5 — MacOS X 10.15.4 — 8 GB RAM
 
User avatar
ski
Site Contributor
Posts: 16605
Joined: Thu Dec 15, 2005 5:12 pm
Location: Los Angeles

Re: Use Scripter to change midi note channel

Tue Oct 07, 2014 3:52 pm

That's not quite right. I'll post back later with something.
 
User avatar
ski
Site Contributor
Posts: 16605
Joined: Thu Dec 15, 2005 5:12 pm
Location: Los Angeles

Re: Use Scripter to change midi note channel

Tue Oct 07, 2014 4:03 pm

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();

}
}
Last edited by ski on Tue Oct 07, 2014 4:05 pm, edited 1 time in total.
 
User avatar
ski
Site Contributor
Posts: 16605
Joined: Thu Dec 15, 2005 5:12 pm
Location: Los Angeles

Re: Use Scripter to change midi note channel

Tue Oct 07, 2014 4:04 pm

BTW, the "e.trace()" items are used to show the MIDI data in the Scripter's "console" and as such are entirely optional. However, the "e.send()" items are required to send data out of the Scripter.
 
User avatar
ski
Site Contributor
Posts: 16605
Joined: Thu Dec 15, 2005 5:12 pm
Location: Los Angeles

Re: Use Scripter to change midi note channel

Tue Oct 07, 2014 4:08 pm

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.
 
ninox_rufa
Topic Author
Posts: 143
Joined: Mon Sep 08, 2008 12:33 am
Location: Byron Bay, Australia

Re: Use Scripter to change midi note channel

Tue Oct 07, 2014 4:33 pm

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

ski wrote:
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.
Logic 10.2.0, 10.2.1 | OS 10.9.5 | 2012 MBP 2.3GHz i7 16GB | MOTU Ultralite mk3
 
User avatar
ski
Site Contributor
Posts: 16605
Joined: Thu Dec 15, 2005 5:12 pm
Location: Los Angeles

Re: Use Scripter to change midi note channel

Wed Oct 08, 2014 11:08 pm

You're welcome ninox! Thanks for your offer for help with the environment. Who knows, maybe one day I'll take you up on that! 8)

Lemme know if you need any clarification on how that script works.
 
User avatar
Atlas007
Posts: 9516
Joined: Mon Dec 14, 2009 11:58 pm
Location: Montreal

Re: Use Scripter to change midi note channel

Thu Oct 23, 2014 10:56 pm

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}
];
//=============
LogicPro 10.6.1 ( & 9.1.8),MainStage3.5.1
MBPro 17", Core2Duo, 8G, OSX 10.12.6
MacPro, Xeon 6Cores, 64GB, OSX 10.15.7
ULN8, MOTU MIDI TP-AV, C4, MCU Pro, KorgNano, Novation SLMkII
AAS, NI, Celemony, Spectrasonics, Korg, etc...
PC, iPad3(V-Control & LogicRemote), AtariST(Notator SL), Several vintage gear
 
User avatar
ski
Site Contributor
Posts: 16605
Joined: Thu Dec 15, 2005 5:12 pm
Location: Los Angeles

Re: Use Scripter to change midi note channel

Fri Nov 21, 2014 6:10 pm

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?
 
User avatar
Atlas007
Posts: 9516
Joined: Mon Dec 14, 2009 11:58 pm
Location: Montreal

Re: Use Scripter to change midi note channel

Mon Nov 24, 2014 9:47 pm

ski wrote:
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...
LogicPro 10.6.1 ( & 9.1.8),MainStage3.5.1
MBPro 17", Core2Duo, 8G, OSX 10.12.6
MacPro, Xeon 6Cores, 64GB, OSX 10.15.7
ULN8, MOTU MIDI TP-AV, C4, MCU Pro, KorgNano, Novation SLMkII
AAS, NI, Celemony, Spectrasonics, Korg, etc...
PC, iPad3(V-Control & LogicRemote), AtariST(Notator SL), Several vintage gear
 
User avatar
ski
Site Contributor
Posts: 16605
Joined: Thu Dec 15, 2005 5:12 pm
Location: Los Angeles

Re: Use Scripter to change midi note channel

Mon Nov 24, 2014 11:08 pm

Thanks Atlas. I totally hear you about writing "safety code". :D FWIW, though, in this case it's unlikely the channel will get messed up because you're reading it directly from the data itself: e.channel

Best Regards,

Ski
 
Palimpsest9
Posts: 86
Joined: Mon Apr 29, 2019 9:26 am

Re: Use Scripter to change midi note channel

Sun Aug 16, 2020 10:10 am

ski wrote:
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.)
 
User avatar
Dewdman42
Posts: 3184
Joined: Tue Sep 09, 2014 3:01 pm
Location: Salt Lake City, UT

Re: Use Scripter to change midi note channel

Sun Aug 16, 2020 10:19 am

Most software instruments operate in omni mode. Which instrument are you trying to use?
OSX 10.15 (Catalina) on OpenCore - Logic Pro 10.6.2, VePro7, Mainstage3
5,1 MacPro 3.46ghz x 12 128gb ram
 
Palimpsest9
Posts: 86
Joined: Mon Apr 29, 2019 9:26 am

Re: Use Scripter to change midi note channel

Sun Aug 16, 2020 11:46 am

Dewdman42 wrote:
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.
 
User avatar
Dewdman42
Posts: 3184
Joined: Tue Sep 09, 2014 3:01 pm
Location: Salt Lake City, UT

Re: Use Scripter to change midi note channel

Sun Aug 16, 2020 11:55 am

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 ) ??
OSX 10.15 (Catalina) on OpenCore - Logic Pro 10.6.2, VePro7, Mainstage3
5,1 MacPro 3.46ghz x 12 128gb ram
 
Palimpsest9
Posts: 86
Joined: Mon Apr 29, 2019 9:26 am

Re: Use Scripter to change midi note channel

Sun Aug 16, 2020 12:23 pm

Dewdman42 wrote:
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
 
User avatar
Dewdman42
Posts: 3184
Joined: Tue Sep 09, 2014 3:01 pm
Location: Salt Lake City, UT

Re: Use Scripter to change midi note channel

Sun Aug 16, 2020 12:43 pm

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.
OSX 10.15 (Catalina) on OpenCore - Logic Pro 10.6.2, VePro7, Mainstage3
5,1 MacPro 3.46ghz x 12 128gb ram
 
Palimpsest9
Posts: 86
Joined: Mon Apr 29, 2019 9:26 am

Re: Use Scripter to change midi note channel

Sun Aug 16, 2020 1:35 pm

Dewdman42 wrote:
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.