GMKeyboard:
Filter:
GraphicalModule/Classes (extension) | GUI > Graphical Module

GMKeyboard
ExtensionExtension

A widget that displays a keyboard and can interface a HID

Description

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.

Class Methods

.new

Creates a new instance of GMKeyboard.

Its graphical properties are defined by its associated GMStyle.

Instance Methods

Interaction

.action

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.

.sustainMode

Sets or gets wether the keyboard only responds to mouseDownAction, or if it emits two different actions when pressed or released (see action).

.keyNumber

Sets or gets the number of displayed keys.

Graphics

.mode

Sets or gets the keyboard display mode. Valid values are either \diatonic or \chromatic.

Changing mode will reset names and highlights.

.chromaticStartNote

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.

.displayNames

Sets or gets wether labels should be displayed on the keyboard.

.names

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.

.displayHighlights

Sets or gets wether certain notes should be highlighted.

.highlights

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.

.names

Sets or gets the labels displayed on keys.

.keyColor

Sets or gets the Color that will be used to draw 'white' keys.

.keyOutlineColor

Sets or gets the border Color that will be used to draw 'white' keys.

.blackKeyColor

Sets or gets the Color that will be used to draw 'black' keys.

.blackKeyOutlineColor

Sets or gets the border Color that will be used to draw 'black' keys.

.blinkColor

Sets or gets the Color that will be used to draw keys when they've been pressed.

.blinkFontColor

Sets or gets the Color that will be used to draw labels on keys when they've been pressed.

.fontRatio

Sets or gets the relative size of labels displayed on keys.

.margins

Sets or gets the margins size between keys, in pixel.

.outlineKeys

Sets or gets wether keys borders should be drawn.

.blackKeyRatio

Sets or gets the height of 'black' keys relative to the size of 'white' keys.

HID interfacing

.playKey

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.

.sustainKey

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.

.releaseKey

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.

Internal methods

.draw

The function associated to the View's drawFunc. Shouldn't be modified.

.prAddBlink

.prDetectChromaKey

.prDrawChromatic

.prDrawDiatonic

.prDrawKey

.prDrawLeftKey

.prDrawMiddleKey

.prDrawRightKey

.prGetChromaticCaseSize

.prGetTimerColor

.prGetWhiteKeysNumber

.prUpdateBlinks

Examples

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:

WARNING: This functionality is currently unavailable when using computer keyboard (unless using 'hacks'), due to the current implementation of Qts keyboard response to held keys. See https://github.com/supercollider/supercollider/issues/6466 .

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: