AI-powered music composition and harmony analysis — generating melodic structures, chord progressions, and arrangement suggestions with generative AI.
Topics: audio-ml · creative-ai · deep-learning · generative-ai · large-language-models · music-ai · music-generation · neural-audio · neural-networks · sound-synthesis
HarmoniaX is a generative music intelligence platform that applies AI to two complementary problems: analysis and generation. On the analysis side, it parses uploaded MIDI files or audio recordings to extract chord progressions, identify key and mode, compute harmonic tension curves, and detect structural patterns (verse/chorus, AABA form). On the generation side, it uses generative models to suggest chord progressions, melodic continuations, and full arrangements given a seed melody or harmonic context.
The generation engine draws on multiple approaches depending on the task: a fine-tuned transformer model handles melodic continuation and chord sequence generation; a rule-based harmonisation engine applies classical voice-leading principles for four-part SATB writing; and an LLM-powered arrangement advisor translates abstract musical intent ("make this sound cinematic and melancholic") into concrete instrumentation and dynamic guidance.
The application is designed for both musicians who want AI as a creative collaborator and non-musicians who want to explore music generation without formal training. An interactive piano roll display makes generated MIDI immediately visible and audible, with playback in the browser via WebAudio API.
Music composition is one of the highest forms of creative expression, yet it has a steep learning curve: harmony theory, voice leading, form, and orchestration each take years to master. HarmoniaX was built to lower the barrier of entry for music creation — not by replacing human creativity, but by providing an intelligent assistant that handles the mechanical constraints of harmony and arrangement, freeing the human to focus on the emotional and expressive dimensions of their music.
User Input: Seed melody (MIDI / hummed) or text prompt
│
┌──────────────────────────────────────────────┐
│ Analysis Engine: │
│ MIDI parsing → chord detection → key/mode │
│ Harmonic tension curve computation │
└──────────────────────────────────────────────┘
│
┌──────────────────────────────────────────────┐
│ Generation Engine: │
│ ├── Transformer: melodic continuation │
│ ├── Rule-based: SATB harmonisation │
│ └── LLM advisor: arrangement suggestions │
└──────────────────────────────────────────────┘
│
Piano roll display + MIDI export + audio playback
Parse uploaded MIDI files to extract chord progressions, tempo, time signature, key/mode (using Krumhansl-Schmuckler key-finding algorithm), and structural segmentation.
Generate contextually appropriate chord progressions in any key and mode — from simple I-IV-V-I to jazz-influenced secondary dominants and modal interchange.
Given a seed melody of 4–16 bars, generate musically coherent continuations that respect the established harmonic context and rhythmic character.
Four-part (Soprano/Alto/Tenor/Bass) harmonisation of a given melody following classical voice-leading rules: minimal voice movement, no parallel fifths/octaves, correct resolution of dissonances.
Natural language arrangement suggestions: paste a text description of the desired mood and style, receive specific instrumentation, dynamics, and texture recommendations.
Plot of harmonic tension (dissonance level) across the composition over time, helping composers identify emotional arcs and climax points.
Generated MIDI displayed as an interactive piano roll with playback via Tone.js, allowing immediate audition and manual editing before export.
All generated content exportable as standard MIDI files compatible with any DAW (Ableton, Logic, GarageBand, FL Studio).
| Library / Tool | Role | Why This Choice |
|---|---|---|
| music21 | Music analysis | Chord detection, key analysis, SATB harmonisation, MIDI I/O |
| Magenta (optional) | Generative models | Melody RNN and Music Transformer for continuation |
| Streamlit | Application UI | Piano roll display, file upload, playback integration |
| OpenAI/Gemini API | Arrangement advisor | LLM-powered text-to-arrangement recommendations |
| midiutil | MIDI generation | Programmatic MIDI file creation |
| NumPy | Signal processing | Harmonic tension curve computation |
| Tone.js (JS, optional) | Browser audio | WebAudio-based MIDI playback in Streamlit WebView |
- Python 3.9+ (or Node.js 18+ for TypeScript/JavaScript projects)
- A virtual environment manager (
venv,conda, or equivalent) - API keys as listed in the Configuration section
git clone https://github.com/Devanik21/HarmoniaX.git
cd HarmoniaX
python -m venv venv && source venv/bin/activate
pip install streamlit music21 numpy midiutil openai python-dotenv
echo 'OPENAI_API_KEY=sk-...' > .env
streamlit run app.py# Launch the application
streamlit run app.py
# Analyse a MIDI file from CLI
python analyse_midi.py --input composition.mid --output analysis_report.json
# Generate chord progression
python generate_chords.py --key C --mode major --length 8 --style jazz
# Harmonise a melody
python harmonise.py --melody melody.mid --voices 4 --output harmonised.mid| Variable | Default | Description |
|---|---|---|
OPENAI_API_KEY |
(optional) |
For LLM arrangement advisor feature |
DEFAULT_KEY |
C |
Default key for generation |
DEFAULT_MODE |
major |
Default mode: major, minor, dorian, mixolydian |
GENERATION_BARS |
8 |
Default number of bars to generate |
TEMPO_BPM |
120 |
Default generation tempo |
Copy
.env.exampleto.envand populate required values before running.
HarmoniaX/
├── README.md
├── requirements.txt
├── app.py
└── ...
- Real-time collaborative composition mode with WebSocket-based multi-user piano roll
- Style transfer: reharmonise a melody in the style of specific composers (Bach, Bill Evans, John Williams)
- Lyric writing assistant aligned to melodic rhythm and syllable count
- Audio-to-MIDI transcription using basic-pitch for uploading recorded performances
- Integration with Ableton Live and Logic Pro X via OSC protocol for DAW-connected generation
Contributions, issues, and suggestions are welcome.
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-idea - Commit your changes:
git commit -m 'feat: add your idea' - Push to your branch:
git push origin feature/your-idea - Open a Pull Request with a clear description
Please follow conventional commit messages and add documentation for new features.
The SATB harmonisation engine applies classical common-practice voice-leading rules and is most appropriate for tonal music. Jazz and contemporary styles may benefit from the LLM advisor for more idiomatic voicings. Magenta models require separate installation and add ~2GB of model weight downloads.
Devanik Debnath
B.Tech, Electronics & Communication Engineering
National Institute of Technology Agartala
This project is open source and available under the MIT License.
Built with curiosity, depth, and care — because good projects deserve good documentation.