Spelled Pitch
Overview
Spelled pitches and intervals are the standard types of the Western music notation system. Unlike MIDI pitches, spelled pitches distinguish between enharmonically equivalent pitches such as E♭
and D♯
. Similarly, spelled intervals distinguish between intervals such as m3
(minor 3rd) and a2
(augmented second) that would be equivalent in the MIDI system.
The easiest way to use spelled pitches and intervals is to use the string macros i
(for intervals) and p
(for pitches), which parse a string in a standard notation that corresponds to how spelled pitches and intervals are printed. For parsing these representations programmatically, use parsespelled
and parsespelledpitch
for intervals and pitches, respectively. Spelled pitch classes are represented by an uppercase letter followed by zero or more accidentals, which can be either written as b/#
or as ♭/♯
. Spelled pitches take an additional octave number after the letter and the accidentals.
julia> p"Eb"
E♭
julia> parsespelledpitch("Eb")
E♭
julia> typeof(p"Eb")
Pitch{SpelledIC}
julia> p"Eb4"
E♭4
julia> typeof(p"Eb4")
Pitch{SpelledInterval}
Spelled interval classes consist of one or more letters that indicate the quality of the interval and a number between 1 and 7 that indicates the generic interval, e.g. P1
for a perfect unison, m3
for a minor 3rd or aa4
for a double augmented 4th.
letter | quality |
---|---|
dd... | diminished multiple times |
d | diminished |
m | minor |
P | perfect |
M | major |
a | augmented |
aa... | augmented multiple times |
Spelled intervals have the same elements as intervals but additionally take a number of octaves, written a suffix :n
, e.g. P1:0
or m3:20
. By default, intervals are directed upwards. Downwards intervals are indicated by a negative sign, e.g. -M2:1
(a major 9th down). For interval classes, downward and upward intervals cannot be distinguish, so a downward interval is represented by its complementary upward interval:
julia> i"-M3"
m6
julia> -i"M3"
m6
Representations of Spelled Intervals
Fifths and Octaves
Internally, spelled intervals are represented by, 5ths and octaves. Both dimensions are logically dependent: a major 2nd up is represented by going two 5ths up and one octave down.
julia> spelled(2,-1) # two 5ths, one octave
M2:0
This representation is convenient for arithmetics, which can usually be done component-wise. However, special care needs to be taken when converting to other representations. For example, the notated octave number (e.g. :0
in i"M2:0"
) does not correspond to the internal octaves of the interval (-1 in this case). In the notation, the interval class (M2
) and the octave (:0
) are independent.
Interpreting the "internal" (or dependent) octave dimension of the interval does not make much sense without looking at the fifths. Therefore, the function octaves
returns the "external" (or independent) octaves as used in the string representation, e.g.
julia> octaves(i"M2:0")
0
julia> octaves(i"M2:1")
1
julia> octaves(i"M2:-1")
-1
If you want to look at the internal octaves, use internalocts
. This corresponds to looking at the .octaves
field, but works on interval classes too.
Diatonic Steps and Alterations
We provide a number of convenience functions to derive other properties from this representation. The generic interval (i.e. the number of diatonic steps) can be obtained using generic
. generic
respects the direction of the interval but is limitied to a single octave (0 to ±6). If you need the total number of diatonic steps, including octaves, use diasteps
. The function degree
returns the scale degree implied by the interval relative to some root. Since scale degrees are always above the root, degree
, it treats negative intervals like their positive complements:
julia> Pitches.generic(Pitches.i"-M3:1") # some kind of 3rd down
-2
julia> Pitches.diasteps(Pitches.i"-M3:1") # a 10th down
-9
julia> Pitches.degree(Pitches.i"-M3:1") # scale degree VI
5
For interval classes, all three functions are equivalent. Note that all three count from 0 (for unison/I), not 1.
Complementary to the generic interval functions, alteration
returns the specific quality of the interval. For perfect or major intervals, it returns 0
. Larger absolute intervals return positive values, smaller intervals return negative values.
degree
and alteration
also work on pitches. degree(p)
returns an integer corresponding to the letter (C=0
, D=1
, ...), while alteration(p)
provides the accidentals (natural=0
, sharps -> positive, flats -> negative). For convenience, letter(p)
returns the letter as an uppercase character.
Reference
Types
Pitches.SpelledInterval
— TypeSpelledInterval <: Interval
Spelled intervals represented as pairs of fifths and octaves. E.g., SpelledInterval(-3, 2)
represents a minor 3rd upwards (3 fifths down, 2 octaves up).
Pitches.SpelledIC
— TypeSpelledIC <: IntervalClass
Spelled interval class represented on the line of 5ths with 0 = C
. E.g., SpelledIC(3)
represents a major 6th upwards or minor 3rd downwards (i.e., three 5ths up modulo octave).
Constructors
Pitches.spelled
— Functionspelled(fifths, octaves)
Creates a spelled interval from fifths
and octaves
.
Pitches.spelledp
— Functionspelledp(fifths, octaves)
Creates a spelled pitch from fifths
and octaves
.
Pitches.sic
— Functionsic(fifths)
Creates a spelled interval class going fifths
5ths upwards.
Pitches.spc
— Functionspc(fifths)
Creates a spelled pitch class. In analogy to sic
, this function takes a number of 5ths.
Pitches.@i_str
— Macroi"str"
Parse a spelled interval or interval class string. The type is determined from the string, so i"M3:0"
returns an interval while i"M3"
returns an interval class.
See also: @p_str
, parsespelled
, parsespelledpitch
.
Pitches.@p_str
— Macrop"str"
Parse a spelled pitch or pitch class string. The type is determined from the string, so p"G4"
returns a pitch while p"G"
returns a pitch class.
See also: @i_str
, parsespelledpitch
, parsespelled
.
Pitches.parsespelled
— Functionparsespelled(str)
Parse a spelled interval or interval class string. The type is determined from the string, so i"M3:0"
returns an interval while i"M3"
returns an interval class.
See also: @i_str
, parsespelledpitch
.
Pitches.parsespelledpitch
— Functionparsespelledpitch(str)
Parse a spelled pitch or pitch class string. The type is determined from the string, so p"G4"
returns a pitch while p"G"
returns a pitch class.
See also: @p_str
, parsespelled
.
Other Special Functions
Pitches.octaves
— Functionoctaves(i)
octaves(p)
Return the number of octaves the interval spans. Positive intervals start at 0 octaves, increasing. Negative intervals start at -1 octaves, decreasing. (You might want to use octaves(abs(i))
instead).
For a pitch, return its octave.
Pitches.internalocts
— Functioninternalocts(i)
Return the internal octaves (i.e. dependent on the 5ths dimension) of an interval.
Pitches.fifths
— Functionfifths(i)
fifths(p)
Return the octave-invariant part of the interval in fifths (unison=0
, 5th up=1
, 4th up/5th down=-1
). For a pitch, return the pitch class on the line of fifths.
Pitches.degree
— Functiondegree(i)
degree(p)
Return the "relative scale degree" (0-6) to which the interval points (unison=0
, 2nd=1
, octave=0
, 2nd down=6
, etc.). For pitches, return the integer that corresponds to the letter (C=0
, D=1
, ...).
Pitches.generic
— Functiongeneric(i)
Return the generic interval, i.e. the number of diatonic steps modulo octave. Unlike degree
, the result respects the sign of the interval (unison=0
, 2nd up=1
, 2nd down=-1
). For pitches, use degree
.
Pitches.diasteps
— Functiondiasteps(i)
Return the diatonic steps of the interval (unison=0
, 2nd=1
, ..., octave=7
). Respects both direction and octaves.
Pitches.alteration
— Functionalteration(i)
alteration(p)
Return the number of semitones by which the interval is altered from its the perfect or major variant. Positive alteration always indicates augmentation, negative alteration indicates diminution (minor or smaller) of the interval. For interval classes, the alteration always corresponds to the upward version of the interval. For pitches, return the accidentals (positive=sharps, negative=flats, 0
=natural).
Pitches.letter
— Function