hmt-base-0.20: Haskell Music Theory Base
Safe HaskellSafe-Inferred
LanguageHaskell2010

Music.Theory.Time.Duration

Description

Ordinary timing durations, in H:M:S:m (Hours:Minutes:Seconds:milliseconds)

Synopsis

Documentation

data Duration Source #

Duration stored as hours, minutes, seconds and milliseconds.

Constructors

Duration 

Fields

Instances

Instances details
Read Duration Source # 
Instance details

Defined in Music.Theory.Time.Duration

Show Duration Source # 
Instance details

Defined in Music.Theory.Time.Duration

Eq Duration Source # 
Instance details

Defined in Music.Theory.Time.Duration

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. The notation writes seconds fractionally, and allows hours and minutes to be elided if zero.

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. Inverse of read_duration. Hours and minutes are always shown, even if zero.

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

normalise_minutes :: Duration -> Duration Source #

If minutes is not in (0,59) then edit hours.

normalise_seconds :: Duration -> Duration Source #

If seconds is not in (0,59) then edit minutes.

normalise_milliseconds :: Duration -> Duration Source #

If milliseconds is not in (0,999) then edit seconds.

normalise_duration :: Duration -> Duration Source #

Normalise duration so that all parts are in normal ranges.

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

Extract Duration tuple applying filter function at each element

duration_to_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 as fractional hours.

duration_to_hours (read "01:35:05.250") == 1.5847916666666668

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

Duration as fractional minutes.

duration_to_minutes (read "01:35:05.250") == 95.0875

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

Duration as fractional seconds.

duration_to_seconds (read "01:35:05.250") == 5705.25

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

Inverse of duration_to_hours.

hours_to_duration 1.5847916 == Duration 1 35 5 250

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

Inverse of duration_to_minutes.

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

Inverse of duration_to_seconds.

nil_duration :: Duration Source #

Empty (zero) duration.

negate_duration :: Duration -> Duration Source #

Negate the leftmost non-zero element of Duration.

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

Difference between two durations as a duration. Implemented by translation to and from Rational fractional hours.

duration_diff (Duration 1 35 5 250) (Duration 0 25 1 125) == Duration 1 10 4 125
duration_diff (Duration 0 25 1 125) (Duration 1 35 5 250) == Duration (-1) 10 4 125
duration_diff (Duration 0 25 1 125) (Duration 0 25 1 250) == Duration 0 0 0 (-125)