Every line of code has a melody. CodeSonify transforms source code into real music. Functions become melodies, loops become rhythms, conditionals become chord changes, and bugs sound dissonant. Export to MIDI, sonify git diffs, and hear the evolution of your codebase β all integrated into GitHub Copilot via MCP.
Try it yourself: Clone the repo, run npm start, and open http://localhost:3000
Paste any code β JavaScript, TypeScript, Python, Java, C#, Go, Rust β and hear it as music. Each programming construct maps to a distinct musical element:
| Code Structure | Musical Element | Why |
|---|---|---|
| Functions | Ascending melodic phrases | Functions are the building blocks β they create the melody |
| Loops | Repeating rhythmic patterns | Loops repeat β just like rhythm |
| Conditionals | Harmonic chord changes | if/else creates branching paths β like harmonic tension and resolution |
| Variables | Deep bass notes | Variables are the foundation β like bass in music |
| Classes | Power chords | Classes are structures β rich, layered chords |
| Comments | Ambient pads | Comments are the quiet spaces between the code |
| Errors | Dissonant clusters | Bugs should sound bad β because they are |
| Nesting depth | Octave (pitch) | Deeper nesting = higher pitch = more tension |
| Complexity | Tempo (BPM) | Complex code plays faster and more intensely |
| Language | Musical key | Each language has its own key signature |
Export any sonification as a real .mid file that opens in GarageBand, FL Studio, Ableton, Logic Pro, or any DAW. Your code becomes real, editable, shareable music.
Sonify git diffs and code changes:
- Added lines β Bright, ascending melodies in major key
- Removed lines β Dark, descending bass in minor key
- Context β Soft ambient background
- Hear a refactoring as a musical journey from tension to resolution
| Style | Key | Character |
|---|---|---|
| π» Classical | C Major | Elegant, sine/triangle waves |
| πΉ Electronic | A Minor | Driving, square/sawtooth waves |
| π Ambient | D Pentatonic | Dreamy, heavy reverb |
| π· Jazz | F Dorian | Warm, swing feel |
| πΈ Rock | E Blues | Aggressive, distorted |
CodeSonify integrates directly into VS Code via MCP, giving GitHub Copilot 5 powerful tools:
| # | Tool | What it does |
|---|---|---|
| 1 | sonify_code |
Transform any code into a full musical composition |
| 2 | analyze_code_structure |
Get code metrics: complexity, functions, nesting, loops |
| 3 | compare_code_musically |
Compare two code snippets by their musical output |
| 4 | sonify_git_diff |
Turn git diffs into music β hear your code reviews |
| 5 | export_midi |
Export code as a real MIDI file for music production |
A polished, real-time web interface featuring:
- Code editor with syntax highlighting
- Real-time canvas visualization with animated note particles
- Live audio playback using Tone.js Web Audio synthesis
- Stats dashboard showing tempo, key, complexity, notes, duration, tracks
- Track breakdown with per-instrument volume bars
- Musical interpretation β human-readable description of what the music represents
- Diff Mode β compare old vs new code versions visually and musically
- MIDI download β one-click export to .mid file
- Node.js v18 or later
- VS Code with GitHub Copilot (for MCP integration)
# Clone the repository
git clone https://github.com/YOUR_USERNAME/codesonify.git
cd codesonify
# Install dependencies
npm install
# Start the web application
npm startOpen http://localhost:3000 in your browser. Paste code, pick a style, and click Sonify Code. π΅
- Open the project folder in VS Code
- Open
.vscode/mcp.jsonβ click the "Start" button that appears - Open Copilot Chat (
Ctrl+Shift+I) β switch to Agent Mode - Try these prompts:
Sonify this code: function fibonacci(n) { if (n <= 1) return n; return fibonacci(n-1) + fibonacci(n-2); }
Analyze the code structure of my current file
Export this as MIDI: const greet = (name) => console.log(`Hello ${name}`)
Sonify the diff between these:
Old: "function add(a,b) { return a+b; }"
New: "const add = (a: number, b: number): number => a + b;"
codesonify/
βββ src/
β βββ core/ # Core analysis and music engine
β β βββ types.ts # TypeScript type definitions (40+ types)
β β βββ parser.ts # Code structure analyzer & tokenizer
β β βββ mapper.ts # Code-to-music mapping engine (8 scales, 5 styles)
β β βββ composer.ts # Composition orchestrator
β β βββ midi.ts # Pure TypeScript MIDI file generator (zero dependencies)
β β βββ diff.ts # Git diff parser & sonification engine
β β βββ index.ts # Module exports
β βββ mcp/ # MCP Server for VS Code / GitHub Copilot
β β βββ index.ts # MCP server with 5 tools
β βββ web/ # Web application
β βββ server.ts # Express API server (5 endpoints)
β βββ public/
β βββ index.html # Frontend (Tone.js + Canvas visualization)
βββ docs/
β βββ copilot-usage/ # Screenshots of GitHub Copilot usage
βββ .vscode/
β βββ mcp.json # MCP server configuration for VS Code
βββ .gitignore
βββ package.json
βββ tsconfig.json
βββ LICENSE
βββ README.md
GitHub Copilot was instrumental throughout the entire development of CodeSonify. Here's how AI-assisted development shaped this project:
- Brainstormed the mapping between programming constructs and musical elements
- Designed the TypeScript type system with 40+ types for code analysis and music composition
- Explored which musical scales best represent each programming language
- Debugged audio timing issues with Tone.js Web Audio API
- Auto-completed musical scale definitions (major, minor, pentatonic, blues, dorian, mixolydian, lydian, chromatic)
- Generated Express route handlers with input validation
- Suggested the canvas visualization algorithm for animated note particles
- Completed the MIDI binary format implementation (variable-length quantities, track chunks)
- Used Copilot to explore different approaches to code complexity scoring
- Generated example code snippets that showcase diverse musical outputs
- Helped design the diff-to-music mapping logic (ascending = additions, descending = deletions)
- Copilot Chat helped structure the MCP tool definitions with proper Zod schemas
- Generated the formatted markdown output for each tool response
- Assisted with the comparison table formatting in
compare_code_musically
πΈ Screenshots of these interactions are in
docs/copilot-usage/
Transform code into music.
Request:
{
"code": "function hello() { console.log('world'); }",
"language": "javascript",
"style": "classical"
}Response: Full composition with tracks, notes, analysis, and visualization data.
Export code as a downloadable MIDI file.
Request: Same as /api/sonify
Response: Binary .mid file download.
Sonify code changes.
Request:
{
"old_code": "function add(a,b) { return a+b; }",
"new_code": "const add = (a: number, b: number): number => a + b;",
"style": "electronic"
}Get example code snippets for demo.
Health check.
| Criteria | Weight | How CodeSonify Delivers |
|---|---|---|
| Accuracy & Relevance | 20% | Fully meets Creative Apps track requirements. Extensive GitHub Copilot usage documented. MCP server with 5 tools integrated into VS Code. |
| Reasoning & Multi-step Thinking | 20% | 7-step pipeline: Code β Tokenize β Analyze β Map β Compose β Visualize β Play. Diff analysis adds comparison reasoning. MIDI export adds format transformation. |
| Creativity & Originality | 15% | First-of-its-kind code sonification tool. Unique concept bridging programming and music. Diff sonification has never been done. MIDI export makes it tangible. |
| User Experience & Presentation | 15% | Polished web UI with real-time visualization, 5 musical styles, Diff Mode, MIDI download, example code, animated particles, playback controls. |
| Reliability & Safety | 20% | TypeScript strict mode throughout, input validation on all endpoints, error handling with user-friendly messages, no secrets/PII, public repo, MIT license. |
| Community Vote | 10% | Viral concept β "hear your code" is immediately shareable. Fun to demo. Everyone can try it. MIDI export makes it tangible and social. |
| Technology | Purpose |
|---|---|
| TypeScript | Type-safe code throughout (strict mode) |
| MCP SDK | Model Context Protocol for VS Code/Copilot integration |
| Express 5 | Web server and REST API |
| Tone.js | Web Audio synthesis and real-time playback |
| Canvas API | Animated note particle visualization |
| Zod | Runtime input validation for MCP tools |
| GitHub Copilot | AI-assisted development throughout |
- Code Review β Sonify a pull request diff and hear if the changes feel harmonious or chaotic
- Education β Help students understand code structure through musical metaphor
- Accessibility β Provide auditory feedback for visually impaired developers
- Team Building β Turn your team's code into a collaborative soundtrack
- Art β Generate music from open-source projects and create "code albums"
- Quality Monitoring β Complexity score as tempo: if your code sounds like speed metal, maybe refactor
MIT License β free to use, modify, and distribute.
- Built for Agents League 2026 by Microsoft
- Powered by GitHub Copilot
- Audio synthesis by Tone.js
- MCP integration via @modelcontextprotocol/sdk
π΅ Where every line of code has a melody π΅