duncanmalashock/elm-music-theory/1.0.0

Music.Interval

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

type alias Interval =
Interval
betweenPitches : Pitch -> Pitch -> Interval

Get the interval between two pitches:

betweenPitches Pitch.c4 Pitch.g4 == perfectFifth

Comparison

isEqualTo : Interval -> Interval -> Bool

Check whether two intervals are equivalent:

isEqualTo augmentedFourth diminishedFifth == True
isGreaterThan : Interval -> Interval -> Bool

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

isGreaterThan perfectFifth perfectUnison == True
isLessThan : Interval -> Interval -> 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 -> Bool

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

isUp majorThird == True
isDown : Interval -> Bool

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

isDown (reverse majorThird) == True

Conversion

semitones : Interval -> 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 : Interval
, max : 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
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
augmentedTwelfth : Interval