accompy.chord_resolution#

Chord symbol to MIDI notes resolution.

Provides pluggable chord resolution with multiple backends (tonal, music21). Implements dependency injection pattern for flexibility.

Functions

chord_to_notes(symbol)

Convert chord symbol to MIDI notes using the current default resolver.

get_chord_resolver()

Get the current default chord resolver.

music21_resolver(symbol, *[, transpose])

Resolve chord symbol using music21 library (alternative).

set_chord_resolver(resolver)

Set the default chord resolver.

tonal_resolver(symbol, *[, transpose])

Resolve chord symbol to MIDI notes using the tonal package (default).

accompy.chord_resolution.chord_to_notes(symbol)[source]#

Convert chord symbol to MIDI notes using the current default resolver.

This is the main entry point for chord resolution in accompy.

Parameters:

symbol (str) – Chord symbol (e.g., “Dm7”, “G7”)

Return type:

list[int]

Returns:

List of MIDI note numbers

Example

>>> notes = chord_to_notes("C")
>>> len(notes) > 0
True
accompy.chord_resolution.get_chord_resolver()[source]#

Get the current default chord resolver.

Return type:

Callable[[str], list[int]]

Returns:

The active chord resolution function

Example

>>> resolver = get_chord_resolver()
>>> notes = resolver("C")
>>> len(notes) > 0
True
accompy.chord_resolution.music21_resolver(symbol, *, transpose=-12)[source]#

Resolve chord symbol using music21 library (alternative).

Music21 is a comprehensive music analysis library. It provides more sophisticated chord parsing but has heavier dependencies.

Parameters:
  • symbol (str) – Chord symbol

  • transpose (int) – Semitone offset to apply (default: -12)

Return type:

list[int]

Returns:

List of MIDI note numbers

Note

Requires: pip install music21 This is provided as an alternative for advanced use cases. Consider using tonal_resolver for standard accompaniment generation.

accompy.chord_resolution.set_chord_resolver(resolver)[source]#

Set the default chord resolver.

This enables global customization of chord-to-notes resolution.

Parameters:

resolver (Callable[[str], list[int]]) – A function that takes a chord symbol (str) and returns MIDI notes (list[int])

Return type:

None

Example

>>> def my_resolver(symbol: str) -> list[int]:
...     # Custom chord voicing logic
...     return [60, 64, 67]  # C major triad
>>> previous = get_chord_resolver()
>>> set_chord_resolver(my_resolver)
>>> chord_to_notes("Dm7")
[60, 64, 67]
>>> set_chord_resolver(previous)  # put the default back: the setting is process-global
accompy.chord_resolution.tonal_resolver(symbol, *, transpose=-12)[source]#

Resolve chord symbol to MIDI notes using the tonal package (default).

The tonal package is lightweight and designed for music theory operations. It anchors chord roots around C4=60. We apply a default -12 semitone transpose to voice chords closer to C3=48 for better bass/piano range.

Parameters:
  • symbol (str) – Chord symbol (e.g., “Dm7”, “G7”, “Cmaj7”)

  • transpose (int) – Semitone offset to apply (default: -12)

Return type:

list[int]

Returns:

List of MIDI note numbers

Example

>>> notes = tonal_resolver("Cmaj7")
>>> len(notes) > 0
True

Note

Requires: pip install tonal See: thorwhalen/tonal