Jamba Views / Toggle Button

Toggle Button

Toggle Button

A toggle button is a button that lets you toggle the value of a parameter between an “on” value and an “off” value.

This view is designed to handle parameters which are backed by a bool representation but it works for any parameter (both Vst and Jmb) that is (or can be interpreted as) a discrete parameter.

Info

This view defines the “on” state as being the opposite of the “off” state and so the “off” state is the one being checked against the off value (otherwise we could end up in a situation where both isOn and isOff are true…). The consequence is that the underlying parameter might have a value that is neither the “off” value nor the “on” value, but for the sake of this view it will be treated as “on” (similarly to C/C++ where 0 is false and any non-zero is true).

In addition to the attributes exposed by CustomDiscreteControlView, this class exposes the following attributes:

Attribute Description
on-step Maps to the “on” value unless it is set to its default (-1) value in which case it maps to getStepCount() (should be -1 or a value in [0, stepCount]).
off-step Maps to the “off” value unless it is set to its default (-1) value in which case it maps to 0 (should be -1 or a value in [0, stepCount]).
on-color When no image is provided, back-color is used for the “off” state and on-color for the “on” state (draws a rectangle with this color).
frames The number of frames the image contains. Should be either 2 or 4 (4 includes the pressed state).
button-image The image to use to draw the button (2 or 4 frames).
inverse Inverses the meaning of “on” and “off” in regards to drawing the view/image.

Example

The XML defining the button (4 frames) (Source)

<view button-image="Button_Live_4frames" class="jamba::ToggleButton" control-tag="Param_LCDLiveView" frames="4" origin="14, 148" size="40, 43" ... />

The vst param is defined this way (boolean parameter) (Source)

VstParam<bool> fLCDLiveViewParam;

The vst param is initialized this way (Source)

fLCDLiveViewParam =
  vst<BooleanParamConverter>(EVAC6ParamID::kLCDLiveView, STR16 ("Live"))
    .defaultValue(true)
    .shortTitle(STR16 ("Live"))
    .transient() // means NOT saved with the state
    .add();