From edc8f4ef6eaafd68c207e3fabd9fd588c4c50b62 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Mon, 13 Apr 2020 09:42:26 +0100 Subject: [PATCH] Remodel model.selectedChord as Maybe Chord Until the user presses play, we shouldn't display any chords. --- .../sandbox/chord-drill-sergeant/src/Main.elm | 111 ++++++++++-------- 1 file changed, 63 insertions(+), 48 deletions(-) diff --git a/website/sandbox/chord-drill-sergeant/src/Main.elm b/website/sandbox/chord-drill-sergeant/src/Main.elm index a9f94af79..2c9f33aa6 100644 --- a/website/sandbox/chord-drill-sergeant/src/Main.elm +++ b/website/sandbox/chord-drill-sergeant/src/Main.elm @@ -18,7 +18,7 @@ type alias Model = , whitelistedChordTypes : List Theory.ChordType , whitelistedInversions : List Theory.ChordInversion , whitelistedNoteClasses : List Theory.NoteClass - , selectedChord : Theory.Chord + , selectedChord : Maybe Theory.Chord , isPaused : Bool , tempo : Int , firstNote : Theory.Note @@ -42,8 +42,11 @@ type Msg | ToggleInversion Theory.ChordInversion | ToggleChordType Theory.ChordType | ToggleNoteClass Theory.NoteClass + | DoNothing +{-| The amount by which we increase or decrease tempo. +-} tempoStep : Int tempoStep = 5 @@ -61,14 +64,6 @@ bpmToMilliseconds 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. -} init : Model @@ -97,7 +92,7 @@ init = , whitelistedChordTypes = chordTypes , whitelistedInversions = inversions , whitelistedNoteClasses = noteClasses - , selectedChord = cmajor + , selectedChord = Nothing , isPaused = True , tempo = 60 , firstNote = firstNote @@ -123,8 +118,11 @@ subscriptions { isPaused, tempo } = update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of + DoNothing -> + ( model, Cmd.none ) + NewChord chord -> - ( { model | selectedChord = chord } + ( { model | selectedChord = Just chord } , Cmd.none ) @@ -137,7 +135,7 @@ update msg model = NewChord chord ( Nothing, _ ) -> - NewChord cmajor + DoNothing ) (Random.List.choose model.whitelistedChords) ) @@ -329,47 +327,64 @@ 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 = - 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. + div [] + [ Tempo.render + { tempo = model.tempo + , handleIncrease = IncreaseTempo + , handleDecrease = DecreaseTempo + , handleInput = SetTempo + } + , noteClassCheckboxes model.whitelistedNoteClasses + , inversionCheckboxes model.whitelistedInversions + , chordTypeCheckboxes model.whitelistedChordTypes + , playPause model + , if model.debug.enable then + debugger - Chord: - """ ++ Theory.inspectChord model.selectedChord) ] - - Just x -> - div [] - [ Tempo.render - { tempo = model.tempo - , handleIncrease = IncreaseTempo - , handleDecrease = DecreaseTempo - , handleInput = SetTempo + else + span [] [] + , case model.selectedChord of + Just chord -> + displayChord + { debug = model.debug.inspectChord + , chord = chord + , firstNote = model.firstNote + , lastNote = model.lastNote } - , noteClassCheckboxes model.whitelistedNoteClasses - , inversionCheckboxes model.whitelistedInversions - , chordTypeCheckboxes model.whitelistedChordTypes - , playPause model - , if model.debug.enable then - debugger - else - span [] [] - , if model.debug.inspectChord then - ChordInspector.render model.selectedChord - - else - span [] [] - , p [] [ text (Theory.viewChord model.selectedChord) ] - , Piano.render - { highlight = x - , start = model.firstNote - , end = model.lastNote - } - ] + Nothing -> + p [] [ text "No chord to display" ] + ] {-| For now, I'm just dumping things onto the page to sketch ideas.