One Button with Alternating CC Messages

florian

2012-05-20 10:40:50

A user asks this:
i'm trying to work out an elegant way to have a button alternate between two CC with each push (the goal being to have it act as a switch between two clips). To extend on that, i'm also looking for a way to have a button change the CC of another knob (so that a button underneath a physical control could give access to a different virtual control.)

florian

2012-05-20 10:52:31

A) on each button push, send alternating messages
So for the sake of example:
Message sent by controller when you push the button: Note On - 90 20 7F
First message to send out: CC00 - B0 40 7F
Second message to send out: CC01 - B0 41 7F

Approach:
Use a global variable (here I use g0) to store the state. If it's 0 (the default value at start-up), send the first message and set g0 to 1. If it's 1, send second message and revert it to 0.

1st way: Use two distinct translators

Code: Select all

Translator 0: Convert Button to first alternating CC message
INCOMING: MIDI 90 20 7F
RULES:
 g0=1-g0
 if g0!=1 then exit rules, skip outgoing action
OUTGOING: MIDI B0 40 7F

Translator 1: Convert Button to second alternating CC message
INCOMING: MIDI 90 20 7F
RULES:
 if g0!=0 then exit rules, skip outgoing action
OUTGOING: MIDI B0 41 7F
Note the way I flip g0. It's the simplest way :)

2nd way: calculate the message to send in the rules, only use one translator:

Code: Select all

Translator: Convert Button to alternating CC messages
INCOMING: MIDI 90 20 7F
RULES:
 if g0=0 then pp=0x40
 if g0=1 then pp=0x41
 g0=1-g0
OUTGOING: MIDI B0 pp 7F
Note the difference of decimal (normal) numbers and hexadecimal notation: in MIDI messages, MIDI Translator always requires hexadecimal numbers. In the rules, you can enter hexadecimal by prepending "0x" to the number. So "pp=0x40" will set pp to the hexadecimal number 40. However, MIDI Translator will automatically convert rules to decimal, so your rule will eventually say "pp=64". 64 is the decimal representation of hexadecimal 0x40.

Florian

florian

2012-05-20 11:16:29

B) Alternate the controller number of a knob
Again, as an example, I define these messages:
Button press message sent by controller: Note On - 90 30 7F
Knob Controller message sent by controller: CC 0 - B0 00 <value>
First Controller to use: CC20 - B0 14 <value>
First Controller to use: CC46 - B0 2E <value>

Code: Select all

Translator 0: Button alternates
INCOMING: MIDI 90 30 7F
RULES:
g0=1-g0
OUTGOING: <none>

Translator 1: Convert Knob Controller message 1
INCOMING: MIDI B0 00 pp
RULES:
if g0!=0 then exit rules, skip outgoing action
OUTGOING: MIDI B0 14 pp

Translator 2: Convert Knob Controller message 2
INCOMING: MIDI B0 00 pp
RULES:
if g0!=1 then exit rules, skip outgoing action
OUTGOING: MIDI B0 2E pp
Again, you can unify Translator 1 and Translator 2 into one. This is left as an exercise for the reader :)

Hope this is useful!
Florian

mocker

2012-05-20 17:54:05

Great thanks ! You should make it 'sticky'.

Madeon

2012-05-23 04:44:59

Fantastic, much more elegant than my solution ("g0=1-g0" is brilliant.)
If the controller has lighting buttons/pads, associating a MIDI output message directed to the controller to show the status of the button is really helpful (creating two new translators using the g0 variable, one outputting the note start message associated with that button/pad, the other the note end).

DvlsAdvct

2012-05-23 16:00:24

You can actually do this with one translator. In the Outgoing message of Florian's Translator 0 put a timer on a 0ms delay called LED

Code: Select all

Translator 1: LED
Incoming Message: LED Timer
RULES:
if g0==0 then pp=0
if g0==1 then pp=127
OUTGOING: 90 30 pp
I'm guessing the 90 30 is the same message that the LED requires.