sakuramml-libplayer
v0.1.1
Published
MML and MIDI sound player for browsers using SakuraMML WebAssembly.
Maintainers
Readme
sakuramml-libplayer
A browser JavaScript library for playing Sakura MML and MIDI. It uses Rust and WebAssembly for MML compilation, MIDI parsing, and PCM rendering, then sends the generated audio to the Web Audio API.
Usage
import { SakuraPlayer } from 'sakuramml-libplayer';
const player = new SakuraPlayer();
await player.init();
await player.loadSoundFont('/fonts/TimGM6mb.sf2');
await player.play('テンポ120 ドレミファソラシド');To use it from a CDN, import the ES module URL provided by your CDN.
<script type="module">
import { SakuraPlayer } from 'https://cdn.jsdelivr.net/npm/[email protected]/sakura-mml-player.js';
const player = new SakuraPlayer();
await player.init();
await player.loadSoundFont('https://example.com/TimGM6mb.sf2');
await player.play('テンポ120 ドレミファソラシド');
</script>SoundFonts are not bundled with this package. Host a SoundFont yourself, or provide SoundFont bytes, and pass it to loadSoundFont().
await player.loadSoundFont('https://example.com/TimGM6mb.sf2');API
compileMML(source)Compiles MML source text into MIDI bytes and returns{ midi, log }.loadSoundFont(source)Loads a SoundFont.sourcecan be a URL,Uint8Array,ArrayBuffer, orBlob.play(input)Plays an MML string or MIDI bytes. With no argument, playback resumes from the paused position.pause()Pauses playback.stop()Stops playback and resets the position to the beginning.setPosistion(seconds)Sets the playback position in seconds.setPosition(seconds)is also available as an alias.setLength(seconds)Limits the playback end position in seconds.onEvent(name, handler)Subscribes to events such ascompile,load,play,pause,stop,position, andended.
Package Contents
sakura-mml-player.jsPublic JavaScript API.pkg/WebAssembly bundle generated bywasm-pack.
