Struct SpnNote
Musical note in scientific pitch notation (pitch class + octave). Backed by MIDI semantics: C-1 = 0, C4 = 60.
public readonly record struct SpnNote : IEquatable<SpnNote>
- Implements
- Inherited Members
Constructors
SpnNote(PitchClass, int)
Musical note in scientific pitch notation (pitch class + octave). Backed by MIDI semantics: C-1 = 0, C4 = 60.
public SpnNote(PitchClass PitchClass, int Octave)
Parameters
PitchClassPitchClassThe pitch class (0..11).
OctaveintThe scientific-pitch octave number (C4 is middle C).
Properties
MidiPitch
MIDI pitch number for this note (middle C = 60).
public int MidiPitch { get; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The note falls outside MIDI range 0..127.
Octave
The scientific-pitch octave number (C4 is middle C).
public int Octave { get; init; }
Property Value
PitchClass
The pitch class (0..11).
public PitchClass PitchClass { get; init; }
Property Value
Methods
A(int)
Note A in the given octave.
public static SpnNote A(int octave)
Parameters
octaveint
Returns
ASharp(int)
Note A# in the given octave.
public static SpnNote ASharp(int octave)
Parameters
octaveint
Returns
Ab(int)
Note Ab in the given octave.
public static SpnNote Ab(int octave)
Parameters
octaveint
Returns
B(int)
Note B in the given octave.
public static SpnNote B(int octave)
Parameters
octaveint
Returns
Bb(int)
Note Bb in the given octave.
public static SpnNote Bb(int octave)
Parameters
octaveint
Returns
C(int)
Note C in the given octave.
public static SpnNote C(int octave)
Parameters
octaveint
Returns
CSharp(int)
Note C# in the given octave.
public static SpnNote CSharp(int octave)
Parameters
octaveint
Returns
D(int)
Note D in the given octave.
public static SpnNote D(int octave)
Parameters
octaveint
Returns
DSharp(int)
Note D# in the given octave.
public static SpnNote DSharp(int octave)
Parameters
octaveint
Returns
Db(int)
Note Db in the given octave.
public static SpnNote Db(int octave)
Parameters
octaveint
Returns
E(int)
Note E in the given octave.
public static SpnNote E(int octave)
Parameters
octaveint
Returns
Eb(int)
Note Eb in the given octave.
public static SpnNote Eb(int octave)
Parameters
octaveint
Returns
F(int)
Note F in the given octave.
public static SpnNote F(int octave)
Parameters
octaveint
Returns
FSharp(int)
Note F# in the given octave.
public static SpnNote FSharp(int octave)
Parameters
octaveint
Returns
FromMidi(int)
Creates a note from a MIDI pitch number (middle C = 60).
public static SpnNote FromMidi(int midiPitch)
Parameters
midiPitchintMIDI pitch number, 0..127.
Returns
Exceptions
- ArgumentOutOfRangeException
midiPitchis outside 0..127.
G(int)
Note G in the given octave.
public static SpnNote G(int octave)
Parameters
octaveint
Returns
GSharp(int)
Note G# in the given octave.
public static SpnNote GSharp(int octave)
Parameters
octaveint
Returns
Gb(int)
Note Gb in the given octave.
public static SpnNote Gb(int octave)
Parameters
octaveint
Returns
Parse(string)
Parses a note in scientific pitch notation such as "C4" or "F#5".
public static SpnNote Parse(string notation)
Parameters
notationstringThe note text to parse.
Returns
- SpnNote
The parsed note.
Exceptions
- ArgumentNullException
notationis null.- ArgumentException
notationis not valid note notation.
ToNotation(bool)
Renders this note in scientific pitch notation (e.g. "C4"). Formats directly from the pitch class and octave, so it never throws — even for notes outside the MIDI 0..127 range (e.g. "A9" or "C-2").
public string ToNotation(bool preferSharps = true)
Parameters
Returns
ToString()
Returns the sharp-preferring scientific pitch notation. Never throws, even outside MIDI range.
public override string ToString()
Returns
TryParse(ReadOnlySpan<char>, out SpnNote)
Attempts to parse a note in scientific pitch notation such as "C4" or "F#5".
public static bool TryParse(ReadOnlySpan<char> notation, out SpnNote note)
Parameters
notationReadOnlySpan<char>The note text to parse.
noteSpnNoteOn success, the parsed note; otherwise default.
Returns
Operators
operator +(SpnNote, ChromaticInterval)
Transposes note up by interval.
public static SpnNote operator +(SpnNote note, ChromaticInterval interval)
Parameters
noteSpnNoteintervalChromaticInterval
Returns
Exceptions
- ArgumentOutOfRangeException
noteitself, or the transposed result, falls outside the MIDI range 0..127.
operator -(SpnNote, ChromaticInterval)
Transposes note down by interval.
public static SpnNote operator -(SpnNote note, ChromaticInterval interval)
Parameters
noteSpnNoteintervalChromaticInterval
Returns
Exceptions
- ArgumentOutOfRangeException
noteitself, or the transposed result, falls outside the MIDI range 0..127.
operator -(SpnNote, SpnNote)
The signed chromatic interval in semitones from from to to.
Computed from the pitch-class and octave components, so it never throws — even when an
operand falls outside the MIDI 0..127 range.
public static ChromaticInterval operator -(SpnNote to, SpnNote from)