Detalhes do pacote

midi

justinlatimer858MIT2.0.0

MIDI hardware IO

readme (leia-me)

♪ ♫ ♩ ♬

node-midi

A node.js wrapper for the RtMidi C++ library that provides realtime MIDI I/O. RtMidi supports Linux (ALSA & Jack), Macintosh OS X (CoreMidi), and Windows (Multimedia).

Build Status

Prerequisites

OSX

  • Some version of Xcode (or Command Line Tools)
  • Python (for node-gyp)

Windows

  • Microsoft Visual C++ (the Express edition works fine)
  • Python (for node-gyp)

Linux

  • A C++ compiler
  • You must have installed and configured ALSA. Without it this module will NOT build.
  • Install the libasound2-dev package.
  • Python (for node-gyp)

Installation

Installation uses node-gyp and requires Python 2.7.2 or higher.

From npm:

$ npm install midi

From source:

$ git clone https://github.com/justinlatimer/node-midi.git
$ cd node-midi/
$ npm install

Usage

MIDI Messages

This library deals with MIDI messages as JS Arrays for both input and output. For example, [144,69,127] is MIDI message with status code 144 which means "Note on" on "Channel 1".

For list of midi status codes, see http://www.midi.org/techspecs/midimessages.php

Input

const midi = require('midi');

// Set up a new input.
const input = new midi.Input();

// Count the available input ports.
input.getPortCount();

// Get the name of a specified input port.
input.getPortName(0);

// Configure a callback.
input.on('message', (deltaTime, message) => {
  // The message is an array of numbers corresponding to the MIDI bytes:
  //   [status, data1, data2]
  // https://www.cs.cf.ac.uk/Dave/Multimedia/node158.html has some helpful
  // information interpreting the messages.
  console.log(`m: ${message} d: ${deltaTime}`);
});

// Open the first available input port.
input.openPort(0);

// Sysex, timing, and active sensing messages are ignored
// by default. To enable these message types, pass false for
// the appropriate type in the function below.
// Order: (Sysex, Timing, Active Sensing)
// For example if you want to receive only MIDI Clock beats
// you should use
// input.ignoreTypes(true, false, true)
input.ignoreTypes(false, false, false);

// ... receive MIDI messages ...

// Close the port when done.
setTimeout(function() {
  input.closePort();
}, 100000);

Output

const midi = require('midi');

// Set up a new output.
const output = new midi.Output();

// Count the available output ports.
output.getPortCount();

// Get the name of a specified output port.
output.getPortName(0);

// Open the first available output port.
output.openPort(0);

// Send a MIDI message.
output.sendMessage([176,22,1]);

// Close the port when done.
output.closePort();

Virtual Ports

Instead of opening a connection to an existing MIDI device, on Mac OS X and Linux with ALSA you can create a virtual device that other software may connect to. This can be done simply by calling openVirtualPort(portName) instead of openPort(portNumber).

const midi = require('midi');

// Set up a new input.
const input = new midi.Input();

// Configure a callback.
input.on('message', (deltaTime, message) => {
    console.log(`m: ${message} d: ${deltaTime}`);
});

// Create a virtual input port.
input.openVirtualPort("Test Input");

// A midi device "Test Input" is now available for other
// software to send messages to.

// ... receive MIDI messages ...

// Close the port when done.
input.closePort();

The same can be done with output ports.

Streams

You can also use this library with streams! Here are the interfaces

Readable Stream

// create a readable stream
const stream1 = midi.createReadStream();

// createReadStream also accepts an optional `input` param
const input = new midi.Input();
input.openVirtualPort('hello world');

const stream2 = midi.createReadStream(input)

stream2.pipe(require('fs').createWriteStream('something.bin'));

Writable Stream

// create a writable stream
const stream1 = midi.createWriteStream();

// createWriteStream also accepts an optional `output` param
const output = new midi.Output();
output.openVirtualPort('hello again');

const stream2 = midi.createWriteStream(output);

require('fs').createReadStream('something.bin').pipe(stream2);

References

Maintainers

Contributors

License

Copyright (C) 2011-2021 by Justin Latimer.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

A different license may apply to other software included in this package, including RtMidi. Please consult their respective license files for the terms of their individual licenses.

changelog (log de mudanças)

node-midi Changelog

Version 2.0.0

  • Add tests for listing ports.
  • Prevent RtMidi from ensuring unique port names on Windows (Breaking change to behaviour of port names on Windows).
  • RtMidi Changes
    • Trim whitespace changes from endpoint names (Breaking change to behaviour of port names on macOS).
    • Refactor CoreMIDI client usage for stability.

Version 1.0.4

  • Use a git submodule for RtMidi.
  • Use a larger sysex message buffer size on Windows.
  • Fix links in readme (dzoba)

Version 1.0.3

  • Update RtMidi to d2dd50d.

Version 1.0.2

  • Add a 'send' alias for 'sendMessage'.
  • Use the NAN module init.
  • Ensure promises can be resolved inside on('message') callbacks (Malvineous)

Version 1.0.1

  • Update supported node versions.
  • Update dependencies.

Version 1.0.0

  • Added isPortOpen (nroadley)
  • Improve examples in README (Simon Egersand)
  • Updated examples to es6 (Amila Welihinda)
  • Update mocha (The Repo Nanny)
  • Update rtmidi to 4.0.0 (Tim Susa)
  • Add license to package.json.
  • Use NAN to handle additional differences in modern nodejs versions.
  • Change supported nodejs version to 6, 8, 10, 12.
  • Better handling of Buffer for stream (jhorology)
  • Fixing read stream resume bug (justinjmoses)
  • Fix clean up of inputs.
  • Exception catching to prevent RtMidi errors crashing the node process (Jeremy Bernstein)
  • Split classes into different files.
  • Fix capitalisation on the classes.
  • Add some documentation about MIDI message formats.

Version 0.9.5

  • Updated RtMidi to most recent version (Szymon Kaliski)
  • Updating NAN to the latest version. This allows node 6.2.0 to be used. (Michael Lawrence)

Version 0.9.4

  • Upgrade to nan v2.0 (Julián Duque)
  • Call cancelCallback when closing port (Szymon Kaliski)

Version 0.9.3

  • Update NAN version for iojs 2.x support. (Ilkka Myller)

Version 0.9.2

  • More NAN use for broader support (nw.js, iojs). (Andrew Morton)

Version 0.9.1

  • Use NAN to support node 0.8-0.12. (Andrew Morton)

Version 0.9.0

  • Avoid fatal error closing unopened port. (Andrew Morton)
  • Upgraded RtMidi to 2.1.0. (Hugo Hromic)
  • Fixed compile warnings on Windows. (Hugo Hromic)

Version 0.8.1

  • Fixing crash when new is omitted. (Andrew Morton)

Version 0.8.0

  • Update RtMidi to latest upstream. (Andrew Morton)
  • Added missing MIDI Clock event case. (Hugo Hromic)
  • Upgraded RtMidi library to version 2.0.1. (Hugo Hromic)

Version 0.7.1

  • Remove unmatched uv_unref() causing segfault. (Andrew Morton)

Version 0.7.0

  • Add readable/writable stream support. (Elijah Insua)

Version 0.6.0

  • Upgrade build system to node-gyp bringing Windows support. (Michael Alyn Miller)
  • Fix an overzealous delete.

Version 0.5.0

  • Switch from using libev to libuv. (Luc Deschenaux)
  • Check a port number is valid before trying to open it. (Luc Deschenaux)
  • Remove support for node versions < 0.6.0.
  • Code and build system improvements with new supported node versions.
  • Update documentation.

Version 0.4.0

  • Upgrade RtMidi to 1.0.15. (Luc Deschenaux)
  • Refactor the EventEmitter inheritance to support node > 0.5.2. (Luc Deschenaux)
  • Add support for ignore type settings (Sysex, Timing, Active Sensing) on the input. (Luc Deschenaux)
  • List supported node versions in the package.json.

Version 0.3.0

  • Add support for virtual input and output ports.

Version 0.2.0

  • Add Linux support to the build script.

Version 0.1.0

  • Initial release.