Combo Box

Combobox creates a drop-down list of items which users can choose from. Once the user selects an item, the index of their selection will be sent to Csound on a channel named by the channel string. The default value is 0. The first item in the combobox will be seen as a 1, while 0 refers to no current selection.

A combobox can also be set up a work with strings. In this case Csound will receive the currently selected string instead of the current index. Note that using a combobox in this way renders it useless in terms of host automation. Host automation can only be achieved when a combobox is sending the current index, rather than the current string.

combobox align("position"), channelType("type"), file("filename"), items("item1", "item2", ...), populate("filetype", "dir"), active(val), alpha(val), automatable(val), bounds(x, y, width, height), channel("chan"), colour("colour"), fontColour("colour"), identChannel("channel"), popup(val), presetIgnore(val), protectedItems(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.

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.

automatable(val) Default 1. Determines if a widget is automatable by a DAW host. Automatable widgets show up as plug-in parameters in the host. Non-automatable widgets still communicate with Csound but are not accessible by the host. Note that hosts don't allow this parameter to change dynamically -- the plugin will have to be reloaded for any changes to take effect.

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

protectedItems(val) Defaults to 0. Sets the number of read-only presets. Use this to protect certain presets from being overwritten. For example, a value of 3 will prevent users from overwritting the first three presets.

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.

<!--UPDATE WIDGETINCSOUND SIdent sprintf "value(%f) ", rnd(1) SIdentifier strcat SIdentifier, SIdent --> Comboboxes indices start at 1, not 0. If you set the initial value to 0 the combobox will not show any items.

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

<Cabbage>
form caption("Combobox Example") size(380, 500), guiMode("queue"), colour(2, 145, 209) pluginId("def1")

rslider bounds(12, 9, 86, 90), channel("att"), range(0, 1, 0.01, 1, 0.001), text("Att.")
rslider bounds(99, 9, 86, 90), channel("dec"), range(0, 1, 0.4, 1, 0.001), text("Dec.")
rslider bounds(187, 9, 86, 90), channel("sus"), range(0, 1, 0.7, 1, 0.001), text("Sus.")
rslider bounds(274, 9, 86, 90), channel("rel"), range(0, 1, 0.8, 1, 0.001), text("Rel.")

texteditor bounds(18, 256, 341, 208) channel("infoText"), readOnly(1), wrap(1), scrollbars(1)
keyboard bounds(12, 104, 348, 80) channel("keyboard")
combobox bounds(260, 188, 100, 30) channel("waveform"), colour:0(147, 210, 0), corners(5), items("Saw", "Square", "Triangle")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key=4 --midi-velocity-amp=5
</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 99

    SText  = "An combobox used to toggle through different items. The widget will send its current index to is associated channel, starting from 1*.\n\nIn this example an combobox can be used to select a given waveform. We can't just pass these indices to the vco2 opcode. Instead we use them as indices to simple array that hold the appropriate vco2 waveform modes.\n\n [A combobox always start with index 1, not 0]"
    cabbageSet "infoText", "text", SText

endin

instr 1

    iVcoModes[] fillarray 0, 10, 12    
    iAtt cabbageGetValue "att"
    iDec cabbageGetValue "dec"
    iSus cabbageGetValue "sus"
    iRel cabbageGetValue "rel"
    kEnv madsr iAtt, iDec, iSus, iRel
    aVco vco2 kEnv*p5, cpsmidinn(p4), iVcoModes[cabbageGetValue:i("waveform")-1]
    outs aVco, aVco    

endin


</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
i99 0 z
</CsScore>
</CsoundSynthesizer>