Skip to content

Features

New to music terms?

If terms such as voice, bar, chord, fifth, cadence, or fugue subject are unfamiliar, read the Music Primer for Engineers first. This page still gives short explanations where the terms first matter.

10 Musical Forms

MIDI Sketch Bach generates compositions in ten distinct Baroque instrumental forms, organized into three systems. Each form fixes its own voice count, meter, and natural length — there is no voice-count option.

Form, voice, meter, natural length

A form is a composition plan such as fugue or passacaglia. A voice is one independent melodic line. Meter is the beat pattern, such as 4/4 or 3/4. Natural length is the reference bar count used before scale or targetBars; the result is then snapped to the form's bar grid. For example, the fugue's reference length is 42 bars and its default resolved output is 44.

Quick chooser

Choose fugue to hear strict line-against-line writing, prelude_and_fugue for a flowing prelude followed by a fugue, chorale_prelude for slower hymn-based material, passacaglia or chaconne for variation over a repeating bass, and cello_prelude for a single flowing solo line. If you omit form, the default is fugue.

Organ System (Forms 0--6)

IDFormVoicesDescription
0Fugue3Pure contrapuntal fugue with subject, answer, and episodes
1Prelude and Fugue3Flowing prelude paired with an elaborate fugue
2Trio Sonata3Three independent voices: two upper parts over a bass line
3Chorale Prelude3Hymn melody with figuration and an independent bass
4Toccata and Fugue3Dramatic virtuosic toccata followed by a strict fugue
5Passacaglia3Variations and a counterline over a repeating ground bass (3/4)
6Fantasia and Fugue3Free-form fantasia paired with a structured fugue

Solo Instrument System (Forms 7--8)

IDFormVoicesDescription
7Cello Prelude1Flowing single-line prelude for solo cello
8Chaconne2Monumental ground-bass variation form for solo violin (3/4)

Variation System (Form 9)

IDFormVoicesDescription
9Goldberg Variations3Aria and variations over an immutable bass, incl. canons

TIP

See Forms for detailed descriptions and Baroque historical context for each form.

Counterpoint and Polyphony

  • Form-decided voice count (1--3 voices) with proper voice leading
  • Rule-based counterpoint validated against per-beat chord-tone anchoring
  • Authentic voice independence -- each voice has its own melodic identity
  • Proper interval handling: consonance, dissonance, and resolution
  • Subject-answer relationships in fugal forms
  • Forbidden parallel fifths and octaves avoidance

Counterpoint and polyphony

Polyphony means several independent lines sounding at once. Counterpoint is the rule system for making those lines fit together: each line should make melodic sense, and the vertical intervals between lines should stay controlled.

INFO

See Counterpoint Course for the full set of rules governing voice interaction.

Multiple Instruments

Six instrument presets shape the MIDI output, each accepted by the forms written for it:

InstrumentAccepted by
OrganFugue, Prelude and Fugue, Trio Sonata, Chorale Prelude, Toccata and Fugue, Passacaglia, Fantasia and Fugue
HarpsichordGoldberg Variations
PianoGoldberg Variations
ViolinChaconne
CelloCello Prelude
Guitar--

Each instrument maps to a General MIDI program number and a playable range, and shapes how densely the ornament pass decorates the line. The range is used to fit the completed output by whole-octave displacement. Instrument compatibility is defined per form: the Goldberg Variations is the only form offering a choice.

Subject Characters

Four character types influence the melodic character of fugue subjects and thematic material:

Subject

A subject is the main theme of a fugue. The character option changes the contour and rhythmic profile of that theme and related material; it does not select an instrument or output style.

CharacterStyle
severeStrict, intellectually rigorous (default)
playfulLight, agile, rhythmically lively
nobleStately, broad, dignified
restlessDriving, chromatic, dramatically charged

INFO

Some character/form combinations are forbidden and throw: chorale_prelude rejects playful/restless, and toccata_and_fugue rejects noble.

Deterministic Generation

Every generation is controlled by a seed value. The same configuration with the same seed always produces byte-identical output:

js
// These two calls produce identical MIDI
generator.generate({ form: 'fugue', key: 0, seed: 42 })
generator.generate({ form: 'fugue', key: 0, seed: 42 })

Set seed: 0 (or omit it) for random generation; the resolved seed is reported via getInfo().seedUsed so you can reproduce the run.

WARNING

Deterministic reproduction requires the same version of MIDI Sketch Bach. Different versions may produce different output for the same seed due to algorithm improvements.

Multiple Output Formats

MIDI File

Get standard MIDI file data as a Uint8Array, ready to write to disk or create a download link:

js
const midi = generator.getMidi()

Structured Event Data

Get detailed event data including track information, note events, and metadata:

js
const events = generator.getEvents()
// events.form             - "fugue"
// events.key              - "C_major" (the selected output key)
// events.bpm              - 100 (starting tempo)
// events.total_bars       - 44 (42-bar reference length, snapped to 4 bars)
// events.tempos           - tempo map, including the closing ritardando
// events.time_signatures  - meter map
// events.tracks           - output-key pitches; each note carries a "source" tag

Each note's source records its provenance: "material" (subjects, grounds, cantus firmus), "compose" (candidate search, currently used by the opt-in Passacaglia free-counterpoint path), or "ornament" (the ornament pass). Default form generation replays authored carrier material rather than emitting "compose" notes.

For scoring and analysis rather than playback, getGenerated() and getProvenance() return the flat generated.v1 note list and the index-parallel provenance.v1 record of how each note was chosen. Unlike getEvents(), generated.v1 keeps the composer's internal C pitches.

Duration Control

Four scale modes set the length as a multiple of each form's natural length:

ScaleDescription
Short~1x natural length (default)
Medium~2x natural length
Long~3x natural length
Full~4x natural length

You can also set a specific bar count with targetBars, which overrides scale and is clamped to [form minimum, 128].

TIP

See Option Relationships for how targetBars interacts with the scale setting and other configuration options.

Additional Capabilities

  • All 12 keys supported (C through B), both major and minor
  • Tempo control from 40 to 200 BPM
  • Cross-platform: runs in Node.js and all modern browsers via WebAssembly
  • Standard MIDI output: compatible with every DAW and MIDI tool
  • Dual-licensed: AGPL-3.0 — free to use, modify, and redistribute, including commercially, under its copyleft terms; a separate commercial license is available for closed-source products and proprietary SaaS. Generated MIDI is yours to use freely, including commercially

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