Button (File button)

A filebutton can be used to select files from disk. The filename selected, or created will be sent to Csound on the named channel as a string message. Filebuttons can also be used to select snapshot files for Cabbage to save parameter presets. See the populate identifier below.

filebutton populate("filetype", "dir", ignoreVal), mode("mode"), active(val), alpha(val), bounds(x, y, width, height), channel("chan"), corners(val), colour:0("colour"), colour:1("colour"), fontColour:0("colour"), fontColour:1("colour"), identChannel("channel"), parent(val), popup(val), rotate(radians, pivotx, pivoty), imgFile("type", "file"), text("string"), visible(val), toFront(), moveBehind("widgetName"), widgetArray("chan", number),

Specific Identifiers


populate("filetype", "dir", ignoreVal) Sets the type of file to search for, and the initial directory to look in. If you wish to list all wave files from a set directory, use "*.wav" as the filetype string. If using the filebutton to record parameter snapshots, you must specify a filetype of "*.snaps", and a mode type of snapshot. If no directory is specified, the file browser will open in the current working directory. If the ignoreVal is set to 1 it will ignore the last known location and continue to open from the given directory. If set to 0, or left out completely, the filebutton will always open at the last directory the user browsed to. When used with a combobox, or listbox, it will load all files it finds as selectable items. When clicked, they will send the full file path to Csound.

You can also set the name of the custom preset file. Instead of passing "*.snaps" as the file type, pass the full file name, i.e, "myPresets.snaps". Don't pass a full path here. Cabbage will automatically save and locate from the most suitable directory. Note that the same preset filename should be passed to all filebutton and combobox widgets involved in the management of the presets.


mode("mode")

When used with a filebutton, valid modes are:

  • file, Default. Will open a browser to select a file
  • save, Will open a browser to select an existing file, or write the name of a new file. Note Cabbage will not create this new file, you will need to do that yourself in Csound.
  • directory, Will open the browser to select a folder/directory
  • preset, Will stop the file browser from opening, and instead write a preset file to disk with a default file name. See Presets
  • named preset, Will display a message box with a text editor so that users can name their presets. See Presets
  • remove preset, Will remove the currently select preset from the snapshot XML file. See Presets


When used with a texteditor, it sets multiline mode. Defaults to "single". Use "multi" to enable multiline.

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") 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.


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.


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.


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, 500), guiMode("queue"), colour(2, 145, 209) pluginId("def1")

filebutton bounds(16, 12, 117, 40) channel("loadfile"), text("Load Sample"), corners(5)
button bounds(146, 12, 80, 40) channel("play"), text("Play", "Stop"), corners(5)
button bounds(242, 12, 117, 40) channel("randomSpeed"), text("Random Speed"), corners(5)

texteditor bounds(18, 256, 341, 208) channel("infoText"), readOnly(1), wrap(1), scrollbars(1)
soundfiler bounds(18, 76, 342, 157), channel("soundfiler1"), showScrubber(0), colour(147, 210, 0), tableBackgroundColour(0, 0, 0, 0)

label bounds(18, 230, 341, 24) visible(0), channel("warningLabel"), fontColour("white"), text("Plase load a sample first..."), colour(147, 210, 0)
</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 file buttons can be used in Cabbage. A file button will launch a browser dialogue when clicked. The user selects a file or directory, depending on the mode. When they click Ok, it will return the name of the file or directory they just selected.\n\nIn the example above, a soundfiler widget is used to display the selected file"
    cabbageSet "infoText", "text", SText

    ;load sample to soundfiler - and dismiss wanring if it is showing
    SFilename, kLoadFile cabbageGetValue "loadfile"
    cabbageSet kLoadFile, "soundfiler1", "file", SFilename
    cabbageSet kLoadFile, "warningLabel", "visible", 0

    ;trigger playback of sample
    kPlayState, kPlayTrig cabbageGetValue "play"
    if kPlayTrig == 1 then
        if kPlayState == 1 then
            event "i", "SamplePlayback", 0, -1
        else
            turnoff2 nstrnum("SamplePlayback"), 0, 0
        endif
    endif


endin

instr SamplePlayback

    SFile cabbageGetValue "loadfile"

    if strlen(SFile) == 0 then    
        cabbageSet "warningLabel", "visible", 1
        turnoff        
    else    
        kRandomSpeed init 1
        kRandom, kTrig cabbageGetValue "randomSpeed"    
        kRandomSpeed = (kTrig == 1 ? random:k(-2, 2) : kRandomSpeed)
        a1, a2 diskin2 SFile, kRandomSpeed, 0, 1
        outs a1, a2
    endif

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>