I wrote this script because I needed a 3 way selector switch, then wondered how it would scale if I wanted more positions. So this script is salable to any number of positions (although I think 10 or so would be quite enough ).
The light were just for my testing (it was a pain to keep switching back to the plugin view to see if it worked).
Code:-
Var
Switch1 : Widget
//All Plugins in switch need to be declared here
Plugin1 : PluginBlock
Plugin2 : PluginBlock
Plugin3 : PluginBlock
Plugin4 : PluginBlock
Plugin5 : PluginBlock
Plugin6 : PluginBlock
Plugin7 : PluginBlock
// Global flags
Switch1Snaped : Boolean
// We'll actually keep these in an array and just index them
// That will allow us to use some functions that will work for all widgets
position : PluginBlock Array // Dynamic array
is_active : Boolean Array // Dynamic array
no_plugins : integer
j : integer
Initialization
// The other 2 lines that need to be set for Switch
no_plugins = 7 //Set Number of Plugins
position = [Plugin1, Plugin2, Plugin3, Plugin4, Plugin5, Plugin6, Plugin7]; // Add all names of plugins here
// ***** Nothing more needs to be changed *****
// Global flags initialization
Switch1Snaped = False;
for j = 0; j < no_plugins; j = j + 1 do
is_active[j] = True
end
End
// The array here indicates the value to which each Plugin should be set
Function UpdateAllplugins (vs : Boolean Array)
var i : integer
for i = 0; i < no_plugins; i = i + 1 do
SetPluginBypassed(position[i], vs[i])
is_active[i] = vs[i] == False
end
end
// Called when widget value has changed to do the actual work
Function Process(widgetIndex : Integer)
var vs : Boolean array
i : integer
for i = 0; i < no_plugins; i = i + 1 do
vs[i] = True
end
if is_active[widgetIndex]
then
vs[widgetIndex] = True // This is the one we need to deactivate
UpdateAllplugins (vs)
else
if not is_active[widgetIndex]
then
vs[widgetIndex] = False // This is the one we need to activate
UpdateAllplugins (vs)
end
end
End
// Convert Step Dent Position to slider value
Function Switchposition(widgetValue : Double) returns Double
var
stepValue : Integer
stepValue = Round(widgetValue * (no_plugins-1));
result = Scale(stepValue,0, (no_plugins-1), 0, 1);
End
// So make one of these for each MidiIn block you want to control
On WidgetValueChanged(newValue : double) from Switch1
var pos : Double
pos = Switchposition(newValue)
If Switch1Snaped
Then
Switch1Snaped = False;
Else
Switch1.SetWidgetValue(pos);
Switch1Snaped = True;
If IsPluginBypassed( position[Round(newValue*(no_plugins-1))]) //Sort Debounce Issue
then
Process(Round(newValue*(no_plugins-1)))
end
End
End
And a Gig file to show it:-
7 pos Switch.gig (35.5 KB)