npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@marmooo/midy

v0.6.8

Published

A MIDI player/synthesizer written in TypeScript that supports GM-Lite/GM1 and SF2/SF3.

Readme

Midy

A MIDI player/synthesizer written in TypeScript that supports GM-Lite/GM1/GM2 and SF2/SF3.

This library provides several files depending on the implementation level.

  • midy-GMLite.js: support minimal GM-Lite (ref: en, ja)
  • midy-GM1.js: support minimal GM1 (ref: en, en full, ja)
  • midy-GM2.js: support minimal GM2 (ref: en v1.2a, en v1.0, ja v1.0)
  • midy.js: full implementation (in progress)

Demo

Support Status

All implementations follow the specification.

| Message | Support | Notes | | :----------------------- | :-----: | :------- | | Note Off | ✔️ | | | Note On | ✔️ | | | Polyphonic Key Pressure | ✔️ | full GM2 | | Controller Change | ✔️ | full GM2 | | Program Change | ✔️ | full GM2 | | Channel Pressure | ✔️ | full GM2 | | Pitch Bend | ✔️ | | | System Exclusive Message | ✔️ | full GM2 | | System Common Message | ❌ | | | System Real Time Message | ✔️ | full GM2 | | MIDI Time Code | ❌ | | | MIDI Show Control | ❌ | | | MIDI Machine Control | ❌ | |

Usage

Initialization

// import { MidyGMLite as Midy } from "midy-GMLite.js";
// import { MidyGM1 as Midy } from "midy-GM1.js";
// import { MidyGM2 as Midy } from "midy-GM2.js";
import { Midy } from "midy.js";

const audioContext = new AudioContext();
if (audioContext.state === "running") await audioContext.suspend();
const midy = new Midy(audioContext);
await midy.loadMIDI("test.mid");
await midy.loadSoundFont("test.sf3");
await midy.start();

Playback

midy.loop = true;
await midy.start();
await midy.stop();
await midy.pause();
await midy.resume();
midy.seekTo(second);
midy.tempoChange(tempo);

Events

midy.addEventListener("looped", func);
midy.addEventListener("started", func);
midy.addEventListener("ended", func);
midy.addEventListener("stopped", func);
midy.addEventListener("paused", func);
midy.addEventListener("resumed", func);
midy.addEventListener("seeked", func);
midy.addEventListener("tempoChanged", func);

Cache Mode

  • "none" Full real-time control (dynamic CC, LFO, pitch). Highest CPU.
  • "ads" Pre-render ADS; release fades in real time. LFO stays live.
  • "adsr" Pre-render full ADSR keyed by duration ticks + volRelease.
  • "note" Per-note offline bake (automation in-interval). MIDI-file only.
  • "segment" Per-channel tiled offline buffers; channel vol/pan stay live.
  • "chunk" All-channel tiled offline mix; vol/pan snapshotted into buffer.
  • "audio" Entire song pre-rendered to one buffer. Lowest CPU.
midy.cacheMode = "audio";

Reverb Mode

  • "Convolution" - Convolution Reverb
  • "Schroeder" - Schroeder (1962)
  • "Moorer" - Moorer (1979)
  • "FDN" - FDN (1992)
  • "Dattorro" - Dattorro (1997)
  • "Freeverb" - Freeverb (1999)
  • "VelvetNoise" - Velvet Noise Reverb (2012)
midy.setReverbEffect("FDN");

MIDI Message

There are functions that handle MIDI messages as they are, as well as simplified functions.

midy.handleMessage(data, scheduleTime);
const channel = midy.channels[0];
channel.noteOff(noteNumber, velocity, endTime, force);
channel.noteOn(noteNumber, velocity, startTime);
channel.setPolyphonicKeyPressure(noteNumber, pressure);
channel.setControlChange(controlType, value);
channel.setProgramChange(programNumber);
channel.setChannelPressure(value);
channel.setPitchBend(value);

Control Change

There are functions that handle control changes as they are, as well as simplified functions.

const channel = midy.channels[0];
channel.setControlChange(controller, value, scheduleTime); // [0-127] value
channel.setModulationDepth(value, scheduleTime); // [0-127] value
channel.setVolume(volume, scheduleTime); // [0-127] value

System Exclusive Message

There are functions that handle SysEx data as is, as well as simplified functions.

midy.handleSysEx(data, scheduleTime); // SysEx data without F0/F7
midy.handleMasterVolumeSysEx(data, scheduleTime); // [7F 7F 04 01 vv vv] data
midy.setMasterVolume(volume); // [0-1] volume

MPE (MIDI Polyphonic Expression)

midy.noteOff(channelNumber, noteNumber, velocity, endTime, force);
midy.noteOn(channelNumber, noteNumber, velocity, startTime);
midy.setControlChange(channelNumber, controlType, value);
midy.setProgramChange(channelNumber, programNumber);
midy.setChannelPressure(channelNumber, value);
midy.setPitchBend(channelNumber, value);

Multiple Soundfonts

This library supports SF2 and SF3. In addition, it supports multiple soundfonts and splitted soundfonts that are optimized for playback on the web. The following example loads only the minimum presets required for playback.

const soundFontURL = "https://soundfonts.pages.dev/GeneralUser_GS_v2.0.3";
function getSoundFontPaths() {
  const paths = [];
  for (const instrument of midy.instruments) {
    const [bank, program] = instrument.split(":");
    const bankNumber = Number(bank);
    const programNumber = Number(program);
    const index = midy.soundFontTable[programNumber][bankNumber];
    if (index !== undefined) continue;
    const bankDir = String(bankNumber).padStart(3, "0");
    const programFile = String(programNumber).padStart(3, "0");
    paths.push(`${soundFontURL}/${bankDir}/${programFile}.sf3`);
  }
  return paths;
}
const paths = getSoundFontPaths();
await midy.loadSoundFont(paths);
// Optional: custom URL fallback
// (default: melodic .../BBB/PPP → .../000/PPP, drums .../128/PPP → .../128/000)
// await midy.loadSoundFont(paths, { fallback: (url) => [...] });
// await midy.loadSoundFont(paths, { fallback: null }); // disable

Build

deno task build

Test

deno test tests
deno test tests/GMLite-mock
deno test tests/GM1-mock
deno test tests/GM2-mock
deno test tests/full-mock
deno test tests/MPE-mock

License

Apache-2.0