# ishandave1/pymusic architecture

> Architecture diagram of the GitHub repository ishandave1/pymusic, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ishandave1/pymusic
- Repository: https://github.com/ishandave1/pymusic

## Overview

#### 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: [`src/music_theory/core/notes.py`](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/core/notes.py) (Notes and pitches), [`src/music_theory/midi/compose.py`](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/midi/compose.py) (MIDI composer), [`src/music_theory/guitar/guitar_chord.py`](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/guitar/guitar_chord.py) (Guitar note mapping), [`src/music_theory/raga/raga_generator.py`](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/raga/raga_generator.py) (Raga generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Theory Core"]
  node_constants["Theory constants<br/>definitions<br/>[constants.py]"]
  node_notes["Notes and pitches<br/>pitch model<br/>[notes.py]"]
  node_chord["Chord analysis<br/>chord model<br/>[chord.py]"]
end

subgraph group_domains["Music Domains"]
  node_western_input["Western composition inputs<br/>musical inputs"]
  node_guitar_chord["Guitar note mapping<br/>guitar domain<br/>[guitar_chord.py]"]
  node_synthesizer["Guitar synthesizer<br/>synthesis<br/>[synthesizer.py]"]
  node_raga_generator["Raga generator<br/>raga domain<br/>[raga_generator.py]"]
end

subgraph group_midi["MIDI Rendering"]
  node_compose["MIDI composer<br/>MIDI renderer<br/>[compose.py]"]
  node_arpeggio["Arpeggio renderer<br/>MIDI renderer<br/>[arpeggio.py]"]
  node_midiutil{{"midiutil<br/>external dependency<br/>[requirements.txt]"}}
end

subgraph group_scripts["Executable Scripts"]
  node_compose_script["Compose chords<br/>script entry point<br/>[compose_chords.py]"]
  node_arpeggios_script["Generate arpeggios<br/>script entry point"]
  node_raga_script["Generate raga<br/>script entry point<br/>[generate_raga.py]"]
  node_guitar_script["Synthesize guitar<br/>script entry point"]
end

node_constants -->|"defines theory data"| node_notes
node_notes -->|"provides pitches"| node_chord
node_western_input -->|"resolves scales and chords"| node_notes
node_chord -->|"chords and voicings"| node_compose
node_notes -->|"ordered MIDI pitches"| node_compose
node_notes -->|"pitch collections"| node_arpeggio
node_guitar_chord -->|"sounded pitches"| node_notes
node_guitar_chord -->|"guitar note material"| node_synthesizer
node_raga_generator -->|"melodic pitches"| node_notes
node_raga_generator -->|"melody and timing"| node_compose
node_compose -->|"writes MIDI files"| node_midiutil
node_arpeggio -->|"writes MIDI files"| node_midiutil
node_compose_script -->|"selects inputs"| node_western_input
node_compose_script -->|"initiates rendering"| node_compose
node_arpeggios_script -->|"selects inputs"| node_western_input
node_arpeggios_script -->|"initiates rendering"| node_arpeggio
node_raga_script -->|"initiates generation"| node_raga_generator
node_guitar_script -->|"provides guitar inputs"| node_guitar_chord
node_guitar_script -->|"initiates synthesis"| node_synthesizer

click node_constants "https://github.com/ishandave1/pymusic/blob/main/src/music_theory/core/constants.py"
click node_notes "https://github.com/ishandave1/pymusic/blob/main/src/music_theory/core/notes.py"
click node_chord "https://github.com/ishandave1/pymusic/blob/main/src/music_theory/core/chord.py"
click node_guitar_chord "https://github.com/ishandave1/pymusic/blob/main/src/music_theory/guitar/guitar_chord.py"
click node_synthesizer "https://github.com/ishandave1/pymusic/blob/main/src/music_theory/guitar/synthesizer.py"
click node_raga_generator "https://github.com/ishandave1/pymusic/blob/main/src/music_theory/raga/raga_generator.py"
click node_compose "https://github.com/ishandave1/pymusic/blob/main/src/music_theory/midi/compose.py"
click node_arpeggio "https://github.com/ishandave1/pymusic/blob/main/src/music_theory/midi/arpeggio.py"
click node_midiutil "https://github.com/ishandave1/pymusic/blob/main/requirements.txt"
click node_compose_script "https://github.com/ishandave1/pymusic/blob/main/scripts/compose_chords.py"
click node_arpeggios_script "https://github.com/ishandave1/pymusic/blob/main/scripts/generate_arpeggios.py"
click node_raga_script "https://github.com/ishandave1/pymusic/blob/main/scripts/generate_raga.py"
click node_guitar_script "https://github.com/ishandave1/pymusic/blob/main/scripts/synthesize_guitar.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_constants,node_notes,node_chord toneBlue
class node_western_input,node_guitar_chord,node_synthesizer,node_raga_generator toneAmber
class node_compose,node_arpeggio,node_midiutil toneMint
class node_compose_script,node_arpeggios_script,node_raga_script,node_guitar_script toneRose
```

## Components

### Theory Core

Reusable pitch, scale, and chord primitives.

- [Theory constants](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/core/constants.py): definitions · Canonical notes, intervals, scales, and chord formulas. · `src/music_theory/core/constants.py`
- [Notes and pitches](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/core/notes.py): pitch model · Builds scales and chords and translates note strings and MIDI pitches. · `src/music_theory/core/notes.py`
- [Chord analysis](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/core/chord.py): chord model · Chord-oriented analysis and progression behavior. · `src/music_theory/core/chord.py`

### Music Domains

Western, guitar, and raga-specific generation.

- **Western composition inputs**: musical inputs · Roots, scale or chord types, voicings, and timing choices.
- [Guitar note mapping](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/guitar/guitar_chord.py): guitar domain · Maps tuning, tab, and fret positions to sounded notes. · `src/music_theory/guitar/guitar_chord.py`
- [Guitar synthesizer](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/guitar/synthesizer.py): synthesis · Produces synthesized output from guitar-oriented material. · `src/music_theory/guitar/synthesizer.py`
- [Raga generator](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/raga/raga_generator.py): raga domain · 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](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/midi/compose.py): MIDI renderer · Schedules abstract notes and chords as MIDI file events. · `src/music_theory/midi/compose.py`
- [Arpeggio renderer](https://github.com/ishandave1/pymusic/blob/main/src/music_theory/midi/arpeggio.py): MIDI renderer · Turns ordered pitch patterns into MIDI events. · `src/music_theory/midi/arpeggio.py`
- [midiutil](https://github.com/ishandave1/pymusic/blob/main/requirements.txt): external dependency · MIDI file-writing dependency. · `requirements.txt`

### Executable Scripts

Batch-generation entry points.

- [Compose chords](https://github.com/ishandave1/pymusic/blob/main/scripts/compose_chords.py): script entry point · `scripts/compose_chords.py`
- [Generate arpeggios](https://github.com/ishandave1/pymusic/blob/main/scripts/generate_arpeggios.py): script entry point · `scripts/generate_arpeggios.py`
- [Generate raga](https://github.com/ishandave1/pymusic/blob/main/scripts/generate_raga.py): script entry point · `scripts/generate_raga.py`
- [Synthesize guitar](https://github.com/ishandave1/pymusic/blob/main/scripts/synthesize_guitar.py): script entry point · `scripts/synthesize_guitar.py`

## Connections

- 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
