KeySignature API Reference
Complete API documentation for the KeySignature
class.
Class Definition
Constructors
KeySignature(Note, KeyMode)
Creates a new key signature with the specified tonic and mode.
Parameters:
tonic
: The tonic (root) note of the keymode
: The mode (Major or Minor)
Example:
Properties
Tonic
Gets the tonic (root) note of the key.
Mode
Gets the mode (Major or Minor).
AccidentalCount
Gets the number of accidentals in the key signature.
Positive values indicate sharps
Negative values indicate flats
Zero indicates no accidentals (C major/A minor)
Examples:
C major: 0
G major: 1 (one sharp)
F major: -1 (one flat)
D major: 2 (two sharps)
Bb major: -2 (two flats)
AlteredNotes
Gets the list of note names that are altered in this key.
Order:
Sharps: F, C, G, D, A, E, B
Flats: B, E, A, D, G, C, F
Instance Methods
GetAlteration(NoteName)
Gets the alteration for a specific note in this key.
Parameters:
noteName
: The note name to check
Returns: The alteration (Sharp, Flat, or Natural)
Example:
GetRelativeKey()
Gets the relative major or minor key.
Returns:
For major keys: the relative minor (down a minor 3rd)
For minor keys: the relative major (up a minor 3rd)
Example:
GetParallelKey()
Gets the parallel major or minor key.
Returns: The key with the same tonic but opposite mode
Example:
GetEnharmonicEquivalents()
Gets enharmonically equivalent key signatures.
Returns: List of enharmonic keys (e.g., C# major ↔ Db major)
Example:
NextInCircle(Direction?)
Gets the next key in the circle of fifths.
Parameters:
direction
: Up for clockwise/sharps, Down for counterclockwise/flats
Returns: The next key in the circle of fifths
Example:
PreviousInCircle()
Gets the previous key in the circle of fifths.
Returns: The previous key (equivalent to NextInCircle(Direction.Down))
ToString()
Returns a string representation of the key signature.
Format: "{Tonic} {mode}"
Examples:
"C major"
"A minor"
"G major"
"Eb minor"
Equals(KeySignature?)
Determines if this key signature equals another.
GetHashCode()
Returns the hash code for the key signature.
Static Methods
GetAllKeys()
Gets all standard key signatures.
Returns: List of all 30 standard keys (15 major + 15 minor)
Example:
Operators
Equality Operators
Compare key signatures by tonic and mode.
Key Signature Reference
Major Keys
Key | Accidentals | Notes Altered |
---|---|---|
C | 0 | None |
G | 1# | F# |
D | 2# | F#, C# |
A | 3# | F#, C#, G# |
E | 4# | F#, C#, G#, D# |
B | 5# | F#, C#, G#, D#, A# |
F# | 6# | F#, C#, G#, D#, A#, E# |
C# | 7# | F#, C#, G#, D#, A#, E#, B# |
F | 1b | Bb |
Bb | 2b | Bb, Eb |
Eb | 3b | Bb, Eb, Ab |
Ab | 4b | Bb, Eb, Ab, Db |
Db | 5b | Bb, Eb, Ab, Db, Gb |
Gb | 6b | Bb, Eb, Ab, Db, Gb, Cb |
Cb | 7b | Bb, Eb, Ab, Db, Gb, Cb, Fb |
Minor Keys
Key | Accidentals | Relative Major |
---|---|---|
A | 0 | C |
E | 1# | G |
B | 2# | D |
F# | 3# | A |
C# | 4# | E |
G# | 5# | B |
D# | 6# | F# |
A# | 7# | C# |
D | 1b | F |
G | 2b | Bb |
C | 3b | Eb |
F | 4b | Ab |
Bb | 5b | Db |
Eb | 6b | Gb |
Ab | 7b | Cb |
Common Patterns
Working with Keys
Key Relationships
Finding Key from Notes
Performance Notes
Accidental count is calculated once during construction
Circle of fifths navigation uses efficient modular arithmetic
Key equality comparison is optimized
Static key lists are cached
Thread Safety
The KeySignature
class is immutable and thread-safe. Multiple threads can safely:
Read all properties
Call all methods
Share KeySignature instances
No synchronization is needed.