event-list-0.1.2: Event lists with relative or absolute time stamps

Copyright(c) Henning Thielemann 2007-2010
Maintainerhaskell@henning-thielemann.de
Stabilitystable
PortabilityHaskell 98
Safe HaskellSafe
LanguageHaskell98

Data.EventList.Absolute.TimeBody

Description

 

Synopsis

Documentation

data T time body Source #

Instances

Functor (T time) Source # 

Methods

fmap :: (a -> b) -> T time a -> T time b #

(<$) :: a -> T time b -> T time a #

Foldable (T time) Source # 

Methods

fold :: Monoid m => T time m -> m #

foldMap :: Monoid m => (a -> m) -> T time a -> m #

foldr :: (a -> b -> b) -> b -> T time a -> b #

foldr' :: (a -> b -> b) -> b -> T time a -> b #

foldl :: (b -> a -> b) -> b -> T time a -> b #

foldl' :: (b -> a -> b) -> b -> T time a -> b #

foldr1 :: (a -> a -> a) -> T time a -> a #

foldl1 :: (a -> a -> a) -> T time a -> a #

toList :: T time a -> [a] #

null :: T time a -> Bool #

length :: T time a -> Int #

elem :: Eq a => a -> T time a -> Bool #

maximum :: Ord a => T time a -> a #

minimum :: Ord a => T time a -> a #

sum :: Num a => T time a -> a #

product :: Num a => T time a -> a #

Traversable (T time) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> T time a -> f (T time b) #

sequenceA :: Applicative f => T time (f a) -> f (T time a) #

mapM :: Monad m => (a -> m b) -> T time a -> m (T time b) #

sequence :: Monad m => T time (m a) -> m (T time a) #

(Eq body, Eq time) => Eq (T time body) Source # 

Methods

(==) :: T time body -> T time body -> Bool #

(/=) :: T time body -> T time body -> Bool #

(Ord body, Ord time) => Ord (T time body) Source # 

Methods

compare :: T time body -> T time body -> Ordering #

(<) :: T time body -> T time body -> Bool #

(<=) :: T time body -> T time body -> Bool #

(>) :: T time body -> T time body -> Bool #

(>=) :: T time body -> T time body -> Bool #

max :: T time body -> T time body -> T time body #

min :: T time body -> T time body -> T time body #

(Show body, Show time) => Show (T time body) Source # 

Methods

showsPrec :: Int -> T time body -> ShowS #

show :: T time body -> String #

showList :: [T time body] -> ShowS #

(Num time, Ord time) => Semigroup (T time body) Source # 

Methods

(<>) :: T time body -> T time body -> T time body #

sconcat :: NonEmpty (T time body) -> T time body #

stimes :: Integral b => b -> T time body -> T time body #

(Num time, Ord time) => Monoid (T time body) Source # 

Methods

mempty :: T time body #

mappend :: T time body -> T time body -> T time body #

mconcat :: [T time body] -> T time body #

(Arbitrary time, Arbitrary body) => Arbitrary (T time body) Source # 

Methods

arbitrary :: Gen (T time body) #

shrink :: T time body -> [T time body] #

empty :: T time body Source #

singleton :: time -> body -> T time body Source #

null :: T time body -> Bool Source #

viewL :: T time body -> Maybe ((time, body), T time body) Source #

viewR :: T time body -> Maybe (T time body, (time, body)) Source #

switchL :: c -> ((time, body) -> T time body -> c) -> T time body -> c Source #

switchR :: c -> (T time body -> (time, body) -> c) -> T time body -> c Source #

cons :: time -> body -> T time body -> T time body Source #

snoc :: T time body -> time -> body -> T time body Source #

fromPairList :: [(a, b)] -> T a b Source #

toPairList :: T a b -> [(a, b)] Source #

getTimes :: T time body -> [time] Source #

getBodies :: T time body -> [body] Source #

duration :: Num time => T time body -> time Source #

Duration of an empty event list is considered zero. However, I'm not sure if this is sound.

mapBody :: (body0 -> body1) -> T time body0 -> T time body1 Source #

mapTime :: (time0 -> time1) -> T time0 body -> T time1 body Source #

concatMapMonoid :: Monoid m => (time -> m) -> (body -> m) -> T time body -> m Source #

traverse :: Applicative m => (time0 -> m time1) -> (body0 -> m body1) -> T time0 body0 -> m (T time1 body1) Source #

traverse_ :: Applicative m => (time -> m ()) -> (body -> m ()) -> T time body -> m () Source #

traverseBody :: Applicative m => (body0 -> m body1) -> T time body0 -> m (T time body1) Source #

traverseTime :: Applicative m => (time0 -> m time1) -> T time0 body -> m (T time1 body) Source #

mapM :: Monad m => (time0 -> m time1) -> (body0 -> m body1) -> T time0 body0 -> m (T time1 body1) Source #

mapM_ :: Monad m => (time -> m ()) -> (body -> m ()) -> T time body -> m () Source #

mapBodyM :: Monad m => (body0 -> m body1) -> T time body0 -> m (T time body1) Source #

mapTimeM :: Monad m => (time0 -> m time1) -> T time0 body -> m (T time1 body) Source #

merge :: (Ord time, Ord body) => T time body -> T time body -> T time body Source #

The first important function is merge which merges the events of two lists into a new time order list.

mergeBy :: Ord time => (body -> body -> Bool) -> T time body -> T time body -> T time body Source #

Note that merge compares entire events rather than just start times. This is to ensure that it is commutative, a desirable condition for some of the proofs used in secref{equivalence}. It is also necessary to assert a unique representation of the performance independent of the structure of the 'Music.T note'. The same function for inserting into a time ordered list with a trailing pause. The strictness annotation is necessary for working with infinite lists.

Here are two other functions that are already known for non-padded time lists.

insert :: (Ord time, Ord body) => time -> body -> T time body -> T time body Source #

The final critical function is insert, which inserts an event into an already time-ordered sequence of events. For instance it is used in MidiFiles to insert a NoteOff event into a list of NoteOn and NoteOff events.

insertBy :: Ord time => (body -> body -> Bool) -> time -> body -> T time body -> T time body Source #

moveForward :: (Ord time, Num time) => T time (time, body) -> T time body Source #

Move events towards the front of the event list. You must make sure, that no event is moved before time zero. This works only for finite lists.

decreaseStart :: (Ord time, Num time) => time -> T time body -> T time body Source #

delay :: (Ord time, Num time) => time -> T time body -> T time body Source #

filter :: Num time => (body -> Bool) -> T time body -> T time body Source #

partition :: (body -> Bool) -> T time body -> (T time body, T time body) Source #

partitionMaybe :: (body0 -> Maybe body1) -> T time body0 -> (T time body1, T time body0) Source #

slice :: Eq a => (body -> a) -> T time body -> [(a, T time body)] Source #

Since we need it later for MIDI generation, we will also define a slicing into equivalence classes of events.

foldr :: (time -> a -> b) -> (body -> b -> a) -> b -> T time body -> b Source #

foldrPair :: (time -> body -> a -> a) -> a -> T time body -> a Source #

mapMaybe :: Num time => (body0 -> Maybe body1) -> T time body0 -> T time body1 Source #

catMaybes :: Num time => T time (Maybe body) -> T time body Source #

normalize :: (Ord time, Num time, Ord body) => T time body -> T time body Source #

sort sorts a list of coinciding events, that is all events but the first one have time difference 0. normalize sorts all coinciding events in a list thus yielding a canonical representation of a time ordered list.

isNormalized :: (Ord time, Num time, Ord body) => T time body -> Bool Source #

collectCoincident :: Eq time => T time body -> T time [body] Source #

We will also sometimes need a function which groups events by equal start times. This implementation is not so obvious since we work with time differences. The criterion is: Two neighbouring events start at the same time if the second one has zero time difference.

flatten :: Ord time => T time [body] -> T time body Source #

mapCoincident :: Ord time => ([a] -> [b]) -> T time a -> T time b Source #

Apply a function to the lists of coincident events.

append :: (Ord time, Num time) => T time body -> T time body -> T time body Source #

concat :: (Ord time, Num time) => [T time body] -> T time body Source #

cycle :: (Ord time, Num time) => T time body -> T time body Source #

discretize :: (RealFrac time, Integral i) => T time body -> T i body Source #

Here are some functions for discretizing the time information. When converting the precise relative event times to the integer relative event times we have to prevent accumulation of rounding errors. We avoid this problem with a stateful conversion which remembers each rounding error we make. This rounding error is used to correct the next rounding. Given the relative time and duration of a note the function discretizeEventM creates a State which computes the rounded relative time. It is corrected by previous rounding errors.

The resulting event list may have differing time differences which were equal before discretization, but the overall timing is uniformly close to the original.

resample :: (RealFrac time, Integral i) => time -> T time body -> T i body Source #

checkTimes :: Ord time => T time body -> T time body Source #

Check whether time values are in ascending order. The list is processed lazily and times that are smaller than there predecessors are replaced by undefined. If you would remove the undefined times from the resulting list the times may still not be ordered. E.g. consider the time list [0,3,1,2]

collectCoincidentFoldr :: Eq time => T time body -> T time [body] Source #

collectCoincidentNonLazy :: Eq time => T time body -> T time [body] Source #

Will fail on infinite lists.