List box

Listbox creates a list of custom items. Similary to a combobox in functionality, listboxes can be used for much longer lists that users can scroll through. Double-clicking on a listbox item will send a channel message to Csound.

listbox align("position"), channelType("type"), file("filename"), highlightColour("colour"), items("item1", "item2", ...), numberOfClicks(val), parent(val), populate("filetype", "dir", ignoreVal), sort(val), active(val), alpha(val), bounds(x, y, width, height), caption("string"), channel("chan"), colour("colour"), fontColour("colour"), identChannel("channel"), popup(val), presetIgnore(val), rotate(radians, pivotx, pivoty), visible(val), toFront(), moveBehind("widgetName"), widgetArray("chan", number),

Specific Identifiers


align("position") Aligns the widget's text. "position" should be 'left', 'right' 'centre', or 'top'.


channelType("type") Specifies the type of channel. Default is "float". If you wish to send the text contained in the combobox, for examples the names of a set of audio samples, set type to "string". If type is not set to string the index of the selected item will be sent to Csound on the named channel.


file("filename") This identifier is used across a number of widgets.

combobox and listbox - will load lines from a file as selectable items.
gentable and soundfiler - will load a sound file to display
image - will load an iamge to display (PNG/JPG/SVG)
infobutton - sets the file to display when the button is clicked This can be a local html file, or a URL.
texteditor - sets the file to load, should be a text file.

If a full file path is not given, file() will search in the current directory, i.e., the directory that contains the csd file that is open. It is best to keep all files in the same directory as your csd file. If you wish to keep them in a separate folder use relative paths, i.e, ../../folder.

Avoid absolute path at all costs. Failure to do so will most likely problems with your instruments as soon as you share them.


highlightColour("colour") Sets the colour of the selected text. See above for details on valid colours.


items("item1", "item2", ...) list of items that will populate the combo box. Each item has a corresponding index value. The first item when selected will send a 1, the second item a 2, the third a 3 etc. If this identifier is left out default values of "Item 1", "Item 2", "Item 3", "Item 4" and "Item 5" will be used.

If you wish to use submenus in your combox box, you can use 'items:' followed by a number or a string. The first string you pass to item:..() will be the sub menu heading. For example, the following will create two sub menus called Strings and Woodwind:

combobox bounds(10, 10, 100, 50), items:1("Strings", "Violin", "Viola", "Cello", "Contrabass"), items:2("Woodwind", "Clarinet", "Oboe", "Bassoon")

The index of each item is always determined by where is appear in the widget declaration.


numberOfClicks(val) Sets how many clicks initiate an event. The default for a listbox is 1, but this can set to 2 if you would like events to be sent on a double-click.


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.


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.

If you want to query the widget's current file type or directory you can use fileType or currentDir with cabbageGet.

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.


sort(val) Default is 1. Enables or disables sorting of preset combobox items. If you set this to 0, items will be based on numbers first, alphabetically sorted uppercase items followed by lowercase alphabetically sorted items.

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


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.


colour("colour") This sets the main colour. 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.


fontColour("colour") Sets the colour of the font. In the case of slider this sets teh colour of the font in the value textBox if it is shown.


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.


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.


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.


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

Example

form caption("Listbox Example") size(380, 520), guiMode("queue"), colour(2, 145, 209) pluginId("def1")

texteditor bounds(11, 300, 361, 205) channel("infoText"), readOnly(1), wrap(1), scrollbars(1)

soundfiler bounds(12, 16, 354, 160), channel("soundfiler1"), file("808loop.wav") zoom(.5), colour(147, 210, 0), tableBackgroundColour(0, 0, 0, 0) soundfiler bounds(12, 16, 354, 160), channel("soundfiler2"),file("808loop.wav") zoom(.5), alpha(0), colour(255, 255, 0), tableBackgroundColour(0, 0, 0, 0) listbox bounds(18, 186, 346, 79) channel("samples"), channelType("string"), populate("*.wav", ".") colour(34, 34, 34, 0), value("1") -n -d -+rtmidi=NULL -M0 -m0d --midi-key=4 --midi-velocity-amp=5 ; Initialize the global variables. ksmps = 16 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  = "A listbox can be used to display a list of items. The items can be set using the 'items()' identifier, or by using the 'populate()' identifier, and pointing to a directory on disk. To send the item index, or item string if you set the channel type to 'string', users must double-click the item.\n\nIn this example the listbox points at the current directory, and lists all the '.wav' files it finds there. There are two 'soundfiler' widgets that are used to display the different files. When a user double-clicks a sound file in the list box, it triggers a amplitude fade out on the current audio sample, and a fade in on the next. At the same time, the two soundfiler widgets have their alpha() values modified so they also fade in and out."  

cabbageSet "infoText", "text", SText
kSoundfilerIndex init 1
SSample, kSampleTrig cabbageGetValue "samples"
if kSampleTrig == 1 then

    if active:k(nstrnum("SamplePlayback")) > 0 then
           turnoff2 nstrnum("SamplePlayback"), 1, 1
    endif
           event "i", "SamplePlayback", 0, 1000, kSoundfilerIndex

    kSoundfilerIndex = kSoundfilerIndex < 2 ? kSoundfilerIndex+1 : 1
endif

endin

instr SamplePlayback kEnv madsr 1, 0, 1, 1 print p4 SFilename cabbageGetValue "samples" SSoundfiler sprintf "soundfiler%d", p4 cabbageSet SSoundfiler, sprintfk("file(\"%s\")", SFilename) if filevalid(SFilename) ==1 then iLen = filelen(SFilename)sr kScrubber phasor 1/(iLen/sr) cabbageSet metro(20), SSoundfiler, "scrubberPosition", kScrubberiLen a1, a2 diskin2 SFilename, 1, 0, 1 outs a1kEnv, a1kEnv endif

if kEnv < 1 then
    cabbageSet 1, SSoundfiler, "alpha", kEnv
endif

endin

;causes Csound to run for about 7000 years... i1 0 z

<!--(End Widget Example)/-->
![](../../images/docs/listbox.png)