Table of Contents

Struct PitchClass

Namespace
Celeritas.Core
Assembly
Celeritas.dll

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

value int

Any integer; folded into 0..11.

Properties

A

Pitch class A (9).

public static PitchClass A { get; }

Property Value

PitchClass

ASharp

Pitch class A# (10).

public static PitchClass ASharp { get; }

Property Value

PitchClass

Ab

Pitch class Ab (8).

public static PitchClass Ab { get; }

Property Value

PitchClass

B

Pitch class B (11).

public static PitchClass B { get; }

Property Value

PitchClass

Bb

Pitch class Bb (10).

public static PitchClass Bb { get; }

Property Value

PitchClass

C

Pitch class C (0).

public static PitchClass C { get; }

Property Value

PitchClass

CSharp

Pitch class C# (1).

public static PitchClass CSharp { get; }

Property Value

PitchClass

D

Pitch class D (2).

public static PitchClass D { get; }

Property Value

PitchClass

DSharp

Pitch class D# (3).

public static PitchClass DSharp { get; }

Property Value

PitchClass

Db

Pitch class Db (1).

public static PitchClass Db { get; }

Property Value

PitchClass

E

Pitch class E (4).

public static PitchClass E { get; }

Property Value

PitchClass

Eb

Pitch class Eb (3).

public static PitchClass Eb { get; }

Property Value

PitchClass

F

Pitch class F (5).

public static PitchClass F { get; }

Property Value

PitchClass

FSharp

Pitch class F# (6).

public static PitchClass FSharp { get; }

Property Value

PitchClass

G

Pitch class G (7).

public static PitchClass G { get; }

Property Value

PitchClass

GSharp

Pitch class G# (8).

public static PitchClass GSharp { get; }

Property Value

PitchClass

Gb

Pitch class Gb (6).

public static PitchClass Gb { get; }

Property Value

PitchClass

Name

Sharp-preferring note name for this pitch class (e.g. "C#").

public string Name { get; }

Property Value

string

Value

The pitch-class value, 0..11 (C…B).

public byte Value { get; }

Property Value

byte

Methods

FromMidi(int)

Pitch class of a MIDI pitch (its remainder modulo 12).

public static PitchClass FromMidi(int midiPitch)

Parameters

midiPitch int

MIDI pitch number, 0..127.

Returns

PitchClass

Exceptions

ArgumentOutOfRangeException

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

to PitchClass

Returns

ChromaticInterval

Parse(string)

Parses a pitch-class name such as "C", "F#", or "Bb".

public static PitchClass Parse(string text)

Parameters

text string

The pitch-class text to parse.

Returns

PitchClass

The parsed pitch class.

Exceptions

ArgumentNullException

text is null.

ArgumentException

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

to PitchClass

Returns

ChromaticInterval

ToName(bool)

Note name for this pitch class.

public string ToName(bool preferSharps = true)

Parameters

preferSharps bool

When true, spell black keys with sharps (C#); otherwise flats (Db).

Returns

string

The one- or two-character note name.

ToString()

Returns the sharp-preferring note name.

public override string ToString()

Returns

string

Transpose(ChromaticInterval)

Transposes this pitch class by interval (result wraps modulo 12).

public PitchClass Transpose(ChromaticInterval interval)

Parameters

interval ChromaticInterval

Returns

PitchClass

Transpose(int)

Transposes this pitch class by semitones (result wraps modulo 12).

public PitchClass Transpose(int semitones)

Parameters

semitones int

Returns

PitchClass

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

text ReadOnlySpan<char>

The pitch-class text to parse.

pitchClass PitchClass

On success, the parsed pitch class; otherwise default.

Returns

bool

true if parsing succeeded; otherwise false.

Operators

operator +(PitchClass, ChromaticInterval)

Transposes pc up by interval (wraps modulo 12).

public static PitchClass operator +(PitchClass pc, ChromaticInterval interval)

Parameters

pc PitchClass
interval ChromaticInterval

Returns

PitchClass

operator +(PitchClass, int)

Transposes pc up by semitones (wraps modulo 12).

public static PitchClass operator +(PitchClass pc, int semitones)

Parameters

pc PitchClass
semitones int

Returns

PitchClass

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

from PitchClass
to PitchClass

Returns

ChromaticInterval

operator -(PitchClass, ChromaticInterval)

Transposes pc down by interval (wraps modulo 12).

public static PitchClass operator -(PitchClass pc, ChromaticInterval interval)

Parameters

pc PitchClass
interval ChromaticInterval

Returns

PitchClass

operator -(PitchClass, PitchClass)

Ascending pitch-class interval from from to to.

public static ChromaticInterval operator -(PitchClass to, PitchClass from)

Parameters

to PitchClass
from PitchClass

Returns

ChromaticInterval

operator -(PitchClass, int)

Transposes pc down by semitones (wraps modulo 12).

public static PitchClass operator -(PitchClass pc, int semitones)

Parameters

pc PitchClass
semitones int

Returns

PitchClass