All Projects → jazz-soft → JZZ-midi-SMF

jazz-soft / JZZ-midi-SMF

Licence: MIT license
Standard MIDI Files: read / write / play

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to JZZ-midi-SMF

MD MIDIFile
Standard MIDI Files (SMF) Processing Library
Stars: ✭ 63 (+125%)
Mutual labels:  midi, smf, midi-file
midi degradation toolkit
A toolkit for generating datasets of midi files which have been degraded to be 'un-musical'.
Stars: ✭ 29 (+3.57%)
Mutual labels:  midi, midi-files
UnityMidiPlayer
Midi file player for unity. Allows import of type zero and one midi files and playing them via midi outputs. Also provides code for creating procedural music using midi.
Stars: ✭ 30 (+7.14%)
Mutual labels:  midi, midi-files
guitar-tabs-to-MIDI
A program that converts Guitar Tabs into MIDI files.
Stars: ✭ 38 (+35.71%)
Mutual labels:  midi, midi-files
ADLMIDI-Player-Java
Simple MIDI-player for Android based on libADLMIDI library
Stars: ✭ 24 (-14.29%)
Mutual labels:  midi, midi-player
unity-midi
Play MIDI (SMF) on Unity, using C# Synth Project.
Stars: ✭ 101 (+260.71%)
Mutual labels:  midi, smf
MidiAnimImporter
A custom importer that imports a .mid file (SMF; Standard MIDI File) into an animation clip.
Stars: ✭ 69 (+146.43%)
Mutual labels:  midi, smf
teensy-midi-looper
teensy midi loop recorder
Stars: ✭ 30 (+7.14%)
Mutual labels:  midi, smf
flutter midi
Midi Playback in Flutter
Stars: ✭ 52 (+85.71%)
Mutual labels:  midi, midi-player
midica
A Music programming language. Translates source code into MIDI. Includes a player. Supports MIDI-Karaoke. Includes a MIDI analyzer.
Stars: ✭ 57 (+103.57%)
Mutual labels:  midi, midi-player
webmscore
MuseScore's core library (libmscore) in WebAssembly! Read mscz data, and generate audio/MIDI/MusicXML/SVG/PNG/PDF sheets right in browsers.
Stars: ✭ 91 (+225%)
Mutual labels:  midi
qq
Houdini little tools and knowledge
Stars: ✭ 21 (-25%)
Mutual labels:  midi
learn-push2-with-svelte
Learn chords, scales, and music theory on the Push 2, right inside your web browser!
Stars: ✭ 37 (+32.14%)
Mutual labels:  midi
amanuensis
The Amanuensis is an automated songwriting and recording system aimed at ridding the process of anything left-brained, so one need never leave a creative, spontaneous and improvisational state of mind, from the inception of the song until its final master. See the README for instructions and feel free to message me at soundcloud.com/to_the_sun.
Stars: ✭ 30 (+7.14%)
Mutual labels:  midi
BS2-Web
Novation Bass Station II Web interface
Stars: ✭ 34 (+21.43%)
Mutual labels:  midi
midi2cv
Use a simple Python script, a few wires, and a MCP4725 to convert any MIDI signal to a control voltage.
Stars: ✭ 26 (-7.14%)
Mutual labels:  midi
apollo-studio
Apollo Studio is a standalone editor and live playback engine for RGB Launchpad light effects.
Stars: ✭ 115 (+310.71%)
Mutual labels:  midi
libDaisy
Hardware Library for the Daisy Audio Platform
Stars: ✭ 164 (+485.71%)
Mutual labels:  midi
kotoist
A VST plugin for live coding and algorithmic composition
Stars: ✭ 37 (+32.14%)
Mutual labels:  midi
facet
Facet is a live coding system for algorithmic music
Stars: ✭ 72 (+157.14%)
Mutual labels:  midi

JZZ-midi-SMF

Standard MIDI Files: read / write / play

Node.js Firefox Chrome Opera Safari Internet Explorer Edge
npm npm build Coverage Status Try jzz-midi-smf on RunKit

Install

npm install jzz-midi-smf --save
or yarn add jzz-midi-smf
or get the full development version and minified scripts from GitHub

Usage

Plain HTML
<script src="JZZ.js"></script>
<script src="JZZ.midi.SMF.js"></script>
//...
CDN (jsdelivr)
<script src="https://cdn.jsdelivr.net/npm/jzz"></script>
<script src="https://cdn.jsdelivr.net/npm/jzz-midi-smf"></script>
//...
CDN (unpkg)
<script src="https://unpkg.com/jzz"></script>
<script src="https://unpkg.com/jzz-midi-smf"></script>
//...
CommonJS (Browserify and Node.js command line applications)
var JZZ = require('jzz');
require('jzz-midi-smf')(JZZ);
//...
AMD
require(['JZZ', 'JZZ.midi.SMF'], function(JZZ, dummy) {
  // ...
});

MIDI files

Supported file formats: .mid, .kar, .rmi

Please check the API Reference !

Playing MIDI file
var midiout = JZZ().openMidiOut();
var data = require('fs').readFileSync('file.mid', 'binary');
// data can be String, Buffer, ArrayBuffer, Uint8Array or Int8Array
var smf = new JZZ.MIDI.SMF(data);
var player = smf.player();
player.connect(midiout);
player.play();
//...
player.speed(0.5); // play twice slower
Viewing the contents of MIDI file
console.log(smf.toString());
Validating MIDI file
var warn = smf.validate();
if (warn) console.log(warn);
Creating MIDI file from scratch
var smf = new JZZ.MIDI.SMF(0, 96); // type 0, 96 ticks per quarter note
var trk = new JZZ.MIDI.SMF.MTrk();
smf.push(trk);
// add contents:
trk.add(0, JZZ.MIDI.smfSeqName('This is a sequence name'))
   .add(0, JZZ.MIDI.smfBPM(90)) // tempo 90 bpm
   .add(96, JZZ.MIDI.noteOn(0, 'C6', 127))
   .add(96, JZZ.MIDI.noteOn(0, 'Eb6', 127))
   .add(96, JZZ.MIDI.noteOn(0, 'G6', 127))
   .add(192, JZZ.MIDI.noteOff(0, 'C6'))
   .add(192, JZZ.MIDI.noteOff(0, 'Eb6'))
   .add(192, JZZ.MIDI.noteOff(0, 'G6'))
   .add(288, JZZ.MIDI.smfEndOfTrack());
// or an alternative way:
trk.smfSeqName('This is a sequence name').smfBPM(90).tick(96)
   .noteOn(0, 'C6', 127).noteOn(0, 'Eb6', 127).noteOn(0, 'G6', 127)
   .tick(96).noteOff(0, 'C6').noteOff(0, 'Eb6').noteOff(0, 'G6')
   .tick(96).smfEndOfTrack();
// or even shorter:
trk.smfSeqName('This is a sequence name').smfBPM(90).tick(96)
   .ch(0).note('C6', 127, 96).note('Eb6', 127, 96).note('G6', 127, 96)
   .tick(192).smfEndOfTrack();
Exporting MIDI file data as JSON or any custom format

One easy thing to remember: SMF is an Array of Tracks and Track is an Array of MIDI events:

for (var i = 0; i < smf.length; i++) {
  for (var j = 0; j < smf[i].length; j++) {
    console.log('track:', i, 'tick:', smf[i][j].tt, smf[i][j].toString());
    // or do whatever else with the message
  }
}
Transposing MIDI file
for (var i = 0; i < smf.length; i++) {
  if (smf[i] instanceof JZZ.MIDI.SMF.MTrk) {
    for (var j = 0; j < smf[i].length; j++) {
      var note = smf[i][j].getNote();
      if (typeof note != 'undefined') {
        if (smf[i][j].getChannel() != 9) { // skip the percussion channel
          smf[i][j].setNote(note + 12);    // transpose one octave up
        }
      }
    }
  }
}
Getting the info
var player = smf.player();
var dump = smf.dump();
console.log('Type:', player.type());
console.log('Number of tracks:', player.tracks());
console.log('Size:', dump.length, 'bytes');
console.log('Duration:', player.duration(), 'ticks');
console.log('Total time:', player.durationMS(), 'milliseconds');
Saving MIDI file
require('fs').writeFileSync('out.mid', smf.dump(), 'binary');

SYX files

All calls are almost identical to those for the SMF files:
var data = require('fs').readFileSync('file.syx', 'binary');
var syx = new JZZ.MIDI.SYX(data);
syx.send([0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7]);
syx.sxMasterVolumeF(0.5);
var player = syx.player();
player.connect(midiout);
player.play();
require('fs').writeFileSync('out.syx', syx.dump(), 'binary');

Live DEMOs (source code included)

Read MIDI file - from file, URL, Base64
Write MIDI file - create MIDI file from scratch
MIDI Player - various ways to play MIDI file
Karaoke - playing MIDI files in .kar format

See also

Test MIDI Files - these may be useful if you write a MIDI application...

More information

Please visit https://jazz-soft.net for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].