Inspiration

As a composer and pianist, music has always been one of the most reliable ways for me to regulate my emotions. When I feel overwhelmed, anxious, or mentally overloaded, sitting down at a piano and playing simple, repetitive chord progressions helps calm my thoughts and slow everything down. Over time I noticed that certain musical structures naturally guided my mental state back toward focus and stability.

That observation inspired this project. What if we could take the emotional signals someone is experiencing and automatically translate them into music designed to help regulate that state?

Instead of telling someone to relax, breathe, or meditate, we wanted to build a system that literally composes music intended to guide the listener toward a calmer or more focused mental state.

The Algorithmic Composer explores that idea by turning emotional inputs into playable piano music.


What it does

The Algorithmic Composer converts emotional and physiological signals into therapeutic piano compositions.

Users can input their emotional state in two ways:

  • Adjust sliders for stress, energy, and heart rate
  • Describe how they feel using natural language

An AI mood interpreter analyzes the text input and converts it into a structured emotional profile. That profile feeds into a deterministic music engine that generates a musical composition designed to regulate the user's emotional state.

The system determines:

  • Musical key
  • Chord progression
  • Tempo
  • Melodic motion
  • Harmonic resolution patterns

The generated music can then be:

  • Played instantly in the browser
  • Downloaded as a MIDI composition
  • Performed live on a keyboard

The goal is to transform emotional data into structured music that encourages relaxation, focus, or emotional regulation.


How we built it

The project consists of three major components.

Streamlit Front-End

We built the interface using Streamlit to create a clean, interactive environment where users can adjust emotional inputs or describe how they feel. The interface dynamically generates compositions and presents them with explanations and live audio playback.

Deterministic Music Engine

The core of the system is a rule-based music generator grounded in simple music theory and emotional regulation principles. Based on user inputs, the engine determines tempo adjustments, chord progressions, and melodic motion patterns.

For example:

  • Higher stress lowers tempo
  • Higher heart rate reduces rhythmic density
  • Certain moods map to specific harmonic progressions

This deterministic approach ensures the system is predictable and reliable during live demonstrations.

AI Mood Interpreter

We integrated a lightweight AI layer using Claude to translate natural language emotional descriptions into structured emotional inputs. The AI does not generate the music itself. Instead, it converts text such as "I feel overwhelmed before an exam" into numerical values for stress, energy, heart rate, and mood classification.

Audio and MIDI Generation

To make the experience interactive, we implemented:

  • Real-time audio synthesis for browser playback
  • Piano-like chord rendering with layered harmonics
  • MIDI export using pretty_midi so the composition can be opened in music software or played live

This allowed us to demonstrate the music both digitally and on a physical keyboard.


Challenges we ran into

One of the biggest challenges was balancing musical complexity with reliability.

Music generation systems can quickly become unpredictable, especially when AI is directly responsible for composition. For a hackathon demo, we needed something that would produce musically coherent results every time.

To solve this, we designed the system so that AI only interprets emotional input, while the music generation itself remains deterministic.

Another challenge was generating convincing piano audio without relying on heavy audio libraries or external synthesis engines. We solved this by writing a lightweight waveform generator that layers harmonic sine waves to approximate a piano sound.

Finally, mapping emotional states to music in a meaningful way required careful tuning so that the output felt intentional rather than random.


Accomplishments that we're proud of

We are proud that the system produces real musical compositions that can be played, downloaded, and performed live.

Some highlights include:

  • Real-time music generation based on emotional inputs
  • Browser-based audio playback without external synthesis tools
  • Downloadable MIDI compositions
  • AI-assisted mood interpretation
  • Live keyboard performance capability

Most importantly, we built a system that connects emotional states to musical structure in a way that feels intuitive and engaging.


What we learned

This project taught us how closely music theory, emotional perception, and computational systems can interact.

We learned how to:

  • Translate emotional data into structured algorithmic rules
  • Build interactive music systems in Python
  • Combine deterministic systems with AI interpretation
  • Generate audio programmatically without traditional synthesis tools

We also learned that simple musical ideas such as predictable chord progressions and controlled tempo changes can have a surprisingly strong emotional impact when used intentionally.


What's next for The Algorithmic Composer

There are several directions we would like to explore next.

One exciting possibility is integrating biometric data from wearable devices, such as real-time heart rate. This would allow the system to dynamically adapt the music as the user's physiological state changes.

We are also interested in expanding the music engine to support multiple instruments and richer compositions.

Another future direction would be creating a feedback loop where the system analyzes how the user's state changes after listening to the generated music and adjusts future compositions accordingly.

Ultimately, we see The Algorithmic Composer evolving into a personalized music-based emotional regulation tool that bridges technology, creativity, and mental wellness.

Built With

  • music
  • musictheory
  • numpy-style
  • pretty-midi
  • python
  • streamlit
  • wave
Share this project:

Updates