Button

Button creates a button on screen that can be used for a whole range of different tasks. The "channel" string identifies the channel on which Cabbage will communicate with Csound. "OnCaption" and "OffCaption" determine the strings that will appear on the button as users toggle between two states, i.e., 0 or 1. By default these captions are set to "On" and "Off" but the user can specify any strings they wish.

button latched(val), active(val), alpha(val), automatable(val), bounds(x, y, width, height), caption("string"), channel("chan"), corners(val), colour:0("colour"), colour:1("colour"), fontColour:0("colour"), fontColour:1("colour"), identChannel("channel"), outlineColour("colour"), outlineColour("colour"), outlineThickness(value), parent(val), popup(val), presetIgnore(val), radioGroup(val), rotate(radians, pivotx, pivoty), imgFile("type", "file"), text("string"), visible(val), toFront(), moveBehind("widgetName"), widgetArray("chan", number),

Specific Identifiers


latched(val) With latched set to 0 the button will send a message to Csound on the initial mouse press, and once again as soon as the user releases the button. Therefore the button will toggle between 0 and 1 on each click rather than needing two separate mouse clicks.

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.


automatable(val) Default 1. Determines if a widget is automatable by a DAW host. Automatable widgets show up as plug-in parameters in the host. Non-automatable widgets still communicate with Csound but are not accessible by the host. Note that hosts don't allow this parameter to change dynamically -- the plugin will have to be reloaded for any changes to take effect.


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


caption("string") The string passed to caption will be the string that appears on the main application window.


channel("chan") or channel("chan1", "chan2") in the case of widgets that accept two channels such as xypad, soundfiler and range widgets. channel() accepts a string/s that names the channel/s that Cabbage will communicate with Csound on. The current value of this widget can be retrieved in Csound using a chnget, or a cabbageGetValue opcode. Its value can be set using the cabbageSet, or cabbageSetValue opcodes. hrange, vrange, xypad, and soundfiler all take two channels:

hrange, vrange : channel("min", "max") - min and max values

xypad : channel("x", "y") - x and y values

soundfiler : channel("start", "length") - start time and length of user selection, in samples

Channels named should start with a letter and cannot have any white spaces. Note that all widgets should have a unique channel name.


corners(val) Sets the radius size of the widget's corners.


colour:0("colour") This sets the colour of the button when it's value is 0. 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.


colour:1("colour") This sets the colour of the button when it's value is 1. See above for details on valid colours.

You can create an invisible button by setting the colour to something with an alpha value of 0. Images can then be placed under the button to create an image button.


fontColour:0("colour")Sets the colour of the text that appears on the button when it's in its off state. See above for details on valid colours.


fontColour:1("colour") Sets the colour of the text that appears on the button when it's in its on state. See above for details on valid colours.


identChannel("channel") [!!! DEPRECATED !!!] Although identifier channels still work, they are no longer supported. Please use the new guiMode("queue") system and the cabbageGet and cabbageSet opcodes instead. They are far more efficient then identifiers channel.


outlineColour("colour") Sets the colour of a button outline, or a rotary slider`s tracker outline. In the case of rslider's 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.


outlineColour("colour") Sets the colour of a button outline, or a rotary slider`s tracker outline. In the case of rslider's 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.


outlineThickness(value) Sets the thickness of the widget's outline. Set to 0 to disable.


parent(val) This identifier is can be to set a widget's parent. It should only be used when creating widgets dynamically using the cabbageCreate opcode. See plants for more details.


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.


presetIgnore(val) Defaults to 0. Set this to 1 to ignore this widget's value when a preset is taken.


radioGroup(val) Set the radioGroup which this button will belong to. Can be a number or a string.


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.


imgFile("type", "file") Use this identifier to set a unique .svg or .png file to be used instead of the default look and feel. "type" should be one of the following:

Buttons:
- "on" : sets the button image when it is on - "off" : sets the button image when it is off
Sliders:
- "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 and PNGs


text("string") "string" will be the text that appears on the widget. button widgets take two strings, one for on and one for off.


value(val) value sets the initial state of the widget. In the case of a keyboard widget, it sets the leftmost ky to appear.


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 takes no arguments and is only intended for use within the Csound orchestra. it makes no sense to call it when declaring the widget.


moveBehind("widgetName") Moves a widget directly behind another. This identifier should only ever be called from your Csound orchestra using a cabbageSet opcode.

This only works with widgets or plants that have the same parent.


widgetArray("chan", number) [!!! DEPRECATED !!!] Deprecated. Please see the section on Managing large numbers of widgets

colour:1() and fontColour:1() can be set using colour() and fontColour(). However, it's recommended that you use the numerated colour identifiers in order to make your code as readable a possible.

Example

<Cabbage>
form caption("Button Example") size(380, 300), guiMode("queue"), , colour(2, 145, 209) pluginId("def1")

button bounds(16, 12, 117, 40) channel("trigger"), text("Start Synth", "Stop Synth"), corners(5)
button bounds(146, 12, 80, 40) channel("mute"), text("Mute", "Unmute"), corners(5), value(1)
button bounds(242, 12, 117, 40) channel("toggleFreq"), text("Toggle Freq"), corners(5)

texteditor bounds(17, 69, 341, 208) channel("infoText"), readOnly(1), wrap(1), scrollbars(1)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>e
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

; Rory Walsh 2021 
;
; License: CC0 1.0 Universal
; You can copy, modify, and distribute this file, 
; even for commercial purposes, all without asking permission. 

instr 1

    SText  = "This instrument shows an example of how buttons can be used in Cabbage. Button will send a 0 or a 1 when they are pressed. Typically you simply test if they have been pressed and do somthing accordingly.\n\n In this example, each time the \"Start Synth\" button is pressed Csound will either enable or disable the Synth instrument. The other two button show how the instrument can be controlled in real time" 
    cabbageSet "infoText", "text", SText

    kVal, kTrig cabbageGetValue "trigger"

    if kTrig == 1 then
        if kVal == 1 then
            event "i", "Synth", 0, 3600
        else
            turnoff2 nstrnum("Synth"), 0, 0
        endif
    endif

endin

instr Synth

    prints "Starting Synth"
    kMute cabbageGetValue "mute"
    a1 oscili .5*kMute, 300*(cabbageGet:k("toggleFreq")+1)
    outs a1, a1

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
</CsScore>
</CsoundSynthesizer>