How ishandave1/pymusic works
Purpose and Entry Points
pyMusic is a Python library and script collection for generating music-theory structures and rendering compositions as MIDI. Primary runnable entry points are composition/generation scripts: scripts/compose_chords.py, scripts/generate_arpeggios.py, scripts/generate_raga.py, and scripts/synthesize_guitar.py. Library consumers import from the src/music_theory package.
Core Theory Model
src/music_theory/core/constants.py defines canonical note names, scale intervals, chord formulas, and interval mappings. src/music_theory/core/notes.py translates note strings and MIDI pitches, builds scales/chords, and provides the pitch-level representation used by all higher layers. src/music_theory/core/chord.py holds chord-oriented analysis or progression behavior.
Western Composition Flow
Chord and arpeggio workflows start with named roots, scale/chord types, and voicing choices; core modules resolve these to ordered MIDI-note collections. Those collections are scheduled into MIDI events by src/music_theory/midi/compose.py and src/music_theory/midi/arpeggio.py. Script front ends select musical inputs and initiate file-oriented generation rather than serving requests.
Guitar Domain and Synthesis
src/music_theory/guitar/guitar_chord.py maps guitar tuning/tab or fret-position concepts to sounded notes, forming the boundary between string-based input and general MIDI pitches. src/music_theory/guitar/synthesizer.py consumes guitar-oriented note/chord material to produce synthesized output. scripts/synthesize_guitar.py is the corresponding executable workflow.
Raga Generation Pipeline
src/music_theory/raga/raga_generator.py encapsulates Indian classical raga definitions/rules and melody generation. Generated melodic note sequences cross into the MIDI layer for persistence/playback, with scripts/generate_raga.py providing a batch-generation entry point. This domain is parallel to Western chord generation but shares MIDI pitch/output infrastructure.
MIDI Output Boundary
src/music_theory/midi/compose.py and src/music_theory/midi/arpeggio.py are the rendering boundary: abstract notes, chords, and timing patterns become MIDI file events. The material external dependency is midiutil (declared in requirements.txt); no service, database, or network infrastructure is indicated. Python 3.8+ is the target runtime.
Architectural Boundaries
The package is layered around reusable theory primitives → specialized musical domains (guitar, raga) → MIDI composition/rendering → executable scripts. src/music_theory/__init__.py and subpackage initializers provide import/package boundaries, while scripts should remain orchestration clients rather than places for theory rules.
Main entry points: notes.py Notes and pitches · compose.py MIDI composer · guitar_chord.py Guitar note mapping · raga_generator.py Raga generator
Components 14
Theory Core
Reusable pitch, scale, and chord primitives.
- Theory constants · Canonical notes, intervals, scales, and chord formulas.
src/music_theory/core/constants.py - Notes and pitches · Builds scales and chords and translates note strings and MIDI pitches.
src/music_theory/core/notes.py - Chord analysis · Chord-oriented analysis and progression behavior.
src/music_theory/core/chord.py
Music Domains
Western, guitar, and raga-specific generation.
- Western composition inputs · Roots, scale or chord types, voicings, and timing choices.
- Guitar note mapping · Maps tuning, tab, and fret positions to sounded notes.
src/music_theory/guitar/guitar_chord.py - Guitar synthesizer · Produces synthesized output from guitar-oriented material.
src/music_theory/guitar/synthesizer.py - Raga generator · Applies raga rules to generate melodic note sequences.
src/music_theory/raga/raga_generator.py
MIDI Rendering
Converts musical material into MIDI events and files.
- MIDI composer · Schedules abstract notes and chords as MIDI file events.
src/music_theory/midi/compose.py - Arpeggio renderer · Turns ordered pitch patterns into MIDI events.
src/music_theory/midi/arpeggio.py - midiutil · MIDI file-writing dependency.
requirements.txt
Executable Scripts
Batch-generation entry points.
- Compose chords
scripts/compose_chords.py - Generate arpeggios
scripts/generate_arpeggios.py - Generate raga
scripts/generate_raga.py - Synthesize guitar
scripts/synthesize_guitar.py
Connections 19
- Theory constants → Notes and pitches: defines theory data
- Notes and pitches → Chord analysis: provides pitches
- Western composition inputs → Notes and pitches: resolves scales and chords
- Chord analysis → MIDI composer: chords and voicings
- Notes and pitches → MIDI composer: ordered MIDI pitches
- Notes and pitches → Arpeggio renderer: pitch collections
- Guitar note mapping → Notes and pitches: sounded pitches
- Guitar note mapping → Guitar synthesizer: guitar note material
- Raga generator → Notes and pitches: melodic pitches
- Raga generator → MIDI composer: melody and timing
- MIDI composer → midiutil: writes MIDI files
- Arpeggio renderer → midiutil: writes MIDI files
- Compose chords → Western composition inputs: selects inputs
- Compose chords → MIDI composer: initiates rendering
- Generate arpeggios → Western composition inputs: selects inputs
- Generate arpeggios → Arpeggio renderer: initiates rendering
- Generate raga → Raga generator: initiates generation
- Synthesize guitar → Guitar note mapping: provides guitar inputs
- Synthesize guitar → Guitar synthesizer: initiates synthesis