Using array in WidgetValueChanged

I’m trying to link one set of radio buttons to another set of radio buttons. Goal: click a button in one set, to engage a button in the other set.

In the amp panel, the ampButtons are in a Radio Group and enable the linked plugin and disable all the others. The ampViewButtons open/close the linked plugin editor and are configured the same way.

They can’t all be in the same Radio Group since I want two buttons engaged simultaneously.
If I could, I’d put the two sets into a Widget Link AND the Radio group, but that’s not allowed. So I turn to scripting.

In my script, I’ve declared:

var ampViewButtons: Widget Array = [
  BUTTON_VIEW_WONG,
  BUTTON_VIEW_GOJIRA,
  BUTTON_VIEW_RABEA
]

var ampButtons: Widget Array = [
  BUTTON_AMP_WONG,
  BUTTON_AMP_GOJIRA,
  BUTTON_AMP_RABEA
]  

I want to use the multi-Widget form of On WidgetValueChanged:

On WidgetValueChanged(w: Widget, index: integer, newValue: double) from <Widget name>, <Widget name>

The docs show a slightly different function signature:

On WidgetValueChanged ([w : Widget, index : integer,] newValue : double) from SomeWidget [,SomeWidget]*

I’m not able to find the right syntax to pass the ampButtons array to the WidgetValueChanged function. I’m also not able to use the w object in any way. I can get the index value.

Is there any better examples of Array usage? Can anyone share experience in this? Thanks!

I’m able to use the arrays and indices as i would expect in the function code. I’m just not sure how to pass the array to the function.

This works quite well, I just don’t like hardcoding the input params:

On WidgetValueChanged(w: Widget, index: integer, newValue: double) from BUTTON_AMP_WONG, BUTTON_AMP_GOJIRA, 
  BUTTON_AMP_NAMELESS, BUTTON_AMP_SOLDANO, BUTTON_AMP_MARSHALL
    SetWidgetValue(ampViewButtons[index], newValue)
End

I believe the way you have now done it - explicitly referencing the widgets in the callback - is the only way to do it. You are right though, being able to reference from an array could be neater if that were possible to be implemented.

This is not a function signature - it is basically BNF meta-syntax to demonstrate the form of a function.

So those square brackets mean that the widget and index parameters are optional - they are not arrays

Similarly, at the end of the definition, this means that you can optionally have more than one widget

Fair enough! I was just hoping that star * was a clue that we could use splatting/spreading on arrays.

If we could declare maps, that’d be even nicer, so we wouldn’t have to rely on keeping the array indices aligned.

GP Script was intended to be a simple language mostly for manipulation of MIDI messages and widgets/plugins :slight_smile:

If you need something more sophisticated, you can always write an extension using any language you want that supports C headers. You can even have it inject new GP Script system functions into the environment which would let you implement associative arrays (aka maps)

I agree it would be nicer if one could declare an array of widgets and then just use the array name

However, for various reasons beyond the scope of this discussion, this would get messy and since the same widget cannot participate in more than one callback, such a declaration could not be used anywhere other than once in one callback.

Since you cannot put widgets in both

No, BUT you can script the radio button function for one set of buttons and then you can widget link each button to the other group of buttons as needed.

There are many use cases for needing both the radio button and widget link functionality, so I hope some day it will be possible. I used to need to mute/unmute channels in a mixer as the radio buttons selected various VST’s. I scripted the radio buttons and then used the widget link for the mute buttons.

I’ve done the opposite: I linked the Amp Button group as Radios, and scripted the Amp View Buttons to change when the radios change:

On WidgetValueChanged(w: Widget, index: integer, newValue: double) from BUTTON_AMP_WONG, BUTTON_AMP_GOJIRA, 
  BUTTON_AMP_NAMELESS, BUTTON_AMP_SOLDANO, BUTTON_AMP_MARSHALL
    SetWidgetValue(ampViewButtons[index], newValue)
End

Yep! Same concept! PotEHto / PotAHto… :wink: