Value on a label widget

No, you can only do so within the On WidgetValueChanged(newValue : double) from TRIGGER_DRONE_PAD callback.

And by the way, in the On ParameterValueChanged(index : integer, value : double) from SysActions callback, you could also check the index (which is the parameter index), if it is not 68, it means that the parameter 68 didn’t change, so you don’t need to do anything.

1 Like

Interesting, I will definitely try that out later today. Thanks!

1 Like

Tried to make sense of what you described above with both the newValue and also check the index for ParameterValueChanged, etc. I’m not quite understanding. (Appreciate your patience as I’m a complete beginner at this)

When a callback is called it “brings” some variable values with it. In the case of a widget callback the newValue holds the value of the widget when it changed. Within this callback, no need to request the value of the widget, it is already there as newValue.

In the case of the SysActions callback the index variable holds the index of the parameter that changed and the value variable its value. So you probably don’t want to do anything if another parameter than the #68 changed
.
Does my answer help?

2 Likes

Got it, I definitely understand the logic behind it. My only issue is implementing it into the script. Still have lots to learn so I’ll be looking closely at the GP Script manual.

So, in the On WidgetValueChanged(newValue : double) from TRIGGER_DRONE_PAD callback:

replace GetWidgetValue(TRIGGER_DRONE_PAD) by newValue

And in the other callback do something like :

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

Regarding the second code modification, you can test the difference. In your current code, if a drone is playing and you change any SysActions parameter, then your GPScript will send an AllNotesOff message even if the song key didn’t change.

1 Like

Yeah, I’ll definitely test it out later. Thanks again for your help!

1 Like

I’m getting an “Identifier not declared: newValue”. Not sure how I am supposed to declare it. Don’t I somehow have to reference that widget so it knows what newValue it’s referencing?

It doesn’t help to say this out of context. You need to show the script and the actual error message complete with line information.

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 index == 68 && newValue > 0.0 
       then   
          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

GLOBAL RACKSPACE (GlobalRackspace) - Semantic error in “Main”: Line 113, Col 24: Identifier not declared: newValue

You’ve called it value, not newValue.
These variable names can be anything (e.g. you could call it mySuperFantasticValue), but you obviously have to refer to these names within your callback code.

1 Like

Sorry, it was me, here you cannot replace GetWidgetValue(TRIGGER_DRONE_PAD) by newValue, rather write:

On ParameterValueChanged(index : integer, value : double) from SysActions
var
   MM : MidiMessage
   songKey : string
   
    If index == 68 && GetWidgetValue(TRIGGER_DRONE_PAD) > 0.0 
       then   
          songKey = GetParameterText(SysActions, 68) …

As I wrote newValue is defined in the On WidgetValueChanged(newValue : double) from TRIGGER_DRONE_PAD callback, not in the On ParameterValueChanged(index : integer, value : double) from SysActions one.

On WidgetValueChanged(newValue : double) from TRIGGER_DRONE_PAD
var
   MM : MidiMessage
   songKey : string
    
    If newValue == 0.0 
       then …
1 Like

That’s what I suspected, thanks for clarifying and thank you all again for all the help. Working through this script has been very helpful in learning some GP Script basics.

1 Like

I used this script over the weekend and it worked great. I did notice one small problem, maybe you guys can give me some insight on how to fix this. It seems like for every song and song part change GP considers it a system actions parameter song key change even when the song didn’t change key from the previous song. So what ends up happening is if I leave TRIGGER_DRONE_PAD on and the key didn’t change it will still carry out the ParameterValueChanged callback.

I tried to fix this by adding the below.

&& GetSongKeySignature(GetCurrentSongIndex()) != GetSongKeySignature(GetCurrentSongIndex()-1)

It seems to work partially, if the song key didn’t change it won’t carry out the callback from song to song, but it will still carry out the callback from song part to song part which has me confused. I tried using GetCurrentSongPart both instead of and in conjunction with GetCurrentSongIndex but that had weird results. Any ideas?

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 index == 68 && GetWidgetValue(TRIGGER_DRONE_PAD) > 0.0 && GetSongKeySignature(GetCurrentSongIndex()) != GetSongKeySignature(GetCurrentSongIndex()-1)
       then   
          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

Store the song key in a global variable, i.e, declared outside the callback.

In the callback, compare the new song key that you get with global one — if they are the same, don’t do anything, otherwise, do everything and save the new key back into the global variable

Not sure what you mean by “save the new key back into the global variable”

I guess I’m just not fully grasping how I would declare the song key as a global variable in a way where I would somehow “save the key”.