Code Monkey home page Code Monkey logo

midi-node's Introduction

MIDI for Node.js

A very basic node library to parse and write MIDI messages.

Usage

The library supports three major types of MIDI structures:

  1. A sequence, representing a full MIDI file with multiple tracks.
  2. A track, a ordered collection of messages.
  3. A message, the basic component for the MIDI protocol.

These can all be parsed from a Buffer.

Parsing a Message

var midi = require('midi-node');
var noteOff = new Buffer('803c00', 'hex'); // Channel 0, middle C4, 0 velocity
var message = midi.Message.fromBuffer(noteOff);

message.getStatus(); // 0x80
message.getCommand(); // "NOTE_OFF"
message.getChannel(); // 0
message.getData(); // [0x3c, 0x00]

Parsing messages from a stream

Anything that emits a 'data' event can be used as a stream.

var midi = require('midi-node');
var input = <something readable>;
var stream = new midi.Stream(input);

stream.on('startTrack', function (track) {
		// do something with the track
});

stream.on('event', function (delta, message) {
		message.getStatus(); // 0x80
		message.getCommand(); // "NOTE_OFF"
		message.getChannel(); // 0
		message.getData(); // [0x3c, 0x00]
});

The following events are emitted:

  • startFile, parameter is the file header
  • startTrack, parameter is the track object
  • event, parameters are delta and message
  • endTrack, parameter is the track object
  • error, parameter is the error object

Writing a Message

var midi = require('midi-node');
var stream = <something writable>;
var writer = new midi.Writer(stream);

writer.startFile(0, 1, 128);
writer.startTrack();
writer.noteOn(0, 0, 0x3c, 100); // Channel 0, middle C4, 100 velocity

Resources

http://www.midi.org/techspecs/midimessages.php

midi-node's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.