MusicTheory Docs API Toolbox GitHub NuGet
Contents

API / MusicTheory

Note record

A spelled pitch: a letter, an accidental and an octave in scientific pitch notation (middle C is C4). Two notes are equal when all three match, so C#4 and Db4 are different notes that are enharmonic (Note.IsEnharmonicWith).

Constructors

Note(NoteName name, Alteration alteration = Alteration.Natural, int octave = 4)
Creates a note.
name
The letter.
alteration
The accidental, natural by default.
octave
The octave, 4 by default.

Throws ArgumentOutOfRangeException An undefined letter or accidental, or an octave outside Note.MinOctave..Note.MaxOctave.

Properties

NoteName Name { get; }
The letter.
Alteration Alteration { get; }
The accidental.
int Octave { get; }
The octave, from Note.MinOctave to Note.MaxOctave. Middle C is in octave 4.
int PitchClass { get; }
The pitch class, 0 (C) to 11 (B), octave ignored: B# is 0, Cb is 11.
double Frequency { get; }
The frequency in Hz in twelve-tone equal temperament at concert pitch (A4 = 440 Hz).
int MidiNumber { get; }
The MIDI note number: C4 (middle C) is 60.

Throws InvalidOperationException The note is outside MIDI's 0..127.

Fields

const int MinOctave = -1
The lowest octave a note may have (C-1 is MIDI 0).
const int MaxOctave = 9
The highest octave a note may have (G9 is MIDI 127).
const double StandardA4 = 440
Concert pitch: A4 = 440 Hz.

Methods

static TunedPitch FromFrequency(double hz, double a4 = 440, bool preferFlats = false)
The nearest 12-TET note to hz and the deviation in cents, in [-50, +50): an exact quarter tone above a note reads as the next note at -50. Spelled like Note.FromMidiNumber.
hz
The measured frequency in Hz.
a4
The frequency of A4 in Hz.
preferFlats
Spell black keys with flats instead of sharps.

Throws ArgumentOutOfRangeException hz or a4 is not a positive, finite number, or the nearest note is outside MIDI's 0..127.

static Note FromMidiNumber(int midiNumber, bool preferFlats = false)
The note for a MIDI number. Black keys are C#, Eb, F#, Ab, Bb by default, or Db, Eb, Gb, Ab, Bb with preferFlats.

Throws ArgumentOutOfRangeException midiNumber is outside 0..127.

IEnumerable<Note> GetAllEnharmonicEquivalents()
Every other spelling of this pitch with at most two accidentals: C4 gives B#3 and Dbb4.
Note? GetEnharmonicEquivalent()
The usual alternative spelling of this pitch: C# ↔ Db, E ↔ Fb, B# → C, C## → D, Cbb → Bb. Null for D, G and A, which have no common alternative.
double GetFrequency(double a4 = 440)
The frequency in Hz in twelve-tone equal temperament, tuned to a4: 442 for many orchestras, 415 for baroque pitch.
a4
The frequency of A4 in Hz.

Throws ArgumentOutOfRangeException a4 is not a positive, finite number.

string GetName(AccidentalStyle style = AccidentalStyle.Ascii)
The note name without octave, e.g. Bb or (Unicode) B♭.
bool IsEnharmonicWith(Note? other)
True when other sounds the same pitch: C#4 and Db4, B#3 and C4. Notes an octave apart are not enharmonic.
static Note Parse(string noteString)
Parses a note in English notation: a letter in any case, up to two accidentals in ASCII (#, b) or Unicode (♯ ♭ 𝄪 𝄫), and an optional octave (default 4), e.g. C#4, Bb3, F##, B♭.

Throws FormatException The text is not a note.

static Note Parse(string noteString, NoteNotation notation)
Parses a note in the given notation; see NoteNotation.

Throws FormatException The text is not a note in that notation.

Note? Respell(NoteName letter)
The same pitch written with letter, or null when that takes more than two accidentals: C4 respelled with B is B#3, with D is Dbb4, with E is null.
Note SimplifyEnharmonic()
The plainest spelling: double accidentals and E#, Fb, B#, Cb become their natural or single-accidental equivalent; every other note is returned as is.
string ToString()
The note as C#4, Bb3, F##5.
Note Transpose(Interval interval)
Transposes by a spelled interval, honouring its direction: C4 up an augmented 4th is F#4, E4 down a major 3rd is C4. The letter moves by the interval number, so the spelling is exact.

Throws ArgumentNullException interval is null.

Throws InvalidOperationException The result needs more than two accidentals (B## up a major 2nd).

Throws ArgumentOutOfRangeException The result is outside the octave range.

Note TransposeBySemitones(int semitones)
Transposes by semitones, spelling black keys with sharps (C#, D#, F#, G#, A#). Use Note.TransposeBySemitones to spell in a key.
Note TransposeBySemitones(int semitones, KeySignature targetKey)
Transposes by semitones and spells the result in targetKey (see KeySignature.Spell): A +1 in Eb major is Bb, in E major A#.
static bool TryParse(string? text, out Note? note)
Tries to parse a note in English notation; see Note.Parse.
static bool TryParse(string? text, NoteNotation notation, out Note? note)
Tries to parse a note in the given notation; never throws.
static bool TryParsePitchClass(ReadOnlySpan<char> s, out Note? note, out int consumed)
Reads an English note letter (any case) and up to two accidentals at the start of s.
s
The text to read from; anything after the note is ignored.
note
The note read, in octave 4.
consumed
How many characters the note used.

Returns True when s starts with a note letter.