Value on a label widget

Hi,

Is there a way for the value to change on a label widget when the label is displaying song key via system actions? I noticed the value doesn’t ever change when it’s just a song key label.

What I’m basically trying to accomplish is to have a value which represents a song key, then I’m able to reference that widget value in GP Script to accomplish different things based on the song key.

Hopefully that makes sense. Any advice is appreciated. Thanks.

You can access the key information directly in GP Script - for example

Var
   SysActions : PluginBlock  // References to a system actions plugin block

Initialization
var
   s : string = GetParameterText(SysActions, 68)  // 68 is the parameter number for the song key            
   Print(s)   
End
1 Like

Thanks! I’ll play around with this later today.

Follow up question. How would I reference that string that gives me the song key value in an “if” and “then” statement. Basically trying to figure out, if song key is X then perform action Y.

if s == "C" then
 Print("C")
else
 Print("Not C")
end
1 Like

Perfect, makes sense. Thank you!

1 Like

For some reason I’m getting, Semantic error in “Main”: Line 16, Col 12: Identifier not declared: s
What am I getting wrong here?

Var
Global_MIDI : MidiInBlock
TRIGGER_DRONE_PAD: Widget
SysActions : PluginBlock  // References to a system actions plugin block
MM : MidiMessage

Initialization
var
s : string = GetParameterText(SysActions, 68)  // 68 is the parameter number for the song key            
    Print(s)
    End
    On WidgetValueChanged(newValue : double) from TRIGGER_DRONE_PAD
    If GetWidgetValue(TRIGGER_DRONE_PAD) == 0.0 then
        AllNotesOff(Global_MIDI)
       Else
        if s == "C Major" then
        Print("C Major")
        SendNow(Global_MIDI, MM)
        MM = MakeNoteMessage (60,64)
        SendNow(Global_MIDI, MM)
        MM = MakeNoteMessage (67,64)
        SendNow(Global_MIDI, MM)
        MM = MakeNoteMessage (72,64)
        End
End
End

You didn’t declare the variable s and initialize it in the WidgetValueChanged callback

1 Like

Ok I think I almost have it. Only issue is now it doesn’t seem to initialize everytime the variable changes which is what I’m assuming I need it to do in order for it to select the current song key.
I’m guessing it might have to do with what you mentioned above “initialize it in the WidgetValueChanged callback”. Not sure how to accomplish that. I tried to put that variable right after the On WidgetValueChanged callback but no luck. I’m sure it’s something simple I’m missing. It’s my first time trying to write a script so I appreciate the help and patience.

Var
Global_MIDI : MidiInBlock
TRIGGER_DRONE_PAD: Widget
SysActions : PluginBlock  // References to a system actions plugin block
s : string = GetParameterText(SysActions, 68)  // 68 is the parameter number for the song key
MM : MidiMessage

Initialization
Var
    s : string = GetParameterText(SysActions, 68)  // 68 is the parameter number for the song key
    Print(s)
End
    On WidgetValueChanged(newValue : double) from TRIGGER_DRONE_PAD
    If GetWidgetValue(TRIGGER_DRONE_PAD) == 0.0 then
    AllNotesOff(Global_MIDI)
    
   Else
    if s == "C Major" then
        Print("C Major")
    SendNow(Global_MIDI, MM)
    MM = MakeNoteMessage (60,64)
      SendNow(Global_MIDI, MM)
    MM = MakeNoteMessage (67,64)

   Else 
    if s == "C#/Db Major" then
        Print("C#/Db Major")
    SendNow(Global_MIDI, MM)
    MM = MakeNoteMessage (61,64)
    SendNow(Global_MIDI, MM)
    MM = MakeNoteMessage (68,64)
    
   Else
    if s == "D Major" then
        Print("D Major")
    SendNow(Global_MIDI, MM)
    MM = MakeNoteMessage (62,64)
    SendNow(Global_MIDI, MM)
    MM = MakeNoteMessage (69,64)
 
    End
    End
    End
    End
End

If you’re only using the parameter text within the On WidgetChanged callback, then that’s the only place you need to declare the variable “s”.

You don’t need to declare it as a global variable, and you don’t need the Initialisation section at all, as you’re only doing a Print.

On WidgetValueChanged(newValue : double) from TRIGGER_DRONE_PAD
    Var s : string = GetParameterText(SysActions, 68)
1 Like

Also try to use Select rather then nested If.. Then .. Else.. Else.. Else. :wink:

1 Like

And you should “make” the note message before you send it.

3 Likes

The main problem with this code is that you’re sending messages before you’re making them.

Here’s a revised version, cleaned up, with recommended syntax and indentation


Var
   Global_MIDI : MidiInBlock
   TRIGGER_DRONE_PAD: Widget
   SysActions : PluginBlock  // References to a system actions plugin block


On WidgetValueChanged(newValue : double) from TRIGGER_DRONE_PAD
var
   MM : MidiMessage
   songKey : string
    
    If GetWidgetValue(TRIGGER_DRONE_PAD) == 0.0 
       then AllNotesOff(Global_MIDI)    
       else
          songKey = GetParameterText(SysActions, 68)  // 68 is the parameter number for the song key
          Print(songKey)
          
          select  
          
             songKey == "C Major" do
               MM = MakeNoteMessage (60,64)
               SendNow(Global_MIDI, MM)  
               MM = MakeNoteMessage (67,64)  
               SendNow(Global_MIDI, MM)

            songKey == "C#/Db Major" do                 
                    MM = MakeNoteMessage (61,64)
                    SendNow(Global_MIDI, MM)
                    MM = MakeNoteMessage (68,64) 
                    SendNow(Global_MIDI, MM)
    
           songKey == "D Major" do                
                   MM = MakeNoteMessage (62,64)
                   SendNow(Global_MIDI, MM)
                   MM = MakeNoteMessage (69,64) 
                   SendNow(Global_MIDI, MM)
 
          End // Select
    End // If
    
    
End // WidgetValueChanged

2 Likes

Hi David, thanks for cleaning that up for me. I was able to make it work with everyone’s advice above but your revised version works a lot “smoother”.

Thanks everyone for your help with this one. It was my first attempt ever at writing a script and I learned a lot.

3 Likes

Hi all, this script has been working beautifully for me. I do want to take it one step further and want to see if this is possible. Currently when changing a song the script will keep the same key as the previous rackspace until I turn it off with the widget and turn it back on. What I would like to accomplish is for the key on the script to automatically change when I change the song so that the synth pad that it’s playing back just smoothly changes to the next key. Hopefully that explanation made sense.

I’m looking through the GP Script manual to try and figure this out. I’m assuming it will have to be a song event in the gig script where I would use an “on song” callback but I’m stuck after that. Any idea what statements I would have to use and what they would have to “point” to?

After some experimentation it looks like I was able to figure it out on my own, so far seems to be working like I intended. I guess I’m starting to get the hang of this :wink:

If anyone happens to see any glaring issues in this script that might give me some issues down the line your feedback is appreciated.

Var
   Global_MIDI : MidiInBlock
   TRIGGER_DRONE_PAD: Widget
   SysActions : PluginBlock  // References to a system actions plugin block
    

On WidgetValueChanged(newValue : double) from TRIGGER_DRONE_PAD
var
   MM : MidiMessage
   songKey : string
    
    If GetWidgetValue(TRIGGER_DRONE_PAD) == 0.0 
       then AllNotesOff(Global_MIDI)    
       else
          songKey = GetParameterText(SysActions, 68)  // 68 is the parameter number for the song key
          Print(songKey)
          
          select  
          
            songKey == "C Major" do
               MM = MakeNoteMessage (60,64)
               SendNow(Global_MIDI, MM)  
               MM = MakeNoteMessage (67,64)  
               SendNow(Global_MIDI, MM)

            songKey == "C#/Db Major" do                 
               MM = MakeNoteMessage (61,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (68,64) 
               SendNow(Global_MIDI, MM)
    
            songKey == "D Major" do                
               MM = MakeNoteMessage (62,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (69,64) 
               SendNow(Global_MIDI, MM)

            songKey == "D#/Eb Major" do                
               MM = MakeNoteMessage (63,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (70,64) 
               SendNow(Global_MIDI, MM)

            songKey == "E Major" do
               MM = MakeNoteMessage (64,64)
               SendNow(Global_MIDI, MM)  
               MM = MakeNoteMessage (71,64)  
               SendNow(Global_MIDI, MM)

            songKey == "F Major" do                 
               MM = MakeNoteMessage (65,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (72,64) 
               SendNow(Global_MIDI, MM)
    
            songKey == "F#/Gb Major" do                
               MM = MakeNoteMessage (66,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (73,64) 
               SendNow(Global_MIDI, MM)

            songKey == "G Major" do                
               MM = MakeNoteMessage (67,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (74,64) 
               SendNow(Global_MIDI, MM)

            songKey == "G#/Ab Major" do
               MM = MakeNoteMessage (68,64)
               SendNow(Global_MIDI, MM)  
               MM = MakeNoteMessage (75,64)  
               SendNow(Global_MIDI, MM)

            songKey == "A Major" do                 
               MM = MakeNoteMessage (69,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (76,64) 
               SendNow(Global_MIDI, MM)
    
            songKey == "A#/Bb Major" do                
               MM = MakeNoteMessage (70,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (77,64) 
               SendNow(Global_MIDI, MM)

            songKey == "B Major" do                
               MM = MakeNoteMessage (71,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (78,64) 
               SendNow(Global_MIDI, MM)
 
          End // Select
    End // If
    
    
End // WidgetValueChanged
  
On ParameterValueChanged(index : integer, value : double) from SysActions
var
   MM : MidiMessage
   songKey : string
   
    If GetWidgetValue(TRIGGER_DRONE_PAD) == 0.0 
       then   
       else
          songKey = GetParameterText(SysActions, 68)  // 68 is the parameter number for the song key
          Print(songKey)
          AllNotesOff(Global_MIDI)
          
          select
          
          
            songKey == "C Major" do
               MM = MakeNoteMessage (60,64)
               SendNow(Global_MIDI, MM)  
               MM = MakeNoteMessage (67,64)  
               SendNow(Global_MIDI, MM)

            songKey == "C#/Db Major" do
               MM = MakeNoteMessage (61,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (68,64) 
               SendNow(Global_MIDI, MM)
    
            songKey == "D Major" do
               MM = MakeNoteMessage (62,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (69,64) 
               SendNow(Global_MIDI, MM)

            songKey == "D#/Eb Major" do
               MM = MakeNoteMessage (63,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (70,64) 
               SendNow(Global_MIDI, MM)

            songKey == "E Major" do
               MM = MakeNoteMessage (64,64)
               SendNow(Global_MIDI, MM)  
               MM = MakeNoteMessage (71,64)  
               SendNow(Global_MIDI, MM)

            songKey == "F Major" do
               MM = MakeNoteMessage (65,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (72,64) 
               SendNow(Global_MIDI, MM)
    
            songKey == "F#/Gb Major" do
               MM = MakeNoteMessage (66,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (73,64) 
               SendNow(Global_MIDI, MM)

            songKey == "G Major" do
               MM = MakeNoteMessage (67,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (74,64) 
               SendNow(Global_MIDI, MM)

            songKey == "G#/Ab Major" do
               MM = MakeNoteMessage (68,64)
               SendNow(Global_MIDI, MM)  
               MM = MakeNoteMessage (75,64)  
               SendNow(Global_MIDI, MM)

            songKey == "A Major" do
               MM = MakeNoteMessage (69,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (76,64) 
               SendNow(Global_MIDI, MM)
    
            songKey == "A#/Bb Major" do
               MM = MakeNoteMessage (70,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (77,64) 
               SendNow(Global_MIDI, MM)

            songKey == "B Major" do
               MM = MakeNoteMessage (71,64)
               SendNow(Global_MIDI, MM)
               MM = MakeNoteMessage (78,64) 
               SendNow(Global_MIDI, MM)
 
          End // Select
    End // If

End // ParameterValueChanged

This is not very elegant, try rather something like:

If GetWidgetValue(TRIGGER_DRONE_PAD) > 0.0 
       then   
          songKey = …..
1 Like

Got it, I’ll give that a shot. Appreciate the feedback.

1 Like

Also you can directly use newValue rather then GetWidgetValue(TRIGGER_DRONE_PAD) :wink:

So if I’m understanding correctly I can do this instead?

On ParameterValueChanged(index : integer, value : double) from SysActions
var
   MM : MidiMessage
   songKey : string
   
    If newValue > 0.0 
       then   
          songKey =