Sliders

Slider can be used to create an on-screen slider. Data can be sent to Csound on the channel specified through the channel string. Sliders can be rotary, vertical, horizontal, frange-based, or number boxes, and can react in both a linear and non-linear fashion.

slider max(val), min(val), outlinecolour("colour"), popuptext("text"), popuptext("text"), popuppostfix("text"), range(min, max, value, skew, incr), svgfile("type", "file"), textcolour("colour"), text("name"), trackerthickness(val), trackerinsideradius(val), trackeroutsideradius(val), textboxoutlinecolour("colour"), textboxcolour("colour"), trackercolour("colour"), valuetextbox(val), velocity(val), active(val), alpha(val), bounds(x, y, width, height), channel("chan"), colour("colour"), fontcolour("colour"), identchannel("channel"), popup(val), rotate(radians, pivotx, pivoty), visible(val), tofront(), widgetarray("chan", number),

Specific Identifiers

max(val) If using a double or triple pointer slider (hslider2, hslider3, vslider2, vslider3), max() will set the default maximum position of the maximum thumb controller. The absolute maximum is set using the range identifier. See above.

min(val) If using a double or triple pointer slider (hslider2, hslider3, vslider2, vslider3), min() will set the default minimum position of the minimum thumb controller. The absolute minimum is set using the range identifier. See above.

outlinecolour("colour") Sets the colour of a rotary slider`s tracker outline. This is the line that is drawn around the rslider's tracker. If you don't wish to display the tracker outline set the colour to something with an alpha value of 0. See above for details on valid colours.

popuptext("text") Sets the text that will appear in the popup text bubble when a user hovers over the widget. This can be used to override the defaul text which displays the channel name and the current value. Passing a 0 will disable all popuptext notices completely.

<!--UPDATE WIDGETINCSOUND SIdent sprintf "popuptext(\"Popup Text %d\") ", rnd(1000) SIdentifier strcat SIdentifier, SIdent --> Not available to nslider

popuptext("text") Sets the text that will appear in the popup text bubble when a user hovers over the widget. This can be used to override the defaul text which displays the channel name and the current value. Passing a 0 will disable all popuptext notices completely. Not available to nslider

popuppostfix("text") Sets the postfix text that will appear in the popup text bubble. This string will appear just after the current value of the slider. Although nslider's don't use popup bubbles, this identifier will set a value postfix.

range(min, max, value, skew, incr) the first 2 parameters are required. The rest are optional. The first two parameters let you set the minimum value and the maximum value. The next parameter determines the initial value of the slider. The 4th parameter allows you to adjust the skew factor. Tweaking the skew factor will cause the slider to output values in a non linear fashion. A skew of 0.5 will cause the slider to output values in an exponential fashion. A skew of 1 is the default value, which causes the slider to behave is a typical linear form. The final parameter sets the incremental step size for the slider. If you need to have very fine control of steps you may wish to look at using an Endless Encoder instead.

svgfile("type", "file") Use this identifier to pass a unique svg file to use instead of the default look and feel. "type" should be one of the following:

  • "background" : sets the slider background image
  • "slider" : sets the slider thumb, or in the case of a rotary slider, the inner circle. This image moves in sympathy with that the mouse as users move the slider.

For more information see Using SVGs

textcolour("colour") This set the colour of the text passed to text(). If you wish to change the colour of the numbers being displayed use fontcolour(). See below. See above for details on valid colours.

text("name") The string passed in for "name" will appear on a label beside the slider. This is useful for naming sliders.

trackerthickness(val) Sets the thickness of the slider's tracker, 1 being full thickness. This is the line that follows the slider when you move it. To disable the tracker you can set its thickness to 0 or it's alpha colour channel to 0.

<!--UPDATE WIDGETINCSOUND SIdent sprintf "trackerthickness(%f) ", rnd(10) SIdentifier strcat SIdentifier, SIdent --> Not available for rsliders

trackerinsideradius(val) Sets the inner radius of a rotary tracker, proportional to the overall rotary slider size. val should be in the range 0 to 1

<!--UPDATE WIDGETINCSOUND SIdent sprintf "trackerinsideradius(%f) ", rnd(10)/10 SIdentifier strcat SIdentifier, SIdent --> Only available to rsliders

trackeroutsideradius(val) Sets the outer radius of a rotary tracker, proportional to the overall rotary slider size. val should be in the range 0 to 1

<!--UPDATE WIDGETINCSOUND SIdent sprintf "trackeroutsideradius(%f) ", rnd(10)/10 SIdentifier strcat SIdentifier, SIdent --> Only available to rsliders

textboxoutlinecolour("colour") Sets the colour of the outline of the value text box used to display the slider's value when textbox is enable. See above for details on valid colours.

textboxcolour("colour") Sets the colour of the background of the value text box used to display the slider's value when textbox is enable. See above for details on valid colours.

trackercolour("colour") Sets the colour of the slider's tracker. This is the line that follows the slider when you move it.

valuetextbox(val) textbox takes a 0 or a 1. 1 will cause a text box to appear with the sliders values. Leaving this out will result in the numbers appearing automatically when you hover over the sliders with your mouse.

velocity(val) Sets the sensitivity of the slider to mouse movement. The value passed should be in the range of 1 upwards. Note that velocity mode will only work if the range of the slider is greater than the distance in pixels between min and max.

Common Identifiers

active(val) Will deactivate a control if 0 is passed. Controls which are deactivate can still be updated from Csound.

alpha(val) A value between 0 and 1 will set the alpha blend value for the entire component. Can be useful if you need to fade widgets in and out.

bounds(x, y, width, height) integer values that set position and size on screen(in pixels).

channel("chan") "chan" is the name of the channel that Cabbage will communicate with Csound on. The current value of this widget can be retrieved in Csound using a chnget opcode, or can be set using a chnset opcode.

colour("colour") This sets the main colour. Any CSS or HTML colour string can be passed to this identifier. The colour identifier can also be passed an RBG, or RGBA value. All channel values must be between 0 and 255. For instance colour(0, 0, 255) will create a blue, while colour(0, 255, 0, 255) will create a green with an alpha channel set to full.

fontcolour("colour") Sets the colour of the font. In the case of slider this sets teh colour of the font in the value textbox if it is shown.

identchannel("channel") Sets the channel which data is sent and retrieved from Csound. When used with a chnset opcode users can override widget attributes. See Identifier channels

popup(val) This identifier, used with an image or groupbox will convert the plant into a popup plant. The plant will not be shown on the instrument's main interface, but will instead appear when the user sets visible to 1. < DAWs treat popup dialogue windows in different ways. As a result, you may notice inconsistent behaviour when running your instruments as plugins across a variety of different hosts.
Not available to nslider

rotate(radians, pivotx, pivoty) Rotates the widget by a number of radians(2xPI=full rotation). pivotx and pivoty will determine the rotation pivot points, where 0, 0 represents the component's top-left position.

visible(val) A value of 0 will cause the widget to become invisible. Widgets have their visibility set to 1 by default.

tofront() Brings a widget to the front of the z order. This identifier takses no arguments and is only intended for use with identifier channels.

widgetarray("chan", number) Creates a number of widgets in a single pass. See Widget arrays

Slider types:

  • rslider, a standard rotary or knob slider

  • hslider, a standard horizontal slider

  • vslider, a standard vertical slider

  • hslider2, two value horizontal range slider (deprecated, use hrange)

  • vslider2, two value vertical range slider (deprecated, use vrange)

  • nslider, a number box slider in the style of Pure Data /MaxMSP

Make sure to use two unique channel names when using hslider2 and vslider2, otherwise min and max will be set to the same value.

Example

<Cabbage>
form caption("Slider Example") size(400, 300), colour(220, 220, 220), pluginID("def1")
label bounds(8, 6, 368, 20), text("Basic Usage"), fontcolour("black")
hslider bounds(8, 38, 369, 50), channel("gain"), text("Gain") range(0, 1, 0, 1, 0.001) fontcolour(91, 46, 46, 255) textcolour(29, 29, 29, 255)
groupbox bounds(8, 110, 380, 177), text("Randomly Updated Identifiers")
rslider bounds(70, 140, 41, 119) channel("rsliderChannel"), identchannel("widgetIdent"), range(0, 1, 0, 1, 0.001) 
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

seed 0 
;basic usage
instr 1
    aTone oscili chnget:k("gain"), 300
    outs aTone, aTone    
endin

;WIDGET_ADVANCED_USAGE

instr 2
    if metro(1) == 1 then
        event "i", "ChangeAttributes", 0, 1
    endif
endin

instr ChangeAttributes
    SIdentifier init ""
    SIdent sprintf "outlinecolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent  
    SIdent sprintf "popuptext(\"Popup Text %d\") ", rnd(1000)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "textcolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent  
    SIdent sprintf "text(\"TextOff %f\") ", rnd(100)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "trackerthickness(%f) ", rnd(10)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "trackerinsideradius(%f) ", rnd(10)/10
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "trackeroutsideradius(%f) ", rnd(10)/10
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "textboxoutlinecolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent  
    SIdent sprintf "textboxcolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent  
    SIdent sprintf "trackercolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent  
    SIdent sprintf "alpha(%f) ", 50 + rnd(50)/50
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "pos(%d, 140) ", 100 + rnd(100)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "size(%d, %d) ", abs(rnd(200))+40, abs(rnd(100))+50
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "colour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent  
    SIdent sprintf "fontcolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent  
    SIdent sprintf "visible(%d) ", (rnd(100) > 80 ? 0 : 1)
    SIdentifier strcat SIdentifier, SIdent
    ;send identifier string to Cabbage
    chnset SIdentifier, "widgetIdent"           
endin


</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 z
i2 0 z
</CsScore>
</CsoundSynthesizer>