The XOR operator truth table is below
So essential if the 2 incoming bits are the same you get an output of 1
If the incoming bits are different you get an output of 0
If 1 of the incoming bits is 1 and the other is the current bit state, the new bit state will toggle.
Example. Say the global variable g0=0
If you do
then ga will be 1
if you do it again
then ga will be 0
The net effect is you are toggling the value of ga between 0 and 1
Keep in mind that global variables are 32 bit integers so in binary you are really toggling
only the first bit of 32 bits
Binary representation below
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0001
So it is important that you start out with ga=0 otherwise you will get a different result
If you start out with ga being 2
0000 0000 0000 0000 0000 0000 0000 0010
then ga=ga^1 will product
0000 0000 0000 0000 0000 0000 0000 0011
or 3 decimal so you will be toggling between 2 and 3 instead of 0 and 1.
Why do you do this?
Say the button you are pushing is momentary and you want toggle behaviour
In momentary behavior when you push the button it will generally send Note On Note xx with velocity qq (where qq is typically a value of 127)
When you release the button it sends Note Off Note xx with velocity of qq (where qq can be anything but it is typically either 0 or 127).
In toggle behavior you want to push the button once for on and again for off and so on.
So the translator will be written as follows:
Incoming Note-On note xx any velocity
// Note that when you start an MT project all global variables default to 0
// Toggle ga
// Set default output value
// change it to 127
if ga==1 then qq=127
Outgoing Note-On note xx velocity qq
In most cases MIDI Note-on with velocity 0 also represents note-off
Now to send this to your application and to back to your controller, you can specify in the translator, or it’s parent preset where to receive input and send output.
For information on how to route to MIID devices you can review this tutorial.
Each button will need a different global variable so as not to interfere with other buttons.
However if you understand bitmapping you could use a single global variable and only toggle a given bit and control up to 32 button on/off states with a single global variable. I posted an example file that does just this using the APC-MINI. Just search for APC MINI and bitmap and if you can’t find it let me know. It is quite an advance project though so unless you are running short on global variables (there are 360 global variables available in MT Pro) it is probably simpler to use one global variable for each button than to go through a bitmapping exercise.
Bome Customer Care
Also available for paid consulting services: email@example.com