Installation
Alpha — not yet published to npm
This package is in alpha and has not been published to the npm registry yet. The commands on this page will not work until the first public release. Until then, try it in the live demo on this site.
npm Package
Install MIDI Sketch Bach as a dependency in your Node.js project:
npm install @libraz/midi-sketch-bachyarn add @libraz/midi-sketch-bachpnpm add @libraz/midi-sketch-bachbun add @libraz/midi-sketch-bachThen import and use it in your code:
import { init, BachGenerator } from '@libraz/midi-sketch-bach'
await init()
const generator = new BachGenerator()CLI (Global Install)
Install globally to use the @libraz/midi-sketch-bach command anywhere:
npm install -g @libraz/midi-sketch-bachOr run directly without installing:
npx @libraz/midi-sketch-bach --form fugue -o fugue.midBrowser Usage
MIDI Sketch Bach runs in the browser via WebAssembly. When using in a browser environment, specify the path to the WASM file:
import { init, BachGenerator } from '@libraz/midi-sketch-bach'
// Specify the WASM file location for browser environments
await init({ wasmPath: '/wasm/bach.wasm' })
const generator = new BachGenerator()
generator.generate({ form: 'fugue', key: 0 })
const midi = generator.getMidi()
// Create a download link
const blob = new Blob([midi], { type: 'audio/midi' })
const url = URL.createObjectURL(blob)
// See the JavaScript API page for the full download flowWASM Path
In Node.js, the WASM file is resolved automatically. In browser environments, you need to provide the wasmPath option pointing to where the .wasm file is served.
Bundler Configuration
Vite
For Vite projects, ensure the WASM file is served correctly:
// vite.config.js
export default {
optimizeDeps: {
exclude: ['@libraz/midi-sketch-bach']
}
}Webpack
For Webpack, you may need to configure asset handling for .wasm files:
// webpack.config.js
module.exports = {
experiments: {
asyncWebAssembly: true
}
}System Requirements
- Node.js: 18.0 or later
- Browser: Any modern browser with WebAssembly support (Chrome, Firefox, Safari, Edge)
- No native dependencies: The package is pure JavaScript + WebAssembly