Skip to content
Cabbage
Install

Widgets

GenTable

genTable creates a table widget on screen that can be used to display the contents of a function table or the contents of a file. When selectableRegions is enabled, users can interactively select portions of the waveform by clicking and dragging.

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

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. The default varies by widget: most interactive controls default to true, while display-only widgets such as label, image and csoundOutput default to false.

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": "gentableStart",
"event": "valueChanged",
"range": { "min": 0, "max": -1 }
},
{
"id": "gentableLength",
"event": "valueChanged",
"range": { "min": 0, "max": -1 }
}
]

The genTable has two default channels that provide information about the current selection. Note these channels are only valid if selectableRegions is set to true.

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

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.

"fill": 1

Fill determines if the genTable waveform should be filled or drawn as an outline. Set to 1 for filled, 0 for outline.

"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": "",
"offsetY": 0,
"offsetX": 0,
"align": "center"
}

Configures the widget label displayed near the control.

  • text: the label text.
  • offsetY: vertical offset applied when the label is rendered outside the control (pixels).
  • offsetX: horizontal offset applied when the label is rendered outside the control (pixels).
  • align: label alignment for widgets that support it, such as groupBox, rotarySlider and numberSlider. numberSlider also accepts left and right to place the label beside the value.

For the slider widgets with a nested style.label object (horizontalSlider, verticalSlider, rotarySlider and numberSlider), typography is set under style.label.*. Other widgets use style.fontFamily, style.fontSize, style.fontColor and style.textAlign.

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

"range": {"y": {"min": -1, "max": 1}}

Sets the vertical display range of the genTable waveform. min and max define the values shown at the bottom and top of the widget.

"range": {"x": {"start": 0, "end": -1}}

Sets the visible sample range on the genTable's X axis. start and end are sample indices; an end of -1 uses the last sample. These values can be changed in real-time to enable zooming.

"samples": []

Samples contains the audio sample data for genTable widgets. This is typically managed internally by Cabbage.

"selectableRegions": true

When enabled, users can click and drag on the waveform to select a region of samples. The selected region is highlighted with a semi-transparent overlay.

Behavior:

  • Click and drag: Select a region by clicking on the waveform and dragging to define the selection boundaries
  • Click without drag: Clicking without dragging (less than 3 pixels of movement) clears the current selection
  • Visual feedback: Selected regions are shown with a semi-transparent overlay
  • Channel output: When a region is selected, the start and end sample indices are automatically sent to Csound via the configured channels (see channelGentable)

This feature is useful for selecting portions of audio for processing, looping, or analysis.

"tableNumber": 1

Sets the function table to be displayed by the genTable widget.

"visible": true

A value of true shows the widget; set it to false to hide it (use 0/1 to update from Csound). Widgets are visible by default.

"zIndex": 0

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

"style": {
"opacity": 1,
"borderRadius": 4,
"borderWidth": 1,
"borderColor": "#dddddd11",
"strokeColor": "#dddddd",
"strokeWidth": 1,
"fillColor": "#ffffff11",
"backgroundColor": "#00000000",
"fontFamily": "Verdana",
"fontSize": "auto",
"fontColor": "#dddddd",
"textAlign": "left",
"logarithmic": false
},
  • backgroundColor fills the area behind the waveform, while fillColor is the waveform colour when fill is 1.
  • strokeColor and strokeWidth control the waveform outline when fill is 0.
  • logarithmic displays the waveform using logarithmic scaling.
  • Label typography is configured with fontFamily, fontSize, fontColor and textAlign.
  • Colors accept named CSS colors, hex (e.g., #RRGGBB or #RRGGBBAA), or rgb/rgba strings.

The genTable display is kept in sync from Csound with cabbageSet. Use the trigger value from a widget channel to gate the update so the table only redraws when something changes:

fillRes:CabbageNumTrig = cabbageGetValue("fill")
cabbageSet(fillRes.trig, "gentable1", "fill", fillRes.val)
cabbageSet("gentable1", "tableNumber", 1)

To fill the table with your own samples, regenerate its function table in Csound and then point the widget at it with tableNumber. The example below rebuilds table 1 from five harmonic amplitudes passed as p4–p8, optionally inverting it, and refreshes the display:

instr UpdateTable
normal:i = (cabbageGetValue:i("normal") == 0 ? -1 : 1)
sumTable = ftgen(1, 0, 1024, 10*normal, p4, p5, p6, p7, p8)
cabbageSet("gentable1", "tableNumber", 1) ; update table display
endin

Related slider values are read at k-rate in the usual way, and a changed trigger fires the update instrument only when one moves:

harm1:k = cabbageGetValue("harm1")
trigger:k = changed(harm1, harm2, harm3, harm4, harm5)
if trigger == 1 then
event("i", "UpdateTable", 0, .01, harm1, harm2, harm3, harm4, harm5)
endif
gentable.csd
<Cabbage>
{
"pluginId" : "def1",
"enableDevTools": true,
"channelConfig" : [ {"name": "0 in 2 out", "ins": "0", "outs": "2"} ],
"widgets" : [
{ "type": "form", "caption": "Gentable Example", "size": {"width": 400, "height": 650}, "guiMode": "queue" },
{ "type": "genTable", "bounds": {"left": 10, "top": 7, "width": 380, "height": 200}, "id": "gentable1", "tableNumber": 1 },
{
"type" : "horizontalSlider",
"bounds" : {"left": 14, "top": 212, "width": 368, "height": 14},
"channels": [
{ "id": "harm1", "range": {"min": 0, "max": 1, "value": 1, "skew": 1, "increment": 0.01} }
],
"label" : {"text": "Harm1"}
},
{
"type" : "horizontalSlider",
"bounds" : {"left": 14, "top": 244, "width": 368, "height": 14},
"channels": [
{ "id": "harm2", "range": {"min": 0, "max": 1, "value": 0, "skew": 1, "increment": 0.01} }
],
"label" : {"text": "Harm2"}
},
{
"type" : "horizontalSlider",
"bounds" : {"left": 14, "top": 276, "width": 368, "height": 14},
"channels": [
{ "id": "harm3", "range": {"min": 0, "max": 1, "value": 0, "skew": 1, "increment": 0.01} }
],
"label" : {"text": "Harm3"}
},
{
"type" : "horizontalSlider",
"bounds" : {"left": 14, "top": 308, "width": 368, "height": 14},
"channels": [
{ "id": "harm4", "range": {"min": 0, "max": 1, "value": 0, "skew": 1, "increment": 0.01} }
],
"label" : {"text": "Harm4"}
},
{
"type" : "horizontalSlider",
"bounds" : {"left": 14, "top": 340, "width": 368, "height": 14},
"channels": [
{ "id": "harm5", "range": {"min": 0, "max": 1, "value": 0, "skew": 1, "increment": 0.01} }
],
"label" : {"text": "Harm5"}
},
{
"type" : "checkBox",
"bounds" : {"left": 16, "top": 380, "width": 120, "height": 20},
"channels": [ {"id": "normal"} ],
"label" : {"text": "Normalise"},
"value" : 1
},
{
"type" : "checkBox",
"bounds" : {"left": 140, "top": 380, "width": 120, "height": 20},
"channels": [ {"id": "fill"} ],
"label" : {"text": "Fill Table"},
"value" : 1
}
]
}
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-d -n -m0d
</CsOptions>
<CsInstruments>
;sr is set by the host
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.
sumTable@global:i = ftgen(1, 0, 1024, 10, 1)
//fill table with default values
schedule("UpdateTable", 0, 0, 1, 0, 0, 0, 0, 0)
instr 1
;toggle fill
fillRes:CabbageNumTrig = cabbageGetValue("fill")
cabbageSet(fillRes.trig, "gentable1", "fill", fillRes.val)
harm1:k = cabbageGetValue("harm1")
harm2:k = cabbageGetValue("harm2")
harm3:k = cabbageGetValue("harm3")
harm4:k = cabbageGetValue("harm4")
harm5:k = cabbageGetValue("harm5")
outSig:a = oscili(.2, 200, 1)
outs(outSig, outSig)
trigger:k = changed(harm1, harm2, harm3, harm4, harm5)
if trigger==1 then
;if a slider changes trigger instrument 2 to update table
event("i", "UpdateTable", 0, .01, harm1, harm2, harm3, harm4, harm5)
endif
endin
instr UpdateTable
normal:i = (cabbageGetValue:i("normal")==0 ? -1 : 1)
sumTable = ftgen(1, 0, 1024, 10*normal, p4, p5, p6, p7, p8)
cabbageSet("gentable1", "tableNumber", 1) ; update table display
endin
</CsInstruments>
<CsScore>
f1 0 1024 10 1
i1 0 [3600*24*7]
</CsScore>
</CsoundSynthesizer>

Files can be loaded straight into a genTable widget. The example below uses a fileButton to pick a file and cabbageSet to load it:

gentableFile.csd
<Cabbage>
{
"pluginId" : "def1",
"enableDevTools": true,
"channelConfig" : [ {"name": "0 in 2 out", "ins": "0", "outs": "2"} ],
"widgets" : [
{ "type": "form", "caption": "Gentable Example", "size": {"width": 400, "height": 650}, "guiMode": "queue" },
{
"type" : "genTable",
"bounds" : {"left": 10, "top": 7, "width": 380, "height": 200},
"id" : "gentable1",
"tableNumber" : 1,
"selectableRegions": true
},
{
"type" : "fileButton",
"bounds" : {"left": 14, "top": 212, "width": 80, "height": 24},
"channels": [ {"id": "fileToOpen"} ],
"text" : {"off": "Open File", "on": "Open File"}
}
]
}
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-d -n -m0d
</CsOptions>
<CsInstruments>
;sr is set by the host
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 1
fileRes:CabbageStrTrig = cabbageGetValue("fileToOpen")
printf("File selected:%s", fileRes.trig, fileRes.val)
cabbageSet(fileRes.trig, "gentable1", "file", fileRes.val)
endin
</CsInstruments>
<CsScore>
f1 0 1024 10 1
i1 0 [3600*24*7]
</CsScore>
</CsoundSynthesizer>

Download gentableFile.csd