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
BlackKeyHeight
Height of black keys relative to white keys.
public float BlackKeyHeight { get; set; }
Property Value
BlackKeyWidth
Width of black keys relative to white keys.
public float BlackKeyWidth { get; set; }
Property Value
DefaultSize
Natural size used when no explicit size is given.
protected override Size DefaultSize { get; }
Property Value
ExternalColor
Highlight color of notes set with SetNoteState(int, bool) (null = theme alternate accent).
public Color? ExternalColor { get; set; }
Property Value
HighestNote
Highest note (MIDI number; adjusted up to a white key).
public int HighestNote { get; set; }
Property Value
LowestNote
Lowest note (MIDI number; adjusted down to a white key).
public int LowestNote { get; set; }
Property Value
MiddleCOctave
Octave number of middle C (MIDI 60): 4 (scientific, default) or 3 (Yamaha / many DAWs).
public int MiddleCOctave { get; set; }
Property Value
PlayedColor
Highlight color of notes played on this keyboard (null = theme accent).
public Color? PlayedColor { get; set; }
Property Value
QwertyEnabled
Plays notes from the computer keyboard while focused.
public bool QwertyEnabled { get; set; }
Property Value
QwertyVelocity
Velocity of notes played from the computer keyboard (0..1).
public float QwertyVelocity { get; set; }
Property Value
ShowOctaveLabels
Labels the C keys with their octave (C3, C4...).
public bool ShowOctaveLabels { get; set; }
Property Value
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
noteint
Returns
IsNotePlayed(int)
true if a note is held on this keyboard (mouse or computer keyboard).
public bool IsNotePlayed(int note)
Parameters
noteint
Returns
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
styleVectorStylelabelRectwidgetRectvalueRect
NoteAt(Point)
Note under a point (black keys first), or -1.
public int NoteAt(Point point)
Parameters
pointPoint
Returns
NoteName(int)
Note name with octave ("C4", "F#2") using MiddleCOctave.
public string NoteName(int note)
Parameters
noteint
Returns
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
OnKeyUp(KeyEventArgs)
Key released while focused.
protected override void OnKeyUp(KeyEventArgs e)
Parameters
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
OnMouseMove(MouseEventArgs)
Mouse moved over the element (or captured).
protected override void OnMouseMove(MouseEventArgs e)
Parameters
OnMouseUp(MouseEventArgs)
Mouse button released.
protected override void OnMouseUp(MouseEventArgs e)
Parameters
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
dcDrawingContextwidgetRectstyleVectorStyle
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
Events
NoteOff
Raised when a note stops.
public event Action<PianoKeyboard, int>? NoteOff
Event Type
NoteOn
Raised when a note starts (note, velocity 0..1).
public event Action<PianoKeyboard, int, float>? NoteOn