General

Change CC number via scirpt?

Started by cliffman on .

Sign in or create an account to join the conversation.

15 posts

AFAIK you can't change directly the midi settings but you can send the CC yourself in an On Expression script.

Select your fader, add a script, give the function some smart name (like OnChangeX)

Select On Expression from the list and type x in the following single line text box

Then below in the code text area, enter this:

ctlout(0,myCC,x*127,1); // 0 is the port, myCC the CC you want to send, x*127 if you want values between 0 and 127 and 1 is the channel

myCC can be a variable that you set using a menu or another fader or whatever actually.

If you want feedback you'll have to handle it as well.
When you handle the midi out yourself you can can do anything you want, using a different port, message type , channel.

if you have 4 faders , one for the port, one to select a cc, one to select a channel and the 4th one to output the midi then you would have

ctlout(fPort.x*7, fCC.x*127, x*127, fChan.x*15+1);

Changing channel may be tricky in some situations, like sending notes were you have to send the note off to the correct channel, or you may want to reset a pitch wheel before switching channel, ....
Hopefully this is still on topic here. It would be handy if there was an event triggered right before midi is sent out. Just like onMidi but would be called onMidiOut or something.

A useful example would be a drum pad. This is completely pseudo code but hopefully gets the point across:

OnMidiOut(midi_args) :
If(useChannel2) {
midi_args.channel =2;
}
MidiOut(midi_args);

Thoughts?
Why not but that would create a problem with midi feedback, so this should probably be a port option for the control and if this special midi out is used then it's a special midi in function that should handle feedback.
Hey,
there is also another way than "ctlout"...maybe less cryptic.

Create Custom MIDI
- click on that Midisymbol at the bottom of the right side (beneath Interface, variable etc...)
- make sure the object targets fit to your defined Midi targets on your Lemur.
- select as message "B0 - Control Change"
- select as value your Fader ("Fader.x"), triggered by "any".
- for controller or midichannel you can fill in anything, e.g. another object, variable or script or type in directly.

Example - Menu for choosing Midichannel: create menu with 16 options, numbered 1-16, fill in "LemurMenu.selection+1" in Custom Midis "channel"...
For Controller I would suggest 2 menus, combined as "(menu1*10)+menu2" .....11*10+3=113
That way you can easily control channel and controllernumber of an output.

There is one problem with this (but same with ctlout): Midifeedback does not work this way. Bidirectional midi only works for direct routing.

Hope that helps
Enjoy

mat
Hey that's cool, at some point I was wondering what this custom MIDI was for but then forgot about it.

That's an elegant way to handle it and easier than scripting.

Feedback is not always needed but in case, you just need an array that keeps track of the individual CC number * channel used for each control, and refresh the control(s) on CC and/or channel change, and update the array on incoming MIDI.
mbncp wrote:
Feedback is not always needed but in case, you just need an array that keeps track of the individual CC number * channel used for each control, and refresh the control(s) on CC and/or channel change, and update the array on incoming MIDI.
Can you explain that a bit more with an eample?
kraftf wrote:
mbncp wrote:
Feedback is not always needed but in case, you just need an array that keeps track of the individual CC number * channel used for each control, and refresh the control(s) on CC and/or channel change, and update the array on incoming MIDI.
Can you explain that a bit more with an eample?
If we use more than one cc and/or channel for a single fader then we need to store these values so when we switch cc/channel we can reflect their actual values.
Also in case these values are changed on feedback we need to store them as well.

For this we need a variable that stores the value for each cc/channel pair.
Then an on expression script to store the changes we make in lemur
and an On Midi script to store the values on feedback change.
Then we need another on expression function for the control that makes the cc channel selection, so we can update our fader.

If we have only different cc's or channels then we need a simple array:
example using 4 ccs, we create a variable:
myFaderValues = {0,0,0,0}
We access the correct item with something like that:
index = currentCC - lowestCC;
myFaderValues[index] = value;

In case we use different cc and channels, example 4 CC and 2 channels our variable would be like this
myFaderValues = { {0,0,0,0} , {0,0,0,0} }
in this case we access the correct value this way:
index = (currentChannel - lowestChannel - 1) * (currentCC - lowestCC);
myFaderValues[index] = value;

Then all we need to do is to get or set values from that array in the different script and update the fader when needed (external midi in or cc/channel change).

On request I could make a real example when I'm back to my machine.
mbncp wrote:
kraftf wrote:
mbncp wrote:
Feedback is not always needed but in case, you just need an array that keeps track of the individual CC number * channel used for each control, and refresh the control(s) on CC and/or channel change, and update the array on incoming MIDI.
Can you explain that a bit more with an eample?
If we use more than one cc and/or channel for a single fader then we need to store these values so when we switch cc/channel we can reflect their actual values.
Also in case these values are changed on feedback we need to store them as well.

For this we need a variable that stores the value for each cc/channel pair.
Then an on expression script to store the changes we make in lemur
and an On Midi script to store the values on feedback change.
Then we need another on expression function for the control that makes the cc channel selection, so we can update our fader.

If we have only different cc's or channels then we need a simple array:
example using 4 ccs, we create a variable:
myFaderValues = {0,0,0,0}
We access the correct item with something like that:
index = currentCC - lowestCC;
myFaderValues[index] = value;

In case we use different cc and channels, example 4 CC and 2 channels our variable would be like this
myFaderValues = { {0,0,0,0} , {0,0,0,0} }
in this case we access the correct value this way:
index = (currentChannel - lowestChannel - 1) * (currentCC - lowestCC);
myFaderValues[index] = value;

Then all we need to do is to get or set values from that array in the different script and update the fader when needed (external midi in or cc/channel change).

On request I could make a real example when I'm back to my machine.
Yes that's exactly what I; trying to do but I can't make it yet.
I have a multislider that sends 8 different CCs in one channel with a custom midi message.
I've created an array called midiwatch={0,0,0,0,0,0,0,0}.
Now I've made a script called trackCC to respond to On Midi. In the arguments I select control numbers 8 to 15 on channel 1.

And now what?????I I don't know how to handle the incoming midi CCs. How sould I reference the cc value, the midi channel?????There is no documentation about it.
God the manual is incomlete for a newcomer.
So to get back to my problem:
I've put inside the script this code

midiwatch[x]=x;
Is the x valid?
Does x mean the incoming array from midi ?
How would you define currectCC and lowest CC?From midi_Args?
Please enlighten me. There is nothing inside the manual how to track incoming midi,
I just made a script that makes it pretty easy to use multiple object that can use multiple cc with feedback, but all object must share the same amount of CCs.
Let's say you have controls for volume, pan, mute, solo, ... but only one of them. With this script you can access any number of tracks (or whatever) with these single objects.

I'm done but I need to do some testing first and it's getting late ... Posting soon.
multiCC.jzml.zip
So this project let's you use multiple object that can deal with different cc. There is a switch in radio mode that selects the cc index.
When adding, removing object make sure to update the TODO section found in the OnLoad script of the multiCC object.
To add a control, you can just alt+drag/drop an existing one and update the array.
If you create a new control make sure to add a call and index variable (expression) and an OnChange script with execution set to On Expression x with this single line of code:
setexpression(call, 'Trigger', {index, x});

Note that I haven't used custom midi, as scripting is already involved it's easier this way.
You could use a menu or whatever to switch the cc index, make sure that this control sends the new index to the multiCC object:
multiCC.OnIndexChange(somevalue);

You can have multiple multiCC objects in a project, just make sure to update me = in the todo section
me = multiCC2;
And avoid using the same objects, cc-channels combo or you''ll go into troubles ;)

Btw, if you click on the multiCC object (a pad actually), this just calls OnLoad and all variable are initialized. I noticed that sometime this is needed as the OnLoad function doesn't get always called.