GMKeyboard is a piano keyboard emulation widget, with visual feedback.
It includes two displays modes : diatonic
or chromatic
.
It also provides an easy way to be controlled by a HID (a computer keyboard or a MIDI device). See the example section for a detailed example of this functionality.
Creates a new instance of GMKeyboard.
Its graphical properties are defined by its associated GMStyle.
Sets or gets the Function to be triggered when the button is pressed down. This Function takes an Integer argument: the index of the pressed key. If sustainMode
is set to true
, the action will take a second argument : a Boolean indicating if the key has been pressed or released.
Sets or gets wether the keyboard only responds to mouseDownAction
, or if it emits two different actions when pressed or released (see action
).
Sets or gets the number of displayed keys.
Sets or gets the keyboard display mode. Valid values are either \diatonic
or \chromatic
.
Changing mode will reset names and highlights.
In chromatic
mode, sets or gets the offset of the keyboard representation.
For example, with a value of 3, the keyboard representation would start with the 'Eb' key instead of the 'C' key.
Sets or gets wether labels should be displayed on the keyboard.
Sets or gets the labels displayed on keys.
When using chromatic
mode, chromaticStartNote
is used to offset the index of labels. This means that, in chromatic
mode, when names are overriden, the first index of the array still corresponds to the 'C' key of the keyboard, even if the keyboard display has been offset.
Sets or gets wether certain notes should be highlighted.
Sets or gets the key highlighting policy. The array will be wrapped around if its size is shorter than the number of keys. As an example, in diatonic
mode, [1, 0.5, 0.75, 0.5, 0.75, 0.5 , 0.5]
will highlight the fundamental, the third and the fifth of the scale.
Sets or gets the labels displayed on keys.
Sets or gets the Color that will be used to draw 'white' keys.
Sets or gets the border Color that will be used to draw 'white' keys.
Sets or gets the Color that will be used to draw 'black' keys.
Sets or gets the border Color that will be used to draw 'black' keys.
Sets or gets the Color that will be used to draw keys when they've been pressed.
Sets or gets the Color that will be used to draw labels on keys when they've been pressed.
Sets or gets the relative size of labels displayed on keys.
Sets or gets the margins size between keys, in pixel.
Sets or gets wether keys borders should be drawn.
Sets or gets the height of 'black' keys relative to the size of 'white' keys.
Plays the key at specified index, starting its blinking animation. If doAction
is true
, this will also evaluate the associated action
, passing only the key index as argument.
Plays the key at specified index, toggling its color. If doAction
is true
, this will also evaluate the associated action
, passing the key index as argument, and true
, meaning the key has been pressed.
Stops the key at specified index, starting its blinking animation. If doAction
is true
, this will also evaluate the associated action
, passing the key index as argument, and false
, meaning the key has been released.
The function associated to the View's drawFunc
. Shouldn't be modified.
Simple setup example:
Sustain mode example:
Synths are stored inside an array so they can be accessed when they are released. Pressing a key will play the synth, releasing a key will release the synths enveloppe.
HID interfacing example:
playKey
, sustainKey
and releaseKey
allow to use GMKeyboard as an interface, using a HID.
The idea is that the GMKeyboard is responsible for the action
, with the HID only 'pressing' the keys, thus triggering the action.
In fact, triggering the action
is optionnal and will depend on the doAction
argument of those methods. This allows you to animate the GMKeyboard with the HID without evaluating the action
.
This example demonstrates how to manipulate the GMKeyboard with a MIDI keyboard: