accompy.renderers#
MIDI and MMA rendering backends for accompy.
This module provides different backends for generating MIDI from scores:
midi: Built-in MIDI generation using midiutil
mma: MMA (Musical MIDI Accompaniment) backend for more realistic grooves
Functions
|
The drum, bass and piano events |
|
The bass note a pattern's |
|
The notes the piano plays for a chord: its first four notes moved into C4-B4. |
|
Return unique pitch classes (0-11) as a tuple. |
|
Resolve a pitch offset against a chord. |
|
The note events the builtin backend plays for |
|
The |
|
Generate MIDI events from score. |
|
Write MIDI events to a MIDI file. |
- accompy.renderers.bass_pitch(root, chord_notes, pitch_offset)[source]#
The bass note a pattern’s
pitch_offsetplays over a chord.The chord’s root is moved to C2-B2, then the offset is resolved against the chord (
resolve_pitch_offset()), so a pattern’s “3rd” follows the chord’s quality.>>> bass_pitch(57, [57, 60, 64], 4), bass_pitch(48, [48, 52, 55], 4) (48, 40)
- Return type:
- accompy.renderers.chord_events(chord_notes, *, style='swing', start_beat=0, duration=4, beats_per_bar=4, instruments=None, volumes=None, pattern_source=None)[source]#
The drum, bass and piano events
styleplays over one chord.This is one step of
generate_midi_events(), which calls it for every chord of a score:chord_notesare the chord’s MIDI notes, root first (what a chord resolver returns),start_beatwhere the chord starts anddurationhow many beats it lasts. It reads no tempo and keeps no state between chords.>>> [(e.time, e.channel, e.note) for e in chord_events([48, 52, 55], style="rock", ... duration=1)] [(0, 9, 36), (0, 9, 42), (0.5, 9, 42), (0, 0, 36), (0, 1, 60), (0, 1, 64), (0, 1, 67)]
- accompy.renderers.comp_voicing(chord_notes)[source]#
The notes the piano plays for a chord: its first four notes moved into C4-B4.
A chord with no notes is voiced as a C major triad.
>>> comp_voicing([50, 53, 57, 60, 64]), comp_voicing([]) ([62, 65, 69, 60], [60, 64, 67])
- accompy.renderers.events_to_midi_file(events, path, tempo, time_signature=(4, 4))[source]#
Write MIDI events to a MIDI file.
- Parameters:
- Return type:
- Returns:
Path to the created MIDI file
Note
Requires midiutil: pip install midiutil
- accompy.renderers.generate_events(chords, *, style='swing', repeats=1, time_signature=None, instruments=None, volumes=None, pattern_source=None, chord_resolver=None)[source]#
The note events the builtin backend plays for
chords, without writing a file.chordsis anythingaccompy.ensure_score()accepts (a chord string, an iReal URL, measures, chord symbols,(chord, beats)pairs, a Score);time_signatureapplies to the forms that do not carry one (default: the style’s, seestyle_time_signature(): 3/4 forwaltz, else 4/4). Times and durations are in beats: the events do not depend on tempo.repeatsdefaults to 1, as inaccompy.generate_accompaniment().>>> events = generate_events("| C | G |", style="bossa") >>> events[0] MidiEvent(time=0, channel=9, note=37, velocity=56, duration=0.25) >>> max(e.time for e in events) < 8 True
- accompy.renderers.generate_midi_events(score, config, *, pattern_source, chord_resolver)[source]#
Generate MIDI events from score.
Yields events in time order. Does NOT write files. This enables real-time streaming or batch file creation.
- Parameters:
score (
Score) – Musical score with chord progressionconfig (
AccompanimentConfig) – Accompaniment configurationpattern_source – Source providing patterns (must have get_patterns method)
chord_resolver – Function to convert chord symbols to MIDI notes
- Yields:
MidiEvent– MidiEvent objects in chronological order- Return type:
Example
>>> from accompy.base import Score, AccompanimentConfig >>> from accompy.patterns import get_patterns >>> from accompy.chord_resolution import chord_to_notes >>> score = Score.from_string("| C | Am | F | G |") >>> config = AccompanimentConfig() >>> events = generate_midi_events(score, config, ... pattern_source=type('PS', (), {'get_patterns': get_patterns})(), ... chord_resolver=chord_to_notes) >>> first_event = next(events)
- accompy.renderers.resolve_pitch_offset(*, root_pc, chord_pcs, target_offset)[source]#
Resolve a pitch offset against a chord.
The patterns use semitone offsets (0=root, 7=5th, etc.). When an offset represents a chord tone which varies by quality (e.g. 3rd), we prefer a matching chord tone from
chord_pcs.Examples
For a minor chord, a pattern might request offset 4 (“3rd”); this function will choose 3 if the chord contains a minor 3rd.
- Return type:
- accompy.renderers.select_patterns(patterns, beats_per_bar)[source]#
The
(drum, bass, comp)patterns the renderer plays from a style’s pattern lists.The drum pattern is the first one whose
beats_per_barmatches (else the first); bass and comping take the first of their list. A missing one isNone.>>> from accompy.patterns import get_patterns >>> [p.name for p in select_patterns(get_patterns("swing"), 4)] ['swing_basic', 'walking', 'swing_comp']
- Return type:
Modules
MIDI event generation (stateless, iterator-based). |