diff --git a/src/Applications/UI.elm b/src/Applications/UI.elm index 8eacc289..799b37ba 100644 --- a/src/Applications/UI.elm +++ b/src/Applications/UI.elm @@ -10,6 +10,7 @@ import Conditional exposing (..) import Css exposing (url) import Debouncer.Basic as Debouncer import Dict +import Equalizer import Keyboard import LastFm import Maybe.Extra as Maybe @@ -138,6 +139,12 @@ init flags url key = |> Debouncer.debounce |> Debouncer.toDebouncer + ----------------------------------------- + -- Equalizer + ----------------------------------------- + , eqKnobOperation = Nothing + , eqSettings = Equalizer.defaultSettings + ----------------------------------------- -- Instances ----------------------------------------- @@ -149,7 +156,6 @@ init flags url key = -- Children (TODO) ----------------------------------------- , authentication = Authentication.initialModel url - , equalizer = Equalizer.initialModel , playlists = Playlists.initialModel , queue = Queue.initialModel , sources = Sources.initialModel @@ -249,10 +255,10 @@ update msg = -- Equalizer ----------------------------------------- ActivateKnob a b -> - Equalizer.organize (Equalizer.activateKnob a b) + Equalizer.activateKnob a b AdjustKnob a -> - Equalizer.organize (Equalizer.adjustKnob a) + Equalizer.adjustKnob a DeactivateKnob _ -> Equalizer.deactivateKnob diff --git a/src/Applications/UI/Equalizer/State.elm b/src/Applications/UI/Equalizer/State.elm index 0e3b2837..e45c78b4 100644 --- a/src/Applications/UI/Equalizer/State.elm +++ b/src/Applications/UI/Equalizer/State.elm @@ -8,9 +8,7 @@ import Html.Events.Extra.Pointer as Pointer import Json.Decode as Decode import Management import Material.Icons as Icons -import Monocle.Lens as Lens exposing (Lens) -import Return exposing (return) -import UI.Equalizer.Types as Equalizer exposing (..) +import Return exposing (andThen, return) import UI.Ports as Ports import UI.Reply exposing (Reply(..)) import UI.Types as UI exposing (..) @@ -18,69 +16,28 @@ import UI.User.State.Export as User --- 🌳 - - -type alias Model = - { low : Float - , mid : Float - , high : Float - , volume : Float - - -- - , activeKnob : Maybe Knob - , startCoordinates : Coordinates - } - - -initialModel : Model -initialModel = - { low = defaultSettings.low - , mid = defaultSettings.mid - , high = defaultSettings.high - , volume = defaultSettings.volume - - -- Knob interactions - -------------------- - , activeKnob = Nothing - , startCoordinates = { x = 0, y = 0 } - } - - -lens : Lens UI.Model Equalizer.Model -lens = - { get = .equalizer - , set = \equalizer ui -> { ui | equalizer = equalizer } - } - - - -- 📣 -organize : Organizer Equalizer.Model -> Manager -organize = - Management.organize lens - - - --- 🔱 - - -activateKnob : Knob -> Pointer.Event -> Organizer Equalizer.Model +activateKnob : Knob -> Pointer.Event -> Manager activateKnob theKnob { pointer } model = - Return.singleton - { model - | activeKnob = Just theKnob - , startCoordinates = Coordinates.fromTuple pointer.clientPos - } + { knob = theKnob + , startingPosition = Coordinates.fromTuple pointer.clientPos + } + |> (\m -> { model | eqKnobOperation = Just m }) + |> Return.singleton -adjustKnob : Pointer.Event -> Organizer Equalizer.Model +adjustKnob : Pointer.Event -> Manager adjustKnob { pointer } model = let start = - model.startCoordinates + case model.eqKnobOperation of + Just { startingPosition } -> + startingPosition + + Nothing -> + { x = 0, y = 0 } end = (\( a, b ) -> { x = a, y = b }) @@ -102,7 +59,7 @@ adjustKnob { pointer } model = |> min maxAngle value = - case ( distance > 10, model.activeKnob ) of + case ( distance > 10, Maybe.map .knob model.eqKnobOperation ) of ( True, Just Volume ) -> Just ( Volume, (maxAngle + angle) / (maxAngle * 2) ) @@ -112,43 +69,44 @@ adjustKnob { pointer } model = _ -> Nothing - newModel = + settings = + model.eqSettings + + newSettings = case value of Just ( Low, v ) -> - { model | low = v } + { settings | low = v } Just ( Mid, v ) -> - { model | mid = v } + { settings | mid = v } Just ( High, v ) -> - { model | high = v } + { settings | high = v } Just ( Volume, v ) -> - { model | volume = v } + { settings | volume = v } Nothing -> - model + settings in case value of Just ( knobType, v ) -> - return newModel (adjustKnobUsingPort knobType v) + return { model | eqSettings = newSettings } (adjustKnobUsingPort knobType v) Nothing -> - Return.singleton newModel + Return.singleton { model | eqSettings = newSettings } deactivateKnob : Manager deactivateKnob model = - model - |> organize (\m -> Return.singleton { m | activeKnob = Nothing }) - |> Return.andThen User.saveEnclosedUserData + User.saveEnclosedUserData { model | eqKnobOperation = Nothing } resetKnob : Knob -> Manager resetKnob knob model = model - |> organize (resetKnobOrganizer knob) - |> Return.andThen User.saveEnclosedUserData + |> resetKnobOrganizer knob + |> andThen User.saveEnclosedUserData @@ -175,13 +133,13 @@ adjustKnobUsingPort knobType value = } -adjustAllKnobs : Equalizer.Model -> Cmd Msg -adjustAllKnobs model = +adjustAllKnobs : Settings -> Cmd Msg +adjustAllKnobs eqSettings = Cmd.batch - [ adjustKnobUsingPort Low model.low - , adjustKnobUsingPort Mid model.mid - , adjustKnobUsingPort High model.high - , adjustKnobUsingPort Volume model.volume + [ adjustKnobUsingPort Low eqSettings.low + , adjustKnobUsingPort Mid eqSettings.mid + , adjustKnobUsingPort High eqSettings.high + , adjustKnobUsingPort Volume eqSettings.volume ] @@ -189,24 +147,31 @@ adjustAllKnobs model = -- ㊙️ -resetKnobOrganizer : Knob -> Organizer Equalizer.Model +resetKnobOrganizer : Knob -> Manager resetKnobOrganizer knob model = + let + d = + defaultSettings + + s = + model.eqSettings + in case knob of Low -> - reset { model | low = defaultSettings.low } Low defaultSettings.low + reset Low { s | low = d.low } d.low model Mid -> - reset { model | mid = defaultSettings.mid } Mid defaultSettings.mid + reset Mid { s | mid = d.mid } d.mid model High -> - reset { model | high = defaultSettings.high } High defaultSettings.high + reset High { s | high = d.high } d.high model Volume -> - reset { model | volume = defaultSettings.volume } Volume defaultSettings.volume + reset Volume { s | volume = d.volume } d.volume model -reset : Equalizer.Model -> Knob -> Float -> ( Equalizer.Model, Cmd Msg ) -reset newModel knobType value = - ( newModel +reset : Knob -> Equalizer.Settings -> Float -> Manager +reset knobType newSettings value model = + ( { model | eqSettings = newSettings } , adjustKnobUsingPort knobType value ) diff --git a/src/Applications/UI/Equalizer/Types.elm b/src/Applications/UI/Equalizer/Types.elm deleted file mode 100644 index 78efead9..00000000 --- a/src/Applications/UI/Equalizer/Types.elm +++ /dev/null @@ -1,20 +0,0 @@ -module UI.Equalizer.Types exposing (..) - -import Coordinates exposing (Coordinates) -import Equalizer exposing (..) - - - --- 🌳 - - -type alias Model = - { low : Float - , mid : Float - , high : Float - , volume : Float - - -- - , activeKnob : Maybe Knob - , startCoordinates : Coordinates - } diff --git a/src/Applications/UI/Equalizer/View.elm b/src/Applications/UI/Equalizer/View.elm index 7c62a26d..e02e6705 100644 --- a/src/Applications/UI/Equalizer/View.elm +++ b/src/Applications/UI/Equalizer/View.elm @@ -18,7 +18,6 @@ import Json.Decode as Decode import Material.Icons as Icons import Svg.Styled import Svg.Styled.Attributes -import UI.Equalizer.Types as Equalizer import UI.Kit import UI.Navigation exposing (..) import UI.Page @@ -29,8 +28,8 @@ import UI.Types exposing (Msg(..)) -- 🗺 -view : Equalizer.Model -> Html Msg -view model = +view : Settings -> Html Msg +view settings = UI.Kit.receptacle { scrolling = True } [ ----------------------------------------- @@ -56,12 +55,12 @@ view model = -- , UI.Kit.centeredContent - [ eqView model ] + [ eqView settings ] ] -eqView : Equalizer.Model -> Html Msg -eqView model = +eqView : Settings -> Html Msg +eqView settings = chunk [ C.text_center ] [ chunk @@ -74,7 +73,7 @@ eqView model = ------------ , C.dark__border_base00 ] - [ knob Volume model.volume + [ knob Volume settings.volume ] -- @@ -89,9 +88,9 @@ eqView model = ------------ , C.dark__border_base00 ] - [ knob Low model.low - , knob Mid model.mid - , knob High model.high + [ knob Low settings.low + , knob Mid settings.mid + , knob High settings.high ] ] diff --git a/src/Applications/UI/Types.elm b/src/Applications/UI/Types.elm index 73cc8317..03f66a68 100644 --- a/src/Applications/UI/Types.elm +++ b/src/Applications/UI/Types.elm @@ -43,7 +43,6 @@ import UI.Authentication as Authentication import UI.Authentication.ContextMenu as Authentication import UI.Demo as Demo import UI.DnD as DnD -import UI.Equalizer.Types as Equalizer import UI.Navigation as Navigation import UI.Notifications import UI.Page as Page exposing (Page) @@ -123,6 +122,12 @@ type alias Model = ----------------------------------------- , debounce : Debouncer Msg Msg + ----------------------------------------- + -- Equalizer + ----------------------------------------- + , eqKnobOperation : Maybe Equalizer.KnobOperation + , eqSettings : Equalizer.Settings + ----------------------------------------- -- Instances ----------------------------------------- @@ -134,7 +139,6 @@ type alias Model = -- Children (TODO) ----------------------------------------- , authentication : Authentication.Model - , equalizer : Equalizer.Model , queue : Queue.Model , playlists : Playlists.Model , sources : Sources.Model diff --git a/src/Applications/UI/User/State/Export.elm b/src/Applications/UI/User/State/Export.elm index 1be7ed7d..c7e414ad 100644 --- a/src/Applications/UI/User/State/Export.elm +++ b/src/Applications/UI/User/State/Export.elm @@ -13,16 +13,8 @@ import User.Layer exposing (..) saveEnclosedUserData : Manager saveEnclosedUserData model = - let - equalizerSettings = - { low = model.equalizer.low - , mid = model.equalizer.mid - , high = model.equalizer.high - , volume = model.equalizer.volume - } - in { cachedTracks = model.tracks.cached - , equalizerSettings = equalizerSettings + , equalizerSettings = model.eqSettings , grouping = model.tracks.grouping , onlyShowCachedTracks = model.tracks.cachedOnly , onlyShowFavourites = model.tracks.favouritesOnly diff --git a/src/Applications/UI/User/State/Import.elm b/src/Applications/UI/User/State/Import.elm index b5326094..d8c881e6 100644 --- a/src/Applications/UI/User/State/Import.elm +++ b/src/Applications/UI/User/State/Import.elm @@ -189,14 +189,17 @@ importHypaethral value model = importEnclosed : Json.Decode.Value -> Model -> Return3.Return Model Msg Reply importEnclosed value model = let - { equalizer, playlists, queue, tracks } = + { playlists, queue, tracks } = model + + equalizerSettings = + model.eqSettings in case decodeEnclosedData value of Ok data -> let - newEqualizer = - { equalizer + newEqualizerSettings = + { equalizerSettings | low = data.equalizerSettings.low , mid = data.equalizerSettings.mid , high = data.equalizerSettings.high @@ -226,14 +229,14 @@ importEnclosed value model = } in ( { model - | equalizer = newEqualizer + | eqSettings = newEqualizerSettings , playlists = newPlaylists , queue = newQueue , tracks = newTracks } -- , Cmd.batch - [ Equalizer.adjustAllKnobs newEqualizer + [ Equalizer.adjustAllKnobs newEqualizerSettings , Ports.setRepeat data.repeat ] -- diff --git a/src/Applications/UI/View.elm b/src/Applications/UI/View.elm index 55c8347d..f2934317 100644 --- a/src/Applications/UI/View.elm +++ b/src/Applications/UI/View.elm @@ -68,7 +68,7 @@ body model = (if Maybe.isJust model.contextMenu || Maybe.isJust model.alfred then [ on "tap" (Json.Decode.succeed HideOverlay) ] - else if Maybe.isJust model.equalizer.activeKnob then + else if Maybe.isJust model.eqKnobOperation then [ Pointer.onMove AdjustKnob , Pointer.onUp DeactivateKnob , Pointer.onCancel DeactivateKnob @@ -176,7 +176,7 @@ defaultScreen model = -------- , case model.page of Page.Equalizer -> - Lazy.lazy Equalizer.view model.equalizer + Lazy.lazy Equalizer.view model.eqSettings Page.Index -> nothing diff --git a/src/Library/Equalizer.elm b/src/Library/Equalizer.elm index 74acdd10..83ffdf1b 100644 --- a/src/Library/Equalizer.elm +++ b/src/Library/Equalizer.elm @@ -1,5 +1,6 @@ module Equalizer exposing (..) +import Coordinates exposing (Coordinates) import Json.Decode import Json.Encode @@ -15,6 +16,12 @@ type Knob | Volume +type alias KnobOperation = + { knob : Knob + , startingPosition : Coordinates + } + + type alias Settings = { low : Float , mid : Float