Turning buttons off: Simplify Script

Hello All…

I am really new to this scripting, and must admit this is hard for me.

I have a series of button widgets that I use to change a plugin’s preset via a CC command. That bit is done. The big issue I came across, it that when I select a widget button, it turns on visually, but the previously selected widget stays on. So it can get confusing as to the preset you are actually using.

I have managed to solve this in scripting. And it works perfectly. My question, is now I would like to add more presets, and wonder if there is a more efficient way to script this. I just have no idea.

Thanks in advance…!!!

// MIDI Section

MIDI_IN : MidiInBlock

// Widget Section


Preset_1 : Widget
Preset_2 : Widget
Preset_3 : Widget
Preset_4 : Widget
Preset_5 : Widget
Preset_6 : Widget
Preset_7 : Widget
Preset_8 : Widget
Preset_9 : Widget
Preset_10 : Widget
Preset_11 : Widget
Preset_12 : Widget
Preset_13 : Widget
Preset_14 : Widget
Preset_15 : Widget

// Pedalboard Preset Section

On WidgetValueChanged(newValue : double) from Preset_1

If (newValue > 0.5)
SendNow(MIDI_IN, MakeControlChangeMessage(11,127))
// SetWidgetValue(Preset_1, 0)
SetWidgetValue(Preset_2, 0)
SetWidgetValue(Preset_3, 0)
SetWidgetValue(Preset_4, 0)
SetWidgetValue(Preset_5, 0)
SetWidgetValue(Preset_6, 0)
SetWidgetValue(Preset_7, 0)
SetWidgetValue(Preset_8, 0)
SetWidgetValue(Preset_9, 0)
SetWidgetValue(Preset_10, 0)
SetWidgetValue(Preset_11, 0)
SetWidgetValue(Preset_12, 0)
SetWidgetValue(Preset_13, 0)
SetWidgetValue(Preset_14, 0)
SetWidgetValue(Preset_15, 0)
// Else
// ClosePlugin(Clean)

This will actually become a little easier with GP4 due to some language improvements but in the meantime, you could do something like the following: (I just did it with a few widgets to show the concept)

   MIDI_IN : MidiInBlock

   Preset_0, Preset_1, Preset_2 : Widget

   widgets : widget array  

   widgets = [Preset_0, Preset_1, Preset_2]

function UpdateExcept(newValue : double, index : integer)
   var i : integer
   if (newValue > 0.5)
           SendNow(MIDI_IN, MakeControlChangeMessage(11,127)) // Does this value depend on the widget?
           for i = 0; i < Size(widgets); i = i + 1 do
              if i != index
                 then SetWidgetValue(widgets[i], 0)

// Pedalboard Preset Section

On WidgetValueChanged(newValue : double) from Preset_0
   UpdateExcept(newValue, 0)

On WidgetValueChanged(newValue : double) from Preset_1
   UpdateExcept(newValue, 1)

On WidgetValueChanged(newValue : double) from Preset_2
   UpdateExcept(newValue, 2)


That’s awesome…!!! Now to figure this out.

And the answer is yes. Each widget sends a different CC:

  • Preset 1 = 11
  • Preset 2 = 12
    etc etc…
  • Preset 15 = 25

Again, thanks & Wow…!!

Since your CC controllers just go up by one each time, just modify the SendNow message

SendNow(MIDI_IN, MakeControlChangeMessage(11 + index, 127))

Index will be 0 for the first preset, 1 for the second, 2 for the third, etc


I was close…!!! Been trying all afternoon to solve this. Just put the statement in the wrong spot.

Thank you so much…!!!

By the way (for others who may be interested), if the MIDI CC numbers needed to be arbitrary, i.e. not increasing by one, you could just define an integer array, similar to the widget array, and initialize it with the desired CC numbers and then dereference it

it would be great to get an update to this solution based on the GP4 features !!

Have a look at the script here by @dhj

Thanks for the hint and link …

… looks like i need to spend a bit more time with scripting…