sh4r3m4n / elm-piano / Piano

A customizable piano component

Model


type alias Model =
{ notes : Set Note
, noteRange : ( Note
, Note )
, interactive : Basics.Bool
, showSizeSelector : Basics.Bool
, debugNotes : Basics.Bool 
}

The model of the component.

notes is the set of currently pressed notes.

noteRange determines the first and last notes of the keyboard.

If interactive is True, the component will generate KeyUp and KeyDown messages when the user clicks on a note. (Now this mode is experimental and has some UI issues).

If showSizeSelector is True a button group will be shown to select the keyboard size.

If debugNotes is True a text will appear, showin the note names of each currently pressed note.

initialModel : Model

Common initial configuration for the component

Now it starts with no keys being pressed in a 25-key keyboard, in interactive mode and with the size selector and the note debugger.


type alias Note =
Basics.Int

Represents a note giving its MIDI Note Number

See http://www.electronics.dit.ie/staff/tscarff/Music_technology/midi/midi_note_numbers_for_octaves.htm for more information

Messages and updates

update : Msg -> Model -> Model

Handle the messages by updating model.notes or model.noteRange


type Msg
    = KeyUp Note
    | KeyDown Note
    | ChangeNoteRange (( Basics.Int, Basics.Int ))

Messages received when clicking a key or changing the keyboard's size

Keyboard size helpers

keyboard12Keys : ( Basics.Int, Basics.Int )

Note range of a 12-key keyboard

keyboard25Keys : ( Basics.Int, Basics.Int )

Note range of a 25-key keyboard

keyboard49Keys : ( Basics.Int, Basics.Int )

Note range of a 49-key keyboard

keyboard61Keys : ( Basics.Int, Basics.Int )

Note range of a 61-key keyboard

keyboard76Keys : ( Basics.Int, Basics.Int )

Note range of a 76-key keyboard

keyboard88Keys : ( Basics.Int, Basics.Int )

Note range of a 88-key keyboard

HTML rendering

view : Model -> Html Msg

Show the Piano component and, if set in the model, the debug text and the keyboard size changer.

Note helpers

noteName : Note -> String

Represent a note number as a string

isNatural : Note -> Basics.Bool

Return False is note is a flat or sharp, True otherwise

octave : Note -> Basics.Int

Octave number of a note