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", ...), populate("filetype", "dir"), 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), value(val), visible(val), toFront(), 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") Using this identifier will cause Cabbage to load lines from the given file into the combo box. 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, but if you wish to keep them in a sperate folder you can pass a full path to the file() identifier.

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.

populate("filetype", "dir") This will auto-populate the combobox with a set of files from a given directory. Users should specify the file type and the directory to look in. If using a combobox to recall previously recorded preset snapshots you must specify a filetype of "*.snaps". When using the populate() identifier you do not need to use the items() identifier. If no directory is specified, Cabbage will look in the current working directory. 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).

caption("string") The string passed to caption will be the string that appears on the main application window.

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

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

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)