Copyright | (c) Hans Hoglund 2012-2014 |
---|---|

License | BSD-style |

Maintainer | hans@hanshoglund.se |

Stability | experimental |

Portability | non-portable (TF,GNTD) |

Safe Haskell | None |

Language | Haskell2010 |

- data Time
- data Duration
- type LocalDuration = Duration
- offsetPoints :: AffineSpace p => p -> [Diff p] -> [p]
- pointOffsets :: AffineSpace p => p -> [p] -> [Diff p]
- toAbsoluteTime :: [Duration] -> [Time]
- toRelativeTime :: [Time] -> [Duration]
- toRelativeTimeN :: [Time] -> [Duration]
- toRelativeTimeN' :: Time -> [Time] -> [Duration]
- data Span
- (<->) :: Time -> Time -> Span
- (>->) :: Time -> Duration -> Span
- (<-<) :: Duration -> Time -> Span
- delta :: Iso' Span (Time, Duration)
- range :: Iso' Span (Time, Time)
- codelta :: Iso' Span (Duration, Time)
- stretchComponent :: Span -> Duration
- delayComponent :: Span -> Time
- fixedDurationSpan :: Prism' Span Time
- fixedOnsetSpan :: Prism' Span Duration
- normalizeSpan :: Span -> Span
- reverseSpan :: Span -> Span
- reflectSpan :: Time -> Span -> Span
- isEmptySpan :: Span -> Bool
- isForwardSpan :: Span -> Bool
- isBackwardSpan :: Span -> Bool
- inside :: Time -> Span -> Bool
- encloses :: Span -> Span -> Bool
- properlyEncloses :: Span -> Span -> Bool
- overlaps :: Span -> Span -> Bool
- isBefore :: Span -> Span -> Bool
- afterOnset :: Time -> Span -> Bool
- strictlyAfterOnset :: Time -> Span -> Bool
- beforeOnset :: Time -> Span -> Bool
- strictlyBeforeOnset :: Time -> Span -> Bool
- afterOffset :: Time -> Span -> Bool
- strictlyAfterOffset :: Time -> Span -> Bool
- beforeOffset :: Time -> Span -> Bool
- strictlyBeforeOffset :: Time -> Span -> Bool
- startsWhenStarts :: Span -> Span -> Bool
- startsWhenStops :: Span -> Span -> Bool
- stopsWhenStops :: Span -> Span -> Bool
- stopsWhenStarts :: Span -> Span -> Bool
- startsBefore :: Span -> Span -> Bool
- startsLater :: Span -> Span -> Bool
- stopsAtTheSameTime :: Span -> Span -> Bool
- stopsBefore :: Span -> Span -> Bool
- stopsLater :: Span -> Span -> Bool
- showRange :: Span -> String
- showDelta :: Span -> String
- showCodelta :: Span -> String

# Basic types

`Time`

represents points in time space. The difference between two time points
is a `Duration`

, for example in a bar of duration 4/4 (that is 1), the difference
between the first and third beat 1/2.

Time has an origin (zero) which usually represents the beginning of the musical
performance, but this may not always be the case, as the modelled music may be
infinite, or contain a musical pickup. Hence `Time`

values can be negative.

Duration, corresponding to note values in standard notation.
The standard names can be used: `1/2`

for half note `1/4`

for a quarter note and so on.

type LocalDuration = Duration Source

## Convert between time and duration

Note that you should use `.-.`

and `.+^`

to convert between time and
duration. To refer to time zero (the beginning of the music), use
`origin`

.

offsetPoints :: AffineSpace p => p -> [Diff p] -> [p] Source

Lay out a series of vectors from a given point. Return all intermediate points.

lenght xs + 1 == length (offsetPoints p xs)

`>>>`

[0,1,2,3]`offsetPoints 0 [1,1,1] :: [Time]`

pointOffsets :: AffineSpace p => p -> [p] -> [Diff p] Source

Calculate the relative difference between vectors.

lenght xs + 1 == length (offsetPoints p xs)

`>>>`

[0,1,2,3]`offsetPoints 0 [1,1,1] :: [Time]`

toAbsoluteTime :: [Duration] -> [Time] Source

Interpret as durations from 0.

toAbsoluteTime (toRelativeTime xs) == xs

lenght xs == length (toRelativeTime xs)

`>>>`

[1,2,3]`toAbsoluteTime [1,1,1] :: [Time]`

toRelativeTime :: [Time] -> [Duration] Source

Duration between 0 and first value and so on until the last.

toAbsoluteTime (toRelativeTime xs) == xs

lenght xs == length (toRelativeTime xs)

`>>>`

[1,1,1]`toRelativeTime [1,2,3]`

toRelativeTimeN :: [Time] -> [Duration] Source

toRelativeTimeN' :: Time -> [Time] -> [Duration] Source

Duration between values until the last, then up to the given final value. > lenght xs == length (toRelativeTime xs)

# Time spans

## Constructing spans

stretchComponent :: Span -> Duration Source

Access the stretch component in a span.

delayComponent :: Span -> Time Source

Access the delay component in a span.

fixedDurationSpan :: Prism' Span Time Source

A prism to the subset of `Span`

that performs a delay but no stretch.

fixedOnsetSpan :: Prism' Span Duration Source

A prism to the subset of `Span`

that performs a stretch but no delay.

## Transformations

normalizeSpan :: Span -> Span Source

Normalize a span, i.e. reverse it if negative, and do nothing otherwise.

_duration s = _duration (normalizeSpan s) _midpoint s = _midpoint (normalizeSpan s)

reverseSpan :: Span -> Span Source

Reflect a span through its midpoint.

reflectSpan :: Time -> Span -> Span Source

Reflect a span through an arbitrary point.

## Properties

isEmptySpan :: Span -> Bool Source

Whether the given span is empty, i.e. whether its `onset`

and `offset`

are equivalent.

isForwardSpan :: Span -> Bool Source

Whether the given span has a positive duration, i.e. whether its `onset`

is before its `offset`

.

isBackwardSpan :: Span -> Bool Source

Whether the given span has a negative duration, i.e. whether its `offset`

is before its `onset`

.

## Points in spans

inside :: Time -> Span -> Bool infixl 5 Source

Whether the given point falls inside the given span (inclusively).

Designed to be used infix, for example

`>>>`

False`0.5 `inside` 1 <-> 2`

`>>>`

True`1.5 `inside` 1 <-> 2`

`>>>`

True`1 `inside` 1 <-> 2`

## Partial orders

encloses :: Span -> Span -> Bool infixl 5 Source

Whether the first given span encloses the second span.

`>>>`

True`0 <-> 3 `encloses` 1 <-> 2`

`>>>`

True`0 <-> 2 `encloses` 1 <-> 2`

`>>>`

True`1 <-> 3 `encloses` 1 <-> 2`

`>>>`

True`1 <-> 2 `encloses` 1 <-> 2`

properlyEncloses :: Span -> Span -> Bool infixl 5 Source

Whether the first given span encloses the second span.

`>>>`

True`0 <-> 3 `properlyEncloses` 1 <-> 2`

`>>>`

True`0 <-> 2 `properlyEncloses` 1 <-> 2`

`>>>`

True`1 <-> 3 `properlyEncloses` 1 <-> 2`

`>>>`

False`1 <-> 2 `properlyEncloses` 1 <-> 2`

### etc.

afterOnset :: Time -> Span -> Bool Source

strictlyAfterOnset :: Time -> Span -> Bool Source

beforeOnset :: Time -> Span -> Bool Source

strictlyBeforeOnset :: Time -> Span -> Bool Source

afterOffset :: Time -> Span -> Bool Source

strictlyAfterOffset :: Time -> Span -> Bool Source

beforeOffset :: Time -> Span -> Bool Source

strictlyBeforeOffset :: Time -> Span -> Bool Source

startsWhenStarts :: Span -> Span -> Bool Source

startsWhenStops :: Span -> Span -> Bool Source

stopsWhenStops :: Span -> Span -> Bool Source

stopsWhenStarts :: Span -> Span -> Bool Source

startsBefore :: Span -> Span -> Bool Source

startsLater :: Span -> Span -> Bool Source

stopsAtTheSameTime :: Span -> Span -> Bool Source

stopsBefore :: Span -> Span -> Bool Source

stopsLater :: Span -> Span -> Bool Source

## Read/Show

showCodelta :: Span -> String Source

Show a span in codelta notation, i.e. `t <-< d`

.