pyabc2.Key

class pyabc2.Key(name=None, *, tonic=None, mode=None)

Key, including mode.

Pass either name (key spec with tonic and mode combined, used in ABC notation) or tonic and mode.

Parameters:
  • name (str | None) – Key name (e.g., D, Amaj, Em, Ador, Bbmin, …). (Major assumed if mode not specified.)

  • tonic (str | None) – Tonic of the key (e.g., C, D, …).

  • mode (str | None) – Mode specification, (e.g., maj, min, dor, …).

Examples

>>> from pyabc2 import Key
>>> Key('C')
Key(tonic=C, mode='Major')
>>> Key('Ador')
Key(tonic=A, mode='Dorian')
>>> Key('Em')
Key(tonic=E, mode='Minor')
>>> Key(tonic='Bb', mode='Locrian')
Key(tonic=Bb, mode='Locrian')
__init__(name=None, *, tonic=None, mode=None)
Parameters:
  • name (str | None)

  • tonic (str | None)

  • mode (str | None)

Methods

__init__([name, tonic, mode])

parse_key(key)

Parse a key spec string (e.g., D, Amin) and return the tonic and mode (3-char abbreviation).

print_chromatic_scale_degrees(**kwargs)

print_intervals(*[, fmt])

print_scale()

print_scale_chromatic_values()

print_scale_degrees_wrt_major(**kwargs)

relative(mode, *[, match_acc])

Compute a relative key by specifying the target mode.

Attributes

accidentals

A dictionary of accidentals in the key signature, mapping natural note names to the accidental applied.

intervals

List of the intervals that compose the scale.

key_signature

List of accidentals that should be displayed in the key signature for the given key description.

mode

Full mode name (e.g., Major).

relative_major

relative_minor

scale

Notes (pitch classes) of the scale.

scale_chromatic_values

Integer chromatic values that make up the scale, relative to the tonic.

scale_degrees_wrt_major

Scale degrees of the mode's scale, with #/b as compared to the major scale with the same tonic.

tonic

The tonic of the key.