{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# 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 { Time n -> n
unTime :: n }
deriving (Time n -> Time n -> Bool
(Time n -> Time n -> Bool)
-> (Time n -> Time n -> Bool) -> Eq (Time n)
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, Eq (Time n)
Eq (Time n)
-> (Time n -> Time n -> Ordering)
-> (Time n -> Time n -> Bool)
-> (Time n -> Time n -> Bool)
-> (Time n -> Time n -> Bool)
-> (Time n -> Time n -> Bool)
-> (Time n -> Time n -> Time n)
-> (Time n -> Time n -> Time n)
-> Ord (Time n)
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
$cp1Ord :: forall n. Ord n => Eq (Time n)
Ord, Int -> Time n -> ShowS
[Time n] -> ShowS
Time n -> String
(Int -> Time n -> ShowS)
-> (Time n -> String) -> ([Time n] -> ShowS) -> Show (Time n)
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)
Int -> ReadS (Time n)
ReadS [Time n]
(Int -> ReadS (Time n))
-> ReadS [Time n]
-> ReadPrec (Time n)
-> ReadPrec [Time n]
-> Read (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]
(Time n -> Time n)
-> (Time n -> Time n)
-> (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 -> [Time n])
-> Enum (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
(Time n -> Time n -> Time n)
-> (Time n -> Time n -> Time n)
-> (Time n -> Time n -> Time n)
-> (Time n -> Time n)
-> (Time n -> Time n)
-> (Time n -> Time n)
-> (Integer -> Time n)
-> Num (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, Num (Time n)
Num (Time n)
-> (Time n -> Time n -> Time n)
-> (Time n -> Time n)
-> (Rational -> Time n)
-> Fractional (Time n)
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
$cp1Fractional :: forall n. Fractional n => Num (Time n)
Fractional, Num (Time n)
Ord (Time n)
Num (Time n)
-> Ord (Time n) -> (Time n -> Rational) -> Real (Time n)
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
$cp2Real :: forall n. Real n => Ord (Time n)
$cp1Real :: forall n. Real n => Num (Time n)
Real, Fractional (Time n)
Real (Time n)
Real (Time n)
-> Fractional (Time n)
-> (forall b. Integral b => Time n -> (b, Time n))
-> (forall b. Integral b => Time n -> b)
-> (forall b. Integral b => Time n -> b)
-> (forall b. Integral b => Time n -> b)
-> (forall b. Integral b => Time n -> b)
-> RealFrac (Time n)
Time n -> b
Time n -> b
Time n -> b
Time n -> b
Time n -> (b, Time n)
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 :: Time n -> b
$cfloor :: forall n b. (RealFrac n, Integral b) => Time n -> b
ceiling :: Time n -> b
$cceiling :: forall n b. (RealFrac n, Integral b) => Time n -> b
round :: Time n -> b
$cround :: forall n b. (RealFrac n, Integral b) => Time n -> b
truncate :: Time n -> b
$ctruncate :: forall n b. (RealFrac n, Integral b) => Time n -> b
properFraction :: Time n -> (b, Time n)
$cproperFraction :: forall n b. (RealFrac n, Integral b) => Time n -> (b, Time n)
$cp2RealFrac :: forall n. RealFrac n => Fractional (Time n)
$cp1RealFrac :: forall n. RealFrac n => Real (Time n)
RealFrac, a -> Time b -> Time a
(a -> b) -> Time a -> Time b
(forall a b. (a -> b) -> Time a -> Time b)
-> (forall a b. a -> Time b -> Time a) -> Functor Time
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
<$ :: a -> Time b -> Time a
$c<$ :: forall a b. a -> Time b -> Time a
fmap :: (a -> b) -> Time a -> Time b
$cfmap :: forall a b. (a -> b) -> Time a -> Time b
Functor)
makeWrapped ''Time
toTime :: n -> Time n
toTime :: n -> Time n
toTime = n -> Time n
forall n. n -> Time n
Time
fromTime :: Time n -> n
fromTime :: Time n -> n
fromTime = Time n -> n
forall n. Time n -> n
unTime
newtype Duration n = Duration n
deriving (Duration n -> Duration n -> Bool
(Duration n -> Duration n -> Bool)
-> (Duration n -> Duration n -> Bool) -> Eq (Duration n)
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, Eq (Duration n)
Eq (Duration n)
-> (Duration n -> Duration n -> Ordering)
-> (Duration n -> Duration n -> Bool)
-> (Duration n -> Duration n -> Bool)
-> (Duration n -> Duration n -> Bool)
-> (Duration n -> Duration n -> Bool)
-> (Duration n -> Duration n -> Duration n)
-> (Duration n -> Duration n -> Duration n)
-> Ord (Duration n)
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
$cp1Ord :: forall n. Ord n => Eq (Duration n)
Ord, Int -> Duration n -> ShowS
[Duration n] -> ShowS
Duration n -> String
(Int -> Duration n -> ShowS)
-> (Duration n -> String)
-> ([Duration n] -> ShowS)
-> Show (Duration n)
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)
Int -> ReadS (Duration n)
ReadS [Duration n]
(Int -> ReadS (Duration n))
-> ReadS [Duration n]
-> ReadPrec (Duration n)
-> ReadPrec [Duration n]
-> Read (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]
(Duration n -> Duration n)
-> (Duration n -> Duration n)
-> (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 -> [Duration n])
-> Enum (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
(Duration n -> Duration n -> Duration n)
-> (Duration n -> Duration n -> Duration n)
-> (Duration n -> Duration n -> Duration n)
-> (Duration n -> Duration n)
-> (Duration n -> Duration n)
-> (Duration n -> Duration n)
-> (Integer -> Duration n)
-> Num (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, Num (Duration n)
Num (Duration n)
-> (Duration n -> Duration n -> Duration n)
-> (Duration n -> Duration n)
-> (Rational -> Duration n)
-> Fractional (Duration n)
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
$cp1Fractional :: forall n. Fractional n => Num (Duration n)
Fractional, Num (Duration n)
Ord (Duration n)
Num (Duration n)
-> Ord (Duration n)
-> (Duration n -> Rational)
-> Real (Duration n)
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
$cp2Real :: forall n. Real n => Ord (Duration n)
$cp1Real :: forall n. Real n => Num (Duration n)
Real, Fractional (Duration n)
Real (Duration n)
Real (Duration n)
-> Fractional (Duration n)
-> (forall b. Integral b => Duration n -> (b, Duration n))
-> (forall b. Integral b => Duration n -> b)
-> (forall b. Integral b => Duration n -> b)
-> (forall b. Integral b => Duration n -> b)
-> (forall b. Integral b => Duration n -> b)
-> RealFrac (Duration n)
Duration n -> b
Duration n -> b
Duration n -> b
Duration n -> b
Duration n -> (b, Duration n)
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 :: Duration n -> b
$cfloor :: forall n b. (RealFrac n, Integral b) => Duration n -> b
ceiling :: Duration n -> b
$cceiling :: forall n b. (RealFrac n, Integral b) => Duration n -> b
round :: Duration n -> b
$cround :: forall n b. (RealFrac n, Integral b) => Duration n -> b
truncate :: Duration n -> b
$ctruncate :: forall n b. (RealFrac n, Integral b) => Duration n -> b
properFraction :: Duration n -> (b, Duration n)
$cproperFraction :: forall n b.
(RealFrac n, Integral b) =>
Duration n -> (b, Duration n)
$cp2RealFrac :: forall n. RealFrac n => Fractional (Duration n)
$cp1RealFrac :: forall n. RealFrac n => Real (Duration n)
RealFrac, a -> Duration b -> Duration a
(a -> b) -> Duration a -> Duration b
(forall a b. (a -> b) -> Duration a -> Duration b)
-> (forall a b. a -> Duration b -> Duration a) -> Functor Duration
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
<$ :: a -> Duration b -> Duration a
$c<$ :: forall a b. a -> Duration b -> Duration a
fmap :: (a -> b) -> Duration a -> Duration b
$cfmap :: forall a b. (a -> b) -> Duration a -> Duration b
Functor)
toDuration :: n -> Duration n
toDuration :: n -> Duration n
toDuration = n -> Duration n
forall n. n -> Duration n
Duration
fromDuration :: Duration n -> n
fromDuration :: Duration n -> n
fromDuration (Duration n
n) = n
n
instance Applicative Duration where
pure :: a -> Duration a
pure = a -> Duration a
forall n. n -> Duration n
Duration
Duration a -> b
f <*> :: Duration (a -> b) -> Duration a -> Duration b
<*> Duration a
x = b -> Duration b
forall n. n -> Duration n
Duration (a -> b
f a
x)
instance Additive Duration where
zero :: Duration a
zero = Duration a
0
instance Num n => Semigroup (Duration n) where
<> :: Duration n -> Duration n -> Duration n
(<>) = 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 = Duration n -> Duration n -> Duration n
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) .-. :: Time a -> Time a -> Diff Time a
.-. (Time a
t2) = a -> Duration a
forall n. n -> Duration n
Duration (a
t1 a -> a -> a
forall a. Num a => a -> a -> a
- a
t2)
(Time a
t) .+^ :: Time a -> Diff Time a -> Time a
.+^ (Duration d) = a -> Time a
forall n. n -> Time n
Time (a
t a -> a -> a
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
[Era n] -> ShowS
Era n -> String
(Int -> Era n -> ShowS)
-> (Era n -> String) -> ([Era n] -> ShowS) -> Show (Era n)
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, b -> Era n -> Era n
NonEmpty (Era n) -> Era n
Era n -> Era n -> Era n
(Era n -> Era n -> Era n)
-> (NonEmpty (Era n) -> Era n)
-> (forall b. Integral b => b -> Era n -> Era n)
-> Semigroup (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 :: 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 :: Time n -> Time n -> Era n
mkEra Time n
s Time n
e = (Min (Time n), Max (Time n)) -> Era n
forall n. (Min (Time n), Max (Time n)) -> Era n
Era (Time n -> Min (Time n)
forall a. a -> Min a
Min Time n
s, Time n -> Max (Time n)
forall a. a -> Max a
Max Time n
e)
start :: Era n -> Time n
start :: Era n -> Time n
start (Era (Min Time n
t, Max (Time n)
_)) = Time n
t
end :: Era n -> Time n
end :: Era n -> Time n
end (Era (Min (Time n)
_, Max Time n
t)) = Time n
t
duration :: Num n => Era n -> Duration n
duration :: Era n -> Duration n
duration = Time n -> Time n -> Duration n
forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
(.-.) (Time n -> Time n -> Duration n)
-> (Era n -> Time n) -> Era n -> Time n -> Duration n
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Era n -> Time n
forall n. Era n -> Time n
end (Era n -> Time n -> Duration n)
-> (Era n -> Time n) -> Era n -> Duration n
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Era n -> Time n
forall n. Era n -> Time n
start
data Dynamic a = Dynamic { Dynamic a -> Era Rational
era :: Era Rational
, Dynamic a -> Time Rational -> a
runDynamic :: Time Rational -> a
}
deriving a -> Dynamic b -> Dynamic a
(a -> b) -> Dynamic a -> Dynamic b
(forall a b. (a -> b) -> Dynamic a -> Dynamic b)
-> (forall a b. a -> Dynamic b -> Dynamic a) -> Functor Dynamic
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
<$ :: a -> Dynamic b -> Dynamic a
$c<$ :: forall a b. a -> Dynamic b -> Dynamic a
fmap :: (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) <.> :: Dynamic (a -> b) -> Dynamic a -> Dynamic b
<.> (Dynamic Era Rational
d2 Time Rational -> a
f2) = Era Rational -> (Time Rational -> b) -> Dynamic b
forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
Dynamic (Era Rational
d1 Era Rational -> Era Rational -> Era Rational
forall a. Semigroup a => a -> a -> a
<> Era Rational
d2) (Time Rational -> a -> b
f1 (Time Rational -> a -> b)
-> (Time Rational -> a) -> Time Rational -> b
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 = Era Rational -> (Time Rational -> a) -> Dynamic a
forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
Dynamic (Era Rational
d1 Era Rational -> Era Rational -> Era Rational
forall a. Semigroup a => a -> a -> a
<> Era Rational
d2) (Time Rational -> a
f1 (Time Rational -> a) -> (Time Rational -> a) -> Time Rational -> a
forall a. Semigroup a => a -> a -> a
<> Time Rational -> a
f2)
mkDynamic :: Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic :: Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic Time Rational
s Time Rational
e = Era Rational -> (Time Rational -> a) -> Dynamic a
forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
Dynamic (Time Rational -> Time Rational -> Era Rational
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 :: (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 (Era Rational -> Time Rational
forall n. Era n -> Time n
start Era Rational
e) (Era Rational -> Time Rational
forall n. Era n -> Time n
end Era Rational
e) Time Rational -> a
d
shiftDynamic :: Duration Rational -> Dynamic a -> Dynamic a
shiftDynamic :: Duration Rational -> Dynamic a -> Dynamic a
shiftDynamic Duration Rational
sh =
(Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a
-> Dynamic a
forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic
(Time Rational
s Time Rational -> Diff Time Rational -> Time Rational
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ Diff Time Rational
Duration Rational
sh)
(Time Rational
e Time Rational -> Diff Time Rational -> Time Rational
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ Diff Time Rational
Duration Rational
sh)
(\Time Rational
t -> Time Rational -> a
d (Time Rational
t Time Rational -> Diff Time Rational -> Time Rational
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.-^ Diff Time Rational
Duration Rational
sh))
newtype Active a = Active (MaybeApply Dynamic a)
deriving (a -> Active b -> Active a
(a -> b) -> Active a -> Active b
(forall a b. (a -> b) -> Active a -> Active b)
-> (forall a b. a -> Active b -> Active a) -> Functor Active
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
<$ :: a -> Active b -> Active a
$c<$ :: forall a b. a -> Active b -> Active a
fmap :: (a -> b) -> Active a -> Active b
$cfmap :: forall a b. (a -> b) -> Active a -> Active b
Functor, Functor Active
Functor Active
-> (forall a b. Active (a -> b) -> Active a -> Active b)
-> (forall a b. Active a -> Active b -> Active b)
-> (forall a b. Active a -> Active b -> Active a)
-> (forall a b c.
(a -> b -> c) -> Active a -> Active b -> Active c)
-> Apply Active
Active a -> Active b -> Active b
Active a -> Active b -> Active a
Active (a -> b) -> Active a -> Active b
(a -> b -> c) -> Active a -> Active b -> Active c
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 :: (a -> b -> c) -> Active a -> Active b -> Active c
$cliftF2 :: forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
<. :: Active a -> Active b -> Active a
$c<. :: forall a b. Active a -> Active b -> Active a
.> :: Active a -> Active b -> Active b
$c.> :: forall a b. Active a -> Active b -> Active b
<.> :: Active (a -> b) -> Active a -> Active b
$c<.> :: forall a b. Active (a -> b) -> Active a -> Active b
$cp1Apply :: Functor Active
Apply, Functor Active
a -> Active a
Functor Active
-> (forall a. a -> Active a)
-> (forall a b. Active (a -> b) -> Active a -> Active b)
-> (forall a b c.
(a -> b -> c) -> Active a -> Active b -> Active c)
-> (forall a b. Active a -> Active b -> Active b)
-> (forall a b. Active a -> Active b -> Active a)
-> Applicative Active
Active a -> Active b -> Active b
Active a -> Active b -> Active a
Active (a -> b) -> Active a -> Active b
(a -> b -> c) -> Active a -> Active b -> Active c
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
<* :: Active a -> Active b -> Active a
$c<* :: forall a b. Active a -> Active b -> Active a
*> :: Active a -> Active b -> Active b
$c*> :: forall a b. Active a -> Active b -> Active b
liftA2 :: (a -> b -> c) -> Active a -> Active b -> Active c
$cliftA2 :: forall a b c. (a -> b -> c) -> Active a -> Active b -> Active c
<*> :: Active (a -> b) -> Active a -> Active b
$c<*> :: forall a b. Active (a -> b) -> Active a -> Active b
pure :: a -> Active a
$cpure :: forall a. a -> Active a
$cp1Applicative :: Functor Active
Applicative)
makeWrapped ''Active
active :: Iso' (Active a) (Either (Dynamic a) a)
active :: p (Either (Dynamic a) a) (f (Either (Dynamic a) a))
-> p (Active a) (f (Active a))
active = p (MaybeApply Dynamic a) (f (MaybeApply Dynamic a))
-> p (Active a) (f (Active a))
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (p (MaybeApply Dynamic a) (f (MaybeApply Dynamic a))
-> p (Active a) (f (Active a)))
-> (p (Either (Dynamic a) a) (f (Either (Dynamic a) a))
-> p (MaybeApply Dynamic a) (f (MaybeApply Dynamic a)))
-> p (Either (Dynamic a) a) (f (Either (Dynamic a) a))
-> p (Active a) (f (Active a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MaybeApply Dynamic a -> Either (Dynamic a) a)
-> (Either (Dynamic a) a -> MaybeApply Dynamic a)
-> Iso
(MaybeApply Dynamic a)
(MaybeApply Dynamic a)
(Either (Dynamic a) a)
(Either (Dynamic a) a)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso MaybeApply Dynamic a -> Either (Dynamic a) a
forall (f :: * -> *) a. MaybeApply f a -> Either (f a) a
runMaybeApply Either (Dynamic a) a -> MaybeApply Dynamic a
forall (f :: * -> *) a. Either (f a) a -> MaybeApply f a
MaybeApply
instance Semigroup a => Semigroup (Active a) where
(Getting (Either (Dynamic a) a) (Active a) (Either (Dynamic a) a)
-> Active a -> Either (Dynamic a) a
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Either (Dynamic a) a) (Active a) (Either (Dynamic a) a)
forall a. Iso' (Active a) (Either (Dynamic a) a)
active -> Either (Dynamic a) a
a) <> :: Active a -> Active a -> Active a
<> (Getting (Either (Dynamic a) a) (Active a) (Either (Dynamic a) a)
-> Active a -> Either (Dynamic a) a
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Either (Dynamic a) a) (Active a) (Either (Dynamic a) a)
forall a. Iso' (Active a) (Either (Dynamic a) a)
active -> Either (Dynamic a) a
b) = AReview (Active a) (Either (Dynamic a) a)
-> Either (Dynamic a) a -> Active a
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview (Active a) (Either (Dynamic a) a)
forall a. Iso' (Active a) (Either (Dynamic a) a)
active (Either (Dynamic a) a -> Active a)
-> Either (Dynamic a) a -> Active a
forall a b. (a -> b) -> a -> b
$ Either (Dynamic a) a
-> Either (Dynamic a) a -> Either (Dynamic a) a
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)
= a -> Either (Dynamic a) a
forall a b. b -> Either a b
Right (a
m1 a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
m2)
combine (Left (Dynamic Era Rational
dur Time Rational -> a
f)) (Right a
m)
= Dynamic a -> Either (Dynamic a) a
forall a b. a -> Either a b
Left (Era Rational -> (Time Rational -> a) -> Dynamic a
forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
Dynamic Era Rational
dur (Time Rational -> a
f (Time Rational -> a) -> (Time Rational -> a) -> Time Rational -> a
forall a. Semigroup a => a -> a -> a
<> a -> Time Rational -> a
forall a b. a -> b -> a
const a
m))
combine (Right a
m) (Left (Dynamic Era Rational
dur Time Rational -> a
f))
= Dynamic a -> Either (Dynamic a) a
forall a b. a -> Either a b
Left (Era Rational -> (Time Rational -> a) -> Dynamic a
forall a. Era Rational -> (Time Rational -> a) -> Dynamic a
Dynamic Era Rational
dur (a -> Time Rational -> a
forall a b. a -> b -> a
const a
m (Time Rational -> a) -> (Time Rational -> a) -> Time Rational -> a
forall a. Semigroup a => a -> a -> a
<> Time Rational -> a
f))
combine (Left Dynamic a
d1) (Left Dynamic a
d2)
= Dynamic a -> Either (Dynamic a) a
forall a b. a -> Either a b
Left (Dynamic a
d1 Dynamic a -> Dynamic a -> Dynamic a
forall a. Semigroup a => a -> a -> a
<> Dynamic a
d2)
instance (Monoid a, Semigroup a) => Monoid (Active a) where
mempty :: Active a
mempty = MaybeApply Dynamic a -> Active a
forall a. MaybeApply Dynamic a -> Active a
Active (Either (Dynamic a) a -> MaybeApply Dynamic a
forall (f :: * -> *) a. Either (f a) a -> MaybeApply f a
MaybeApply (a -> Either (Dynamic a) a
forall a b. b -> Either a b
Right a
forall a. Monoid a => a
mempty))
mappend :: Active a -> Active a -> Active a
mappend = Active a -> Active a -> Active a
forall a. Semigroup a => a -> a -> a
(<>)
fromDynamic :: Dynamic a -> Active a
fromDynamic :: Dynamic a -> Active a
fromDynamic = MaybeApply Dynamic a -> Active a
forall a. MaybeApply Dynamic a -> Active a
Active (MaybeApply Dynamic a -> Active a)
-> (Dynamic a -> MaybeApply Dynamic a) -> Dynamic a -> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either (Dynamic a) a -> MaybeApply Dynamic a
forall (f :: * -> *) a. Either (f a) a -> MaybeApply f a
MaybeApply (Either (Dynamic a) a -> MaybeApply Dynamic a)
-> (Dynamic a -> Either (Dynamic a) a)
-> Dynamic a
-> MaybeApply Dynamic a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dynamic a -> Either (Dynamic a) a
forall a b. a -> Either a b
Left
mkActive :: Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
mkActive :: Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
mkActive Time Rational
s Time Rational
e Time Rational -> a
f = Dynamic a -> Active a
forall a. Dynamic a -> Active a
fromDynamic (Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
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 :: (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 :: (a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive a -> b
f Dynamic a -> Dynamic b
g = (a -> Active b) -> (Dynamic a -> Active b) -> Active a -> Active b
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive (b -> Active b
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> Active b) -> (a -> b) -> a -> Active b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) (Dynamic b -> Active b
forall a. Dynamic a -> Active a
fromDynamic (Dynamic b -> Active b)
-> (Dynamic a -> Dynamic b) -> Dynamic a -> Active b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dynamic a -> Dynamic b
g)
runActive :: Active a -> Time Rational -> a
runActive :: Active a -> Time Rational -> a
runActive = (a -> Time Rational -> a)
-> (Dynamic a -> Time Rational -> a)
-> Active a
-> Time Rational
-> a
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive a -> Time Rational -> a
forall a b. a -> b -> a
const Dynamic a -> Time Rational -> a
forall a. Dynamic a -> Time Rational -> a
runDynamic
activeStart :: Active a -> a
activeStart :: Active a -> a
activeStart = (a -> a) -> (Dynamic a -> a) -> Active a -> a
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive a -> a
forall a. a -> a
id ((Time Rational -> Time Rational -> (Time Rational -> a) -> a)
-> Dynamic a -> a
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic ((Time Rational -> Time Rational -> (Time Rational -> a) -> a)
-> Dynamic a -> a)
-> (Time Rational -> Time Rational -> (Time Rational -> a) -> a)
-> Dynamic a
-> a
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 :: Active a -> a
activeEnd = (a -> a) -> (Dynamic a -> a) -> Active a -> a
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive a -> a
forall a. a -> a
id ((Time Rational -> Time Rational -> (Time Rational -> a) -> a)
-> Dynamic a -> a
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic ((Time Rational -> Time Rational -> (Time Rational -> a) -> a)
-> Dynamic a -> a)
-> (Time Rational -> Time Rational -> (Time Rational -> a) -> a)
-> Dynamic a
-> a
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 :: Active a -> Maybe (Era Rational)
activeEra = (a -> Maybe (Era Rational))
-> (Dynamic a -> Maybe (Era Rational))
-> Active a
-> Maybe (Era Rational)
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive (Maybe (Era Rational) -> a -> Maybe (Era Rational)
forall a b. a -> b -> a
const Maybe (Era Rational)
forall a. Maybe a
Nothing) (Era Rational -> Maybe (Era Rational)
forall a. a -> Maybe a
Just (Era Rational -> Maybe (Era Rational))
-> (Dynamic a -> Era Rational) -> Dynamic a -> Maybe (Era Rational)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dynamic a -> Era Rational
forall a. Dynamic a -> Era Rational
era)
isConstant :: Active a -> Bool
isConstant :: Active a -> Bool
isConstant = (a -> Bool) -> (Dynamic a -> Bool) -> Active a -> Bool
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive (Bool -> a -> Bool
forall a b. a -> b -> a
const Bool
True) (Bool -> Dynamic a -> Bool
forall a b. a -> b -> a
const Bool
False)
isDynamic :: Active a -> Bool
isDynamic :: Active a -> Bool
isDynamic = (a -> Bool) -> (Dynamic a -> Bool) -> Active a -> Bool
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive (Bool -> a -> Bool
forall a b. a -> b -> a
const Bool
False) (Bool -> Dynamic a -> Bool
forall a b. a -> b -> a
const Bool
True)
ui :: Fractional a => Active a
ui :: Active a
ui = Time Rational -> Time Rational -> Active a
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 :: Time Rational -> Time Rational -> Active a
interval Time Rational
a Time Rational
b = Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
mkActive Time Rational
a Time Rational
b (Rational -> a
forall a. Fractional a => Rational -> a
fromRational (Rational -> a)
-> (Time Rational -> Rational) -> Time Rational -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Time Rational -> Rational
forall n. Time n -> n
unTime)
stretch :: Rational -> Active a -> Active a
stretch :: Rational -> Active a -> Active a
stretch Rational
str =
(a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive a -> a
forall a. a -> a
id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
-> ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a -> Active a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic Time Rational
s (Time Rational
s Time Rational -> Diff Time Rational -> Time Rational
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ (Rational
str Rational -> Duration Rational -> Duration Rational
forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^ (Time Rational
e Time Rational -> Time Rational -> Diff Time Rational
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 Time Rational -> Diff Time Rational -> Time Rational
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ ((Time Rational
t Time Rational -> Time Rational -> Diff Time Rational
forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
.-. Time Rational
s) Duration Rational -> Rational -> Duration Rational
forall (f :: * -> *) a.
(Functor f, Fractional a) =>
f a -> a -> f a
^/ Rational
str)))
stretchTo :: Duration Rational -> Active a -> Active a
stretchTo :: Duration Rational -> Active a -> Active a
stretchTo Duration Rational
d Active a
a
| Duration Rational
d Duration Rational -> Duration Rational -> Bool
forall a. Ord a => a -> a -> Bool
<= Duration Rational
0 = Active a
a
| (Era Rational -> Duration Rational
forall n. Num n => Era n -> Duration n
duration (Era Rational -> Duration Rational)
-> Maybe (Era Rational) -> Maybe (Duration Rational)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Active a -> Maybe (Era Rational)
forall a. Active a -> Maybe (Era Rational)
activeEra Active a
a) Maybe (Duration Rational) -> Maybe (Duration Rational) -> Bool
forall a. Eq a => a -> a -> Bool
== Duration Rational -> Maybe (Duration Rational)
forall a. a -> Maybe a
Just Duration Rational
0 = Active a
a
| Bool
otherwise = Active a -> (Rational -> Active a) -> Maybe Rational -> Active a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Active a
a (Rational -> Active a -> Active a
forall a. Rational -> Active a -> Active a
`stretch` Active a
a) ((Duration Rational -> Rational
forall a. Real a => a -> Rational
toRational (Duration Rational -> Rational)
-> (Era Rational -> Duration Rational) -> Era Rational -> Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Duration Rational
d Duration Rational -> Duration Rational -> Duration Rational
forall a. Fractional a => a -> a -> a
/) (Duration Rational -> Duration Rational)
-> (Era Rational -> Duration Rational)
-> Era Rational
-> Duration Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Era Rational -> Duration Rational
forall n. Num n => Era n -> Duration n
duration) (Era Rational -> Rational)
-> Maybe (Era Rational) -> Maybe Rational
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Active a -> Maybe (Era Rational)
forall a. Active a -> Maybe (Era Rational)
activeEra Active a
a)
during :: Active a -> Active a -> Active a
during :: Active a -> Active a -> Active a
during Active a
a1 Active a
a2 = Active a
-> ((Duration Rational, Time Rational) -> Active a)
-> Maybe (Duration Rational, Time Rational)
-> Active a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Active a
a1 (\(Duration Rational
d,Time Rational
s) -> Duration Rational -> Active a -> Active a
forall a. Duration Rational -> Active a -> Active a
stretchTo Duration Rational
d (Active a -> Active a)
-> (Active a -> Active a) -> Active a -> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Time Rational -> Active a -> Active a
forall a. Time Rational -> Active a -> Active a
atTime Time Rational
s (Active a -> Active a) -> Active a -> Active a
forall a b. (a -> b) -> a -> b
$ Active a
a1)
((Era Rational -> Duration Rational
forall n. Num n => Era n -> Duration n
duration (Era Rational -> Duration Rational)
-> (Era Rational -> Time Rational)
-> Era Rational
-> (Duration Rational, Time Rational)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& Era Rational -> Time Rational
forall n. Era n -> Time n
start) (Era Rational -> (Duration Rational, Time Rational))
-> Maybe (Era Rational) -> Maybe (Duration Rational, Time Rational)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Active a -> Maybe (Era Rational)
forall a. Active a -> Maybe (Era Rational)
activeEra Active a
a2)
shift :: Duration Rational -> Active a -> Active a
shift :: Duration Rational -> Active a -> Active a
shift Duration Rational
sh = (a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive a -> a
forall a. a -> a
id (Duration Rational -> Dynamic a -> Dynamic a
forall a. Duration Rational -> Dynamic a -> Dynamic a
shiftDynamic Duration Rational
sh)
backwards :: Active a -> Active a
backwards :: Active a -> Active a
backwards =
(a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive a -> a
forall a. a -> a
id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
-> ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a -> Active a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
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 Time Rational -> Diff Time Rational -> Time Rational
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ (Time Rational
e Time Rational -> Time Rational -> Diff Time Rational
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 :: Time Rational -> Active a -> Active a
snapshot Time Rational
t Active a
a = a -> Active a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Active a -> Time Rational -> a
forall a. Active a -> Time Rational -> a
runActive Active a
a Time Rational
t)
clamp :: Active a -> Active a
clamp :: Active a -> Active a
clamp =
(a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive a -> a
forall a. a -> a
id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
-> ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a -> Active a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
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 Time Rational -> Time Rational -> Bool
forall a. Ord a => a -> a -> Bool
< Time Rational
s -> Time Rational -> a
d Time Rational
s
| Time Rational
t Time Rational -> Time Rational -> Bool
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 :: Active a -> Active a
clampBefore = Active a -> Active a
forall a. HasCallStack => a
undefined
clampAfter :: Active a -> Active a
clampAfter :: Active a -> Active a
clampAfter = Active a -> Active a
forall a. HasCallStack => a
undefined
trim :: Monoid a => Active a -> Active a
trim :: Active a -> Active a
trim =
(a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive a -> a
forall a. a -> a
id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
-> ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a -> Active a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
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 Time Rational -> Time Rational -> Bool
forall a. Ord a => a -> a -> Bool
< Time Rational
s -> a
forall a. Monoid a => a
mempty
| Time Rational
t Time Rational -> Time Rational -> Bool
forall a. Ord a => a -> a -> Bool
> Time Rational
e -> a
forall a. Monoid a => a
mempty
| Bool
otherwise -> Time Rational -> a
d Time Rational
t
)
trimBefore :: Monoid a => Active a -> Active a
trimBefore :: Active a -> Active a
trimBefore =
(a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive a -> a
forall a. a -> a
id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
-> ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a -> Active a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
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 Time Rational -> Time Rational -> Bool
forall a. Ord a => a -> a -> Bool
< Time Rational
s -> a
forall a. Monoid a => a
mempty
| Bool
otherwise -> Time Rational -> a
d Time Rational
t
)
trimAfter :: Monoid a => Active a -> Active a
trimAfter :: Active a -> Active a
trimAfter =
(a -> a) -> (Dynamic a -> Dynamic a) -> Active a -> Active a
forall a b.
(a -> b) -> (Dynamic a -> Dynamic b) -> Active a -> Active b
modActive a -> a
forall a. a -> a
id ((Dynamic a -> Dynamic a) -> Active a -> Active a)
-> ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic ((Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a -> Active a)
-> (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Active a
-> Active a
forall a b. (a -> b) -> a -> b
$ \Time Rational
s Time Rational
e Time Rational -> a
d ->
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
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 Time Rational -> Time Rational -> Bool
forall a. Ord a => a -> a -> Bool
> Time Rational
e -> a
forall a. Monoid a => a
mempty
| Bool
otherwise -> Time Rational -> a
d Time Rational
t
)
setEra :: Era Rational -> Active a -> Active a
setEra :: Era Rational -> Active a -> Active a
setEra Era Rational
er =
(a -> Active a) -> (Dynamic a -> Active a) -> Active a -> Active a
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive
(Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Active a
mkActive (Era Rational -> Time Rational
forall n. Era n -> Time n
start Era Rational
er) (Era Rational -> Time Rational
forall n. Era n -> Time n
end Era Rational
er) ((Time Rational -> a) -> Active a)
-> (a -> Time Rational -> a) -> a -> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Time Rational -> a
forall a b. a -> b -> a
const)
(Dynamic a -> Active a
forall a. Dynamic a -> Active a
fromDynamic (Dynamic a -> Active a)
-> (Dynamic a -> Dynamic a) -> Dynamic a -> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Time Rational
-> Time Rational -> (Time Rational -> a) -> Dynamic a)
-> Dynamic a -> Dynamic a
forall a b.
(Time Rational -> Time Rational -> (Time Rational -> a) -> b)
-> Dynamic a -> b
onDynamic (\Time Rational
_ Time Rational
_ -> Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
forall a.
Time Rational -> Time Rational -> (Time Rational -> a) -> Dynamic a
mkDynamic (Era Rational -> Time Rational
forall n. Era n -> Time n
start Era Rational
er) (Era Rational -> Time Rational
forall n. Era n -> Time n
end Era Rational
er)))
atTime :: Time Rational -> Active a -> Active a
atTime :: Time Rational -> Active a -> Active a
atTime Time Rational
t Active a
a = Active a
-> (Era Rational -> Active a) -> Maybe (Era Rational) -> Active a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Active a
a (\Era Rational
e -> Duration Rational -> Active a -> Active a
forall a. Duration Rational -> Active a -> Active a
shift (Time Rational
t Time Rational -> Time Rational -> Diff Time Rational
forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
.-. Era Rational -> Time Rational
forall n. Era n -> Time n
start Era Rational
e) Active a
a) (Active a -> Maybe (Era Rational)
forall a. Active a -> Maybe (Era Rational)
activeEra Active a
a)
after :: Active a -> Active a -> Active a
after :: Active a -> Active a -> Active a
after Active a
a1 Active a
a2 = Active a
-> (Era Rational -> Active a) -> Maybe (Era Rational) -> Active a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Active a
a1 ((Time Rational -> Active a -> Active a
forall a. Time Rational -> Active a -> Active a
`atTime` Active a
a1) (Time Rational -> Active a)
-> (Era Rational -> Time Rational) -> Era Rational -> Active a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Era Rational -> Time Rational
forall n. Era n -> Time n
end) (Active a -> Maybe (Era Rational)
forall a. Active a -> Maybe (Era Rational)
activeEra Active a
a2)
infixr 5 ->>
(->>) :: Semigroup a => Active a -> Active a -> Active a
Active a
a1 ->> :: Active a -> Active a -> Active a
->> Active a
a2 = Active a
a1 Active a -> Active a -> Active a
forall a. Semigroup a => a -> a -> a
<> (Active a
a2 Active a -> Active a -> Active a
forall a. Active a -> Active a -> Active a
`after` Active a
a1)
(|>>) :: Active a -> Active a -> Active a
Active a
a1 |>> :: Active a -> Active a -> Active a
|>> Active a
a2 = (Maybe a -> a
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe a -> a) -> (First a -> Maybe a) -> First a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. First a -> Maybe a
forall a. First a -> Maybe a
getFirst) (First a -> a) -> Active (First a) -> Active a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Active (First a) -> Active (First a)
forall a. Monoid a => Active a -> Active a
trimAfter (Maybe a -> First a
forall a. Maybe a -> First a
First (Maybe a -> First a) -> (a -> Maybe a) -> a -> First a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe a
forall a. a -> Maybe a
Just (a -> First a) -> Active a -> Active (First a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Active a
a1) Active (First a) -> Active (First a) -> Active (First a)
forall a. Semigroup a => Active a -> Active a -> Active a
->> Active (First a) -> Active (First a)
forall a. Monoid a => Active a -> Active a
trimBefore (Maybe a -> First a
forall a. Maybe a -> First a
First (Maybe a -> First a) -> (a -> Maybe a) -> a -> First a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe a
forall a. a -> Maybe a
Just (a -> First a) -> Active a -> Active (First a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Active a
a2))
movie :: [Active a] -> Active a
movie :: [Active a] -> Active a
movie = (Active a -> Active a -> Active a) -> [Active a] -> Active a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 Active a -> Active a -> Active a
forall a. Active a -> Active a -> Active a
(|>>)
discrete :: [a] -> Active a
discrete :: [a] -> Active a
discrete [] = String -> Active a
forall a. HasCallStack => String -> a
error String
"Data.Active.discrete must be called with a non-empty list."
discrete [a]
xs = Rational -> a
f (Rational -> a) -> Active Rational -> Active a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Active Rational
forall a. Fractional a => Active a
ui
where f :: Rational -> a
f (Rational
t :: Rational)
| Rational
t Rational -> Rational -> Bool
forall a. Ord a => a -> a -> Bool
<= Rational
0 = Vector a -> a
forall a. Vector a -> a
V.unsafeHead Vector a
v
| Rational
t Rational -> Rational -> Bool
forall a. Ord a => a -> a -> Bool
>= Rational
1 = Vector a -> a
forall a. Vector a -> a
V.unsafeLast Vector a
v
| Bool
otherwise = Vector a -> Int -> a
forall a. Vector a -> Int -> a
V.unsafeIndex Vector a
v (Int -> a) -> Int -> a
forall a b. (a -> b) -> a -> b
$ Rational -> Int
forall a b. (RealFrac a, Integral b) => a -> b
floor (Rational
t Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
* Int -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector a -> Int
forall a. Vector a -> Int
V.length Vector a
v))
v :: Vector a
v = [a] -> Vector a
forall a. [a] -> Vector a
V.fromList [a]
xs
simulate :: Rational -> Active a -> [a]
simulate :: Rational -> Active a -> [a]
simulate Rational
0 = [a] -> Active a -> [a]
forall a b. a -> b -> a
const []
simulate Rational
rate =
(a -> [a]) -> (Dynamic a -> [a]) -> Active a -> [a]
forall a b. (a -> b) -> (Dynamic a -> b) -> Active a -> b
onActive (a -> [a] -> [a]
forall a. a -> [a] -> [a]
:[])
(\Dynamic a
d -> (Time Rational -> a) -> [Time Rational] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (Dynamic a -> Time Rational -> a
forall a. Dynamic a -> Time Rational -> a
runDynamic Dynamic a
d)
(let s :: Time Rational
s = Era Rational -> Time Rational
forall n. Era n -> Time n
start (Dynamic a -> Era Rational
forall a. Dynamic a -> Era Rational
era Dynamic a
d)
e :: Time Rational
e = Era Rational -> Time Rational
forall n. Era n -> Time n
end (Dynamic a -> Era Rational
forall a. Dynamic a -> Era Rational
era Dynamic a
d)
in [Time Rational
s, Time Rational
s Time Rational -> Time Rational -> Time Rational
forall a. Num a => a -> a -> a
+ Time Rational
1Time Rational -> Rational -> Time Rational
forall (f :: * -> *) a.
(Functor f, Fractional a) =>
f a -> a -> f a
^/Rational
rate .. Time Rational
e]
)
)