module Music.Theory.Time.Seq where
import Data.Bifunctor
import Data.Function
import Data.List
import Data.Maybe
import Data.Ratio
import Safe
import qualified Data.List.Ordered as O
import qualified Data.Map as Map
import qualified Music.Theory.List as T
import qualified Music.Theory.Math as T
import qualified Music.Theory.Ord as T
import qualified Music.Theory.Tuple as T
type Useq t a = (t,[a])
type Dseq t a = [(t,a)]
type Iseq t a = [(t,a)]
type Pseq t a = [((t,t,t),a)]
type Tseq t a = [(t,a)]
type Wseq t a = [((t,t),a)]
type Eseq t a = [((t,t,t),a)]
pseq_zip :: [t] -> [t] -> [t] -> [a] -> Pseq t a
pseq_zip :: forall t a. [t] -> [t] -> [t] -> [a] -> Pseq t a
pseq_zip [t]
l [t]
o [t]
f = forall a b. [a] -> [b] -> [(a, b)]
zip (forall a b c. [a] -> [b] -> [c] -> [(a, b, c)]
zip3 [t]
l [t]
o [t]
f)
wseq_zip :: [t] -> [t] -> [a] -> Wseq t a
wseq_zip :: forall t a. [t] -> [t] -> [a] -> Wseq t a
wseq_zip [t]
t [t]
d = forall a b. [a] -> [b] -> [(a, b)]
zip (forall a b. [a] -> [b] -> [(a, b)]
zip [t]
t [t]
d)
seq_tspan :: Num n => (t -> n) -> (t -> n) -> [(t,a)] -> (n,n)
seq_tspan :: forall n t a. Num n => (t -> n) -> (t -> n) -> [(t, a)] -> (n, n)
seq_tspan t -> n
st t -> n
et [(t, a)]
sq =
(forall b a. b -> (a -> b) -> Maybe a -> b
maybe n
0 (t -> n
st forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) (forall a. [a] -> Maybe a
headMay [(t, a)]
sq)
,forall b a. b -> (a -> b) -> Maybe a -> b
maybe n
0 (t -> n
et forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) (forall a. [a] -> Maybe a
lastMay [(t, a)]
sq))
tseq_tspan :: Num t => Tseq t a -> (t,t)
tseq_tspan :: forall t a. Num t => Tseq t a -> (t, t)
tseq_tspan = forall n t a. Num n => (t -> n) -> (t -> n) -> [(t, a)] -> (n, n)
seq_tspan forall a. a -> a
id forall a. a -> a
id
wseq_tspan :: Num t => Wseq t a -> (t,t)
wseq_tspan :: forall t a. Num t => Wseq t a -> (t, t)
wseq_tspan = forall n t a. Num n => (t -> n) -> (t -> n) -> [(t, a)] -> (n, n)
seq_tspan forall a b. (a, b) -> a
fst (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Num a => a -> a -> a
(+))
wseq_start :: Num t => Wseq t a -> t
wseq_start :: forall t a. Num t => Wseq t a -> t
wseq_start = forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. Num t => Wseq t a -> (t, t)
wseq_tspan
wseq_end :: Num t => Wseq t a -> t
wseq_end :: forall t a. Num t => Wseq t a -> t
wseq_end = forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. Num t => Wseq t a -> (t, t)
wseq_tspan
dseq_dur :: Num t => Dseq t a -> t
dseq_dur :: forall t a. Num t => Dseq t a -> t
dseq_dur = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst
iseq_dur :: Num t => Iseq t a -> t
iseq_dur :: forall t a. Num t => Dseq t a -> t
iseq_dur = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst
pseq_dur :: Num t => Pseq t a -> t
pseq_dur :: forall t a. Num t => Pseq t a -> t
pseq_dur = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall t. T3 t -> t
T.t3_third forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst)
tseq_dur :: Num t => Tseq t a -> t
tseq_dur :: forall t a. Num t => Dseq t a -> t
tseq_dur = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Num a => a -> a -> a
subtract forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. Num t => Tseq t a -> (t, t)
tseq_tspan
wseq_dur :: Num t => Wseq t a -> t
wseq_dur :: forall t a. Num t => Wseq t a -> t
wseq_dur = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Num a => a -> a -> a
subtract forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. Num t => Wseq t a -> (t, t)
wseq_tspan
wseq_until :: Ord t => t -> Wseq t a -> Wseq t a
wseq_until :: forall t a. Ord t => t -> Wseq t a -> Wseq t a
wseq_until t
tm = forall a. (a -> Bool) -> [a] -> [a]
takeWhile (\((t
t0,t
_),a
_) -> t
t0 forall a. Ord a => a -> a -> Bool
<= t
tm)
wseq_twindow :: (Num t, Ord t) => (t,t) -> Wseq t a -> Wseq t a
wseq_twindow :: forall t a. (Num t, Ord t) => (t, t) -> Wseq t a -> Wseq t a
wseq_twindow (t
w0,t
w1) =
let f :: (t, t) -> Bool
f (t
st,t
du) = t
w0 forall a. Ord a => a -> a -> Bool
<= t
st Bool -> Bool -> Bool
&& (t
st forall a. Num a => a -> a -> a
+ t
du) forall a. Ord a => a -> a -> Bool
<= t
w1
in forall t a. ((t, t) -> Bool) -> Wseq t a -> Wseq t a
wseq_tfilter (t, t) -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. Ord t => t -> Wseq t a -> Wseq t a
wseq_until t
w1
wseq_at :: (Num t,Ord t) => Wseq t a -> t -> Wseq t a
wseq_at :: forall t a. (Num t, Ord t) => Wseq t a -> t -> Wseq t a
wseq_at Wseq t a
sq t
tm =
let sel :: ((t, t), b) -> Bool
sel ((t
t0,t
t1),b
_) = t
t0 forall a. Ord a => a -> a -> Bool
<= t
tm Bool -> Bool -> Bool
&& t
tm forall a. Ord a => a -> a -> Bool
< (t
t0 forall a. Num a => a -> a -> a
+ t
t1)
end :: ((t, b), b) -> Bool
end ((t
t0,b
_),b
_) = t
t0 forall a. Ord a => a -> a -> Bool
<= t
tm
in forall a. (a -> Bool) -> [a] -> [a]
filter forall {b}. ((t, t), b) -> Bool
sel (forall a. (a -> Bool) -> [a] -> [a]
takeWhile forall {b} {b}. ((t, b), b) -> Bool
end Wseq t a
sq)
wseq_at_window :: (Num t, Ord t) => Wseq t a -> (t,t) -> Wseq t a
wseq_at_window :: forall t a. (Num t, Ord t) => Wseq t a -> (t, t) -> Wseq t a
wseq_at_window Wseq t a
sq (t
w0,t
w1) =
let f :: (a, a) -> a -> Bool
f (a
t0,a
t1) a
t = a
t0 forall a. Ord a => a -> a -> Bool
<= a
t Bool -> Bool -> Bool
&& a
t forall a. Ord a => a -> a -> Bool
< a
t1
g :: (t, t) -> Bool
g (t
st,t
du) = let w :: (t, t)
w = (t
st,t
st forall a. Num a => a -> a -> a
+ t
du) in forall {a}. Ord a => (a, a) -> a -> Bool
f (t, t)
w t
w0 Bool -> Bool -> Bool
|| forall {a}. Ord a => (a, a) -> a -> Bool
f (t, t)
w t
w1
in forall t a. ((t, t) -> Bool) -> Wseq t a -> Wseq t a
wseq_tfilter (t, t) -> Bool
g (forall t a. Ord t => t -> Wseq t a -> Wseq t a
wseq_until t
w1 Wseq t a
sq)
dseq_append :: Dseq t a -> Dseq t a -> Dseq t a
dseq_append :: forall t a. Dseq t a -> Dseq t a -> Dseq t a
dseq_append = forall a. [a] -> [a] -> [a]
(++)
iseq_append :: Iseq t a -> Iseq t a -> Iseq t a
iseq_append :: forall t a. Dseq t a -> Dseq t a -> Dseq t a
iseq_append = forall a. [a] -> [a] -> [a]
(++)
pseq_append :: Pseq t a -> Pseq t a -> Pseq t a
pseq_append :: forall t a. Pseq t a -> Pseq t a -> Pseq t a
pseq_append = forall a. [a] -> [a] -> [a]
(++)
tseq_merge :: Ord t => Tseq t a -> Tseq t a -> Tseq t a
tseq_merge :: forall t a. Ord t => Tseq t a -> Tseq t a -> Tseq t a
tseq_merge = forall a. (a -> a -> Ordering) -> [a] -> [a] -> [a]
O.mergeBy (forall a. Ord a => a -> a -> Ordering
compare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` forall a b. (a, b) -> a
fst)
tseq_merge_by :: Ord t => T.Compare_F a -> Tseq t a -> Tseq t a -> Tseq t a
tseq_merge_by :: forall t a.
Ord t =>
Compare_F a -> Tseq t a -> Tseq t a -> Tseq t a
tseq_merge_by Compare_F a
cmp = forall b a c.
Ord b =>
(a -> b) -> Compare_F c -> (a -> c) -> [a] -> [a] -> [a]
T.merge_by_two_stage forall a b. (a, b) -> a
fst Compare_F a
cmp forall a b. (a, b) -> b
snd
tseq_merge_resolve :: Ord t => (a -> a -> a) -> Tseq t a -> Tseq t a -> Tseq t a
tseq_merge_resolve :: forall t a.
Ord t =>
(a -> a -> a) -> Tseq t a -> Tseq t a -> Tseq t a
tseq_merge_resolve a -> a -> a
f =
let cmp :: (t, b) -> (t, b) -> Ordering
cmp = forall a. Ord a => a -> a -> Ordering
compare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` forall a b. (a, b) -> a
fst
g :: (a, a) -> (a, a) -> (a, a)
g (a
t,a
p) (a
_,a
q) = (a
t,a -> a -> a
f a
p a
q)
in forall a. (a -> a -> a) -> Compare_F a -> [a] -> [a] -> [a]
T.merge_by_resolve forall {a} {a}. (a, a) -> (a, a) -> (a, a)
g forall {b}. (t, b) -> (t, b) -> Ordering
cmp
w_compare :: Ord t => ((t,t),a) -> ((t,t),a) -> Ordering
w_compare :: forall t a. Ord t => ((t, t), a) -> ((t, t), a) -> Ordering
w_compare ((t
t1,t
d1),a
_) ((t
t2,t
d2),a
_) =
case forall a. Ord a => a -> a -> Ordering
compare t
t1 t
t2 of
Ordering
EQ -> forall a. Ord a => a -> a -> Ordering
compare t
d1 t
d2
Ordering
r -> Ordering
r
wseq_merge :: Ord t => Wseq t a -> Wseq t a -> Wseq t a
wseq_merge :: forall t a. Ord t => Wseq t a -> Wseq t a -> Wseq t a
wseq_merge = forall a. (a -> a -> Ordering) -> [a] -> [a] -> [a]
O.mergeBy (forall a. Ord a => a -> a -> Ordering
compare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst))
wseq_merge_set :: Ord t => [Wseq t a] -> Wseq t a
wseq_merge_set :: forall t a. Ord t => [Wseq t a] -> Wseq t a
wseq_merge_set = forall a. (a -> a -> Ordering) -> [[a]] -> [a]
T.merge_set_by forall t a. Ord t => ((t, t), a) -> ((t, t), a) -> Ordering
w_compare
eseq_merge :: Ord t => Eseq t a -> Eseq t a -> Eseq t a
eseq_merge :: forall t a. Ord t => Eseq t a -> Eseq t a -> Eseq t a
eseq_merge = forall a. (a -> a -> Ordering) -> [a] -> [a] -> [a]
O.mergeBy (forall a. Ord a => a -> a -> Ordering
compare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (forall t. T3 t -> t
T.t3_fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst))
tseq_lookup_window_by :: (t -> t -> Ordering) -> Tseq t e -> t -> (Maybe (t,e),Maybe (t,e))
tseq_lookup_window_by :: forall t e.
(t -> t -> Ordering)
-> Tseq t e -> t -> (Maybe (t, e), Maybe (t, e))
tseq_lookup_window_by t -> t -> Ordering
cmp =
let recur :: Maybe (t, b) -> [(t, b)] -> t -> (Maybe (t, b), Maybe (t, b))
recur Maybe (t, b)
l [(t, b)]
sq t
t =
case [(t, b)]
sq of
[] -> (Maybe (t, b)
l,forall a. Maybe a
Nothing)
(t
t',b
e):[(t, b)]
sq' -> case t -> t -> Ordering
cmp t
t t
t' of
Ordering
LT -> (Maybe (t, b)
l,forall a. a -> Maybe a
Just (t
t',b
e))
Ordering
_ -> case [(t, b)]
sq' of
[] -> (forall a. a -> Maybe a
Just (t
t',b
e),forall a. Maybe a
Nothing)
(t
t'',b
e'):[(t, b)]
_ -> case t -> t -> Ordering
cmp t
t t
t'' of
Ordering
LT -> (forall a. a -> Maybe a
Just (t
t',b
e),forall a. a -> Maybe a
Just (t
t'',b
e'))
Ordering
_ -> Maybe (t, b) -> [(t, b)] -> t -> (Maybe (t, b), Maybe (t, b))
recur (forall a. a -> Maybe a
Just (t
t',b
e)) [(t, b)]
sq' t
t
in forall {b}.
Maybe (t, b) -> [(t, b)] -> t -> (Maybe (t, b), Maybe (t, b))
recur forall a. Maybe a
Nothing
tseq_lookup_active_by :: (t -> t -> Ordering) -> Tseq t e -> t -> Maybe e
tseq_lookup_active_by :: forall t e. (t -> t -> Ordering) -> Tseq t e -> t -> Maybe e
tseq_lookup_active_by t -> t -> Ordering
cmp Tseq t e
sq = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t e.
(t -> t -> Ordering)
-> Tseq t e -> t -> (Maybe (t, e), Maybe (t, e))
tseq_lookup_window_by t -> t -> Ordering
cmp Tseq t e
sq
tseq_lookup_active :: Ord t => Tseq t e -> t -> Maybe e
tseq_lookup_active :: forall t e. Ord t => Tseq t e -> t -> Maybe e
tseq_lookup_active = forall t e. (t -> t -> Ordering) -> Tseq t e -> t -> Maybe e
tseq_lookup_active_by forall a. Ord a => a -> a -> Ordering
compare
tseq_lookup_active_by_def :: e -> (t -> t -> Ordering) -> Tseq t e -> t -> e
tseq_lookup_active_by_def :: forall e t. e -> (t -> t -> Ordering) -> Tseq t e -> t -> e
tseq_lookup_active_by_def e
def t -> t -> Ordering
cmp Tseq t e
sq = forall a. a -> Maybe a -> a
fromMaybe e
def forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t e. (t -> t -> Ordering) -> Tseq t e -> t -> Maybe e
tseq_lookup_active_by t -> t -> Ordering
cmp Tseq t e
sq
tseq_lookup_active_def :: Ord t => e -> Tseq t e -> t -> e
tseq_lookup_active_def :: forall t e. Ord t => e -> Tseq t e -> t -> e
tseq_lookup_active_def e
def = forall e t. e -> (t -> t -> Ordering) -> Tseq t e -> t -> e
tseq_lookup_active_by_def e
def forall a. Ord a => a -> a -> Ordering
compare
data Interpolation_T =
None | Linear
deriving (Interpolation_T -> Interpolation_T -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Interpolation_T -> Interpolation_T -> Bool
$c/= :: Interpolation_T -> Interpolation_T -> Bool
== :: Interpolation_T -> Interpolation_T -> Bool
$c== :: Interpolation_T -> Interpolation_T -> Bool
Eq,Int -> Interpolation_T
Interpolation_T -> Int
Interpolation_T -> [Interpolation_T]
Interpolation_T -> Interpolation_T
Interpolation_T -> Interpolation_T -> [Interpolation_T]
Interpolation_T
-> Interpolation_T -> Interpolation_T -> [Interpolation_T]
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 :: Interpolation_T
-> Interpolation_T -> Interpolation_T -> [Interpolation_T]
$cenumFromThenTo :: Interpolation_T
-> Interpolation_T -> Interpolation_T -> [Interpolation_T]
enumFromTo :: Interpolation_T -> Interpolation_T -> [Interpolation_T]
$cenumFromTo :: Interpolation_T -> Interpolation_T -> [Interpolation_T]
enumFromThen :: Interpolation_T -> Interpolation_T -> [Interpolation_T]
$cenumFromThen :: Interpolation_T -> Interpolation_T -> [Interpolation_T]
enumFrom :: Interpolation_T -> [Interpolation_T]
$cenumFrom :: Interpolation_T -> [Interpolation_T]
fromEnum :: Interpolation_T -> Int
$cfromEnum :: Interpolation_T -> Int
toEnum :: Int -> Interpolation_T
$ctoEnum :: Int -> Interpolation_T
pred :: Interpolation_T -> Interpolation_T
$cpred :: Interpolation_T -> Interpolation_T
succ :: Interpolation_T -> Interpolation_T
$csucc :: Interpolation_T -> Interpolation_T
Enum,Int -> Interpolation_T -> ShowS
[Interpolation_T] -> ShowS
Interpolation_T -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Interpolation_T] -> ShowS
$cshowList :: [Interpolation_T] -> ShowS
show :: Interpolation_T -> String
$cshow :: Interpolation_T -> String
showsPrec :: Int -> Interpolation_T -> ShowS
$cshowsPrec :: Int -> Interpolation_T -> ShowS
Show)
type Lseq t a = Tseq (t,Interpolation_T) a
lerp :: (Fractional t,Real t,Fractional e) => (t,e) -> (t,e) -> t -> e
lerp :: forall t e.
(Fractional t, Real t, Fractional e) =>
(t, e) -> (t, e) -> t -> e
lerp (t
t0,e
e0) (t
t1,e
e1) t
t =
let n :: t
n = t
t1 forall a. Num a => a -> a -> a
- t
t0
m :: t
m = t
t forall a. Num a => a -> a -> a
- t
t0
l :: t
l = t
m forall a. Fractional a => a -> a -> a
/ t
n
in forall a b. (Real a, Fractional b) => a -> b
realToFrac t
l forall a. Num a => a -> a -> a
* (e
e1 forall a. Num a => a -> a -> a
- e
e0) forall a. Num a => a -> a -> a
+ e
e0
lseq_tmap :: (t -> t') -> Lseq t a -> Lseq t' a
lseq_tmap :: forall t t' a. (t -> t') -> Lseq t a -> Lseq t' a
lseq_tmap t -> t'
f = let g :: ((t, b), b) -> ((t', b), b)
g ((t
t,b
i),b
e) = ((t -> t'
f t
t,b
i),b
e) in forall a b. (a -> b) -> [a] -> [b]
map forall {b} {b}. ((t, b), b) -> ((t', b), b)
g
lseq_lookup :: (Fractional t,Real t,Fractional e) => (t -> t -> Ordering) -> Lseq t e -> t -> Maybe e
lseq_lookup :: forall t e.
(Fractional t, Real t, Fractional e) =>
(t -> t -> Ordering) -> Lseq t e -> t -> Maybe e
lseq_lookup t -> t -> Ordering
cmp Lseq t e
sq t
t =
case forall t e.
(t -> t -> Ordering)
-> Tseq t e -> t -> (Maybe (t, e), Maybe (t, e))
tseq_lookup_window_by (t -> t -> Ordering
cmp forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` forall a b. (a, b) -> a
fst) Lseq t e
sq (t
t,forall a. HasCallStack => a
undefined) of
(Maybe ((t, Interpolation_T), e)
Nothing,Maybe ((t, Interpolation_T), e)
_) -> forall a. Maybe a
Nothing
(Just ((t
_,Interpolation_T
None),e
e),Maybe ((t, Interpolation_T), e)
_) -> forall a. a -> Maybe a
Just e
e
(Just ((t
t0,Interpolation_T
Linear),e
e0),Just ((t
t1,Interpolation_T
_),e
e1)) -> forall a. a -> Maybe a
Just (forall t e.
(Fractional t, Real t, Fractional e) =>
(t, e) -> (t, e) -> t -> e
lerp (t
t0,e
e0) (t
t1,e
e1) t
t)
(Maybe ((t, Interpolation_T), e), Maybe ((t, Interpolation_T), e))
_ -> forall a. Maybe a
Nothing
lseq_lookup_err :: (Fractional t,Real t,Fractional e) => (t -> t -> Ordering) -> Lseq t e -> t -> e
lseq_lookup_err :: forall t e.
(Fractional t, Real t, Fractional e) =>
(t -> t -> Ordering) -> Lseq t e -> t -> e
lseq_lookup_err t -> t -> Ordering
cmp Lseq t e
sq = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => String -> a
error String
"lseq_lookup") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t e.
(Fractional t, Real t, Fractional e) =>
(t -> t -> Ordering) -> Lseq t e -> t -> Maybe e
lseq_lookup t -> t -> Ordering
cmp Lseq t e
sq
seq_tmap :: (t1 -> t2) -> [(t1,a)] -> [(t2,a)]
seq_tmap :: forall t1 t2 a. (t1 -> t2) -> [(t1, a)] -> [(t2, a)]
seq_tmap t1 -> t2
f = forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first t1 -> t2
f)
seq_map :: (e1 -> e2) -> [(t,e1)] -> [(t,e2)]
seq_map :: forall e1 e2 t. (e1 -> e2) -> [(t, e1)] -> [(t, e2)]
seq_map e1 -> e2
f = forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second e1 -> e2
f)
seq_bimap :: (t1 -> t2) -> (e1 -> e2) -> [(t1,e1)] -> [(t2,e2)]
seq_bimap :: forall t1 t2 e1 e2.
(t1 -> t2) -> (e1 -> e2) -> [(t1, e1)] -> [(t2, e2)]
seq_bimap t1 -> t2
f = forall a b. (a -> b) -> [a] -> [b]
map forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap t1 -> t2
f
seq_tfilter :: (t -> Bool) -> [(t,a)] -> [(t,a)]
seq_tfilter :: forall t a. (t -> Bool) -> [(t, a)] -> [(t, a)]
seq_tfilter t -> Bool
f = forall a. (a -> Bool) -> [a] -> [a]
filter (t -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst)
seq_filter :: (b -> Bool) -> [(a,b)] -> [(a,b)]
seq_filter :: forall b a. (b -> Bool) -> [(a, b)] -> [(a, b)]
seq_filter b -> Bool
f = forall a. (a -> Bool) -> [a] -> [a]
filter (b -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd)
seq_find :: (e -> Bool) -> [(t,e)] -> Maybe (t,e)
seq_find :: forall e t. (e -> Bool) -> [(t, e)] -> Maybe (t, e)
seq_find e -> Bool
f = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (e -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd)
seq_map_maybe :: (p -> Maybe q) -> [(t,p)] -> [(t,q)]
seq_map_maybe :: forall p q t. (p -> Maybe q) -> [(t, p)] -> [(t, q)]
seq_map_maybe p -> Maybe q
f =
let g :: (a, p) -> Maybe (a, q)
g (a
t,p
e) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\q
e' -> (a
t,q
e')) (p -> Maybe q
f p
e)
in forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe forall {a}. (a, p) -> Maybe (a, q)
g
seq_cat_maybes :: [(t,Maybe q)] -> [(t,q)]
seq_cat_maybes :: forall t q. [(t, Maybe q)] -> [(t, q)]
seq_cat_maybes = forall p q t. (p -> Maybe q) -> [(t, p)] -> [(t, q)]
seq_map_maybe forall a. a -> a
id
seq_changed_by :: (a -> a -> Bool) -> [(t,a)] -> [(t,Maybe a)]
seq_changed_by :: forall a t. (a -> a -> Bool) -> [(t, a)] -> [(t, Maybe a)]
seq_changed_by a -> a -> Bool
f [(t, a)]
l =
let recur :: a -> [(a, a)] -> [(a, Maybe a)]
recur a
z [(a, a)]
sq =
case [(a, a)]
sq of
[] -> []
(a
t,a
e):[(a, a)]
sq' -> if a -> a -> Bool
f a
e a
z
then (a
t,forall a. Maybe a
Nothing) forall a. a -> [a] -> [a]
: a -> [(a, a)] -> [(a, Maybe a)]
recur a
z [(a, a)]
sq'
else (a
t,forall a. a -> Maybe a
Just a
e) forall a. a -> [a] -> [a]
: a -> [(a, a)] -> [(a, Maybe a)]
recur a
e [(a, a)]
sq'
in case [(t, a)]
l of
[] -> []
(t
t,a
e) : [(t, a)]
l' -> (t
t,forall a. a -> Maybe a
Just a
e) forall a. a -> [a] -> [a]
: forall {a}. a -> [(a, a)] -> [(a, Maybe a)]
recur a
e [(t, a)]
l'
seq_changed :: Eq a => [(t,a)] -> [(t,Maybe a)]
seq_changed :: forall a t. Eq a => [(t, a)] -> [(t, Maybe a)]
seq_changed = forall a t. (a -> a -> Bool) -> [(t, a)] -> [(t, Maybe a)]
seq_changed_by forall a. Eq a => a -> a -> Bool
(==)
wseq_tmap_st :: (t -> t) -> Wseq t a -> Wseq t a
wseq_tmap_st :: forall t a. (t -> t) -> Wseq t a -> Wseq t a
wseq_tmap_st t -> t
f = forall t1 t2 a. (t1 -> t2) -> [(t1, a)] -> [(t2, a)]
seq_tmap (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first t -> t
f)
wseq_tmap_dur :: (t -> t) -> Wseq t a -> Wseq t a
wseq_tmap_dur :: forall t a. (t -> t) -> Wseq t a -> Wseq t a
wseq_tmap_dur t -> t
f = forall t1 t2 a. (t1 -> t2) -> [(t1, a)] -> [(t2, a)]
seq_tmap (forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second t -> t
f)
seq_partition :: Ord v => (a -> v) -> [(t,a)] -> [(v,[(t,a)])]
seq_partition :: forall v a t. Ord v => (a -> v) -> [(t, a)] -> [(v, [(t, a)])]
seq_partition a -> v
voice [(t, a)]
sq =
let assign :: Map v [(a, a)] -> (a, a) -> Map v [(a, a)]
assign Map v [(a, a)]
m (a
t,a
a) = forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
Map.insertWith forall a. [a] -> [a] -> [a]
(++) (a -> v
voice a
a) [(a
t,a
a)] Map v [(a, a)]
m
from_map :: Map v [a] -> [(v, [a])]
from_map = forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second forall a. [a] -> [a]
reverse) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall k a. Map k a -> [(k, a)]
Map.toList
in forall {a}. Map v [a] -> [(v, [a])]
from_map (forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl forall {a}. Map v [(a, a)] -> (a, a) -> Map v [(a, a)]
assign forall k a. Map k a
Map.empty [(t, a)]
sq)
tseq_partition :: Ord v => (a -> v) -> Tseq t a -> [(v,Tseq t a)]
tseq_partition :: forall v a t. Ord v => (a -> v) -> [(t, a)] -> [(v, [(t, a)])]
tseq_partition = forall v a t. Ord v => (a -> v) -> [(t, a)] -> [(v, [(t, a)])]
seq_partition
wseq_partition :: Ord v => (a -> v) -> Wseq t a -> [(v,Wseq t a)]
wseq_partition :: forall v a t. Ord v => (a -> v) -> Wseq t a -> [(v, Wseq t a)]
wseq_partition = forall v a t. Ord v => (a -> v) -> [(t, a)] -> [(v, [(t, a)])]
seq_partition
coalesce_f :: (t -> t -> Bool) -> (t -> t -> t) -> [t] -> [t]
coalesce_f :: forall t. (t -> t -> Bool) -> (t -> t -> t) -> [t] -> [t]
coalesce_f t -> t -> Bool
dec_f t -> t -> t
jn_f [t]
z =
let recur :: t -> [t] -> [t]
recur t
p [t]
l =
case [t]
l of
[] -> [t
p]
t
c:[t]
l' -> if t -> t -> Bool
dec_f t
p t
c
then t -> [t] -> [t]
recur (t -> t -> t
jn_f t
p t
c) [t]
l'
else t
p forall a. a -> [a] -> [a]
: t -> [t] -> [t]
recur t
c [t]
l'
in case [t]
z of
[] -> []
t
e0:[t]
z' -> t -> [t] -> [t]
recur t
e0 [t]
z'
coalesce_m :: Monoid t => (t -> t -> Bool) -> [t] -> [t]
coalesce_m :: forall t. Monoid t => (t -> t -> Bool) -> [t] -> [t]
coalesce_m t -> t -> Bool
dec_f = forall t. (t -> t -> Bool) -> (t -> t -> t) -> [t] -> [t]
coalesce_f t -> t -> Bool
dec_f forall a. Monoid a => a -> a -> a
mappend
coalesce_t :: Num t => ((t,a) -> (t,a) -> Bool) -> (a -> a -> a) -> [(t,a)] -> [(t,a)]
coalesce_t :: forall t a.
Num t =>
((t, a) -> (t, a) -> Bool) -> (a -> a -> a) -> [(t, a)] -> [(t, a)]
coalesce_t (t, a) -> (t, a) -> Bool
dec_f a -> a -> a
jn_f = forall t. (t -> t -> Bool) -> (t -> t -> t) -> [t] -> [t]
coalesce_f (t, a) -> (t, a) -> Bool
dec_f (\(t
t1,a
a1) (t
t2,a
a2) -> (t
t1 forall a. Num a => a -> a -> a
+ t
t2,a -> a -> a
jn_f a
a1 a
a2))
seq_coalesce :: Num t => (a -> a -> Bool) -> (a -> a -> a) -> [(t,a)] -> [(t,a)]
seq_coalesce :: forall t a.
Num t =>
(a -> a -> Bool) -> (a -> a -> a) -> [(t, a)] -> [(t, a)]
seq_coalesce a -> a -> Bool
dec_f a -> a -> a
jn_f = forall t a.
Num t =>
((t, a) -> (t, a) -> Bool) -> (a -> a -> a) -> [(t, a)] -> [(t, a)]
coalesce_t (a -> a -> Bool
dec_f forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` forall a b. (a, b) -> b
snd) a -> a -> a
jn_f
dseq_coalesce :: Num t => (a -> a -> Bool) -> (a -> a -> a) -> Dseq t a -> Dseq t a
dseq_coalesce :: forall t a.
Num t =>
(a -> a -> Bool) -> (a -> a -> a) -> [(t, a)] -> [(t, a)]
dseq_coalesce = forall t a.
Num t =>
(a -> a -> Bool) -> (a -> a -> a) -> [(t, a)] -> [(t, a)]
seq_coalesce
dseq_coalesce' :: Num t => (a -> a -> Bool) -> Dseq t a -> Dseq t a
dseq_coalesce' :: forall t a. Num t => (a -> a -> Bool) -> Dseq t a -> Dseq t a
dseq_coalesce' a -> a -> Bool
eq =
let f :: [(a, b)] -> (a, b)
f [(a, b)]
l = let ([a]
t,[b]
e) = forall a b. [(a, b)] -> ([a], [b])
unzip [(a, b)]
l in (forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [a]
t,forall a. [a] -> a
head [b]
e)
in forall a b. (a -> b) -> [a] -> [b]
map forall {a} {b}. Num a => [(a, b)] -> (a, b)
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy (a -> a -> Bool
eq forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` forall a b. (a, b) -> b
snd)
iseq_coalesce :: Num t => (a -> a -> Bool) -> (a -> a -> a) -> Iseq t a -> Iseq t a
iseq_coalesce :: forall t a.
Num t =>
(a -> a -> Bool) -> (a -> a -> a) -> [(t, a)] -> [(t, a)]
iseq_coalesce = forall t a.
Num t =>
(a -> a -> Bool) -> (a -> a -> a) -> [(t, a)] -> [(t, a)]
seq_coalesce
seq_tcoalesce :: (t -> t -> Bool) -> (a -> a -> a) -> [(t,a)] -> [(t,a)]
seq_tcoalesce :: forall t a.
(t -> t -> Bool) -> (a -> a -> a) -> [(t, a)] -> [(t, a)]
seq_tcoalesce t -> t -> Bool
eq_f a -> a -> a
jn_f =
let dec_f :: (t, b) -> (t, b) -> Bool
dec_f = t -> t -> Bool
eq_f forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` forall a b. (a, b) -> a
fst
jn_f' :: (a, a) -> (a, a) -> (a, a)
jn_f' (a
t,a
a1) (a
_,a
a2) = (a
t,a -> a -> a
jn_f a
a1 a
a2)
in forall t. (t -> t -> Bool) -> (t -> t -> t) -> [t] -> [t]
coalesce_f forall {b}. (t, b) -> (t, b) -> Bool
dec_f forall {a} {a}. (a, a) -> (a, a) -> (a, a)
jn_f'
tseq_tcoalesce :: Eq t => (a -> a -> a) -> Tseq t a -> Tseq t a
tseq_tcoalesce :: forall t a. Eq t => (a -> a -> a) -> Tseq t a -> Tseq t a
tseq_tcoalesce = forall t a.
(t -> t -> Bool) -> (a -> a -> a) -> [(t, a)] -> [(t, a)]
seq_tcoalesce forall a. Eq a => a -> a -> Bool
(==)
wseq_tcoalesce :: ((t,t) -> (t,t) -> Bool) -> (a -> a -> a) -> Wseq t a -> Wseq t a
wseq_tcoalesce :: forall t a.
((t, t) -> (t, t) -> Bool) -> (a -> a -> a) -> Wseq t a -> Wseq t a
wseq_tcoalesce = forall t a.
(t -> t -> Bool) -> (a -> a -> a) -> [(t, a)] -> [(t, a)]
seq_tcoalesce
group_f :: (Eq t,Num t) => (t -> t -> Bool) -> [(t,a)] -> [(t,[a])]
group_f :: forall t a.
(Eq t, Num t) =>
(t -> t -> Bool) -> [(t, a)] -> [(t, [a])]
group_f t -> t -> Bool
cmp =
let f :: [(a, b)] -> (a, [b])
f [(a, b)]
l = let ([a]
t,[b]
a) = forall a b. [(a, b)] -> ([a], [b])
unzip [(a, b)]
l
in case [a]
t of
[] -> forall a. HasCallStack => String -> a
error String
"group_f: []?"
a
t0:[a]
_ -> (a
t0,[b]
a)
in forall a b. (a -> b) -> [a] -> [b]
map forall {a} {b}. [(a, b)] -> (a, [b])
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy (t -> t -> Bool
cmp forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` forall a b. (a, b) -> a
fst)
tseq_group :: (Eq t,Num t) => Tseq t a -> Tseq t [a]
tseq_group :: forall t a. (Eq t, Num t) => Tseq t a -> Tseq t [a]
tseq_group = forall t a.
(Eq t, Num t) =>
(t -> t -> Bool) -> [(t, a)] -> [(t, [a])]
group_f forall a. Eq a => a -> a -> Bool
(==)
iseq_group :: (Eq t,Num t) => Iseq t a -> Iseq t [a]
iseq_group :: forall t a. (Eq t, Num t) => Tseq t a -> Tseq t [a]
iseq_group = forall t a.
(Eq t, Num t) =>
(t -> t -> Bool) -> [(t, a)] -> [(t, [a])]
group_f (\t
_ t
d -> t
d forall a. Eq a => a -> a -> Bool
== t
0)
wseq_fill_dur :: Num t => Wseq t a -> Wseq t a
wseq_fill_dur :: forall t a. Num t => Wseq t a -> Wseq t a
wseq_fill_dur Wseq t a
l =
let f :: (((b, b), b), ((b, b), b)) -> ((b, b), b)
f (((b
t1,b
_),b
e),((b
t2,b
_),b
_)) = ((b
t1,b
t2forall a. Num a => a -> a -> a
-b
t1),b
e)
in forall a b. (a -> b) -> [a] -> [b]
map forall {b} {b} {b} {b} {b}.
Num b =>
(((b, b), b), ((b, b), b)) -> ((b, b), b)
f (forall t. Int -> [t] -> [(t, t)]
T.adj2 Int
1 Wseq t a
l) forall a. [a] -> [a] -> [a]
++ [forall a. [a] -> a
last Wseq t a
l]
dseq_lcm :: Dseq Rational e -> Integer
dseq_lcm :: forall e. Dseq Rational e -> Integer
dseq_lcm = forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 forall a. Integral a => a -> a -> a
lcm forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall a. Ratio a -> a
denominator forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst)
dseq_set_whole :: [Dseq Rational e] -> [Dseq Integer e]
dseq_set_whole :: forall e. [Dseq Rational e] -> [Dseq Integer e]
dseq_set_whole [Dseq Rational e]
sq =
let m :: Integer
m = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum (forall a b. (a -> b) -> [a] -> [b]
map forall e. Dseq Rational e -> Integer
dseq_lcm [Dseq Rational e]
sq)
t_f :: Ratio a -> a
t_f Ratio a
n = forall a. Integral a => Ratio a -> a
T.rational_whole_err (Ratio a
n forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
m)
in forall a b. (a -> b) -> [a] -> [b]
map (forall t1 t2 a. (t1 -> t2) -> [(t1, a)] -> [(t2, a)]
dseq_tmap forall a. Integral a => Ratio a -> a
t_f) [Dseq Rational e]
sq
dseq_end :: Num t => Dseq t a -> t
dseq_end :: forall t a. Num t => Dseq t a -> t
dseq_end = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst
tseq_latch :: Ord t => a -> Tseq t a -> [t] -> Tseq t a
tseq_latch :: forall t a. Ord t => a -> Tseq t a -> [t] -> Tseq t a
tseq_latch a
def Tseq t a
sq [t]
t =
case (Tseq t a
sq,[t]
t) of
([],[t]
_) -> forall a b. [a] -> [b] -> [(a, b)]
zip [t]
t (forall a. a -> [a]
repeat a
def)
(Tseq t a
_,[]) -> []
((t
sq_t,a
sq_e):Tseq t a
sq',t
t0:[t]
t') -> case forall a. Ord a => a -> a -> Ordering
compare t
sq_t t
t0 of
Ordering
LT -> (t
sq_t,a
sq_e) forall a. a -> [a] -> [a]
: forall t a. Ord t => a -> Tseq t a -> [t] -> Tseq t a
tseq_latch a
sq_e Tseq t a
sq' [t]
t
Ordering
EQ -> (t
sq_t,a
sq_e) forall a. a -> [a] -> [a]
: forall t a. Ord t => a -> Tseq t a -> [t] -> Tseq t a
tseq_latch a
sq_e Tseq t a
sq' [t]
t'
Ordering
GT -> (t
t0,a
def) forall a. a -> [a] -> [a]
: forall t a. Ord t => a -> Tseq t a -> [t] -> Tseq t a
tseq_latch a
def Tseq t a
sq [t]
t'
tseq_end :: Tseq t a -> t
tseq_end :: forall t a. Tseq t a -> t
tseq_end = forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> a
last
tseq_add_nil_after :: Num t => a -> t -> Tseq t a -> Tseq t a
tseq_add_nil_after :: forall t a. Num t => a -> t -> Tseq t a -> Tseq t a
tseq_add_nil_after a
nil t
n Tseq t a
sq = Tseq t a
sq forall a. [a] -> [a] -> [a]
++ [(forall t a. Tseq t a -> t
tseq_end Tseq t a
sq forall a. Num a => a -> a -> a
+ t
n,a
nil)]
wseq_sort :: Ord t => Wseq t a -> Wseq t a
wseq_sort :: forall t a. Ord t => Wseq t a -> Wseq t a
wseq_sort = forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (forall a. Ord a => a -> a -> Ordering
compare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst))
wseq_discard_dur :: Wseq t a -> Tseq t a
wseq_discard_dur :: forall t a. Wseq t a -> Tseq t a
wseq_discard_dur = let f :: ((a, b), b) -> (a, b)
f ((a
t,b
_),b
e) = (a
t,b
e) in forall a b. (a -> b) -> [a] -> [b]
map forall {a} {b} {b}. ((a, b), b) -> (a, b)
f
wseq_nodes_overlap :: (Ord t,Num t) => (e -> e -> Bool) -> ((t,t),e) -> ((t,t),e) -> Bool
wseq_nodes_overlap :: forall t e.
(Ord t, Num t) =>
(e -> e -> Bool) -> ((t, t), e) -> ((t, t), e) -> Bool
wseq_nodes_overlap e -> e -> Bool
eq_f ((t
t1,t
d1),e
a1) ((t
t2,t
_d2),e
a2) =
e -> e -> Bool
eq_f e
a1 e
a2 Bool -> Bool -> Bool
&& ((t
t1 forall a. Eq a => a -> a -> Bool
== t
t2 Bool -> Bool -> Bool
&& t
d1 forall a. Ord a => a -> a -> Bool
> t
0) Bool -> Bool -> Bool
|| (t
t2 forall a. Ord a => a -> a -> Bool
< (t
t1 forall a. Num a => a -> a -> a
+ t
d1)))
wseq_find_overlap_1 :: (Ord t,Num t) => (e -> e -> Bool) -> ((t,t),e) -> Wseq t e -> Bool
wseq_find_overlap_1 :: forall t e.
(Ord t, Num t) =>
(e -> e -> Bool) -> ((t, t), e) -> Wseq t e -> Bool
wseq_find_overlap_1 e -> e -> Bool
eq_f ((t, t), e)
e0 = forall a. Maybe a -> Bool
isJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (forall t e.
(Ord t, Num t) =>
(e -> e -> Bool) -> ((t, t), e) -> ((t, t), e) -> Bool
wseq_nodes_overlap e -> e -> Bool
eq_f ((t, t), e)
e0)
wseq_has_overlaps :: (Ord t, Num t) => (e -> e -> Bool) -> Wseq t e -> Bool
wseq_has_overlaps :: forall t e. (Ord t, Num t) => (e -> e -> Bool) -> Wseq t e -> Bool
wseq_has_overlaps e -> e -> Bool
eq_fn =
let recur :: [((t, t), e)] -> Bool
recur [((t, t), e)]
sq =
case [((t, t), e)]
sq of
[] -> Bool
False
((t, t), e)
e0:[((t, t), e)]
sq' -> forall t e.
(Ord t, Num t) =>
(e -> e -> Bool) -> ((t, t), e) -> Wseq t e -> Bool
wseq_find_overlap_1 e -> e -> Bool
eq_fn ((t, t), e)
e0 [((t, t), e)]
sq' Bool -> Bool -> Bool
|| [((t, t), e)] -> Bool
recur [((t, t), e)]
sq'
in forall {t}. (Ord t, Num t) => [((t, t), e)] -> Bool
recur
wseq_remove_overlaps_rm :: (Ord t,Num t) => (e -> e -> Bool) -> Wseq t e -> Wseq t e
wseq_remove_overlaps_rm :: forall t e.
(Ord t, Num t) =>
(e -> e -> Bool) -> Wseq t e -> Wseq t e
wseq_remove_overlaps_rm e -> e -> Bool
eq_f =
let recur :: [((t, t), e)] -> [((t, t), e)]
recur [((t, t), e)]
sq =
case [((t, t), e)]
sq of
[] -> []
((t, t), e)
e0:[((t, t), e)]
sq' -> ((t, t), e)
e0 forall a. a -> [a] -> [a]
: [((t, t), e)] -> [((t, t), e)]
recur (forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t e.
(Ord t, Num t) =>
(e -> e -> Bool) -> ((t, t), e) -> ((t, t), e) -> Bool
wseq_nodes_overlap e -> e -> Bool
eq_f ((t, t), e)
e0) [((t, t), e)]
sq')
in forall {t}. (Ord t, Num t) => [((t, t), e)] -> [((t, t), e)]
recur
wseq_remove_overlap_rw_1 :: (Ord t,Num t) =>
(e -> e -> Bool) -> (t -> t) -> ((t,t),e) -> Wseq t e -> Maybe (Wseq t e)
wseq_remove_overlap_rw_1 :: forall t e.
(Ord t, Num t) =>
(e -> e -> Bool)
-> (t -> t) -> ((t, t), e) -> Wseq t e -> Maybe (Wseq t e)
wseq_remove_overlap_rw_1 e -> e -> Bool
eq_f t -> t
dur_fn ((t
t,t
d),e
a) Wseq t e
sq =
let n_eq :: ((a, a), e) -> ((a, a), e) -> Bool
n_eq ((a
t1,a
d1),e
e1) ((a
t2,a
d2),e
e2) = a
t1 forall a. Eq a => a -> a -> Bool
== a
t2 Bool -> Bool -> Bool
&& a
d1 forall a. Eq a => a -> a -> Bool
== a
d2 Bool -> Bool -> Bool
&& e -> e -> Bool
eq_f e
e1 e
e2
in case forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (e -> e -> Bool
eq_f e
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) Wseq t e
sq of
Maybe ((t, t), e)
Nothing -> forall a. Maybe a
Nothing
Just ((t
t',t
d'),e
a') ->
if t
t forall a. Eq a => a -> a -> Bool
== t
t'
then if t
d forall a. Ord a => a -> a -> Bool
<= t
d'
then forall a. a -> Maybe a
Just Wseq t e
sq
else forall a. a -> Maybe a
Just (((t
t,t
d),e
a) forall a. a -> [a] -> [a]
: forall a. (a -> a -> Bool) -> a -> [a] -> [a]
deleteBy forall {a} {a}. (Eq a, Eq a) => ((a, a), e) -> ((a, a), e) -> Bool
n_eq ((t
t',t
d'),e
a') Wseq t e
sq)
else if t
t' forall a. Ord a => a -> a -> Bool
< t
t forall a. Num a => a -> a -> a
+ t
d
then forall a. a -> Maybe a
Just (((t
t,t -> t
dur_fn (t
t' forall a. Num a => a -> a -> a
- t
t)),e
a) forall a. a -> [a] -> [a]
: Wseq t e
sq)
else forall a. Maybe a
Nothing
wseq_remove_overlaps_rw :: (Ord t,Num t) => (e -> e -> Bool) -> (t -> t) -> Wseq t e -> Wseq t e
wseq_remove_overlaps_rw :: forall t e.
(Ord t, Num t) =>
(e -> e -> Bool) -> (t -> t) -> Wseq t e -> Wseq t e
wseq_remove_overlaps_rw e -> e -> Bool
eq_f t -> t
dur_fn =
let recur :: [((t, t), e)] -> [((t, t), e)]
recur [((t, t), e)]
sq =
case [((t, t), e)]
sq of
[] -> []
((t, t), e)
h:[((t, t), e)]
sq' ->
case forall t e.
(Ord t, Num t) =>
(e -> e -> Bool)
-> (t -> t) -> ((t, t), e) -> Wseq t e -> Maybe (Wseq t e)
wseq_remove_overlap_rw_1 e -> e -> Bool
eq_f t -> t
dur_fn ((t, t), e)
h [((t, t), e)]
sq' of
Maybe [((t, t), e)]
Nothing -> ((t, t), e)
h forall a. a -> [a] -> [a]
: [((t, t), e)] -> [((t, t), e)]
recur [((t, t), e)]
sq'
Just [((t, t), e)]
sq'' -> [((t, t), e)] -> [((t, t), e)]
recur [((t, t), e)]
sq''
in [((t, t), e)] -> [((t, t), e)]
recur
seq_unjoin :: [(t,[e])] -> [(t,e)]
seq_unjoin :: forall t e. [(t, [e])] -> [(t, e)]
seq_unjoin = let f :: (a, [b]) -> [(a, b)]
f (a
t,[b]
e) = forall a b. [a] -> [b] -> [(a, b)]
zip (forall a. a -> [a]
repeat a
t) [b]
e in forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall {a} {b}. (a, [b]) -> [(a, b)]
f
wseq_unjoin :: Wseq t [e] -> Wseq t e
wseq_unjoin :: forall t e. Wseq t [e] -> Wseq t e
wseq_unjoin = forall t e. [(t, [e])] -> [(t, e)]
seq_unjoin
wseq_shift :: Num t => t -> Wseq t a -> Wseq t a
wseq_shift :: forall t a. Num t => t -> Wseq t a -> Wseq t a
wseq_shift t
i = forall t a. (t -> t) -> Wseq t a -> Wseq t a
wseq_tmap_st (forall a. Num a => a -> a -> a
+ t
i)
wseq_append :: Num t => Wseq t a -> Wseq t a -> Wseq t a
wseq_append :: forall t a. Num t => Wseq t a -> Wseq t a -> Wseq t a
wseq_append Wseq t a
p Wseq t a
q = Wseq t a
p forall a. [a] -> [a] -> [a]
++ forall t a. Num t => t -> Wseq t a -> Wseq t a
wseq_shift (forall t a. Num t => Wseq t a -> t
wseq_end Wseq t a
p) Wseq t a
q
wseq_concat :: Num t => [Wseq t a] -> Wseq t a
wseq_concat :: forall t a. Num t => [Wseq t a] -> Wseq t a
wseq_concat = forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 forall t a. Num t => Wseq t a -> Wseq t a -> Wseq t a
wseq_append
wseq_zero :: Num t => Wseq t a -> Wseq t a
wseq_zero :: forall t a. Num t => Wseq t a -> Wseq t a
wseq_zero Wseq t a
sq = let t0 :: t
t0 = forall t a. Num t => Wseq t a -> t
wseq_start Wseq t a
sq in forall t t' a. ((t, t) -> (t', t')) -> Wseq t a -> Wseq t' a
wseq_tmap (\(t
st,t
du) -> (t
st forall a. Num a => a -> a -> a
- t
t0,t
du)) Wseq t a
sq
data Begin_End a = Begin a | End a deriving (Begin_End a -> Begin_End a -> Bool
forall a. Eq a => Begin_End a -> Begin_End a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Begin_End a -> Begin_End a -> Bool
$c/= :: forall a. Eq a => Begin_End a -> Begin_End a -> Bool
== :: Begin_End a -> Begin_End a -> Bool
$c== :: forall a. Eq a => Begin_End a -> Begin_End a -> Bool
Eq,Int -> Begin_End a -> ShowS
forall a. Show a => Int -> Begin_End a -> ShowS
forall a. Show a => [Begin_End a] -> ShowS
forall a. Show a => Begin_End a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Begin_End a] -> ShowS
$cshowList :: forall a. Show a => [Begin_End a] -> ShowS
show :: Begin_End a -> String
$cshow :: forall a. Show a => Begin_End a -> String
showsPrec :: Int -> Begin_End a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Begin_End a -> ShowS
Show)
begin_end_map :: (t -> u) -> Begin_End t -> Begin_End u
begin_end_map :: forall t u. (t -> u) -> Begin_End t -> Begin_End u
begin_end_map t -> u
f Begin_End t
x =
case Begin_End t
x of
Begin t
a -> forall a. a -> Begin_End a
Begin (t -> u
f t
a)
End t
a -> forall a. a -> Begin_End a
End (t -> u
f t
a)
instance Functor Begin_End where fmap :: forall t u. (t -> u) -> Begin_End t -> Begin_End u
fmap = forall t u. (t -> u) -> Begin_End t -> Begin_End u
begin_end_map
cmp_begin_end :: Begin_End a -> Begin_End b -> Ordering
cmp_begin_end :: forall a b. Begin_End a -> Begin_End b -> Ordering
cmp_begin_end Begin_End a
p Begin_End b
q =
case (Begin_End a
p,Begin_End b
q) of
(Begin a
_,End b
_) -> Ordering
LT
(Begin a
_,Begin b
_) -> Ordering
EQ
(End a
_,End b
_) -> Ordering
EQ
(End a
_,Begin b
_) -> Ordering
GT
either_to_begin_end :: Either a a -> Begin_End a
either_to_begin_end :: forall a. Either a a -> Begin_End a
either_to_begin_end Either a a
p =
case Either a a
p of
Left a
a -> forall a. a -> Begin_End a
Begin a
a
Right a
a -> forall a. a -> Begin_End a
End a
a
begin_end_to_either :: Begin_End a -> Either a a
begin_end_to_either :: forall a. Begin_End a -> Either a a
begin_end_to_either Begin_End a
p =
case Begin_End a
p of
Begin a
a -> forall a b. a -> Either a b
Left a
a
End a
a -> forall a b. b -> Either a b
Right a
a
begin_end_partition :: [Begin_End a] -> ([a],[a])
begin_end_partition :: forall a. [Begin_End a] -> ([a], [a])
begin_end_partition =
let f :: Begin_End a -> ([a], [a]) -> ([a], [a])
f Begin_End a
e ([a]
p,[a]
q) = case Begin_End a
e of
Begin a
x -> (a
xforall a. a -> [a] -> [a]
:[a]
p,[a]
q)
End a
x -> ([a]
p,a
xforall a. a -> [a] -> [a]
:[a]
q)
in forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall {a}. Begin_End a -> ([a], [a]) -> ([a], [a])
f ([],[])
begin_end_track_by :: (a -> a -> Bool) -> [a] -> Begin_End a -> [a]
begin_end_track_by :: forall a. (a -> a -> Bool) -> [a] -> Begin_End a -> [a]
begin_end_track_by a -> a -> Bool
eq_f [a]
st Begin_End a
e =
case Begin_End a
e of
Begin a
x -> a
x forall a. a -> [a] -> [a]
: [a]
st
End a
x -> forall a. (a -> a -> Bool) -> a -> [a] -> [a]
deleteBy a -> a -> Bool
eq_f a
x [a]
st
begin_end_track :: Eq a => [a] -> Begin_End a -> [a]
begin_end_track :: forall a. Eq a => [a] -> Begin_End a -> [a]
begin_end_track = forall a. (a -> a -> Bool) -> [a] -> Begin_End a -> [a]
begin_end_track_by forall a. Eq a => a -> a -> Bool
(==)
wseq_begin_end :: (Num t, Ord t) => Wseq t a -> Tseq t (Begin_End a)
wseq_begin_end :: forall t a. (Num t, Ord t) => Wseq t a -> Tseq t (Begin_End a)
wseq_begin_end Wseq t a
sq =
let f :: ((a, a), a) -> [(a, Begin_End a)]
f ((a
t,a
d),a
a) = [(a
t,forall a. a -> Begin_End a
Begin a
a),(a
t forall a. Num a => a -> a -> a
+ a
d,forall a. a -> Begin_End a
End a
a)]
g :: [Tseq t (Begin_End a)] -> Tseq t (Begin_End a)
g [Tseq t (Begin_End a)]
l =
case [Tseq t (Begin_End a)]
l of
[] -> []
Tseq t (Begin_End a)
e:[Tseq t (Begin_End a)]
l' -> forall t a.
Ord t =>
Compare_F a -> Tseq t a -> Tseq t a -> Tseq t a
tseq_merge_by (\Begin_End a
x -> Ordering -> Ordering
T.ord_invert forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Begin_End a -> Begin_End b -> Ordering
cmp_begin_end Begin_End a
x) Tseq t (Begin_End a)
e ([Tseq t (Begin_End a)] -> Tseq t (Begin_End a)
g [Tseq t (Begin_End a)]
l')
in forall {t} {a}.
Ord t =>
[Tseq t (Begin_End a)] -> Tseq t (Begin_End a)
g (forall a b. (a -> b) -> [a] -> [b]
map forall {a} {a}. Num a => ((a, a), a) -> [(a, Begin_End a)]
f Wseq t a
sq)
wseq_begin_end_either :: (Num t, Ord t) => Wseq t a -> Tseq t (Either a a)
wseq_begin_end_either :: forall t a. (Num t, Ord t) => Wseq t a -> Tseq t (Either a a)
wseq_begin_end_either = forall e1 e2 t. (e1 -> e2) -> [(t, e1)] -> [(t, e2)]
tseq_map forall a. Begin_End a -> Either a a
begin_end_to_either forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. (Num t, Ord t) => Wseq t a -> Tseq t (Begin_End a)
wseq_begin_end
wseq_begin_end_f :: (Ord t,Num t) => (a -> b) -> (a -> b) -> Wseq t a -> Tseq t b
wseq_begin_end_f :: forall t a b.
(Ord t, Num t) =>
(a -> b) -> (a -> b) -> Wseq t a -> Tseq t b
wseq_begin_end_f a -> b
f a -> b
g = forall e1 e2 t. (e1 -> e2) -> [(t, e1)] -> [(t, e2)]
tseq_map (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either a -> b
f a -> b
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. (Num t, Ord t) => Wseq t a -> Tseq t (Either a a)
wseq_begin_end_either
tseq_begin_end_accum :: Eq a => Tseq t [Begin_End a] -> Tseq t ([a],[a],[a])
tseq_begin_end_accum :: forall a t. Eq a => Tseq t [Begin_End a] -> Tseq t ([a], [a], [a])
tseq_begin_end_accum =
let f :: [a] -> (a, [Begin_End a]) -> ([a], (a, ([a], [a], [a])))
f [a]
st (a
t,[Begin_End a]
x) =
let ([a]
b,[a]
e) = forall a. [Begin_End a] -> ([a], [a])
begin_end_partition [Begin_End a]
x
st' :: [a]
st' = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl forall a. Eq a => [a] -> Begin_End a -> [a]
begin_end_track [a]
st [Begin_End a]
x
in ([a]
st',(a
t,([a]
b,[a]
e,[a]
st forall a. Eq a => [a] -> [a] -> [a]
\\ [a]
e)))
in forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL forall {a} {a}.
Eq a =>
[a] -> (a, [Begin_End a]) -> ([a], (a, ([a], [a], [a])))
f []
wseq_begin_end_accum :: (Eq e, Ord t, Num t) => Wseq t e -> (Bool, Tseq t ([e],[e],[e]))
wseq_begin_end_accum :: forall e t.
(Eq e, Ord t, Num t) =>
Wseq t e -> (Bool, Tseq t ([e], [e], [e]))
wseq_begin_end_accum Wseq t e
sq =
let ol :: Bool
ol = forall t e. (Ord t, Num t) => (e -> e -> Bool) -> Wseq t e -> Bool
wseq_has_overlaps forall a. Eq a => a -> a -> Bool
(==) Wseq t e
sq
sq_edit :: Wseq t e
sq_edit = if Bool
ol then forall t e.
(Ord t, Num t) =>
(e -> e -> Bool) -> (t -> t) -> Wseq t e -> Wseq t e
wseq_remove_overlaps_rw forall a. Eq a => a -> a -> Bool
(==) forall a. a -> a
id Wseq t e
sq else Wseq t e
sq
a_sq :: Tseq t ([e], [e], [e])
a_sq = forall a t. Eq a => Tseq t [Begin_End a] -> Tseq t ([a], [a], [a])
tseq_begin_end_accum (forall t a. (Eq t, Num t) => Tseq t a -> Tseq t [a]
tseq_group (forall t a. (Num t, Ord t) => Wseq t a -> Tseq t (Begin_End a)
wseq_begin_end Wseq t e
sq_edit))
in (Bool
ol,Tseq t ([e], [e], [e])
a_sq)
tseq_accumulate :: Eq a => Tseq t [Begin_End a] -> Tseq t [a]
tseq_accumulate :: forall a t. Eq a => Tseq t [Begin_End a] -> Tseq t [a]
tseq_accumulate =
let f :: [a] -> (a, t (Begin_End a)) -> ([a], (a, [a]))
f [a]
st (a
t,t (Begin_End a)
e) =
let g :: b -> (b, (a, b))
g b
st' = (b
st',(a
t,b
st'))
in forall {b}. b -> (b, (a, b))
g (forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl forall a. Eq a => [a] -> Begin_End a -> [a]
begin_end_track [a]
st t (Begin_End a)
e)
in forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL forall {t :: * -> *} {a} {a}.
(Foldable t, Eq a) =>
[a] -> (a, t (Begin_End a)) -> ([a], (a, [a]))
f []
wseq_accumulate :: (Eq a,Ord t,Num t) => Wseq t a -> Tseq t [a]
wseq_accumulate :: forall a t. (Eq a, Ord t, Num t) => Wseq t a -> Tseq t [a]
wseq_accumulate = forall a t. Eq a => Tseq t [Begin_End a] -> Tseq t [a]
tseq_accumulate forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. (Eq t, Num t) => Tseq t a -> Tseq t [a]
tseq_group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. (Num t, Ord t) => Wseq t a -> Tseq t (Begin_End a)
wseq_begin_end
tseq_begin_end_to_wseq :: Num t => (a -> a -> Bool) -> Tseq t (Begin_End a) -> Wseq t a
tseq_begin_end_to_wseq :: forall t a.
Num t =>
(a -> a -> Bool) -> Tseq t (Begin_End a) -> Wseq t a
tseq_begin_end_to_wseq a -> a -> Bool
cmp =
let cmp' :: a -> Begin_End a -> Bool
cmp' a
x Begin_End a
e =
case Begin_End a
e of
End a
x' -> a -> a -> Bool
cmp a
x a
x'
Begin_End a
_ -> Bool
False
f :: a -> [(a, Begin_End a)] -> a
f a
e [(a, Begin_End a)]
r = case forall e t. (e -> Bool) -> [(t, e)] -> Maybe (t, e)
seq_find (a -> Begin_End a -> Bool
cmp' a
e) [(a, Begin_End a)]
r of
Maybe (a, Begin_End a)
Nothing -> forall a. HasCallStack => String -> a
error String
"tseq_begin_end_to_wseq: no matching end?"
Just (a
t,Begin_End a
_) -> a
t
go :: [(b, Begin_End a)] -> [((b, b), a)]
go [(b, Begin_End a)]
sq = case [(b, Begin_End a)]
sq of
[] -> []
(b
_,End a
_) : [(b, Begin_End a)]
sq' -> [(b, Begin_End a)] -> [((b, b), a)]
go [(b, Begin_End a)]
sq'
(b
t,Begin a
e) : [(b, Begin_End a)]
sq' -> let t' :: b
t' = forall {a}. a -> [(a, Begin_End a)] -> a
f a
e [(b, Begin_End a)]
sq' in ((b
t,b
t' forall a. Num a => a -> a -> a
- b
t),a
e) forall a. a -> [a] -> [a]
: [(b, Begin_End a)] -> [((b, b), a)]
go [(b, Begin_End a)]
sq'
in forall {b}. Num b => [(b, Begin_End a)] -> [((b, b), a)]
go
useq_to_dseq :: Useq t a -> Dseq t a
useq_to_dseq :: forall {a} {b}. (a, [b]) -> [(a, b)]
useq_to_dseq (t
t,[a]
e) = forall a b. [a] -> [b] -> [(a, b)]
zip (forall a. a -> [a]
repeat t
t) [a]
e
useq_to_wseq :: Num t => t -> Useq t a -> Wseq t a
useq_to_wseq :: forall t a. Num t => t -> Useq t a -> Wseq t a
useq_to_wseq t
t0 = forall t a. Num t => t -> Dseq t a -> Wseq t a
dseq_to_wseq t
t0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {b}. (a, [b]) -> [(a, b)]
useq_to_dseq
dseq_to_tseq :: Num t => t -> a -> Dseq t a -> Tseq t a
dseq_to_tseq :: forall t a. Num t => t -> a -> Dseq t a -> Dseq t a
dseq_to_tseq t
t0 a
nil = forall t u v w.
([t] -> [u]) -> ([v] -> [w]) -> [(t, v)] -> [(u, w)]
T.rezip (forall a. Num a => a -> [a] -> [a]
T.dx_d t
t0) (forall a. a -> [a] -> [a]
T.snoc a
nil)
dseq_to_tseq_last :: Num t => t -> Dseq t a -> Tseq t a
dseq_to_tseq_last :: forall t a. Num t => t -> Dseq t a -> Dseq t a
dseq_to_tseq_last t
t0 Dseq t a
sq = forall t a. Num t => t -> a -> Dseq t a -> Dseq t a
dseq_to_tseq t
t0 (forall a b. (a, b) -> b
snd (forall a. [a] -> a
last Dseq t a
sq)) Dseq t a
sq
dseq_to_tseq_discard :: Num t => t -> Dseq t a -> Tseq t a
dseq_to_tseq_discard :: forall t a. Num t => t -> Dseq t a -> Dseq t a
dseq_to_tseq_discard t
t0 = forall a. [a] -> [a]
T.drop_last forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. Num t => t -> a -> Dseq t a -> Dseq t a
dseq_to_tseq t
t0 forall a. HasCallStack => a
undefined
iseq_to_tseq :: Num t => t -> Iseq t a -> Tseq t a
iseq_to_tseq :: forall t a. Num t => t -> Dseq t a -> Dseq t a
iseq_to_tseq t
t0 = forall t u v w.
([t] -> [u]) -> ([v] -> [w]) -> [(t, v)] -> [(u, w)]
T.rezip (forall a. [a] -> [a]
tail forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => a -> [a] -> [a]
T.dx_d t
t0) forall a. a -> a
id
pseq_to_wseq :: Num t => t -> Pseq t a -> Wseq t a
pseq_to_wseq :: forall t a. Num t => t -> Pseq t a -> Wseq t a
pseq_to_wseq t
t0 Pseq t a
sq =
let ([(t, t, t)]
p,[a]
a) = forall a b. [(a, b)] -> ([a], [b])
unzip Pseq t a
sq
([t]
_,[t]
d,[t]
f) = forall a b c. [(a, b, c)] -> ([a], [b], [c])
unzip3 [(t, t, t)]
p
t :: [t]
t = forall a. Num a => a -> [a] -> [a]
T.dx_d t
t0 [t]
f
in forall t a. [t] -> [t] -> [a] -> Wseq t a
wseq_zip [t]
t [t]
d [a]
a
tseq_to_dseq :: (Ord t,Num t) => a -> Tseq t a -> Dseq t a
tseq_to_dseq :: forall t a. (Ord t, Num t) => a -> Tseq t a -> Tseq t a
tseq_to_dseq a
empty Tseq t a
sq =
let ([t]
t,[a]
a) = forall a b. [(a, b)] -> ([a], [b])
unzip Tseq t a
sq
d :: [t]
d = forall a. Num a => [a] -> [a]
T.d_dx [t]
t
in case [t]
t of
[] -> []
t
t0:[t]
_ -> if t
t0 forall a. Ord a => a -> a -> Bool
> t
0 then (t
t0,a
empty) forall a. a -> [a] -> [a]
: forall a b. [a] -> [b] -> [(a, b)]
zip [t]
d [a]
a else forall a b. [a] -> [b] -> [(a, b)]
zip [t]
d [a]
a
tseq_to_dseq_final_dur :: (Ord t,Num t) => a -> t -> Tseq t a -> Dseq t a
tseq_to_dseq_final_dur :: forall t a. (Ord t, Num t) => a -> t -> Tseq t a -> Tseq t a
tseq_to_dseq_final_dur a
empty t
dur Tseq t a
sq =
let ([t]
t,[a]
a) = forall a b. [(a, b)] -> ([a], [b])
unzip Tseq t a
sq
d :: [t]
d = forall a. Num a => [a] -> [a]
T.d_dx [t]
t forall a. [a] -> [a] -> [a]
++ [t
dur]
in case [t]
t of
[] -> []
t
t0:[t]
_ -> if t
t0 forall a. Ord a => a -> a -> Bool
> t
0 then (t
t0,a
empty) forall a. a -> [a] -> [a]
: forall a b. [a] -> [b] -> [(a, b)]
zip [t]
d [a]
a else forall a b. [a] -> [b] -> [(a, b)]
zip [t]
d [a]
a
tseq_to_dseq_total_dur :: (Ord t,Num t) => a -> t -> Tseq t a -> Dseq t a
tseq_to_dseq_total_dur :: forall t a. (Ord t, Num t) => a -> t -> Tseq t a -> Tseq t a
tseq_to_dseq_total_dur a
empty t
dur Tseq t a
sq = forall t a. (Ord t, Num t) => a -> t -> Tseq t a -> Tseq t a
tseq_to_dseq_final_dur a
empty (t
dur forall a. Num a => a -> a -> a
- forall t a. Tseq t a -> t
tseq_end Tseq t a
sq) Tseq t a
sq
tseq_to_wseq :: Num t => Maybe (a -> t) -> Tseq t a -> Wseq t a
tseq_to_wseq :: forall t a. Num t => Maybe (a -> t) -> Tseq t a -> Wseq t a
tseq_to_wseq Maybe (a -> t)
dur_f Tseq t a
sq =
let ([t]
t,[a]
a) = forall a b. [(a, b)] -> ([a], [b])
unzip Tseq t a
sq
d :: [t]
d = case Maybe (a -> t)
dur_f of
Just a -> t
f -> forall a b. (a -> b) -> [a] -> [b]
map a -> t
f (forall a b. (a, b) -> a
fst (forall a. [a] -> ([a], a)
T.separate_last [a]
a))
Maybe (a -> t)
Nothing -> forall a. Num a => [a] -> [a]
T.d_dx [t]
t
in forall t a. [t] -> [t] -> [a] -> Wseq t a
wseq_zip [t]
t [t]
d [a]
a
tseq_to_wseq_iot :: Num t => t -> Tseq t a -> Wseq t a
tseq_to_wseq_iot :: forall t a. Num t => t -> Dseq t a -> Wseq t a
tseq_to_wseq_iot t
total_dur Tseq t a
sq =
let ([t]
t, [a]
e) = forall a b. [(a, b)] -> ([a], [b])
unzip Tseq t a
sq
d :: [t]
d = forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (-) (forall a. [a] -> [a]
tail [t]
t forall a. [a] -> [a] -> [a]
++ [t
total_dur]) [t]
t
in forall a b. [a] -> [b] -> [(a, b)]
zip (forall a b. [a] -> [b] -> [(a, b)]
zip [t]
t [t]
d) [a]
e
tseq_to_iseq :: Num t => Tseq t a -> Iseq t a
tseq_to_iseq :: forall t a. Num t => Tseq t a -> Tseq t a
tseq_to_iseq =
let recur :: t -> [(t, b)] -> [(t, b)]
recur t
n [(t, b)]
p =
case [(t, b)]
p of
[] -> []
(t
t,b
e):[(t, b)]
p' -> (t
t forall a. Num a => a -> a -> a
- t
n,b
e) forall a. a -> [a] -> [a]
: t -> [(t, b)] -> [(t, b)]
recur t
t [(t, b)]
p'
in forall t a. Num t => t -> Dseq t a -> Dseq t a
recur t
0
dseq_to_wseq :: Num t => t -> Dseq t a -> Wseq t a
dseq_to_wseq :: forall t a. Num t => t -> Dseq t a -> Wseq t a
dseq_to_wseq t
t0 Dseq t a
sq =
let ([t]
d,[a]
a) = forall a b. [(a, b)] -> ([a], [b])
unzip Dseq t a
sq
t :: [t]
t = forall a. Num a => a -> [a] -> [a]
T.dx_d t
t0 [t]
d
in forall a b. [a] -> [b] -> [(a, b)]
zip (forall a b. [a] -> [b] -> [(a, b)]
zip [t]
t [t]
d) [a]
a
wseq_to_dseq :: (Num t,Ord t) => a -> Wseq t a -> Dseq t a
wseq_to_dseq :: forall t a. (Num t, Ord t) => a -> Wseq t a -> Dseq t a
wseq_to_dseq a
empty Wseq t a
sq =
let f :: (((a, a), a), ((a, b), b)) -> [(a, a)]
f (((a
st0,a
d),a
e),((a
st1,b
_),b
_)) =
let d' :: a
d' = a
st1 forall a. Num a => a -> a -> a
- a
st0
in case forall a. Ord a => a -> a -> Ordering
compare a
d a
d' of
Ordering
LT -> [(a
d,a
e),(a
d'forall a. Num a => a -> a -> a
-a
d,a
empty)]
Ordering
EQ -> [(a
d,a
e)]
Ordering
GT -> [(a
d',a
e)]
((t
_,t
dN),a
eN) = forall a. [a] -> a
last Wseq t a
sq
r :: [(t, a)]
r = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall {a} {b} {b}.
(Ord a, Num a) =>
(((a, a), a), ((a, b), b)) -> [(a, a)]
f (forall t. Int -> [t] -> [(t, t)]
T.adj2 Int
1 Wseq t a
sq) forall a. [a] -> [a] -> [a]
++ [(t
dN,a
eN)]
in case Wseq t a
sq of
((t
st,t
_),a
_):Wseq t a
_ -> if t
st forall a. Ord a => a -> a -> Bool
> t
0 then (t
st,a
empty) forall a. a -> [a] -> [a]
: [(t, a)]
r else [(t, a)]
r
[] -> forall a. HasCallStack => String -> a
error String
"wseq_to_dseq"
eseq_to_wseq :: Eseq t a -> Wseq t a
eseq_to_wseq :: forall t a. Eseq t a -> Wseq t a
eseq_to_wseq = let f :: ((a, b, c), b) -> ((a, b), b)
f ((a
t, b
d, c
_), b
e) = ((a
t, b
d), b
e) in forall a b. (a -> b) -> [a] -> [b]
map forall {a} {b} {c} {b}. ((a, b, c), b) -> ((a, b), b)
f
dseql_to_tseql :: Num t => t -> [Dseq t a] -> (t,[Tseq t a])
dseql_to_tseql :: forall t a. Num t => t -> [Dseq t a] -> (t, [Dseq t a])
dseql_to_tseql =
let f :: a -> [(a, b)] -> (a, [(a, b)])
f a
z [(a, b)]
dv =
let ([a]
tm,[b]
el) = forall a b. [(a, b)] -> ([a], [b])
unzip [(a, b)]
dv
(a
z',[a]
r) = forall t. Num t => t -> [t] -> (t, [t])
T.dx_d' a
z [a]
tm
in (a
z',forall a b. [a] -> [b] -> [(a, b)]
zip [a]
r [b]
el)
in forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL forall {a} {b}. Num a => a -> [(a, b)] -> (a, [(a, b)])
f
wseq_cycle_ls :: Num t => Wseq t a -> [Wseq t a]
wseq_cycle_ls :: forall t a. Num t => Wseq t a -> [Wseq t a]
wseq_cycle_ls Wseq t a
sq =
let (t
_,t
et) = forall t a. Num t => Wseq t a -> (t, t)
wseq_tspan Wseq t a
sq
t_sq :: [t]
t_sq = forall a. (a -> a) -> a -> [a]
iterate (forall a. Num a => a -> a -> a
+ t
et) t
0
in forall a b. (a -> b) -> [a] -> [b]
map (\t
x -> forall t t' a. ((t, t) -> (t', t')) -> Wseq t a -> Wseq t' a
wseq_tmap (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (forall a. Num a => a -> a -> a
+ t
x)) Wseq t a
sq) [t]
t_sq
wseq_cycle :: Num t => Wseq t a -> Wseq t a
wseq_cycle :: forall t a. Num t => Wseq t a -> Wseq t a
wseq_cycle = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. Num t => Wseq t a -> [Wseq t a]
wseq_cycle_ls
wseq_cycle_n :: Num t => Int -> Wseq t a -> Wseq t a
wseq_cycle_n :: forall t a. Num t => Int -> Wseq t a -> Wseq t a
wseq_cycle_n Int
n = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> [a] -> [a]
take Int
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. Num t => Wseq t a -> [Wseq t a]
wseq_cycle_ls
wseq_cycle_until :: (Num t,Ord t) => t -> Wseq t a -> Wseq t a
wseq_cycle_until :: forall t a. (Num t, Ord t) => t -> Wseq t a -> Wseq t a
wseq_cycle_until t
et = forall t a. Ord t => t -> Wseq t a -> Wseq t a
wseq_until t
et forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t a. Num t => Wseq t a -> Wseq t a
wseq_cycle
dseq_tmap :: (t -> t') -> Dseq t a -> Dseq t' a
dseq_tmap :: forall t1 t2 a. (t1 -> t2) -> [(t1, a)] -> [(t2, a)]
dseq_tmap = forall t1 t2 a. (t1 -> t2) -> [(t1, a)] -> [(t2, a)]
seq_tmap
pseq_tmap :: ((t,t,t) -> (t',t',t')) -> Pseq t a -> Pseq t' a
pseq_tmap :: forall t t' a. ((t, t, t) -> (t', t', t')) -> Pseq t a -> Pseq t' a
pseq_tmap = forall t1 t2 a. (t1 -> t2) -> [(t1, a)] -> [(t2, a)]
seq_tmap
tseq_tmap :: (t -> t') -> Dseq t a -> Dseq t' a
tseq_tmap :: forall t1 t2 a. (t1 -> t2) -> [(t1, a)] -> [(t2, a)]
tseq_tmap = forall t1 t2 a. (t1 -> t2) -> [(t1, a)] -> [(t2, a)]
seq_tmap
tseq_bimap :: (t -> t') -> (e -> e') -> Tseq t e -> Tseq t' e'
tseq_bimap :: forall t1 t2 e1 e2.
(t1 -> t2) -> (e1 -> e2) -> [(t1, e1)] -> [(t2, e2)]
tseq_bimap = forall t1 t2 e1 e2.
(t1 -> t2) -> (e1 -> e2) -> [(t1, e1)] -> [(t2, e2)]
seq_bimap
wseq_tmap :: ((t,t) -> (t',t')) -> Wseq t a -> Wseq t' a
wseq_tmap :: forall t t' a. ((t, t) -> (t', t')) -> Wseq t a -> Wseq t' a
wseq_tmap = forall t1 t2 a. (t1 -> t2) -> [(t1, a)] -> [(t2, a)]
seq_tmap
dseq_map :: (a -> b) -> Dseq t a -> Dseq t b
dseq_map :: forall e1 e2 t. (e1 -> e2) -> [(t, e1)] -> [(t, e2)]
dseq_map = forall e1 e2 t. (e1 -> e2) -> [(t, e1)] -> [(t, e2)]
seq_map
pseq_map :: (a -> b) -> Pseq t a -> Pseq t b
pseq_map :: forall a b t. (a -> b) -> Pseq t a -> Pseq t b
pseq_map = forall e1 e2 t. (e1 -> e2) -> [(t, e1)] -> [(t, e2)]
seq_map
tseq_map :: (a -> b) -> Tseq t a -> Tseq t b
tseq_map :: forall e1 e2 t. (e1 -> e2) -> [(t, e1)] -> [(t, e2)]
tseq_map = forall e1 e2 t. (e1 -> e2) -> [(t, e1)] -> [(t, e2)]
seq_map
wseq_map :: (a -> b) -> Wseq t a -> Wseq t b
wseq_map :: forall a b t. (a -> b) -> Wseq t a -> Wseq t b
wseq_map = forall e1 e2 t. (e1 -> e2) -> [(t, e1)] -> [(t, e2)]
seq_map
dseq_tfilter :: (t -> Bool) -> Dseq t a -> Dseq t a
dseq_tfilter :: forall t a. (t -> Bool) -> [(t, a)] -> [(t, a)]
dseq_tfilter = forall t a. (t -> Bool) -> [(t, a)] -> [(t, a)]
seq_tfilter
iseq_tfilter :: (t -> Bool) -> Iseq t a -> Iseq t a
iseq_tfilter :: forall t a. (t -> Bool) -> [(t, a)] -> [(t, a)]
iseq_tfilter = forall t a. (t -> Bool) -> [(t, a)] -> [(t, a)]
seq_tfilter
pseq_tfilter :: ((t,t,t) -> Bool) -> Pseq t a -> Pseq t a
pseq_tfilter :: forall t a. ((t, t, t) -> Bool) -> Pseq t a -> Pseq t a
pseq_tfilter = forall t a. (t -> Bool) -> [(t, a)] -> [(t, a)]
seq_tfilter
tseq_tfilter :: (t -> Bool) -> Tseq t a -> Tseq t a
tseq_tfilter :: forall t a. (t -> Bool) -> [(t, a)] -> [(t, a)]
tseq_tfilter = forall t a. (t -> Bool) -> [(t, a)] -> [(t, a)]
seq_tfilter
wseq_tfilter :: ((t,t) -> Bool) -> Wseq t a -> Wseq t a
wseq_tfilter :: forall t a. ((t, t) -> Bool) -> Wseq t a -> Wseq t a
wseq_tfilter = forall t a. (t -> Bool) -> [(t, a)] -> [(t, a)]
seq_tfilter
dseq_filter :: (a -> Bool) -> Dseq t a -> Dseq t a
dseq_filter :: forall b a. (b -> Bool) -> [(a, b)] -> [(a, b)]
dseq_filter = forall b a. (b -> Bool) -> [(a, b)] -> [(a, b)]
seq_filter
iseq_filter :: (a -> Bool) -> Iseq t a -> Iseq t a
iseq_filter :: forall b a. (b -> Bool) -> [(a, b)] -> [(a, b)]
iseq_filter = forall b a. (b -> Bool) -> [(a, b)] -> [(a, b)]
seq_filter
pseq_filter :: (a -> Bool) -> Pseq t a -> Pseq t a
pseq_filter :: forall a t. (a -> Bool) -> Pseq t a -> Pseq t a
pseq_filter = forall b a. (b -> Bool) -> [(a, b)] -> [(a, b)]
seq_filter
tseq_filter :: (a -> Bool) -> Tseq t a -> Tseq t a
tseq_filter :: forall b a. (b -> Bool) -> [(a, b)] -> [(a, b)]
tseq_filter = forall b a. (b -> Bool) -> [(a, b)] -> [(a, b)]
seq_filter
wseq_filter :: (a -> Bool) -> Wseq t a -> Wseq t a
wseq_filter :: forall a t. (a -> Bool) -> Wseq t a -> Wseq t a
wseq_filter = forall b a. (b -> Bool) -> [(a, b)] -> [(a, b)]
seq_filter
wseq_map_maybe :: (a -> Maybe b) -> Wseq t a -> Wseq t b
wseq_map_maybe :: forall a b t. (a -> Maybe b) -> Wseq t a -> Wseq t b
wseq_map_maybe = forall p q t. (p -> Maybe q) -> [(t, p)] -> [(t, q)]
seq_map_maybe
wseq_cat_maybes :: Wseq t (Maybe a) -> Wseq t a
wseq_cat_maybes :: forall t a. Wseq t (Maybe a) -> Wseq t a
wseq_cat_maybes = forall t q. [(t, Maybe q)] -> [(t, q)]
seq_cat_maybes
tseq_to_map :: Ord t => Tseq t e -> Map.Map t e
tseq_to_map :: forall t e. Ord t => Tseq t e -> Map t e
tseq_to_map = forall t e. Ord t => Tseq t e -> Map t e
Map.fromList