Skip to content

Instruments

The engine represents an instrument with a General MIDI program, a playable range, and an ornament-density profile. It does not simulate performer ergonomics such as bow direction, hand span, fret position, or fatigue.

What an Instrument Selects

Choosing an instrument affects three things:

  1. General MIDI program — the sound written into the MIDI file.
  2. Playable range — the output compass used after composition. Once the requested key is applied, the engine fits the authored score with a whole-score octave displacement instead of clamping individual notes.
  3. Ornament density — how heavily the ornament pass decorates the line (combined with the character).

The voice count, meter, and structure come from the form, not from the instrument. Each form has an explicit set of compatible instruments — see Default Instrument per Form.

Instrument vs voice

An instrument is the playback sound and range profile. A voice is the musical line being generated. A single instrument, such as organ, can carry several voices.

General MIDI Programs

InstrumentStringGM ProgramSound
Organ"organ"19Church Organ
Harpsichord"harpsichord"6Harpsichord
Piano"piano"0Acoustic Grand Piano
Violin"violin"40Violin
Cello"cello"42Cello
Guitar"guitar"24Acoustic Guitar (Nylon)

An unknown instrument string is rejected (it throws) rather than silently falling back to a default.

Default Instrument per Form

FormDefault InstrumentAlso accepted
fugue, prelude_and_fugue, trio_sonata, chorale_prelude, toccata_and_fugue, passacaglia, fantasia_and_fugueOrgan--
cello_preludeCello--
chaconneViolin--
goldberg_variationsHarpsichordPiano

Guitar has a General MIDI program and a range profile but is not currently accepted by any form. Requesting an instrument outside a form's row throws an incompatible-instrument error.

Ornament Density

The deterministic ornament pass adds trills, mordents, and Nachschlag. How densely it decorates depends on both the character and the instrument, and some lines are never ornamented:

Trill, mordent, Nachschlag

These are short Baroque decorative figures around a structural note. They are added after the main composition is validated, so they are tagged as source: "ornament" rather than "material" or "compose".

  • Ground-bass lines (passacaglia, chaconne, Goldberg bass) are never ornamented.
  • Cantus-firmus lines (chorale prelude) are never ornamented.

Notes added here carry the source: "ornament" provenance tag.

Expression Output

Beyond ornaments, the engine writes form-appropriate expression, and all of it is readable from the event data as well as the MIDI file:

  • Registration curve — CC 7 and CC 11 points following the form's energy arc, reported per track as control_changes with duplicates already merged.
  • Tempo map — the closing ritardando, plus a section tempo change at the fugue entry of the prelude, toccata and fantasia forms. Reported as tempos.
  • Time signature — 3/4 for passacaglia and chaconne, 4/4 otherwise. Reported as time_signatures.

Because tempo varies within a piece, use the tempo map rather than bpm when placing events on the clock — see Converting Ticks to Seconds.

TIP

See Voice Architecture for how voices map to instruments and tracks, and the Generation Pipeline for where the ornament and expression passes sit.

Dual-licensed: AGPL-3.0 · commercial licensing available. Generated MIDI is yours to use freely.