Skip to content

Option Relationships

MIDI Sketch Bach's configuration options interact with each other in specific ways. Understanding these relationships helps you craft configurations that produce the results you want.

Dependency Overview

Form Determines Defaults

The form parameter is the most influential configuration option. It determines the default values for instrument, numVoices, and bpm.

Default Cascade

When you specify a form, defaults are applied for any unspecified fields:

js
// You specify:
generator.generate({ form: 'fugue', key: 2, isMinor: true })

// Engine resolves to:
// {
//   form: 0,
//   key: 2,
//   isMinor: true,
//   instrument: 0,    ← form default (organ)
//   numVoices: 4,     ← form default
//   bpm: 85,          ← form default
//   seed: 0,          ← random
//   character: 0,     ← balanced
//   scale: 1,         ← medium
// }

Any field you explicitly set overrides the form default:

js
// Override instrument and BPM
generator.generate({
  form: 'fugue',
  instrument: 'harpsichord',  // overrides organ
  bpm: 72                     // overrides 85
})

See the Presets Reference for the complete default table.

Voice Count Constraints

The numVoices parameter has valid ranges that depend on the form:

FormDefaultMinimumMaximumNotes
0: Fugue425
1: Prelude and Fugue425
2: Trio Sonata333Fixed at 3
3: Chorale Prelude435Needs at least 3 for cantus + 2 accompaniment
4: Toccata and Fugue435
5: Passacaglia435
6: Fantasia and Fugue435
7: Cello Prelude323Solo instrument implied voices
8: Chaconne324Solo instrument implied voices

WARNING

Setting numVoices outside the valid range for a form may cause the engine to clamp to the nearest valid value. For example, requesting 5 voices for a Trio Sonata will still produce 3 voices.

Scale vs. targetBars

The scale and targetBars parameters both control output length, but they interact:

ConfigurationBehavior
scale onlyOutput length determined by scale level and form
targetBars onlyEngine aims for the specified bar count
Both specifiedtargetBars overrides scale
Neither specifiedDefault: scale: 1 (medium)

TIP

Use scale when you want a general size category (short, medium, long, full). Use targetBars when you need a specific length. The actual output may differ slightly from targetBars because musical phrases need to end at natural boundaries.

js
// General length control
generator.generate({ form: 'fugue', scale: 'long' })

// Specific length control
generator.generate({ form: 'fugue', targetBars: 48 })

// targetBars wins when both specified
generator.generate({
  form: 'fugue',
  scale: 'short',      // ignored
  targetBars: 48        // this is used
})

Seed Behavior

The seed parameter controls deterministic output:

Seed ValueBehavior
0 (default)Random seed — different output each time
Any positive integerDeterministic — same config + same seed = same output

Reproducibility

Deterministic reproduction requires the same version of MIDI Sketch Bach. The internal algorithms may change between versions, so the same seed may produce different output after an upgrade. If you need to preserve specific outputs, save the generated MIDI files rather than relying on seed reproducibility across versions.

js
// Random each time
generator.generate({ form: 'fugue', seed: 0 })

// Always produces the same result
generator.generate({ form: 'fugue', key: 2, isMinor: true, seed: 42 })

// Different key = different output even with same seed
generator.generate({ form: 'fugue', key: 0, isMinor: true, seed: 42 })

Key and Mode

The key and isMinor parameters work together to define the tonal center:

js
// D major
generator.generate({ key: 2, isMinor: false })

// D minor
generator.generate({ key: 2, isMinor: true })
ParameterRangeDefault
key0--11 (pitch class)0 (C)
isMinortrue / falsefalse (major)

The key affects:

  • The pitch center and scale of the composition
  • The harmonic vocabulary available to the engine
  • Modulation targets (related keys)

Character and Form

The character parameter's impact varies by form type:

Form TypeCharacter Impact
Fugal forms (0, 1, 4, 6)Strong — directly shapes the fugue subject, which defines the entire piece
Variation forms (5, 8)Moderate — influences the bass theme and variation character
Chorale Prelude (3)Moderate — affects the accompanying voices, cantus firmus is fixed
Trio Sonata (2)Moderate — shapes the motivic material for both upper voices
Cello Prelude (7)Moderate — influences figuration patterns

TIP

Character 0 (balanced) is a good default for most situations. Try character 3 (dramatic) for Toccata and Fugue, or character 1 (lyrical) for Chorale Prelude.

Validation Rules

Complete validation constraints for all configuration fields:

FieldTypeRangeDefaultValidation
formnumber or string0--80Clamped to valid range
keynumber0--110Clamped to valid range
isMinorbooleantrue/falsefalse--
numVoicesnumberForm-dependent (2--5)Form defaultClamped to form's valid range
bpmnumber40--200Form default0 uses form default; clamped otherwise
seednumber0+00 = random
characternumber or string0--30Clamped to valid range
instrumentnumber or string0--5Form defaultClamped to valid range
scalenumber or string0--31Clamped to valid range
targetBarsnumber1+--Overrides scale when specified

Released under the Apache-2.0 License.