Table of Contents

Struct SpnNote

Namespace
Celeritas.Core
Assembly
Celeritas.dll

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

PitchClass PitchClass

The pitch class (0..11).

Octave int

The 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

int

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

int

PitchClass

The pitch class (0..11).

public PitchClass PitchClass { get; init; }

Property Value

PitchClass

Methods

A(int)

Note A in the given octave.

public static SpnNote A(int octave)

Parameters

octave int

Returns

SpnNote

ASharp(int)

Note A# in the given octave.

public static SpnNote ASharp(int octave)

Parameters

octave int

Returns

SpnNote

Ab(int)

Note Ab in the given octave.

public static SpnNote Ab(int octave)

Parameters

octave int

Returns

SpnNote

B(int)

Note B in the given octave.

public static SpnNote B(int octave)

Parameters

octave int

Returns

SpnNote

Bb(int)

Note Bb in the given octave.

public static SpnNote Bb(int octave)

Parameters

octave int

Returns

SpnNote

C(int)

Note C in the given octave.

public static SpnNote C(int octave)

Parameters

octave int

Returns

SpnNote

CSharp(int)

Note C# in the given octave.

public static SpnNote CSharp(int octave)

Parameters

octave int

Returns

SpnNote

D(int)

Note D in the given octave.

public static SpnNote D(int octave)

Parameters

octave int

Returns

SpnNote

DSharp(int)

Note D# in the given octave.

public static SpnNote DSharp(int octave)

Parameters

octave int

Returns

SpnNote

Db(int)

Note Db in the given octave.

public static SpnNote Db(int octave)

Parameters

octave int

Returns

SpnNote

E(int)

Note E in the given octave.

public static SpnNote E(int octave)

Parameters

octave int

Returns

SpnNote

Eb(int)

Note Eb in the given octave.

public static SpnNote Eb(int octave)

Parameters

octave int

Returns

SpnNote

F(int)

Note F in the given octave.

public static SpnNote F(int octave)

Parameters

octave int

Returns

SpnNote

FSharp(int)

Note F# in the given octave.

public static SpnNote FSharp(int octave)

Parameters

octave int

Returns

SpnNote

FromMidi(int)

Creates a note from a MIDI pitch number (middle C = 60).

public static SpnNote FromMidi(int midiPitch)

Parameters

midiPitch int

MIDI pitch number, 0..127.

Returns

SpnNote

Exceptions

ArgumentOutOfRangeException

midiPitch is outside 0..127.

G(int)

Note G in the given octave.

public static SpnNote G(int octave)

Parameters

octave int

Returns

SpnNote

GSharp(int)

Note G# in the given octave.

public static SpnNote GSharp(int octave)

Parameters

octave int

Returns

SpnNote

Gb(int)

Note Gb in the given octave.

public static SpnNote Gb(int octave)

Parameters

octave int

Returns

SpnNote

Parse(string)

Parses a note in scientific pitch notation such as "C4" or "F#5".

public static SpnNote Parse(string notation)

Parameters

notation string

The note text to parse.

Returns

SpnNote

The parsed note.

Exceptions

ArgumentNullException

notation is null.

ArgumentException

notation is 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

preferSharps bool

When true, spell black keys with sharps; otherwise flats.

Returns

string

ToString()

Returns the sharp-preferring scientific pitch notation. Never throws, even outside MIDI range.

public override string ToString()

Returns

string

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

notation ReadOnlySpan<char>

The note text to parse.

note SpnNote

On success, the parsed note; otherwise default.

Returns

bool

true if parsing succeeded; otherwise false.

Operators

operator +(SpnNote, ChromaticInterval)

Transposes note up by interval.

public static SpnNote operator +(SpnNote note, ChromaticInterval interval)

Parameters

note SpnNote
interval ChromaticInterval

Returns

SpnNote

Exceptions

ArgumentOutOfRangeException

note itself, 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

note SpnNote
interval ChromaticInterval

Returns

SpnNote

Exceptions

ArgumentOutOfRangeException

note itself, 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)

Parameters

to SpnNote
from SpnNote

Returns

ChromaticInterval