How to realize "radio buttons" with scripting

Because this is a topic that pops up regularly, i decided to upload an example for anyone who is in need of such a useful thing. I made two rows with a diffrent number of buttons, where each row acts “radio-like”.

radiobuttons_example.gig (142.5 KB)

This is the code that is contained in the rackspace:

var
btn_u1, btn_u2, btn_u3, btn_l1, btn_l2, btn_l3, btn_l4, btn_l5 : Widget //used button's names

u_last, l_last : Integer // buffer variables to store the last pressed button

//Declaration of widget arrays for upper and lower preset buttons
u_buttons : Widget Array = [btn_u1, btn_u2, btn_u3]
l_buttons : Widget Array = [btn_l1, btn_l2, btn_l3, btn_l4, btn_l5]


Initialization //Called on first run
var i : Integer
//Check & store state of buttons - if all off, assume the first as "ON"
    For i = 0; i < Size(u_buttons); i = i + 1 Do
        If GetWidgetValue(u_buttons[i]) == 1.0 Then
            u_last = i
        Else
            u_last = 0
        End
    End

    For i = 0; i < Size(l_buttons); i = i + 1 Do
        If GetWidgetValue(l_buttons[i]) == 1.0 Then
            l_last = i
        Else
            l_last = 0
        End
    End

End


// Called when any of several widgets changed -> This is the block for UPPER buttons
On WidgetValueChanged(w : Widget, index: integer, newValue : double) from btn_u1, btn_u2, btn_u3
    var i : integer
    if newValue == 1.0 and index <> u_last then
        // Deselect other buttons
        for i = 0; i < Size(u_buttons); i = i + 1 do
            if i <> index then SetWidgetValue(u_buttons[i],0.0) end
        end
    u_last = index
end

    //Prevent a button to be switched off manually
    If newValue == 0.0 and index == u_last Then
        SetWidgetValue(u_buttons[index],1.0)
    End
End

// Called when any of several widgets changed -> This is the block for LOWER buttons
On WidgetValueChanged(w : Widget, index: integer, newValue : double) from btn_l1, btn_l2, btn_l3, btn_l4, btn_l5
    var i : integer
    if newValue == 1.0 and index <> l_last then
        // Deselect other buttons
        for i = 0; i < Size(l_buttons); i = i + 1 do
            if i <> index then SetWidgetValue(l_buttons[i],0.0) end
        end
    l_last = index
    end

    //Prevent a button to be switched off manually
    If newValue == 0.0 and index == l_last Then
        SetWidgetValue(l_buttons[index],1.0)
    End
End

If you should have any questions, don’t hesitate to ask. :slight_smile:
Cheers
Erik

13 Likes

I really hope that at a time this script will be useless… :innocent:

6 Likes

I am definitely hoping with you! :innocent: …maybe we should use the Force to get what we want?! :alien:
Or even Voodoo? I could pin some needles in the buttons of my controller… :ghost:

5 Likes

ooh sexay! My first thought would be to incorporate the buttons to control plugin bypass state to audition a number of say stomp box distortion types for a guitar amp , fun way to audition each one separately with simply one foot press …

Thank you! I’ve been wanting to setup radio buttons controlling patch selection in the global rackspace. Going to give this a try.
I’m also hoping Gig Performer will implement a radio button feature.

2 Likes

May you hope hard enough! :wink:

3 Likes

I have setup an alternative way to realise RadioButtons using a Skriptlet.

The advantage is that you can link the skriptlet directly to other components. You can save / copy / paste a group of components incl the related scriptlet and you have not to care about the rackspace script and there is no need to change / adjust a rackspace script.

The example shows a B3 organ with 7 presets mapped to 7 RadioButtons. You can switch the presets via the RadioButtons or via the BlackKeys if they are enabled on the keyboard.

RadioButton Skriptlet Demo.gig (879.1 KB)

2 Likes

The widget ‘btn_l2’ is declared in a script but does not exist in the rackspace called ‘Radio buttons’
Radio buttons (Rackspace) - GPScript System Function Exception: Attempt to access missing widget

How do I fix this? I’m trying to add more buttons. Initially, I deleted button2 then tried to add it again.

The script knows about the widgets via the name specified in the widget properties Advanced tab.

If you have added new ones or duplicated existing ones, then you will need to update the names in the advanced tab and ensure they are listed the same in the script. Or, if the widgets no longer exist, remove any reference to them in the script.

1 Like

I’m not sure what’s happening, but something in the script is randomly “misfiring” and now allowing widget to follow variations. Meaning, sometimes (randomly) I have to click (whichever) button 2 or 3 times for it to “register” (even if there is only one variation) and when there are more variations, the radio buttons do not the variations. I can also deselect a widget after 3 clicks. When I delete the script, it follows the variations just fine. Its basically the script in the OP, with less buttons and no upper/lower sets of widgets. Any ideas what could be going on?

var
N1, N2, N3, N4 : Widget //used button's names

u_last, l_last : Integer // buffer variables to store the last pressed button

//Declaration of widget arrays for upper and lower preset buttons
u_buttons : Widget Array = [N1, N2, N3, N4]


Initialization //Called on first run
var i : Integer
//Check & store state of buttons - if all off, assume the first as "ON"
    For i = 0; i < Size(u_buttons); i = i + 1 Do
        If GetWidgetValue(u_buttons[i]) == 1.0 Then
            u_last = i
        Else
            u_last = 0
        End
    End

End


// Called when any of several widgets changed -> This is the block for UPPER buttons
On WidgetValueChanged(w : Widget, index: integer, newValue : double) from N1, N2, N3, N4
    var i : integer
    if newValue == 1.0 and index <> u_last then
        // Deselect other buttons
        for i = 0; i < Size(u_buttons); i = i + 1 do
            if i <> index then SetWidgetValue(u_buttons[i],0.0) end
        end
    u_last = index
end

    //Prevent a button to be switched off manually
    If newValue == 0.0 and index == u_last Then
        SetWidgetValue(u_buttons[index],1.0)
    End
End


Hi, to answer this old open question, and as I finally was playing around with radio buttons this evening:

There’s an On Variation code block missing to determine the right u_last in the called variation…

Add

On Variation(oldVariation : integer, newVariation : integer)
var i : integer
    For i = 0; i < Size(u_buttons); i = i + 1 Do
        If GetWidgetValue(u_buttons[i]) == 1.0 Then
            u_last = i
        End
    End
end

to your rackspace script and everything will be OK :slight_smile:

Alternatively, you can use the “Radio Buttons” extension: Gig Performer | What are extensions in Gig Performer and how to use them

… and a new update of Gig Performer will bring some new related features in this field.

2 Likes

… and a new update of Gig Performer will bring some new related features in this field.

I already was curious about the upcoming release after the today’s Gig Performer live stream, now even more :sunglasses:

1 Like

What was in the stream? My German is non existent

The radio button function of the select buttons in my rackspace was also implemented via scripting. As I mentioned in the stream, I didn’t use any new features of the beta version except for the visual things (colors and fonts).

2 Likes

I was not discovering new features in the live stream, but with the discussions and hints in the various threads over the last time I‘m getting more and more curious.
4.5 was already a big step :star_struck:

@LeeHarvey BTW: a very impressive way to use GigPerformer! I took some inspirations :slightly_smiling_face:

1 Like

I’m glad to hear it! Too bad that the time was not enough. There would have been so much to show. And at the end I was a bit rushed and unstructured. Sorry.