Script for snap-in movement of widgets (needs GP V4 or higher)

Today i tried to simulate the behaviour of “multi-position” switches with knob or fader widgets…
the script i wrote makes the widget’s position “snap” to the next “fixed-switch-point” if there is no more manual widget movement within a specified time threshold.
That way you can emulate such things as 3, 4, or more way selector switches like they can be found on many plugin’s GUIs.

You need a widget with the ScriptName “w_snapped” (see “advanced” tab in edit mode) and then, within the script, you can specify the number of snap-points (snaps) and the time threshold (waiting_time) value in ms…

The movement of a fader “acting” as a three-way switch looks like this:
position-snapping

The code of the script:

var
w_snapped : widget //handle name of the widget - set in edit/advvanced tab

snaps : Integer = 3 //total number of snap points
waiting_time : double = 20 //time to wait in ms befor switching to snap point

snap_point : Integer //varable for actual snap point number
old_snap_point: Integer //buffering the old snap-point
snap_interval : double = 1.0 / (snaps-1) //jumping range for the widget

widget_pos : double
snapped : boolean = false
move_start : double //the moment the widget started to change

On WidgetValueChanged (knb_val : double) From w_snapped
    snap_point = Round(knb_val / snap_interval)
    move_start = TimeSinceStartup()
    SetTimersRunning(true)
End

On TimerTick(ms : double)
    If ms - move_start > waiting_time and snapped == false Then
        snapped = true
        widget_pos = snap_point * snap_interval
        If snap_point == 0 Then
            widget_pos = 0.0
        End
        
        SetWidgetValue (w_snapped, widget_pos)
        SetTimersRunning(false)
        snapped = false
    End
End

And here is a rackspace which you can import into a gig file to try it:
Snap-Widget.rackspace (22.3 KB)

Maybe it’s useful for some of you guys…
Cheers! :beers:
Erik (aka Schamass) :metal: :sunglasses: :metal:

10 Likes

You might even consider using a label strip to show the name of the value in case it is useful, e.g. saw, sine, square. Instead of just a value from the slider.

Or even better, e.g three label strips under the slider at the correct positions where only the active label is visible.

Thank you! I’m amazed that there are not stock, factory-equipped multi-position switch widgets. Major feature requests, Deskew.

I just tried it, and it works nicely! The plugin Learn also functioned properly. I’d love to figure out how to detente the switches - maybe that can be done with the response curves?

(I’ve just started learning my way around GP4 today, so bear with me)

With widget scaling curves you can easily implement that

2 Likes