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"), mouseoeverkeycolour("colour"), whitenotecolour("colour"), blacknotecolour("colour"), arrowbackgroundcolour("colour"), arrowcolour("colour"), keywidth(val), middlec(val), scrollbars(val), value(note), bounds(x, y, width, height), identchannel("channel"), tofront(), 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.

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

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.

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) Enables or disables scrolling up and down through octaves. Enabled by defaut.

value(note) sets the note on the leftmost side of the keyboard when it appears on-screen. Middle C, 60, is the default.

Common Identifiers

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

identchannel("channel") Sets the channel which data is sent and retrieved from Csound. When used with a chnset opcode users can override widget attributes. See Identifier channels

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.

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 Cabbage. Treating it as anything more than that could result in severe disappointment!

Example

<Cabbage>
form size(400, 300), caption("Keyboard"), pluginID("plu1")
keyboard bounds(10, 10, 385, 160), identchannel("widgetIdent")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key=4
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

;basic usage
instr 1 
a1 oscil 1, cpsmidinn(p4)
outs a1, a1
endin        

;WIDGET_ADVANCED_USAGE

instr 2
    if metro(1) == 1 then
        event "i", "ChangeAttributes", 0, 1
    endif
endin

instr ChangeAttributes
    SIdentifier init ""
    SIdent sprintf "keyseperatorcolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "mouseoeverkeycolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "whitenotecolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "blacknotecolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "arrowbackgroundcolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "arrowcolour(%d, %d, %d) ", rnd(255), rnd(255), rnd(255)
    SIdentifier strcat SIdentifier, SIdent
    SIdent sprintf "keywidth(%d) ", 20+rnd(20)
    SIdentifier strcat SIdentifier, SIdent
    ;send identifier string to Cabbage
    chnset SIdentifier, "widgetIdent"           
endin


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