Order of preset and translator processing

kanthos

2010-05-11 21:04:29

Say I have the following setup:

Preset 1 (always active)
Translator 1 - On any program change, activate preset 4
Translator 2 - On program change 1, activate preset 2
Translator 3 - On program change 2, activate preset 3
Preset 2
Set a few specific global variables to 1
Activate preset 5
Preset 3
Set a few specific global variables to 1 (different set from those set in preset 2, probably)
Activate preset 6
Preset 4
Set all the global variables I use to 0
Preset 5
Convert some MIDI event into some other MIDI event
Preset 6
Convert some MIDI event into some other MIDI event
Preset 7 (always active)
If global variables are set to 1, convert some MIDI events into other MIDI events


In the example, Preset 1 is a master setlist for the performance I'm doing, Presets 2 and 3 are presets for specific songs on the setlist, Preset 4 sets global variables to 0, presets 5 and 6 are pretty straight ahead translators, and preset 7 uses the global variables to determine if events should be translated or not.

My idea is that I want to set all global variables to 0 when I get a program change, and then let a song-specific preset set a few of those back to 1. I want to zero my global variables in a separate preset so that my main setlist isn't cluttered with a bunch of translators for zeroing variables, and I don't want them in my song presets either (I'd obviously only set some to 0 and others to 1 this way, depending on what the song called for) because then my song presets get cluttered.

I know that all the translators in a preset are run in order, but what order are the presets run in? Let's say that I send a program change that will activate Song 1. Preset 1 will be run first, and presets 2 and 4 will be activated by Preset 1's translators. What happens next? Does Preset 4 run first, since it was activated first, or does Preset 2 run first because when Preset 1 finishes running its translators, both Presets 2 and 4 have been activated and Preset 2 is higher up the list than Preset 4? Obviously, I need preset 4 to run before preset 2.

Is it also guaranteed that each preset runs all its translators before any other preset can run, regardless of who activates it? Or is it possible that there might be some interleaving (i.e. some of the rules from preset 2 run, then some of the rules from preset 4, then some more from preset 2, then more from preset 4, etc.)

kanthos

2010-05-13 16:10:07

I wrote a fairly involved test and looked at the log window to see exactly what was happening, and see the following results.

1) Translators within a preset are always run in order (everyone already knew this one)

2) When a translator action in preset A activates preset B, preset B is not immediately activated. It is added to the end of a list of presets waiting to be activated. The remaining translators in preset A are run first. If any of the other translators also activate presets, say preset C, preset C is added to the end of the list.

3) When all translators in the current preset have run, Bome's looks at the list of presets to activate. The first preset is chosen and activated, and all its translators are run. As in point 2, any presets needing to be activated are added to the end of the list.

4) Repeat step 3 until the list of presets to activate is empty, and all translators running on preset activation have finished.




To make it clear, in my example in the previous post, the following would happen on a program change of 1:

Preset 1, Translator 1 runs, adding Preset 4 to the list (list is Preset 4)
Preset 1, Translator 2 runs, adding Preset 2 to the list (list is Preset 4, Preset 2)
All the translators in Preset 4 run (none of them activates a new preset) - (list is Preset 2)
Some global variables are set in Preset 2 (list is empty)
The translator to activate preset 5 is run. Since there are no other translators needing to run in Preset 2, Preset 5 gets activated next
Preset 5 has no 'on activation' translators, just some 'With incoming MIDI' translators, so it does nothing for now

Preset 3 is never activated in this sequence, preset 6 isn't activated since it's only activated from preset 3, and preset 7 is always on, so nothing changes with it.



For anyone who understands a bit of basic computer science or math, Bome's is doing a breadth-first search on preset activation.