Okay, before we dive into that script. I'm seeing something unexpected, or at least different than how MOS worked. Second, I notice an unintended change to the binding editor. When scripts do not use #focused, it won't show a Send To field to select the script target. It should, so let's assume that you can still do that.
Let me start by describing some of the concepts used in complicated scripts like this.
First, I think we need a new word. The target track.
A target track exists only within a script. When a script is run it is given a target track. What this is will depend on the binding used to run the script.
By default, the script's target track will be whatever track is currently selected, the one with the white box around it.
If the Send To field in the binding is a specific track, say Track 4, then the target track for the script will be track 4 no matter which track is currently selected in the UI.
If the Send To is Focused...it's more complicated I'll get to that later. Just understand that whenever a script runs, it has a target track, and that will be determined by the binding and passed in. You do not need to do anything special to read from or send things to the target track. If you do this:
if quantize == :off
It reads the value of the quantize parameter from the target track.
If you do this:
quantize = :off
It changes the value of quantize in the target track.
And if you do this:
Mute
It sends the Mute action to the target track. Remember, the target track does not have to be the selected track in the UI. It might be, but it will depend on where the binding told it to go.
Somewhere in the script, you may wish to read from or send things to a different track than the target track. Do to that use in.
// when the script starts the target track is the selected track
print("I'm starting in" trackNumber)
in 2 {
// inside an in block, the target changes to the number after the in
print("I'm now in track" trackNumber);
}
// after the in block finishes, the target track goes back to where it was
// when the script started
print ("I'm back in" trackNumber)
This is important. in does not permanently change the target track. The target track only changes for the things inside the in block, the statements between the {} braces. Once you leave an in block, you are back to the same target track the script had when it was started.
Now, do this:
SelectTrack(5)
This will change the selected track in the UI. The white box will move, assuming 5 wasn't already selected.
The important thing here is this does not change the script target track. It just moves the white box. Things outside the script will start using that as the new selected track, but inside the script, it still has the same target it was started with, the one from the binding.
So if you did this:
// assume this starts with a target track of 4
// this will Mute track 4
Mute
// this will select track 5 in the UI
SelectTrack(5)
// this will NOT mute track 5, it will unmute track 4
Mute
If you wanted to mute track 4 (the target) and then also track 5, you would do this:
Mute // mutes the target
in 5 Mute // mutes track 5
If all you're trying to do is make things happen in specific tracks, there is usually no reason to use SelectTrack in a script. Just use in. SelectTrack looks like it does something it doesn't.
I think this is not the way MOS worked. And I'm not convinced it should. SelectTrack is really just a UI function, if the binding said the target track for this script should be 4 then it should stay 4. If this script were #focused it would absolutely stay 4.
I'll get to what this all means when you use #focused in a script next.