Socket
Socket
Sign inDemoInstall

yjmidi

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yjmidi - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0

2

dist/yjmidi.min.js

@@ -1,1 +0,1 @@

(()=>{var e={270:(e,t,i)=>{e.exports={Consts:i(370),MidiFile:i(23),MidiTrack:i(524),MidiPlayer:i(720)}},127:(e,t,i)=>{e.exports={ByteStream:i(615),ByteStreamSimulator:i(889)}},615:(e,t,i)=>{const r=i(349),n=i(114);e.exports=class{constructor(e){this.buf=e?this.ensureArrayBuffer(e):new ArrayBuffer,this.i=0,this.view=new DataView(this.buf),this.u8=new Uint8Array(this.buf)}get buffer(){return this.buf}get length(){return this.buf.byteLength}get isDataAvailable(){return this.i<this.buf.byteLength}readInt8(){return this.view.getInt8(this.i++)}readUint8(){return this.view.getUint8(this.i++)}readBytes(e){if(this.i+e>this.buf.byteLength)throw new RangeError("Offset is outside the bounds of the ArrayBuffer");return this.u8.subarray(this.i,this.i+=e)}readInt16(e){let t=this.view.getInt16(this.i,e);return this.i+=2,t}readUint16(e){let t=this.view.getUint16(this.i,e);return this.i+=2,t}readInt32(e){let t=this.view.getInt32(this.i,e);return this.i+=4,t}readUint32(e){let t=this.view.getUint32(this.i,e);return this.i+=4,t}readBigInt64(e){let t=this.view.getBigInt64(this.i,e);return this.i+=8,t}readBigUint64(e){let t=this.view.getBigUint64(this.i,e);return this.i+=8,t}readFloat32(e){let t=this.view.getFloat32(this.i,e);return this.i+=4,t}readFloat64(e){let t=this.view.getFloat64(this.i,e);return this.i+=8,t}readVarIntBytes(e=1/0){let t=[],i=0;for(;e>i++;)if(t.push(this.readUint8()),!(128&t[t.length-1]))return t;throw new RangeError(`0x${this.i.toString(16)}: Variable integer length cannot exceed ${e} bytes`)}readVarInt(e,t=1/0){let i=this.readVarIntBytes(t);return e||(i=i.reverse(),i[0]+=128,i[i.length-1]-=128),r.decode(i)}readVarUint(e,t=1/0){let i=this.readVarIntBytes(t);return e||(i=i.reverse(),i[0]+=128,i[i.length-1]-=128),n.decode(i)}expandBuffer(e){if(this.buf.byteLength>=this.i+e)return;if((e=this.i+e-this.buf.byteLength)<=0)return;let t=new Uint8Array(this.buf.byteLength+e);t.set(new Uint8Array(this.buf)),this.buf=t.buffer,this.view=new DataView(this.buf),this.u8=t}writeInt8(e){this.expandBuffer(1),this.view.setInt8(this.i++,e)}writeUint8(e){this.expandBuffer(1),this.view.setUint8(this.i++,e)}writeBytes(e){this.expandBuffer(e.length),this.u8.set(e,this.i),this.i+=e.length}writeInt16(e,t){this.expandBuffer(2),this.view.setInt16(this.i,e,t),this.i+=2}writeUint16(e,t){this.expandBuffer(2),this.view.setUint16(this.i,e,t),this.i+=2}writeInt32(e,t){this.expandBuffer(4),this.view.setInt32(this.i,e,t),this.i+=4}writeUint32(e,t){this.expandBuffer(4),this.view.setUint32(this.i,e,t),this.i+=4}writeBigInt64(e,t){this.expandBuffer(8),this.view.setBigInt64(this.i,e,t),this.i+=8}writeBigUint64(e,t){this.expandBuffer(8),this.view.setBigUint64(this.i,e,t),this.i+=8}writeFloat32(e,t){this.expandBuffer(4),this.view.setFloat32(this.i,e,t),this.i+=4}writeFloat64(e,t){this.expandBuffer(8),this.view.setFloat64(this.i,e,t),this.i+=8}writeVarInt(e,t){let i=r.encode(e);t||(i=i.reverse(),i[0]+=128,i[i.length-1]-=128),i.forEach((e=>this.writeUint8(e)))}writeVarUint(e,t){let i=n.encode(e);t||(i=i.reverse(),i[0]+=128,i[i.length-1]-=128),i.forEach((e=>this.writeUint8(e)))}ensureArrayBuffer(e){if(e){if(e instanceof ArrayBuffer)return e;if(e instanceof Uint8Array)return new Uint8Array(e).buffer}throw new Error("Unsupported buffer type, need ArrayBuffer or Uint8Array or nodejs Buffer")}}},889:(e,t,i)=>{const r=i(349),n=i(114);class s extends Error{constructor(...e){super(...e),this.name="WriteOnlyException"}}e.exports=class{constructor(e){this.i=0,this.length=0}get buffer(){return this.buf}readInt8(){throw new s(null)}readUint8(){throw new s(null)}readBytes(){throw new s(null)}readInt16(){throw new s(null)}readUint16(){throw new s(null)}readInt32(){throw new s(null)}readUint32(){throw new s(null)}readBigInt64(){throw new s(null)}readBigUint64(){throw new s(null)}readFloat32(){throw new s(null)}readFloat64(){throw new s(null)}readVarIntBytes(){throw new s(null)}readVarInt(){throw new s(null)}readVarUint(){throw new s(null)}expandBuffer(e){this.length>=this.i+e||(this.length+=this.i+e-this.length)}writeInt8(){this.expandBuffer(1),this.i++}writeUint8(){this.expandBuffer(1),this.i++}writeBytes(e){let t=[...e];for(let e=0;e<t.length;e++)this.writeUint8()}writeInt16(){this.expandBuffer(2),this.i+=2}writeUint16(){this.expandBuffer(2),this.i+=2}writeInt32(){this.expandBuffer(4),this.i+=4}writeUint32(){this.expandBuffer(4),this.i+=4}writeBigInt64(){this.expandBuffer(8),this.i+=8}writeBigUint64(){this.expandBuffer(8),this.i+=8}writeFloat32(){this.expandBuffer(4),this.i+=4}writeFloat64(){this.expandBuffer(8),this.i+=8}writeVarInt(e){r.encode(e).forEach((()=>this.writeUint8()))}writeVarUint(e){n.encode(e).forEach((()=>this.writeUint8()))}}},343:e=>{"use strict";var t,i="object"==typeof Reflect?Reflect:null,r=i&&"function"==typeof i.apply?i.apply:function(e,t,i){return Function.prototype.apply.call(e,t,i)};t=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var n=Number.isNaN||function(e){return e!=e};function s(){s.init.call(this)}e.exports=s,e.exports.once=function(e,t){return new Promise((function(i,r){function n(i){e.removeListener(t,s),r(i)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",n),i([].slice.call(arguments))}c(e,t,s,{once:!0}),"error"!==t&&function(e,t,i){"function"==typeof e.on&&c(e,"error",t,{once:!0})}(e,n)}))},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var o=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function h(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function u(e,t,i,r){var n,s,o,u;if(a(i),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,i.listener?i.listener:i),s=e._events),o=s[t]),void 0===o)o=s[t]=i,++e._eventsCount;else if("function"==typeof o?o=s[t]=r?[i,o]:[o,i]:r?o.unshift(i):o.push(i),(n=h(e))>0&&o.length>n&&!o.warned){o.warned=!0;var p=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");p.name="MaxListenersExceededWarning",p.emitter=e,p.type=t,p.count=o.length,u=p,console&&console.warn&&console.warn(u)}return e}function p(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(e,t,i){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:i},n=p.bind(r);return n.listener=i,r.wrapFn=n,n}function E(e,t,i){var r=e._events;if(void 0===r)return[];var n=r[t];return void 0===n?[]:"function"==typeof n?i?[n.listener||n]:[n]:i?function(e){for(var t=new Array(e.length),i=0;i<t.length;++i)t[i]=e[i].listener||e[i];return t}(n):f(n,n.length)}function l(e){var t=this._events;if(void 0!==t){var i=t[e];if("function"==typeof i)return 1;if(void 0!==i)return i.length}return 0}function f(e,t){for(var i=new Array(t),r=0;r<t;++r)i[r]=e[r];return i}function c(e,t,i,r){if("function"==typeof e.on)r.once?e.once(t,i):e.on(t,i);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function n(s){r.once&&e.removeEventListener(t,n),i(s)}))}}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(e){if("number"!=typeof e||e<0||n(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");o=e}}),s.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||n(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},s.prototype.getMaxListeners=function(){return h(this)},s.prototype.emit=function(e){for(var t=[],i=1;i<arguments.length;i++)t.push(arguments[i]);var n="error"===e,s=this._events;if(void 0!==s)n=n&&void 0===s.error;else if(!n)return!1;if(n){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var h=s[e];if(void 0===h)return!1;if("function"==typeof h)r(h,this,t);else{var u=h.length,p=f(h,u);for(i=0;i<u;++i)r(p[i],this,t)}return!0},s.prototype.addListener=function(e,t){return u(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return u(this,e,t,!0)},s.prototype.once=function(e,t){return a(t),this.on(e,d(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,d(this,e,t)),this},s.prototype.removeListener=function(e,t){var i,r,n,s,o;if(a(t),void 0===(r=this._events))return this;if(void 0===(i=r[e]))return this;if(i===t||i.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,i.listener||t));else if("function"!=typeof i){for(n=-1,s=i.length-1;s>=0;s--)if(i[s]===t||i[s].listener===t){o=i[s].listener,n=s;break}if(n<0)return this;0===n?i.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(i,n),1===i.length&&(r[e]=i[0]),void 0!==r.removeListener&&this.emit("removeListener",e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,i,r;if(void 0===(i=this._events))return this;if(void 0===i.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==i[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete i[e]),this;if(0===arguments.length){var n,s=Object.keys(i);for(r=0;r<s.length;++r)"removeListener"!==(n=s[r])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=i[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},s.prototype.listeners=function(e){return E(this,e,!0)},s.prototype.rawListeners=function(e){return E(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):l.call(e,t)},s.prototype.listenerCount=l,s.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},349:(e,t,i)=>{var r=i(862);t.encode=function e(t,i,n){t=t>=0?2*t:-2*t-1;var s=r.encode(t,i,n);return e.bytes=r.encode.bytes,s},t.decode=function e(t,i){var n=r.decode(t,i);return e.bytes=r.decode.bytes,1&n?(n+1)/-2:n/2},t.encodingLength=function(e){return r.encodingLength(e>=0?2*e:-2*e-1)}},646:e=>{e.exports=function e(t,i){var r,n=0,s=0,o=i=i||0,a=t.length;do{if(o>=a)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],n+=s<28?(127&r)<<s:(127&r)*Math.pow(2,s),s+=7}while(r>=128);return e.bytes=o-i,n}},964:e=>{e.exports=function e(i,r,n){r=r||[];for(var s=n=n||0;i>=t;)r[n++]=255&i|128,i/=128;for(;-128&i;)r[n++]=255&i|128,i>>>=7;return r[n]=0|i,e.bytes=n-s+1,r};var t=Math.pow(2,31)},862:(e,t,i)=>{e.exports={encode:i(964),decode:i(646),encodingLength:i(697)}},697:e=>{var t=Math.pow(2,7),i=Math.pow(2,14),r=Math.pow(2,21),n=Math.pow(2,28),s=Math.pow(2,35),o=Math.pow(2,42),a=Math.pow(2,49),h=Math.pow(2,56),u=Math.pow(2,63);e.exports=function(e){return e<t?1:e<i?2:e<r?3:e<n?4:e<s?5:e<o?6:e<a?7:e<h?8:e<u?9:10}},434:e=>{e.exports=function e(t,i){var r,n=0,s=0,o=i=i||0,a=t.length;do{if(o>=a||s>49)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],n+=s<28?(127&r)<<s:(127&r)*Math.pow(2,s),s+=7}while(r>=128);return e.bytes=o-i,n}},399:e=>{e.exports=function e(i,r,n){if(Number.MAX_SAFE_INTEGER&&i>Number.MAX_SAFE_INTEGER)throw e.bytes=0,new RangeError("Could not encode varint");r=r||[];for(var s=n=n||0;i>=t;)r[n++]=255&i|128,i/=128;for(;-128&i;)r[n++]=255&i|128,i>>>=7;return r[n]=0|i,e.bytes=n-s+1,r};var t=Math.pow(2,31)},114:(e,t,i)=>{e.exports={encode:i(399),decode:i(434),encodingLength:i(581)}},581:e=>{var t=Math.pow(2,7),i=Math.pow(2,14),r=Math.pow(2,21),n=Math.pow(2,28),s=Math.pow(2,35),o=Math.pow(2,42),a=Math.pow(2,49),h=Math.pow(2,56),u=Math.pow(2,63);e.exports=function(e){return e<t?1:e<i?2:e<r?3:e<n?4:e<s?5:e<o?6:e<a?7:e<h?8:e<u?9:10}},370:e=>{e.exports={events:{types:{META:255,MIDI:8,SYSEX:240,ESCAPE:247},subtypes:{meta:{SEQUENCE_NUMBER:0,TEXT:1,COPYRIGHT_NOTICE:2,TRACK_NAME:3,INSTRUMENT_NAME:4,LYRICS:5,MARKER:6,CUE_POINT:7,CHANNEL_PREFIX:32,PORT_PREFIX:33,END_OF_TRACK:47,SET_TEMPO:81,SMPTE_OFFSET:84,TIME_SIGNATURE:88,KEY_SIGNATURE:89,SEQUENCER_SPECIFIC:127},midi:{NOTE_OFF:8,NOTE_ON:9,NOTE_AFTERTOUCH:10,CONTROL_CHANGE:11,PROGRAM_CHANGE:12,CHANNEL_AFTERTOUCH:13,PITCH_BEND:14,cc:{BANK_SELECT:0,MODULATION:1,BREATH:2,FOOT:4,PORTAMENTO_TIME:5,DATA_ENTRY_MSB:6,CHANNEL_VOLUME:7,BALANCE:8,PAN:10,EXPRESSION:11,EFFECT_1:12,EFFECT_2:13,GENERAL_PURPOSE_1:16,GENERAL_PURPOSE_2:17,GENERAL_PURPOSE_3:18,GENERAL_PURPOSE_4:19,BANK_SELECT_LSB:32,MODULATION_LSB:33,BREATH_LSB:34,CONTROLLER_0X03_LSB:35,FOOT_LSB:36,PORTAMENTO_TIME_LSB:37,DATA_ENTRY_LSB:38,CHANNEL_VOLUME_LSB:39,BALANCE_LSB:40,CONTROLLER_0X09_LSB:41,PAN_LSB:42,EXPRESSION_LSB:43,EFFECT_1_LSB:44,EFFECT_2_LSB:45,CONTROLLER_0X0E_LSB:46,CONTROLLER_0X0F_LSB:47,GENERAL_PURPOSE_1_LSB:48,GENERAL_PURPOSE_2_LSB:49,GENERAL_PURPOSE_3_LSB:50,GENERAL_PURPOSE_4_LSB:51,CONTROLLER_0X14_LSB:52,CONTROLLER_0X15_LSB:53,CONTROLLER_0X16_LSB:54,CONTROLLER_0X17_LSB:55,CONTROLLER_0X18_LSB:56,CONTROLLER_0X19_LSB:57,CONTROLLER_0X1A_LSB:58,CONTROLLER_0X1B_LSB:59,CONTROLLER_0X1C_LSB:60,CONTROLLER_0X1D_LSB:61,CONTROLLER_0X1E_LSB:62,CONTROLLER_0X1F_LSB:63,SUSTAIN_ONOFF:64,PORTAMENTO_ONOFF:65,SOSTENUTO_ONOFF:66,SOFT_PEDAL_ONOFF:67,LEGATO_FOOTSWITCH:68,HOLD_2:69,SOUND_VARIATION:70,TIMBRE_HARMONIC_INTENS:71,RELEASE_TIME:72,ATTACK_TIME:73,BRIGHTNESS:74,DECAY_TIME:75,VIBRATO_RATE:76,VIBRATO_DEPTH:77,VIBRATO_DELAYT:78,SOUND_CONTROLLER_10:79,GENERAL_PURPOSE_5:80,GENERAL_PURPOSE_6:81,GENERAL_PURPOSE_7:82,GENERAL_PURPOSE_8:83,PORTAMENTO_CONTROL:84,HIGH_RESOLUTION_VELOCITY_PREFIX:88,REVERB_SEND_LEVEL:91,TREMOLO_DEPTH:92,CHORUS_DEPTH:93,CELESTE_DEPTH:94,PHASER_DEPTH:95,DATA_INCREMENT:96,DATA_DECREMENT:97,NRPN_LSB:98,NRPN_MSB:99,RPN_LSB:100,RPN_MSB:101,ALL_SOUND_OFF:120,RESET_ALL_CONTROLLERS:121,LOCAL_CONTROL_ONOFF:122,ALL_NOTES_OFF:123,OMNI_OFF:124,OMNI_ON:125,MONO_ON:126,POLY_ON:127,rpn:{PITCH_BEND_SENSITIVITY:[0,0],CHANNEL_FINE_TUNING:[0,1],CHANNEL_COARSE_TUNING:[0,2],TUNING_PROGRAM_CHANGE:[0,3],TUNING_BANK_SELECT:[0,4],MODULATION_DEPTH_RANGE:[0,5],MPE_CONFIGURATION:[0,6],AZIMUTH_ANGLE:[61,0],ELEVATION_ANGLE:[61,1],GAIN:[61,2],DISTANCE_RATIO:[61,3],MAXIMUM_DISTANCE:[61,4],GAIN_AT_MAXIMUM_DISTANCE:[61,5],REFERENCE_DISTANCE_RATIO:[61,6],PAN_SPREAD_ANGLE:[61,7],ROLL_ANGLE:[61,8],NULL:[127,127]}}}}}}},23:(e,t,i)=>{const r=i(524),n=i(370),{ByteStream:s}=i(127);e.exports=class{constructor(e,t=!0){let i=[],o=new s(e);for(;o.i<o.buffer.byteLength;){let e=o.readBytes(4).reduce(((e,t)=>e+String.fromCharCode(t)),"");if(o.i<=4&&"MThd"!=e)throw new Error("Invalid header signature(MThd)");let t=o.readUint32(),r={id:e,data:o.readBytes(t)};i.push(r)}let a=[];this.unknownChunks=[];let h=i.filter((e=>"MThd"==e.id?(a.push(e),!1):"MTrk"==e.id||(unknownChunks.push(e),!1)));if(a.length>1)throw new Error("Too many header chunks");if(a.length<1)throw new Error("No header chunk");let u=new s(a[0].data);if(6!=u.buffer.byteLength)throw new Error("Invalid header length");this.header={format:u.readUint16(),tracksCount:u.readUint16(),ticksPerBeat:null,framesPerSecond:null,ticksPerFrame:null,tickResolution:null};let p=u.readBytes(2);128&p[0]?(this.header.framesPerSecond=127&p[0],this.header.ticksPerFrame=p[1],this.header.tickResolution=1e6/(this.header.framesPerSecond*this.header.ticksPerFrame)):this.header.ticksPerBeat=(p[0]<<8)+p[1];let d=[];h.forEach((e=>{let t,i,r=new s(e.data),o=[];for(;r.i<r.buffer.byteLength;){let e,s,a,h,u,p=r.readVarUint(),d=r.readUint8();240==(240&d)?d==n.events.types.META?(s=r.readUint8(),e=r.readVarUint(),h=r.readBytes(e)):d!=n.events.types.SYSEX&&d!=n.events.types.ESCAPE||(e=r.readVarUint(),h=r.readBytes(e)):(u=[],0==(128&d)?(s=t,a=i,u.push(d)):(s=t=d>>4,a=i=15&d,u.push(r.readUint8())),d=n.events.types.MIDI,s==n.events.subtypes.midi.PROGRAM_CHANGE||s==n.events.subtypes.midi.CHANNEL_AFTERTOUCH||u.push(r.readUint8()),s==n.events.subtypes.midi.NOTE_ON&&0==u[1]&&(s=n.events.subtypes.midi.NOTE_OFF,u[1]=127));let E={delta:p,type:d};void 0!==s&&(E.subtype=s),void 0!==e&&(E.length=e),void 0!==a&&(E.channel=a),void 0!==h&&(E.data=[...h]),void 0!==u&&(E.params=u),o.push(E)}d.push(o)})),this.ports=[];let E=[];this.tempoEvents=new r;for(let e in d){let i=0,s=0,o=0,a=new r(e),h=new TextDecoder;d[e].forEach((e=>{i+=e.delta,e.type==n.events.types.META&&(e.subtype==n.events.subtypes.meta.SEQUENCE_NUMBER||(e.subtype==n.events.subtypes.meta.TEXT||e.subtype==n.events.subtypes.meta.COPYRIGHT_NOTICE||e.subtype==n.events.subtypes.meta.TRACK_NAME||e.subtype==n.events.subtypes.meta.INSTRUMENT_NAME||e.subtype==n.events.subtypes.meta.LYRICS||e.subtype==n.events.subtypes.meta.MARKER||e.subtype==n.events.subtypes.meta.CUE_POINT?e.content=h.decode(new Uint8Array(e.data)):e.subtype==n.events.subtypes.meta.CHANNEL_PREFIX?e.prefix=e.data[0]:e.subtype==n.events.subtypes.meta.PORT_PREFIX?o=e.port=e.data[0]:e.subtype==n.events.subtypes.meta.END_OF_TRACK||(e.subtype==n.events.subtypes.meta.SET_TEMPO?(e.tempo=0,e.tempo+=e.data[0]<<16,e.tempo+=e.data[1]<<8,e.tempo+=e.data[2],e.tempoBPM=6e7/e.tempo):e.subtype==n.events.subtypes.meta.SMPTE_OFFSET?(e.hour=e.data[0],e.minutes=e.data[1],e.seconds=e.data[2],e.frames=e.data[3],e.subframes=e.data[4]):e.subtype==n.events.subtypes.meta.TIME_SIGNATURE||(e.subtype==n.events.subtypes.meta.KEY_SIGNATURE?(e.key=e.data[0]>127?e.data[0]-256:e.data[0],e.scale=e.data[1]):(e.subtype,n.events.subtypes.meta.SEQUENCER_SPECIFIC))))),a.addEvent(i,e),e.type!=n.events.types.META&&(s=i),e.type==n.events.types.META&&e.subtype==n.events.subtypes.meta.SET_TEMPO&&(this.tempoEvents.addEvent(i,e),s=i)})),this.ports[o]||(this.ports[o]=[]),this.ports[o].push(a),E.push(t?s:i)}if(this.header.durationTick=Math.max(...E),this.header.ticksPerBeat){this.header.durationMs=0;let e=this.tempoEvents.getEvents(),t=5e5,i=0;for(let r of Object.keys(e)){this.header.durationMs+=t*((r-i)/this.header.ticksPerBeat),t=e[r][e[r].length-1].tempo;for(let t in e[r])e[r][t].playms=this.header.durationMs/1e3;i=r}this.header.durationMs+=t*((this.header.durationTick-i)/this.header.ticksPerBeat),this.header.durationMs/=1e3}else this.header.durationMs=this.header.durationTick*this.header.tickResolution/1e3;if(this.header.durationMs=Math.round(this.header.durationMs),t)if(this.header.durationMs+=3e3,this.header.ticksPerBeat){let e=this.tempoEvents.getEvents();e=e[Math.max(...Object.keys(e))];let t=e[e.length-1]?e[e.length-1].tempo:5e5;this.header.durationTick+=Math.round(3e6/t*this.header.ticksPerBeat)}else this.header.durationTick+=Math.round(3e6/this.header.tickResolution)}}},720:(e,t,i)=>{const r=i(343),n=i(370),s=i(23);e.exports=class extends r{constructor(e=1){if(super(),e<1)throw new RangeError("portCount(1st argument) must be >= 1. Received "+e);this.portCount=e}loadMidi(e){this.playing&&this.pause(),this.d=e instanceof s?e:new s(e),this.prepare()}getPoly(e){return this.calcPolyOfAllTracks()}calcPoly(e=0,t=!1){let i=0,r=0,s=t?this.d.ports:[this.d.ports[e]];for(let e=0;e<=this.durationTick;e++){if(i<0)throw new RangeError("currentPoly must not be 0");s.forEach((t=>t.forEach((t=>{let s=t.getEvents();s[e]&&s[e].forEach((e=>{e.type==n.events.types.MIDI&&(e.subtype==n.events.subtypes.midi.NOTE_ON?(i++,i>r&&(r=i)):e.subtype==n.events.subtypes.midi.NOTE_OFF&&i--)}))}))))}return console.log(i,r),r}prepare(){this.playms=0,this.lastplayms=0,this.playtick=0,this.tempo=1,this.resetNotes(!0);for(let e=0;e<this.portCount;e++)this.triggerMidiEvent({type:n.events.types.SYSEX,data:[65,16,66,18,64,0,127,0,65,247]},e)}triggerMidiEvent(e,t=0){e.type==n.events.types.SYSEX?this.emit("midievent",e,t,[e.type,...e.data]):e.type==n.events.types.ESCAPE?this.emit("midievent",e,t,e.data):e.type==n.events.types.MIDI?this.emit("midievent",e,t,[(e.subtype<<4)+e.channel,...e.params]):e.type==n.events.types.META&&this.emit("midievent",e,t,null)}resetNotes(e=!1){for(let i=0;i<this.portCount;i++)for(var t=0;t<16;t++)this.triggerMidiEvent({type:n.events.types.MIDI,subtype:n.events.subtypes.midi.CONTROL_CHANGE,channel:t,params:[n.events.subtypes.midi.cc.ALL_SOUND_OFF,0]},i),this.triggerMidiEvent({type:n.events.types.MIDI,subtype:n.events.subtypes.midi.PITCH_BEND,channel:t,params:[0,64]},i),this.triggerMidiEvent({type:n.events.types.MIDI,subtype:n.events.subtypes.midi.CONTROL_CHANGE,channel:t,params:[n.events.subtypes.midi.cc.SUSTAIN_ONOFF,0]},i),e&&(this.triggerMidiEvent({type:n.events.types.MIDI,subtype:n.events.subtypes.midi.CONTROL_CHANGE,channel:t,params:[n.events.subtypes.midi.cc.RESET_ALL_CONTROLLERS,0]},i),this.triggerMidiEvent({type:n.events.types.MIDI,subtype:n.events.subtypes.midi.PROGRAM_CHANGE,channel:t,params:[0,0]},i))}calcCurrentTickFromCurrentMs(e){if(!this.d.header.ticksPerBeat)return Math.round(e/(this.d.header.tickResolution/1e3));let t=this.d.tempoEvents.getEvents();for(let i of Object.keys(t).reverse())for(let r in t[i])if(t[i][r].playms<=e)return i=parseInt(i,10),r=parseInt(r,10),Math.round((e-t[i][r].playms)/(t[i][r].tempo/1e3)*this.d.header.ticksPerBeat+i)}get currentTick(){return this.calcCurrentTickFromCurrentMs(this.playms)}set currentTick(e){if(e<0)return;if(this.resetNotes(),this.playtick=e,!this.d.header.ticksPerBeat)return void(this.playms=Math.round(e*(this.d.header.tickResolution/1e3)));let t=this.d.tempoEvents.getEvents();for(let i of Object.keys(t).reverse())for(let r in t[i])i<this.currentTick&&(i=parseInt(i,10),r=parseInt(r,10),this.playms=Math.round((e-i)/this.d.header.ticksPerBeat*(t[i][r].tempo/1e3)+t[i][r].playms))}get currentMs(){return this.playms}set currentMs(e){e<0||(this.resetNotes(),this.playms=Math.round(e),this.playtick=this.currentTick)}get durationTick(){return this.d.header.durationTick}get durationMs(){return this.d.header.durationMs}get ended(){return this.currentTick>=this.durationTick&&this.currentMs>=this.durationMs}play(){this.playing||(this.lastplayms=Date.now(),this.playing=!0,this.interval=setInterval(this.playLoop.bind(this),1))}pause(){this.playing&&(this.resetNotes(),this.playing=!1,clearInterval(this.interval))}playLoop(){if(this.inLoop)return;this.inLoop=!0;let e=Date.now(),t=(e-this.lastplayms)*this.tempo;this.lastplayms=e,this.playms+=t;let i=this.currentTick-this.playtick;for(let e=0;e<i;e++)this.d.ports.forEach(((e,t)=>{e.forEach((e=>{let i=e.getEvents();i[this.playtick]&&i[this.playtick].forEach((e=>this.triggerMidiEvent(e,t)))}))})),this.playtick++;this.ended&&this.pause(),this.inLoop=!1}}},524:e=>{e.exports=class{constructor(e,t){this.trackNo=e,this.meta=t,this.events={}}addEvent(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}getEvents(){return this.events}}}},t={};!function i(r){var n=t[r];if(void 0!==n)return n.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,i),s.exports}(270)})();
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.yjmidi=t():e.yjmidi=t()}(self,(()=>{return e={270:(e,t,i)=>{e.exports={Consts:i(370),MidiFile:i(23),MidiTrack:i(524),MidiPlayer:i(720)}},127:(e,t,i)=>{e.exports={ByteStream:i(615),ByteStreamSimulator:i(889)}},615:(e,t,i)=>{const r=i(349),n=i(114);e.exports=class{constructor(e){this.buf=e?this.ensureArrayBuffer(e):new ArrayBuffer,this.i=0,this.view=new DataView(this.buf),this.u8=new Uint8Array(this.buf)}get buffer(){return this.buf}get length(){return this.buf.byteLength}get isDataAvailable(){return this.i<this.buf.byteLength}readInt8(){return this.view.getInt8(this.i++)}readUint8(){return this.view.getUint8(this.i++)}readBytes(e){if(this.i+e>this.buf.byteLength)throw new RangeError("Offset is outside the bounds of the ArrayBuffer");return this.u8.subarray(this.i,this.i+=e)}readInt16(e){let t=this.view.getInt16(this.i,e);return this.i+=2,t}readUint16(e){let t=this.view.getUint16(this.i,e);return this.i+=2,t}readInt32(e){let t=this.view.getInt32(this.i,e);return this.i+=4,t}readUint32(e){let t=this.view.getUint32(this.i,e);return this.i+=4,t}readBigInt64(e){let t=this.view.getBigInt64(this.i,e);return this.i+=8,t}readBigUint64(e){let t=this.view.getBigUint64(this.i,e);return this.i+=8,t}readFloat32(e){let t=this.view.getFloat32(this.i,e);return this.i+=4,t}readFloat64(e){let t=this.view.getFloat64(this.i,e);return this.i+=8,t}readVarIntBytes(e=1/0){let t=[],i=0;for(;e>i++;)if(t.push(this.readUint8()),!(128&t[t.length-1]))return t;throw new RangeError(`0x${this.i.toString(16)}: Variable integer length cannot exceed ${e} bytes`)}readVarInt(e,t=1/0){let i=this.readVarIntBytes(t);return e||(i=i.reverse(),i[0]+=128,i[i.length-1]-=128),r.decode(i)}readVarUint(e,t=1/0){let i=this.readVarIntBytes(t);return e||(i=i.reverse(),i[0]+=128,i[i.length-1]-=128),n.decode(i)}expandBuffer(e){if(this.buf.byteLength>=this.i+e)return;if((e=this.i+e-this.buf.byteLength)<=0)return;let t=new Uint8Array(this.buf.byteLength+e);t.set(new Uint8Array(this.buf)),this.buf=t.buffer,this.view=new DataView(this.buf),this.u8=t}writeInt8(e){this.expandBuffer(1),this.view.setInt8(this.i++,e)}writeUint8(e){this.expandBuffer(1),this.view.setUint8(this.i++,e)}writeBytes(e){this.expandBuffer(e.length),this.u8.set(e,this.i),this.i+=e.length}writeInt16(e,t){this.expandBuffer(2),this.view.setInt16(this.i,e,t),this.i+=2}writeUint16(e,t){this.expandBuffer(2),this.view.setUint16(this.i,e,t),this.i+=2}writeInt32(e,t){this.expandBuffer(4),this.view.setInt32(this.i,e,t),this.i+=4}writeUint32(e,t){this.expandBuffer(4),this.view.setUint32(this.i,e,t),this.i+=4}writeBigInt64(e,t){this.expandBuffer(8),this.view.setBigInt64(this.i,e,t),this.i+=8}writeBigUint64(e,t){this.expandBuffer(8),this.view.setBigUint64(this.i,e,t),this.i+=8}writeFloat32(e,t){this.expandBuffer(4),this.view.setFloat32(this.i,e,t),this.i+=4}writeFloat64(e,t){this.expandBuffer(8),this.view.setFloat64(this.i,e,t),this.i+=8}writeVarInt(e,t){let i=r.encode(e);t||(i=i.reverse(),i[0]+=128,i[i.length-1]-=128),i.forEach((e=>this.writeUint8(e)))}writeVarUint(e,t){let i=n.encode(e);t||(i=i.reverse(),i[0]+=128,i[i.length-1]-=128),i.forEach((e=>this.writeUint8(e)))}ensureArrayBuffer(e){if(e){if(e instanceof ArrayBuffer)return e;if(e instanceof Uint8Array)return new Uint8Array(e).buffer}throw new Error("Unsupported buffer type, need ArrayBuffer or Uint8Array or nodejs Buffer")}}},889:(e,t,i)=>{const r=i(349),n=i(114);class s extends Error{constructor(...e){super(...e),this.name="WriteOnlyException"}}e.exports=class{constructor(e){this.i=0,this.length=0}get buffer(){return this.buf}readInt8(){throw new s(null)}readUint8(){throw new s(null)}readBytes(){throw new s(null)}readInt16(){throw new s(null)}readUint16(){throw new s(null)}readInt32(){throw new s(null)}readUint32(){throw new s(null)}readBigInt64(){throw new s(null)}readBigUint64(){throw new s(null)}readFloat32(){throw new s(null)}readFloat64(){throw new s(null)}readVarIntBytes(){throw new s(null)}readVarInt(){throw new s(null)}readVarUint(){throw new s(null)}expandBuffer(e){this.length>=this.i+e||(this.length+=this.i+e-this.length)}writeInt8(){this.expandBuffer(1),this.i++}writeUint8(){this.expandBuffer(1),this.i++}writeBytes(e){let t=[...e];for(let e=0;e<t.length;e++)this.writeUint8()}writeInt16(){this.expandBuffer(2),this.i+=2}writeUint16(){this.expandBuffer(2),this.i+=2}writeInt32(){this.expandBuffer(4),this.i+=4}writeUint32(){this.expandBuffer(4),this.i+=4}writeBigInt64(){this.expandBuffer(8),this.i+=8}writeBigUint64(){this.expandBuffer(8),this.i+=8}writeFloat32(){this.expandBuffer(4),this.i+=4}writeFloat64(){this.expandBuffer(8),this.i+=8}writeVarInt(e){r.encode(e).forEach((()=>this.writeUint8()))}writeVarUint(e){n.encode(e).forEach((()=>this.writeUint8()))}}},343:e=>{"use strict";var t,i="object"==typeof Reflect?Reflect:null,r=i&&"function"==typeof i.apply?i.apply:function(e,t,i){return Function.prototype.apply.call(e,t,i)};t=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var n=Number.isNaN||function(e){return e!=e};function s(){s.init.call(this)}e.exports=s,e.exports.once=function(e,t){return new Promise((function(i,r){function n(i){e.removeListener(t,s),r(i)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",n),i([].slice.call(arguments))}c(e,t,s,{once:!0}),"error"!==t&&function(e,t,i){"function"==typeof e.on&&c(e,"error",t,{once:!0})}(e,n)}))},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var o=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function h(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function u(e,t,i,r){var n,s,o,u;if(a(i),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,i.listener?i.listener:i),s=e._events),o=s[t]),void 0===o)o=s[t]=i,++e._eventsCount;else if("function"==typeof o?o=s[t]=r?[i,o]:[o,i]:r?o.unshift(i):o.push(i),(n=h(e))>0&&o.length>n&&!o.warned){o.warned=!0;var p=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");p.name="MaxListenersExceededWarning",p.emitter=e,p.type=t,p.count=o.length,u=p,console&&console.warn&&console.warn(u)}return e}function p(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(e,t,i){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:i},n=p.bind(r);return n.listener=i,r.wrapFn=n,n}function E(e,t,i){var r=e._events;if(void 0===r)return[];var n=r[t];return void 0===n?[]:"function"==typeof n?i?[n.listener||n]:[n]:i?function(e){for(var t=new Array(e.length),i=0;i<t.length;++i)t[i]=e[i].listener||e[i];return t}(n):l(n,n.length)}function f(e){var t=this._events;if(void 0!==t){var i=t[e];if("function"==typeof i)return 1;if(void 0!==i)return i.length}return 0}function l(e,t){for(var i=new Array(t),r=0;r<t;++r)i[r]=e[r];return i}function c(e,t,i,r){if("function"==typeof e.on)r.once?e.once(t,i):e.on(t,i);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function n(s){r.once&&e.removeEventListener(t,n),i(s)}))}}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(e){if("number"!=typeof e||e<0||n(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");o=e}}),s.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||n(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},s.prototype.getMaxListeners=function(){return h(this)},s.prototype.emit=function(e){for(var t=[],i=1;i<arguments.length;i++)t.push(arguments[i]);var n="error"===e,s=this._events;if(void 0!==s)n=n&&void 0===s.error;else if(!n)return!1;if(n){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var h=s[e];if(void 0===h)return!1;if("function"==typeof h)r(h,this,t);else{var u=h.length,p=l(h,u);for(i=0;i<u;++i)r(p[i],this,t)}return!0},s.prototype.addListener=function(e,t){return u(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return u(this,e,t,!0)},s.prototype.once=function(e,t){return a(t),this.on(e,d(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,d(this,e,t)),this},s.prototype.removeListener=function(e,t){var i,r,n,s,o;if(a(t),void 0===(r=this._events))return this;if(void 0===(i=r[e]))return this;if(i===t||i.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,i.listener||t));else if("function"!=typeof i){for(n=-1,s=i.length-1;s>=0;s--)if(i[s]===t||i[s].listener===t){o=i[s].listener,n=s;break}if(n<0)return this;0===n?i.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(i,n),1===i.length&&(r[e]=i[0]),void 0!==r.removeListener&&this.emit("removeListener",e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,i,r;if(void 0===(i=this._events))return this;if(void 0===i.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==i[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete i[e]),this;if(0===arguments.length){var n,s=Object.keys(i);for(r=0;r<s.length;++r)"removeListener"!==(n=s[r])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=i[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},s.prototype.listeners=function(e){return E(this,e,!0)},s.prototype.rawListeners=function(e){return E(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):f.call(e,t)},s.prototype.listenerCount=f,s.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},349:(e,t,i)=>{var r=i(862);t.encode=function e(t,i,n){t=t>=0?2*t:-2*t-1;var s=r.encode(t,i,n);return e.bytes=r.encode.bytes,s},t.decode=function e(t,i){var n=r.decode(t,i);return e.bytes=r.decode.bytes,1&n?(n+1)/-2:n/2},t.encodingLength=function(e){return r.encodingLength(e>=0?2*e:-2*e-1)}},646:e=>{e.exports=function e(t,i){var r,n=0,s=0,o=i=i||0,a=t.length;do{if(o>=a)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],n+=s<28?(127&r)<<s:(127&r)*Math.pow(2,s),s+=7}while(r>=128);return e.bytes=o-i,n}},964:e=>{e.exports=function e(i,r,n){r=r||[];for(var s=n=n||0;i>=t;)r[n++]=255&i|128,i/=128;for(;-128&i;)r[n++]=255&i|128,i>>>=7;return r[n]=0|i,e.bytes=n-s+1,r};var t=Math.pow(2,31)},862:(e,t,i)=>{e.exports={encode:i(964),decode:i(646),encodingLength:i(697)}},697:e=>{var t=Math.pow(2,7),i=Math.pow(2,14),r=Math.pow(2,21),n=Math.pow(2,28),s=Math.pow(2,35),o=Math.pow(2,42),a=Math.pow(2,49),h=Math.pow(2,56),u=Math.pow(2,63);e.exports=function(e){return e<t?1:e<i?2:e<r?3:e<n?4:e<s?5:e<o?6:e<a?7:e<h?8:e<u?9:10}},434:e=>{e.exports=function e(t,i){var r,n=0,s=0,o=i=i||0,a=t.length;do{if(o>=a||s>49)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],n+=s<28?(127&r)<<s:(127&r)*Math.pow(2,s),s+=7}while(r>=128);return e.bytes=o-i,n}},399:e=>{e.exports=function e(i,r,n){if(Number.MAX_SAFE_INTEGER&&i>Number.MAX_SAFE_INTEGER)throw e.bytes=0,new RangeError("Could not encode varint");r=r||[];for(var s=n=n||0;i>=t;)r[n++]=255&i|128,i/=128;for(;-128&i;)r[n++]=255&i|128,i>>>=7;return r[n]=0|i,e.bytes=n-s+1,r};var t=Math.pow(2,31)},114:(e,t,i)=>{e.exports={encode:i(399),decode:i(434),encodingLength:i(581)}},581:e=>{var t=Math.pow(2,7),i=Math.pow(2,14),r=Math.pow(2,21),n=Math.pow(2,28),s=Math.pow(2,35),o=Math.pow(2,42),a=Math.pow(2,49),h=Math.pow(2,56),u=Math.pow(2,63);e.exports=function(e){return e<t?1:e<i?2:e<r?3:e<n?4:e<s?5:e<o?6:e<a?7:e<h?8:e<u?9:10}},370:e=>{e.exports={events:{types:{META:255,MIDI:8,SYSEX:240,ESCAPE:247},subtypes:{meta:{SEQUENCE_NUMBER:0,TEXT:1,COPYRIGHT_NOTICE:2,TRACK_NAME:3,INSTRUMENT_NAME:4,LYRICS:5,MARKER:6,CUE_POINT:7,CHANNEL_PREFIX:32,PORT_PREFIX:33,END_OF_TRACK:47,SET_TEMPO:81,SMPTE_OFFSET:84,TIME_SIGNATURE:88,KEY_SIGNATURE:89,SEQUENCER_SPECIFIC:127},midi:{NOTE_OFF:8,NOTE_ON:9,NOTE_AFTERTOUCH:10,CONTROL_CHANGE:11,PROGRAM_CHANGE:12,CHANNEL_AFTERTOUCH:13,PITCH_BEND:14,cc:{BANK_SELECT:0,MODULATION:1,BREATH:2,FOOT:4,PORTAMENTO_TIME:5,DATA_ENTRY_MSB:6,CHANNEL_VOLUME:7,BALANCE:8,PAN:10,EXPRESSION:11,EFFECT_1:12,EFFECT_2:13,GENERAL_PURPOSE_1:16,GENERAL_PURPOSE_2:17,GENERAL_PURPOSE_3:18,GENERAL_PURPOSE_4:19,BANK_SELECT_LSB:32,MODULATION_LSB:33,BREATH_LSB:34,CONTROLLER_0X03_LSB:35,FOOT_LSB:36,PORTAMENTO_TIME_LSB:37,DATA_ENTRY_LSB:38,CHANNEL_VOLUME_LSB:39,BALANCE_LSB:40,CONTROLLER_0X09_LSB:41,PAN_LSB:42,EXPRESSION_LSB:43,EFFECT_1_LSB:44,EFFECT_2_LSB:45,CONTROLLER_0X0E_LSB:46,CONTROLLER_0X0F_LSB:47,GENERAL_PURPOSE_1_LSB:48,GENERAL_PURPOSE_2_LSB:49,GENERAL_PURPOSE_3_LSB:50,GENERAL_PURPOSE_4_LSB:51,CONTROLLER_0X14_LSB:52,CONTROLLER_0X15_LSB:53,CONTROLLER_0X16_LSB:54,CONTROLLER_0X17_LSB:55,CONTROLLER_0X18_LSB:56,CONTROLLER_0X19_LSB:57,CONTROLLER_0X1A_LSB:58,CONTROLLER_0X1B_LSB:59,CONTROLLER_0X1C_LSB:60,CONTROLLER_0X1D_LSB:61,CONTROLLER_0X1E_LSB:62,CONTROLLER_0X1F_LSB:63,SUSTAIN_ONOFF:64,PORTAMENTO_ONOFF:65,SOSTENUTO_ONOFF:66,SOFT_PEDAL_ONOFF:67,LEGATO_FOOTSWITCH:68,HOLD_2:69,SOUND_VARIATION:70,TIMBRE_HARMONIC_INTENS:71,RELEASE_TIME:72,ATTACK_TIME:73,BRIGHTNESS:74,DECAY_TIME:75,VIBRATO_RATE:76,VIBRATO_DEPTH:77,VIBRATO_DELAYT:78,SOUND_CONTROLLER_10:79,GENERAL_PURPOSE_5:80,GENERAL_PURPOSE_6:81,GENERAL_PURPOSE_7:82,GENERAL_PURPOSE_8:83,PORTAMENTO_CONTROL:84,HIGH_RESOLUTION_VELOCITY_PREFIX:88,REVERB_SEND_LEVEL:91,TREMOLO_DEPTH:92,CHORUS_DEPTH:93,CELESTE_DEPTH:94,PHASER_DEPTH:95,DATA_INCREMENT:96,DATA_DECREMENT:97,NRPN_LSB:98,NRPN_MSB:99,RPN_LSB:100,RPN_MSB:101,ALL_SOUND_OFF:120,RESET_ALL_CONTROLLERS:121,LOCAL_CONTROL_ONOFF:122,ALL_NOTES_OFF:123,OMNI_OFF:124,OMNI_ON:125,MONO_ON:126,POLY_ON:127,rpn:{PITCH_BEND_SENSITIVITY:[0,0],CHANNEL_FINE_TUNING:[0,1],CHANNEL_COARSE_TUNING:[0,2],TUNING_PROGRAM_CHANGE:[0,3],TUNING_BANK_SELECT:[0,4],MODULATION_DEPTH_RANGE:[0,5],MPE_CONFIGURATION:[0,6],AZIMUTH_ANGLE:[61,0],ELEVATION_ANGLE:[61,1],GAIN:[61,2],DISTANCE_RATIO:[61,3],MAXIMUM_DISTANCE:[61,4],GAIN_AT_MAXIMUM_DISTANCE:[61,5],REFERENCE_DISTANCE_RATIO:[61,6],PAN_SPREAD_ANGLE:[61,7],ROLL_ANGLE:[61,8],NULL:[127,127]}}}}}}},23:(e,t,i)=>{const r=i(524),n=i(370),{ByteStream:s}=i(127);e.exports=class{constructor(e,t=500){let i=[],o=new s(e);for(;o.i<o.buffer.byteLength;){let e=o.readBytes(4).reduce(((e,t)=>e+String.fromCharCode(t)),"");if(o.i<=4&&"MThd"!=e)throw new Error("Invalid header signature(MThd)");let t=o.readUint32(),r={id:e,data:o.readBytes(t)};i.push(r)}let a=[];this.unknownChunks=[];let h=i.filter((e=>"MThd"==e.id?(a.push(e),!1):"MTrk"==e.id||(unknownChunks.push(e),!1)));if(a.length>1)throw new Error("Too many header chunks");if(a.length<1)throw new Error("No header chunk");let u=new s(a[0].data);if(6!=u.buffer.byteLength)throw new Error("Invalid header length");this.header={format:u.readUint16(),tracksCount:u.readUint16(),ticksPerBeat:null,framesPerSecond:null,ticksPerFrame:null,tickResolution:null};let p=u.readBytes(2);128&p[0]?(this.header.framesPerSecond=127&p[0],this.header.ticksPerFrame=p[1],this.header.tickResolution=1e6/(this.header.framesPerSecond*this.header.ticksPerFrame)):this.header.ticksPerBeat=(p[0]<<8)+p[1];let d=[];h.forEach((e=>{let t,i,r=new s(e.data),o=[];for(;r.i<r.buffer.byteLength;){let e,s,a,h,u,p=r.readVarUint(),d=r.readUint8();240==(240&d)?d==n.events.types.META?(s=r.readUint8(),e=r.readVarUint(),h=r.readBytes(e)):d!=n.events.types.SYSEX&&d!=n.events.types.ESCAPE||(e=r.readVarUint(),h=r.readBytes(e)):(u=[],0==(128&d)?(s=t,a=i,u.push(d)):(s=t=d>>4,a=i=15&d,u.push(r.readUint8())),d=n.events.types.MIDI,s==n.events.subtypes.midi.PROGRAM_CHANGE||s==n.events.subtypes.midi.CHANNEL_AFTERTOUCH||u.push(r.readUint8()),s==n.events.subtypes.midi.NOTE_ON&&0==u[1]&&(s=n.events.subtypes.midi.NOTE_OFF,u[1]=127));let E={delta:p,type:d};void 0!==s&&(E.subtype=s),void 0!==e&&(E.length=e),void 0!==a&&(E.channel=a),void 0!==h&&(E.data=[...h]),void 0!==u&&(E.params=u),o.push(E)}d.push(o)})),this.ports=[];let E=[];this.tempoEvents=new r;for(let e in d){let t=0,i=0,s=new r(e),o=new TextDecoder;d[e].forEach((e=>{t+=e.delta,e.type==n.events.types.META&&(e.subtype==n.events.subtypes.meta.SEQUENCE_NUMBER||(e.subtype==n.events.subtypes.meta.TEXT||e.subtype==n.events.subtypes.meta.COPYRIGHT_NOTICE||e.subtype==n.events.subtypes.meta.TRACK_NAME||e.subtype==n.events.subtypes.meta.INSTRUMENT_NAME||e.subtype==n.events.subtypes.meta.LYRICS||e.subtype==n.events.subtypes.meta.MARKER||e.subtype==n.events.subtypes.meta.CUE_POINT?e.content=o.decode(new Uint8Array(e.data)):e.subtype==n.events.subtypes.meta.CHANNEL_PREFIX?e.prefix=e.data[0]:e.subtype==n.events.subtypes.meta.PORT_PREFIX?i=e.port=e.data[0]:e.subtype==n.events.subtypes.meta.END_OF_TRACK||(e.subtype==n.events.subtypes.meta.SET_TEMPO?(e.tempo=0,e.tempo+=e.data[0]<<16,e.tempo+=e.data[1]<<8,e.tempo+=e.data[2],e.tempoBPM=6e7/e.tempo):e.subtype==n.events.subtypes.meta.SMPTE_OFFSET?(e.hour=e.data[0],e.minutes=e.data[1],e.seconds=e.data[2],e.frames=e.data[3],e.subframes=e.data[4]):e.subtype==n.events.subtypes.meta.TIME_SIGNATURE||(e.subtype==n.events.subtypes.meta.KEY_SIGNATURE?(e.key=e.data[0]>127?e.data[0]-256:e.data[0],e.scale=e.data[1]):(e.subtype,n.events.subtypes.meta.SEQUENCER_SPECIFIC))))),s.addEvent(t,e),e.type==n.events.types.META&&e.subtype==n.events.subtypes.meta.SET_TEMPO&&this.tempoEvents.addEvent(t,e)})),this.ports[i]||(this.ports[i]=[]),this.ports[i].push(s),E.push(t)}if(this.header.durationTick=Math.max(...E),this.header.ticksPerBeat){this.header.durationMs=0;let e=this.tempoEvents.getEvents(),t=5e5,i=0;for(let r of Object.keys(e)){this.header.durationMs+=t*((r-i)/this.header.ticksPerBeat),t=e[r][e[r].length-1].tempo;for(let t in e[r])e[r][t].playms=this.header.durationMs/1e3;i=r}this.header.durationMs+=t*((this.header.durationTick-i)/this.header.ticksPerBeat),this.header.durationMs/=1e3}else this.header.durationMs=this.header.durationTick*this.header.tickResolution/1e3;if(this.header.durationMs=Math.round(this.header.durationMs),t>0)if(this.header.durationMs+=t,this.header.ticksPerBeat){let e=this.tempoEvents.getEvents();e=e[Math.max(...Object.keys(e))];let i=e[e.length-1]?e[e.length-1].tempo:5e5;this.header.durationTick+=Math.round(1e3*t/i*this.header.ticksPerBeat)}else this.header.durationTick+=Math.round(1e3*t/this.header.tickResolution)}}},720:(e,t,i)=>{const r=i(343),n=i(370),s=i(23);e.exports=class extends r{constructor(e=1){if(super(),e<1)throw new RangeError("portCount(1st argument) must be >= 1. Received "+e);this.portCount=e}loadMidi(e){this.playing&&this.pause(),this.d=e instanceof s?e:new s(e),this.prepare()}getPoly(e){return this.calcPolyOfAllTracks()}calcPoly(e=0,t=!1){let i=0,r=0,s=t?this.d.ports:[this.d.ports[e]];for(let e=0;e<=this.durationTick;e++){if(i<0)throw new RangeError("currentPoly must not be 0");s.forEach((t=>t.forEach((t=>{let s=t.getEvents();s[e]&&s[e].forEach((e=>{e.type==n.events.types.MIDI&&(e.subtype==n.events.subtypes.midi.NOTE_ON?(i++,i>r&&(r=i)):e.subtype==n.events.subtypes.midi.NOTE_OFF&&i--)}))}))))}return console.log(i,r),r}prepare(){this.playms=0,this.lastplayms=0,this.playtick=0,this.tempo=1,this.resetNotes(!0);for(let e=0;e<this.portCount;e++)this.triggerMidiEvent({type:n.events.types.SYSEX,data:[65,16,66,18,64,0,127,0,65,247]},e)}triggerMidiEvent(e,t=0){e.type==n.events.types.SYSEX?this.emit("midievent",e,t,[e.type,...e.data]):e.type==n.events.types.ESCAPE?this.emit("midievent",e,t,e.data):e.type==n.events.types.MIDI?this.emit("midievent",e,t,[(e.subtype<<4)+e.channel,...e.params]):e.type==n.events.types.META&&this.emit("midievent",e,t,null)}resetNotes(e=!1){for(let i=0;i<this.portCount;i++)for(var t=0;t<16;t++)this.triggerMidiEvent({type:n.events.types.MIDI,subtype:n.events.subtypes.midi.CONTROL_CHANGE,channel:t,params:[n.events.subtypes.midi.cc.ALL_SOUND_OFF,0]},i),this.triggerMidiEvent({type:n.events.types.MIDI,subtype:n.events.subtypes.midi.PITCH_BEND,channel:t,params:[0,64]},i),this.triggerMidiEvent({type:n.events.types.MIDI,subtype:n.events.subtypes.midi.CONTROL_CHANGE,channel:t,params:[n.events.subtypes.midi.cc.SUSTAIN_ONOFF,0]},i),e&&(this.triggerMidiEvent({type:n.events.types.MIDI,subtype:n.events.subtypes.midi.CONTROL_CHANGE,channel:t,params:[n.events.subtypes.midi.cc.RESET_ALL_CONTROLLERS,0]},i),this.triggerMidiEvent({type:n.events.types.MIDI,subtype:n.events.subtypes.midi.PROGRAM_CHANGE,channel:t,params:[0,0]},i))}calcCurrentTickFromCurrentMs(e){if(!this.d.header.ticksPerBeat)return Math.round(e/(this.d.header.tickResolution/1e3));let t=this.d.tempoEvents.getEvents();for(let i of Object.keys(t).reverse())for(let r in t[i])if(t[i][r].playms<=e)return i=parseInt(i,10),r=parseInt(r,10),Math.round((e-t[i][r].playms)/(t[i][r].tempo/1e3)*this.d.header.ticksPerBeat+i)}get currentTick(){return this.calcCurrentTickFromCurrentMs(this.playms)}set currentTick(e){if(e<0)return;if(this.resetNotes(),this.playtick=e,!this.d.header.ticksPerBeat)return void(this.playms=Math.round(e*(this.d.header.tickResolution/1e3)));let t=this.d.tempoEvents.getEvents();for(let i of Object.keys(t).reverse())for(let r in t[i])i<this.currentTick&&(i=parseInt(i,10),r=parseInt(r,10),this.playms=Math.round((e-i)/this.d.header.ticksPerBeat*(t[i][r].tempo/1e3)+t[i][r].playms))}get currentMs(){return this.playms}set currentMs(e){e<0||(this.resetNotes(),this.playms=Math.round(e),this.playtick=this.currentTick)}get durationTick(){return this.d.header.durationTick}get durationMs(){return this.d.header.durationMs}get ended(){return this.currentTick>=this.durationTick&&this.currentMs>=this.durationMs}play(){this.playing||(this.lastplayms=Date.now(),this.playing=!0,this.interval=setInterval(this.playLoop.bind(this),1))}pause(){this.playing&&(this.resetNotes(),this.playing=!1,clearInterval(this.interval))}playLoop(){if(this.inLoop)return;this.inLoop=!0;let e=Date.now(),t=(e-this.lastplayms)*this.tempo;this.lastplayms=e,this.playms+=t;let i=this.currentTick-this.playtick;for(let e=0;e<i;e++)this.d.ports.forEach(((e,t)=>{e.forEach((e=>{let i=e.getEvents();i[this.playtick]&&i[this.playtick].forEach((e=>this.triggerMidiEvent(e,t)))}))})),this.playtick++;this.ended&&this.pause(),this.inLoop=!1}}},524:e=>{e.exports=class{constructor(e,t){this.trackNo=e,this.meta=t,this.events={}}addEvent(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}getEvents(){return this.events}}}},t={},function i(r){var n=t[r];if(void 0!==n)return n.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,i),s.exports}(270);var e,t}));
{
"name": "yjmidi",
"version": "2.3.0",
"version": "2.4.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "description": "midi/yjk file parser/player",

@@ -5,8 +5,5 @@ const MidiTrack = require('./MidiTrack');

const DURATION_TAIL_MS = 3000;
module.exports = class MidiFile{
// unsafe를 true로 설정하면 파일의 duration은 (마지막 midi이벤트 타이밍)+3초 가 됨
// unsafe를 false로 설정하면 파일의 duration은 (meta이벤트를 포함한 마지막 이벤트 시간)이 됨
constructor(data,unsafe = true){
// tailMs = 미디파일이 공백 없이 끝나는 경우에 대비해 추가되는 공백시간(밀리초)
constructor(data,tailMs = 500){
let chunks = [];

@@ -139,4 +136,2 @@ let d = new ByteStream(data);

let playms = 0;
let lastMidiEvent = 0;
let lastMidiEventMs = 0;
let port = 0; // 포트번호 기본값은 0

@@ -192,11 +187,4 @@ let track = new MidiTrack(i);

track.addEvent(playtick,event);
if(event.type != Consts.events.types.META){
lastMidiEvent = playtick;
}
if(event.type == Consts.events.types.META && event.subtype == Consts.events.subtypes.meta.SET_TEMPO){
this.tempoEvents.addEvent(playtick,event);
// 모든 midi 이벤트가 끝나고도 tempo 이벤트가 남아있는 경우
// durationMs와 durationTick에 차이가 생기는 것을 방지
lastMidiEvent = playtick;
}

@@ -206,4 +194,3 @@ });

this.ports[port].push(track);
endtimes.push(unsafe ? lastMidiEvent : playtick);
//endtimesMs.push(unsafe ? lastMidiEventMs : playms);
endtimes.push(playtick);
}

@@ -234,5 +221,5 @@ this.header.durationTick = Math.max(...endtimes);

// durationTick에도 정확히 3초를 추가
if(unsafe){
this.header.durationMs += DURATION_TAIL_MS;
// durationTick에도 정확히 tailMs만큼의 공백시간을 추가
if(tailMs > 0){
this.header.durationMs += tailMs;
if(this.header.ticksPerBeat){

@@ -242,5 +229,5 @@ let tevents = this.tempoEvents.getEvents();

let lastTempo = tevents[tevents.length-1] ? tevents[tevents.length-1].tempo : 500000;
this.header.durationTick += Math.round(DURATION_TAIL_MS*1000/lastTempo*this.header.ticksPerBeat);
this.header.durationTick += Math.round(tailMs*1000/lastTempo*this.header.ticksPerBeat);
}else{
this.header.durationTick += Math.round(DURATION_TAIL_MS*1000/this.header.tickResolution);
this.header.durationTick += Math.round(tailMs*1000/this.header.tickResolution);
}

@@ -247,0 +234,0 @@ }

@@ -6,2 +6,4 @@ module.exports = {

output:{
library:'yjmidi',
libraryTarget:'umd',
path:`${__dirname}/dist`,

@@ -8,0 +10,0 @@ filename:'yjmidi.min.js'

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc