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"), colour:0("colour"), colour:1("colour"), fontColour:0("colour"), fontColour:1("colour"), identChannel("channel"), popup(val), rotate(radians, pivotx, pivoty), imgFile("type", "file"), text("name"), visible(val), toFront(), widgetArray("chan", number),

Specific Identifiers

populate("filetype", "dir", ignoreVal) Sets the type of file to search for, and the initial directory to look in. For example, to set the file type to wave files 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.

mode("mode") Set how the button will behave when pressed. 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

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: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 cabbageSet opcodes instead. They are far more efficient then identifiers channel.

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:

  • "on" : sets the button image when it is on
  • "off" : sets the button image when it is off

For more information see Using SVGs and PNGs

text("name") "name" will be the text that appears on the widget.

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) [!!! 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>