about summary refs log tree commit diff
path: root/website
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-04-13T08·42+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-04-13T08·42+0100
commitedc8f4ef6eaafd68c207e3fabd9fd588c4c50b62 (patch)
tree7c276cf9f943d9f935ac6aa2d69704cf410161b8 /website
parent6a91065677cb2a6571f53f5378b433c8c0e6537c (diff)
Remodel model.selectedChord as Maybe Chord
Until the user presses play, we shouldn't display any chords.
Diffstat (limited to 'website')
-rw-r--r--website/sandbox/chord-drill-sergeant/src/Main.elm115
1 files changed, 65 insertions, 50 deletions
diff --git a/website/sandbox/chord-drill-sergeant/src/Main.elm b/website/sandbox/chord-drill-sergeant/src/Main.elm
index a9f94af7908f..2c9f33aa609d 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.
-
-                       Chord:
-                       """ ++ Theory.inspectChord model.selectedChord) ]
-
-        Just x ->
-            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
-
-                  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
+    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
+
+          else
+            span [] []
+        , case model.selectedChord of
+            Just chord ->
+                displayChord
+                    { debug = model.debug.inspectChord
+                    , chord = chord
+                    , firstNote = model.firstNote
+                    , lastNote = model.lastNote
                     }
-                ]
+
+            Nothing ->
+                p [] [ text "No chord to display" ]
+        ]
 
 
 {-| For now, I'm just dumping things onto the page to sketch ideas.