Piano Roll

The notes of a song passing by as it plays, as on the paper roll of a player piano: a keyboard standing on the left, one lane for each key, and each note as a block in the lane of its pitch, as wide as it lasts. A note sounds from the moment it touches the keyboard until it has gone into it, and lights its key meanwhile. Pressing a key mutes it: its notes fade and it no longer lights up. Under the notes sit a button that plays and pauses, the time played, a progress bar and the length of the song.

The keyboard goes from one key below the lowest note to one above the highest, and the lanes share the height of the element.

Import

Importing the library registers <pix-piano-roll>.

import '@ilusiva/pix';

Basic

Attributes

NameTypeDefaultDescription
positionnumber0Seconds of the song already played. Defaults to 0.
durationnumber0Length of the song in seconds. Defaults to the end of its last note.
playingbooleanfalseWhether the song is playing, which the button switches. While it plays, `position` advances by itself.
loopbooleanfalseThe song repeats: `position` may keep growing past the length, and the beginning of the song is shown coming again before the end.
play-labelstring'Play'Accessible name of the button while it plays the song. Defaults to `Play`.
pause-labelstring'Pause'Accessible name of the button while it pauses the song. Defaults to `Pause`.
mute-labelstring'Mute'Start of the accessible name of each key, followed by the name of the key. Defaults to `Mute`.

Properties

NameTypeDescription
notesPianoRollNote[]In any order.
mutednumber[]Pitches of the muted keys, counted as in MIDI.
lengthnumberLength of the song in seconds: `duration` when it is set, and the end of the last note otherwise.

Methods

MethodDescription
play(): voidStarts over when a song that plays once is at its end. Does nothing while playing.
pause(): voidDoes nothing unless playing.
mute(pitch: number): voidDoes nothing when the key is muted already.
unmute(pitch: number): voidDoes nothing unless the key is muted.

Events

NameDescription
playThe song started, or went on from where it paused.
pauseThe song paused, keeping its place, or reached its end.
muteA key was muted or unmuted.
noteA note started on a key that is not muted. `event.detail` holds its `pitch` and its `duration`. The piano roll makes no sound: this is when the page plays the note.