hmt-0.15: Haskell Music Theory

Safe Haskell | Safe
Language | Haskell98

Music.Theory.Time.Duration

Synopsis

- data Duration = Duration {
  - hours :: Int
  - minutes :: Int
  - seconds :: Int
  - milliseconds :: Int
  }
- s_sms :: (RealFrac n, Integral i) => n -> (i, i)
- sms_s :: Integral i => (i, i) -> Double
- read_duration_tuple :: String -> (Int, Int, Int, Int)
- read_duration :: String -> Duration
- show_duration :: Duration -> String
- normalise_minutes :: Duration -> Duration
- normalise_seconds :: Duration -> Duration
- normalise_milliseconds :: Duration -> Duration
- normalise_duration :: Duration -> Duration
- duration_to_tuple :: (Int -> a) -> Duration -> (a, a, a, a)
- tuple_to_duration :: (a -> Int) -> (a, a, a, a) -> Duration
- duration_to_hours :: Fractional n => Duration -> n
- duration_to_minutes :: Fractional n => Duration -> n
- duration_to_seconds :: Fractional n => Duration -> n
- hours_to_duration :: RealFrac a => a -> Duration
- minutes_to_duration :: RealFrac a => a -> Duration
- seconds_to_duration :: RealFrac a => a -> Duration
- nil_duration :: Duration
- negate_duration :: Duration -> Duration
- duration_diff :: Duration -> Duration -> Duration

# Documentation

data Duration Source #

Duration stored as hours, minutes, seconds and milliseconds.

Constructors

Duration |

Fields

- hours :: Int
- minutes :: Int
- seconds :: Int
- milliseconds :: Int

Instances

Eq Duration Source # |
Methods (==) :: Duration -> Duration -> Bool # (/=) :: Duration -> Duration -> Bool #
Read Duration Source # |
Methods readsPrec :: Int -> ReadS Duration # readList :: ReadS [Duration] # readPrec :: ReadPrec Duration # readListPrec :: ReadPrec [Duration] #
Show Duration Source # |
Methods showsPrec :: Int -> Duration -> ShowS # show :: Duration -> String # showList :: [Duration] -> ShowS #

s_sms :: (RealFrac n, Integral i) => n -> (i, i) Source #

Convert fractional seconds to integral (seconds,milliseconds).

    s_sms 1.75 == (1,750)

sms_s :: Integral i => (i, i) -> Double Source #

Inverse of `s_sms`.

    sms_s (1,750) == 1.75

read_duration_tuple :: String -> (Int, Int, Int, Int) Source #

`Read` function for `Duration` tuple.

read_duration :: String -> Duration Source #

`Read` function for `Duration`. Allows either `H:M:S.MS` or `M:S.MS` or `S.MS`.

    read_duration "01:35:05.250" == Duration 1 35 5 250
    read_duration    "35:05.250" == Duration 0 35 5 250
    read_duration       "05.250" == Duration 0 0 5 250

show_duration :: Duration -> String Source #

`Show` function for `Duration`.

    show_duration (Duration 1 35 5 250) == "01:35:05.250"
    show (Duration 1 15 0 000) == "01:15:00.000"

normalise_minutes :: Duration -> Duration Source #

normalise_seconds :: Duration -> Duration Source #

normalise_milliseconds :: Duration -> Duration Source #

normalise_duration :: Duration -> Duration Source #

duration_to_tuple :: (Int -> a) -> Duration -> (a, a, a, a) Source #

Extract `Duration` tuple applying filter function at each element

    duration_tuple id (Duration 1 35 5 250) == (1,35,5,250)

tuple_to_duration :: (a -> Int) -> (a, a, a, a) -> Duration Source #

Inverse of `duration_to_tuple`.

duration_to_hours :: Fractional n => Duration -> n Source #

duration_to_minutes :: Fractional n => Duration -> n Source #

duration_to_seconds :: Fractional n => Duration -> n Source #

hours_to_duration :: RealFrac a => a -> Duration Source #

minutes_to_duration :: RealFrac a => a -> Duration Source #

seconds_to_duration :: RealFrac a => a -> Duration Source #

nil_duration :: Duration Source #

negate_duration :: Duration -> Duration Source #

duration_diff :: Duration -> Duration -> Duration Source #