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 🙏

© 2024 – Pkg Stats / Ryan Hefner

midifile

v2.0.0

Published

Read/write standard MIDI files.

Downloads

649

Readme

midifile

Read/write standard MIDI files.

NPM version Build status Dependency Status devDependency Status Coverage Status Code Climate Dependency Status

MIDIFile uses the MIDIEvents project and is part of the MIDIPlayer one. You can also check this Karaoke Player built on top of those libraries.

What it does

  • Read MIDI files
  • Check MIDI file structure (using strictMode)
  • Write MIDI files (still experimental)

What it doesn't do

Usage

// Your variable with your MIDI file as an ArrayBuffer or UInt8Array instance
var anyBuffer;

// Creating the MIDIFile instance
var midiFile = new MIDIFile(anyBuffer);

// Reading headers
midiFile.header.getFormat(); // 0, 1 or 2
midiFile.header.getTracksCount(); // n
// Time division
if(midiFile.header.getTimeDivision() === MIDIFile.Header.TICKS_PER_BEAT) {
	midiFile.header.getTicksPerBeat();
} else {
	midiFile.header.getSMPTEFrames();
	midiFile.header.getTicksPerFrame();
}

// MIDI events retriever
var events = midiFile.getMidiEvents();
events[0].subtype; // type of [MIDI event](https://github.com/nfroidure/MIDIFile/blob/master/src/MIDIFile.js#L34)
events[0].playTime; // time in ms at wich the event must be played
events[0].param1; // first parameter
events[0].param2; // second one

// Lyrics retriever
var lyrics = midiFile.getLyrics();
if ( lyrics.length ) {
	lyrics[0].playTime; // Time at wich the text must be displayed
	lyrics[0].text; // The text content to be displayed
}

// Reading whole track events and filtering them yourself
var events = midiFile.getTrackEvents(0);

events.forEach(console.log.bind(console));

// Or for a single track
var trackEventsChunk = midiFile.tracks[0].getTrackContent();
var events = MIDIEvents.createParser(trackEventsChunk);

var event;
while(event = events.next()) {
	// Printing meta events containing text only
	if(event.type === MIDIEvents.EVENT_META && event.text) {
		console.log('Text meta: '+event.text);
	}
}

Testing

Unit tests are using mocha and NodeJS. Install them and run the following command:

mocha tests/*.mocha.js

Why ArrayBuffers ?

ArrayBuffer instances are the best way to manage binary data like MIDI files.

Why not streams ?

The Standard MIDI files format isn't streamable by nature. If you want to stream MIDI file contents, you should consider transforming your files in another format (plain linearized MIDI events should do the job).

Requirements

  • ArrayBuffer, DataView or their polyfills

Contributing

  • Feel free to PR
  • If you find a MIDI File the library can't read an if it's under a free, PR the file in the sounds folder and add tests for him. I'll work on it asap.

License

MIT