Skip to content
Cabbage
Install

Widgets

File Button

fileButton creates a button that opens a native file browser dialog. When clicked, it allows users to select files from their system. The selected file path is sent as a string value through the widget’s channel, enabling dynamic audio file loading and other file-based operations in Csound.

fileButton.csd
Download .csd
"active": true

Will deactivate a control if false is set (use 0/1 to update from Csound). Controls which are deactivated can still be updated from Csound. Any widget that has its active property set to false will allow all mouse-clicks to pass through it.

"automatable": true

Defaults to true. Determines if a widget is automatable by a host DAW. Automatable widgets show up as plug-in parameters in the host. Non-automatable widgets can still communicate with Csound but are not accessible by the host. Note that hosts don't allow this parameter to change dynamically. If you change this setting, the plugin will need to be reloaded.

"bounds": {"left":0, "top":0, "width":100, "height":100}

Integer values that set position and size on screen(in pixels).

"channels": [
{
"id": "channelName",
"label": { "name": "Channel Name", "prefix": "", "suffix": "" },
"event": "valueChanged",
"type": "number",
"range": {"min":0, "max":100, "defaultValue":0, "skew":1, "increment":0.1}
}
]

In Cabbage 3, widgets use an array of channels instead of a single channel string. Each channel object includes an id that defines a unique channel name. Widgets in Cabbage 3 can have any number of channels attached to them. An optional label object controls how the parameter appears in DAW parameter editors and automation lanes; if omitted, the id is used. An optional event property specifies the type of interaction. A range object can define the minimum, maximum, and default values, along with the skew and step increment. The type is set to number by default. Each widget sets its own type, number or string. A "string" channel carries text (readable with the string variant of cabbageGetValue), persists through session saves, and is excluded from DAW automation. See Persisting Custom UI State.

Channel label: DAW display name

The label object separates the internal channel identifier from the display name shown in DAWs, and allows a prefix and suffix to be appended to the parameter's value string in the DAW. This is useful when you want short, code-friendly channel IDs (e.g., hrm1, hrm2) while showing descriptive names in the DAW (e.g., Harmonic 1, Harmonic 2). Csound code always uses the id for channel access via cabbageGetValue and cabbageSetValue.

FieldDescription
name Human-readable parameter name shown in the DAW (required if using label)
prefix String prepended to the value in the DAW's value display (optional)
suffix String appended to the value in the DAW's value display (optional)

If range is omitted, it defaults to a range from 0 to 1, with increments of 0.001 for widgets that use drag events (e.g., sliders, XY pads) and 1 for widgets that use click or toggle events (e.g., buttons, checkboxes).

Note on increment parameter behavior:

The increment parameter quantizes all values sent to Csound channels, ensuring they snap to the specified step size. For example, with increment: 0.1, values will be rounded to 0.0, 0.1, 0.2, etc. before reaching Csound.

The DAW host automation has additional constraints:

  • increment >= 1.0: The host will display discrete integer steps (e.g., move from 1 to 2 to 3, etc.) in its native controls, and enforce these steps during automation.
  • increment < 1.0: The host displays a continuous slider.

Cabbage always quantizes values internally before sending to Csound.

Supported event types:

EventDescription
valueChanged (default)Tracks simple value changes
mousePressLeftTracks presses of left mouse button
mousePressRightTracks presses of right mouse button
mousePressMiddleTracks presses of middle mouse button
mouseMoveXTracks movement along X axis.
mouseMoveYTracks movement along Y axis.
mouseDragXTracks movement along X axis with mouse pressed
mouseDragYTracks movement along Y axis with mouse pressed
mouseInside Returns max when any mouse button is within the bounds of the widget, min if outside.

The fileButton channel returns a string value containing the full path to the selected file. Use cabbageGetValue in Csound to retrieve both the file path and a trigger value (1 when a new file is selected, 0 otherwise).

Type: String Default: ""

Sets the initial directory that the file browser will open in. If empty, the browser opens in the system’s default location or the last known location (depending on openAtLastKnownLocation).

"directory": "/Users/username/audio_files"

Type: String Default: "*"

Specifies file type filters for the file browser. Use wildcards to filter by extension. Multiple filters can be separated by semicolons.

"filters": "*.wav;*.aif;*.mp3"

For all files, use "*" or "*.*".

"id": "widgetId"

This optional channel can be used to define a top-level line of communication between the instrument’s UI and Csound. It is reserved for UI updates only. If omitted, it defaults to the first id from the channels array. Its primary purpose is to help produce clearer code, especially for widgets with multiple channels.

"label": {
"text": {
"off": "Start",
"on": "Stop"
},
"align": "center"
}

Configures the label shown inside widgets that switch between off/on states, such as button and fileButton.

  • text.off: string — the text shown when the widget value is 0.
  • text.on: string — the text shown when the widget value is 1.
  • align: string — optional text alignment for widgets that support it, such as button.

Typography and colors are configured via style.*, including style.on.textColor, style.off.textColor, and related state styles.

Type: String Default: "file"

Determines whether the file browser selects files or directories.

  • "file": Select a single file (default)
  • "directory": Select a directory/folder
"mode": "directory"

Type: Boolean Default: true

When true, the file browser will open at the location of the last selected file. When false, it opens at the location specified by directory (or the system default if directory is empty).

"openAtLastKnownLocation": false
"persistence": {
"preset": true,
"session": true
}

Controls whether a widget's state is saved in DAW presets and Csound session files. Both properties default to true.

  • preset: When true, the widget's current value/state is included when using Csound's cabbageSaveState opcode to save preset data. Set to false for widgets that should not persist in Csound preset files (e.g., widgets that load presets).
  • session: When true, the widget's state is included when the DAW saves a preset. Set to false for widgets that should not have their values loaded/saved when a DAW session loads (e.g., widgets that load presets).

Auto-cascade behavior: If you set preset to false without explicitly setting session, the system automatically sets session to false as well. This prevents state from being saved anywhere unless explicitly requested.

"visible": true

A value of true will cause the widget to become invisible (use 0/1 to update from Csound). Widgets have their visibility set to true by default.

"zIndex": 1

Sets the stacking order of the widget. Widgets with higher zIndex values will appear in front of widgets with lower values. Default is 1.

"style": {
"opacity": 1,
"borderRadius": 4,
"borderWidth": 0,
"borderColor": "#dddddd",
"on": {
"backgroundColor": "#3d800a",
"textColor": "#dddddd"
},
"off": {
"backgroundColor": "#3d800a",
"textColor": "#dddddd"
},
"hover": {
"backgroundColor": "#4ca10c",
"textColor": "#dddddd"
},
"active": {
"backgroundColor": "#2d6008",
"textColor": "#dddddd"
}
},
  • Colors accept named CSS colors, hex (e.g., #RRGGBB or #RRGGBBAA), or rgb/rgba strings.
  • The label text is configured under label.text.on and label.text.off.
  • Border radius/width/color control the button outline.

The fileButton returns a string containing the file path and a k-rate trigger value. The trigger value will be 1 for one k-cycle when a new file is selected, then return to 0. Read it with the CabbageStrTrig struct form of cabbageGetValue:

file:CabbageStrTrig = cabbageGetValue("audioFile")
if file.trig == 1 then
cabbageSet("infoText", "text", file.val)
endif
fileButton.csd
<Cabbage>
{
"pluginId" : "def1",
"enableDevTools": true,
"channelConfig" : [ {"name": "0 in 2 out", "ins": "0", "outs": "2"} ],
"widgets" : [
{
"type" : "form",
"caption": "File Button Example",
"size" : {"width": 400, "height": 300},
"guiMode": "queue"
},
{
"type" : "fileButton",
"bounds" : {"left": 20, "top": 20, "width": 120, "height": 30},
"channels": [ {"id": "audioFile"} ],
"label" : { "text": {"off": "Choose File", "on": "Choose File"} },
"filters" : "*.wav;*.aif;*.mp3",
"mode" : "file"
},
{
"type" : "textEditor",
"bounds" : {"left": 20, "top": 62, "width": 360, "height": 80},
"channels": [ {"id": "infoText"} ],
"label" : {"text": "No file selected"},
"readOnly": 1,
"wrap" : 1
}
]
}
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0
</CsOptions>
<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 Loader
file:CabbageStrTrig = cabbageGetValue("audioFile")
if file.trig == 1 then
if active:k(nstrnum("Player")) > 0 then
turnoff2(nstrnum("Player"), 0, 0)
endif
event("i", "Player", 0, 3600)
endif
endin
instr Player
path:S = cabbageGetValue("audioFile")
cabbageSet("infoText", "label.text", path)
if filevalid(path) == 1 then
if filenchnls(path) == 2 then
sigL:a, sigR:a = diskin2(path, 1, 0, 1)
outs(sigL, sigR)
else
sig:a = diskin2(path, 1, 0, 1)
outs(sig, sig)
endif
else
prints("File not found: %s\n", path)
turnoff()
endif
endin
</CsInstruments>
<CsScore>
;starts the loader and runs it for a week
i"Loader" 0 z
</CsScore>
</CsoundSynthesizer>