Inspiration

I recently started learning guitar and music theory, and I quickly realized that while playing other people's songs is fun, composing your own is a completely different beast. It felt overwhelming. As a developer, I love tools like Copilot, but I've noticed they sometimes encourage "vibe coding" where you get the result but miss the why. I didn't want that for my music. I didn't want an AI that just did the work for me, because that kills the joy of learning. I wanted to build a "scientific calculator" for composers, a tool that helps you solve the problem but ensures you understand the math. Ghost Writer is the mentor I wish I had: an AI that suggests what to play next, but crucially, explains the reasoning behind it so I can actually learn and grow as a musician.

What it does

Ghost Writer is a browser based music editor that transforms the solitary act of composing into a collaborative jam session. It listens to your current track, analyzing the rhythm and harmony to understand exactly where the music is going. Instead of just filling in the blanks, it uses Google's Gemini model to suggest a continuation while acting as a tutor. For every melody it generates, it provides a specific explanation of the music theory behind it. It helps you understand the relationship between notes so you can apply that knowledge to your next project, turning the creative process into a learning moment.

How I built it

I leveraged an existing open source MIDI editor for the user interface, which provided a robust piano roll. This allowed me to focus entirely on the intelligent layer, writing the majority of the logic in TypeScript to build the AI integration. I used the Google GenAI JS SDK to bridge the frontend with Gemini 3 Flash. I engineered a prompt that enforces a specific JSON output structure. This format allows the application to ingest the AI response and instantly render it as playable notes on the grid.

Challenges I ran into

Crafting the prompt was the first major hurdle. I needed the AI to not just output notes but also explain its reasoning, all while adhering to a strict JSON structure that the application could actually parse. Integrating this into a pre-existing MIDI codebase was equally daunting. The logic was complex, involving thousands of lines of code and intricate state management, so figuring out exactly where to inject the AI without breaking the sound engine took time. Finally, manipulating the sensitive HTML5 Canvas to ensure smooth scrolling during generation required precise adjustments to avoid graphical glitches.

Accomplishments that I'm proud of and what I learned

I am proud of successfully transitioning from the Python SDK to the TypeScript ecosystem for this project. It forced me to deepen my understanding of the language while implementing complex AI logic using the JS SDK. Beyond the code, I actually learned the music theory required to build the tool. The project felt daunting at the start because of the moving parts, but I am proud that I didn't compromise. I executed the exact vision I had in mind, creating a tool that actually helps me learn.

What's next for Ghost Writer

I plan to take this beyond the browser. I want to leverage Gemini's 1 million token context window to build plugins for professional DAWs like Logic Pro, FL Studio, and Ableton. This would allow the AI to see the full project context, including audio effects and automation, rather than just the MIDI notes. I also want to add explicit genre selection to the core loop. Right now the AI infers the style, but I want users to be able to select genres like Rock, Indie, or Pop. This gives Gemini a blueprint to follow, ensuring the suggestions are not just musically correct, but stylistically relevant to the specific vibe of the song.

Credits

This project is a fork of Signal by Ryohey. Huge thanks to him and contributors for the wonderful MIDI UI.

Built With

Share this project:

Updates