API / MusicTheory
Note record
C#4 and Db4 are different notes that are enharmonic (Note.IsEnharmonicWith).Constructors
Note(NoteName name, Alteration alteration = Alteration.Natural, int octave = 4)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; }Alteration Alteration { get; }int Octave { get; }Note.MinOctave to Note.MaxOctave. Middle C is in octave 4.int PitchClass { get; }B# is 0, Cb is 11.double Frequency { get; }int MidiNumber { get; }Throws InvalidOperationException The note is outside MIDI's 0..127.
Fields
const int MinOctave = -1const int MaxOctave = 9const double StandardA4 = 440Methods
static TunedPitch FromFrequency(double hz, double a4 = 440, bool preferFlats = false)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)preferFlats.Throws ArgumentOutOfRangeException midiNumber is outside 0..127.
IEnumerable<Note> GetAllEnharmonicEquivalents()Note? GetEnharmonicEquivalent()double GetFrequency(double a4 = 440)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)Bb or (Unicode) B♭.bool IsEnharmonicWith(Note? other)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)#, 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)NoteNotation.Throws FormatException The text is not a note in that notation.
Note? Respell(NoteName letter)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()string ToString()C#4, Bb3, F##5.Note Transpose(Interval interval)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)Note.TransposeBySemitones to spell in a key.Note TransposeBySemitones(int semitones, KeySignature targetKey)targetKey (see KeySignature.Spell): A +1 in Eb major is Bb, in E major A#.static bool TryParse(string? text, out Note? note)Note.Parse.static bool TryParse(string? text, NoteNotation notation, out Note? note)static bool TryParsePitchClass(ReadOnlySpan<char> s, out Note? note, out int consumed)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.