Remodel model.selectedChord as Maybe Chord
Until the user presses play, we shouldn't display any chords.
This commit is contained in:
parent
6a91065677
commit
edc8f4ef6e
1 changed files with 63 additions and 48 deletions
|
@ -18,7 +18,7 @@ type alias Model =
|
||||||
, whitelistedChordTypes : List Theory.ChordType
|
, whitelistedChordTypes : List Theory.ChordType
|
||||||
, whitelistedInversions : List Theory.ChordInversion
|
, whitelistedInversions : List Theory.ChordInversion
|
||||||
, whitelistedNoteClasses : List Theory.NoteClass
|
, whitelistedNoteClasses : List Theory.NoteClass
|
||||||
, selectedChord : Theory.Chord
|
, selectedChord : Maybe Theory.Chord
|
||||||
, isPaused : Bool
|
, isPaused : Bool
|
||||||
, tempo : Int
|
, tempo : Int
|
||||||
, firstNote : Theory.Note
|
, firstNote : Theory.Note
|
||||||
|
@ -42,8 +42,11 @@ type Msg
|
||||||
| ToggleInversion Theory.ChordInversion
|
| ToggleInversion Theory.ChordInversion
|
||||||
| ToggleChordType Theory.ChordType
|
| ToggleChordType Theory.ChordType
|
||||||
| ToggleNoteClass Theory.NoteClass
|
| ToggleNoteClass Theory.NoteClass
|
||||||
|
| DoNothing
|
||||||
|
|
||||||
|
|
||||||
|
{-| The amount by which we increase or decrease tempo.
|
||||||
|
-}
|
||||||
tempoStep : Int
|
tempoStep : Int
|
||||||
tempoStep =
|
tempoStep =
|
||||||
5
|
5
|
||||||
|
@ -61,14 +64,6 @@ bpmToMilliseconds target =
|
||||||
round (toFloat msPerMinute / toFloat target)
|
round (toFloat msPerMinute / toFloat target)
|
||||||
|
|
||||||
|
|
||||||
cmajor : Theory.Chord
|
|
||||||
cmajor =
|
|
||||||
{ note = Theory.C4
|
|
||||||
, chordType = Theory.MajorDominant7
|
|
||||||
, chordInversion = Theory.Root
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{-| The initial state for the application.
|
{-| The initial state for the application.
|
||||||
-}
|
-}
|
||||||
init : Model
|
init : Model
|
||||||
|
@ -97,7 +92,7 @@ init =
|
||||||
, whitelistedChordTypes = chordTypes
|
, whitelistedChordTypes = chordTypes
|
||||||
, whitelistedInversions = inversions
|
, whitelistedInversions = inversions
|
||||||
, whitelistedNoteClasses = noteClasses
|
, whitelistedNoteClasses = noteClasses
|
||||||
, selectedChord = cmajor
|
, selectedChord = Nothing
|
||||||
, isPaused = True
|
, isPaused = True
|
||||||
, tempo = 60
|
, tempo = 60
|
||||||
, firstNote = firstNote
|
, firstNote = firstNote
|
||||||
|
@ -123,8 +118,11 @@ subscriptions { isPaused, tempo } =
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
|
DoNothing ->
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
NewChord chord ->
|
NewChord chord ->
|
||||||
( { model | selectedChord = chord }
|
( { model | selectedChord = Just chord }
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -137,7 +135,7 @@ update msg model =
|
||||||
NewChord chord
|
NewChord chord
|
||||||
|
|
||||||
( Nothing, _ ) ->
|
( Nothing, _ ) ->
|
||||||
NewChord cmajor
|
DoNothing
|
||||||
)
|
)
|
||||||
(Random.List.choose model.whitelistedChords)
|
(Random.List.choose model.whitelistedChords)
|
||||||
)
|
)
|
||||||
|
@ -329,19 +327,36 @@ inversionCheckboxes inversions =
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
displayChord :
|
||||||
|
{ debug : Bool
|
||||||
|
, chord : Theory.Chord
|
||||||
|
, firstNote : Theory.Note
|
||||||
|
, lastNote : Theory.Note
|
||||||
|
}
|
||||||
|
-> Html Msg
|
||||||
|
displayChord { debug, chord, firstNote, lastNote } =
|
||||||
|
div []
|
||||||
|
[ if debug then
|
||||||
|
ChordInspector.render chord
|
||||||
|
|
||||||
|
else
|
||||||
|
span [] []
|
||||||
|
, p [] [ text (Theory.viewChord chord) ]
|
||||||
|
, case Theory.notesForChord chord of
|
||||||
|
Just x ->
|
||||||
|
Piano.render
|
||||||
|
{ highlight = x
|
||||||
|
, start = firstNote
|
||||||
|
, end = lastNote
|
||||||
|
}
|
||||||
|
|
||||||
|
Nothing ->
|
||||||
|
p [] [ text "No chord to show" ]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
case Theory.notesForChord model.selectedChord of
|
|
||||||
Nothing ->
|
|
||||||
p [] [ text ("""
|
|
||||||
We cannot render the chord that you provided because the
|
|
||||||
notes that comprise the chord fall off either the upper
|
|
||||||
or lower end of the piano.
|
|
||||||
|
|
||||||
Chord:
|
|
||||||
""" ++ Theory.inspectChord model.selectedChord) ]
|
|
||||||
|
|
||||||
Just x ->
|
|
||||||
div []
|
div []
|
||||||
[ Tempo.render
|
[ Tempo.render
|
||||||
{ tempo = model.tempo
|
{ tempo = model.tempo
|
||||||
|
@ -358,17 +373,17 @@ view model =
|
||||||
|
|
||||||
else
|
else
|
||||||
span [] []
|
span [] []
|
||||||
, if model.debug.inspectChord then
|
, case model.selectedChord of
|
||||||
ChordInspector.render model.selectedChord
|
Just chord ->
|
||||||
|
displayChord
|
||||||
else
|
{ debug = model.debug.inspectChord
|
||||||
span [] []
|
, chord = chord
|
||||||
, p [] [ text (Theory.viewChord model.selectedChord) ]
|
, firstNote = model.firstNote
|
||||||
, Piano.render
|
, lastNote = model.lastNote
|
||||||
{ highlight = x
|
|
||||||
, start = model.firstNote
|
|
||||||
, end = model.lastNote
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Nothing ->
|
||||||
|
p [] [ text "No chord to display" ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue