A pitch represents a specific frequency of sound with a letter name, octave, and accidental. E.g. the pitch "B♭4".
Transpose a pitch upward by an interval.
transposeUp Interval.perfectFifth c4 == g4Transpose a pitch downward by an interval.
transposeDown Interval.perfectFifth c4 == f3Get the interval between two pitches:
intervalBetween c4 g4 == Interval.perfectFifthCheck whether two pitches are enharmonic equivalents of each other. Enharmonic equivalents are two pitches with different names but the same sound:
areEnharmonicEquivalents cSharp4 dFlat4 == TrueGet the octave of a pitch:
octave c4 == 4Generate a section of the ascending or descending chromatic scale between two pitches:
chromaticRun a4 d5
== [ a4
, aSharp4
, b4
, c5
, cSharp5
, d5
]Ascending runs use sharps; descending runs use flats:
chromaticRun d5 a4
== [ d5
, dFlat5
, c5
, b4
, bFlat4
, a4
]Distance in semitones from C0. Useful for sorting.
semitones c4 == 48Convert a pitch to a MIDI number:
toMIDINoteNumber c4 == 60Convert a pitch to a frequency in Hertz:
toFrequency c4 == 261.6255653005986A pitch's letter name, accidental, and octave number:
toString cSharp4 == "C♯4"Create a pitch from a pitch class and octave number:
fromPitchClassInOctave 4 c == c4Equivalent pitches can be spelled multiple ways. These functions help with respelling pitches for certain circumstances.
Respell a pitch with at most two accidentals:
bTripleSharp4 =
bSharp4
|> transposeUp Interval.augmentedUnison
|> transposeUp Interval.augmentedUnison
normalize bTripleSharp4
== d5Pitches with three or more accidentals are theoretically possible, but extremely unlikely in practice; most notation software will not support them. This function is a helpful pre-export step if you plan to use pitch data with software in which three or more accidentals are not representable.
Respell a pitch with as few accidentals as possible:
simplify fFlat4
== e4This is helpful in musical idioms like jazz, where simple spellings are preferred.
These are used less frequently in music. Most likely you want a pitch from the previous section.