module Mpv.Mpv where

import Mpv.Data.AudioDelay (AudioDelay)
import Mpv.Data.MpvInfo (MpvInfo (MpvInfo))
import qualified Mpv.Data.PlaybackState as PlaybackState
import Mpv.Data.PlaybackState (PlaybackState)
import qualified Mpv.Data.Property as Property
import Mpv.Data.Property (Property)
import Mpv.Data.SubDelay (SubDelay)
import Mpv.Data.Volume (Volume)
import qualified Mpv.Effect.Mpv as Mpv
import Mpv.Effect.Mpv (Mpv)
import Mpv.Track (tracks)

setDefaultOptions ::
  Member Mpv r =>
  Sem r ()
setDefaultOptions :: forall (r :: [(* -> *) -> * -> *]). Member Mpv r => Sem r ()
setDefaultOptions = do
  Text -> Text -> Sem r ()
forall (r :: [(* -> *) -> * -> *]).
MemberWithError Mpv r =>
Text -> Text -> Sem r ()
Mpv.setOption Text
"input-default-bindings" Text
"yes"
  Text -> Text -> Sem r ()
forall (r :: [(* -> *) -> * -> *]).
MemberWithError Mpv r =>
Text -> Text -> Sem r ()
Mpv.setOption Text
"input-vo-keyboard" Text
"yes"
  Text -> Text -> Sem r ()
forall (r :: [(* -> *) -> * -> *]).
MemberWithError Mpv r =>
Text -> Text -> Sem r ()
Mpv.setOption Text
"osd-level" Text
"1"

alterPropM ::
  Show v =>
  Member Mpv r =>
  Property v ->
  (v -> Sem r v) ->
  Sem r v
alterPropM :: forall v (r :: [(* -> *) -> * -> *]).
(Show v, Member Mpv r) =>
Property v -> (v -> Sem r v) -> Sem r v
alterPropM Property v
prop v -> Sem r v
f = do
  Property v -> v -> Sem r ()
forall (r :: [(* -> *) -> * -> *]) v.
(MemberWithError Mpv r, Show v) =>
Property v -> v -> Sem r ()
Mpv.setProp Property v
prop (v -> Sem r ()) -> Sem r v -> Sem r ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< v -> Sem r v
f (v -> Sem r v) -> Sem r v -> Sem r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Property v -> Sem r v
forall (r :: [(* -> *) -> * -> *]) v.
MemberWithError Mpv r =>
Property v -> Sem r v
Mpv.prop Property v
prop
  Property v -> Sem r v
forall (r :: [(* -> *) -> * -> *]) v.
MemberWithError Mpv r =>
Property v -> Sem r v
Mpv.prop Property v
prop

alterProp ::
  Show v =>
  Member Mpv r =>
  Property v ->
  (v -> v) ->
  Sem r v
alterProp :: forall v (r :: [(* -> *) -> * -> *]).
(Show v, Member Mpv r) =>
Property v -> (v -> v) -> Sem r v
alterProp Property v
prop v -> v
f =
  Property v -> (v -> Sem r v) -> Sem r v
forall v (r :: [(* -> *) -> * -> *]).
(Show v, Member Mpv r) =>
Property v -> (v -> Sem r v) -> Sem r v
alterPropM Property v
prop (v -> Sem r v
forall (f :: * -> *) a. Applicative f => a -> f a
pure (v -> Sem r v) -> (v -> v) -> v -> Sem r v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v -> v
f)

togglePlaybackState ::
  Member Mpv r =>
  Sem r PlaybackState
togglePlaybackState :: forall (r :: [(* -> *) -> * -> *]).
Member Mpv r =>
Sem r PlaybackState
togglePlaybackState =
  Property PlaybackState
-> (PlaybackState -> PlaybackState) -> Sem r PlaybackState
forall v (r :: [(* -> *) -> * -> *]).
(Show v, Member Mpv r) =>
Property v -> (v -> v) -> Sem r v
alterProp Property PlaybackState
Property.Paused PlaybackState -> PlaybackState
PlaybackState.toggle

info ::
  Member Mpv r =>
  Sem r MpvInfo
info :: forall (r :: [(* -> *) -> * -> *]). Member Mpv r => Sem r MpvInfo
info = do
  PlaybackState
playback <- Property PlaybackState -> Sem r PlaybackState
forall (r :: [(* -> *) -> * -> *]) v.
MemberWithError Mpv r =>
Property v -> Sem r v
Mpv.prop Property PlaybackState
Property.Paused
  VideoDuration
duration <- Property VideoDuration -> Sem r VideoDuration
forall (r :: [(* -> *) -> * -> *]) v.
MemberWithError Mpv r =>
Property v -> Sem r v
Mpv.prop Property VideoDuration
Property.Duration
  VideoProgress
progress <- Property VideoProgress -> Sem r VideoProgress
forall (r :: [(* -> *) -> * -> *]) v.
MemberWithError Mpv r =>
Property v -> Sem r v
Mpv.prop Property VideoProgress
Property.PercentPos
  VideoExpired
expired <- Property VideoExpired -> Sem r VideoExpired
forall (r :: [(* -> *) -> * -> *]) v.
MemberWithError Mpv r =>
Property v -> Sem r v
Mpv.prop Property VideoExpired
Property.TimePos
  (VideoTracks
_, AudioTracks
audio, Subtitles
subs) <- Sem r (VideoTracks, AudioTracks, Subtitles)
forall (r :: [(* -> *) -> * -> *]).
Member Mpv r =>
Sem r (VideoTracks, AudioTracks, Subtitles)
tracks
  SubDelay
subDelay <- Property SubDelay -> Sem r SubDelay
forall (r :: [(* -> *) -> * -> *]) v.
MemberWithError Mpv r =>
Property v -> Sem r v
Mpv.prop Property SubDelay
Property.SubDelay
  AudioDelay
audioDelay <- Property AudioDelay -> Sem r AudioDelay
forall (r :: [(* -> *) -> * -> *]) v.
MemberWithError Mpv r =>
Property v -> Sem r v
Mpv.prop Property AudioDelay
Property.AudioDelay
  Volume
volume <- Property Volume -> Sem r Volume
forall (r :: [(* -> *) -> * -> *]) v.
MemberWithError Mpv r =>
Property v -> Sem r v
Mpv.prop Property Volume
Property.Volume
  pure (PlaybackState
-> VideoDuration
-> VideoProgress
-> VideoExpired
-> Subtitles
-> SubDelay
-> AudioTracks
-> AudioDelay
-> Volume
-> MpvInfo
MpvInfo PlaybackState
playback VideoDuration
duration VideoProgress
progress VideoExpired
expired Subtitles
subs SubDelay
subDelay AudioTracks
audio AudioDelay
audioDelay Volume
volume)

adjustVolumeBy ::
  Member Mpv r =>
  Volume ->
  Sem r Volume
adjustVolumeBy :: forall (r :: [(* -> *) -> * -> *]).
Member Mpv r =>
Volume -> Sem r Volume
adjustVolumeBy Volume
delta =
  Property Volume -> (Volume -> Volume) -> Sem r Volume
forall v (r :: [(* -> *) -> * -> *]).
(Show v, Member Mpv r) =>
Property v -> (v -> v) -> Sem r v
alterProp Property Volume
Property.Volume (Volume
delta Volume -> Volume -> Volume
forall a. Num a => a -> a -> a
+)

addAudioDelay ::
  Member Mpv r =>
  AudioDelay ->
  Sem r AudioDelay
addAudioDelay :: forall (r :: [(* -> *) -> * -> *]).
Member Mpv r =>
AudioDelay -> Sem r AudioDelay
addAudioDelay AudioDelay
delta =
  Property AudioDelay
-> (AudioDelay -> AudioDelay) -> Sem r AudioDelay
forall v (r :: [(* -> *) -> * -> *]).
(Show v, Member Mpv r) =>
Property v -> (v -> v) -> Sem r v
alterProp Property AudioDelay
Property.AudioDelay (AudioDelay
delta AudioDelay -> AudioDelay -> AudioDelay
forall a. Num a => a -> a -> a
+)

addSubDelay ::
  Member Mpv r =>
  SubDelay ->
  Sem r SubDelay
addSubDelay :: forall (r :: [(* -> *) -> * -> *]).
Member Mpv r =>
SubDelay -> Sem r SubDelay
addSubDelay SubDelay
delta =
  Property SubDelay -> (SubDelay -> SubDelay) -> Sem r SubDelay
forall v (r :: [(* -> *) -> * -> *]).
(Show v, Member Mpv r) =>
Property v -> (v -> v) -> Sem r v
alterProp Property SubDelay
Property.SubDelay (SubDelay
delta SubDelay -> SubDelay -> SubDelay
forall a. Num a => a -> a -> a
+)