{-# LANGUAGE TypeSynonymInstances #-}
module Derive.Args where
import qualified Data.Map as Map
import qualified Util.Lists as Lists
import qualified Util.Log as Log
import qualified Derive.Derive as Derive
import Derive.Derive (Context, PassedArgs)
import qualified Derive.Deriver.Internal as Internal
import qualified Derive.EnvKey as EnvKey
import qualified Derive.Eval as Eval
import qualified Derive.PSignal as PSignal
import qualified Derive.Parse as Parse
import qualified Derive.Pitches as Pitches
import qualified Derive.Score as Score
import qualified Derive.Stream as Stream
import qualified Perform.Pitch as Pitch
import qualified Perform.RealTime as RealTime
import qualified Perform.Signal as Signal
import qualified Ui.Event as Event
import qualified Ui.Events as Events
import qualified Ui.Track as Track
import qualified Ui.Types as Types
import Global
import Types
context :: PassedArgs a -> Context a
context :: forall a. PassedArgs a -> Context a
context = forall a. PassedArgs a -> Context a
Derive.passed_ctx
event :: PassedArgs a -> Event.Event
event :: forall a. PassedArgs a -> Event
event = forall val. Context val -> Event
Derive.ctx_event forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Context a
context
orientation :: PassedArgs a -> Types.Orientation
orientation :: forall a. PassedArgs a -> Orientation
orientation = Event -> Orientation
Event.orientation forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Event
event
negative :: PassedArgs a -> Bool
negative :: forall a. PassedArgs a -> Bool
negative = (forall a. Eq a => a -> a -> Bool
==Orientation
Types.Negative) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Orientation
orientation
prev_control :: Derive.ControlArgs -> Maybe (RealTime, Signal.Y)
prev_control :: ControlArgs -> Maybe (RealTime, Y)
prev_control = forall {k} (kind :: k). Signal kind -> Maybe (RealTime, Y)
Signal.last forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< forall a. PassedArgs a -> Maybe a
prev_val
prev_pitch :: Derive.PitchArgs -> Maybe (RealTime, PSignal.Pitch)
prev_pitch :: PitchArgs -> Maybe (RealTime, Pitch)
prev_pitch = PSignal -> Maybe (RealTime, Pitch)
PSignal.last forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< forall a. PassedArgs a -> Maybe a
prev_val
prev_event :: Derive.NoteArgs -> Maybe Score.Event
prev_event :: NoteArgs -> Maybe Event
prev_event = forall a. PassedArgs a -> Maybe a
prev_val
prev_event_pitch :: PassedArgs Score.Event -> Maybe PSignal.Pitch
prev_event_pitch :: NoteArgs -> Maybe Pitch
prev_event_pitch NoteArgs
args =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. PSignal -> Maybe (RealTime, Pitch)
PSignal.last forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event -> PSignal
Score.event_pitch forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. PassedArgs a -> Maybe a
prev_val NoteArgs
args
prev_val_end :: Derive.Taggable a => PassedArgs a -> Maybe RealTime
prev_val_end :: forall a. Taggable a => PassedArgs a -> Maybe RealTime
prev_val_end = forall {a}. Taggable a => a -> Maybe RealTime
extract forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< forall a. PassedArgs a -> Maybe a
prev_val
where
extract :: a -> Maybe RealTime
extract a
val = case forall a. Taggable a => a -> Tagged
Derive.to_tagged a
val of
Derive.TagEvent Event
event -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Event -> RealTime
Score.event_end Event
event
Derive.TagControl Control
sig -> forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall {k} (kind :: k). Signal kind -> Maybe (RealTime, Y)
Signal.last Control
sig
Derive.TagPitch PSignal
sig -> forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PSignal -> Maybe (RealTime, Pitch)
PSignal.last PSignal
sig
prev_val :: PassedArgs a -> Maybe a
prev_val :: forall a. PassedArgs a -> Maybe a
prev_val = forall val. Context val -> Maybe val
Derive.ctx_prev_val forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Context a
context
prev_note_pitch :: RealTime -> Derive.Deriver (Maybe PSignal.Pitch)
prev_note_pitch :: RealTime -> Deriver (Maybe Pitch)
prev_note_pitch RealTime
start = forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> (a -> m (Maybe b)) -> m (Maybe b)
justm Deriver (Maybe Event)
prev_note forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PSignal -> RealTime -> Maybe Pitch
`PSignal.at_negative` RealTime
start) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event -> PSignal
Score.event_pitch
prev_note :: Derive.Deriver (Maybe Score.Event)
prev_note :: Deriver (Maybe Event)
prev_note = do
(BlockId, TrackId)
addr <- forall a. HasCallStack => Text -> Maybe a -> Deriver a
Derive.require Text
"lookup_prev_note: no state_note_track"
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall st a err. (st -> a) -> Deriver st err a
Derive.gets (Dynamic -> Maybe (BlockId, TrackId)
Derive.state_note_track forall b c a. (b -> c) -> (a -> b) -> a -> c
. State -> Dynamic
Derive.state_dynamic)
forall st a err. (st -> a) -> Deriver st err a
Derive.gets forall a b. (a -> b) -> a -> b
$ forall a. Taggable a => Tagged -> Maybe a
Derive.from_tagged forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (BlockId, TrackId)
addr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Threaded -> Map (BlockId, TrackId) Tagged
Derive.state_prev_val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State -> Threaded
Derive.state_threaded
lookup_next_pitch :: PassedArgs a -> Derive.Deriver (Maybe PSignal.Pitch)
lookup_next_pitch :: forall a. PassedArgs a -> Deriver (Maybe Pitch)
lookup_next_pitch = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) TrackTime -> Deriver (Maybe Pitch)
lookup_pitch_at forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Maybe TrackTime
next_start
lookup_prev_pitch :: PassedArgs a -> Derive.Deriver (Maybe PSignal.Pitch)
lookup_prev_pitch :: forall a. PassedArgs a -> Deriver (Maybe Pitch)
lookup_prev_pitch = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) TrackTime -> Deriver (Maybe Pitch)
lookup_pitch_at forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Maybe TrackTime
prev_start
lookup_next_note_pitch :: ScoreTime -> Derive.Deriver (Maybe PSignal.Pitch)
lookup_next_note_pitch :: TrackTime -> Deriver (Maybe Pitch)
lookup_next_note_pitch TrackTime
start =
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> (a -> m (Maybe b)) -> m (Maybe b)
justm (TrackTime -> Events -> Maybe Event
note_after TrackTime
start forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Deriver Events
get_note_events) forall a b. (a -> b) -> a -> b
$
TrackTime -> Deriver (Maybe Pitch)
lookup_pitch_at forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event -> TrackTime
Event.start
lookup_prev_note_pitch :: ScoreTime -> Derive.Deriver (Maybe PSignal.Pitch)
lookup_prev_note_pitch :: TrackTime -> Deriver (Maybe Pitch)
lookup_prev_note_pitch TrackTime
start =
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> (a -> m (Maybe b)) -> m (Maybe b)
justm (TrackTime -> Events -> Maybe Event
note_before TrackTime
start forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Deriver Events
get_note_events) forall a b. (a -> b) -> a -> b
$
TrackTime -> Deriver (Maybe Pitch)
lookup_pitch_at forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event -> TrackTime
Event.start
note_before :: TrackTime -> Events.Events -> Maybe Event.Event
note_before :: TrackTime -> Events -> Maybe Event
note_before TrackTime
p = Events -> Maybe Event
Events.last forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. TrackTime -> Events -> (Events, Events)
Events.split_exclude TrackTime
p
note_after :: TrackTime -> Events.Events -> Maybe Event.Event
note_after :: TrackTime -> Events -> Maybe Event
note_after TrackTime
p = Events -> Maybe Event
Events.head forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. TrackTime -> Events -> (Events, Events)
Events.split_exclude TrackTime
p
get_note_events :: Derive.Deriver Events.Events
get_note_events :: Deriver Events
get_note_events = do
(BlockId
_, TrackId
track_id) <- forall a. HasCallStack => Text -> Maybe a -> Deriver a
Derive.require Text
"no state_note_track"
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall st a err. (st -> a) -> Deriver st err a
Derive.gets (Dynamic -> Maybe (BlockId, TrackId)
Derive.state_note_track forall b c a. (b -> c) -> (a -> b) -> a -> c
. State -> Dynamic
Derive.state_dynamic)
Track -> Events
Track.track_events forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TrackId -> Deriver Track
Derive.get_track TrackId
track_id
lookup_pitch_at :: TrackTime -> Derive.Deriver (Maybe PSignal.Pitch)
lookup_pitch_at :: TrackTime -> Deriver (Maybe Pitch)
lookup_pitch_at TrackTime
pos = forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> (a -> m (Maybe b)) -> m (Maybe b)
justm (forall a. (Dynamic -> a) -> Deriver a
Internal.get_dynamic Dynamic -> Maybe (Maybe PSignal, [Msg])
Derive.state_pitch_map) forall a b. (a -> b) -> a -> b
$
\(Maybe PSignal
maybe_sig, [Msg]
logs) -> do
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall (m :: * -> *). LogMonad m => Msg -> m ()
Log.write forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Msg -> Msg
Log.add_prefix (Text
"lookup_pitch_at " forall a. Semigroup a => a -> a -> a
<> forall a. Pretty a => a -> Text
pretty TrackTime
pos)) forall a b. (a -> b) -> a -> b
$
forall a. (a -> Bool) -> [a] -> [a]
filter ((forall a. Ord a => a -> a -> Bool
>=Priority
Log.Warn) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Msg -> Priority
Log.msg_priority) [Msg]
logs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip PSignal -> RealTime -> Maybe Pitch
PSignal.at (TrackTime -> RealTime
RealTime.from_score TrackTime
pos) forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe PSignal
maybe_sig
lookup_parsed_pitch_at :: (Pitch.Note -> Maybe a) -> TrackTime
-> Derive.Deriver (Maybe a)
lookup_parsed_pitch_at :: forall a. (Note -> Maybe a) -> TrackTime -> Deriver (Maybe a)
lookup_parsed_pitch_at Note -> Maybe a
parse_pitch TrackTime
pos =
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> (a -> m (Maybe b)) -> m (Maybe b)
justm (TrackTime -> Deriver (Maybe Pitch)
lookup_pitch_at TrackTime
pos) forall a b. (a -> b) -> a -> b
$ \Pitch
pitch -> do
RealTime
rpos <- forall a. Time a => a -> Deriver RealTime
Derive.real TrackTime
pos
Note
note <- Transposed -> Deriver State Error Note
Pitches.pitch_note forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< RealTime -> Pitch -> Deriver Transposed
Derive.resolve_pitch RealTime
rpos Pitch
pitch
forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. HasCallStack => Text -> Maybe a -> Deriver a
Derive.require Text
"unparseable pitch" (Note -> Maybe a
parse_pitch Note
note)
eval :: Derive.CallableExpr d => Context x -> Event.Event -> [Event.Event]
-> Derive.Deriver (Stream.Stream d)
eval :: forall d x.
CallableExpr d =>
Context x -> Event -> [Event] -> Deriver (Stream d)
eval Context x
ctx Event
event [Event]
prev = case Text -> Either Text Expr
Parse.parse_expr (Event -> Text
Event.text Event
event) of
Left Text
err -> forall a. HasCallStack => Text -> Deriver a
Derive.throw forall a b. (a -> b) -> a -> b
$ Text
"parse error: " forall a. Semigroup a => a -> a -> a
<> Text
err
Right Expr
expr -> forall d.
CallableExpr d =>
Bool -> Context d -> Expr -> Deriver (Stream d)
Eval.eval_expr Bool
False forall {val}. Context val
prev_ctx Expr
expr
where
prev_ctx :: Context val
prev_ctx = Context x
ctx
{ ctx_prev_val :: Maybe val
Derive.ctx_prev_val = forall a. Maybe a
Nothing
, ctx_event :: Event
Derive.ctx_event = Event
event
, ctx_prev_events :: [Event]
Derive.ctx_prev_events = [Event]
prev
, ctx_next_events :: [Event]
Derive.ctx_next_events =
forall val. Context val -> Event
Derive.ctx_event Context x
ctx forall a. a -> [a] -> [a]
: forall val. Context val -> [Event]
Derive.ctx_next_events Context x
ctx
, ctx_event_end :: TrackTime
Derive.ctx_event_end = Event -> TrackTime
Event.start forall a b. (a -> b) -> a -> b
$ forall val. Context val -> Event
Derive.ctx_event Context x
ctx
}
eval_next_pitch :: Derive.PitchArgs -> Derive.Deriver (Maybe PSignal.Pitch)
eval_next_pitch :: PitchArgs -> Deriver (Maybe Pitch)
eval_next_pitch = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) Event -> Deriver (Maybe Pitch)
eval_pitch forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Maybe a
Lists.head forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> [Event]
next_events
eval_pitch :: Event.Event -> Derive.Deriver (Maybe PSignal.Pitch)
eval_pitch :: Event -> Deriver (Maybe Pitch)
eval_pitch Event
event = forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> (a -> m (Maybe b)) -> m (Maybe b)
justm (forall {a} {a}. Either a a -> Maybe a
to_maybe forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall d.
CallableExpr d =>
Event -> Deriver (Either Text (Stream d))
Eval.eval_event Event
event) forall a b. (a -> b) -> a -> b
$ \Stream PSignal
stream -> do
RealTime
start <- forall a. Time a => a -> Deriver RealTime
Derive.real (Event -> TrackTime
Event.start Event
event)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ PSignal -> RealTime -> Maybe Pitch
PSignal.at (forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ forall a. Stream a -> [a]
Stream.events_of Stream PSignal
stream) RealTime
start
where to_maybe :: Either a a -> Maybe a
to_maybe = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> b -> a
const forall a. Maybe a
Nothing) forall a. a -> Maybe a
Just
start :: PassedArgs a -> TrackTime
start :: forall a. PassedArgs a -> TrackTime
start = Event -> TrackTime
Event.start forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Event
event
duration :: PassedArgs a -> TrackTime
duration :: forall a. PassedArgs a -> TrackTime
duration = Event -> TrackTime
Event.duration forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Event
event
real_duration :: PassedArgs a -> Derive.Deriver RealTime
real_duration :: forall a. PassedArgs a -> Deriver RealTime
real_duration PassedArgs a
args = (-) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. PassedArgs a -> Deriver RealTime
real_end PassedArgs a
args forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. PassedArgs a -> Deriver RealTime
real_start PassedArgs a
args
real_start :: PassedArgs a -> Derive.Deriver RealTime
real_start :: forall a. PassedArgs a -> Deriver RealTime
real_start = forall a. Time a => a -> Deriver RealTime
Derive.real forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> TrackTime
start
end :: PassedArgs a -> TrackTime
end :: forall a. PassedArgs a -> TrackTime
end = Event -> TrackTime
Event.end forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Event
event
real_end :: PassedArgs a -> Derive.Deriver RealTime
real_end :: forall a. PassedArgs a -> Deriver RealTime
real_end = forall a. Time a => a -> Deriver RealTime
Derive.real forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> TrackTime
end
next :: PassedArgs a -> TrackTime
next :: forall a. PassedArgs a -> TrackTime
next = forall val. Context val -> TrackTime
Derive.ctx_event_end forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Context a
context
next_end :: PassedArgs a -> TrackTime
next_end :: forall a. PassedArgs a -> TrackTime
next_end PassedArgs a
args = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a. PassedArgs a -> TrackTime
next PassedArgs a
args) Event -> TrackTime
Event.end (forall a. [a] -> Maybe a
Lists.head (forall a. PassedArgs a -> [Event]
next_events PassedArgs a
args))
next_start :: PassedArgs a -> Maybe TrackTime
next_start :: forall a. PassedArgs a -> Maybe TrackTime
next_start = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Event -> TrackTime
Event.start forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Maybe a
Lists.head forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> [Event]
next_events
prev_start :: PassedArgs a -> Maybe TrackTime
prev_start :: forall a. PassedArgs a -> Maybe TrackTime
prev_start = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Event -> TrackTime
Event.start forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Maybe a
Lists.head forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> [Event]
prev_events
prev_end :: PassedArgs a -> Maybe TrackTime
prev_end :: forall a. PassedArgs a -> Maybe TrackTime
prev_end = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Event -> TrackTime
Event.end forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Maybe a
Lists.head forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> [Event]
prev_events
prev_events, next_events :: PassedArgs a -> [Event.Event]
next_events :: forall a. PassedArgs a -> [Event]
next_events = forall val. Context val -> [Event]
Derive.ctx_next_events forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Context a
context
prev_events :: forall a. PassedArgs a -> [Event]
prev_events = forall val. Context val -> [Event]
Derive.ctx_prev_events forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Context a
context
set_duration :: TrackTime -> PassedArgs a -> PassedArgs a
set_duration :: forall a. TrackTime -> PassedArgs a -> PassedArgs a
set_duration TrackTime
dur PassedArgs a
args = PassedArgs a
args
{ passed_ctx :: Context a
Derive.passed_ctx = Context a
ctx
{ ctx_event :: Event
Derive.ctx_event = Lens Event TrackTime
Event.duration_ forall f a. Lens f a -> a -> f -> f
#= TrackTime
dur forall a b. (a -> b) -> a -> b
$ forall val. Context val -> Event
Derive.ctx_event Context a
ctx }
}
where ctx :: Context a
ctx = forall a. PassedArgs a -> Context a
Derive.passed_ctx PassedArgs a
args
range :: PassedArgs a -> (TrackTime, TrackTime)
range :: forall a. PassedArgs a -> (TrackTime, TrackTime)
range = Event -> (TrackTime, TrackTime)
Event.range forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Event
event
real_range :: PassedArgs a -> Derive.Deriver (RealTime, RealTime)
real_range :: forall a. PassedArgs a -> Deriver (RealTime, RealTime)
real_range PassedArgs a
args = (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Time a => a -> Deriver RealTime
Derive.real TrackTime
start forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Time a => a -> Deriver RealTime
Derive.real TrackTime
end
where (TrackTime
start, TrackTime
end) = forall a. PassedArgs a -> (TrackTime, TrackTime)
range PassedArgs a
args
range_or_next :: PassedArgs a -> (TrackTime, TrackTime)
range_or_next :: forall a. PassedArgs a -> (TrackTime, TrackTime)
range_or_next PassedArgs a
args
| TrackTime
start forall a. Eq a => a -> a -> Bool
== TrackTime
end = (TrackTime
start, forall a. PassedArgs a -> TrackTime
next PassedArgs a
args)
| Bool
otherwise = (TrackTime
start, TrackTime
end)
where (TrackTime
start, TrackTime
end) = forall a. PassedArgs a -> (TrackTime, TrackTime)
range PassedArgs a
args
real_range_or_next :: PassedArgs a -> Derive.Deriver (RealTime, RealTime)
real_range_or_next :: forall a. PassedArgs a -> Deriver (RealTime, RealTime)
real_range_or_next PassedArgs a
args = (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Time a => a -> Deriver RealTime
Derive.real TrackTime
start forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Time a => a -> Deriver RealTime
Derive.real TrackTime
end
where (TrackTime
start, TrackTime
end) = forall a. PassedArgs a -> (TrackTime, TrackTime)
range_or_next PassedArgs a
args
range_or_note_end :: PassedArgs a -> Derive.Deriver (TrackTime, TrackTime)
range_or_note_end :: forall a. PassedArgs a -> Deriver (TrackTime, TrackTime)
range_or_note_end PassedArgs a
args
| TrackTime
start forall a. Eq a => a -> a -> Bool
== TrackTime
end = do
Maybe TrackTime
note_start <- forall a. Typecheck a => Text -> Deriver (Maybe a)
Derive.lookup_val Text
EnvKey.note_start
Maybe TrackTime
note_end <- forall a. Typecheck a => Text -> Deriver (Maybe a)
Derive.lookup_val Text
EnvKey.note_end
case (Maybe TrackTime
note_start, Maybe TrackTime
note_end) of
(Just TrackTime
note_start, Just TrackTime
note_end)
| TrackTime
start forall a. Ord a => a -> a -> Bool
< TrackTime
note_start -> forall (m :: * -> *) a. Monad m => a -> m a
return (TrackTime
note_start, TrackTime
note_start)
| Bool
otherwise ->
forall (m :: * -> *) a. Monad m => a -> m a
return (TrackTime
start, forall a. Ord a => a -> a -> a
min (forall a. PassedArgs a -> TrackTime
next PassedArgs a
args) (forall a. Ord a => a -> a -> a
max TrackTime
end TrackTime
note_end))
(Maybe TrackTime, Maybe TrackTime)
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return (TrackTime
start, forall a. PassedArgs a -> TrackTime
next PassedArgs a
args)
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return (TrackTime
start, TrackTime
end)
where (TrackTime
start, TrackTime
end) = forall a. PassedArgs a -> (TrackTime, TrackTime)
range PassedArgs a
args
extent :: PassedArgs a -> (TrackTime, TrackTime)
extent :: forall a. PassedArgs a -> (TrackTime, TrackTime)
extent = (\Event
e -> (Event -> TrackTime
Event.start Event
e, Event -> TrackTime
Event.duration Event
e)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PassedArgs a -> Event
event
real_extent :: PassedArgs a -> Derive.Deriver (RealTime, RealTime)
real_extent :: forall a. PassedArgs a -> Deriver (RealTime, RealTime)
real_extent PassedArgs a
args = do
let e :: Event
e = forall a. PassedArgs a -> Event
event PassedArgs a
args
RealTime
start <- forall a. Time a => a -> Deriver RealTime
Derive.real (Event -> TrackTime
Event.start Event
e)
RealTime
end <- forall a. Time a => a -> Deriver RealTime
Derive.real (Event -> TrackTime
Event.end Event
e)
forall (m :: * -> *) a. Monad m => a -> m a
return (RealTime
start, RealTime
end forall a. Num a => a -> a -> a
- RealTime
start)
range_on_track :: PassedArgs a -> (TrackTime, TrackTime)
range_on_track :: forall a. PassedArgs a -> (TrackTime, TrackTime)
range_on_track PassedArgs a
args = (TrackTime
shifted forall a. Num a => a -> a -> a
+ TrackTime
start, TrackTime
shifted forall a. Num a => a -> a -> a
+ TrackTime
end)
where
(TrackTime
start, TrackTime
end) = forall a. PassedArgs a -> (TrackTime, TrackTime)
range PassedArgs a
args
shifted :: TrackTime
shifted = forall val. Context val -> TrackTime
Derive.ctx_track_shifted (forall a. PassedArgs a -> Context a
context PassedArgs a
args)
normalized :: PassedArgs a -> Derive.Deriver b -> Derive.Deriver b
normalized :: forall a b. PassedArgs a -> Deriver b -> Deriver b
normalized PassedArgs a
args = forall a. TrackTime -> TrackTime -> Deriver a -> Deriver a
Derive.place (- (TrackTime
start forall a. Fractional a => a -> a -> a
/ TrackTime
dur)) (TrackTime
1 forall a. Fractional a => a -> a -> a
/ TrackTime
dur)
where
(TrackTime
start, TrackTime
dur_) = forall a. PassedArgs a -> (TrackTime, TrackTime)
extent PassedArgs a
args
dur :: TrackTime
dur = if TrackTime
dur_ forall a. Eq a => a -> a -> Bool
== TrackTime
0 then TrackTime
1 else TrackTime
dur_
normalized_start :: PassedArgs a -> Derive.Deriver b -> Derive.Deriver b
normalized_start :: forall a b. PassedArgs a -> Deriver b -> Deriver b
normalized_start PassedArgs a
args = forall a. TrackTime -> Deriver a -> Deriver a
Derive.at (- forall a. PassedArgs a -> TrackTime
start PassedArgs a
args)