I have a controller (Behringer X-Touch Mini) that can receive MIDI messages to set encoder values and lights. I tried to initialize these in the If load block, but it seems that the messages are never sent. They're displayed in the StreamByter monitor, but never reach the controller. I tried delaying the messages and using Set Flush, all ineffective. Finally, I realized that the trick is to put this initialization after the end of If load, as the first item in the main part of the program, controlled by
If T0 == 0 # put controller initialization here End
As the manual states, T0 is only zero the first time after restoring a scene. If prior data was initialized with +P, so values are saved in the scene, they will be restored, and can be used to reset the controller to its prior state. Now, this won't work until a MIDI message is received, so you need some controller action to trigger it. I use an innocuous button press. Now, finally, the controller state immediately matches the restored state in the script.
You can see that T0 works like a traditional "first time" flag, since it's only zero once. I kinda hate having the extra test in there for every message, but this is only a controller, not a keyboard, so performance is not critical.
The script is configured in Audiobus 3 to receive input from the controller and send output both to the app and back to the controller. They are on separate MIDI channels, so this does not confuse them.
Hi nic, Thanks for the advice. I tried +D500, figuring that was plenty. I'll try +D5000, to see if it helps. I thought maybe that the host needed an input message to trigger collection of the output messages.
I tried this, using Send in If Load, with +D5000 and even +D10000, and nothing is sent when restoring a preset in Audiobus, or a session in AUM. Could this be another change in iOS 14 MIDI? (I'm on iPadOS 14.4 on iPad 6.) However, the trick of testing T0==0 lets me send the init messages on the first input from the controller.
However, it turns out I was wrong overall. When you first start Audiobus and load a preset including SB, T0 is zero initially, and this works. But if you then load another preset, I guess SB is already running, so T0 is not zero anymore. But a conventional first-time flag does work. Initialize to 1 in the load section, test and clear it on the first event, and use that to trigger hardware initialization messages.