about summary refs log tree commit diff
path: root/website/sandbox/chord-drill-sergeant
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-04-12T18·20+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-04-12T18·20+0100
commit1298263629dc43b2a6a2a3f18a7a779189b66738 (patch)
tree6fb6d275f00d265290796a010d8596f8972aeab6 /website/sandbox/chord-drill-sergeant
parent24692ab46508d5e3348af19a6eae583a6d02e0e7 (diff)
Whitelist and blacklist chords by inversion type
Add checkboxes to support various chord positions.
Diffstat (limited to 'website/sandbox/chord-drill-sergeant')
-rw-r--r--website/sandbox/chord-drill-sergeant/src/Main.elm42
-rw-r--r--website/sandbox/chord-drill-sergeant/src/Theory.elm52
2 files changed, 84 insertions, 10 deletions
diff --git a/website/sandbox/chord-drill-sergeant/src/Main.elm b/website/sandbox/chord-drill-sergeant/src/Main.elm
index 5ccc4d303eeb..f551d11e0d3d 100644
--- a/website/sandbox/chord-drill-sergeant/src/Main.elm
+++ b/website/sandbox/chord-drill-sergeant/src/Main.elm
@@ -24,6 +24,7 @@ type alias Model =
         { enable : Bool
         , inspectChord : Bool
         }
+    , whitelistedInversions : List Theory.ChordInversion
     }
 
 
@@ -36,6 +37,7 @@ type Msg
     | DecreaseTempo
     | SetTempo String
     | ToggleInspectChord
+    | ToggleInversion Theory.ChordInversion
 
 
 tempoStep : Int
@@ -71,7 +73,8 @@ init =
         ( firstNote, lastNote ) =
             ( Theory.C3, Theory.C5 )
     in
-    { whitelistedChords = Theory.allChords firstNote lastNote
+    { whitelistedChords = Theory.allChords firstNote lastNote Theory.allInversions
+    , whitelistedInversions = Theory.allInversions
     , selectedChord = cmajor
     , isPaused = True
     , tempo = 60
@@ -147,6 +150,22 @@ update msg model =
             , Cmd.none
             )
 
+        ToggleInversion inversion ->
+            let
+                inversions =
+                    if List.member inversion model.whitelistedInversions then
+                        List.filter ((/=) inversion) model.whitelistedInversions
+
+                    else
+                        inversion :: model.whitelistedInversions
+            in
+            ( { model
+                | whitelistedInversions = inversions
+                , whitelistedChords = Theory.allChords model.firstNote model.lastNote inversions
+              }
+            , Cmd.none
+            )
+
         SetTempo tempo ->
             ( { model
                 | tempo =
@@ -178,6 +197,26 @@ debugger =
         ]
 
 
+inversionCheckboxes : List Theory.ChordInversion -> Html Msg
+inversionCheckboxes inversions =
+    ul []
+        (Theory.allInversions
+            |> List.map
+                (\inversion ->
+                    li []
+                        [ label [] [ text (Theory.inversionName inversion) ]
+                        , input
+                            [ type_
+                                "checkbox"
+                            , onClick (ToggleInversion inversion)
+                            , checked (List.member inversion inversions)
+                            ]
+                            []
+                        ]
+                )
+        )
+
+
 view : Model -> Html Msg
 view model =
     case Theory.notesForChord model.selectedChord of
@@ -198,6 +237,7 @@ view model =
                     , handleDecrease = DecreaseTempo
                     , handleInput = SetTempo
                     }
+                , inversionCheckboxes model.whitelistedInversions
                 , playPause model
                 , if model.debug.enable then
                     debugger
diff --git a/website/sandbox/chord-drill-sergeant/src/Theory.elm b/website/sandbox/chord-drill-sergeant/src/Theory.elm
index 4dc4c3e511e8..b240822999f7 100644
--- a/website/sandbox/chord-drill-sergeant/src/Theory.elm
+++ b/website/sandbox/chord-drill-sergeant/src/Theory.elm
@@ -269,6 +269,21 @@ noteInCentralOctave noteClass =
             B4
 
 
+{-| Return the human-readable version of a chord inversion.
+-}
+inversionName : ChordInversion -> String
+inversionName inversion =
+    case inversion of
+        Root ->
+            "Root"
+
+        First ->
+            "First"
+
+        Second ->
+            "Second"
+
+
 {-| Return the note that is one half step away from `note` in the direction,
 `dir`.
 In the case of stepping up or down from the end of the piano, this returns a
@@ -750,24 +765,43 @@ notesFromRange start end =
         |> List.Extra.takeWhile ((/=) end)
 
 
+{-| Return a list of all of the chord inversions about which we know.
+-}
+allInversions : List ChordInversion
+allInversions =
+    [ Root, First, Second ]
+
+
+{-| Return a list of all of the chord types about which we know.
+-}
+allChordTypes : List ChordType
+allChordTypes =
+    [ Major
+    , Major7
+    , MajorDominant7
+    , Minor
+    , MinorMajor7
+    , MinorDominant7
+    , Augmented
+    , AugmentedDominant7
+    , Diminished
+    , DiminishedDominant7
+    , DiminishedMajor7
+    ]
+
+
 {-| Return a list of all of the chords that we know about.
 Only create chords from the range of notes delimited by the range `start` and
 `end`.
 -}
-allChords : Note -> Note -> List Chord
-allChords start end =
+allChords : Note -> Note -> List ChordInversion -> List Chord
+allChords start end chordInversions =
     let
         notes =
             notesFromRange start end
 
         chordTypes =
-            [ Major
-            ]
-
-        chordInversions =
-            [ Root
-            , First
-            ]
+            allChordTypes
     in
     notes
         |> List.Extra.andThen