Inspiration
I've always been fascinated by the connection between mathematics and music.
At some point, I started wondering: can mathematical models actually create music that sounds meaningful?
That question led me to explore algorithmic music generation and eventually write a research paper comparing different Markov-chain approaches for melody generation. Through that project, I learned how simple probabilistic models could produce musical results.
But while working on the paper, I realized something was missing. The research showed the results, but it didn't let people interact with the models or see how they made decisions.
That's why I created MelodyLab.
I wanted to turn those ideas into an interactive experience where anyone could generate melodies, compare different computational models, listen to the results, and watch the composition process unfold note by note.
What it does
MelodyLab is an interactive web application that generates original melodies using different computational approaches.
Users can choose from multiple melody-generation models:
- Random Generation
- Rule-Based Generation
- First-Order Markov Chains
- Second-Order Markov Chains
After selecting a training melody, users can generate a new melody, listen to it directly in the browser, and analyze it using a built-in music-theory scorecard.
One of the app's main features is Learning Mode. Instead of only showing the final melody, MelodyLab can replay the composition process note by note, showing:
- What the model remembered
- What options it considered
- Which note it selected
- Why that note was chosen
The goal is not only to generate music, but also to help users understand how computational models can create musical structure.
How I built it
I built MelodyLab using:
- Python
- Streamlit
- NumPy
The melody-generation models were implemented from scratch. The app currently includes:
- A random melody generator
- A rule-based generator that follows basic musical constraints
- A first-order Markov model that remembers one previous note
- A second-order Markov model that remembers two previous notes
I also developed a music-theory scorecard that evaluates generated melodies using measures such as:
- Smoothness
- Motif repetition
- Rhythmic variety
- Melodic resolution
To make the system educational, I created a composition replay mode that visualizes the model's decision-making process step by step and allows users to inspect how each melody was constructed.
Challenges I ran into
One challenge was turning a research idea into something interactive and easy to understand.
Markov chains are usually explained through equations and probability tables, but I wanted users to learn by experimenting with the models themselves. Designing a Learning Mode that clearly showed how each note was chosen took several iterations.
Another challenge was creating meaningful ways to compare different melody-generation approaches. I developed a music-theory scorecard so users could evaluate generated melodies beyond simply listening to them.
Finally, I had to translate standalone research code into a polished web application with audio playback, visual feedback, and an intuitive user experience.
Accomplishments that I'm proud of
- Turning a research project into an interactive educational tool
- Creating a note-by-note composition replay system
- Designing a music-theory scorecard for generated melodies
- Combining music, mathematics, and computer science into a single application
What I learned
This project taught me that relatively simple computational models can create musical results.
I gained a much deeper understanding of:
- Probability
- Markov chains
- Music theory
- User-interface design
Most importantly, I learned that educational tools become much more engaging when users can explore and experiment for themselves rather than simply reading about a concept.
What's next for MelodyLab
Some improvements I would like to explore in future versions include:
- Allowing users to upload their own melodies for training
- Supporting MIDI import and export
- Adding additional melody-generation techniques and models
- Expanding the music-theory analysis tools
- Adding piano-roll and musical notation visualizations
My long-term goal is to make MelodyLab a fun and accessible way for people to explore the intersection of music, mathematics, and computation.
Log in or sign up for Devpost to join the conversation.