Skill detail

code-to-music

Composes music with code using music21 and soundfonts, rendering to MP3 with electronic or orchestral pipelines; explicitly not for vocal/lyrical music or mixing.

MatchDirectRecommended for Music Generation
Sourcecam10001110101/​claude-skills-baseExternal source
Reported installs43Popularity signal only

Inspect before use

Read the source instructions and check the requirements before you install this skill.

Saved source preview

SKILL.md

The saved excerpt is a snapshot from when this skill was listed. The external source remains the complete and most current version.

---
name: code-to-music
description: 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.
---

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, blu
Read the full source on GitHub (opens external page)
Context

Related work