midijs
Read and write Standard MIDI files and enable communication with MIDI devices!
This module provides a high-level API for working with Standard MIDI and General MIDI events that are sent through MIDI inputs and outputs, or read from a file.
Install
npm install --save midijs
Run tests
cd midijs/npm installnpm test
Check code coverage
cd midijs/npm installnpm run coverage
Make documentation
cd midijs/npm installnpm run docs
Usage
File
Read or write data from or to a Standard MIDI file.
Creating an empty file:
var MIDI = ;var file = ; // file.header contains default header data// file.tracks is empty
Loading data from an existing file, using the Buffer API:
var MIDI = ;var fs = ; fs;
Or using the Stream API:
var MIDI = ;var fs = ; var file = ; file; file; fs;
Changing elements in a file:
var MIDI = ;var File = MIDIFile; /** edit header **/ file; // speed up twicefile; // change file type /** edit tracks **/ file; // get all tracksfile; // get a trackfile; // remove given track // add a track with eventsfile; /** edit events in a track **/ track; // get all eventstrack; // get an eventtrack; // remove given eventtrack;
Saving data to a SMF file, using the Buffer API:
var MIDI = ;var fs = ; var file = ; // add/remove tracks or events... file;
Or using the Stream API:
var MIDI = ;var fs = ; var file = ; // add/remove tracks or events... file; file; file;
gm
List of programs numbers associated to instruments and families defined by the General MIDI standard.
Knowing an instrument's name (as a string) as defined by the
specification,
you can retrieve its program number, using the getProgram()
method.
IMPORTANT NOTE: the program number is calculated starting from 0, but the specification's indices start from 1. Be careful.
MIDIgm; // 10MIDIgm; // 10MIDIgm; // 10MIDIgm; // false
Knowing an instrument's program number as defined by the
specification,
you can retrieve its name, using the getInstrument()
method, or
its family name with the getFamily()
method.
MIDIgm; // 'music box'MIDIgm; // 'chromatic percussion'MIDIgm; // 'chromatic percussion'MIDIgm; // 'music box'MIDIgm; // false
Result of the getProgram()
or getInstrument()
method can be
limited to check if the given instrument is within the given family,
using the second argument.
connect()
Access a MIDI driver that enables communication with the plugged MIDI devices (outputs and inputs). This API is currently only available in the browser. It relies on the WebMIDI API and thus requires an authorization from the user.
If the user declines access to his MIDI devices, then the Promise fails.
Otherwise, it is fullfilled with a driver instance.
Attempting to connect:
var MIDI = ; MIDI ;
The driver is a bridge to output and input devices. It contains a list
of devices that are currently plugged in, and emits connect
or
disconnect
events whether one of them is connected or disconnected.
var MIDI = ; // driver.inputs is a list of current inputs// driver.outputs is a list of current outputs driver;
You can send events to an output:
var MIDI = ;var ChannelEvent = MIDIFileChannelEvent; output;
And wait for events from an input:
var MIDI = ;var ChannelEvent = MIDIFileChannelEvent; input;
You can select a default input and a default output on the driver. Events from the default input will bubble to the driver and events sent to the driver will be sent to the default output.
var MIDI = ; driver; // by positiondriver; // by unique input ID driver; // by positiondriver; // by unique output ID // send a "note on" event to the default outputdriver; driver;
errors
Constructors of errors that can be emitted by this module.
Contributing
All contributions are welcome! In order to have a consistent repo, we however ask you to comply to the following conventions whenever possible.
1. Commit tags
All commits should be tagged with emojis to make the commit list more readable.
Emoji | Commit content |
---|---|
📖 | Documentation updates |
🐛 | Bug fixes |
📒 | Rename/move files |
💡 | Features |
💄 | Fix coding style |
2. Branches
Please use a branch name that differs from master
whenever possible,
when making pull requests, so that the network history is more
readable.
For example, if you wanted to fix the issue
"improve documentation", you could have
chosen the following branch name: improve-docs
.
3. Coding style
Javascript can be authored by following a lot of different style guides but we decided to be a bit soft on that.
Just follow the conventions that are encoded into the .eslintrc
configuration file. By the way, be sure to check out ESLint,
which is a great toolable style checker.
- Use the radix parameter in
parseInt()
calls. - Declare all your variables at the top of the functions.
- Use the one true brace style.
- Put one space after commas, and no space before.
- Put your comma at the end of the lines.
- Use simple quotes.
- Use camelcase.
- Use 4 spaces for indentation.
License
See LICENSE.