diff --git a/bower.json b/bower.json index 0795fa8..bf1b87c 100644 --- a/bower.json +++ b/bower.json @@ -26,6 +26,6 @@ "Gruntfile.js" ], "dependencies": { - "jzz": "^1.4.1" + "jzz": "^1.4.3" } } diff --git a/javascript/JZZ.midi.SMF.js b/javascript/JZZ.midi.SMF.js index 8506e73..77c02b9 100644 --- a/javascript/JZZ.midi.SMF.js +++ b/javascript/JZZ.midi.SMF.js @@ -14,7 +14,7 @@ /* istanbul ignore next */ if (JZZ.MIDI.SMF) return; - var _ver = '1.6.3'; + var _ver = '1.6.4'; var _now = JZZ.lib.now; function _error(s) { throw new Error(s); } @@ -564,7 +564,7 @@ x = (x + '\x00\x00').substr(0, m); } for (var i = 0; i < m; i++) if (x.charCodeAt(i) > 127) { - trk._complain(off, 'Bad MIDI value', x.charCodeAt(i), t); + trk._complain(off + i, 'Bad MIDI value set to 0', x.charCodeAt(i), t); x = x.substr(0, i) + '\x00' + x.substr(i + 1); } return x; @@ -634,10 +634,10 @@ p += 1; m = _msglen(w.charCodeAt(0)); if (w.charCodeAt(0) > 0xf0) this._complain(offset, 'Unexpected MIDI message', w.charCodeAt(0).toString(16), t); - this.push(new Event(t, w, _validate_msg_data(this, s, p, m, t, offset), offset)); + this.push(new Event(t, w, _validate_msg_data(this, s, p, m, t, offset + 1), offset)); p += m; } - else if (w.charCodeAt(0) & 0x80) { + else if (w.charCodeAt(0) & 0x80) { // running status m = _msglen(w.charCodeAt(0)); if (w.charCodeAt(0) > 0xf0) this._complain(offset, 'Unexpected MIDI message', w.charCodeAt(0).toString(16), t); this.push(new Event(t, w, _validate_msg_data(this, s, p, m, t, offset), offset)); diff --git a/minified/JZZ.midi.SMF.js b/minified/JZZ.midi.SMF.js index c867122..8ad640a 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:"function"==typeof define&&define.amd?define("JZZ.midi.SMF",["JZZ"],t):t(JZZ)}(function(h){var n,i,p;function f(t){throw new Error(t)}function e(t){var r="";return 2097151>21&127))),16383>14&127))),127>7&127))),r+=String.fromCharCode(127&t)}function o(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 a(t){return String.fromCharCode(255&t)+String.fromCharCode(t>>8&255)+String.fromCharCode(t>>16&255)+String.fromCharCode(t>>24&255)}function c(){var t=this;t instanceof c||delete(t=new c).ppqn;var r,i,n=1,o=96;if(1==arguments.length){if(arguments[0]instanceof c)return arguments[0].copy();if(arguments[0]instanceof D){t.type=0,t.ppqn=o,t.push(new A);for(var e=0;e=i[a].length||(s&&(h=i[a][e[a]].tt),s=!1,h>i[a][e[a]].tt&&(h=i[a][e[a]].tt))}if(o=h,s)break}}return n}function y(t,r,i){if(!(this instanceof y))return new y(t,r,i);var n;if(this.sub[t])return this.sub[t](t,r,i);for("string"==typeof t&&4==t.length||f("Invalid chunk type: "+t),n=0;ni?u(t._off,"Invalid "+r+" meta event: data too long",I(t),t.tt):void 0}function S(t,r){return u(t._off,r+" meta events must be in the first track",I(t),t.tt)}function b(t,r,i,n){var o;if(255==r.charCodeAt(0))o=h.MIDI.smf(r.charCodeAt(1),i);else{for(var e=[r.charCodeAt(0)],s=0;st.length&&this._complain(r+t.length,"Incomplete data",o-t.length)},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.join(" ")+" -- "+this.msg+" ("+this.data+")"},c.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?S(t,"SMPTE"):void 0:88==t.ff?(i=k(t,"Time Signature",4))?i:8>4,e=15&i[0];if(11!=o)12==o&&(r[e].bm&&(r[e].bm[1]=!0),r[e].bl&&(r[e].bl[1]=!0),r[e].bl&&!r[e].bm&&(n=r[e].bl[0],t.push(u(n._off,"No matching Bank Select MSB",n.toString(),n.tt,n.track))),r[e].bm&&!r[e].bl&&(n=r[e].bm[0],t.push(u(n._off,"No matching Bank Select LSB",n.toString(),n.tt,n.track))));else switch(i[1]){case 0:_(t,r,e,"bm"),r[e].bm=[i,!1];break;case 32:_(t,r,e,"bl"),r[e].bl=[i,!1];break;case 98:_(t,r,e,"nl"),_(t,r,e,"rm"),_(t,r,e,"rl"),r[e].nl=[i,!1];break;case 99:_(t,r,e,"nm"),_(t,r,e,"rm"),_(t,r,e,"rl"),r[e].nm=[i,!1];break;case 100:_(t,r,e,"rl"),_(t,r,e,"nm"),_(t,r,e,"nl"),r[e].rl=[i,!1];break;case 101:_(t,r,e,"rm"),_(t,r,e,"nm"),_(t,r,e,"nl"),r[e].rm=[i,!1];break;case 6:case 38:case 96:case 97:r[e].rm&&r[e].rl&&(r[e].rm[1]=!0,r[e].rl[1]=!0),!r[e].rm||r[e].rl||r[e].rm[1]||(n=r[e].rm[0],t.push(u(n._off,"No matching RPN LSB",n.toString(),n.tt,n.track)),r[e].rm[1]=!0),r[e].rm||!r[e].rl||r[e].rl[1]||(n=r[e].rl[0],t.push(u(n._off,"No matching RPN MSB",n.toString(),n.tt,n.track)),r[e].rl[1]=!0),r[e].nm&&r[e].nl&&(r[e].nm[1]=!0,r[e].nl[1]=!0),!r[e].nm||r[e].nl||r[e].nm[1]||(n=r[e].nm[0],t.push(u(n._off,"No matching NRPN LSB",n.toString(),n.tt,n.track)),r[e].nm[1]=!0),r[e].nm||!r[e].nl||r[e].nl[1]||(n=r[e].nl[0],t.push(u(n._off,"No matching NRPN MSB",n.toString(),n.tt,n.track)),r[e].nl[1]=!0),r[e].rm||r[e].rl||r[e].nm||r[e].nl||t.push(u(i._off,"RPN/NRPN not set",i.toString(),i.tt,i.track)),r[e].rm&&r[e].rl&&127==r[e].rm[0][2]&&127==r[e].rl[0][2]&&t.push(u(i._off,"RPN/NRPN not set",i.toString(),i.tt,i.track))}}}(r,e,i[o]);if(l(r,e),r.sort(function(t,r){return(t.off||0)-(r.off||0)||(t.track||0)-(r.track||0)||(t.tick||0)-(r.tick||0)}),r.length){for(o=0;ot);i++);return this._orig.splice(i,0,r),this},A.prototype._ch=void 0,A.prototype._sxid=127,A.prototype._image=function(){var t=function(){};t.prototype=this._orig;t=new t;return t._ch=this._ch,t._sxid=this._sxid,t._tick=this._tick,t},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);if(!t)return this;var r=this._image();return r._tick=this._tick+t,r},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._data.length&&(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&&h.lib.schedule(this._tick)},M.prototype.trim=function(){for(var t,r=[],i=0,n=0,o=0;o=this._duration&&(t=this._duration-1),this._goto(t)},M.prototype.jumpMS=function(t){isNaN(parseFloat(t))&&f("Not a number: "+t),(t=t<0?0:t)>=this._durationMS&&(t=this._durationMS-1),this._goto(this._ms2t(t))},M.prototype._t2ms=function(t){if(!t)return 0;for(var r=0;this._ttt[r].t=this._pos)break;81==t.ff&&this.ppqn&&(this._mul=1e3*this.ppqn/w(t.dd))}this.mul=this._mul*this._speed,this._t0=i(),this._p0=this._pos},M.prototype.tick2ms=function(t){return isNaN(parseFloat(t))&&f("Not a number: "+t),t<=0?0:t>=this._duration?this._durationMS:this._t2ms(t)},M.prototype.ms2tick=function(t){return isNaN(parseFloat(t))&&f("Not a number: "+t),t<=0?0:t>=this._durationMS?this._duration:this._ms2t(t)},h.MIDI.SMF=c,D.version=function(){return n},((D.prototype=[]).constructor=D).prototype.copy=function(t){for(var r=0;r>21&127))),16383>14&127))),127>7&127))),r+=String.fromCharCode(127&t)}function o(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 a(t){return String.fromCharCode(255&t)+String.fromCharCode(t>>8&255)+String.fromCharCode(t>>16&255)+String.fromCharCode(t>>24&255)}function c(){var t=this;t instanceof c||delete(t=new c).ppqn;var r,i,n=1,o=96;if(1==arguments.length){if(arguments[0]instanceof c)return arguments[0].copy();if(arguments[0]instanceof D){t.type=0,t.ppqn=o,t.push(new A);for(var e=0;e=i[a].length||(s&&(h=i[a][e[a]].tt),s=!1,h>i[a][e[a]].tt&&(h=i[a][e[a]].tt))}if(o=h,s)break}}return n}function y(t,r,i){if(!(this instanceof y))return new y(t,r,i);var n;if(this.sub[t])return this.sub[t](t,r,i);for("string"==typeof t&&4==t.length||f("Invalid chunk type: "+t),n=0;ni?u(t._off,"Invalid "+r+" meta event: data too long",I(t),t.tt):void 0}function S(t,r){return u(t._off,r+" meta events must be in the first track",I(t),t.tt)}function b(t,r,i,n){var o;if(255==r.charCodeAt(0))o=h.MIDI.smf(r.charCodeAt(1),i);else{for(var e=[r.charCodeAt(0)],s=0;st.length&&this._complain(r+t.length,"Incomplete data",o-t.length)},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.join(" ")+" -- "+this.msg+" ("+this.data+")"},c.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?S(t,"SMPTE"):void 0:88==t.ff?(i=k(t,"Time Signature",4))?i:8>4,e=15&i[0];if(11!=o)12==o&&(r[e].bm&&(r[e].bm[1]=!0),r[e].bl&&(r[e].bl[1]=!0),r[e].bl&&!r[e].bm&&(n=r[e].bl[0],t.push(u(n._off,"No matching Bank Select MSB",n.toString(),n.tt,n.track))),r[e].bm&&!r[e].bl&&(n=r[e].bm[0],t.push(u(n._off,"No matching Bank Select LSB",n.toString(),n.tt,n.track))));else switch(i[1]){case 0:_(t,r,e,"bm"),r[e].bm=[i,!1];break;case 32:_(t,r,e,"bl"),r[e].bl=[i,!1];break;case 98:_(t,r,e,"nl"),_(t,r,e,"rm"),_(t,r,e,"rl"),r[e].nl=[i,!1];break;case 99:_(t,r,e,"nm"),_(t,r,e,"rm"),_(t,r,e,"rl"),r[e].nm=[i,!1];break;case 100:_(t,r,e,"rl"),_(t,r,e,"nm"),_(t,r,e,"nl"),r[e].rl=[i,!1];break;case 101:_(t,r,e,"rm"),_(t,r,e,"nm"),_(t,r,e,"nl"),r[e].rm=[i,!1];break;case 6:case 38:case 96:case 97:r[e].rm&&r[e].rl&&(r[e].rm[1]=!0,r[e].rl[1]=!0),!r[e].rm||r[e].rl||r[e].rm[1]||(n=r[e].rm[0],t.push(u(n._off,"No matching RPN LSB",n.toString(),n.tt,n.track)),r[e].rm[1]=!0),r[e].rm||!r[e].rl||r[e].rl[1]||(n=r[e].rl[0],t.push(u(n._off,"No matching RPN MSB",n.toString(),n.tt,n.track)),r[e].rl[1]=!0),r[e].nm&&r[e].nl&&(r[e].nm[1]=!0,r[e].nl[1]=!0),!r[e].nm||r[e].nl||r[e].nm[1]||(n=r[e].nm[0],t.push(u(n._off,"No matching NRPN LSB",n.toString(),n.tt,n.track)),r[e].nm[1]=!0),r[e].nm||!r[e].nl||r[e].nl[1]||(n=r[e].nl[0],t.push(u(n._off,"No matching NRPN MSB",n.toString(),n.tt,n.track)),r[e].nl[1]=!0),r[e].rm||r[e].rl||r[e].nm||r[e].nl||t.push(u(i._off,"RPN/NRPN not set",i.toString(),i.tt,i.track)),r[e].rm&&r[e].rl&&127==r[e].rm[0][2]&&127==r[e].rl[0][2]&&t.push(u(i._off,"RPN/NRPN not set",i.toString(),i.tt,i.track))}}}(r,e,i[o]);if(l(r,e),r.sort(function(t,r){return(t.off||0)-(r.off||0)||(t.track||0)-(r.track||0)||(t.tick||0)-(r.tick||0)}),r.length){for(o=0;ot);i++);return this._orig.splice(i,0,r),this},A.prototype._ch=void 0,A.prototype._sxid=127,A.prototype._image=function(){var t=function(){};t.prototype=this._orig;t=new t;return t._ch=this._ch,t._sxid=this._sxid,t._tick=this._tick,t},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);if(!t)return this;var r=this._image();return r._tick=this._tick+t,r},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._data.length&&(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&&h.lib.schedule(this._tick)},M.prototype.trim=function(){for(var t,r=[],i=0,n=0,o=0;o=this._duration&&(t=this._duration-1),this._goto(t)},M.prototype.jumpMS=function(t){isNaN(parseFloat(t))&&f("Not a number: "+t),(t=t<0?0:t)>=this._durationMS&&(t=this._durationMS-1),this._goto(this._ms2t(t))},M.prototype._t2ms=function(t){if(!t)return 0;for(var r=0;this._ttt[r].t=this._pos)break;81==t.ff&&this.ppqn&&(this._mul=1e3*this.ppqn/w(t.dd))}this.mul=this._mul*this._speed,this._t0=i(),this._p0=this._pos},M.prototype.tick2ms=function(t){return isNaN(parseFloat(t))&&f("Not a number: "+t),t<=0?0:t>=this._duration?this._durationMS:this._t2ms(t)},M.prototype.ms2tick=function(t){return isNaN(parseFloat(t))&&f("Not a number: "+t),t<=0?0:t>=this._durationMS?this._duration:this._ms2t(t)},h.MIDI.SMF=c,D.version=function(){return n},((D.prototype=[]).constructor=D).prototype.copy=function(t){for(var r=0;r