Anyone fancy explaining what variables are?

lanz_the_joiner

2015-08-12 14:18:27

I've been using Bome's for a few days and I'm having a great time, both in the learning process and in my results. I have achieved a couple of things on my setup (Xone K2 + Traktor) that I'm very happy with - I can toggle an LED between two colours as an effect switches 'on' and 'off' in Traktor, and I can program an LED to change colour as I increase or decrease a value (eg. volume) more smoothly than it can be done in Traktor alone.

However, I've started running into some problems as I've been trying to 'consolidate' the three rule-less translators involved in my 'volume' Green/Orange/Red LED display into one translator with some rules. LED's have been changing to colours that I did not intend.

I was thinking that this could be because I don't understand variables. Local variables "lose their value as soon as the translator finishes" whereas global variables don't do that. Problem is, I don't actually know what any of this means.

Would anyone care to explain the difference between local and global variables in terms I might understand - that is, perhaps with some examples involving features of Traktor (or any music player) + MIDI controller + LED lamps? At the moment it is purely abstract theory to me, that I feel I can't grasp, I can't conceptualize it.

I would appreciate any help.
:D

DvlsAdvct

2015-08-12 20:59:02

Hi lanz_the_joiner

Local and global variables can be confusing, and we are working on better ways to explain them. Let's give this a shot.

When a MIDI message is received by MIDI Translator, it checks to see if it aligns with a translator. This is made up of three bits of data:
  • the Message Type and Channel: 90 would be Note On Channel 1
    The message value: 30 would be middle C
    And the position or velocity: 7F would be 127, or full on
So the message 90 30 7F would be Note On Channel 1, Middle C at full velovity. Now that is an easy translator for a button, right? Because buttons are always on or off. 7F for on, 0 for off. When the button is velocity sensitive, however, you may want to have it trigger no matter how hard you push it. If the translator only goes off when the velocity is 7F, however, then it will only go off when you hit it hard enough. If you want it to trigger no matter what, you'd want to replace the 7F with a variable.

You have two options: local and global. If you select a local variable, say pp, then your incoming message would be 90 30 pp. And now that incoming message will start processing once the button is pressed, no matter how hard. Once MT Pro processes through the rules and triggers the outgoing message (or not, depending on your rules) then MT Pro does not remember or store how hard you hit that button. It would also, however, trigger when you release the button, since 90 30 pp would trigger when the velocity is 0, so the translator would fire off when it's pressed and released. We don't want that. We only want it to trigger when pressed. So, we want to put a rule in that says

Code: Select all

if pp==0 then exit rules, skip outgoing action
This would mean that whenever we release the button, the translator does not finish processing to the outgoing action. But the translator only cares about the value of pp when the incoming message is received. At no point in the future do you need to know the state of the button, right? You only need to know it is being pressed or released WHEN you are trying to fire off the translator. It would look something like:

Code: Select all

Translator 1: Play
Incoming Message: 90 30 pp
Rules: if pp==0 then exit rules, skip outgoing action
Outgoing Message: 90 30 7F
So every time we press the button it sends at full velocity.

Let's expand this. Say we want the button to still send an off message, but we only want it to send 7F and 00, nothing in between. So we'd want it to look something like:

Code: Select all

Translator 1: Play
Incoming Message: 90 30 pp
Rules: if pp>0 then pp=127
Outgoing Message: 90 30 pp
Now, if we press the button and the velocity is greater than 0, it will always be 127, or 7F. If we release the button and the velocity is 0, then the velocity of the message will be 0, same as intended. (hope you're still with me here) But keep in mind that at no time are we able to reference its position because we are only using a local variable.

Now let's say we want our button to have two functions. When we press it it's Play, but when we are holding a Shift button, it's Cue. We would need to use a global variable for this, because our Play button needs to act differently based on the state of a second button. So we would need our shift button to look like

Code: Select all

Translator 2: Shift
Incoming Message: 90 31 pp
Rules: g0=pp
Outgoing Message: none
So what happens? When we press our second button (90 31 pp) we increase the value of the global variable g0. And now we can add a rule in our first translator that is always listening for the value of g0, to decide whether or not to continue processing its rules.

Code: Select all

Translator 1: Play
Incoming Message: 90 30 pp
Rules: if g0!=0 then exit rules, skip outgoing action
if pp>0 then pp=127
Outgoing Message: 90 30 pp
If g0 does not equal 0, so the Shift button is pressed, the translator will not finish processing the rules OR make it to the outgoing action. And we can create a new translator for Cue

Code: Select all

Translator 3: Cue
Incoming Message: 90 30 pp
Rules: if g0==0 then exit rules, skip outgoing action\
if pp>0 then pp=127
Outgoing Message: 90 35 pp
So both translators 1 and 3 are listening for the current state of a DIFFERENT button, based on the global variable. Local variables will only be able to store during the processing OF the translator, and once either A) the outgoing action is triggers OR B) the rules cancel the outgoing action then the local variable is not referenced anymore.

Does that make sense?
Jared

lanz_the_joiner

2015-08-13 13:52:45

That's awesome. I feel that I understand everything you've written, and that it gives me a foundation on which to base most of the ideas I'd like to carry out.

Thanks a lot!