MIDI, LilyPond, and the Production Pipeline

MIDI, LilyPond, and the Production Pipeline

How a pitch class set becomes a printable score and a streamable audio file — the complete technology stack behind the Sound Cells series.

A finished Sound Cells volume contains several distinct output types: a PDF score in standard music notation, MP3 audio files of the exercises and compositions, MIDI files for playback and further processing, and a metadata manifest linking all the above to the mathematical structure (Forte numbers, interval vectors, subset indexes) of the trichord pair. Each of these outputs is produced by a different tool, connected by a Python orchestration layer that manages the full pipeline.

Understanding this pipeline is both a practical guide to music technology production and an example of how modern software engineering principles — modularity, separation of concerns, automation — apply to creative work at scale.

The Full Pipeline

From Pitch Class Set Specification to Published Volume
Python / JSON
1. Mathematical Specification
Trichord pair defined as interval arrays. 12 transpositions generated. 18 permutations computed. Hexatonic validated. Forte number and interval vector assigned. Output: volume_spec.json
↓
Python → LilyPond (.ly)
2. Score Source Generation
Python template fills LilyPond source files with pitch data. One .ly file per exercise (ascending, descending, combined, all permutations). Output: hundreds of .ly files per volume.
↓
LilyPond → PDF + MIDI
3. Score and MIDI Compilation
LilyPond compiles each .ly file to a publication-quality PDF score and a standard MIDI file simultaneously. Batch compilation via Python subprocess. Output: one PDF + one MIDI per exercise.
↓
SuperCollider → WAV → MP3
4. Audio Rendering
SuperCollider reads MIDI or pitch arrays and synthesizes audio with drone. WAV files captured, normalized, converted to MP3 using ffmpeg. Output: one MP3 per exercise or composition.
↓
Python + Pandoc → DOCX/PDF
5. Book Assembly
Python assembles PDFs, scores, text, and metadata into the final volume book. Pandoc converts Markdown text to DOCX. Cover designed separately. Output: final volume book file.
↓
Cloudflare R2 + muse-eek.com
6. Distribution
Audio files uploaded to Cloudflare R2 for streaming. Book files distributed via muse-eek.com. URLs recorded in manifest. Output: published, accessible volume.

The Role of MIDI

MIDI (Musical Instrument Digital Interface) is a 40-year-old protocol that encodes musical events — note on, note off, pitch, velocity, duration — as numerical messages. Despite its age, MIDI remains the lingua franca of music technology because it is universal, compact, and precisely defined.

In the Sound Cells pipeline, MIDI serves as the intermediate format between score generation (LilyPond) and audio rendering (SuperCollider). LilyPond generates a standard MIDI file as a byproduct of score compilation — every note in the score becomes a MIDI event with the correct pitch, duration, and timing. SuperCollider can read this MIDI file and use it as a sequencer to drive audio synthesis, ensuring that the audio matches the score exactly.

MIDI also serves as the format for the exercise files included with each Sound Cells volume — students can import them into any MIDI-capable software or hardware sequencer, play them back at any tempo, and transpose them to any key without affecting the pitch relationships. The mathematical precision of the pitch class set system is preserved exactly through the MIDI format.

LilyPond — Music as Code

LilyPond is unique among music notation programs in treating music as a compiled language: you write a text description of the score, and LilyPond compiles it to a PDF. This makes it ideal for automated generation — the same Python script that generates the pitch class arrays can also generate the LilyPond source code.

LilyPond: 027-027 Hexatonic Exercise (simplified)
% LilyPond source — auto-generated by Python
% Trichord pair: 027-027, Key: C
version "2.24.0"
relative c' {
  clef treble
  key c major
  time 4/4
  % Trichord 1: 027 (C, D, G)
  c8 d g4 ~ g8 d c4
  % Trichord 2: 027 transposed (E, A, B)  
  e8 a b4 ~ b8 a e4
  % Combined hexatonic ascending
  c8 d e8 a b4 g2
}

The LilyPond source is human-readable — a musician can look at it and understand immediately what pitches are being specified — but it is also machine-writable. The Python template that generates the above source needs only to know the trichord pair and key center; the rest is boilerplate that stays constant across all 9,240 permutations.

File Format Relationships

.ly
LilyPond Source
Human and machine readable. Compiled to PDF and MIDI. Version-controlled in git. The “source of truth” for score content.
.pdf
Printed Score
Publication-quality notation. Included in book. Cannot be edited without regenerating from .ly source. The student-facing format.
.mid
MIDI File
Universal playback format. Drives SuperCollider audio synthesis. Importable to any DAW. The machine-readable pitch data.
.scd
SuperCollider Script
Audio synthesis specification. Reads MIDI, applies synthesis, generates WAV. One template per instrument type, parametric over pitch content.
.mp3
Streaming Audio
Final deliverable for students. Hosted on Cloudflare R2. Linked from the book PDF. The listening format.
.json
Metadata Manifest
Links all other files. Records Forte numbers, interval vectors, subset indexes, chord compatibility. The mathematical backbone of the volume.

What “Automation” Actually Means

Describing this pipeline as “automated” can create a misleading impression — that the music produces itself. In practice, automation handles the mechanical tasks (transposing pitch arrays, compiling LilyPond files, encoding audio) while human judgment governs every decision that affects musical quality.

The decisions that are not automated: which trichord pair to use for each volume, what exercise formats best illustrate that pair’s character, what tempo and instrument sound best serves the audio files, whether a specific generated exercise makes musical sense or reveals a problem with the specification. These require a musician’s ear and decades of experience with the material.

Automation provides scale — the ability to produce complete, consistent, high-quality materials for 78 volumes where manual production of each would be prohibitive. It does not provide musical judgment. The two work together, each doing what it does best.

Pipeline Output — Two Contrasting Pairs

Both pieces passed through the full pipeline described above — specification, score generation, MIDI, SuperCollider synthesis, MP3 encoding, R2 upload.

Carry On — Bruce Arnold, computer realization (025-027)
Rectitude — Bruce Arnold, computer realization (025-027)

Production technology and music, the same principles

Modularity

Each stage of the pipeline (specification, score, audio, metadata, distribution) is independent — can be changed without affecting the others. The same modularity principle governs good software architecture and good music theory: separate concerns cleanly.

Single source of truth

The .ly files are the source of truth for score content. The .json manifests are the source of truth for mathematical structure. Every other format (PDF, MIDI, MP3) is derived. Changing the source automatically propagates through the pipeline.

Format as constraint

Each file format constrains what is possible: MIDI encodes pitch and timing but not timbre; LilyPond encodes notation but not synthesis; MP3 encodes audio but not score. Understanding these constraints is essential for using each format correctly.

Scale through automation

78 volumes × hundreds of exercises per volume × 12 keys × multiple formats = millions of files. Manual production is not feasible. Automation makes the scale tractable while keeping human judgment at every decision point that matters.

The Infrastructure of Music Education

The production pipeline described in this article is not visible to the student who opens a Sound Cells volume. They see a score, hear the audio, read the text. The pipeline is invisible infrastructure — like the printing presses behind a book or the CDN behind a streaming service. But understanding it reveals how modern music education can achieve a scope and completeness that was not possible when every page had to be hand-engraved and every audio file had to be recorded in a studio.

The next article looks at how all this material reaches students — the Cloudflare R2 infrastructure that hosts the audio, and what modern content delivery means for a small independent music education publisher.

LilyPond documentation: lilypond.org. MIDI specification: midi.org. SuperCollider: supercollider.github.io. ffmpeg audio encoding: ffmpeg.org. All tools referenced are free and open source. The Sound Cells production pipeline is described in the series documentation at muse-eek.com.

Leave a Reply

Your email address will not be published. Required fields are marked *