Skip to content

GuitarPrometheus::MusicModels::KeySignature

GuitarPrometheus::MusicModels::KeySignature

A key signature in 12-tone equal temperament. More…

#include <MusicalConcepts.h>

Public Functions

Name
KeySignature()
Default constructor: C major (fifths=0, Ionian).
KeySignature(int fifths, Mode mode)
Construct from MusicXML’s <fifths> + <mode> directly.
KeySignature(PitchClass tonic, Accidental tonicAccidental, Mode mode)
Construct from a tonic note + mode (human-friendly).
intgetFifths() const
Number of sharps (positive) or flats (negative) in this key.
ModegetMode() const
Mode of this key.
PitchClassgetTonic() const
Pitch class of this key’s tonic.
AccidentalgetTonicAccidental() const
Accidental on this key’s tonic (e.g., Flat for Bb minor).
AccidentalgetKeyAccidental(PitchClass p) const
Resolve the accidental for a given pitch class in this key.

Detailed Description

class GuitarPrometheus::MusicModels::KeySignature;

A key signature in 12-tone equal temperament.

Stored internally as fifths (the position on the circle of fifths, matching MusicXML’s <fifths> element, range -7..+7) plus a Mode. Accidentals for each pitch class are resolved from fifths alone via a static lookup table — Mode is preserved for display and round-trip purposes (so “Bb minor” can come back out as Bb + Aeolian) but has no effect on accidental resolution.

Public Functions Documentation

function KeySignature

KeySignature()

Default constructor: C major (fifths=0, Ionian).

Provided so types containing [KeySignature](/api-reference/classes/classguitarprometheus_1_1musicmodels_1_1keysignature/) (like Measure) are default-constructible.

function KeySignature

KeySignature(
int fifths,
Mode mode
)

Construct from MusicXML’s <fifths> + <mode> directly.

Parameters:

  • fifths -7..+7. Out-of-range values throw std::invalid_argument.
  • mode The mode of the key (Ionian, Dorian, etc.).

function KeySignature

KeySignature(
PitchClass tonic,
Accidental tonicAccidental,
Mode mode
)

Construct from a tonic note + mode (human-friendly).

Parameters:

  • tonic Pitch class of the tonic note.
  • tonicAccidental Accidental on the tonic (Natural, Sharp, Flat).
  • mode Mode of the key.

Internally computes the fifths value from the tonic and mode. If the resulting fifths falls outside -7..+7 (e.g., C# Lydian requires 8 sharps), throws std::invalid_argument.

function getFifths

int getFifths() const

Number of sharps (positive) or flats (negative) in this key.

function getMode

Mode getMode() const

Mode of this key.

function getTonic

PitchClass getTonic() const

Pitch class of this key’s tonic.

function getTonicAccidental

Accidental getTonicAccidental() const

Accidental on this key’s tonic (e.g., Flat for Bb minor).

function getKeyAccidental

Accidental getKeyAccidental(
PitchClass p
) const

Resolve the accidental for a given pitch class in this key.

Return: One of {Flat, Natural, Sharp}; never None or doubles for standard keys (-7..+7 fifths).


Updated on 2026-05-29 at 07:39:52 +0000