{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}
module Data.Active
(
Time, toTime, fromTime
, Duration, toDuration, fromDuration
, Era, mkEra
, start, end, duration
, Dynamic(..), mkDynamic, onDynamic
, shiftDynamic
, Active, mkActive, fromDynamic, isConstant, isDynamic
, onActive, modActive, runActive
, activeEra, setEra, atTime
, activeStart, activeEnd
, ui, interval
, stretch, stretchTo, during
, shift, backwards
, snapshot
, clamp, clampBefore, clampAfter
, trim, trimBefore, trimAfter
, after
, (->>)
, (|>>), movie
, discrete
, simulate
) where
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
import Control.Arrow ((&&&))
import Control.Lens hiding (backwards, (<.>))
import Data.Functor.Apply
import Data.Maybe
import Data.Monoid (First (..))
import Data.Semigroup hiding (First (..))
import qualified Data.Vector as V
import Linear
import Linear.Affine
newtype Time n = Time { forall n. Time n -> n
unTime :: n }
deriving (Time n -> Time n -> Bool
forall n. Eq n => Time n -> Time n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Time n -> Time n -> Bool
$c/= :: forall n. Eq n => Time n -> Time n -> Bool
== :: Time n -> Time n -> Bool
$c== :: forall n. Eq n => Time n -> Time n -> Bool
Eq, Time n -> Time n -> Bool
Time n -> Time n -> Ordering
Time n -> Time n -> Time n
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {n}. Ord n => Eq (Time n)
forall n. Ord n => Time n -> Time n -> Bool
forall n. Ord n => Time n -> Time n -> Ordering
forall n. Ord n => Time n -> Time n -> Time n
min :: Time n -> Time n -> Time n
$cmin :: forall n. Ord n => Time n -> Time n -> Time n
max :: Time n -> Time n -> Time n
$cmax :: forall n. Ord n => Time n -> Time n -> Time n
>= :: Time n -> Time n -> Bool
$c>= :: forall n. Ord n => Time n -> Time n -> Bool
> :: Time n -> Time n -> Bool
$c> :: forall n. Ord n => Time n -> Time n -> Bool
<= :: Time n -> Time n -> Bool
$c<= :: forall n. Ord n => Time n -> Time n -> Bool
< :: Time n -> Time n -> Bool
$c< :: forall n. Ord n => Time n -> Time n -> Bool
compare :: Time n -> Time n -> Ordering
$ccompare :: forall n. Ord n => Time n -> Time n -> Ordering
Ord, Int -> Time n -> ShowS
forall n. Show n => Int -> Time n -> ShowS
forall n. Show n => [Time n] -> ShowS
forall n. Show n => Time n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Time n] -> ShowS
$cshowList :: forall n. Show n => [Time n] -> ShowS
show :: Time n -> String
$cshow :: forall n. Show n => Time n -> String
showsPrec :: Int -> Time n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Time n -> ShowS
Show, ReadPrec [Time n]
ReadPrec (Time n)
ReadS [Time n]
forall n. Read n => ReadPrec [Time n]
forall n. Read n => ReadPrec (Time n)
forall n. Read n => Int -> ReadS (Time n)
forall n. Read n => ReadS [Time n]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Time n]
$creadListPrec :: forall n. Read n => ReadPrec [Time n]
readPrec :: ReadPrec (Time n)
$creadPrec :: forall n. Read n => ReadPrec (Time n)
readList :: ReadS [Time n]
$creadList :: forall n. Read n => ReadS [Time n]
readsPrec :: Int -> ReadS (Time n)
$creadsPrec :: forall n. Read n => Int -> ReadS (Time n)
Read, Int -> Time n
Time n -> Int
Time n -> [Time n]
Time n -> Time n
Time n -> Time n -> [Time n]
Time n -> Time n -> Time n -> [Time n]
forall n. Enum n => Int -> Time n
forall n. Enum n => Time n -> Int
forall n. Enum n => Time n -> [Time n]
forall n. Enum n => Time n -> Time n
forall n. Enum n => Time n -> Time n -> [Time n]
forall n. Enum n => Time n -> Time n -> Time n -> [Time n]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Time n -> Time n -> Time n -> [Time n]
$cenumFromThenTo :: forall n. Enum n => Time n -> Time n -> Time n -> [Time n]
enumFromTo :: Time n -> Time n -> [Time n]
$cenumFromTo :: forall n. Enum n => Time n -> Time n -> [Time n]
enumFromThen :: Time n -> Time n -> [Time n]
$cenumFromThen :: forall n. Enum n => Time n -> Time n -> [Time n]
enumFrom :: Time n -> [Time n]
$cenumFrom :: forall n. Enum n => Time n -> [Time n]
fromEnum :: Time n -> Int
$cfromEnum :: forall n. Enum n => Time n -> Int
toEnum :: Int -> Time n
$ctoEnum :: forall n. Enum n => Int -> Time n
pred :: Time n -> Time n
$cpred :: forall n. Enum n => Time n -> Time n
succ :: Time n -> Time n
$csucc :: forall n. Enum n => Time n -> Time n
Enum, Integer -> Time n
Time n -> Time n
Time n -> Time n -> Time n
forall n. Num n => Integer -> Time n
forall n. Num n => Time n -> Time n
forall n. Num n => Time n -> Time n -> Time n
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> Time n
$cfromInteger :: forall n. Num n => Integer -> Time n
signum :: Time n -> Time n
$csignum :: forall n. Num n => Time n -> Time n
abs :: Time n -> Time n
$cabs :: forall n. Num n => Time n -> Time n
negate :: Time n -> Time n
$cnegate :: forall n. Num n => Time n -> Time n
* :: Time n -> Time n -> Time n
$c* :: forall n. Num n => Time n -> Time n -> Time n
- :: Time n -> Time n -> Time n
$c- :: forall n. Num n => Time n -> Time n -> Time n
+ :: Time n -> Time n -> Time n
$c+ :: forall n. Num n => Time n -> Time n -> Time n
Num, Rational -> Time n
Time n -> Time n
Time n -> Time n -> Time n
forall {n}. Fractional n => Num (Time n)
forall n. Fractional n => Rational -> Time n
forall n. Fractional n => Time n -> Time n
forall n. Fractional n => Time n -> Time n -> Time n
forall a.
Num a
-> (a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
fromRational :: Rational -> Time n
$cfromRational :: forall n. Fractional n => Rational -> Time n
recip :: Time n -> Time n
$crecip :: forall n. Fractional n => Time n -> Time n
/ :: Time n -> Time n -> Time n
$c/ :: forall n. Fractional n => Time n -> Time n -> Time n
Fractional, Time n -> Rational
forall a. Num a -> Ord a -> (a -> Rational) -> Real a
forall {n}. Real n => Num (Time n)
forall {n}. Real n => Ord (Time n)
forall n. Real n => Time n -> Rational
toRational :: Time n -> Rational
$ctoRational :: forall n. Real n => Time n -> Rational
Real, forall b. Integral b => Time n -> b
forall b. Integral b => Time n -> (b, Time n)
forall a.
Real a
-> Fractional a
-> (forall b. Integral b => a -> (b, a))
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> RealFrac a
forall {n}. RealFrac n => Fractional (Time n)
forall {n}. RealFrac n => Real (Time n)
forall n b. (RealFrac n, Integral b) => Time n -> b
forall n b. (RealFrac n, Integral b) => Time n -> (b, Time n)
floor :: forall b. Integral b => Time n -> b
$cfloor :: forall n b. (RealFrac n, Integral b) => Time n -> b
ceiling :: forall b. Integral b => Time n -> b
$cceiling :: forall n b. (RealFrac n, Integral b) => Time n -> b
round :: forall b. Integral b => Time n -> b
$cround :: forall n b. (RealFrac n, Integral b) => Time n -> b
truncate :: forall b. Integral b => Time n -> b
$ctruncate :: forall n b. (RealFrac n, Integral b) => Time n -> b
properFraction :: forall b. Integral b => Time n -> (b, Time n)
$cproperFraction :: forall n b. (RealFrac n, Integral b) => Time n -> (b, Time n)
RealFrac, forall a b. a -> Time b -> Time a
forall a b. (a -> b) -> Time a -> Time b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Time b -> Time a
$c<$ :: forall a b. a -> Time b -> Time a
fmap :: forall a b. (a -> b) -> Time a -> Time b
$cfmap :: forall a b. (a -> b) -> Time a -> Time b
Functor)
makeWrapped ''Time
toTime :: n -> Time n
toTime :: forall n. n -> Time n
toTime = forall n. n -> Time n
Time
fromTime :: Time n -> n
fromTime :: forall n. Time n -> n
fromTime = forall n. Time n -> n
unTime
newtype Duration n = Duration n
deriving (Duration n -> Duration n -> Bool
forall n. Eq n => Duration n -> Duration n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Duration n -> Duration n -> Bool
$c/= :: forall n. Eq n => Duration n -> Duration n -> Bool
== :: Duration n -> Duration n -> Bool
$c== :: forall n. Eq n => Duration n -> Duration n -> Bool
Eq, Duration n -> Duration n -> Bool
Duration n -> Duration n -> Ordering
Duration n -> Duration n -> Duration n
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {n}. Ord n => Eq (Duration n)
forall n. Ord n => Duration n -> Duration n -> Bool
forall n. Ord n => Duration n -> Duration n -> Ordering
forall n. Ord n => Duration n -> Duration n -> Duration n
min :: Duration n -> Duration n -> Duration n
$cmin :: forall n. Ord n => Duration n -> Duration n -> Duration n
max :: Duration n -> Duration n -> Duration n
$cmax :: forall n. Ord n => Duration n -> Duration n -> Duration n
>= :: Duration n -> Duration n -> Bool
$c>= :: forall n. Ord n => Duration n -> Duration n -> Bool
> :: Duration n -> Duration n -> Bool
$c> :: forall n. Ord n => Duration n -> Duration n -> Bool
<= :: Duration n -> Duration n -> Bool
$c<= :: forall n. Ord n => Duration n -> Duration n -> Bool
< :: Duration n -> Duration n -> Bool
$c< :: forall n. Ord n => Duration n -> Duration n -> Bool
compare :: Duration n -> Duration n -> Ordering
$ccompare :: forall n. Ord n => Duration n -> Duration n -> Ordering
Ord, Int -> Duration n -> ShowS
forall n. Show n => Int -> Duration n -> ShowS
forall n. Show n => [Duration n] -> ShowS
forall n. Show n => Duration n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Duration n] -> ShowS
$cshowList :: forall n. Show n => [Duration n] -> ShowS
show :: Duration n -> String
$cshow :: forall n. Show n => Duration n -> String
showsPrec :: Int -> Duration n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Duration n -> ShowS
Show, ReadPrec [Duration n]
ReadPrec (Duration n)
ReadS [Duration n]
forall n. Read n => ReadPrec [Duration n]
forall n. Read n => ReadPrec (Duration n)
forall n. Read n => Int -> ReadS (Duration n)
forall n. Read n => ReadS [Duration n]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Duration n]
$creadListPrec :: forall n. Read n => ReadPrec [Duration n]
readPrec :: ReadPrec (Duration n)
$creadPrec :: forall n. Read n => ReadPrec (Duration n)
readList :: ReadS [Duration n]
$creadList :: forall n. Read n => ReadS [Duration n]
readsPrec :: Int -> ReadS (Duration n)
$creadsPrec :: forall n. Read n => Int -> ReadS (Duration n)
Read, Int -> Duration n
Duration n -> Int
Duration n -> [Duration n]
Duration n -> Duration n
Duration n -> Duration n -> [Duration n]
Duration n -> Duration n -> Duration n -> [Duration n]
forall n. Enum n => Int -> Duration n
forall n. Enum n => Duration n -> Int
forall n. Enum n => Duration n -> [Duration n]
forall n. Enum n => Duration n -> Duration n
forall n. Enum n => Duration n -> Duration n -> [Duration n]
forall n.
Enum n =>
Duration n -> Duration n -> Duration n -> [Duration n]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Duration n -> Duration n -> Duration n -> [Duration n]
$cenumFromThenTo :: forall n.
Enum n =>
Duration n -> Duration n -> Duration n -> [Duration n]
enumFromTo :: Duration n -> Duration n -> [Duration n]
$cenumFromTo :: forall n. Enum n => Duration n -> Duration n -> [Duration n]
enumFromThen :: Duration n -> Duration n -> [Duration n]
$cenumFromThen :: forall n. Enum n => Duration n -> Duration n -> [Duration n]
enumFrom :: Duration n -> [Duration n]
$cenumFrom :: forall n. Enum n => Duration n -> [Duration n]
fromEnum :: Duration n -> Int
$cfromEnum :: forall n. Enum n => Duration n -> Int
toEnum :: Int -> Duration n
$ctoEnum :: forall n. Enum n => Int -> Duration n
pred :: Duration n -> Duration n
$cpred :: forall n. Enum n => Duration n -> Duration n
succ :: Duration n -> Duration n
$csucc :: forall n. Enum n => Duration n -> Duration n
Enum, Integer -> Duration n
Duration n -> Duration n
Duration n -> Duration n -> Duration n
forall n. Num n => Integer -> Duration n
forall n. Num n => Duration n -> Duration n
forall n. Num n => Duration n -> Duration n -> Duration n
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> Duration n
$cfromInteger :: forall n. Num n => Integer -> Duration n
signum :: Duration n -> Duration n
$csignum :: forall n. Num n => Duration n -> Duration n
abs :: Duration n -> Duration n
$cabs :: forall n. Num n => Duration n -> Duration n
negate :: Duration n -> Duration n
$cnegate :: forall n. Num n => Duration n -> Duration n
* :: Duration n -> Duration n -> Duration n
$c* :: forall n. Num n => Duration n -> Duration n -> Duration n
- :: Duration n -> Duration n -> Duration n
$c- :: forall n. Num n => Duration n -> Duration n -> Duration n
+ :: Duration n -> Duration n -> Duration n
$c+ :: forall n. Num n => Duration n -> Duration n -> Duration n
Num, Rational -> Duration n
Duration n -> Duration n
Duration n -> Duration n -> Duration n
forall {n}. Fractional n => Num (Duration n)
forall n. Fractional n => Rational -> Duration n
forall n. Fractional n => Duration n -> Duration n
forall n. Fractional n => Duration n -> Duration n -> Duration n
forall a.
Num a
-> (a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
fromRational :: Rational -> Duration n
$cfromRational :: forall n. Fractional n => Rational -> Duration n
recip :: Duration n -> Duration n
$crecip :: forall n. Fractional n => Duration n -> Duration n
/ :: Duration n -> Duration n -> Duration n
$c/ :: forall n. Fractional n => Duration n -> Duration n -> Duration n
Fractional, Duration n -> Rational
forall a. Num a -> Ord a -> (a -> Rational) -> Real a
forall {n}. Real n => Num (Duration n)
forall {n}. Real n => Ord (Duration n)
forall n. Real n => Duration n -> Rational
toRational :: Duration n -> Rational
$ctoRational :: forall n. Real n => Duration n -> Rational
Real, forall b. Integral b => Duration n -> b
forall b. Integral b => Duration n -> (b, Duration n)
forall a.
Real a
-> Fractional a
-> (forall b. Integral b => a -> (b, a))
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> RealFrac a
forall {n}. RealFrac n => Fractional (Duration n)
forall {n}. RealFrac n => Real (Duration n)
forall n b. (RealFrac n, Integral b) => Duration n -> b
forall n b.
(RealFrac n, Integral b) =>
Duration n -> (b, Duration n)
floor :: forall b. Integral b => Duration n -> b
$cfloor :: forall n b. (RealFrac n, Integral b) => Duration n -> b
ceiling :: forall b. Integral b => Duration n -> b
$cceiling :: forall n b. (RealFrac n, Integral b) => Duration n -> b
round :: forall b. Integral b => Duration n -> b
$cround :: forall n b. (RealFrac n, Integral b) => Duration n -> b
truncate :: forall b. Integral b => Duration n -> b
$ctruncate :: forall n b. (RealFrac n, Integral b) => Duration n -> b
properFraction :: forall b. Integral b => Duration n -> (b, Duration n)
$cproperFraction :: forall n b.
(RealFrac n, Integral b) =>
Duration n -> (b, Duration n)
RealFrac, forall a b. a -> Duration b -> Duration a
forall a b. (a -> b) -> Duration a -> Duration b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Duration b -> Duration a
$c<$ :: forall a b. a -> Duration b -> Duration a
fmap :: forall a b. (a -> b) -> Duration a -> Duration b
$cfmap :: forall a b. (a -> b) -> Duration a -> Duration b
Functor)
toDuration :: n -> Duration n
toDuration :: forall n. n -> Duration n
toDuration = forall n. n -> Duration n
Duration
fromDuration :: Duration n -> n
fromDuration :: forall n. Duration n -> n
fromDuration (Duration n
n) = n
n
instance Applicative Duration where
pure :: forall n. n -> Duration n
pure = forall n. n -> Duration n
Duration
Duration a -> b
f <*> :: forall a b. Duration (a -> b) -> Duration a -> Duration b
<*> Duration a
x = forall n. n -> Duration n
Duration (a -> b
f a
x)
instance Additive Duration where
zero :: forall a. Num a => Duration a
zero = Duration a
0
instance Num n => Semigroup (Duration n) where
<> :: Duration n -> Duration n -> Duration n
(<>) = forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
(^+^)
instance Num n => Monoid (Duration n) where
mappend :: Duration n -> Duration n -> Duration n
mappend = forall a. Semigroup a => a -> a -> a
(<>)
mempty :: Duration n
mempty = Duration n
0
instance Affine Time where
type Diff Time = Duration
(Time a
t1) .-. :: forall a. Num a => Time a -> Time a -> Diff Time a
.-. (Time a
t2) = forall n. n -> Duration n
Duration (a
t1 forall a. Num a => a -> a -> a
- a
t2)
(Time a
t) .+^ :: forall a. Num a => Time a -> Diff Time a -> Time a
.+^ (Duration a
d) = forall n. n -> Time n
Time (a
t forall a. Num a => a -> a -> a
+ a
d)
makeWrapped ''Duration
newtype Era n = Era (Min (Time n), Max (Time n))
deriving (Int -> Era n -> ShowS
forall n. Show n => Int -> Era n -> ShowS
forall n. Show n => [Era n] -> ShowS
forall n. Show n => Era n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Era n] -> ShowS
$cshowList :: forall n. Show n => [Era n] -> ShowS
show :: Era n -> String
$cshow :: forall n. Show n => Era n -> String
showsPrec :: Int -> Era n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Era n -> ShowS
Show, NonEmpty (Era n) -> Era n
Era n -> Era n -> Era n
forall b. Integral b => b -> Era n -> Era n
forall n. Ord n => NonEmpty (Era n) -> Era n
forall n. Ord n => Era n -> Era n -> Era n
forall n b. (Ord n, Integral b) => b -> Era n -> Era n
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> Era n -> Era n
$cstimes :: forall n b. (Ord n, Integral b) => b -> Era n -> Era n
sconcat :: NonEmpty (Era n) -> Era n
$csconcat :: forall n. Ord n => NonEmpty (Era n) -> Era n
<> :: Era n -> Era n -> Era n
$c<> :: forall n. Ord n => Era n -> Era n -> Era n
Semigroup)
mkEra :: Time n -> Time n -> Era n
mkEra :: forall n. Time n -> Time n -> Era n
mkEra Time n
s Time n
e = forall n. (Min (Time n), Max (Time n)) -> Era n
Era (forall a. a -> Min a
Min Time n
s, forall a. a -> Max a
Max Time n
e)
start :: Era n -> Time n
start :: forall n. Era n -> Time n
start (Era (Min Time n
t, Max (Time n)
_)) = Time n
t
end :: Era n -> Time n
end :: forall n. Era n -> Time n
end (Era (Min (Time n)
_, Max Time n
t)) = Time n
t
duration :: Num n => Era n -> Duration n
duration :: forall n. Num n => Era n -> Duration n
duration = forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
(.-.) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall n. Era n -> Time n
end forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall n. Era n -> Time n
start
data Dynamic a = Dynamic { forall a. Dynamic a -> Era Rational
era :: Era Rational
, forall a. Dynamic a -> Time Rational -> a
runDynamic :: Time Rational -> a
}
deriving forall a b. a -> Dynamic b -> Dynamic a
forall a b. (a -> b) -> Dynamic a -> Dynamic b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Dynamic b -> Dynamic a
$c<$ :: forall a b. a -> Dynamic b -> Dynamic a
fmap :: forall a b. (a -> b) -> Dynamic a -> Dynamic b
$cfmap :: forall a b. (a -> b) -> Dynamic a -> Dynamic b
Functor
instance Apply Dynamic where
(Dynamic Era Rational
d1 Time Rational -> a -> b
f1) <.> :: forall a b. Dynamic (a -> b) -> Dynamic a -> Dynamic b
<.> (Dynamic Era Rational
d2 Time Rational -> a
f2) = forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
Dynamic (Era Rational
d1 forall a. Semigroup a => a -> a -> a
<> Era Rational
d2) (Time Rational -> a -> b
f1 forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> Time Rational -> a
f2)
instance Semigroup a => Semigroup (Dynamic a) where
Dynamic Era Rational
d1 Time Rational -> a
f1 <> :: Dynamic a -> Dynamic a -> Dynamic a
<> Dynamic Era Rational
d2 Time Rational -> a
f2 = forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
Dynamic (Era Rational
d1 forall a. Semigroup a => a -> a -> a
<> Era Rational
d2) (Time Rational -> a
f1 forall a. Semigroup a => a -> a -> a
<> Time Rational -> a
f2)
mkDynamic :: Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic :: forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic Time Rational
s Time Rational
e = forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
Dynamic (forall n. Time n -> Time n -> Era n
mkEra Time Rational
s Time Rational
e)
onDynamic :: (Time Rational -> Time Rational -> (Time Rational -> a) -> b) -> Dynamic a -> b
onDynamic :: forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic Time Rational -> Time Rational -> (Time Rational -> a) -> b
f (Dynamic Era Rational
e Time Rational -> a
d) = Time Rational -> Time Rational -> (Time Rational -> a) -> b
f (forall n. Era n -> Time n
start Era Rational
e) (forall n. Era n -> Time n
end Era Rational
e) Time Rational -> a
d
shiftDynamic :: Duration Rational -> Dynamic a -> Dynamic a
shiftDynamic :: forall a. Duration Rational -> Dynamic a -> Dynamic a
shiftDynamic Duration Rational
sh =
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic
(Time Rational
s forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ Duration Rational
sh)
(Time Rational
e forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ Duration Rational
sh)
(\Time Rational
t -> Time Rational -> a
d (Time Rational
t forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.-^ Duration Rational
sh))
newtype Active a = Active (MaybeApply Dynamic a)
deriving (forall a b. a -> Active b -> Active a
forall a b. (a -> b) -> Active a -> Active b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Active b -> Active a
$c<$ :: forall a b. a -> Active b -> Active a
fmap :: forall a b. (a -> b) -> Active a -> Active b
$cfmap :: forall a b. (a -> b) -> Active a -> Active b
Functor, Functor Active
forall a b. Active a -> Active b -> Active a
forall a b. Active a -> Active b -> Active b
forall a b. Active (a -> b) -> Active a -> Active b
forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
forall (f :: * -> *).
Functor f
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> Apply f
liftF2 :: forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
$cliftF2 :: forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
<. :: forall a b. Active a -> Active b -> Active a
$c<. :: forall a b. Active a -> Active b -> Active a
.> :: forall a b. Active a -> Active b -> Active b
$c.> :: forall a b. Active a -> Active b -> Active b
<.> :: forall a b. Active (a -> b) -> Active a -> Active b
$c<.> :: forall a b. Active (a -> b) -> Active a -> Active b
Apply, Functor Active
forall a. a -> Active a
forall a b. Active a -> Active b -> Active a
forall a b. Active a -> Active b -> Active b
forall a b. Active (a -> b) -> Active a -> Active b
forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: forall a b. Active a -> Active b -> Active a
$c<* :: forall a b. Active a -> Active b -> Active a
*> :: forall a b. Active a -> Active b -> Active b
$c*> :: forall a b. Active a -> Active b -> Active b
liftA2 :: forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
$cliftA2 :: forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
<*> :: forall a b. Active (a -> b) -> Active a -> Active b
$c<*> :: forall a b. Active (a -> b) -> Active a -> Active b
pure :: forall a. a -> Active a
$cpure :: forall a. a -> Active a
Applicative)
makeWrapped ''Active
active :: Iso' (Active a) (Either (Dynamic a) a)
active :: forall a. Iso' (Active a) (Either (Dynamic a) a)
active = forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso forall (f :: * -> *) a. MaybeApply f a -> Either (f a) a
runMaybeApply forall (f :: * -> *) a. Either (f a) a -> MaybeApply f a
MaybeApply
instance Semigroup a => Semigroup (Active a) where
(forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall a. Iso' (Active a) (Either (Dynamic a) a)
active -> Either (Dynamic a) a
a) <> :: Active a -> Active a -> Active a
<> (forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall a. Iso' (Active a) (Either (Dynamic a) a)
active -> Either (Dynamic a) a
b) = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review forall a. Iso' (Active a) (Either (Dynamic a) a)
active forall a b. (a -> b) -> a -> b
$ forall {a}.
Semigroup a =>
Either (Dynamic a) a
-> Either (Dynamic a) a -> Either (Dynamic a) a
combine Either (Dynamic a) a
a Either (Dynamic a) a
b
where
combine :: Either (Dynamic a) a
-> Either (Dynamic a) a -> Either (Dynamic a) a
combine (Right a
m1) (Right a
m2)
= forall a b. b -> Either a b
Right (a
m1 forall a. Semigroup a => a -> a -> a
<> a
m2)
combine (Left (Dynamic Era Rational
dur Time Rational -> a
f)) (Right a
m)
= forall a b. a -> Either a b
Left (forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
Dynamic Era Rational
dur (Time Rational -> a
f forall a. Semigroup a => a -> a -> a
<> forall a b. a -> b -> a
const a
m))
combine (Right a
m) (Left (Dynamic Era Rational
dur Time Rational -> a
f))
= forall a b. a -> Either a b
Left (forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
Dynamic Era Rational
dur (forall a b. a -> b -> a
const a
m forall a. Semigroup a => a -> a -> a
<> Time Rational -> a
f))
combine (Left Dynamic a
d1) (Left Dynamic a
d2)
= forall a b. a -> Either a b
Left (Dynamic a
d1 forall a. Semigroup a => a -> a -> a
<> Dynamic a
d2)
instance (Monoid a, Semigroup a) => Monoid (Active a) where
mempty :: Active a
mempty = forall a. MaybeApply Dynamic a -> Active a
Active (forall (f :: * -> *) a. Either (f a) a -> MaybeApply f a
MaybeApply (forall a b. b -> Either a b
Right forall a. Monoid a => a
mempty))
mappend :: Active a -> Active a -> Active a
mappend = forall a. Semigroup a => a -> a -> a
(<>)
fromDynamic :: Dynamic a -> Active a
fromDynamic :: forall a. Dynamic a -> Active a
fromDynamic = forall a. MaybeApply Dynamic a -> Active a
Active forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Either (f a) a -> MaybeApply f a
MaybeApply forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left
mkActive :: Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
mkActive :: forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
mkActive Time Rational
s Time Rational
e Time Rational -> a
f = forall a. Dynamic a -> Active a
fromDynamic (forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic Time Rational
s Time Rational
e Time Rational -> a
f)
onActive :: (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive :: forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive a -> b
f Dynamic a -> b
_ (Active (MaybeApply (Right a
a))) = a -> b
f a
a
onActive a -> b
_ Dynamic a -> b
f (Active (MaybeApply (Left Dynamic a
d))) = Dynamic a -> b
f Dynamic a
d
modActive
:: (a -> b)
-> (Dynamic a -> Dynamic b)
-> Active a -> Active b
modActive :: forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive a -> b
f Dynamic a -> Dynamic b
g = forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) (forall a. Dynamic a -> Active a
fromDynamic forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dynamic a -> Dynamic b
g)
runActive :: Active a -> Time Rational -> a
runActive :: forall a. Active a -> Time Rational -> a
runActive = forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive forall a b. a -> b -> a
const forall a. Dynamic a -> Time Rational -> a
runDynamic
activeStart :: Active a -> a
activeStart :: forall a. Active a -> a
activeStart = forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive forall a. a -> a
id (forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
_ Time Rational -> a
d -> Time Rational -> a
d Time Rational
s)
activeEnd :: Active a -> a
activeEnd :: forall a. Active a -> a
activeEnd = forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive forall a. a -> a
id (forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic forall a b. (a -> b) -> a -> b
$ \Time Rational
_ Time Rational
e Time Rational -> a
d -> Time Rational -> a
d Time Rational
e)
activeEra :: Active a -> Maybe (Era Rational)
activeEra :: forall a. Active a -> Maybe (Era Rational)
activeEra = forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive (forall a b. a -> b -> a
const forall a. Maybe a
Nothing) (forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Dynamic a -> Era Rational
era)
isConstant :: Active a -> Bool
isConstant :: forall a. Active a -> Bool
isConstant = forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive (forall a b. a -> b -> a
const Bool
True) (forall a b. a -> b -> a
const Bool
False)
isDynamic :: Active a -> Bool
isDynamic :: forall a. Active a -> Bool
isDynamic = forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive (forall a b. a -> b -> a
const Bool
False) (forall a b. a -> b -> a
const Bool
True)
ui :: Fractional a => Active a
ui :: forall a. Fractional a => Active a
ui = forall a.
Fractional a =>
Time Rational -> Time Rational -> Active a
interval Time Rational
0 Time Rational
1
interval :: Fractional a => Time Rational -> Time Rational -> Active a
interval :: forall a.
Fractional a =>
Time Rational -> Time Rational -> Active a
interval Time Rational
a Time Rational
b = forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
mkActive Time Rational
a Time Rational
b (forall a. Fractional a => Rational -> a
fromRational forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. Time n -> n
unTime)
stretch :: Rational -> Active a -> Active a
stretch :: forall a. Rational -> Active a -> Active a
stretch Rational
str =
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic Time Rational
s (Time Rational
s forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ (Rational
str forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^ (Time Rational
e forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
.-. Time Rational
s)))
(\Time Rational
t -> Time Rational -> a
d (Time Rational
s forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ ((Time Rational
t forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
.-. Time Rational
s) forall (f :: * -> *) a.
(Functor f, Fractional a) =>
f a -> a -> f a
^/ Rational
str)))
stretchTo :: Duration Rational -> Active a -> Active a
stretchTo :: forall a. Duration Rational -> Active a -> Active a
stretchTo Duration Rational
d Active a
a
| Duration Rational
d forall a. Ord a => a -> a -> Bool
<= Duration Rational
0 = Active a
a
| (forall n. Num n => Era n -> Duration n
duration forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Active a -> Maybe (Era Rational)
activeEra Active a
a) forall a. Eq a => a -> a -> Bool
== forall a. a -> Maybe a
Just Duration Rational
0 = Active a
a
| Bool
otherwise = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Active a
a (forall a. Rational -> Active a -> Active a
`stretch` Active a
a) ((forall a. Real a => a -> Rational
toRational forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Duration Rational
d forall a. Fractional a => a -> a -> a
/) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. Num n => Era n -> Duration n
duration) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Active a -> Maybe (Era Rational)
activeEra Active a
a)
during :: Active a -> Active a -> Active a
during :: forall a. Active a -> Active a -> Active a
during Active a
a1 Active a
a2 = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Active a
a1 (\(Duration Rational
d,Time Rational
s) -> forall a. Duration Rational -> Active a -> Active a
stretchTo Duration Rational
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Time Rational -> Active a -> Active a
atTime Time Rational
s forall a b. (a -> b) -> a -> b
$ Active a
a1)
((forall n. Num n => Era n -> Duration n
duration forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& forall n. Era n -> Time n
start) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Active a -> Maybe (Era Rational)
activeEra Active a
a2)
shift :: Duration Rational -> Active a -> Active a
shift :: forall a. Duration Rational -> Active a -> Active a
shift Duration Rational
sh = forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive forall a. a -> a
id (forall a. Duration Rational -> Dynamic a -> Dynamic a
shiftDynamic Duration Rational
sh)
backwards :: Active a -> Active a
backwards :: forall a. Active a -> Active a
backwards =
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic Time Rational
s Time Rational
e
(\Time Rational
t -> Time Rational -> a
d (Time Rational
s forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ (Time Rational
e forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
.-. Time Rational
t)))
snapshot :: Time Rational -> Active a -> Active a
snapshot :: forall a. Time Rational -> Active a -> Active a
snapshot Time Rational
t Active a
a = forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. Active a -> Time Rational -> a
runActive Active a
a Time Rational
t)
clamp :: Active a -> Active a
clamp :: forall a. Active a -> Active a
clamp =
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic Time Rational
s Time Rational
e
(\Time Rational
t -> case () of ()
_ | Time Rational
t forall a. Ord a => a -> a -> Bool
< Time Rational
s -> Time Rational -> a
d Time Rational
s
| Time Rational
t forall a. Ord a => a -> a -> Bool
> Time Rational
e -> Time Rational -> a
d Time Rational
e
| Bool
otherwise -> Time Rational -> a
d Time Rational
t
)
clampBefore :: Active a -> Active a
clampBefore :: forall a. Active a -> Active a
clampBefore = forall a. HasCallStack => a
undefined
clampAfter :: Active a -> Active a
clampAfter :: forall a. Active a -> Active a
clampAfter = forall a. HasCallStack => a
undefined
trim :: Monoid a => Active a -> Active a
trim :: forall a. Monoid a => Active a -> Active a
trim =
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic Time Rational
s Time Rational
e
(\Time Rational
t -> case () of ()
_ | Time Rational
t forall a. Ord a => a -> a -> Bool
< Time Rational
s -> forall a. Monoid a => a
mempty
| Time Rational
t forall a. Ord a => a -> a -> Bool
> Time Rational
e -> forall a. Monoid a => a
mempty
| Bool
otherwise -> Time Rational -> a
d Time Rational
t
)
trimBefore :: Monoid a => Active a -> Active a
trimBefore :: forall a. Monoid a => Active a -> Active a
trimBefore =
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic Time Rational
s Time Rational
e
(\Time Rational
t -> case () of ()
_ | Time Rational
t forall a. Ord a => a -> a -> Bool
< Time Rational
s -> forall a. Monoid a => a
mempty
| Bool
otherwise -> Time Rational -> a
d Time Rational
t
)
trimAfter :: Monoid a => Active a -> Active a
trimAfter :: forall a. Monoid a => Active a -> Active a
trimAfter =
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic Time Rational
s Time Rational
e
(\Time Rational
t -> case () of ()
_ | Time Rational
t forall a. Ord a => a -> a -> Bool
> Time Rational
e -> forall a. Monoid a => a
mempty
| Bool
otherwise -> Time Rational -> a
d Time Rational
t
)
setEra :: Era Rational -> Active a -> Active a
setEra :: forall a. Era Rational -> Active a -> Active a
setEra Era Rational
er =
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive
(forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
mkActive (forall n. Era n -> Time n
start Era Rational
er) (forall n. Era n -> Time n
end Era Rational
er) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const)
(forall a. Dynamic a -> Active a
fromDynamic forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic (\Time Rational
_ Time Rational
_ -> forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic (forall n. Era n -> Time n
start Era Rational
er) (forall n. Era n -> Time n
end Era Rational
er)))
atTime :: Time Rational -> Active a -> Active a
atTime :: forall a. Time Rational -> Active a -> Active a
atTime Time Rational
t Active a
a = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Active a
a (\Era Rational
e -> forall a. Duration Rational -> Active a -> Active a
shift (Time Rational
t forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
.-. forall n. Era n -> Time n
start Era Rational
e) Active a
a) (forall a. Active a -> Maybe (Era Rational)
activeEra Active a
a)
after :: Active a -> Active a -> Active a
after :: forall a. Active a -> Active a -> Active a
after Active a
a1 Active a
a2 = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Active a
a1 ((forall a. Time Rational -> Active a -> Active a
`atTime` Active a
a1) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. Era n -> Time n
end) (forall a. Active a -> Maybe (Era Rational)
activeEra Active a
a2)
infixr 5 ->>
(->>) :: Semigroup a => Active a -> Active a -> Active a
Active a
a1 ->> :: forall a. Semigroup a => Active a -> Active a -> Active a
->> Active a
a2 = Active a
a1 forall a. Semigroup a => a -> a -> a
<> (Active a
a2 forall a. Active a -> Active a -> Active a
`after` Active a
a1)
(|>>) :: Active a -> Active a -> Active a
Active a
a1 |>> :: forall a. Active a -> Active a -> Active a
|>> Active a
a2 = (forall a. HasCallStack => Maybe a -> a
fromJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. First a -> Maybe a
getFirst) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(forall a. Monoid a => Active a -> Active a
trimAfter (forall a. Maybe a -> First a
First forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Active a
a1) forall a. Semigroup a => Active a -> Active a -> Active a
->> forall a. Monoid a => Active a -> Active a
trimBefore (forall a. Maybe a -> First a
First forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Active a
a2))
movie :: [Active a] -> Active a
movie :: forall a. [Active a] -> Active a
movie = forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 forall a. Active a -> Active a -> Active a
(|>>)
discrete :: [a] -> Active a
discrete :: forall a. [a] -> Active a
discrete [] = forall a. HasCallStack => String -> a
error String
"Data.Active.discrete must be called with a non-empty list."
discrete [a]
xs = Rational -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Fractional a => Active a
ui
where f :: Rational -> a
f (Rational
t :: Rational)
| Rational
t forall a. Ord a => a -> a -> Bool
<= Rational
0 = forall a. Vector a -> a
V.unsafeHead Vector a
v
| Rational
t forall a. Ord a => a -> a -> Bool
>= Rational
1 = forall a. Vector a -> a
V.unsafeLast Vector a
v
| Bool
otherwise = forall a. Vector a -> Int -> a
V.unsafeIndex Vector a
v forall a b. (a -> b) -> a -> b
$ forall a b. (RealFrac a, Integral b) => a -> b
floor (Rational
t forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Vector a -> Int
V.length Vector a
v))
v :: Vector a
v = forall a. [a] -> Vector a
V.fromList [a]
xs
simulate :: Rational -> Active a -> [a]
simulate :: forall a. Rational -> Active a -> [a]
simulate Rational
0 = forall a b. a -> b -> a
const []
simulate Rational
rate =
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive (forall a. a -> [a] -> [a]
:[])
(\Dynamic a
d -> forall a b. (a -> b) -> [a] -> [b]
map (forall a. Dynamic a -> Time Rational -> a
runDynamic Dynamic a
d)
(let s :: Time Rational
s = forall n. Era n -> Time n
start (forall a. Dynamic a -> Era Rational
era Dynamic a
d)
e :: Time Rational
e = forall n. Era n -> Time n
end (forall a. Dynamic a -> Era Rational
era Dynamic a
d)
in [Time Rational
s, Time Rational
s forall a. Num a => a -> a -> a
+ Time Rational
1forall (f :: * -> *) a.
(Functor f, Fractional a) =>
f a -> a -> f a
^/Rational
rate .. Time Rational
e]
)
)