Skip to content

Features

9 Musical Forms

MIDI Sketch Bach generates compositions in nine distinct Baroque instrumental forms, organized into two systems:

Organ System (Forms 0--6)

IDFormVoicesDescription
0Fugue4Pure contrapuntal fugue with subject, answer, and episodes
1Prelude and Fugue4Flowing prelude paired with an elaborate fugue
2Trio Sonata3Three independent voices: two upper parts over a bass line
3Chorale Prelude4Hymn melody with contrapuntal accompaniment
4Toccata and Fugue4Dramatic virtuosic toccata followed by a strict fugue
5Passacaglia4Continuous variations over a repeating bass theme
6Fantasia and Fugue4Free-form fantasia paired with a structured fugue

Solo Instrument System (Forms 7--8)

IDFormVoicesDescription
7Cello Prelude3Flowing prelude for solo cello
8Chaconne3Monumental variation form for solo violin

TIP

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

Counterpoint and Polyphony

  • 2 to 5 independent voices with proper voice leading
  • Rule-based counterpoint following Baroque compositional principles
  • 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

INFO

See Counterpoint & Voice Leading for the full set of rules governing voice interaction.

Multiple Instruments

Six instrument presets shape the MIDI output:

InstrumentTypical Forms
OrganFugue, Prelude and Fugue, Trio Sonata, Chorale Prelude, Toccata and Fugue, Passacaglia, Fantasia and Fugue
HarpsichordAny organ form (alternative voicing)
PianoAny form
ViolinChaconne
CelloCello Prelude
GuitarCello Prelude, Chaconne (alternative voicing)

Each instrument maps to appropriate General MIDI program numbers and voice ranges.

Subject Characters

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

CharacterStyle
0Default balanced character
1Lyrical, stepwise motion
2Energetic, wider intervals
3Dramatic, rhythmically varied

Deterministic Generation

Every generation is controlled by a seed value. The same configuration with the same seed always produces the exact same 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.

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         - "D minor"
// events.bpm         - 85
// events.total_bars  - 32
// events.tracks      - Array of TrackData with individual notes

Duration Control

Four scale modes control the length of generated compositions:

ScaleDescription
ShortCompact compositions, fewer variations
MediumStandard length (default)
LongExtended compositions with more development
FullMaximum length with full formal structure

You can also set a specific bar count with targetBars.

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
  • Apache-2.0 license: free for commercial and personal use

Released under the Apache-2.0 License.