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,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 -> Html Msg
 | 
				
			||||||
view model =
 | 
					view model =
 | 
				
			||||||
    case Theory.notesForChord model.selectedChord of
 | 
					    div []
 | 
				
			||||||
        Nothing ->
 | 
					        [ Tempo.render
 | 
				
			||||||
            p [] [ text ("""
 | 
					            { tempo = model.tempo
 | 
				
			||||||
                       We cannot render the chord that you provided because the
 | 
					            , handleIncrease = IncreaseTempo
 | 
				
			||||||
                       notes that comprise the chord fall off either the upper
 | 
					            , handleDecrease = DecreaseTempo
 | 
				
			||||||
                       or lower end of the piano.
 | 
					            , handleInput = SetTempo
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        , noteClassCheckboxes model.whitelistedNoteClasses
 | 
				
			||||||
 | 
					        , inversionCheckboxes model.whitelistedInversions
 | 
				
			||||||
 | 
					        , chordTypeCheckboxes model.whitelistedChordTypes
 | 
				
			||||||
 | 
					        , playPause model
 | 
				
			||||||
 | 
					        , if model.debug.enable then
 | 
				
			||||||
 | 
					            debugger
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                       Chord:
 | 
					          else
 | 
				
			||||||
                       """ ++ Theory.inspectChord model.selectedChord) ]
 | 
					            span [] []
 | 
				
			||||||
 | 
					        , case model.selectedChord of
 | 
				
			||||||
        Just x ->
 | 
					            Just chord ->
 | 
				
			||||||
            div []
 | 
					                displayChord
 | 
				
			||||||
                [ Tempo.render
 | 
					                    { debug = model.debug.inspectChord
 | 
				
			||||||
                    { tempo = model.tempo
 | 
					                    , chord = chord
 | 
				
			||||||
                    , handleIncrease = IncreaseTempo
 | 
					                    , firstNote = model.firstNote
 | 
				
			||||||
                    , handleDecrease = DecreaseTempo
 | 
					                    , lastNote = model.lastNote
 | 
				
			||||||
                    , handleInput = SetTempo
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                , noteClassCheckboxes model.whitelistedNoteClasses
 | 
					 | 
				
			||||||
                , inversionCheckboxes model.whitelistedInversions
 | 
					 | 
				
			||||||
                , chordTypeCheckboxes model.whitelistedChordTypes
 | 
					 | 
				
			||||||
                , playPause model
 | 
					 | 
				
			||||||
                , if model.debug.enable then
 | 
					 | 
				
			||||||
                    debugger
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  else
 | 
					            Nothing ->
 | 
				
			||||||
                    span [] []
 | 
					                p [] [ text "No chord to display" ]
 | 
				
			||||||
                , 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
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                ]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{-| For now, I'm just dumping things onto the page to sketch ideas.
 | 
					{-| For now, I'm just dumping things onto the page to sketch ideas.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue