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

@waveform-playlist/midi

v13.0.3

Published

MIDI file loading and parsing for waveform-playlist

Readme

@waveform-playlist/midi

MIDI file loading and parsing for waveform-playlist — fetch a .mid file (or use pre-parsed notes) and get back ClipTrack[] ready to hand to WaveformPlaylistProvider.

This package is the React wrapper over @dawcore/midi (the framework-agnostic parser, re-exported here) plus a useMidiTracks hook that produces waveform-playlist's clip/track shape. It only handles the data pipeline — .mid → notes → ClipTrack. Pair it with @waveform-playlist/browser for the playlist UI and @waveform-playlist/playout (piano-roll rendering + SoundFont/PolySynth playback via Tone.js) for actual MIDI sound.

Features

  • Parse .mid files from an ArrayBuffer or fetch by URL (parseMidiFile, parseMidiUrl)
  • useMidiTracks React hook — loads one or more MIDI configs into ClipTrack[] with loading/error state
  • Accepts pre-parsed midiNotes to skip fetch+parse entirely
  • Multi-track MIDI files expand to one ClipTrack per track by default, or merge into one with flatten: true
  • GM instrument naming (percussion detection, program-number lookup) and per-note channel preserved for multi-timbral playback

Installation

npm install @waveform-playlist/midi @waveform-playlist/browser

react is a peer dependency. @dawcore/midi, @tonejs/midi, and @waveform-playlist/core are regular dependencies — installed automatically.

Usage

import { useMidiTracks } from '@waveform-playlist/midi';
import { WaveformPlaylistProvider } from '@waveform-playlist/browser';

function MidiPlaylist() {
  const audioContext = new AudioContext();

  const { tracks, loading, error } = useMidiTracks(
    [{ src: '/music/song.mid', name: 'Piano' }],
    { sampleRate: audioContext.sampleRate }
  );

  if (loading) return <p>Loading MIDI…</p>;
  if (error) return <p>Error: {error}</p>;

  return <WaveformPlaylistProvider tracks={tracks}>{/* your UI */}</WaveformPlaylistProvider>;
}

Parsing without React (e.g. a Node script or a custom loader):

import { parseMidiFile, parseMidiUrl } from '@waveform-playlist/midi';

const parsed = await parseMidiUrl('/music/song.mid');
console.log(parsed.tracks.map((t) => t.name)); // ['Piano', 'Drums', ...]

API

useMidiTracks(configs, options)

function useMidiTracks(
  configs: MidiTrackConfig[],
  options: UseMidiTracksOptions
): UseMidiTracksReturn;

interface MidiTrackConfig {
  src?: string; // URL to a .mid file (fetched + parsed)
  midiNotes?: MidiNoteData[]; // pre-parsed notes — skips fetch+parse
  name?: string;
  muted?: boolean;
  soloed?: boolean;
  volume?: number; // default 1.0
  pan?: number; // default 0
  color?: string;
  startTime?: number; // clip position on timeline, in seconds (default 0)
  duration?: number; // override clip duration in seconds
  flatten?: boolean; // merge all tracks in the file into one ClipTrack (default false)
}

interface UseMidiTracksOptions {
  sampleRate: number; // pass AudioContext.sampleRate — MIDI has no native sample rate
}

interface UseMidiTracksReturn {
  tracks: ClipTrack[];
  loading: boolean;
  error: string | null;
  loadedCount: number;
  totalCount: number;
}

parseMidiFile(data, options?) / parseMidiUrl(url, options?, signal?)

Re-exported from @dawcore/midi.

function parseMidiFile(data: ArrayBuffer, options?: ParseMidiOptions): ParsedMidi;
function parseMidiUrl(url: string, options?: ParseMidiOptions, signal?: AbortSignal): Promise<ParsedMidi>;

interface ParseMidiOptions {
  flatten?: boolean; // merge all tracks into one ParsedMidiTrack
}

interface ParsedMidi {
  tracks: ParsedMidiTrack[];
  duration: number; // seconds
  name: string; // song name from MIDI header
  bpm: number; // first tempo in the file (default 120)
  timeSignature: [number, number]; // default [4, 4]
}

interface ParsedMidiTrack {
  name: string;
  notes: MidiNoteData[]; // { midi, name, time, duration, velocity, channel }
  duration: number; // seconds
  channel: number; // 9 = GM percussion
  instrument: string;
  programNumber: number; // GM program number (0-127)
}

Examples & Documentation

License

MIT