duncanmalashock / elm-music-theory / Music.Interval

An interval is a measure of the distance between two pitches. E.g. a "perfect fifth".


type alias Interval =
Music.Internal.Interval.Interval

betweenPitches : Music.Internal.Pitch.Pitch -> Music.Internal.Pitch.Pitch -> Interval

Get the interval between two pitches:

betweenPitches Pitch.c4 Pitch.g4 == perfectFifth

Comparison

isEqualTo : Interval -> Interval -> Basics.Bool

Check whether two intervals are equivalent:

isEqualTo augmentedFourth diminishedFifth == True

isGreaterThan : Interval -> Interval -> Basics.Bool

Check whether the distance of one interval is greater than another:

isGreaterThan perfectFifth perfectUnison == True

isLessThan : Interval -> Interval -> Basics.Bool

Check whether the distance of one interval is less than another:

isLessThan perfectFifth perfectUnison == False

Operations

add : Interval -> Interval -> Interval

Add two intervals together:

add majorSecond majorThird == augmentedFourth

subtract : Interval -> Interval -> Interval

Subtract two intervals:

subtract majorSecond minorThird == minorSecond

simplify : Interval -> Interval

Convert any interval to its simple form. A simple interval is one that spans an octave or less.

simplify majorThirteenth == majorSixth

addOctave : Interval -> Interval

Add an octave to an interval:

addOctave majorSecond == majorNinth

Direction

Intervals have direction: a perfect fifth up is different from a perfect fifth down.

reverse : Interval -> Interval

Reverse the direction of an interval

isUp : Interval -> Basics.Bool

Find out whether an interval is in the "up" direction:

isUp majorThird == True

isDown : Interval -> Basics.Bool

Find out whether an interval is in the "down" direction:

isDown (reverse majorThird) == True

Conversion

semitones : Interval -> Basics.Int

Get the number of semitones an interval spans:

semitones majorThird == 4

toString : Interval -> String

Get the short name of an interval:

toString perfectFifth == "P5"

Intervals in the "down" direction are shown with a negative sign:

toString (reverse perfectFifth) == "-P5"

Ranges


type alias Range =
{ min : Music.Internal.Interval.Interval
, max : Music.Internal.Interval.Interval 
}

range : Interval -> Interval -> Range

Create a range of intervals:

range perfectUnison perfectFifth
    == { min = perfectUnison
       , max = perfectFifth
       }

Constructors

Simple intervals

Diatonic

perfectUnison : Interval

minorSecond : Interval

majorSecond : Interval

minorThird : Interval

majorThird : Interval

perfectFourth : Interval

perfectFifth : Interval

minorSixth : Interval

majorSixth : Interval

minorSeventh : Interval

majorSeventh : Interval

perfectOctave : Interval

Chromatic

augmentedUnison : Interval

augmentedSecond : Interval

augmentedThird : Interval

augmentedFourth : Interval

augmentedFifth : Interval

augmentedSixth : Interval

augmentedSeventh : Interval

diminishedSecond : Interval

diminishedThird : Interval

diminishedFourth : Interval

diminishedFifth : Interval

diminishedSixth : Interval

diminishedSeventh : Interval

diminishedOctave : Interval

Compound intervals

Note: This module includes constructors for compound intervals up to the thirteenth, which is the highest interval found in standard chords in tonal music. If you need larger compound intervals, take a look at the add or addOctave helper functions in this module.

Diatonic

minorNinth : Interval

majorNinth : Interval

minorTenth : Interval

majorTenth : Interval

perfectEleventh : Interval

perfectTwelfth : Interval

minorThirteenth : Interval

majorThirteenth : Interval

Chromatic

augmentedOctave : Interval

augmentedNinth : Interval

augmentedEleventh : Interval

augmentedTwelfth : Interval

diminishedTwelfth : Interval