Struct PitchClass
Pitch class in 12-TET: values 0..11 (C…B) with modulo-12 arithmetic.
public readonly record struct PitchClass : IEquatable<PitchClass>
- Implements
- Inherited Members
Constructors
PitchClass(int)
Creates a pitch class from an integer, reduced modulo 12 (negatives wrap up).
public PitchClass(int value)
Parameters
valueintAny integer; folded into 0..11.
Properties
A
Pitch class A (9).
public static PitchClass A { get; }
Property Value
ASharp
Pitch class A# (10).
public static PitchClass ASharp { get; }
Property Value
Ab
Pitch class Ab (8).
public static PitchClass Ab { get; }
Property Value
B
Pitch class B (11).
public static PitchClass B { get; }
Property Value
Bb
Pitch class Bb (10).
public static PitchClass Bb { get; }
Property Value
C
Pitch class C (0).
public static PitchClass C { get; }
Property Value
CSharp
Pitch class C# (1).
public static PitchClass CSharp { get; }
Property Value
D
Pitch class D (2).
public static PitchClass D { get; }
Property Value
DSharp
Pitch class D# (3).
public static PitchClass DSharp { get; }
Property Value
Db
Pitch class Db (1).
public static PitchClass Db { get; }
Property Value
E
Pitch class E (4).
public static PitchClass E { get; }
Property Value
Eb
Pitch class Eb (3).
public static PitchClass Eb { get; }
Property Value
F
Pitch class F (5).
public static PitchClass F { get; }
Property Value
FSharp
Pitch class F# (6).
public static PitchClass FSharp { get; }
Property Value
G
Pitch class G (7).
public static PitchClass G { get; }
Property Value
GSharp
Pitch class G# (8).
public static PitchClass GSharp { get; }
Property Value
Gb
Pitch class Gb (6).
public static PitchClass Gb { get; }
Property Value
Name
Sharp-preferring note name for this pitch class (e.g. "C#").
public string Name { get; }
Property Value
Value
The pitch-class value, 0..11 (C…B).
public byte Value { get; }
Property Value
Methods
FromMidi(int)
Pitch class of a MIDI pitch (its remainder modulo 12).
public static PitchClass FromMidi(int midiPitch)
Parameters
midiPitchintMIDI pitch number, 0..127.
Returns
Exceptions
- ArgumentOutOfRangeException
midiPitchis outside 0..127.
IntervalTo(PitchClass)
Ascending pitch-class interval from this pitch class to to.
Result is always in 0..11.
public ChromaticInterval IntervalTo(PitchClass to)
Parameters
toPitchClass
Returns
Parse(string)
Parses a pitch-class name such as "C", "F#", or "Bb".
public static PitchClass Parse(string text)
Parameters
textstringThe pitch-class text to parse.
Returns
- PitchClass
The parsed pitch class.
Exceptions
- ArgumentNullException
textis null.- ArgumentException
textis not a valid pitch class.
SignedIntervalTo(PitchClass)
Signed shortest pitch-class interval from this pitch class to to.
Result is in -6…+6 (tritone is returned as +6).
public ChromaticInterval SignedIntervalTo(PitchClass to)
Parameters
toPitchClass
Returns
ToName(bool)
Note name for this pitch class.
public string ToName(bool preferSharps = true)
Parameters
Returns
- string
The one- or two-character note name.
ToString()
Returns the sharp-preferring note name.
public override string ToString()
Returns
Transpose(ChromaticInterval)
Transposes this pitch class by interval (result wraps modulo 12).
public PitchClass Transpose(ChromaticInterval interval)
Parameters
intervalChromaticInterval
Returns
Transpose(int)
Transposes this pitch class by semitones (result wraps modulo 12).
public PitchClass Transpose(int semitones)
Parameters
semitonesint
Returns
TryParse(ReadOnlySpan<char>, out PitchClass)
Attempts to parse a pitch-class name such as "C", "F#", or "Bb".
public static bool TryParse(ReadOnlySpan<char> text, out PitchClass pitchClass)
Parameters
textReadOnlySpan<char>The pitch-class text to parse.
pitchClassPitchClassOn success, the parsed pitch class; otherwise default.
Returns
Operators
operator +(PitchClass, ChromaticInterval)
Transposes pc up by interval (wraps modulo 12).
public static PitchClass operator +(PitchClass pc, ChromaticInterval interval)
Parameters
pcPitchClassintervalChromaticInterval
Returns
operator +(PitchClass, int)
Transposes pc up by semitones (wraps modulo 12).
public static PitchClass operator +(PitchClass pc, int semitones)
Parameters
pcPitchClasssemitonesint
Returns
operator ^(PitchClass, PitchClass)
Signed shortest pitch-class interval from from to to.
[Obsolete("Use SignedIntervalTo(). The ^ operator is non-obvious.")]
public static ChromaticInterval operator ^(PitchClass from, PitchClass to)
Parameters
fromPitchClasstoPitchClass
Returns
operator -(PitchClass, ChromaticInterval)
Transposes pc down by interval (wraps modulo 12).
public static PitchClass operator -(PitchClass pc, ChromaticInterval interval)
Parameters
pcPitchClassintervalChromaticInterval
Returns
operator -(PitchClass, PitchClass)
Ascending pitch-class interval from from to to.
public static ChromaticInterval operator -(PitchClass to, PitchClass from)
Parameters
toPitchClassfromPitchClass
Returns
operator -(PitchClass, int)
Transposes pc down by semitones (wraps modulo 12).
public static PitchClass operator -(PitchClass pc, int semitones)
Parameters
pcPitchClasssemitonesint