How theairdemon/musicgenerator works
1. What this repository is
- musicGenerator is a versioned music-composition system written primarily in Python.
- Its core job is to turn music-theory rules and genre presets into song structures, then export them as MIDI-oriented artifacts for playback or DAW use.
2. Repo structure is versioned by architecture
- The root contains multiple generations of the project: Version 1 (deprecated), Version 2 (deprecated), Version 3 (stable), and Version 4 (dev).
- This is not a single flat codebase; it is an evolution path. For an architecture diagram, the current system should center on Version 4, with Versions 1–3 treated as historical layers showing how the pipeline evolved.
3. Current core pipeline: Version 4
- Version 4 (dev)/SongGen.py appears to be the main orchestration class.
- RunSongGen.py is the entry entrypoint that likely initializes configuration and triggers generation.
- The flow is: genre/structure inputs → generator modules → MIDI output, with optional playback/rendering integration.
4. Generation subsystem is split into focused modules
- Version 4 (dev)/Generators/ contains the functional stages of song creation:
- GenChords.py for chord progressions
- GenHarmony.py for harmony parts
- GenMelody.py for lead melody creation
- GenRhythm.py for rhythmic patterns
- GenDrums.py for percussion
- GenMidi.py for writing/exporting MIDI
- This suggests a pipeline where musical concerns are separated by domain, rather than handled in one monolithic generator.
5. Genre subsystem provides constraints and style
- Version 4 (dev)/Genres/ is the style/metadata layer.
- DefineGenre.py and the GenreDefinitions/ package (anime.py, classical.py, cyberpunk.py, fantasy.py, lofi.py, base.py) indicate genre-specific templates or rule sets.
- Supporting files like MelodyInfo.py, RhythmInfo.py, StructureInfo.py, and MidiInfo.py suggest that genre definitions feed structured parameters into the generator pipeline.
6. Primary data flow
- The generator likely starts with genre selection and high-level song shape, then progressively derives lower-level musical parts.
- A typical flow is: genre definition → structure/rhythm/melody constraints → chords/harmony/drums/melody generation → MIDI assembly/export.
- This layered flow is important for the architecture diagram because each stage consumes the output of the previous one.
7. Output boundary: MIDI is the main artifact
- Across the README and filenames, MIDI is the key interchange format.
- GenMidi.py, older song_gen.py, and legacy files like test_midi.py indicate that the system’s output is designed to be imported into external audio tooling rather than producing final mastered audio itself.
- The repository therefore sits upstream of a DAW or synth/rendering pipeline.
8. Audio playback / rendering integration
- The root fluidsynth.sh and the Godot app under musicgeneratorapp/ suggest a playback/rendering path around FluidSynth.
- musicgeneratorapp/Scripts/FluidSynthInstruments.gd and Main.gd imply a UI/frontend that can select or manage instruments and drive playback of generated music.
- This is a distinct boundary from the Python generator: Python creates music data, while the app handles user interaction and audio presentation.
9. Godot app as the user-facing layer
- Version 4 (dev)/musicgeneratorapp/ is a separate frontend project built in Godot.
- Its scene and script structure (Scenes/Main.tscn, Scripts/Main.gd, project.godot) indicates a lightweight application shell around the generation/playback workflow.
- In an architecture diagram, this should be shown as a client UI that invokes or consumes the generator, not as the generation engine itself.
10. Stable and deprecated versions show the architecture’s evolution
- Version 3 (stable)/SongGen.py is the last compact Python-only version and likely represents the mature single-file generator.
- Version 2 (deprecated)/Song Generator.ipynb shows the notebook-era prototype.
- Version 1 (deprecated)/ contains low-level note/sound libraries (noteLib.py, soundLib.py, music.java, songs.java, generator.py) and raw artifacts such as Africa.mid, which suggests early experimentation with direct synthesis and MIDI generation.
11. Legacy V1 differs architecturally from V3/V4
- Version 1 generated sounds directly, with a stronger coupling between note logic and playback/synthesis.
- Version 3 and especially Version 4 move toward a cleaner separation: theory/rules, generation modules, song orchestration, and output/export.
- That shift is one of the main architectural themes of the repo.
12. Testing and experiments
- Files like Version 4 (dev)/Generators/test1.py, Version 4 (dev)/test1, and Version 4 (dev)/test1.c look like experimentation or proof-of-concept code rather than core product paths.
- They are useful to note as auxiliary development artifacts, but they are not central subsystems.
13. Important boundaries to draw
- Input/configuration boundary: genre choice, key/mode, structure, and style parameters.
- Core generation boundary: chord, melody, rhythm, drums, harmony modules.
- Artifact boundary: MIDI generation and any files handed to external tools.
- Presentation/playback boundary: Godot UI and FluidSynth-based playback/rendering.
14. How to diagram the system
- Show Version 4 as the main architecture.
- Place SongGen.py/RunSongGen.py at the center.
- Feed it from the Genres package and fan out into the Generators modules.
- Route output through GenMidi.py to MIDI files, then optionally through FluidSynth/Godot for playback or user interaction.
- Treat Versions 1–3 as historical layers that explain the design evolution, not as the active runtime path.
Main entry points: SongGen.py SongGen.py · GenMidi.py GenMidi.py · GenreDefinitions Genre defs · GenRhythm.py Rhythm
Components 18
Version 4 Core
Active Python generation pipeline.
- RunSongGen.py · Command-line entrypoint for starting generation.
Version 4 (dev)/RunSongGen.py - SongGen.py · Main generator coordinator for Version 4.
Version 4 (dev)/SongGen.py - Chords · Builds chord progressions.
Version 4 (dev)/Generators/GenChords.py - Harmony · Adds harmonic parts and voicings.
Version 4 (dev)/Generators/GenHarmony.py - Melody · Generates lead melody lines.
Version 4 (dev)/Generators/GenMelody.py - Rhythm · Creates rhythmic patterns and timing.
Version 4 (dev)/Generators/GenRhythm.py - Drums · Generates percussion parts.
Version 4 (dev)/Generators/GenDrums.py - GenMidi.py · Assembles and writes MIDI output.
Version 4 (dev)/Generators/GenMidi.py
Version 4 Genres
Genre presets and parameter definitions.
- DefineGenre.py · Selects or resolves genre configuration.
Version 4 (dev)/Genres/DefineGenre.py - Genre defs · Concrete genre rule sets and templates.
Version 4 (dev)/Genres/GenreDefinitions - MelodyInfo · Melody constraints and metadata.
Version 4 (dev)/Genres/MelodyInfo.py - RhythmInfo · Rhythm constraints and metadata.
Version 4 (dev)/Genres/RhythmInfo.py - StructureInfo · Song structure templates and metadata.
Version 4 (dev)/Genres/StructureInfo.py - MidiInfo · MIDI-oriented configuration metadata.
Version 4 (dev)/Genres/MidiInfo.py
Version 4 UI
Godot playback and interaction layer.
- Godot app · User-facing playback and control shell.
Version 4 (dev)/musicgeneratorapp
History
Deprecated and stable predecessors.
- V3 SongGen · Previous compact stable Python generator.
Version 3 (stable)/SongGen.py - V2 notebook · Notebook-era prototype generation workflow.
Version 2 (deprecated)/Song Generator.ipynb - V1 legacy · Early note/sound-centric generation and playback code.
Version 1 (deprecated)
Connections 25
- RunSongGen.py → SongGen.py: starts · CLI entrypoint launches the orchestrator.
- SongGen.py → DefineGenre.py: loads · Orchestrator resolves genre configuration.
- DefineGenre.py → Genre defs: selects · Genre router chooses a concrete preset.
- Genre defs → MelodyInfo: feeds · Genre presets populate melody constraints.
- Genre defs → RhythmInfo: feeds · Genre presets populate rhythm constraints.
- Genre defs → StructureInfo: feeds · Genre presets populate song structure.
- Genre defs → MidiInfo: feeds · Genre presets populate MIDI settings.
- SongGen.py → Chords: drives · Core orchestration starts harmonic construction.
- Chords → Harmony: extends · Chord material is elaborated into harmony.
- RhythmInfo → Rhythm: constrains · Rhythm parameters shape rhythmic generation.
- MelodyInfo → Melody: constrains · Melody parameters shape melodic generation.
- StructureInfo → SongGen.py: shapes · Structure metadata influences orchestration.
- Rhythm → Drums: supports · Rhythmic patterns inform percussion generation.
- SongGen.py → Melody: drives · Orchestrator coordinates melodic generation.
- SongGen.py → Rhythm: drives · Orchestrator coordinates rhythmic generation.
- SongGen.py → Drums: drives · Orchestrator coordinates drum generation.
- Chords → GenMidi.py: exports · Generated musical parts are assembled into MIDI.
- Harmony → GenMidi.py: exports · Harmony is written into the MIDI artifact.
- Melody → GenMidi.py: exports · Melody is written into the MIDI artifact.
- Rhythm → GenMidi.py: exports · Rhythmic data is written into the MIDI artifact.
- Drums → GenMidi.py: exports · Drum tracks are written into the MIDI artifact.
- GenMidi.py → Godot app: plays · Generated MIDI can be consumed by the Godot frontend.
- SongGen.py → V3 SongGen: evolved from · Version 4 grows out of the stable single-file generator.
- V3 SongGen → V2 notebook: evolved from · Stable script follows the notebook prototype.
- V2 notebook → V1 legacy: evolved from · Notebook prototype grew from early legacy code.