piano
Interfaces
PianoLayout
Defined in: piano.ts:24
The geometry of a drawn keyboard.
One description is shared by the drawing and the hit testing, so a key cannot be drawn somewhere other than where it responds.
Properties
blackKeyHeightRatio?
optional blackKeyHeightRatio?: number;
Defined in: piano.ts:50
Height of a black key, as a fraction of the height of the keyboard.
Default
0.6
blackKeyWidthRatio?
optional blackKeyWidthRatio?: number;
Defined in: piano.ts:43
Width of a black key, as a fraction of PianoLayout.whiteKeyWidth.
Default
0.65
keyGap?
optional keyGap?: number;
Defined in: piano.ts:36
Space between two white keys. Part of the slot a white key occupies, so it still belongs to one of the keys for the purpose of hit testing.
Default
1
noteRange
noteRange: NoteRange;
Defined in: piano.ts:25
whiteKeyWidth
whiteKeyWidth: number;
Defined in: piano.ts:28
Width of a white key, excluding PianoLayout.keyGap.
Type Aliases
NoteRange
type NoteRange = object;
Defined in: piano.ts:3
Properties
first
first: number;
Defined in: piano.ts:4
last
last: number;
Defined in: piano.ts:5
Functions
blackKeyWidth()
function blackKeyWidth(layout): number;
Defined in: piano.ts:80
Width of a black key in pixels.
Parameters
| Parameter | Type |
|---|---|
layout | PianoLayout |
Returns
number
getNoteRangeArray()
function getNoteRangeArray(noteRange): number[];
Defined in: piano.ts:11
[noteRange.first, noteRange.first + 1, ..., noteRange.last]
Parameters
| Parameter | Type |
|---|---|
noteRange | NoteRange |
Returns
number[]
noteAt()
function noteAt(
x,
y,
height,
layout
): number | null;
Defined in: piano.ts:135
The note drawn at a point, or null where there is none.
Black keys are tested first, so they win where they overlap a white one. A white key covers its gap as well as its width, so the whole width of the keyboard belongs to some key and a click cannot fall between two.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | number | offset from the left edge of the keyboard, in pixels |
y | number | offset from its top edge, in pixels |
height | number | height of the keyboard, in pixels |
layout | PianoLayout | - |
Returns
number | null
notePosition()
function notePosition(note, layout): number;
Defined in: piano.ts:103
Offset of the left edge of a key from the left edge of the keyboard, in pixels.
Notes outside noteRange are placed too, so the value is negative below
noteRange.first.
Parameters
| Parameter | Type |
|---|---|
note | number |
layout | PianoLayout |
Returns
number
pianoWidth()
function pianoWidth(layout): number;
Defined in: piano.ts:88
Width of the whole keyboard in pixels.
Parameters
| Parameter | Type |
|---|---|
layout | PianoLayout |
Returns
number