For my own education in GP scripting, I started to write a script for implementing “presets” radio-button for changing from current to another Rackspace/Variation. The idea is to add a panel of buttons and a script to a set of rackspaces. This is how it looks :
My script works fine until I activate the “SwitchToProgramNumber” option. I have a “doSwitching” Boolean variable for this purpose in the Initialisation section of my script. When “SwitchToProgramNumber” is activated the script starts to live from its own will I added a set of deguging “Print” for better understanding what happens, but I still don’t.
Could someone clarify this behaviour to me ?
Here is the script :
// Tell GP Script the names of our widgets and FLAGS
var
MIDIin : MidiInBlock;
Button1, Button2 : Widget
Button1_pushed : Boolean
Button2_pushed : Boolean
doSwitching : Boolean
// LedButton : Widget Array
// Label : Widget Array
// Button3,Button4,Button5,Button6,Button7,Button8 :Widget
// Label1,Label2,Label3,Label4,Label5,Label6,Label7,Label8:Widget
initialization
// OpenLogWindow(); // For convenience
Print("=== INITIALIZATION ''" + GetRackspaceName() + "'' called ===");
Print(" ");
// Problems occur when switching is activated :-(
doSwitching = True; // Do Rackspace/Variation switching
// doSwitching = False;// Prevent Rackspace/Variation switching
Button1_pushed = False;
Button2_pushed = False;
//LedButton = [Button1,Button2,Button3,Button4,Button5,Button6,Button7,Button8]
//Label = [Label1,Label2,Label3,Label4,Label5,Label6,Label7,Label8]
End
// Called when rackspace is activated
On Activate
Print("=== ACTIVATE ''" + GetRackspaceName() + "'' called ===");
Print(" ");
// Release all buttons
Button1_pushed = False;
Button2_pushed = False;
SetWidgetValue(Button1, 0.0);
SetWidgetValue(Button2, 0.0);
End
// Called when you switch away from a rackspace
On Deactivate
Print("=== DEACTIVATE ''" + GetRackspaceName() + "'' called ===");
Print(" ");
// Release all buttons
Button1_pushed = False;
Button2_pushed = False;
SetWidgetValue(Button1, 0.0);
SetWidgetValue(Button2, 0.0);
End
// Called when you switch variations
On Variation(oldVariation : integer, newVariation : integer)
Print("@@@ VARIATION ''" + GetVariationName(GetCurrentVariation()) + "'' called @@@ (in ''" + GetRackspaceName() + "'')");
Print(" ");
// Release all buttons
Button1_pushed = False;
Button2_pushed = False;
SetWidgetValue(Button1, 0.0);
SetWidgetValue(Button2, 0.0);
End
// Called when your twist the SLOW_LED_BUTTON widget
On WidgetValueChanged(newValue : double) from Button1
Print("Button1 callback start ============");
If (Button1_pushed)
Then Print(" Button1 ON");
Else Print(" Button1 OFF");
End
If (Button2_pushed)
Then Print(" Button2 ON");
Else Print(" Button2 OFF");
End
If (!Button1_pushed)
Then
If (newValue == 1.0)
Then
Print(" Button1 pushed");
Button1_pushed = True;
Button2_pushed = False;
SetWidgetValue(Button2, 0.0);
//SendNow(MIDIin, MakeProgramChangeMessageEx(0,0));//Program, Channel
If (doSwitching) Then SwitchToProgramNumber(0,0); End //Program,Bank
End
Else //Button is already pushed
// with False => keeps out for the moment
If (newValue == 0.0)
Then
Print(" Button1 keeps pushed!!");
SetWidgetValue(Button1, 1.0);
End
End
Print("Button1 callback stop ============");
Print(" ");
End
// Called when your twist the SLOW_LED_BUTTON widget
On WidgetValueChanged(newValue : double) from Button2
Print("Button2 callback start ============");
If (Button1_pushed)
Then Print(" Button1 ON");
Else Print(" Button1 OFF");
End
If (Button2_pushed)
Then Print(" Button2 ON");
Else Print(" Button2 OFF");
End
If (!Button2_pushed)
Then
If (newValue == 1.0)
Then
Print(" Button2 pushed");
Button2_pushed = True;
Button1_pushed = False;
SetWidgetValue(Button1, 0.0);
//SendNow(MIDIin, MakeProgramChangeMessageEx(0,0));//Program, Channel
If (doSwitching) Then SwitchToProgramNumber(1,0); End//Program,Bank
End
Else //Button is already pushed
// with False => keeps out for the moment
If (newValue == 0.0)
Then
Print(" Button2 keeps pushed!!");
SetWidgetValue(Button2, 1.0);
End
End
Print("Button2 callback stop ============");
Print(" ");
End