MusicTheory Docs API Toolbox GitHub NuGet
Contents

API / MusicTheory

Interval record

A spelled, directed interval: a quality, a number (1 = unison, 8 = octave, 9 and up are compound) and a direction on the staff. A major 3rd and a diminished 4th both span 4 semitones but are different intervals.
Names follow music21: M3, P5, dd2, AAAA1, and a descending interval writes its direction before the number, M-3. A unison has no direction on the staff: d1 lowers a note, A1 raises it.

Constructors

Interval(IntervalQuality quality, int number, Direction direction = Direction.Up)
Creates an interval.
quality
The quality; perfect for 1, 4, 5 and their compounds, minor or major for the others.
number
The number, 1 or more.
direction
Up (default) or down; a unison is always up.

Throws ArgumentOutOfRangeException A number below 1, an undefined quality or direction, a quality that does not exist for that number (a perfect 3rd, a major 5th), or a descending unison.

Properties

IntervalQuality Quality { get; }
The quality.
int Number { get; }
The number: 1 for a unison, 8 for an octave, 9 for a ninth (compound 2nd), and so on.
Direction Direction { get; }
Up or down the staff. Always Direction.Up for a unison.
int Semitones { get; }
The size in semitones, ignoring direction: 4 for a major 3rd, 6 for both A4 and d5, 14 for a major 9th. Negative only for intervals narrower than nothing: a diminished unison is −1, a doubly diminished 2nd −1.
bool IsCompound { get; }
True for intervals wider than an octave (9ths and up).
bool IsAugmented { get; }
True for any degree of augmented.
bool IsDiminished { get; }
True for any degree of diminished.
string Name { get; }
The name without direction: M3, P8, dd2.
int DirectedSemitones { get; }
Semitones with the direction's sign: 4 for M3, −4 for M-3, −1 for d1.

Methods

static Interval Between(Note from, Note to)
The interval from from to to. The number counts letters and the direction follows the staff, so C4→F##4 is a doubly augmented 4th (AA4), E4→C4 is a descending major 3rd (M-3) and C4→B#3 a descending diminished 2nd (d-2) of 0 semitones. Never throws for two notes.

Throws ArgumentNullException A note is null.

Interval Invert()
The inversion, keeping direction: the numbers add up to 9 and the quality mirrors (M ↔ m, A ↔ d, AA ↔ dd, P stays). Compound intervals are reduced first (M10 inverts to m6).
bool IsEnharmonicWith(Interval? other)
True when both intervals move by the same number of semitones in the same direction (A4 and d5).
static Interval Parse(string text)
Parses a music21-style name: quality letters (P, M, m, d…ddddd, A…AAAAA), an optional - for a descending interval, and the number: M3, P-5, dd2, m9.

Throws FormatException The text is not an interval.

Interval Reverse()
The same interval in the other direction; a unison mirrors instead (A1 ↔ d1, P1 stays).
Interval ToSimple()
The interval reduced to an octave or less, keeping quality and direction: M9 → M2, P15 → P8, P8 stays.
string ToString()
The directed name: M3 up, M-3 down.
static bool TryParse(string? text, out Interval? interval)
Tries to parse an interval; see Interval.Parse. Never throws.