What if local variable is undefined but used in outgoing?

gabriels

2009-10-11 04:38:27

I think I found and solved a problem in the MT code I'm writing but don't understand what's happening.
To isolate the problem, I disabled all translators except the problem translator.
I use qq as a local variable in this translator. In one branch of the code I set qq to a specific value. I also set ga to a specific value. Then I exit and execute outgoing qq ga 7F. This works as intended and the outgoing is BD ga 7F.
However if I branch differently through my code, I don't set the value of qq. I still execute the outgoing. Not so good now! The outgoing is DC ga 7F.
What I don't understand is where the value DC comes from. I don't set qq to 220 (hex equivalent of DC) anywhere in my code. Where could DC be coming from?
I've fixed the problem by always setting qq when I intend to use it in the outgoing, but wonder what's going on "under the hood" of MT.
Gabriel
Gabriel

Attigo

2009-11-17 05:56:17

Hi Gabriel,

I'm not sure I understand why your translator is doing this, I personally have never experienced this in the time I have been using MT.

Can you email me your preset and I will have a look at it, try figure out the problem...

scott.attigo(at)gmail.com

cheers,
Scott Hobbs

florian

2009-11-17 09:55:28

Hi Gabriels,

a note from "under the hood": the scope of a local variable is an incoming event. So when you process one incoming MIDI message, the MIDI message has the local variables attached to it. the incoming event is passed through all translators in your presets. Some may alter the value of, say, pp. But the next time your preset is processing an incoming MIDI event, all local variables are reset to some undefined value.

Why we need local variables is this:
it is possible that MT's engine processes two events at the same time, e.g. two MIDI events from different MIDI devices. Now if you do calculations on the local variables, they cannot interfere with each other, because there you have two sets of local variables (one for each incoming event). Global variables only exist once during the "life" of your project. They are guaranteed to be 0 when you start your project. Local variables are not guaranteed to have any particular initial value.

Rule of thumb:
- never use a local variable without initializing it first in the same translator
- use local variables where possible (i.e. for values that you only need within one translator)

Hope that explains a little....

Thanks,
Florian