Note API Reference
Complete API documentation for the Note
class.
Class Definition
Constructors
Note(NoteName, Alteration, int)
Creates a new note with the specified name, alteration, and octave.
Parameters:
name
: The note name (C through B)alteration
: The alteration (double flat through double sharp)octave
: The octave number (-1 to 10)
Exceptions:
ArgumentOutOfRangeException
: If octave is outside valid range
Example:
Note(NoteName, int)
Creates a new natural note (convenience constructor).
Example:
Properties
Name
Gets the note name (C, D, E, F, G, A, or B).
Alteration
Gets the alteration (DoubleFlat, Flat, Natural, Sharp, or DoubleSharp).
Octave
Gets the octave number. Middle C is in octave 4.
Frequency
Gets the frequency in Hz using equal temperament tuning (A4 = 440 Hz).
Calculation:
MidiNumber
Gets the MIDI note number (0-127). Middle C (C4) = 60.
Exceptions:
InvalidOperationException
: If the note is outside MIDI range
SemitonesFromC
Gets the number of semitones from C in the same octave.
Instance Methods
Transpose(Interval, Direction?)
Transposes the note by the specified interval.
Parameters:
interval
: The interval to transpose bydirection
: The direction (Up or Down), default is Up
Returns: A new Note instance
Example:
TransposeBySemitones(int)
Transposes the note by a number of semitones.
Parameters:
semitones
: Number of semitones (positive = up, negative = down)
Returns: A new Note instance
Example:
IsEnharmonicWith(Note)
Determines if this note is enharmonically equivalent to another.
Parameters:
other
: The note to compare with
Returns: True if the notes have the same pitch
Example:
GetEnharmonicEquivalent()
Gets the enharmonic equivalent of this note.
Returns: The enharmonic equivalent, or null if none exists
Example:
ToString()
Returns a string representation of the note.
Format: {NoteName}{Alteration}{Octave}
Examples:
C4 → "C4"
C#4 → "C#4"
Bb3 → "Bb3"
F##5 → "F##5"
Equals(Note?)
Determines if this note equals another note.
Note: Compares by value (name, alteration, octave), not by enharmonic equivalence.
GetHashCode()
Returns the hash code for the note.
Static Methods
FromMidiNumber(int, bool)
Creates a note from a MIDI number.
Parameters:
midiNumber
: The MIDI number (0-127)preferFlats
: Whether to prefer flats for black keys
Returns: A new Note instance
Exceptions:
ArgumentOutOfRangeException
: If MIDI number is outside 0-127
Example:
TryParse(string, out Note?)
Tries to parse a note from a string.
Parameters:
input
: String representation (e.g., "C4", "F#5", "Bb3")note
: The parsed note, or null if parsing fails
Returns: True if parsing succeeded
Supported formats:
Natural: "C4", "D5"
Sharp: "C#4", "F#5"
Flat: "Bb3", "Eb4"
Double sharp: "F##5", "C##4"
Double flat: "Bbb3", "Abb4"
Example:
Operators
Equality Operators
Compare notes by value (not enharmonic equivalence).
Example:
Constants and Limits
Octave Range
Minimum: -1
Maximum: 10
MIDI Range
Minimum: 0 (C-1)
Maximum: 127 (G9)
Frequency Range
Lowest: ~8.18 Hz (C-1)
Highest: ~12543.85 Hz (G9)
Reference: A4 = 440 Hz
Common Patterns
Creating Common Notes
Working with Collections
Enharmonic Handling
Performance Notes
Frequency calculation is cached after first access
MIDI number calculation is performed on construction
Enharmonic lookups use efficient switch expressions
String parsing uses optimized character processing
Thread Safety
The Note
class is immutable and thread-safe. Multiple threads can safely:
Read all properties
Call all methods
Share Note instances
No synchronization is needed.