From 2a5f081be4082f554e3ad201ec962083148cf9d2 Mon Sep 17 00:00:00 2001 From: Sema Date: Tue, 20 Feb 2024 01:17:17 -0500 Subject: [PATCH] Tests and bug fix --- javascript/JZZ.midi.SMF.js | 4 ++-- minified/JZZ.midi.SMF.js | 2 +- package.json | 2 +- test/mocha.js | 8 ++++++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/javascript/JZZ.midi.SMF.js b/javascript/JZZ.midi.SMF.js index a6d1bcb..1e0aa7b 100644 --- a/javascript/JZZ.midi.SMF.js +++ b/javascript/JZZ.midi.SMF.js @@ -15,7 +15,7 @@ /* istanbul ignore next */ if (JZZ.MIDI.SMF) return; - var _ver = '1.8.7'; + var _ver = '1.8.8'; var _now = JZZ.lib.now; function _error(s) { throw new Error(s); } @@ -1436,7 +1436,7 @@ a = []; if (s.length < off + len) { for (i = off; i < s.length; i++) a.push(_hex(s.charCodeAt(i))); - this._complain(off, 'Incomplete message', a.join(' ')); + clip._complain(off, 'Incomplete message', a.join(' ')); off += len; break; } diff --git a/minified/JZZ.midi.SMF.js b/minified/JZZ.midi.SMF.js index da98e82..82cafbc 100644 --- a/minified/JZZ.midi.SMF.js +++ b/minified/JZZ.midi.SMF.js @@ -1 +1 @@ -!function(t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t.SMF=t:"function"==typeof define&&define.amd?define("JZZ.midi.SMF",["JZZ"],t):t(JZZ)}(function(u){var e,i,c,d;function l(t){throw new Error(t)}function o(t){var r="";return 2097151>21&127))),16383>14&127))),127>7&127))),r+=String.fromCharCode(127&t)}function n(t){return String.fromCharCode(t>>8)+String.fromCharCode(255&t)}function s(t){return String.fromCharCode(t>>24&255)+String.fromCharCode(t>>16&255)+String.fromCharCode(t>>8&255)+String.fromCharCode(255&t)}function h(t){return String.fromCharCode(255&t)+String.fromCharCode(t>>8&255)+String.fromCharCode(t>>16&255)+String.fromCharCode(t>>24&255)}function a(t){for(var r="",i=t.byteLength,e=0;e=i[a].length||(s&&(h=i[a][o[a]].tt),s=!1,h>i[a][o[a]].tt&&(h=i[a][o[a]].tt))}if(n=h,s)break}}return e}function C(t,r,i){if(!(this instanceof C))return new C(t,r,i);var e;if(this.sub[t])return this.sub[t](t,r,i);for("string"==typeof t&&4==t.length||l("Invalid chunk type: "+t),e=0;ei?_(t._off,"Invalid "+r+" meta event: data too long",S(t),t.tt):void 0}function b(t,r){return _(t._off,r+" meta events must be in the first track",S(t),t.tt)}function w(t,r,i,e){var n;if(255==r.charCodeAt(0))n=u.MIDI.smf(r.charCodeAt(1),i);else{for(var o=[r.charCodeAt(0)],s=0;s>4,h=[4,4,4,8,8,16,4,4,8,8,8,12,12,16,16,16][a],n=[],r.lengthe.length&&i._complain(n+e.length,"Incomplete data",s-e.length)},c="MThd"+String.fromCharCode(0)+String.fromCharCode(0)+String.fromCharCode(0)+String.fromCharCode(6),m.prototype.toString=function(){var t=[];return void 0!==this.off&&t.push("offset "+this.off),void 0!==this.track&&t.push("track "+this.track),void 0!==this.tick&&t.push("tick "+this.tick),t.push("--"),t.push(this.msg),void 0!==this.data&&t.push("("+this.data+")"),t.join(" ")},p.prototype.tracks=function(){for(var t=0,r=0;r>5?_(t._off,"Invalid SMPTE meta event: incorrect format",t.dd.charCodeAt(0)>>5,t.tt):r&&t.track?b(t,"SMPTE"):void 0):88==t.ff?M(t,"Time Signature",4)||(8>4,f=15&h[0];if(11==p)switch(h[1]){case 0:y(o,s,f,"bm"),s[f].bm=[h,!1];break;case 32:y(o,s,f,"bl"),s[f].bl=[h,!1];break;case 98:y(o,s,f,"nl"),y(o,s,f,"rm"),y(o,s,f,"rl"),s[f].nl=[h,!1];break;case 99:y(o,s,f,"nm"),y(o,s,f,"rm"),y(o,s,f,"rl"),s[f].nm=[h,!1];break;case 100:y(o,s,f,"rl"),y(o,s,f,"nm"),y(o,s,f,"nl"),s[f].rl=[h,!1];break;case 101:y(o,s,f,"rm"),y(o,s,f,"nm"),y(o,s,f,"nl"),s[f].rm=[h,!1];break;case 6:case 38:case 96:case 97:s[f].rm&&s[f].rl&&(s[f].rm[1]=!0,s[f].rl[1]=!0),!s[f].rm||s[f].rl||s[f].rm[1]||(a=s[f].rm[0],o.push(_(a._off,"No matching RPN LSB",a.toString(),a.tt,a.track)),s[f].rm[1]=!0),s[f].rm||!s[f].rl||s[f].rl[1]||(a=s[f].rl[0],o.push(_(a._off,"No matching RPN MSB",a.toString(),a.tt,a.track)),s[f].rl[1]=!0),s[f].nm&&s[f].nl&&(s[f].nm[1]=!0,s[f].nl[1]=!0),!s[f].nm||s[f].nl||s[f].nm[1]||(a=s[f].nm[0],o.push(_(a._off,"No matching NRPN LSB",a.toString(),a.tt,a.track)),s[f].nm[1]=!0),s[f].nm||!s[f].nl||s[f].nl[1]||(a=s[f].nl[0],o.push(_(a._off,"No matching NRPN MSB",a.toString(),a.tt,a.track)),s[f].nl[1]=!0),s[f].rm||s[f].rl||s[f].nm||s[f].nl||o.push(_(h._off,"RPN/NRPN not set",h.toString(),h.tt,h.track)),s[f].rm&&s[f].rl&&127==s[f].rm[0][2]&&127==s[f].rl[0][2]&&o.push(_(h._off,"RPN/NRPN not set",h.toString(),h.tt,h.track))}else 12==p&&(s[f].bm&&(s[f].bm[1]=!0),s[f].bl&&(s[f].bl[1]=!0),s[f].bl&&!s[f].bm&&(a=s[f].bl[0],o.push(_(a._off,"No matching Bank Select MSB",a.toString(),a.tt,a.track))),s[f].bm)&&!s[f].bl&&(a=s[f].bm[0],o.push(_(a._off,"No matching Bank Select LSB",a.toString(),a.tt,a.track)))}}if(g(t,n),t.sort(function(t,r){return(t.off||0)-(r.off||0)||(t.track||0)-(r.track||0)||(t.tick||0)-(r.tick||0)}),t.length){for(e=0;et);i++);this._orig.splice(i,0,r)}return this},A.prototype._sxid=127,A.prototype._image=function(){function t(){}t.prototype=this._orig;var r=new t;return r._ch=this._ch,r._sxid=this._sxid,r._tick=this._tick,r},A.prototype.send=function(t){return this._orig.add(this._tick,t),this},A.prototype.tick=function(t){if(t!=parseInt(t)||t<0)throw RangeError("Bad tick value: "+t);var r;return t?((r=this._image())._tick=this._tick+t,r):this},A.prototype.sxId=function(t){if((t=void 0===t?A.prototype._sxid:t)==this._sxid)return this;if(t!=parseInt(t)||t<0||127this._pos);this._ptr++)this._filter(t);this._ptr>=this._list.length&&(this._list==this._hdr?(this._list=this._data,this._ptr=0,this._p0=0,this._t0=r):(this._loop&&-1!=this._loop&&this._loop--,this._loop?(this._ptr=0,this._p0=0,this._t0=r):this.stop(),this.onEnd())),"stop"==this.event&&(this.playing=!1,this.paused=!1,this._pos=0,this._ptr=0,this.sndOff(),this.event=void 0),"pause"==this.event&&(this.playing=!1,this.paused=!0,this._pos>=this._duration&&(this._pos=this._duration-1),this._p0=this._pos,this.sndOff(),this.event=void 0),this.playing&&u.lib.schedule(this._tick)},N.prototype.trim=function(){for(var t,r=[],i=0,e=0;e=this._duration&&(t=this._duration-1),this._goto(t)},N.prototype.jumpMS=function(t){isNaN(parseFloat(t))&&l("Not a number: "+t),(t=t<0?0:t)>=this._durationMS&&(t=this._durationMS-1),this._goto(this._ms2t(t))},N.prototype._t2ms=function(t){if(!t)return 0;for(var r=0;this._ttt[r].t=this._pos);this._ptr++)t.isTempo()&&this.ppqn&&(this._mul=this.ppqn*(t.isMidi2?1e5:1e3)/(t.getTempo()||1));this._list=this._data,this.mul=this._mul*this._speed,this._t0=i(),this._p0=this._pos},N.prototype.tick2ms=function(t){return isNaN(parseFloat(t))&&l("Not a number: "+t),t<=0?0:t>=this._duration?this._durationMS:this._t2ms(t)},N.prototype.ms2tick=function(t){return isNaN(parseFloat(t))&&l("Not a number: "+t),t<=0?0:t>=this._durationMS?this._duration:this._ms2t(t)},u.MIDI.SMF=p,P.version=function(){return e},((P.prototype=[]).constructor=P).prototype.copy=function(t){for(var r=0;rt);i++);this._orig.splice(i,0,r)}return this},x.prototype.sxId=function(t){if((t=void 0===t?x.prototype._sxid:t)==this._sxid)return this;if(t!=parseInt(t)||t<0||127t);i++);this._orig.splice(i,0,r)}return this},x.prototype._complain=function(t,r,i,e){this._warn||(this._warn=[]);t={off:t,msg:r,data:i};void 0!==e&&(t.tick=e),this._warn.push(t)},x.prototype.validate=function(){var t,r=[];if(this._warn)for(t=0;t>21&127))),16383>14&127))),127>7&127))),r+=String.fromCharCode(127&t)}function n(t){return String.fromCharCode(t>>8)+String.fromCharCode(255&t)}function s(t){return String.fromCharCode(t>>24&255)+String.fromCharCode(t>>16&255)+String.fromCharCode(t>>8&255)+String.fromCharCode(255&t)}function h(t){return String.fromCharCode(255&t)+String.fromCharCode(t>>8&255)+String.fromCharCode(t>>16&255)+String.fromCharCode(t>>24&255)}function C(t){for(var r="",i=t.byteLength,e=0;e=i[a].length||(s&&(h=i[a][o[a]].tt),s=!1,h>i[a][o[a]].tt&&(h=i[a][o[a]].tt))}if(n=h,s)break}}return e}function I(t,r,i){if(!(this instanceof I))return new I(t,r,i);var e;if(this.sub[t])return this.sub[t](t,r,i);for("string"==typeof t&&4==t.length||v("Invalid chunk type: "+t),e=0;ei?u(t._off,"Invalid "+r+" meta event: data too long",S(t),t.tt):void 0}function b(t,r){return u(t._off,r+" meta events must be in the first track",S(t),t.tt)}function w(t,r,i,e){var n;if(255==r.charCodeAt(0))n=g.MIDI.smf(r.charCodeAt(1),i);else{for(var o=[r.charCodeAt(0)],s=0;s>4,u=[4,4,4,8,8,16,4,4,8,8,8,12,12,16,16,16][d],p=[],h.lengthe.length&&i._complain(n+e.length,"Incomplete data",s-e.length)},c="MThd"+String.fromCharCode(0)+String.fromCharCode(0)+String.fromCharCode(0)+String.fromCharCode(6),d.prototype.toString=function(){var t=[];return void 0!==this.off&&t.push("offset "+this.off),void 0!==this.track&&t.push("track "+this.track),void 0!==this.tick&&t.push("tick "+this.tick),t.push("--"),t.push(this.msg),void 0!==this.data&&t.push("("+this.data+")"),t.join(" ")},a.prototype.tracks=function(){for(var t=0,r=0;r>5?u(t._off,"Invalid SMPTE meta event: incorrect format",t.dd.charCodeAt(0)>>5,t.tt):r&&t.track?b(t,"SMPTE"):void 0):88==t.ff?M(t,"Time Signature",4)||(8>4,f=15&h[0];if(11==p)switch(h[1]){case 0:_(o,s,f,"bm"),s[f].bm=[h,!1];break;case 32:_(o,s,f,"bl"),s[f].bl=[h,!1];break;case 98:_(o,s,f,"nl"),_(o,s,f,"rm"),_(o,s,f,"rl"),s[f].nl=[h,!1];break;case 99:_(o,s,f,"nm"),_(o,s,f,"rm"),_(o,s,f,"rl"),s[f].nm=[h,!1];break;case 100:_(o,s,f,"rl"),_(o,s,f,"nm"),_(o,s,f,"nl"),s[f].rl=[h,!1];break;case 101:_(o,s,f,"rm"),_(o,s,f,"nm"),_(o,s,f,"nl"),s[f].rm=[h,!1];break;case 6:case 38:case 96:case 97:s[f].rm&&s[f].rl&&(s[f].rm[1]=!0,s[f].rl[1]=!0),!s[f].rm||s[f].rl||s[f].rm[1]||(a=s[f].rm[0],o.push(u(a._off,"No matching RPN LSB",a.toString(),a.tt,a.track)),s[f].rm[1]=!0),s[f].rm||!s[f].rl||s[f].rl[1]||(a=s[f].rl[0],o.push(u(a._off,"No matching RPN MSB",a.toString(),a.tt,a.track)),s[f].rl[1]=!0),s[f].nm&&s[f].nl&&(s[f].nm[1]=!0,s[f].nl[1]=!0),!s[f].nm||s[f].nl||s[f].nm[1]||(a=s[f].nm[0],o.push(u(a._off,"No matching NRPN LSB",a.toString(),a.tt,a.track)),s[f].nm[1]=!0),s[f].nm||!s[f].nl||s[f].nl[1]||(a=s[f].nl[0],o.push(u(a._off,"No matching NRPN MSB",a.toString(),a.tt,a.track)),s[f].nl[1]=!0),s[f].rm||s[f].rl||s[f].nm||s[f].nl||o.push(u(h._off,"RPN/NRPN not set",h.toString(),h.tt,h.track)),s[f].rm&&s[f].rl&&127==s[f].rm[0][2]&&127==s[f].rl[0][2]&&o.push(u(h._off,"RPN/NRPN not set",h.toString(),h.tt,h.track))}else 12==p&&(s[f].bm&&(s[f].bm[1]=!0),s[f].bl&&(s[f].bl[1]=!0),s[f].bl&&!s[f].bm&&(a=s[f].bl[0],o.push(u(a._off,"No matching Bank Select MSB",a.toString(),a.tt,a.track))),s[f].bm)&&!s[f].bl&&(a=s[f].bm[0],o.push(u(a._off,"No matching Bank Select LSB",a.toString(),a.tt,a.track)))}}if(l(t,n),t.sort(function(t,r){return(t.off||0)-(r.off||0)||(t.track||0)-(r.track||0)||(t.tick||0)-(r.tick||0)}),t.length){for(e=0;et);i++);this._orig.splice(i,0,r)}return this},A.prototype._sxid=127,A.prototype._image=function(){function t(){}t.prototype=this._orig;var r=new t;return r._ch=this._ch,r._sxid=this._sxid,r._tick=this._tick,r},A.prototype.send=function(t){return this._orig.add(this._tick,t),this},A.prototype.tick=function(t){if(t!=parseInt(t)||t<0)throw RangeError("Bad tick value: "+t);var r;return t?((r=this._image())._tick=this._tick+t,r):this},A.prototype.sxId=function(t){if((t=void 0===t?A.prototype._sxid:t)==this._sxid)return this;if(t!=parseInt(t)||t<0||127this._pos);this._ptr++)this._filter(t);this._ptr>=this._list.length&&(this._list==this._hdr?(this._list=this._data,this._ptr=0,this._p0=0,this._t0=r):(this._loop&&-1!=this._loop&&this._loop--,this._loop?(this._ptr=0,this._p0=0,this._t0=r):this.stop(),this.onEnd())),"stop"==this.event&&(this.playing=!1,this.paused=!1,this._pos=0,this._ptr=0,this.sndOff(),this.event=void 0),"pause"==this.event&&(this.playing=!1,this.paused=!0,this._pos>=this._duration&&(this._pos=this._duration-1),this._p0=this._pos,this.sndOff(),this.event=void 0),this.playing&&g.lib.schedule(this._tick)},N.prototype.trim=function(){for(var t,r=[],i=0,e=0;e=this._duration&&(t=this._duration-1),this._goto(t)},N.prototype.jumpMS=function(t){isNaN(parseFloat(t))&&v("Not a number: "+t),(t=t<0?0:t)>=this._durationMS&&(t=this._durationMS-1),this._goto(this._ms2t(t))},N.prototype._t2ms=function(t){if(!t)return 0;for(var r=0;this._ttt[r].t=this._pos);this._ptr++)t.isTempo()&&this.ppqn&&(this._mul=this.ppqn*(t.isMidi2?1e5:1e3)/(t.getTempo()||1));this._list=this._data,this.mul=this._mul*this._speed,this._t0=i(),this._p0=this._pos},N.prototype.tick2ms=function(t){return isNaN(parseFloat(t))&&v("Not a number: "+t),t<=0?0:t>=this._duration?this._durationMS:this._t2ms(t)},N.prototype.ms2tick=function(t){return isNaN(parseFloat(t))&&v("Not a number: "+t),t<=0?0:t>=this._durationMS?this._duration:this._ms2t(t)},g.MIDI.SMF=a,P.version=function(){return e},((P.prototype=[]).constructor=P).prototype.copy=function(t){for(var r=0;rt);i++);this._orig.splice(i,0,r)}return this},x.prototype.sxId=function(t){if((t=void 0===t?x.prototype._sxid:t)==this._sxid)return this;if(t!=parseInt(t)||t<0||127t);i++);this._orig.splice(i,0,r)}return this},x.prototype._complain=function(t,r,i,e){this._warn||(this._warn=[]);t={off:t,msg:r,data:i};void 0!==e&&(t.tick=e),this._warn.push(t)},x.prototype.validate=function(){var t,r=[];if(this._warn)for(t=0;t