accompy.converters#
Core types for the chord-to-audio pipeline.
Defines the data types that flow through the pipeline, plus a converter registry that maps (source_type, target_type) pairs to converter functions.
The key types form a DAG:
ChordSheet --> ChordSequence --> NoteSequence --> MidiData --> AudioData
(Plus shortcut converters that skip intermediate steps.)
Usage:
>>> from accompy.wips.types import converter, ChordSequence, MidiData
>>> # Get a specific converter
>>> to_midi = converter[ChordSequence, MidiData]
>>> # Or convert in one call
>>> midi = convert(chord_seq, MidiData)
Functions
|
Convert source to target_type using the registered converter. |
Classes
|
Container for audio data — numpy array + sample rate. |
|
Ordered sequence of (chord_symbol, duration_beats) pairs with metadata. |
Registry mapping (source_type, target_type) to named converter functions. |
|
|
Container for MIDI data — either as bytes or as a pretty_midi object. |
|
Ordered sequence of (midi_notes, duration_beats) with metadata. |
- class accompy.converters.AudioData(waveform, sr=44100)[source]#
Bases:
objectContainer for audio data — numpy array + sample rate.
>>> import numpy as np >>> ad = AudioData(waveform=np.zeros(44100), sr=44100) >>> ad.duration_seconds 1.0
- class accompy.converters.ChordSequence(chords, title='', key='C', tempo=120, time_signature=(4, 4), sections=list())[source]#
Bases:
objectOrdered sequence of (chord_symbol, duration_beats) pairs with metadata.
This is the canonical internal representation of a chord progression.
>>> cs = ChordSequence([("Dm7", 4.0), ("G7", 4.0), ("Cmaj7", 8.0)]) >>> len(cs) 3 >>> cs[0] ('Dm7', 4.0) >>> cs.total_beats 16.0
- section_chords(label)[source]#
The chords of the first section called
label(case-insensitive), or[].>>> cs = ChordSequence([("C", 4.0), ("G", 4.0)], sections=[("Verse", 0, 1), ("Chorus", 1, 2)]) >>> cs.section_chords("chorus") [('G', 4.0)]
- class accompy.converters.ConverterRegistry[source]#
Bases:
objectRegistry mapping (source_type, target_type) to named converter functions.
Supports multiple converters for the same type pair, distinguished by name. The first registered converter becomes the default.
>>> reg = ConverterRegistry() >>> reg.register(str, int, int, name='builtin') >>> reg[str, int]('42') 42 >>> reg.list_converters(str, int) ['builtin']
- get(source_type, target_type, name=None)[source]#
Get a specific named converter, or the default if name is None.
- Return type:
- class accompy.converters.MidiData(bytes_=None, pretty_midi_obj=None, tempo=120, time_signature=(4, 4))[source]#
Bases:
objectContainer for MIDI data — either as bytes or as a pretty_midi object.
Wraps MIDI content so converters have a uniform interface regardless of which MIDI library produced the data.
>>> import io >>> md = MidiData(bytes_=b'MThd...', tempo=120) >>> md.has_bytes True
- class accompy.converters.NoteSequence(notes, tempo=120, time_signature=(4, 4))[source]#
Bases:
objectOrdered sequence of (midi_notes, duration_beats) with metadata.
Represents resolved chords — chord symbols have been converted to concrete MIDI note numbers.
>>> ns = NoteSequence([([60, 64, 67], 4.0), ([62, 65, 69], 4.0)]) >>> ns[0] ([60, 64, 67], 4.0)