music-pitch-1.3: Abstract representation of musical pitch.

Safe HaskellNone

Music.Pitch.Relative.Interval

Contents

Synopsis

Intervals

data Interval Source

An interval is the difference between two pitches, incuding negative intervals.

Intervals and pitches can be added using .+^. To get the interval between two pitches, use .-..

 c .+^ minor third == eb
 f .-. c           == perfect fourth

Adding intervals preserves spelling. For example:

 m3 ^+^ _M3 = _P5
 d5 ^+^ _M6 = m10

The scalar type of intervals are Integer, using ^* to stack intervals of a certain type on top of each other. For example _P5 ^* 2 is a stack of 2 perfect fifths. The Num instance works as expected for +, negate and abs, and arbitrarily uses octaves for multiplication. If you find yourself *, or signum on intervals, consider switching to ^* or normalized.

Intervals are generally described in terms of Quality and Number. To construct an interval, use the interval constructor, the utility constructors major, minor, augmented and diminished, or the interval literals:

 m5  == minor   fifth    == interval Minor   5
 _P4 == perfect fourth   == interval Perfect 5
 d5  == diminished fifth == diminish (perfect fifth)

Creating intervals

interval :: Quality -> Number -> IntervalSource

Creates an interval from a quality and number.

If given Perfect with an imperfect number (such as 3 or 7) a major interval is returned. If given Major or Minor with a perfect number (such as 5), constructs a perfect or diminished interval respectively.

perfect :: Number -> IntervalSource

Creates a perfect interval. If given an inperfect number, constructs a major interval.

major :: Number -> IntervalSource

Creates a major interval. If given a perfect number, constructs a perfect interval.

minor :: Number -> IntervalSource

Creates a minor interval. If given a perfect number, constructs a diminished interval.

augmented :: Number -> IntervalSource

Creates an augmented interval.

diminished :: Number -> IntervalSource

Creates a diminished interval.

doublyAugmented :: Number -> IntervalSource

Creates a doubly augmented interval.

doublyDiminished :: Number -> IntervalSource

Creates a doubly diminished interval.

Inspecting intervals

number :: Interval -> NumberSource

Returns the number portion of an interval.

The interval number is negative if and only if the interval is negative.

See also quality, octaves and semitones.

isPositive :: Interval -> BoolSource

Returns whether the given interval is positive.

isNegative :: Interval -> BoolSource

Returns whether the given interval is negative.

Simple and compound intervals

isSimple :: Interval -> BoolSource

Returns whether the given interval is simple.

A simple interval is an positive interval spanning less than one octave.

isCompound :: Interval -> BoolSource

Returns whether the given interval is compound.

A compound interval is either a negative interval, or a positive interval spanning more than octave.

separate :: Interval -> (Octaves, Interval)Source

Separate a compound interval into octaves and a simple interval.

 (perfect octave)^*x + y = z  iff  (x, y) = separate z

simple :: Interval -> IntervalSource

Returns the simple part of an interval.

 (perfect octave)^*x + y = z  iff  y = simple z

Inversion

invert :: Interval -> IntervalSource

Intervallic inversion.

The inversion of a simple interval is determined by the following rules:

  • The interval number and the number of its inversion always add up to nine (i.e. 4 + 5 = 9).
  • The inversion of a major interval is a minor interval, and vice versa; the inversion of a perfect interval is also perfect; the inversion of an augmented interval is a diminished interval, and vice versa; the inversion of a doubly augmented interval is a doubly diminished interval, and vice versa.

The inversion of any compound interval is always the same as the inversion of the simple interval from which it is compounded, i.e.:

 invert = simple . negate

Utility

Spelling

Literals (TODO move)