code-to-music

132
12
Source

Tools, patterns, and utilities for creating music with code. Output as a .mp3 file with realistic instrument sounds. Write custom compositions to bring creativity to life through music. This skill should be used whenever the user asks for music to be created. Never use this skill for replicating songs, beats, riffs, or other sensitive works. The skill is not suitable for vocal/lyrical music, audio mixing/mastering (reverb, EQ, compression), real-time MIDI playback, or professional studio recording quality.

Install

mkdir -p .claude/skills/code-to-music && curl -L -o skill.zip "https://mcp.directory/api/skills/download/290" && unzip -o skill.zip -d .claude/skills/code-to-music && rm skill.zip

Installs to .claude/skills/code-to-music

About this skill

This skill provides tools and patterns for music composition, not pre-baked solutions. The intelligence and music21 library should be used to compose dynamically based on user requests.

Core Principle: Write custom code that composes music algorithmically rather than calling functions with hardcoded melodies.

Installation & Setup

Quick Installation

Run the automated installer for complete setup: install.sh. This installs all system dependencies, Python packages, and verifies the installation.

Note: The install script may display "error: externally-managed-environment" messages at the end. These are expected and can be safely ignored - the dependencies are already installed. If such messages appear, the installation was successful.

Available SoundFonts

Traditional Pipeline (Orchestral/Acoustic):

  • /usr/share/sounds/sf2/FluidR3_GM.sf2 (141MB, General MIDI soundfont - use for high-quality orchestral/acoustic samples)
  • /usr/share/sounds/sf2/default.sf2 (symlink to best available)
  • ⚠️ DO NOT use TimGM6mb.sf2 - inferior quality, guitars sound electronic/piano-like

Electronic Pipeline:

  • Uses the same FluidR3_GM.sf2 soundfont as traditional music
  • The difference is which GM programs you choose (synth programs 38-39, 80-95 instead of orchestral)

Key Concepts

  • Always create downloadable MP3 files (not HTML players)
  • music21.instrument classes can be used for convenience: instrument.Violin(), instrument.Violoncello(), instrument.Piano(), instrument.Trumpet(), etc.
  • CRITICAL: ALWAYS use mido to set MIDI program numbers after export - music21's instrument classes do NOT reliably export program_change messages. See the mido workflow below.
  • Generate notes programmatically - avoid hardcoded sequences

Choosing Your Music Generation Pipeline

This skill supports TWO rendering pipelines optimized for different musical styles. Read the user's request carefully and choose the correct pipeline by reading the correct next file.

Decision Process

Identify from the user's request:

  • Genre keywords (house, techno, classical, orchestral, reggae)
  • Instrument references (synthesizers vs acoustic instruments)
  • Musical style descriptions (electronic/DJ vs traditional/acoustic)
  • Artist mentions (DJs vs classical composers)

Electronic Pipeline

Use electronic-music-pipeline.md when request includes:

  • Genres: House, techno, trance, EDM, electronic dance music, ambient electronic, acid house, deep house, club music, DJ sets
  • Instruments: Synthesizers, synth bass/pads/leads, 808 drums, electronic drums, supersaw leads, sub-bass
  • Context: References to DJs (Keinemusik, Black Coffee, Avicii, Swedish House Mafia), BPM 120-140, "for a club", "for dancing"
  • Sound descriptions: "Fat synth sound", "buzzy leads", "electronic", "synth-heavy"

How it works:

  • Uses real-time synthesis (no soundfonts)
  • Synthesizes drums, bass, pads, leads on-the-fly with DSP
  • Genre presets optimize synthesis parameters (deep_house, techno, trance, ambient, acid_house)
  • Frequency-aware mixing automatically balances low/mid/high frequencies
  • Best for: Authentic electronic sounds, modern EDM production

→ See electronic-music-pipeline.md for detailed instructions


Traditional Pipeline

Use traditional-music-pipeline.md when request includes:

  • Genres: Classical, orchestral, jazz, blues, rock, country, folk, reggae, ska, symphonic, chamber music
  • Instruments: Violin, cello, trumpet, flute, piano, acoustic guitar, acoustic bass, brass ensembles, string quartets, organ (reggae/gospel)
  • Context: References to composers (Mozart, Beethoven, Bach), classical periods (Baroque, Romantic), "unplugged", "acoustic version"
  • Sound descriptions: "Traditional", "acoustic", "orchestral"

How it works:

  • Uses pre-recorded orchestral samples (soundfonts)
  • FluidR3_GM.sf2 soundfont with 128 General MIDI instruments
  • Good for realistic orchestral/acoustic instruments
  • Best for: Classical, jazz, reggae, rock, traditional music

→ See traditional-music-pipeline.md for detailed instructions


If Unclear

  • Default to TRADITIONAL for mixed requests or ambiguous genres
  • Ask user for clarification if request could go either way

Why This Matters

  • Using wrong pipeline = poor audio quality (technically works, sounds bad)
  • Electronic pipeline: Real-time synthesis for authentic electronic sounds
  • Traditional pipeline: Pre-recorded samples for realistic orchestral/acoustic

Available Scripts

All scripts are located in ./scripts:

Traditional Rendering:

  • midi_inventory.py - Extract complete structure from ANY MIDI file to JSON format
  • midi_render.py - Render JSON music structure to MP3 using FluidSynth with dynamic range compression
  • midi_utils.py - MIDI utility functions (extract drums, get BPM, etc.)

Utilities:

  • audio_validate.py - Validate audio file quality and format

Note: Both electronic and traditional music use the same rendering pipeline (FluidSynth + FluidR3_GM.sf2). The difference is which GM programs you choose.

Music Theory Reference

Complete General MIDI Instrument Map (Programs 0-127)

CRITICAL: music21 does NOT reliably export program_change messages. You MUST ALWAYS use mido to set program numbers after export, even for traditional instruments like saxophone, guitar, or bass. Without this step, tracks will default to piano (program 0).

INSTRUMENT CATEGORIZATION FOR SYNTHESIS: When composing electronic music, classify instruments by their sonic characteristics for proper synthesis:

  • Guitar (24-31): Plucky attack, bright tone, medium sustain - needs distinct synthesis from pads
  • Bass (32-39): Low-frequency fundamentals, sub-bass energy, short attack
  • Strings (40-47): Sustained bowing, rich harmonics, smooth legato
  • Brass (56-63): Bright attack, sustained tone, powerful projection
  • Reed/Woodwinds (64-79): Breathy attack, organic timbre, expressive dynamics
  • Synth Lead (80-87): Bright, cutting, aggressive - designed for melody
  • Synth Pad (88-95): Soft attack, long sustain, atmospheric - designed for background
  • Ethnic/Percussive (104-119): Plucky or struck sounds with unique timbres
# Piano (0-7)
0: "Acoustic Grand Piano"
1: "Bright Acoustic Piano"
2: "Electric Grand Piano"
3: "Honky-tonk Piano"
4: "Electric Piano 1"
5: "Electric Piano 2"
6: "Harpsichord"
7: "Clavinet"

# Chromatic Percussion (8-15)
8: "Celesta"
9: "Glockenspiel"
10: "Music Box"
11: "Vibraphone"
12: "Marimba"
13: "Xylophone"
14: "Tubular Bells"
15: "Dulcimer"

# Organ (16-23)
16: "Drawbar Organ"
17: "Percussive Organ"
18: "Rock Organ"
19: "Church Organ"
20: "Reed Organ"
21: "Accordion"
22: "Harmonica"
23: "Tango Accordion"

# Guitar (24-31)
24: "Acoustic Guitar (nylon)"
25: "Acoustic Guitar (steel)"
26: "Electric Guitar (jazz)"
27: "Electric Guitar (clean)"
28: "Electric Guitar (muted)"
29: "Overdriven Guitar"
30: "Distortion Guitar"
31: "Guitar Harmonics"

# Bass (32-39)
32: "Acoustic Bass"
33: "Electric Bass (finger)"
34: "Electric Bass (pick)"
35: "Fretless Bass"
36: "Slap Bass 1"
37: "Slap Bass 2"
38: "Synth Bass 1"
39: "Synth Bass 2"

# Strings (40-47)
40: "Violin"
41: "Viola"
42: "Cello"
43: "Contrabass"
44: "Tremolo Strings"
45: "Pizzicato Strings"
46: "Orchestral Harp"
47: "Timpani"

# Ensemble (48-55)
48: "String Ensemble 1"
49: "String Ensemble 2"
50: "Synth Strings 1"
51: "Synth Strings 2"
52: "Choir Aahs"
53: "Voice Oohs"
54: "Synth Voice"
55: "Orchestra Hit"

# Brass (56-63)
56: "Trumpet"
57: "Trombone"
58: "Tuba"
59: "Muted Trumpet"
60: "French Horn"
61: "Brass Section"
62: "Synth Brass 1"
63: "Synth Brass 2"

# Reed (64-71)
64: "Soprano Sax"
65: "Alto Sax"
66: "Tenor Sax"
67: "Baritone Sax"
68: "Oboe"
69: "English Horn"
70: "Bassoon"
71: "Clarinet"

# Pipe (72-79)
72: "Piccolo"
73: "Flute"
74: "Recorder"
75: "Pan Flute"
76: "Blown Bottle"
77: "Shakuhachi"
78: "Whistle"
79: "Ocarina"

# Synth Lead (80-87)
80: "Lead 1 (square)"
81: "Lead 2 (sawtooth)"
82: "Lead 3 (calliope)"
83: "Lead 4 (chiff)"
84: "Lead 5 (charang)"
85: "Lead 6 (voice)"
86: "Lead 7 (fifths)"
87: "Lead 8 (bass + lead)"

# Synth Pad (88-95)
88: "Pad 1 (new age)"
89: "Pad 2 (warm)"
90: "Pad 3 (polysynth)"
91: "Pad 4 (choir)"
92: "Pad 5 (bowed)"
93: "Pad 6 (metallic)"
94: "Pad 7 (halo)"
95: "Pad 8 (sweep)"

# Synth Effects (96-103)
96: "FX 1 (rain)"
97: "FX 2 (soundtrack)"
98: "FX 3 (crystal)"
99: "FX 4 (atmosphere)"
100: "FX 5 (brightness)"
101: "FX 6 (goblins)"
102: "FX 7 (echoes)"
103: "FX 8 (sci-fi)"

# Ethnic (104-111)
104: "Sitar"
105: "Banjo"
106: "Shamisen"
107: "Koto"
108: "Kalimba"
109: "Bag pipe"
110: "Fiddle"
111: "Shanai"

# Percussive (112-119)
112: "Tinkle Bell"
113: "Agogo"
114: "Steel Drums"
115: "Woodblock"
116: "Taiko Drum"
117: "Melodic Tom"
118: "Synth Drum"
119: "Reverse Cymbal"

# Sound Effects (120-127)
120: "Guitar Fret Noise"
121: "Breath Noise"
122: "Seashore"
123: "Bird Tweet"
124: "Telephone Ring"
125: "Helicopter"
126: "Applause"
127: "Gunshot"

Complete Drum Map (MIDI Channel 10, Notes 35-81)

Drums use note numbers for different sounds, NOT pitch. Must be on channel 10 (9 in 0-indexed).

# Bass Drums
35: "Acoustic Bass Drum"
36: "Bass Drum 1"  # Most common kick

# Snares
38: "Acoustic Snare"  # Standard snare
40: "Electric Snare"

# Toms
41: "Low Floor Tom"
43: "High Floor Tom"
45: "Low Tom"
47: "Low-Mid Tom"
48: "Hi-Mid Tom"
50: "High Tom"

# Hi-Hats
42: "Closed Hi-Hat"  # Most used
44: "Pedal Hi-Hat"
46: "Open Hi-Hat"

# Cymbals
49: "Crash Cymbal 1"
51: "Ride Cymbal 1"
52: "Chinese Cymbal"
53: "Ride Bell"
55: "Splash Cymbal"
57: "Crash Cymbal 2"
59: "Ride Cymbal 2"

# Percussion
37: "Side Stick"
39: "Hand Clap"
54: "Tambourine"
56: "Cowbell"
58: "Vibraslap"
60: "Hi Bongo"
61: "Low Bongo"
62: "Mute Hi Conga"
63: "Open Hi Conga"
64: "Low Conga"
65: "High Timba

---

*Content truncated.*

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

1,5731,370

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

1,1161,191

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

1,4181,109

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

1,198748

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

1,155684

pdf-to-markdown

aliceisjustplaying

Convert entire PDF documents to clean, structured Markdown for full context loading. Use this skill when the user wants to extract ALL text from a PDF into context (not grep/search), when discussing or analyzing PDF content in full, when the user mentions "load the whole PDF", "bring the PDF into context", "read the entire PDF", or when partial extraction/grepping would miss important context. This is the preferred method for PDF text extraction over page-by-page or grep approaches.

1,318617

Stay ahead of the MCP ecosystem

Get weekly updates on new skills and servers.