Keyboard

Keyboard will display a keyboard that will send MIDI information to your Csound instrument. This component can be used together with a hardware controller. Pressing keys on the actual MIDI keyboard will cause the on-screen keys to react up.

keyboard keyseperatorcolour("colour"), mouseOverKeyColour("colour"), keypressBaseOctave(val), whiteNoteColour("colour"), blackNoteColour("colour"), arrowBackgroundColour("colour"), keysdowncolour("colour"), arrowColour("colour"), keyWidth(val), middleC(val), scrollbars(val), bounds(x, y, width, height), identChannel("channel"), channel("chan"), toFront(), moveBehind("widgetName"), parent(val), visible(val),

Specific Identifiers


keyseperatorcolour("colour") This sets the colour of the spaces between the notes on the keyboard. 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.


mouseOverKeyColour("colour") This sets the colour of the key currently under the mouse in the keyboard widget. 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.


keypressBaseOctave(val) This sets the base note that is played when you press a key on the computer keyboard. The value must be between 0 and 10. The default is 3 that means the C note of the third MIDI octave (C1 key on the widget keyboard, if you don't change the default 'middleC' value).


whiteNoteColour("colour") This sets the colour of the white notes of the keyboard. 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.


blackNoteColour("colour") This sets the colour of the black notes of the keyboard. 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.


arrowBackgroundColour("colour") This sets the background colour of the arrows by the left and right hand side of the keys in the keyboard widgets. 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.


keysdowncolour("colour") This sets the colour of the key when a MIDI note is pressed on an external MIDI keyboard, or through the PC's ASCII keyboard. 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.


arrowColour("colour") This sets the colour of the arrows by the left and right hand side of the keys in the keyboard widgets. 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.


keyWidth(val) Set the width of the keys in pixels.


middleC(val) Sets the octave number that will appear on the middle C key. By default this is set to 3.


scrollbars(val) Sets whether the widget will show scrollbars or not.


value(val) value sets the initial state of the widget. In the case of a keyboard widget, it sets the leftmost ky to appear.

Common Identifiers


bounds(x, y, width, height) integer values that set position and size on screen(in pixels).


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.


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.


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.


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.


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

The keyboard can be played at different velocities depending on where you click on the key with your mouse. Clicking at the top of the key will cause a quieter velocity while clicking on the bottom will cause the note to sound with full velocity. If you wish to play the keyboard like a nutjob in standalone mode, make sure to pass '-m0d' to the CsOptions(disable console messages). The keyboard widget is only provided as a quick and easy means of testing plugins in the Cabbage IDE. Treating it as anything more than that could result in severe disappointment!

Example

<Cabbage>
form size(465, 505), caption("Keyboard Example"), guiMode("queue"), pluginId("plu1")
keyboard bounds(6, 148, 445, 92)
groupbox bounds(6, 6, 223, 134), text("LFO"), colour(0,0,0,0), fontColour("white")
groupbox bounds(232, 6, 223, 134), text("Filter"), colour(0,0,0,0), fontColour("white")

rslider bounds(16, 32, 100, 100), channel("rate"), textColour("white"), range(0, 10, 1, 1, 0.01), text("rate")
rslider bounds(118, 32, 100, 100), channel("intensity"), textColour("white") range(0, 1, 0, 1, 0.01), text("intensity") 
rslider bounds(246, 32, 100, 100), channel("resonance"), textColour("white") range(0, 1, 0, 1, 0.01), text("res")
rslider bounds(348, 32, 100, 100), channel("cutoff"), textColour("white"), text("cutoff"), colour("white"), range(0, 22050, 10000)

checkbox bounds(10, 252, 65, 20), colour:1(147, 210, 0), channel("cutoffCheckbox"), radioGroup(99) value(1), text("cutoff"), 
checkbox bounds(74, 252, 58, 20), colour:1(147, 210, 0), channel("pitchCheckbox"), radioGroup(99) text("pitch"),

combobox bounds(284, 250, 100, 25), populate("*.snaps"), channel("combo1")
filebutton bounds(222, 250, 60, 25), text("Save", "Save"), populate("*.snaps"),mode("named preset") channel("filebutton1") value(0)
filebutton bounds(386, 250, 60, 25), text("Remove"), populate("*.snaps", "test"), mode("remove preset")

texteditor bounds(10, 288, 438, 209) channel("infoText"), readOnly(1), wrap(1), scrollbars(1)

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -m0d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 64
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  = "A keyboard widget is a simple virtual keyboard that can be used to trigger instruments in Csound. By default it will trigger 'instr 1' on channel 1, 'instr 2' on channel 2 and so on. You can reassign the channels using the 'massign' opcodes in Csound.\n\nIt is set up to use midi note number 60 as C4 bu this can be changing. The keyboard is velocity sensitive. Pressing a key higher up the note will result in a quieter note.\n\nIn this instrument we are sending p4 and p5 to instrument 1. What those p-fields represent is set in the CsOptions section. In this case p4 is the MIDI note number, while p5 is an amplitude value between 0 and 1." 
    cabbageSet "infoText", "text", SText

endin

instr 1
    kDeClick madsr .1, 0, 1, .1
    kAmp cabbageGet "intensity"
    kFreq cabbageGet "rate"
    kRes cabbageGet "resonance"
    kPitch cabbageGet "pitchCheckbox"
    kCutoff cabbageGet "cutoff"
    kLfo lfo kAmp, kFreq, 5

    if kPitch==0 then
        aSig vco2 p5, p4
        aMoog moogladder aSig, (kAmp == 0 ? kCutoff : kLfo*kCutoff), kRes
    else
        aSig vco2 p5, (kAmp == 0 ? p4 : p4 -(1-kLfo*p4*.5))
        aMoog moogladder aSig, kCutoff, kRes
    endif

    outs aMoog*kDeClick, aMoog*kDeClick

endin


</CsInstruments>  
<CsScore>
f1 0 1024 10 1
i99 0 z
f0 3600
</CsScore>
</CsoundSynthesizer>