Skip to content

Getting Started

MIDI Sketch is a lightweight library for auto-generating pop music MIDI sketches. It runs entirely in the browser using WebAssembly.

Quick Start

javascript
import { MidiSketch, init, createDefaultConfig, downloadMidi } from '@libraz/midi-sketch'

// Initialize the WASM module
await init()

// Create an instance
const sketch = new MidiSketch()

// Create a config for a style preset (0 = first style)
const config = createDefaultConfig(0)

// Customize as needed
config.key = 0           // Key (0 = C)
config.bpm = 120         // Tempo (0 = use style default)
config.seed = 12345      // Random seed (0 = random)

// Generate MIDI
sketch.generateFromConfig(config)

// Get the MIDI data
const midiData = sketch.getMidi()

// Download the file
downloadMidi(midiData, 'my-song.mid')

What It Generates

MIDI Sketch generates multi-track MIDI files with:

TrackChannelDescription
Vocal0Main melody line (piano roll-safe)
Aux5Sub-melody support (pulse loops, groove accents)
Chord2Harmonic backing with voice leading
Bass3Bass line with approach notes
Drums9Rhythm patterns with fills (GM drums)
Motif4Background patterns (BackgroundMotif style)
Arpeggio5Synth arpeggios (SynthDriven style)
SE15Section markers

Track Availability

Not all tracks are generated for every style:

  • Motif track: Only in BackgroundMotif composition style
  • Arpeggio track: Only when arpeggioEnabled: true (must be explicitly enabled, even in SynthDriven style)
  • Vocal/Aux: Can be skipped with skipVocal: true for BGM-only generation

Next Steps

Released under the MIT License.