-
Notifications
You must be signed in to change notification settings - Fork 1
/
midiutils.min.js
10 lines (10 loc) · 11.9 KB
/
midiutils.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* MIDI utils v1.0 - https://github.com/hhromic/midi-utils-js
* A very simple collection of utilities to process MIDI data for JavaScript.
* MIT license
* Hugo Hromic - http://github.com/hhromic
*
* @requires EventEmitter
* @license
*/
(function(){"use strict";function e(){EventEmitter.call(this),this._pressed=0,this._heldNotes=new Array(16);for(var e=16;e--;)this._heldNotes[e]=new Uint32Array(4)}e.prototype=Object.create(EventEmitter.prototype);var t=e.prototype;t.press=function(e){this._pressed|=1<<(15&e)},t.release=function(t){this._pressed&=~(1<<(15&t));for(var e=128;e--;)this._heldNotes[15&t][e/32]>>e%32&1&&(this._heldNotes[15&t][e/32]&=~(1<<e%32),this.emit("note-off",t,e,0))},t.noteOn=function(t,e,i){this._heldNotes[15&t][(127&e)/32]>>(127&e)%32&1&&(this._heldNotes[15&t][(127&e)/32]&=~(1<<(127&e)%32)),this.emit("note-on",t,e,i)},t.noteOff=function(e,t,i){this._pressed>>(15&e)&1?this._heldNotes[15&e][(127&t)/32]|=1<<(127&t)%32:this.emit("note-off",e,t,i)},"function"==typeof define&&define.amd?define(function(){return e}):"object"==typeof module&&module.exports?module.exports=e:this.MidiDamperPedal=e}).call(this),function(){"use strict";function e(){EventEmitter.call(this)}var i={35:"Acoustic Bass Drum",36:"Bass Drum 1",37:"Side Stick",38:"Acoustic Snare",39:"Hand Clap",40:"Electric Snare",41:"Low Floor Tom",42:"Closed Hi Hat",43:"High Floor Tom",44:"Pedal Hi-Hat",45:"Low Tom",46:"Open Hi-Hat",47:"Low-Mid Tom",48:"Hi-Mid Tom",49:"Crash Cymbal 1",50:"High Tom",51:"Ride Cymbal 1",52:"Chinese Cymbal",53:"Ride Bell",54:"Tambourine",55:"Splash Cymbal",56:"Cowbell",57:"Crash Cymbal 2",58:"Vibraslap",59:"Ride Cymbal 2",60:"Hi Bongo",61:"Low Bongo",62:"Mute Hi Conga",63:"Open Hi Conga",64:"Low Conga",65:"High Timbale",66:"Low Timbale",67:"High Agogo",68:"Low Agogo",69:"Cabasa",70:"Maracas",71:"Short Whistle",72:"Long Whistle",73:"Short Guiro",74:"Long Guiro",75:"Claves",76:"Hi Wood Block",77:"Low Wood Block",78:"Mute Cuica",79:"Open Cuica",80:"Mute Triangle",81:"Open Triangle"},o={0:"C-2",1:"C#-2",2:"D-2",3:"D#-2",4:"E-2",5:"F-2",6:"F#-2",7:"G-2",8:"G#-2",9:"A-2",10:"A#-2",11:"B-2",12:"C-1",13:"C#-1",14:"D-1",15:"D#-1",16:"E-1",17:"F-1",18:"F#-1",19:"G-1",20:"G#-1",21:"A-1",22:"A#-1",23:"B-1",24:"C0",25:"C#0",26:"D0",27:"D#0",28:"E0",29:"F0",30:"F#0",31:"G0",32:"G#0",33:"A0",34:"A#0",35:"B0",36:"C1",37:"C#1",38:"D1",39:"D#1",40:"E1",41:"F1",42:"F#1",43:"G1",44:"G#1",45:"A1",46:"A#1",47:"B1",48:"C2",49:"C#2",50:"D2",51:"D#2",52:"E2",53:"F2",54:"F#2",55:"G2",56:"G#2",57:"A2",58:"A#2",59:"B2",60:"C3",61:"C#3",62:"D3",63:"D#3",64:"E3",65:"F3",66:"F#3",67:"G3",68:"G#3",69:"A3",70:"A#3",71:"B3",72:"C4",73:"C#4",74:"D4",75:"D#4",76:"E4",77:"F4",78:"F#4",79:"G4",80:"G#4",81:"A4",82:"A#4",83:"B4",84:"C5",85:"C#5",86:"D5",87:"D#5",88:"E5",89:"F5",90:"F#5",91:"G5",92:"G#5",93:"A5",94:"A#5",95:"B5",96:"C6",97:"C#6",98:"D6",99:"D#6",100:"E6",101:"F6",102:"F#6",103:"G6",104:"G#6",105:"A6",106:"A#6",107:"B6",108:"C7",109:"C#7",110:"D7",111:"D#7",112:"E7",113:"F7",114:"F#7",115:"G7",116:"G#7",117:"A7",118:"A#7",119:"B7",120:"C8",121:"C#8",122:"D8",123:"D#8",124:"E8",125:"F8",126:"F#8",127:"G8"},r={0:"Piano",8:"Chromatic Percussion",16:"Organ",24:"Guitar",32:"Bass",40:"Strings",48:"Ensemble",56:"Brass",64:"Reed",72:"Pipe",80:"Synth Lead",88:"Synth Pad",96:"Synth Effects",104:"Ethnic",112:"Percussive",120:"Sound Effects"},s={0:"Acoustic Grand Piano",1:"Bright Acoustic Piano",2:"Electric Grand Piano",3:"Honky-tonk Piano",4:"Electric Piano 1",5:"Electric Piano 2",6:"Harpsichord",7:"Clavi",8:"Celesta",9:"Glockenspiel",10:"Music Box",11:"Vibraphone",12:"Marimba",13:"Xylophone",14:"Tubular Bells",15:"Dulcimer",16:"Drawbar Organ",17:"Percussive Organ",18:"Rock Organ",19:"Church Organ",20:"Reed Organ",21:"Accordion",22:"Harmonica",23:"Tango Accordion",24:"Acoustic Guitar (nylon)",25:"Acoustic Guitar (steel)",26:"Electric Guitar (jazz)",27:"Electric Guitar (clean)",28:"Electric Guitar (muted)",29:"Overdriven Guitar",30:"Distortion Guitar",31:"Guitar harmonics",32:"Acoustic Bass",33:"Electric Bass (finger)",34:"Electric Bass (pick)",35:"Fretless Bass",36:"Slap Bass 1",37:"Slap Bass 2",38:"Synth Bass 1",39:"Synth Bass 2",40:"Violin",41:"Viola",42:"Cello",43:"Contrabass",44:"Tremolo Strings",45:"Pizzicato Strings",46:"Orchestral Harp",47:"Timpani",48:"String Ensemble 1",49:"String Ensemble 2",50:"SynthStrings 1",51:"SynthStrings 2",52:"Choir Aahs",53:"Voice Oohs",54:"Synth Voice",55:"Orchestra Hit",56:"Trumpet",57:"Trombone",58:"Tuba",59:"Muted Trumpet",60:"French Horn",61:"Brass Section",62:"SynthBrass 1",63:"SynthBrass 2",64:"Soprano Sax",65:"Alto Sax",66:"Tenor Sax",67:"Baritone Sax",68:"Oboe",69:"English Horn",70:"Bassoon",71:"Clarinet",72:"Piccolo",73:"Flute",74:"Recorder",75:"Pan Flute",76:"Blown Bottle",77:"Shakuhachi",78:"Whistle",79:"Ocarina",80:"Lead 1 (square)",81:"Lead 2 (sawtooth)",82:"Lead 3 (calliope)",83:"Lead 4 (chiff)",84:"Lead 5 (charang)",85:"Lead 6 (voice)",86:"Lead 7 (fifths)",87:"Lead 8 (bass + lead)",88:"Pad 1 (new age)",89:"Pad 2 (warm)",90:"Pad 3 (polysynth)",91:"Pad 4 (choir)",92:"Pad 5 (bowed)",93:"Pad 6 (metallic)",94:"Pad 7 (halo)",95:"Pad 8 (sweep)",96:"FX 1 (rain)",97:"FX 2 (soundtrack)",98:"FX 3 (crystal)",99:"FX 4 (atmosphere)",100:"FX 5 (brightness)",101:"FX 6 (goblins)",102:"FX 7 (echoes)",103:"FX 8 (sci-fi)",104:"Sitar",105:"Banjo",106:"Shamisen",107:"Koto",108:"Kalimba",109:"Bag pipe",110:"Fiddle",111:"Shanai",112:"Tinkle Bell",113:"Agogo",114:"Steel Drums",115:"Woodblock",116:"Taiko Drum",117:"Melodic Tom",118:"Synth Drum",119:"Reverse Cymbal",120:"Guitar Fret Noise",121:"Breath Noise",122:"Seashore",123:"Bird Tweet",124:"Telephone Ring",125:"Helicopter",126:"Applause",127:"Gunshot"};e.prototype=Object.create(EventEmitter.prototype);var t=e.prototype;t.getGM1DrumNoteName=function(e){return i[e]},t.getGM1NoteName=function(e){return o[e]},t.getGM1FamilyName=function(e){return r[8*Math.floor(e/8)]},t.getGM1ProgramName=function(e){return s[e]},t.parse=function(i){if(i instanceof Uint8Array&&i.length>0){var a=240&i[0],e=15&i[0];switch(a){case 128:if(i.length>1){var o=127&i[1],r=127&i[2];this.emit("note-off",e,o,r)}return;case 144:if(i.length>2){var o=127&i[1],r=127&i[2];r>0?this.emit("note-on",e,o,r):this.emit("note-off",e,o,r)}return;case 160:if(i.length>2){var o=127&i[1],s=127&i[2];this.emit("key-pressure",e,o,s)}return;case 176:if(i.length>2){var n=127&i[1],t=127&i[2];switch(n){case 0:return void this.emit("bank-select",e,t);case 1:return void this.emit("mod-wheel",e,t);case 2:return void this.emit("breath-controller",e,t);case 4:return void this.emit("foot-controller",e,t);case 5:return void this.emit("portamento-time",e,t);case 7:return void this.emit("volume",e,t);case 8:return void this.emit("balance",e,t);case 10:return void this.emit("pan",e,t);case 11:return void this.emit("expression-controller",e,t);case 12:return void this.emit("effect-control-1",e,t);case 13:return void this.emit("effect-control-2",e,t);case 16:return void this.emit("gp-controller-1",e,t);case 17:return void this.emit("gp-controller-2",e,t);case 18:return void this.emit("gp-controller-3",e,t);case 19:return void this.emit("gp-controller-4",e,t);case 32:return void this.emit("bank-select-fine",e,t);case 33:return void this.emit("mod-wheel-fine",e,t);case 34:return void this.emit("breath-controller-fine",e,t);case 36:return void this.emit("foot-controller-fine",e,t);case 37:return void this.emit("portamento-time-fine",e,t);case 39:return void this.emit("volume-fine",e,t);case 40:return void this.emit("balance-fine",e,t);case 42:return void this.emit("pan-fine",e,t);case 43:return void this.emit("expression-controller-fine",e,t);case 44:return void this.emit("effect-control-1-fine",e,t);case 45:return void this.emit("effect-control-2-fine",e,t);case 48:return void this.emit("gp-controller-1-fine",e,t);case 49:return void this.emit("gp-controller-2-fine",e,t);case 50:return void this.emit("gp-controller-3-fine",e,t);case 51:return void this.emit("gp-controller-4-fine",e,t);case 64:return void(64>t?this.emit("damper-off",e):this.emit("damper-on",e));case 65:return void(64>t?this.emit("portamento-off",e):this.emit("portamento-on",e));case 66:return void(64>t?this.emit("sostenuto-off",e):this.emit("sostenuto-on",e));case 67:return void(64>t?this.emit("soft-off",e):this.emit("soft-on",e));case 68:return void(64>t?this.emit("legato-off",e):this.emit("legato-on",e));case 69:return void(64>t?this.emit("hold2-off",e):this.emit("hold2-on",e));case 70:return void this.emit("sound-variation",e,t);case 71:return void this.emit("timbre-intensity",e,t);case 72:return void this.emit("release-time",e,t);case 73:return void this.emit("attack-time",e,t);case 74:return void this.emit("brightness",e,t);case 75:return void this.emit("decay-time",e,t);case 76:return void this.emit("vibrato-rate",e,t);case 77:return void this.emit("vibrato-depth",e,t);case 78:return void this.emit("vibrato-delay",e,t);case 79:return void this.emit("snd-controller-10",e,t);case 80:return void this.emit("gp-controller-5",e,t);case 81:return void this.emit("gp-controller-6",e,t);case 82:return void this.emit("gp-controller-7",e,t);case 83:return void this.emit("gp-controller-8",e,t);case 84:return void this.emit("portamento",e,t);case 91:return void this.emit("reverb-depth",e,t);case 92:return void this.emit("tremolo-depth",e,t);case 93:return void this.emit("chorus-depth",e,t);case 94:return void this.emit("detune-depth",e,t);case 95:return void this.emit("phaser-depth",e,t);case 120:return void this.emit("all-sound-off",e);case 121:return void this.emit("reset-all-controllers",e);case 123:return void this.emit("all-notes-off",e)}}return void this.emit("unknown-control-change",e,n,t);case 192:if(i.length>1){var c=127&i[1];this.emit("program-change",e,c)}return;case 208:if(i.length>1){var s=127&i[1];this.emit("channel-pressure",e,s)}return;case 224:if(i.length>2){var h=127&i[1],l=127&i[2];this.emit("pitch-bend",e,(h<<7)+l)}return}return void this.emit("unknown-message",i)}},"function"==typeof define&&define.amd?define(function(){return e}):"object"==typeof module&&module.exports?module.exports=e:this.MidiParser=e}.call(this),function(){"use strict";function e(){EventEmitter.call(this),this._softenFactor=2/3,this._pressed=0}e.prototype=Object.create(EventEmitter.prototype);var t=e.prototype;t.getSoftenFactor=function(){return this._softenFactor},t.setSoftenFactor=function(e){e>=0&&1>=e&&(this._softenFactor=e)},t.press=function(e){this._pressed|=1<<(15&e)},t.release=function(e){this._pressed&=~(1<<(15&e))},t.noteOn=function(e,t,i){this._pressed>>(15&e)&1&&this.emit("note-on",e,t,Math.round(i*this._softenFactor)),this.emit("note-on",e,t,i)},"function"==typeof define&&define.amd?define(function(){return e}):"object"==typeof module&&module.exports?module.exports=e:this.MidiSoftPedal=e}.call(this),function(){"use strict";function e(){EventEmitter.call(this),this._pressed=0,this._prePedalNotes=new Array(16),this._pedalNotes=new Array(16),this._heldNotes=new Array(16);for(var e=16;e--;)this._prePedalNotes[e]=new Uint32Array(4),this._pedalNotes[e]=new Uint32Array(4),this._heldNotes[e]=new Uint32Array(4)}e.prototype=Object.create(EventEmitter.prototype);var t=e.prototype;t.press=function(e){this._pressed|=1<<(15&e);for(var t=4;t--;)this._pedalNotes[15&e][t]=this._prePedalNotes[15&e][t]},t.release=function(t){this._pressed&=~(1<<(15&t));for(var e=128;e--;)this._pedalNotes[15&t][e/32]&=~(1<<e%32),this._heldNotes[15&t][e/32]>>e%32&1&&(this._heldNotes[15&t][e/32]&=~(1<<e%32),this.emit("note-off",t,e,0))},t.noteOn=function(t,e,i){this._prePedalNotes[15&t][(127&e)/32]|=1<<(127&e)%32,this._pressed>>(15&t)&1&&(this._heldNotes[15&t][(127&e)/32]&=~(1<<(127&e)%32)),this.emit("note-on",t,e,i)},t.noteOff=function(t,e,i){this._prePedalNotes[15&t][(127&e)/32]&=~(1<<(127&e)%32),this._pressed>>(15&t)&1&&this._pedalNotes[15&t][(127&e)/32]>>(127&e)%32&1?this._heldNotes[15&t][(127&e)/32]|=1<<(127&e)%32:this.emit("note-off",t,e,i)},"function"==typeof define&&define.amd?define(function(){return e}):"object"==typeof module&&module.exports?module.exports=e:this.MidiSostenutoPedal=e}.call(this);