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"), 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), svgfile("type", "file"), text("name"), visible(val), tofront(), widgetarray("chan", number),

Specific Identifiers

populate("filetype", "dir") 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.

mode("mode") Set how the button will behave when pressed. Valid modes are:

  • file, Default. Will let the browser to select a file
  • directory, Will let the browser to select a folder/directory
  • snapshot, Will stop the file browser from opening, and instead will write a preset file to disk with a default file name. 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") 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.

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.

svgfile("type", "file") Use this identifier to set a unique .svg file to use 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

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) Creates a number of widgets in a single pass. See Widget arrays

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("File Button Example") size(400, 300), colour(220, 220, 220), pluginID("def1")
label bounds(8, 6, 368, 20), text("Basic Usage"), fontcolour("black")
groupbox bounds(8, 110, 380, 177), text("Randomly Updated Identifiers")
filebutton bounds(108, 30, 150, 50), channel("filebutton1"), text("Browsse", "Browsse") value(0) file("/Users/walshr/sourcecode/cabbage/Examples/Widgets/Sliders.csd")
button bounds(146, 140, 68, 127) identchannel("widgetIdent")
texteditor bounds(10, 84, 379, 21), text(""), identchannel("editorIdent")
</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
SFile chnget "filebutton1" 
    if changed(SFile)== 1 then
        printf "%s\n", k(1), SFile
        SMessage sprintfk "text(\"Selected File:%s\") ", SFile
        chnset SMessage, "editorIdent"
    endif
endin

;WIDGET_ADVANCED_USAGE

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

instr ChangeAttributes
    SIdentifier init ""
    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:0(%d, 255, 255) ", rnd(255)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "colour:1(%d, 0, 255) ", rnd(255)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "fontcolour:0(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "fontcolour:1(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent   
    SIdent sprintf "text(\"TextOff %f\", \"TextOn %f\") ", rnd(100), rnd(100)
    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>