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

@grantler-instruments/mqtt-midi

v0.1.0

Published

Send and receive MIDI over MQTT with binary payloads (JSON for SysEx only)

Readme

@grantler-instruments/mqtt-midi

Send and receive MIDI over MQTT from the browser (or Node). Standard MIDI messages use compact binary payloads; channel and message type live in the topic. SysEx uses JSON only.

Status: v0.1.0 — usable for browser/Node apps with an MQTT broker (WebSocket). Build and tests pass.

Install from npm (once published):

npm install @grantler-instruments/mqtt-midi mqtt

Or from GitHub (runs prepare → builds on install):

npm install github:grantler-instruments/mqtt-midi mqtt

Or locally: npm install ../mqtt-midi mqtt

mqtt (MQTT.js v5+) is a peer dependency — your app installs and bundles it once.

Example: controller in the browser

Two apps (or tabs) share a prefix on the same broker. One sends on {prefix}/in/..., the other listens on {prefix}/out/.... In a single app that both sends and receives, register listeners for out and send on in (defaults).

import { MqttMidi } from "@grantler-instruments/mqtt-midi";

const mqttMidi = new MqttMidi({
  url: import.meta.env.VITE_MQTT_BROKER_URL, // e.g. wss://broker.example.com/mqtt
  prefix: "remote",
});

// Lifecycle
mqttMidi.on("connect", () => console.log("connected"));
mqttMidi.on("error", (err) => console.error("mqtt error", err));

// Listen to all note-ons on the bus
mqttMidi.on("noteOn", ({ channel, note, velocity }) => {
  console.log(`note on  ch=${channel}  note=${note}  vel=${velocity}`);
});

// Only channel 1, volume fader (CC 7)
mqttMidi.channel(1).on("controlChange", { controller: 7 }, ({ value }) => {
  console.log(`volume: ${value}`);
});

// SysEx (JSON payload on the wire)
mqttMidi.on("sysex", ({ data }) => {
  console.log("sysex", data.map((b) => b.toString(16)).join(" "));
});

await mqttMidi.connect();

// Send MIDI toward the remote side (publishes to {prefix}/in/...)
mqttMidi.sendNoteOn(1, 60, 100);
mqttMidi.sendNoteOff(1, 60);
mqttMidi.sendControlChange(1, 7, 127);
mqttMidi.sendSysex([0xf0, 0x7d, 0x09, 0xf7]);

// Later
await mqttMidi.disconnect();

Minimal send-only (no listeners):

import { connect } from "@grantler-instruments/mqtt-midi";

const mqttMidi = await connect({
  url: "wss://broker.example.com/mqtt",
  prefix: "remote",
});

mqttMidi.sendControlChange(1, 1, 64);

Two tabs on the same broker: use the same prefix. Tab A calls sendNoteOn(...) → publishes remote/in/noteon/1/60. Tab B with on("noteOn", ...) subscribed to remote/out/noteon/# receives it only if something republishes or mirrors inout on the remote side. Typically the instrument/firmware bridge publishes out; the web UI sends in.

Subscriptions

There is no broad {prefix}/out/# subscription on connect. MQTT topics are subscribed when you register listeners (ref-counted).

| API | MQTT subscription (default direction out) | |-----|---------------------------------------------| | on("noteOn", fn) | {prefix}/out/noteon/# | | channel(1).on("noteOn", fn) | {prefix}/out/noteon/1/# | | channel(1).on("controlChange", { controller: 7 }, fn) | {prefix}/out/cc/1/7 | | on("clock", fn) | {prefix}/out/clock | | subscribe("custom/topic/#") | raw MQTT topic (low-level) |

  • on / off / channel(n).on / channel(n).off — MIDI events + broker subscribe
  • subscribe / unsubscribe — raw MQTT only
  • on("connect") / on("error") — lifecycle only, no MQTT topic
  • defaultDirection option — "out" (default) or "in" for listener topic paths

Topic layout

| Message | Topic | Payload | |---------|-------|---------| | Control change | {prefix}/in/cc/{channel}/{controller} | 1 byte: value | | Note on | {prefix}/in/noteon/{channel}/{note} | 1 byte: velocity | | Note off | {prefix}/in/noteoff/{channel}/{note} | 1 byte: velocity | | Program change | {prefix}/in/program/{channel} | 1 byte: program | | Pitch bend | {prefix}/in/pitchbend/{channel} | 2 bytes: lsb, msb | | Clock / start / stop / continue | {prefix}/in/{type} | empty | | SysEx | {prefix}/in/sysex | JSON: { "data": [...] } |

send* methods default to {prefix}/in/.... Listeners default to {prefix}/out/....

MIDI channels are 1–16 in the API.

Send API

Channel messages — positional numbers only (binary on the wire):

mqttMidi.sendNoteOn(channel, note, velocity);
mqttMidi.sendNoteOff(channel, note);              // velocity 0
mqttMidi.sendNoteOff(channel, note, velocity);
mqttMidi.sendNoteOff(channel, note, "out");     // direction as 3rd arg
mqttMidi.sendControlChange(channel, controller, value);
mqttMidi.sendProgramChange(channel, program);
mqttMidi.sendPitchBend(channel, value);

Optional last arg: "in" | "out" (default "in").

SysEx — byte array in the API; JSON on the wire:

mqttMidi.sendSysex([0xf0, 0x7d, 0x09, 0xf7]);

Browser bundlers

MQTT.js may require Node polyfills in some Vite setups. See the MQTT.js README.

Support

If you find this library useful, you can support development:

Buy Me A Coffee

License

MIT License — see LICENSE.

Copyright © 2026 Grantler Instruments.