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

@dawcore/midi

v0.0.6

Published

Framework-agnostic MIDI file parsing, and loading a MIDI file as waveform-playlist tracks

Readme

@dawcore/midi

Framework-agnostic MIDI file parsing, and loading a .mid file as waveform-playlist tracks. No React, no DOM, no Lit — plain functions built on @tonejs/midi.

Used by @dawcore/components (the Lit web component layer, via editor.loadMidi()) and by React apps on @waveform-playlist/browser (loadMidiTracks, whose tracks go into the arrangement). It replaces @waveform-playlist/midi, which is no longer published: the names are the same, only the import changes.

Installation

npm install @dawcore/midi

No peer dependencies; @tonejs/midi and @waveform-playlist/core are regular dependencies. @dawcore/components declares this package as an optional peer dependency — add it to your own dependencies to enable editor.loadMidi() (it's dynamic-imported on first call, so non-MIDI users ship zero parser bytes).

Quick Start

import { parseMidiUrl, parseMidiFile } from '@dawcore/midi';

// Fetch and parse a .mid URL (optional AbortSignal for cancellation)
const midi = await parseMidiUrl('/media/song.mid');
// midi: { tracks, duration, name, bpm, timeSignature }

for (const track of midi.tracks) {
  // track: { name, notes, duration, channel, instrument, programNumber }
  console.log(track.name, track.notes.length + ' notes');
}

// Or parse an ArrayBuffer you already have (e.g. from a File input)
const buffer = await file.arrayBuffer();
const parsed = parseMidiFile(buffer, { flatten: true }); // merge all tracks into one

Note timings are in seconds, already tempo-adjusted by @tonejs/midi. Tracks without notes are filtered out.

Loading tracks for an arrangement

loadMidiTracks(src, options) loads a URL, a File or a Blob as ClipTrack[] with kind: 'midi', one track per MIDI track of the file (one in all with flatten). It is a function, not a hook: the app keeps its own loading and error state and adds the tracks to the arrangement that WebAudioProvider plays. Every call makes new track and clip ids.

import { useEffect, useState } from 'react';
import { loadMidiTracks } from '@dawcore/midi';
import { WebAudioProvider, useCreateArrangement } from '@waveform-playlist/browser';

function MidiPlaylist() {
  // Starts empty; the MIDI tracks are added once the file has loaded
  const arrangement = useCreateArrangement();
  const [loaded, setLoaded] = useState(false);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    const controller = new AbortController();
    loadMidiTracks('/music/song.mid', { signal: controller.signal })
      .then((tracks) => {
        if (arrangement.getTracks().length === 0) {
          // What the app adds is not an undo step
          tracks.forEach((track) => arrangement.addTrack(track));
        }
        setLoaded(true);
      })
      .catch((err: unknown) => {
        // An abort (unmount, StrictMode's first run) is not an error
        if (!controller.signal.aborted) setError(err instanceof Error ? err.message : String(err));
      });
    return () => controller.abort();
  }, [arrangement]);

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

  // Rendered once the tracks are in: the playlist's ready happens once per mount
  return (
    <WebAudioProvider arrangement={arrangement}>
      {/* your UI */}
    </WebAudioProvider>
  );
}

The clips' times are seconds, so no sample rate is passed and the tracks play on any hardware. Playing the notes (piano roll, SoundFont or PolySynth) is @waveform-playlist/browser with @waveform-playlist/playout; see the MIDI guide.

API

  • parseMidiFile(data: ArrayBuffer, options?) — parse MIDI data into ParsedMidi
  • parseMidiUrl(url: string, options?, signal?) — fetch and parse a .mid URL
  • Options: { flatten?: boolean } — merge all MIDI tracks into a single track
  • loadMidiTracks(src: string | File | Blob, options?: LoadMidiTracksOptions) — a file as kind: 'midi' tracks:
interface LoadMidiTracksOptions {
  flatten?: boolean; // merge all tracks in the file into one ClipTrack (default false)
  start?: number; // clip position on timeline, in seconds, 0 or more (default 0)
  duration?: number; // clip duration in seconds, above 0 (default: end of the track's last note)
  // a number that is not finite rejects with a TypeError, one out of range with a RangeError,
  // before anything is fetched or read; a null start or duration was not given
  name?: string; // names the track and its clip when the file yields exactly one track
  signal?: AbortSignal; // an aborted signal rejects with the signal's reason
}
  • Types: ParsedMidi, ParsedMidiTrack, ParseMidiOptions, LoadMidiTracksOptions, MidiLoadOptions, MidiLoadResult. The last two are editor.loadMidi()'s (@dawcore/components): MidiLoadOptions is { startTime?, signal?, undoable? } (undoable: false adds the tracks with no undo step, for content the page loads itself; left out, the call is one undo step), and MidiLoadResult.trackIds holds the ids of the tracks added (no <daw-track> element is created)

A URL that does not answer with an OK status rejects with Failed to fetch MIDI file <url>: <status>, with the status text after the code when there is one (Failed to fetch MIDI file /missing.mid: 404 Not Found); data that is not a MIDI file rejects with parseMidiFile: invalid or corrupt MIDI data (<n> bytes): ….

Coming from @waveform-playlist/midi: change the import. Its useMidiTracks hook (13.x) was removed; the upgrade guide has the replacement for each of its options.

Examples & Documentation

  • examples/dawcore-tone/midi-load.html — loading a .mid file (URL or file input) into <daw-editor> via editor.loadMidi(), with cancellation (pnpm example:dawcore-tone)
  • MIDI guide — covers both the React (loadMidiTracks) and Web Components (editor.loadMidi()) paths, which both use this package
  • MIDI example

License

MIT