
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@pioug/MidiConvert
Advanced tools
This is a fork of Tonejs/MidiConvert. The fork has diverged since by including directly the parser of NHQ/midi-file-parser and adding the following features:
The toolchain is also different:
Read more about the changes in the CHANGELOG.md.
This library can be installed via NPM:
npm i --save @pioug/MidiConvert
In HTML:
<script src="build/MidiConvert.js"></script>
Or in JavaScript:
var MidiConvert = require('@pioug/MidiConvert');
MidiConvert.parse(BinaryString midiBlob, [Object options]) => ObjectThis function returns an object with two properties:
transport: the bpm and time signature values of the midi file as a Javascript Object (formerly parseTransport)parts: an array of the tracks. Each track is an array of notes (formerly parseParts)var midiObject = MidiConvert.parse(midiBlob, options);
{
transport: {
bpm: 120,
instruments: [1, 25, 0],
timeSignature: [4, 4],
trackNames: ["Solo piano", "Guitar riff", "Kick-ass drums"]
},
parts: [
[
{
time: "0i",
midiNote: 67,
noteName: "G4",
velocity: 0.7086614173228346,
duration: "12i"
},
... rest of events
],
... rest of tracks
]
}
Which can then be used in Tone.Part:
var pianoPart = new Tone.Part(callback, midiObject.parts[0]).start();
The options object defines how the MIDI file is parsed:
MidiConvert.parse(midiBlob, {
/*
* the pulses per quarter note at which
* the midi file is parsed.
*/
PPQ : 192,
/*
* if the notes scientific pitch notation
* should be included in the output.
*/
noteName : true,
/*
* if the normalized velocity should be included
* in the output
*/
velocity : true,
/*
* if the time between the noteOn and noteOff event
* should be included in the output. Otherwise
* each event represents a noteOn.
*/
duration : true,
/*
* execute an additional sorting function
* useful for testing
*/
deterministic: true
});
MidiConvert.generate(midiJson) => BufferGenerate a file buffer from an object respecting the structure of the parse output.
var sourceFile = fs.readFileSync('./midi/bwv-846.mid', 'binary'),
sourceData = MidiConvert.parse(sourceFile, midiConvertOpts),
destinationData = MidiConvert.parse(MidiConvert.generate(sourceData), midiConvertOpts);
t.deepEqual(sourceData, destinationData) // TRUE;
MidiConvert.FileaddTrack() - Add a new Track object to the file and return the new trackaddTrack(track) - Add the given Track object to the file and return the filetoBytes() - Convert to bufferMidiConvert.TrackTime and duration are specified in "ticks", and there is a hardcoded value of 128 ticks per beat. This means that a quarter note has a duration of 128.
Pitch can be specified by note name with octave (a#4) or by note number (60).
Middle C is represented as c4 or 60.
addNote(channel, pitch, duration[, time[, velocity]])
time is given, delay that many ticks before starting the notevelocity is given, strike the note with that velocityaddNoteOn(channel, pitch[, time[, velocity]])
-Start a new note with the given channel and pitch
time is given, delay that many ticks before starting the notevelocity is given, strike the note with that velocityaddNoteOff(channel, pitch[, time[, velocity]])
time is given, delay that many ticks before ending the notevelocity is given, strike the note with that velocityaddChord(channel, chord[, velocity])
velocity is given, strike the chord with that velocitysetInstrument(channel, instrument[, time])
time is given, delay that many ticks before making the changesetTempo(bpm[, time])
bpm beats per minutetime is given, delay that many ticks before making the changesetTimeSignature(numerator, denominator[, time])
time is given, delay that many ticks before making the changesetTrackName(name[, time])
time is given, delay that many ticks before making the changevar fs = require('fs');
var MidiConvert = require('@pioug/MidiConvert');
var file = new MidiConvert.MidiGen.File();
var track = new MidiConvert.MidiGen.Track();
file.addTrack(track);
track.addNote(0, 'C4', 64);
track.addNote(0, 'D4', 64);
track.addNote(0, 'E4', 64);
track.addNote(0, 'F4', 64);
track.addNote(0, 'G4', 64);
track.addNote(0, 'A4', 64);
track.addNote(0, 'B4', 64);
track.addNote(0, 'B5', 64);
fs.writeFileSync('test.mid', file.toBytes(), 'binary');
In Node.js, pass to MidiConvert the output from fs.readFile:
fs.readFile('./test.mid', 'binary', function(err, buffer) {
if (err) return;
var midiObject = MidiConvert.parse(buffer);
});
In the browser, the MIDI blob as a string can be obtained using the FileReader API.
var reader = new FileReader();
reader.onload = function(e) {
var midiObject = MidiConvert.parse(e.target.result);
}
reader.readAsBinaryString(file);
If you want to contribute to this project:
git clone git@github.com:pioug/MidiConvert.git
npm i
npm run build
npm test
FAQs
Convert MIDI file to JSON-friendly format
We found that @pioug/MidiConvert demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.