Label

Labels can be used for placing text on-screen.

label align("position"), corners(val), fontSize("colour"), active(val), align("position"), alpha(val), bounds(x, y, width, height), channel("chan"), colour("colour"), fontColour("colour"), identChannel("channel"), parent(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'.


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


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

fontStyle("style") Sets the style of the font. Valid styles are, "plain", "bold"(default), "bold italic", "italic", "underlined", "bold underlined", "italic underlined" and "bold italic underlined".

text("text") "text" will be the string to appear on the label

Common Identifiers


active(val) Will deactivate a control if 0 is passed. Controls which are deactivate can still be updated from Csound.


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


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


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.


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.


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.


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

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

texteditor bounds(12, 244, 352, 228) channel("infoText"), readOnly(1), wrap(1), scrollbars(1)
label bounds(38, 6, 303, 26) channel("heading"), text("LABELS WILL BE LABELS"), fontColour(255, 255, 255, 255)
</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  = "A label is a simple widget that can be used to display text the screen. They can act as simple buttons sending a 0 or 1 when they are clicked. Press once for 1, press again for 0, again for 1, etc.\n\nInstrument 1 creates 16 labels in a loop, each with a channel name 'label1', 'label2', 'label3', etc. This is done dynamically using the 'cabbageCreate' opcode. A metro in instr 1 triggers the various labels to appear, and controls both position and fontColour alpha values as the labels are displayed."
    cabbageSet "infoText", "text", SText

    iWidgetCount init 0
    while iWidgetCount < 16 do
        SWidget sprintf "bounds(%d, %d, 200, 23), channel(\"label%d\"), text(\"Cabbage Label %d\"), fontColour(147, 210, 0, 0)", random:i(0, 330), random:i(0, 200), iWidgetCount, iWidgetCount
        cabbageCreate "label", SWidget
        iWidgetCount += 1
    od   

    kIndex init 1
    if metro(4) == 1 then
        event "i", "DisplayLabel", 0, 2, kIndex+1
        kIndex = (kIndex < 16 ? kIndex+1 : 0)
    endif

endin

instr DisplayLabel

    SWidgetChannel sprintf "label%d", p4
    iColour[] cabbageGet SWidgetChannel, "fontColour"
    kAlpha line 255, p3, 0    
    cabbageSet SWidgetChannel, "bounds", random:i(-100, 360), random:i(50, 200), 200, 23
    cabbageSet metro(10), SWidgetChannel, "fontColour", iColour[0], iColour[1], iColour[2], kAlpha

endin


</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 z
</CsScore>
</CsoundSynthesizer>