Free-pitch polyphonic MIDI I/O based on webmidi.js using multi-channel pitch-bend.
Install the package from npm:
npm install xen-midiAPI docs are generated with TypeDoc from the source comments in src/index.ts and published at the project GitHub Pages site:
To regenerate TypeDoc locally:
npm run docThis command writes documentation output to docs/.
import {WebMidi} from 'webmidi';
import {MidiOut} from 'xen-midi';
async function play() {
await WebMidi.enable();
// Set maximum microtonal polyphony to 4 (the number of channels reserved).
const channels = new Set([1, 2, 3, 4]);
const midiOut = new MidiOut(WebMidi.outputs[0], channels);
// Play a just intonation 4:5:6 major chord.
midiOut.playNotes([
{
frequency: 440,
rawAttack: 80,
rawRelease: 80,
time: '+0',
duration: 500,
},
// Attack and release default to 64.
{
frequency: 550,
time: '+100',
duration: 500,
},
{
frequency: 660,
time: '+200',
duration: 500,
},
]);
}
play();frequency: frequency in Hertz (Hz)rawAttack: attack velocity from0to127(optional, defaults to64)rawRelease: release velocity from0to127(optional, defaults to64)time: note-on time in milliseconds; use'+N'for a delay ofNms from nowduration: note length in milliseconds (ms)
The library exports:
BEND_RANGE_IN_SEMITONESMidiOutMidiInmidiKeyInfo- Type aliases:
Voice,Note,NoteOff,NoteOnCallback,MidiKeyInfo