Table of Contents

Class PianoKeyboard

Namespace
PluginUI
Assembly
PluginUI.dll

Horizontal piano keyboard: play with the mouse (velocity from the vertical click position, glissando while dragging), with the computer keyboard when focused (QWERTY rows, Z/X shift octaves), and show notes played elsewhere (host MIDI, sequencer) with the thread-safe SetNoteState(int, bool). iPlug2 IVKeyboardControl.

public class PianoKeyboard : Control
Inheritance
PianoKeyboard
Inherited Members

Constructors

PianoKeyboard()

Creates a keyboard (C3–C6 with middle C = C4... see MiddleCOctave).

public PianoKeyboard()

Properties

ActivitySource

Notes sounding elsewhere (typically the processor's voices, fed from the audio thread), shown like SetNoteState(int, bool) and polled every frame.

[Browsable(false)]
public NoteActivity? ActivitySource { get; set; }

Property Value

NoteActivity

BlackKeyHeight

Height of black keys relative to white keys.

public float BlackKeyHeight { get; set; }

Property Value

float

BlackKeyWidth

Width of black keys relative to white keys.

public float BlackKeyWidth { get; set; }

Property Value

float

DefaultSize

Natural size used when no explicit size is given.

protected override Size DefaultSize { get; }

Property Value

Size

ExternalColor

Highlight color of notes set with SetNoteState(int, bool) (null = theme alternate accent).

public Color? ExternalColor { get; set; }

Property Value

Color?

HighestNote

Highest note (MIDI number; adjusted up to a white key).

public int HighestNote { get; set; }

Property Value

int

LowestNote

Lowest note (MIDI number; adjusted down to a white key).

public int LowestNote { get; set; }

Property Value

int

MiddleCOctave

Octave number of middle C (MIDI 60): 4 (scientific, default) or 3 (Yamaha / many DAWs).

public int MiddleCOctave { get; set; }

Property Value

int

PlayedColor

Highlight color of notes played on this keyboard (null = theme accent).

public Color? PlayedColor { get; set; }

Property Value

Color?

QwertyEnabled

Plays notes from the computer keyboard while focused.

public bool QwertyEnabled { get; set; }

Property Value

bool

QwertyVelocity

Velocity of notes played from the computer keyboard (0..1).

public float QwertyVelocity { get; set; }

Property Value

float

ShowOctaveLabels

Labels the C keys with their octave (C3, C4...).

public bool ShowOctaveLabels { get; set; }

Property Value

bool

Methods

ClearNoteStates()

Clears every externally set note (thread-safe).

public void ClearNoteStates()

IsBlack(int)

true for black keys.

public static bool IsBlack(int note)

Parameters

note int

Returns

bool

IsNotePlayed(int)

true if a note is held on this keyboard (mouse or computer keyboard).

public bool IsNotePlayed(int note)

Parameters

note int

Returns

bool

LayoutParts(VectorStyle, out Rect, out Rect, out Rect)

Splits the bounds into label (top), widget and value (bottom) areas according to the style. Override to change the arrangement (e.g. label on the left for sliders).

protected override void LayoutParts(VectorStyle style, out Rect label, out Rect widget, out Rect value)

Parameters

style VectorStyle
label Rect
widget Rect
value Rect

NoteAt(Point)

Note under a point (black keys first), or -1.

public int NoteAt(Point point)

Parameters

point Point

Returns

int

NoteName(int)

Note name with octave ("C4", "F#2") using MiddleCOctave.

public string NoteName(int note)

Parameters

note int

Returns

string

OnAttached()

Called when the element joins a host (subscribe to external events here).

protected override void OnAttached()

OnCaptureLost()

The mouse capture was lost without a button release.

protected override void OnCaptureLost()

OnDetached()

Called when the element leaves its host (unsubscribe here).

protected override void OnDetached()

OnGotFocus()

Received keyboard focus.

protected override void OnGotFocus()

OnKeyDown(KeyEventArgs)

Key pressed while focused (bubbles to parents).

protected override void OnKeyDown(KeyEventArgs e)

Parameters

e KeyEventArgs

OnKeyUp(KeyEventArgs)

Key released while focused.

protected override void OnKeyUp(KeyEventArgs e)

Parameters

e KeyEventArgs

OnLostFocus()

Lost keyboard focus.

protected override void OnLostFocus()

OnMouseDown(MouseEventArgs)

Mouse button pressed over the element (or captured).

protected override void OnMouseDown(MouseEventArgs e)

Parameters

e MouseEventArgs

OnMouseMove(MouseEventArgs)

Mouse moved over the element (or captured).

protected override void OnMouseMove(MouseEventArgs e)

Parameters

e MouseEventArgs

OnMouseUp(MouseEventArgs)

Mouse button released.

protected override void OnMouseUp(MouseEventArgs e)

Parameters

e MouseEventArgs

ReleaseAll()

Stops every note played on this keyboard.

public void ReleaseAll()

RenderVector(DrawingContext, Rect, VectorStyle)

Vector rendering of the widget area.

protected override void RenderVector(DrawingContext dc, Rect widget, VectorStyle style)

Parameters

dc DrawingContext
widget Rect
style VectorStyle

SetNoteState(int, bool)

Shows or hides a note played elsewhere. Thread-safe (callable from the audio or MIDI thread); the display updates on the next frame.

public void SetNoteState(int note, bool on)

Parameters

note int
on bool

Events

NoteOff

Raised when a note stops.

public event Action<PianoKeyboard, int>? NoteOff

Event Type

Action<PianoKeyboard, int>

NoteOn

Raised when a note starts (note, velocity 0..1).

public event Action<PianoKeyboard, int, float>? NoteOn

Event Type

Action<PianoKeyboard, int, float>