Number Box (deprecated, use nslider instead)

Number boxes can be used to create a PureData, Max/MSP style number box. Data can be sent to Csound on the channel specified through the channel string.

numberbox fontSize("colour"), max(val), min(val), range(min, max, value, skew, incr), text("string"), textBox(on/off), textColour("colour"), toFront(), moveBehind("widgetName"), trackerThickness(val), corners(val), active(val), alpha(val), automatable(val), bounds(x, y, width, height), caption("string"), channel("chan"), colour("colour"), fontColour("colour"), identChannel("channel"), popup(val), parent(val), presetIgnore(val), rotate(radians, pivotx, pivoty), visible(val), widgetArray("chan", number), valuePrefix("valuePrefix"),

Specific Identifiers


fontSize("colour") Sets the size of a nslider's font.


max(val) If using a double or triple pointer slider (hslider2, hslider3, vslider2, vslider3), max() will set the default maximum position of the maximum thumb controller. The absolute maximum is set using the range identifier. See above.


min(val) If using a double or triple pointer slider (hslider2, hslider3, vslider2, vslider3), min() will set the default minimum position of the minimum thumb controller. The absolute minimum is set using the range identifier. See above.


range(min, max, value, skew, incr) the first 2 parameters are required. The rest are optional. The first two parameters let you set the minimum value and the maximum value. The next parameter determines the initial value of the slider. The 4th parameter allows you to adjust the skew factor. Tweaking the skew factor will cause the slider to output values in a non linear fashion. A skew of 0.5 will cause the slider to output values in an exponential fashion. A skew of 1 is the default value, which causes the slider to behave is a typical linear form. The final parameter sets the incremental step size for the slider. If you need to have very fine control of steps you may wish to look at using an Endless Encoder instead.

range() can not be updated or modified once a widget has been declared.


text("string") "string" will be the text that appears on the widget. button widgets take two strings, one for on and one for off.


textBox(on/off) textBox takes a 0 or a 1. 1 will cause a text box to appear with the sliders values. Leaving this out will result in the numbers appearing automatically when you hover over the sliders with your mouse.


textColour("colour") This set the colour of the text passed to text(). If you wish to change the colour of the numbers being displayed use fontColour(). See below. See above for details on valid colours.


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.


trackerThickness(val) Sets the thickness of the slider's tracker, 1 being full thickness. This is the line that follows the slider when you move it. To disable the tracker you can set its thickness to 0 or it's alpha colour channel to 0.

Common Identifiers


corners(val) Sets the radius size of the widget's corners.


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


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.


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.


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.


visible(val) A value of 0 will cause the widget to become invisible. Widgets have their visibility set to 1 by default.


widgetArray("chan", number) [!!! DEPRECATED !!!] Deprecated. Please see the section on Managing large numbers of widgets


valuePrefix("valuePrefix") Sets the prefix that is prepended to parameter values when displayed in the host and the plugin GUI. Defaults to "".

Example

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

texteditor bounds(24, 324, 530, 147) channel("infoText"), readOnly(1), wrap(1), scrollbars(1)
image bounds(78, 8, 29, 239) channel("scrubber"), corners(3)
button bounds(478, 260, 76, 26) channel("play"), corners(5), text("Play", "Stop")
button bounds(74, 256, 82, 20) channel("shuffle"), corners(5), text("Shuffle")
button bounds(74, 278, 82, 20) channel("clear"), corners(5), text("Clear")
nslider bounds(12, 10, 57, 22) channel("note0")  range(38, 88, 72, 1, 1) velocity(50)
nslider bounds(12, 40, 57, 22) channel("note1")  range(38, 88, 67, 1, 1) velocity(50)
nslider bounds(12, 70, 57, 22) channel("note2")  range(38, 88, 60, 1, 1) velocity(50)
nslider bounds(12, 100, 57, 22) channel("note3") range(38, 88, 59, 1, 1) velocity(50)
nslider bounds(12, 130, 57, 22) channel("note4") range(38, 88, 57, 1, 1) velocity(50)
nslider bounds(12, 160, 57, 22) channel("note5") range(38, 88, 52, 1, 1) velocity(50)
nslider bounds(12, 190, 57, 22) channel("note6") range(38, 88, 48, 1, 1) velocity(50)
nslider bounds(12, 220, 57, 22) channel("note7") range(38, 88, 36, 1, 1) velocity(50)


rslider bounds(16, 252, 51, 51) channel("randomWeight"), text("Weight") range(0, 100, 90, 1, 0.001)
rslider bounds(224, 252, 51, 51) channel("decay") range(0, 1, 0.3, 1, 0.001), text("Decay")
rslider bounds(278, 252, 91, 51) channel("pw") range(0.2, 0.8, 0.2, 1, 0.001), text("Pulse Width")
rslider bounds(168, 252, 51, 51) channel("tempo") range(2, 8, 4, 1, 2), text("Tempo")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key=4 --midi-velocity-amp=5
</CsOptions>e
<CsInstruments>
; 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  = "An nslider widget function in the same way a number box does in Pure Data or Max/MSP. You can click and drag to make changes to it. Like all sliders in Cababge, you can press the Alt key while dragging to slow down the speed of increments. You can also double click to enter a value with the keyboard.\n\n\This example create 128 checkbox using the 'cabbageCreate' opcode. A perf-time loop runs through each checkbox to see what its value is. If it is on it will trigger a corresponding note. The 8 nslider widgets set the note of each row. The synth here is a simple square wave synth with some PWM. The output of this gets sent to a master FX instrument that adds a little dynamic shaping a two recursive delay lines."
    cabbageSet "infoText", "text", SText

    iX, iY init 0
    iWidgetCount init 0
    iNumSteps = 16
    iNumRows = 8

    while iY < iNumRows do
        while iX < iNumSteps do
            SWidget sprintf "bounds(%d, %d, 25, 25), channel(\"check%d\"), colour:1(147, 210, 0)", 80+iX*30, 10+iY*30, iWidgetCount
            cabbageCreate "checkbox", SWidget
            iWidgetCount += 1
            iX += 1
        od
        iX = 0
        iY += 1
    od

    ;shuffler
    kShuf, kShufTrig cabbageGetValue "shuffle"
    if kShufTrig ==1 then
        kWidget = 0
        while kWidget < 128 do
            SBoxChannel sprintfk "check%d", kWidget
            cabbageSetValue SBoxChannel, random:k(0, 100) > cabbageGet:k("randomWeight") ? 1 : 0
            kWidget += 1
        od
    endif

    ;clear
    kClear, kClearTrig cabbageGetValue "clear"
    if kClearTrig ==1 then
        kWidget = 0
        while kWidget < 128 do
            SBoxChannel sprintfk "check%d", kWidget
            cabbageSetValue SBoxChannel, 0
            kWidget += 1
        od
    endif

    kPlay cabbageGet "play"
    kCol init 0
    kRow = 0
    if metro(cabbageGet:k("tempo")) == 1 && cabbageGetValue:k("play") == 1 then
        while kRow < 8 do
            SBoxChannel sprintfk "check%d", kCol+(kRow*iNumSteps)
            SNoteChannel sprintfk "note%d", kRow
            if cabbageGetValue:k(SBoxChannel) == 1 then
                event "i", "Synth", 0, 1, cabbageGet:k(SNoteChannel), .1
            endif
            kRow += 1
        od
        cabbageSet 1, "scrubber", "bounds", 78+(kCol*30), 8, 29, 239
        kCol = (kCol < iNumSteps - 1 ? kCol+1 : 0) 
    endif

endin

instr Synth
    kEnv expsegr 0.001, 0.01, .5, .1, 0.00001
    aEnv madsr .1, cabbageGetValue:i("decay"), .3, .1
    aSig vco2 kEnv, cpsmidinn(p4), 2, cabbageGetValue:i("pw") 
    aLp K35_lpf aSig, random:i(100, 2000)*aEnv, .1;[, inlp, isaturation, istor]
    outs aLp*p5, aLp*p5
    ;outs aSig, aSig
    chnmix aLp*p5, "out"
endin

instr MasterFx
    aSnapper oscili 1, 2, 1
    aIn chnget "out"
    a1 comb aIn*aSnapper, 3, .5
    a2 comb aIn*aSnapper, 3, .75
    outs a1, a2
    chnclear "out"
endin
</CsInstruments>
<CsScore>
f1 0 4096 7 0 100 1 2000 1 47 0
i1 0 z
i"MasterFx" 0 z
</CsScore>
</CsoundSynthesizer>