Comparing version 0.0.4 to 0.0.5
# Change Log | ||
## Sep 10, 2018 - v0.0.5 | ||
* Read ID3 tag from audio file in zip | ||
* Output 'title' and 'artist' from tag data to the canvas on file load | ||
## Sep 10, 2018 - v0.0.4 | ||
@@ -4,0 +9,0 @@ |
/** | ||
* @package CDGPlayer | ||
* @version 0.0.4 | ||
* @version 0.0.5 | ||
* @license GPLv3 | ||
@@ -28,3 +28,3 @@ * @copyright Copyright (c) 2018 Stephen G Blades, Jr (AKA 'Cutter') | ||
*/ | ||
function styleInject(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===i&&n.firstChild?n.insertBefore(r,n.firstChild):n.appendChild(r),r.styleSheet?r.styleSheet.cssText=t:r.appendChild(document.createTextNode(t))}}var css=".cdg-video-wrapper{height:0;overflow:hidden;padding-top:72%;background-color:#000;position:relative}.cdg-video-wrapper .cdg-video-player{position:absolute;top:0;left:0;width:100%;height:100%}";styleInject(css);var TILE_WIDTH=6,TILE_HEIGHT=12,TILES_X=50,TILES_Y=18,TILES_X_BORDER=1,TILES_Y_BORDER=1,WIDTH=TILE_WIDTH*TILES_X,HEIGHT=TILE_HEIGHT*TILES_Y,BORDER_WIDTH=TILE_WIDTH*TILES_X_BORDER,BORDER_HEIGHT=TILE_HEIGHT*TILES_Y_BORDER,DISPLAY_WIDTH=WIDTH-2*BORDER_WIDTH,DISPLAY_HEIGHT=HEIGHT-2*BORDER_HEIGHT,DISPLAY_BOUNDS=[BORDER_WIDTH,BORDER_HEIGHT,BORDER_WIDTH+DISPLAY_WIDTH,BORDER_HEIGHT+DISPLAY_HEIGHT],DISPLAY_PIXELS=WIDTH*HEIGHT,CDG_NOOP=0,CDG_MEMORY_PRESET=1,CDG_BORDER_PRESET=2,CDG_TILE_BLOCK=6,CDG_SCROLL_PRESET=20,CDG_SCROLL_COPY=24,CDG_SET_KEY_COLOR=28,CDG_LOAD_CLUT_LOW=30,CDG_LOAD_CLUT_HI=31,CDG_TILE_BLOCK_XOR=38,CDG_SCROLL_NONE=0,CDG_SCROLL_LEFT=1,CDG_SCROLL_RIGHT=2,CDG_SCROLL_UP=1,CDG_SCROLL_DOWN=2,CDG_DATA=4,COMMAND_MASK=63,CDG_COMMAND=9,SECTORS_PER_SECOND=75,PACKETS_PER_SECTOR=4,PACKET_SIZE=24,GAIN_DEFAULT=1,PITCH_DEFAULT=1,SCALE_DEFAULT=1,_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),defineProperty=function(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t},inherits=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},possibleConstructorReturn=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},slicedToArray=function(){return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var i=[],n=!0,r=!1,o=void 0;try{for(var s,a=t[Symbol.iterator]();!(n=(s=a.next()).done)&&(i.push(s.value),!e||i.length!==e);n=!0);}catch(t){r=!0,o=t}finally{try{!n&&a.return&&a.return()}finally{if(r)throw o}}return i}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),CDGContext=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=e.width,n=void 0===i?WIDTH:i,r=e.height,o=void 0===r?HEIGHT:r,s=e.canvas,a=void 0===s?this.createCanvas(n,o):s,u=e.ctx,c=void 0===u?this.createCanvasContext(a):u,l=e.imageData,h=void 0===l?this.createImageData(a,c,n,o):l;classCallCheck(this,t),this.hOffset=0,this.vOffset=0,this.keyColor=null,this.backgroundContainer=null,this.borderColor=null,this.memoryColor=null,this.clut=new Array(16).fill([0,0,0]),this.pixels=new Array(DISPLAY_PIXELS).fill(0),this.buffer=new Array(DISPLAY_PIXELS).fill(0),this.canvas=a,this.ctx=c,this.imageData=h}return createClass(t,[{key:"createCanvas",value:function(t,e){var i=document.createElement("canvas");return i.width=t,i.height=e,i}},{key:"createCanvasContext",value:function(t){var e=t.getContext("2d");return e.mozImageSmoothingEnabled=!1,e.webkitImageSmoothingEnabled=!1,e.msImageSmoothingEnabled=!1,e.imageSmoothingEnabled=!1,e}},{key:"createImageData",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t.width,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.height;return e.createImageData(i,n)}},{key:"reset",value:function(){this.hOffset=0,this.vOffset=0,this.keyColor=null,this.backgroundColor=null,this.borderColor=null,this.memoryColor=null,this.pixels.fill(0)}},{key:"setCLUTEntry",value:function(t,e,i,n){this.clut[t]=[e,i,n].map(function(t){return 17*t})}},{key:"setPixel",value:function(t,e,i){this.pixels[t+e*WIDTH]=i}},{key:"getPixel",value:function(t,e){return this.pixels[t+e*WIDTH]}},{key:"getBackground",value:function(){switch(!0){case null!=this.keyColor:return this.keyColor;case null!=this.backgroundColor:return this.backgroundColor;case null!=this.memoryColor:return this.memoryColor;case null!=this.borderColor:return this.borderColor;default:return 0}}},{key:"generateImageData",value:function(){for(var t=WIDTH,e=HEIGHT,i=0;i<t;i++)for(var n=0;n<e;n++){var r=4*(i+n*WIDTH),o=(i-this.hOffset+WIDTH)%WIDTH+(n-this.vOffset+HEIGHT)%HEIGHT*WIDTH,s=this.pixels[o],a=slicedToArray(this.clut[s],3),u=a[0],c=a[1],l=a[2];this.imageData.data[r]=u,this.imageData.data[r+1]=c,this.imageData.data[r+2]=l,this.imageData.data[r+3]=s===this.keyColor?0:255}return this.imageData}},{key:"renderFrame",value:function(){this.ctx.putImageData(this.generateImageData(),0,0)}}]),t}();function warn(){var t;console&&console.warn&&(t=console).warn.apply(t,arguments)}var CDGInstruction=function(){function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,t),this.bytes=e.slice(i,i+PACKET_SIZE)}return createClass(t,[{key:"instruction",get:function(){return this.constructor.instruction}},{key:"opcode",get:function(){return this.constructor.opcode}}]),createClass(t,[{key:"execute",value:function(){}},{key:"bytecodeToString",value:function(){return this.bytes.map(function(t){return t.toString(16).padStart(2,"0")}).join("")}},{key:"detailsToString",value:function(){return""}},{key:"toString",value:function(){return this.instruction}}]),t}();CDGInstruction.instruction="",CDGInstruction.opcode=null;var CDGNoopInstruction=function(t){function e(){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return inherits(e,CDGInstruction),e}();CDGNoopInstruction.instruction="No-op",CDGNoopInstruction.opcode=CDG_NOOP;var CDGMemoryPresetInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i)),r=i+CDG_DATA;return n.color=15&t[r],n.repeat=15&t[r+1],n}return inherits(e,CDGInstruction),createClass(e,[{key:"execute",value:function(t){t.memoryColor=this.color,t.backgroundColor=this.color,t.pixels.fill(this.color)}},{key:"detailsToString",value:function(){return"color index: "+this.color}}]),e}();CDGMemoryPresetInstruction.instruction="Memory Preset",CDGMemoryPresetInstruction.opcode=CDG_MEMORY_PRESET;var CDGBorderPresetInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i));return n.color=15&t[i+CDG_DATA],n}return inherits(e,CDGInstruction),createClass(e,[{key:"execute",value:function(t){t.borderColor=this.color,t.backgroundColor=this.color;for(var e=slicedToArray(DISPLAY_BOUNDS,4),i=e[0],n=e[1],r=e[2],o=e[3],s=0;s<WIDTH;s++){for(var a=0;a<n;a++)t.setPixel(s,a,this.color);for(var u=o+1;u<HEIGHT;u++)t.setPixel(s,u,this.color)}for(var c=n;c<=o;c++){for(var l=0;l<i;l++)t.setPixel(l,c,this.color);for(var h=r+1;h<WIDTH;h++)t.setPixel(h,c,this.color)}}},{key:"detailsToString",value:function(){return"color index: "+this.color}}]),e}();CDGBorderPresetInstruction.instruction="Border Preset",CDGBorderPresetInstruction.opcode=CDG_BORDER_PRESET;var CDGTileBlockInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i)),r=i+CDG_DATA;return n.colors=[15&t[r],15&t[r+1]],n.row=31&t[r+2],n.column=63&t[r+3],n.pixels=t.slice(r+4,r+16),n}return inherits(e,CDGInstruction),createClass(e,[{key:"execute",value:function(t){var e=this.column*TILE_WIDTH,i=this.row*TILE_HEIGHT;if(e+TILE_WIDTH>WIDTH||i+TILE_HEIGHT>HEIGHT)warn("TileBlock out of bounds ("+this.row+", "+this.column+")");else for(var n=0;n<TILE_HEIGHT;n++)for(var r=this.pixels[n],o=0;o<TILE_WIDTH;o++){var s=this.colors[r>>5-o&1];this.op(t,e+o,i+n,s)}}},{key:"op",value:function(t,e,i,n){t.setPixel(e,i,n)}},{key:"detailsToString",value:function(){return"row: "+this.row+", column: "+this.column+", color indexes: ["+this.colors.join(", ")+"]"}}]),e}();CDGTileBlockInstruction.instruction="Tile Block",CDGTileBlockInstruction.opcode=CDG_TILE_BLOCK;var CDGTileBlockXORInstruction=function(t){function e(){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return inherits(e,CDGTileBlockInstruction),createClass(e,[{key:"op",value:function(t,e,i,n){t.setPixel(e,i,t.getPixel(e,i)^n)}}]),e}();CDGTileBlockXORInstruction.instruction="Tile Block (XOR)",CDGTileBlockXORInstruction.opcode=CDG_TILE_BLOCK_XOR;var CDGScrollPresetInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i)),r=i+CDG_DATA;n.color=15&t[r];var o=63&t[r+1];n.hCmd=(48&o)>>4,n.hOffset=7&o;var s=63&t[r+2];return n.vCmd=(48&s)>>4,n.vOffset=15&s,n}return inherits(e,CDGInstruction),createClass(e,[{key:"execute",value:function(t){t.backgroundColor=this.color,t.hOffset=Math.min(this.hOffset,TILE_WIDTH-1),t.vOffset=Math.min(this.vOffset,TILE_HEIGHT-1);var e=0;switch(this.hCmd){case CDG_SCROLL_RIGHT:e=TILE_WIDTH;break;case CDG_SCROLL_LEFT:e=-TILE_WIDTH}var i=0;switch(this.hCmd){case CDG_SCROLL_DOWN:i=TILE_HEIGHT;break;case CDG_SCROLL_UP:i=-TILE_HEIGHT}if(e||i){for(var n=0;n<WIDTH;n++)for(var r=0;r<HEIGHT;r++)t.buffer[n+r*WIDTH]=this.getPixel(t,n+e,r+i);var o=[t.buffer,t.pixels];t.pixels=o[0],t.buffer=o[1]}}},{key:"getPixel",value:function(t,e,i){return e>0&&e<WIDTH&&i>0&&i<HEIGHT?t.pixels[e+i*WIDTH]:this.color}},{key:"detailsToString",value:function(){var t=!1,e=!1;return this.vCmd===CDG_SCROLL_UP?t="up":this.vCmd===CDG_SCROLL_DOWN&&(t="down"),this.vCmd===CDG_SCROLL_LEFT?e="left":this.vCmd===CDG_SCROLL_RIGHT&&(e="right"),[t,e,"vOffset: "+this.vOffset,"hOffset: "+this.hOffset].filter(function(t){return t}).join(" ")}}]),e}();CDGScrollPresetInstruction.instruction="Scroll Preset",CDGScrollPresetInstruction.opcode=CDG_SCROLL_PRESET;var CDGScrollCopyInstruction=function(t){function e(){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return inherits(e,CDGScrollPresetInstruction),createClass(e,[{key:"getPixel",value:function(t,e,i){return e=(e+WIDTH)%WIDTH,i=(i+HEIGHT)%HEIGHT,t.pixels[e+i*WIDTH]}}]),e}();CDGScrollCopyInstruction.instruction="Scroll Copy",CDGScrollCopyInstruction.opcode=CDG_SCROLL_COPY;var CDGSetKeyColorInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i));return n.color=15&t[i+CDG_DATA],n}return inherits(e,CDGInstruction),createClass(e,[{key:"execute",value:function(t){t.keyColor=this.color}},{key:"detailsToString",value:function(){return"color index: "+this.color}}]),e}();CDGSetKeyColorInstruction.instruction="Set Key Color",CDGSetKeyColorInstruction.opcode=CDG_SET_KEY_COLOR;var CDGLoadCLUTLowInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i)),r=i+CDG_DATA;n.colors=[];for(var o=0;o<8;o++){var s=r+2*o,a=((63&t[s])<<6)+(63&t[s+1]);n.colors[o]=[a>>8,(240&a)>>4,15&a]}return n}return inherits(e,CDGInstruction),createClass(e,[{key:"clutOffset",get:function(){return 0}}]),createClass(e,[{key:"execute",value:function(t){for(var e=0;e<8;e++)t.setCLUTEntry(e+this.clutOffset,this.colors[e][0],this.colors[e][1],this.colors[e][2])}},{key:"detailsToString",value:function(){var t=this;return"colors: ["+this.colors.map(function(e,i){return i+t.clutOffset+": #"+e.map(function(t){return t.toString(16)}).join("")}).join(", ")+"]"}}]),e}();CDGLoadCLUTLowInstruction.instruction="Load CLUT (Low)",CDGLoadCLUTLowInstruction.opcode=CDG_LOAD_CLUT_LOW;var CDGLoadCLUTHighInstruction=function(t){function e(){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return inherits(e,CDGLoadCLUTLowInstruction),createClass(e,[{key:"clutOffset",get:function(){return 8}}]),e}();CDGLoadCLUTHighInstruction.instruction="Load CLUT (High)",CDGLoadCLUTHighInstruction.opcode=CDG_LOAD_CLUT_HI;var CDGParser=function(){function t(){classCallCheck(this,t),this.instructionClassByType=this.constructor.instructionClassByType}return createClass(t,[{key:"registerInstruction",value:function(t,e){this.instructionClassByType[t]=e}},{key:"createInstruction",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return t in this.instructionClassByType||warn("Unknown CDG instruction (instruction = "+t+")"),new(this.instructionClassByType[t]||CDGNoopInstruction)(e,i)}},{key:"parseInstruction",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if((t[e]&COMMAND_MASK)===CDG_COMMAND){var i=t[e+1]&COMMAND_MASK;return this.createInstruction(i,t,e)}return new CDGNoopInstruction(t,e)}},{key:"parseInstructions",value:function(t){for(var e=[],i=t.length,n=0;n<i;n+=PACKET_SIZE)e.push(this.parseInstruction(t,n));return e.filter(function(t){return t})}}],[{key:"instructionClassByType",get:function(){var t;return defineProperty(t={},CDG_NOOP,CDGNoopInstruction),defineProperty(t,CDG_MEMORY_PRESET,CDGMemoryPresetInstruction),defineProperty(t,CDG_BORDER_PRESET,CDGBorderPresetInstruction),defineProperty(t,CDG_TILE_BLOCK,CDGTileBlockInstruction),defineProperty(t,CDG_SCROLL_PRESET,CDGScrollPresetInstruction),defineProperty(t,CDG_SCROLL_COPY,CDGScrollCopyInstruction),defineProperty(t,CDG_SET_KEY_COLOR,CDGSetKeyColorInstruction),defineProperty(t,CDG_LOAD_CLUT_LOW,CDGLoadCLUTLowInstruction),defineProperty(t,CDG_LOAD_CLUT_HI,CDGLoadCLUTHighInstruction),defineProperty(t,CDG_TILE_BLOCK_XOR,CDGTileBlockXORInstruction),t}}]),t}();function now(){if("undefined"!=typeof performance&&"function"==typeof performance.now)return performance.now();if("undefined"!=typeof process&&"function"==typeof process.hrtime){var t=process.hrtime(),e=slicedToArray(t,2);return 1e3*e[0]+e[1]/1e6}return Date.now()}function requestFrame(t){return"function"==typeof requestAnimationFrame?window.requestAnimationFrame(t):setTimeout(t,25)}function cancelFrame(t){return"function"==typeof cancelAnimationFrame?cancelAnimationFrame(t):clearTimeout(t)}var CDGPlayer=function(){function t(){var e=this,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=i.contextOptions,r=void 0===n?{}:n,o=i.context,s=void 0===o?this.createContext(r):o,a=i.afterRender;classCallCheck(this,t),this.instructions=[],this.pc=-1,this.frameId=null,this.pos=0,this.lastSyncPos=null,this.lastTimestamp=null,this.update=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:now();if(-1===e.pc)return e;e.frameId=requestFrame(e.update),e.lastSyncPos?e.pos=e.lastSyncPos+(t-e.lastTimestamp):(e.pos+=t-e.lastTimestamp,e.lastTimestamp=t);var i=Math.floor(SECTORS_PER_SECOND*PACKETS_PER_SECTOR*(e.pos/1e3))-e.pc;return i>0&&(e.fastForward(i),e.render()),e},this.context=s,this.afterRender=a}return createClass(t,[{key:"createContext",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new CDGContext(t)}},{key:"load",value:function(t){var e=new CDGParser;return this.instructions=e.parseInstructions(t),this.reset(),this}},{key:"reset",value:function(){return this.pc=0,this.pos=0,this.lastSyncPos=null,this.context.reset(),this}},{key:"render",value:function(){return this.context.renderFrame(),this.afterRender&&this.afterRender(this.context),this}},{key:"executeInstruction",value:function(t){return t&&"function"==typeof t.execute&&t.execute(this.context),this}},{key:"step",value:function(){return this.pc>=0&&this.pc<this.instructions.length?(this.executeInstruction(this.instructions[this.pc]),this.pc+=1):(this.pc=-1,this.stop()),this}},{key:"fastForward",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=this.pc+t;this.pc>=0&&this.pc<e;)this.step();return this}},{key:"play",value:function(){return this.frameId||(this.frameId=requestFrame(this.update),this.lastTimestamp=now()),this}},{key:"stop",value:function(){return cancelFrame(this.frameId),this.frameId=null,this.lastSyncPos=null,this}},{key:"sync",value:function(t){return this.lastSyncPos=t,this.lastTimestamp=now(),this}}]),t}(),Deferred=function(){return"undefined"!=typeof Promise&&Promise.defer?Promise.defer():"undefined"!=typeof PromiseUtils&&PromiseUtils.defer?PromiseUtils.defer():(this.resolve=null,this.reject=null,this.promise=new Promise(function(t,e){this.resolve=t,this.reject=e}.bind(this)),void Object.freeze(this))},getDataFile=function(t){var e=new Deferred;return JSZipUtils.getBinaryContent(t,function(i,n){i?e.reject(new Error("There was an error retrieving "+t,i)):e.resolve(n)}),e.promise},loadZipBuffer=function(t){return JSZip.loadAsync(t).catch(function(t){return Promise.reject(new Error("There was an error reading the zip file.",t))})},loadAudio=function(t){return t.async("arraybuffer").catch(function(t){return Promise.reject(new Error("Unable to load the audio file",t))})},loadVideo=function(t){return t.async("uint8array").catch(function(t){return Promise.reject(new Error("Unable to load the video file",t))})},getKaraokeFiles=function(t){var e=t.filter(function(t){return t.endsWith(".cdg")||t.endsWith(".mp3")});return 2===e.length?Promise.resolve(e):Promise.reject("The file is not a karaoke .zip file")},processZip=function(t){var e=t.filter(function(t){return t.name.endsWith(".mp3")}),i=t.filter(function(t){return t.name.endsWith(".cdg")}),n=[];if(e.length&&i.length)return n.push(loadAudio(e[0])),n.push(loadVideo(i[0])),Promise.all(n).catch(function(t){return Promise.reject(new Error("Processing audio and video failed",t))});var r=[];return e.length||r.push("No mp3 audio file present."),i.length||r.push("No cdg video file present."),Promise.reject(new Error(r.join(" ")))},CDGFileLoader=function(){function t(){classCallCheck(this,t)}return createClass(t,null,[{key:"loadZipFile",value:function(t){return getDataFile(t).then(function(t){return loadZipBuffer(t)}).then(function(t){return getKaraokeFiles(t)}).then(function(t){return processZip(t)}).catch(function(t){return Promise.reject(t)})}},{key:"loadFileBuffer",value:function(t){return loadZipBuffer(t).then(function(t){return getKaraokeFiles(t)}).then(function(t){return processZip(t)}).catch(function(t){return Promise.reject(t)})}}]),t}(),classCallCheck$1=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass$1=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),get$1=function t(e,i,n){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,i);if(void 0===r){var o=Object.getPrototypeOf(e);return null===o?void 0:t(o,i,n)}if("value"in r)return r.value;var s=r.get;return void 0!==s?s.call(n):void 0},inherits$1=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+(void 0===e?"undefined":_typeof(e)));t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},possibleConstructorReturn$1=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!==(void 0===e?"undefined":_typeof(e))&&"function"!=typeof e?t:e},FifoSampleBuffer=function(){function t(){classCallCheck$1(this,t),this._vector=new Float32Array,this._position=0,this._frameCount=0}return createClass$1(t,[{key:"clear",value:function(){this.receive(this._frameCount),this.rewind()}},{key:"put",value:function(t){this._frameCount+=t}},{key:"putSamples",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=2*(e=e||0);i>=0||(i=(t.length-n)/2);var r=2*i;this.ensureCapacity(i+this._frameCount);var o=this.endIndex;this.vector.set(t.subarray(n,n+r),o),this._frameCount+=i}},{key:"putBuffer",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;e=e||0,i>=0||(i=t.frameCount-e),this.putSamples(t.vector,t.position+e,i)}},{key:"receive",value:function(t){t>=0&&!(t>this._frameCount)||(t=this.frameCount),this._frameCount-=t,this._position+=t}},{key:"receiveSamples",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=2*e,n=this.startIndex;t.set(this._vector.subarray(n,n+i)),this.receive(e)}},{key:"extract",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=this.startIndex+2*e,r=2*i;t.set(this._vector.subarray(n,n+r))}},{key:"ensureCapacity",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=parseInt(2*t);if(this._vector.length<e){var i=new Float32Array(e);i.set(this._vector.subarray(this.startIndex,this.endIndex)),this._vector=i,this._position=0}else this.rewind()}},{key:"ensureAdditionalCapacity",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.ensureCapacity(this._frameCount+t)}},{key:"rewind",value:function(){this._position>0&&(this._vector.set(this._vector.subarray(this.startIndex,this.endIndex)),this._position=0)}},{key:"vector",get:function(){return this._vector}},{key:"position",get:function(){return this._position}},{key:"startIndex",get:function(){return 2*this._position}},{key:"frameCount",get:function(){return this._frameCount}},{key:"endIndex",get:function(){return 2*(this._position+this._frameCount)}}]),t}(),AbstractFifoSamplePipe=function(){function t(e){classCallCheck$1(this,t),e?(this._inputBuffer=new FifoSampleBuffer,this._outputBuffer=new FifoSampleBuffer):this._inputBuffer=this._outputBuffer=null}return createClass$1(t,[{key:"clear",value:function(){this._inputBuffer.clear(),this._outputBuffer.clear()}},{key:"inputBuffer",get:function(){return this._inputBuffer},set:function(t){this._inputBuffer=t}},{key:"outputBuffer",get:function(){return this._outputBuffer},set:function(t){this._outputBuffer=t}}]),t}(),RateTransposer=function(t){function e(t){classCallCheck$1(this,e);var i=possibleConstructorReturn$1(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.reset(),i._rate=1,i}return inherits$1(e,AbstractFifoSamplePipe),createClass$1(e,[{key:"reset",value:function(){this.slopeCount=0,this.prevSampleL=0,this.prevSampleR=0}},{key:"clone",value:function(){var t=new e;return t.rate=this._rate,t}},{key:"process",value:function(){var t=this._inputBuffer.frameCount;this._outputBuffer.ensureAdditionalCapacity(t/this._rate+1);var e=this.transpose(t);this._inputBuffer.receive(),this._outputBuffer.put(e)}},{key:"transpose",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(0===t)return 0;for(var e=this._inputBuffer.vector,i=this._inputBuffer.startIndex,n=this._outputBuffer.vector,r=this._outputBuffer.endIndex,o=0,s=0;this.slopeCount<1;)n[r+2*s]=(1-this.slopeCount)*this.prevSampleL+this.slopeCount*e[i],n[r+2*s+1]=(1-this.slopeCount)*this.prevSampleR+this.slopeCount*e[i+1],s+=1,this.slopeCount+=this._rate;if(this.slopeCount-=1,1!==t)t:for(;;){for(;this.slopeCount>1;)if(this.slopeCount-=1,(o+=1)>=t-1)break t;var a=i+2*o;n[r+2*s]=(1-this.slopeCount)*e[a]+this.slopeCount*e[a+2],n[r+2*s+1]=(1-this.slopeCount)*e[a+1]+this.slopeCount*e[a+3],s+=1,this.slopeCount+=this._rate}return this.prevSampleL=e[i+2*t-2],this.prevSampleR=e[i+2*t-1],s}},{key:"rate",set:function(t){this._rate=t}}]),e}(),FilterSupport=function(){function t(e){classCallCheck$1(this,t),this._pipe=e}return createClass$1(t,[{key:"fillInputBuffer",value:function(){throw new Error("fillInputBuffer() not overridden")}},{key:"fillOutputBuffer",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.outputBuffer.frameCount<t;){var e=16384-this.inputBuffer.frameCount;if(this.fillInputBuffer(e),this.inputBuffer.frameCount<16384)break;this._pipe.process()}}},{key:"clear",value:function(){this._pipe.clear()}},{key:"pipe",get:function(){return this._pipe}},{key:"inputBuffer",get:function(){return this._pipe.inputBuffer}},{key:"outputBuffer",get:function(){return this._pipe.outputBuffer}}]),t}(),noop=function(){},SimpleFilter=function(t){function e(t,i){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:noop;classCallCheck$1(this,e);var r=possibleConstructorReturn$1(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,i));return r.callback=n,r.sourceSound=t,r.historyBufferSize=22050,r._sourcePosition=0,r.outputBufferPosition=0,r._position=0,r}return inherits$1(e,FilterSupport),createClass$1(e,[{key:"onEnd",value:function(){this.callback()}},{key:"fillInputBuffer",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=new Float32Array(2*t),i=this.sourceSound.extract(e,t,this._sourcePosition);this._sourcePosition+=i,this.inputBuffer.putSamples(e,0,i)}},{key:"extract",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;this.fillOutputBuffer(this.outputBufferPosition+e);var i=Math.min(e,this.outputBuffer.frameCount-this.outputBufferPosition);this.outputBuffer.extract(t,this.outputBufferPosition,i);var n=this.outputBufferPosition+i;return this.outputBufferPosition=Math.min(this.historyBufferSize,n),this.outputBuffer.receive(Math.max(n-this.historyBufferSize,0)),this._position+=i,i}},{key:"handleSampleData",value:function(t){this.extract(t.data,4096)}},{key:"clear",value:function(){get$1(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"clear",this).call(this),this.outputBufferPosition=0}},{key:"position",get:function(){return this._position},set:function(t){if(t>this._position)throw new RangeError("New position may not be greater than current position");var e=this.outputBufferPosition-(this._position-t);if(e<0)throw new RangeError("New position falls outside of history buffer");this.outputBufferPosition=e,this._position=t}},{key:"sourcePosition",get:function(){return this._sourcePosition},set:function(t){this.clear(),this._sourcePosition=t}}]),e}(),USE_AUTO_SEQUENCE_LEN=0,DEFAULT_SEQUENCE_MS=USE_AUTO_SEQUENCE_LEN,USE_AUTO_SEEKWINDOW_LEN=0,DEFAULT_SEEKWINDOW_MS=USE_AUTO_SEEKWINDOW_LEN,DEFAULT_OVERLAP_MS=8,_SCAN_OFFSETS=[[124,186,248,310,372,434,496,558,620,682,744,806,868,930,992,1054,1116,1178,1240,1302,1364,1426,1488,0],[-100,-75,-50,-25,25,50,75,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[-20,-15,-10,-5,5,10,15,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[-4,-3,-2,-1,1,2,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]],AUTOSEQ_TEMPO_LOW=.5,AUTOSEQ_TEMPO_TOP=2,AUTOSEQ_AT_MIN=125,AUTOSEQ_AT_MAX=50,AUTOSEQ_K=(AUTOSEQ_AT_MAX-AUTOSEQ_AT_MIN)/(AUTOSEQ_TEMPO_TOP-AUTOSEQ_TEMPO_LOW),AUTOSEQ_C=AUTOSEQ_AT_MIN-AUTOSEQ_K*AUTOSEQ_TEMPO_LOW,AUTOSEEK_AT_MIN=25,AUTOSEEK_AT_MAX=15,AUTOSEEK_K=(AUTOSEEK_AT_MAX-AUTOSEEK_AT_MIN)/(AUTOSEQ_TEMPO_TOP-AUTOSEQ_TEMPO_LOW),AUTOSEEK_C=AUTOSEEK_AT_MIN-AUTOSEEK_K*AUTOSEQ_TEMPO_LOW,Stretch=function(t){function e(t){classCallCheck$1(this,e);var i=possibleConstructorReturn$1(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i._quickSeek=!0,i.midBufferDirty=!1,i.midBuffer=null,i.overlapLength=0,i.autoSeqSetting=!0,i.autoSeekSetting=!0,i._tempo=1,i.setParameters(44100,DEFAULT_SEQUENCE_MS,DEFAULT_SEEKWINDOW_MS,DEFAULT_OVERLAP_MS),i}return inherits$1(e,AbstractFifoSamplePipe),createClass$1(e,[{key:"clear",value:function(){get$1(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"clear",this).call(this),this.clearMidBuffer()}},{key:"clearMidBuffer",value:function(){this.midBufferDirty&&(this.midBufferDirty=!1,this.midBuffer=null)}},{key:"setParameters",value:function(t,e,i,n){t>0&&(this.sampleRate=t),n>0&&(this.overlapMs=n),e>0?(this.sequenceMs=e,this.autoSeqSetting=!1):this.autoSeqSetting=!0,i>0?(this.seekWindowMs=i,this.autoSeekSetting=!1):this.autoSeekSetting=!0,this.calculateSequenceParameters(),this.calculateOverlapLength(this.overlapMs),this.tempo=this._tempo}},{key:"calculateOverlapLength",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=void 0;e=(e=this.sampleRate*t/1e3)<16?16:e,e-=e%8,this.overlapLength=e,this.refMidBuffer=new Float32Array(2*this.overlapLength),this.midBuffer=new Float32Array(2*this.overlapLength)}},{key:"checkLimits",value:function(t,e,i){return t<e?e:t>i?i:t}},{key:"calculateSequenceParameters",value:function(){var t=void 0,e=void 0;this.autoSeqSetting&&(t=AUTOSEQ_C+AUTOSEQ_K*this._tempo,t=this.checkLimits(t,AUTOSEQ_AT_MAX,AUTOSEQ_AT_MIN),this.sequenceMs=Math.floor(t+.5)),this.autoSeekSetting&&(e=AUTOSEEK_C+AUTOSEEK_K*this._tempo,e=this.checkLimits(e,AUTOSEEK_AT_MAX,AUTOSEEK_AT_MIN),this.seekWindowMs=Math.floor(e+.5)),this.seekWindowLength=Math.floor(this.sampleRate*this.sequenceMs/1e3),this.seekLength=Math.floor(this.sampleRate*this.seekWindowMs/1e3)}},{key:"clone",value:function(){var t=new e;return t.tempo=this._tempo,t.setParameters(this.sampleRate,this.sequenceMs,this.seekWindowMs,this.overlapMs),t}},{key:"seekBestOverlapPosition",value:function(){return this._quickSeek?this.seekBestOverlapPositionStereoQuick():this.seekBestOverlapPositionStereo()}},{key:"seekBestOverlapPositionStereo",value:function(){var t=void 0,e=void 0,i=void 0,n=0;for(this.preCalculateCorrelationReferenceStereo(),t=0,e=Number.MIN_VALUE;n<this.seekLength;n+=1)(i=this.calculateCrossCorrelationStereo(2*n,this.refMidBuffer))>e&&(e=i,t=n);return t}},{key:"seekBestOverlapPositionStereoQuick",value:function(){var t=void 0,e=void 0,i=void 0,n=0,r=void 0,o=void 0;for(this.preCalculateCorrelationReferenceStereo(),e=Number.MIN_VALUE,t=0,r=0,o=0;n<4;n+=1){for(var s=0;_SCAN_OFFSETS[n][s]&&!((o=r+_SCAN_OFFSETS[n][s])>=this.seekLength);)(i=this.calculateCrossCorrelationStereo(2*o,this.refMidBuffer))>e&&(e=i,t=o),s+=1;r=t}return t}},{key:"preCalculateCorrelationReferenceStereo",value:function(){for(var t=0,e=void 0,i=void 0;t<this.overlapLength;t+=1)i=t*(this.overlapLength-t),e=2*t,this.refMidBuffer[e]=this.midBuffer[e]*i,this.refMidBuffer[e+1]=this.midBuffer[e+1]*i}},{key:"calculateCrossCorrelationStereo",value:function(t,e){var i=this._inputBuffer.vector;t+=this._inputBuffer.startIndex;for(var n=0,r=2,o=2*this.overlapLength,s=void 0;r<o;r+=2)n+=i[s=r+t]*e[r]+i[s+1]*e[r+1];return n}},{key:"overlap",value:function(t){this.overlapStereo(2*t)}},{key:"overlapStereo",value:function(t){var e=this._inputBuffer.vector;t+=this._inputBuffer.startIndex;for(var i=this._outputBuffer.vector,n=this._outputBuffer.endIndex,r=0,o=void 0,s=void 0,a=1/this.overlapLength,u=void 0,c=void 0,l=void 0;r<this.overlapLength;r+=1)s=(this.overlapLength-r)*a,u=r*a,c=(o=2*r)+t,i[(l=o+n)+0]=e[c+0]*u+this.midBuffer[o+0]*s,i[l+1]=e[c+1]*u+this.midBuffer[o+1]*s}},{key:"process",value:function(){var t=void 0,e=void 0,i=void 0;if(null===this.midBuffer){if(this._inputBuffer.frameCount<this.overlapLength)return;this.midBuffer=new Float32Array(2*this.overlapLength),this._inputBuffer.receiveSamples(this.midBuffer,this.overlapLength)}for(;this._inputBuffer.frameCount>=this.sampleReq;){t=this.seekBestOverlapPosition(),this._outputBuffer.ensureAdditionalCapacity(this.overlapLength),this.overlap(Math.floor(t)),this._outputBuffer.put(this.overlapLength),(e=this.seekWindowLength-2*this.overlapLength)>0&&this._outputBuffer.putBuffer(this._inputBuffer,t+this.overlapLength,e);var n=this._inputBuffer.startIndex+2*(t+this.seekWindowLength-this.overlapLength);this.midBuffer.set(this._inputBuffer.vector.subarray(n,n+2*this.overlapLength)),this.skipFract+=this.nominalSkip,i=Math.floor(this.skipFract),this.skipFract-=i,this._inputBuffer.receive(i)}}},{key:"tempo",set:function(t){var e;this._tempo=t,this.calculateSequenceParameters(),this.nominalSkip=this._tempo*(this.seekWindowLength-this.overlapLength),this.skipFract=0,e=Math.floor(this.nominalSkip+.5),this.sampleReq=Math.max(e+this.overlapLength,this.seekWindowLength)+this.seekLength},get:function(){return this._tempo}},{key:"inputChunkSize",get:function(){return this.sampleReq}},{key:"outputChunkSize",get:function(){return this.overlapLength+Math.max(0,this.seekWindowLength-2*this.overlapLength)}},{key:"quickSeek",set:function(t){this._quickSeek=t}}]),e}(),testFloatEqual=function(t,e){return(t>e?t-e:e-t)>1e-10},SoundTouch=function(){function t(){classCallCheck$1(this,t),this.transposer=new RateTransposer(!1),this.stretch=new Stretch(!1),this._inputBuffer=new FifoSampleBuffer,this._intermediateBuffer=new FifoSampleBuffer,this._outputBuffer=new FifoSampleBuffer,this._rate=0,this._tempo=0,this.virtualPitch=1,this.virtualRate=1,this.virtualTempo=1,this.calculateEffectiveRateAndTempo()}return createClass$1(t,[{key:"clear",value:function(){this.transposer.clear(),this.stretch.clear()}},{key:"clone",value:function(){var e=new t;return e.rate=this.rate,e.tempo=this.tempo,e}},{key:"calculateEffectiveRateAndTempo",value:function(){var t=this._tempo,e=this._rate;this._tempo=this.virtualTempo/this.virtualPitch,this._rate=this.virtualRate*this.virtualPitch,testFloatEqual(this._tempo,t)&&(this.stretch.tempo=this._tempo),testFloatEqual(this._rate,e)&&(this.transposer.rate=this._rate),this._rate>1?this._outputBuffer!=this.transposer.outputBuffer&&(this.stretch.inputBuffer=this._inputBuffer,this.stretch.outputBuffer=this._intermediateBuffer,this.transposer.inputBuffer=this._intermediateBuffer,this.transposer.outputBuffer=this._outputBuffer):this._outputBuffer!=this.stretch.outputBuffer&&(this.transposer.inputBuffer=this._inputBuffer,this.transposer.outputBuffer=this._intermediateBuffer,this.stretch.inputBuffer=this._intermediateBuffer,this.stretch.outputBuffer=this._outputBuffer)}},{key:"process",value:function(){this._rate>1?(this.stretch.process(),this.transposer.process()):(this.transposer.process(),this.stretch.process())}},{key:"rate",get:function(){return this._rate},set:function(t){this.virtualRate=t,this.calculateEffectiveRateAndTempo()}},{key:"rateChange",set:function(t){this._rate=1+.01*t}},{key:"tempo",get:function(){return this._tempo},set:function(t){this.virtualTempo=t,this.calculateEffectiveRateAndTempo()}},{key:"tempoChange",set:function(t){this.tempo=1+.01*t}},{key:"pitch",set:function(t){this.virtualPitch=t,this.calculateEffectiveRateAndTempo()}},{key:"pitchOctaves",set:function(t){this.pitch=Math.exp(.69314718056*t),this.calculateEffectiveRateAndTempo()}},{key:"pitchSemitones",set:function(t){this.pitchOctaves=t/12}},{key:"inputBuffer",get:function(){return this._inputBuffer}},{key:"outputBuffer",get:function(){return this._outputBuffer}}]),t}(),WebAudioBufferSource=function(){function t(e){classCallCheck$1(this,t),this.buffer=e,this._position=0}return createClass$1(t,[{key:"extract",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;this.position=i;for(var n=this.buffer.getChannelData(0),r=this.dualChannel?this.buffer.getChannelData(1):this.buffer.getChannelData(0),o=0;o<e;o++)t[2*o]=n[o+i],t[2*o+1]=r[o+i];return Math.min(e,n.length-i)}},{key:"dualChannel",get:function(){return this.buffer.numberOfChannels>1}},{key:"position",get:function(){return this._position},set:function(t){this._position=t}}]),t}(),getWebAudioNode=function(t,e,i){var n=i||4096,r=t.createScriptProcessor(n,2,2),o=new Float32Array(2*n);return r.onaudioprocess=function(t){var i=t.outputBuffer.getChannelData(0),r=t.outputBuffer.getChannelData(1),s=e.extract(o,n);0===s&&e.onEnd();for(var a=0;a<s;a++)i[a]=o[2*a],r[a]=o[2*a+1]},r},pad=function(t,e,i){return i=i||"0",(t+="").length>=e?t:new Array(e-t.length+1).join(i)+t},minsSecs=function(t){var e=Math.floor(t/60);return e+":"+pad(parseInt(t-60*e),2)},PitchShifter=function(){function t(e,i,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:noop;classCallCheck$1(this,t),this._soundtouch=new SoundTouch;var o=new WebAudioBufferSource(i);this._filter=new SimpleFilter(o,this._soundtouch,r),this._node=getWebAudioNode(e,this._filter),this.tempo=1,this.rate=1,this.duration=function(){return i.duration},this.sampleRate=function(){return e.sampleRate}}return createClass$1(t,[{key:"connect",value:function(t){this._node.connect(t)}},{key:"disconnect",value:function(){this._node.disconnect()}},{key:"formattedDuration",get:function(){var t=this.duration()||0;return minsSecs(t)}},{key:"formattedTimePlayed",get:function(){return minsSecs(this.timePlayed)}},{key:"timePlayed",get:function(){return this._filter.sourcePosition/this.sampleRate()}},{key:"sourcePosition",get:function(){return this._filter.sourcePosition}},{key:"percentagePlayed",get:function(){var t=this.duration()||0;return 100*this._filter.sourcePosition/(t*this.sampleRate())},set:function(t){var e=this.duration()||0;this._filter.sourcePosition=parseInt(t*e*this.sampleRate())}},{key:"node",get:function(){return this._node}},{key:"pitch",set:function(t){this._soundtouch.pitch=t}},{key:"pitchSemitones",set:function(t){this._soundtouch.pitchSemitones=t}},{key:"rate",set:function(t){this._soundtouch.rate=t}},{key:"tempo",set:function(t){this._soundtouch.tempo=t}}]),t}(),isString=function(t){return"string"==typeof t},PubSub=function(){function t(){classCallCheck(this,t),this.fns={any:[]}}return createClass(t,[{key:"has",value:function(t){return t in this.fns&&this.fns[t].length>0||this.fns.any.length>0}},{key:"on",value:function(t,e){return t in this.fns==!1&&(this.fns[t]=[]),this.fns[t].push(e),e}},{key:"fire",value:function(t,e,i){return this.fns.any.concat(t in this.fns?this.fns[t]:[]).forEach(function(n){return n(e,i,t)}),this}},{key:"off",value:function(t){for(var e in this.fns)for(var i=this.fns[e],n=0;n<i.length;n++)if(i[n]===t)return i.splice(n,1),!0;return!1}},{key:"once",value:function(t,e){var i=this;return this.on(t,function t(n,r,o){e(n,r,o),i.off(t)}),e}}]),t}(),observable=function(t){if(t.on&&t.off)return t;var e=new PubSub,i=new Proxy(t,{get:function(t,n){if(n in t){if(t.constructor===Array){var r=i;"pop"===n?r=t[t.length-1]:"shift"===n&&(r=t[0]),"push"!==n&&"length"!==n&&e.fire(n,r)}return t[n]}return"on"===n?e.on.bind(e):"once"===n?e.once.bind(e):"off"===n?e.off.bind(e):void 0},set:function(t,i,n){return t.constructor===Array?"length"!==i&&e.fire("change",n):e.has(i)&&e.fire(i,n,t[i]),t[i]=n,!0}});return i},createDisplayCanvas=function(t,e){var i=document.createElement("canvas");return i.width=t,i.height=e,i},createCanvasContext=function(t){var e=t.getContext("2d");return e.mozImageSmoothingEnabled=!1,e.webkitImageSmoothingEnabled=!1,e.msImageSmoothingEnabled=!1,e.imageSmoothingEnabled=!1,e},copyContextToCanvas=function(t){t.keyColor>=0&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.drawImage(t.canvas,0,0,t.canvas.width,t.canvas.height,0,0,this.canvas.width,this.canvas.height)},clearCanvas=function(t,e){t.clearRect(0,0,e.width,e.height)},loadAudio$1=function(t){var e=this;return this.audio.decodeAudioData(t).then(function(t){e.shifter=new PitchShifter(e.audio,t,1024,function(){e.stop()}),e.shifter.pitch=PITCH_DEFAULT,e.props.trackLength=e.shifter.formattedDuration}).catch(function(t){return Promise.reject(new Error("There was an error decoding the audio file",t))})},loadVideo$1=function(t){var e=new Deferred;return t?(this.player.load(Array.from(t)),e.resolve()):e.reject(new Error("There was an error loading the video file")),e.promise},handleExtractedZip=function(t){var e=this,i=[];return i.push(loadAudio$1.call(this,t[0])),i.push(loadVideo$1.call(this,t[1])),Promise.all(i).then(function(){e.props.status="File Loaded",e.props.loaded=!0}).catch(function(t){return e.props.status="File Loading Failed",Promise.reject(t)}).then(function(){e.props.loading=!1})},updatePlayPosition=function(){this.props.timePlayed=this.shifter.formattedTimePlayed,this.props.percentagePlayed=this.shifter.percentagePlayed,this.player.sync(1e3*this.shifter.timePlayed)},KaraokePlayer=function(){function t(e){var i=this;if(classCallCheck(this,t),this.audio=null,this.gainNode=null,this.shifter=null,this.wrapper=null,this.player=null,this.currentSize=SCALE_DEFAULT,this.canvas=null,this.ctx=null,this.props=observable({status:"",loaded:!1,loading:!1,isPlaying:!1,timePlayed:"0:00",trackLength:"0:00",percentagePlayed:0,destroy:!1}),this.wrapper=document.querySelector(e),!this.wrapper)throw new Error('CDGPlayer: and element was not found with the "'+e+'" selector');this.wrapper.classList.add("cdg-video-wrapper"),this.canvas=createDisplayCanvas(WIDTH,HEIGHT),this.canvas.classList.add("cdg-video-player"),this.ctx=createCanvasContext(this.canvas),this.player=new CDGPlayer({afterRender:function(t){return copyContextToCanvas.call(i,t)}}),this.wrapper.appendChild(this.canvas),this.audio=new(window.AudioContext||window.webkitAudioContext),this.gainNode=this.audio.createGain(),this.gainNode.gain.value=GAIN_DEFAULT}return createClass(t,[{key:"destroy",value:function(){this.wrapper.classList.remove("cdg-video-wrapper"),this.stop(),this.gainNode.disconnect(),this.shifter=null,this.gainNode=null,this.audio=null,this.canvas.remove(),this.props.destroy=!0}},{key:"load",value:function(t){var e=this;this.stop(),clearCanvas(this.ctx,this.canvas),this.props.loading=!0;var i=void 0;if(isString(t)){if(!t.toLowerCase().endsWith(".zip"))return this.props.loading=!1,this.props.status=t+' doesn\'t appear to be a ".zip" file.',Promise.reject(this.props.status);this.props.status="Retrieving File...",i=CDGFileLoader.loadZipFile(t)}else this.props.status="Loading File...",i=CDGFileLoader.loadFileBuffer(t);return i.then(function(t){return handleExtractedZip.call(e,t)}).catch(function(t){return Promise.reject(t)})}},{key:"togglePlay",value:function(){this.props.isPlaying?this.pause():this.start()}},{key:"start",value:function(){var t=this;this.shifter.connect(this.gainNode),this.gainNode.connect(this.audio.destination),this.props.isPlaying=!0,this.player.play(),this.timeInterval=setInterval(function(){return updatePlayPosition.call(t)},20)}},{key:"pause",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.props.isPlaying=t,this.shifter.disconnect(),this.timeInterval&&(clearInterval(this.timeInterval),this.timeInterval=null),this.player.stop()}},{key:"stop",value:function(){this.shifter&&(this.pause(),this.changePlayerPosition(0))}},{key:"changePlayerPosition",value:function(t){t=t<0?0:t>100?100:t,this.shifter.percentagePlayed=t,this.props.percentagePlayed=this.shifter.percentagePlayed,this.props.timePlayed=this.shifter.formattedTimePlayed,this.player.reset(),this.props.isPlaying&&updatePlayPosition.call(this)}},{key:"changeKey",value:function(t){t=t<-7?-7:t>7?7:t,this.shifter.pitchSemitones=t,this.shifter.tempo=1}},{key:"volume",value:function(t){var e=+(this.gainNode.gain.value+t).toFixed(2);this.gainNode.gain.value=e>=0?e:0}},{key:"toggleMute",value:function(){var t=this.gainNode.gain.value;this.gainNode.gain.value=t?0:this.fallbackVolume,this.fallbackVolume=t}}]),t}(),ctrlTemplate='<cdg-controls> <button class="playButton" disabled><i class="icofont-play-alt-1"></i></button> <span class="timePlayed"></span> <div class="progress-container"> <progress class="progressMeter" ng-disabled="$ctrls.loading" value="0" max="100"></progress> </div> <span class="trackLength"></span> <span> <input type="number" class="pitch" step="1" min="-7" max="7" value="0" disabled> </span> </cdg-controls>',css$1='@font-face{font-family:IcoFont;font-weight:400;font-style:normal;src:url("data:application/font-woff2;base64,d09GMgABAAAAAANAAAsAAAAABtwAAALxAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHFQGVgCCfgqCHIIeATYCJAMMCwgABCAFhAoHPBsRBhHVk6NkXxaYh0PxNxTNnhifG8s2BnhaP6LjV+5CR+g+Lczng+Cp3+/17N0QkULiKmBUgDKq6DodH5K/LiT8W53aS+hkQHphxR/dg5OS1unLU+KeBQA45La0a4SJ849uHr5C2ttTc+Brm9pegBsw+oDb4CUEdn2Vmg6ck1cE9QKwrKTj6Xp/44HaIorwwvhh7CbKg7gFAVzIohhTWd3Yicfi2IllQrAD1AvE2bI4NzOGk67CriZbcEJwKJmp+9KRgjlpGAG3+e/FRiUBg70C9mqdrpqk9Pj9cW23KP0q8HQ8B4CWhgJp69FId6mpFQ1DaSguTsiOOFjXKIHjlsExylrtHx4YBMQBkOkGQJIYNnAMs2JxkXPGZQqAA7eQ1g1cASDz6ztAgw30fNc2RLeVb1fxS9m9s4PW3XrFd+LrIk8KP/fx+lL0wquPp26KJcKLLYV3DMWlbi0wWLCbv6s6/9z6BcYr/eaTrES1pqKqfBOPMMwmX1Wm03MrJFsLt/FG2cL/c7n4slXfa/WXpNhPs5G8nVr3YhOOJ+02t8HN1g6RFe3Xg4rV8vLVig0vRGe9V8s3Krzkku07gZBBYDat1SfiGAUsUKj1VwIW5RLhHxzG2+hmP+LJjar7BLDr257IaM9ulw5OGHBYbzwB3bcMKM/ligLNs2oYmigQLUr6HQQM4AK9YAGwePG3v01wvDODwVHm3p/FEY8YsEP8Sfa4EkZywJFEkgupZMx3xZc+FLFzRvBgUQAMchJQ5Dpghzwl2RPAO5IDHnwnudDNv3VdSRDuMYymNZqeOB+SuXU0QuewaV90fjUaqrzMXdChRscIJ+B/8OdcEwkQzigYYD+U0oB1ZsOR8oXINkUhyr6Qj0YFw2hao+mJ8yGZW8sRUSFV+kXnV70/qPKyHuhEug0tI5zW4X/w51wTCUkgpJhRsIpxKKUBWz5uw5HypUfANgWsJtqK8tkl6m01AC6AS1SMqNjhsirZP2OSsiq17PAYBAAAAA==") format("woff2"),url("data:application/font-woff;base64,d09GRgABAAAAAASsAAsAAAAABtwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADsAAABUIIslek9TLzIAAAFEAAAAQwAAAFZCxU4eY21hcAAAAYgAAABUAAABfp998U1nbHlmAAAB3AAAAPEAAAEcMf3mymhlYWQAAALQAAAAMwAAADYSUZ1SaGhlYQAAAwQAAAAcAAAAJAc7A1ZobXR4AAADIAAAAAwAAAAMC7j//2xvY2EAAAMsAAAACAAAAAgARACObWF4cAAAAzQAAAAeAAAAIAEQADluYW1lAAADVAAAASsAAAIKNKI0mnBvc3QAAASAAAAAKwAAADxH3y55eJxjYGRgYOBiMGCwY2BycfMJYeDLSSzJY5BiYGGAAJA8MpsxJzM9kYEDxgPKsYBpDiBmg4gCACY7BUgAeJxjYGR+wTiBgZWBgamKaQ8DA0MPhGZ8wGDIyAQUZWBlZsAKAtJcUxgc3ix9s4w56H8WQxRzMMM0oDAjSA4AJPsNaQB4nO2QsQ2AMAwEz4mhQIxBQcEwVGxIpmOH8HYYg5f+5T/ZjYEJqPIhO9iFETpFLXllSe5suePBn9a78o5U1yUluM38WjP3r5X403DObRh7AZXQD1N4nGNg+v//fx7zC2ZfBgkGDQYGQRFxMXE5RnMxM3MgNDVR12NUV+NjZGdTFZNnFBNhZ2XTYzQVNLFj1NTwcNuaEL/VzUNDy93pUUPy9gka2ozTE/aZ8fH9W8Mlxs8vxhiXFRfp4uzOyOjm5BIZl91TktPAxOTeFhlfZVWqyKnMeYGNWZCHcSGPIDMDAxD9zwK6I5hBhEGBQYeBgVGJnY2dTQDoHDEFkFsE1NXU1ZhF2JTUgPabGYmJMiKzv3SUFDq7uDgXljAKwFjXFPUUgYiRBUIzB4EE/31AVfi3SFxRUZzRDET+O4VgMzAwAAAXDj+xAAAAeJxjYGRgYADidaVdE+P5bb4ycDO/AIowXF+65gaM/v//fxbzC+ZgIJeDgQkkCgCi4A+IAHicY2BkYGAO+p8FJF/8/w8iGYAiKIAZAIvIBZgD6AAAA+j//wPoAAAAAAAAAEQAjnicY2BkYGBgZtAFYhBgAmIuIGRg+A/mMwAADUUBSgAAeJxdkE1qwzAQhZ/zS2MIhdKsStGqXRScn2UOkJBtFoYuHUd2HGzLyEogPUFP0BP0FD1A6bH6bKaLRkLSN2+epJEA3OIbHprmYdjOTeuQh8Jd0li4R74X7sPHg/CA+rPwCC8IhH3c4ZUneL0bKmPkwh3ym3CX/C7cI38I9zHBp/CA+pfwCCF+hH08eY+b2KxM6bY6PeWRzWKTMJIl1LbOTKnmwUyUtS61jZzeq91F1ed04VyiEmsK1Ryi89yoypqjjl1wcK5aTqeJ6EFsCmwQw2DFUcJhC40UJ74rgkXW5hLJ/Y9COi1qqk2sMOcfza48a3rK1hcx0tjTt8OFc40z71lQdXQrDss9BemvEs0acrJC1eaOVGLqAQ7trgpLTNmTK3/QVlD8AsE9WlYAeJxjYGKAAC4G7ICZkYmRmZGFgasgJ7FSNzGnRNeQtSCxtDiVgQEAQLEFywA=") format("woff")}[class*=" icofont-"],[class^=icofont-]{font-family:IcoFont!important;speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;white-space:nowrap;word-wrap:normal;direction:ltr;line-height:1;-webkit-font-feature-settings:"liga";-webkit-font-smoothing:antialiased}.icofont-play-alt-1:before{content:"\\eca6"}.icofont-pause:before{content:"\\eca5"}.icofont-md,cdg-controls .playButton>i{font-size:1.25em}.icofont-fw,cdg-controls .playButton>i{text-align:center;width:1.25em}cdg-controls{position:relative;display:-ms-flexbox;display:-webkit-flex;display:-webkit-box;display:flex;height:40px;-webkit-flex-direction:row;-ms-flex-direction:row;-webkit-box-orient:horizontal;-webkit-box-direction:normal;flex-direction:row;-webkit-flex-wrap:nowrap;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;width:100%;font-size:1.25em}cdg-controls>button,cdg-controls>div,cdg-controls>span{margin:3px 5px}cdg-controls>button:first-child,cdg-controls>div:first-child,cdg-controls>span:first-child{margin-left:0}cdg-controls>button:last-child,cdg-controls>div:last-child,cdg-controls>span:last-child{margin-right:0}cdg-controls .playButton{padding:5px;width:34px;height:34px}cdg-controls .playButton[disabled]{cursor:not-allowed}cdg-controls .pitch{height:28px;font-size:.8em;text-align:right}cdg-controls .pitch[disabled]{cursor:not-allowed}cdg-controls .progress-container{position:relative;-webkit-box-flex:0;-webkit-flex:0 1 auto;-ms-flex:0 1 auto;flex:0 1 auto;width:100%;display:inline-block}cdg-controls .progress-container progress{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:100%;height:1em}cdg-controls .progress-container progress::-webkit-progress-bar{background-color:#eee;border-radius:.5em;-webkit-box-shadow:0 2px 5px rgba(0,0,0,.25) inset;box-shadow:inset 0 2px 5px rgba(0,0,0,.25)}cdg-controls .progress-container progress::-webkit-progress-value{background-image:-webkit-linear-gradient(-45deg,transparent 33%,transparent 0,rgba(0,0,0,.1) 66%,transparent 0),-webkit-linear-gradient(top,hsla(0,0%,100%,.25),rgba(0,0,0,.25)),-webkit-linear-gradient(left,#09c,#f44);border-radius:.5em;-webkit-background-size:35px 20px,100% 100%,100% 100%;background-size:35px 20px,100% 100%,100% 100%}';styleInject(css$1);var playIcon="icofont-play-alt-1",pauseIcon="icofont-pause",htmlToElement=function(t){var e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild},setupListeners=function(){var t=this,e=this.player.props;this.onloaded=e.on("loaded",function(e){e?(t.playBtn.removeAttribute("disabled"),t.pitch.removeAttribute("disabled")):(t.playBtn.setAttribute("disabled","disabled"),t.pitch.setAttribute("disabled","disabled"))}),this.ontimeplayed=e.on("timePlayed",function(e,i){e!==i&&(t.timePlayed.innerHTML=e)}),this.onpercentageplayed=e.on("percentagePlayed",function(e,i){e!==i&&(t.progress.value=e)}),this.ontracklength=e.on("trackLength",function(e,i){e!==i&&(t.trackLength.innerHTML=e)}),this.ondestroy=e.on("destroy",function(e){e&&removeListeners.call(t)}),this.onplay=e.on("isPlaying",function(e){t.playIcn.classList.remove(playIcon,pauseIcon),t.playIcn.classList.add(e?pauseIcon:playIcon)}),this.playBtn.addEventListener("click",function(){return t.player.togglePlay()}),this.progress.addEventListener("click",function(e){return changePosition.call(t,e)}),this.pitch.addEventListener("change",function(){return changeKey.call(t)})},removeListeners=function(){var t=this,e=this.player.props;e.off(this.onloaded),e.off(this.ontimeplayed),e.off(this.onpercentageplayed),e.off(this.ontracklength),e.off(this.ondestroy),this.playBtn.removeEventListener("click",function(){return t.player.togglePlay()}),this.progress.removeEventListener("click",function(e){return changePosition.call(t,e)}),this.pitch.removeEventListener("change",function(){return changeKey.call(t)})},changePosition=function(t){var e=t.target.getBoundingClientRect(),i=(t.pageX-e.x)/t.target.offsetWidth;this.player.changePlayerPosition(i)},changeKey=function(){var t=this.pitch.value;isNaN(t)?this.pitch.value=this.fallbackPitch:(this.fallbackPitch=t<-7?-7:t>7?7:t,this.player.changeKey(this.fallbackPitch))},CDGControls=function t(e,i){classCallCheck(this,t),this.controls=htmlToElement(ctrlTemplate),this.player=null,this.playBtn=null,this.playIcn=null,this.timePlayed=null,this.progress=null,this.trackLength=null,this.pitch=null,document.querySelector(e).appendChild(this.controls),this.player=i;var n=this.player.props;this.playBtn=this.controls.querySelector(".playButton"),this.playIcn=this.playBtn.querySelector("i"),this.timePlayed=this.controls.querySelector(".timePlayed"),this.timePlayed.innerHTML=n.timePlayed,this.progress=this.controls.querySelector(".progressMeter"),this.progress.value=n.percentagePlayed,this.trackLength=this.controls.querySelector(".trackLength"),this.trackLength.innerHTML=n.trackLength,this.pitch=this.controls.querySelector(".pitch"),this.fallbackPitch=0,setupListeners.call(this)};export{KaraokePlayer as CDGPlayer,CDGControls}; | ||
function styleInject(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===i&&n.firstChild?n.insertBefore(r,n.firstChild):n.appendChild(r),r.styleSheet?r.styleSheet.cssText=t:r.appendChild(document.createTextNode(t))}}var css=".cdg-video-wrapper{height:0;overflow:hidden;padding-top:72%;background-color:#000;position:relative}.cdg-video-wrapper .cdg-video-player{position:absolute;top:0;left:0;width:100%;height:100%}";styleInject(css);var TILE_WIDTH=6,TILE_HEIGHT=12,TILES_X=50,TILES_Y=18,TILES_X_BORDER=1,TILES_Y_BORDER=1,WIDTH=TILE_WIDTH*TILES_X,HEIGHT=TILE_HEIGHT*TILES_Y,BORDER_WIDTH=TILE_WIDTH*TILES_X_BORDER,BORDER_HEIGHT=TILE_HEIGHT*TILES_Y_BORDER,DISPLAY_WIDTH=WIDTH-2*BORDER_WIDTH,DISPLAY_HEIGHT=HEIGHT-2*BORDER_HEIGHT,DISPLAY_BOUNDS=[BORDER_WIDTH,BORDER_HEIGHT,BORDER_WIDTH+DISPLAY_WIDTH,BORDER_HEIGHT+DISPLAY_HEIGHT],DISPLAY_PIXELS=WIDTH*HEIGHT,CDG_NOOP=0,CDG_MEMORY_PRESET=1,CDG_BORDER_PRESET=2,CDG_TILE_BLOCK=6,CDG_SCROLL_PRESET=20,CDG_SCROLL_COPY=24,CDG_SET_KEY_COLOR=28,CDG_LOAD_CLUT_LOW=30,CDG_LOAD_CLUT_HI=31,CDG_TILE_BLOCK_XOR=38,CDG_SCROLL_NONE=0,CDG_SCROLL_LEFT=1,CDG_SCROLL_RIGHT=2,CDG_SCROLL_UP=1,CDG_SCROLL_DOWN=2,CDG_DATA=4,COMMAND_MASK=63,CDG_COMMAND=9,SECTORS_PER_SECOND=75,PACKETS_PER_SECTOR=4,PACKET_SIZE=24,GAIN_DEFAULT=1,PITCH_DEFAULT=1,SCALE_DEFAULT=1,_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),defineProperty=function(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t},inherits=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},possibleConstructorReturn=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},slicedToArray=function(){return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var i=[],n=!0,r=!1,o=void 0;try{for(var s,a=t[Symbol.iterator]();!(n=(s=a.next()).done)&&(i.push(s.value),!e||i.length!==e);n=!0);}catch(t){r=!0,o=t}finally{try{!n&&a.return&&a.return()}finally{if(r)throw o}}return i}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),CDGContext=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=e.width,n=void 0===i?WIDTH:i,r=e.height,o=void 0===r?HEIGHT:r,s=e.canvas,a=void 0===s?this.createCanvas(n,o):s,u=e.ctx,c=void 0===u?this.createCanvasContext(a):u,l=e.imageData,h=void 0===l?this.createImageData(a,c,n,o):l;classCallCheck(this,t),this.hOffset=0,this.vOffset=0,this.keyColor=null,this.backgroundContainer=null,this.borderColor=null,this.memoryColor=null,this.clut=new Array(16).fill([0,0,0]),this.pixels=new Array(DISPLAY_PIXELS).fill(0),this.buffer=new Array(DISPLAY_PIXELS).fill(0),this.canvas=a,this.ctx=c,this.imageData=h}return createClass(t,[{key:"createCanvas",value:function(t,e){var i=document.createElement("canvas");return i.width=t,i.height=e,i}},{key:"createCanvasContext",value:function(t){var e=t.getContext("2d");return e.mozImageSmoothingEnabled=!1,e.webkitImageSmoothingEnabled=!1,e.msImageSmoothingEnabled=!1,e.imageSmoothingEnabled=!1,e}},{key:"createImageData",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t.width,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.height;return e.createImageData(i,n)}},{key:"reset",value:function(){this.hOffset=0,this.vOffset=0,this.keyColor=null,this.backgroundColor=null,this.borderColor=null,this.memoryColor=null,this.pixels.fill(0)}},{key:"setCLUTEntry",value:function(t,e,i,n){this.clut[t]=[e,i,n].map(function(t){return 17*t})}},{key:"setPixel",value:function(t,e,i){this.pixels[t+e*WIDTH]=i}},{key:"getPixel",value:function(t,e){return this.pixels[t+e*WIDTH]}},{key:"getBackground",value:function(){switch(!0){case null!=this.keyColor:return this.keyColor;case null!=this.backgroundColor:return this.backgroundColor;case null!=this.memoryColor:return this.memoryColor;case null!=this.borderColor:return this.borderColor;default:return 0}}},{key:"generateImageData",value:function(){for(var t=WIDTH,e=HEIGHT,i=0;i<t;i++)for(var n=0;n<e;n++){var r=4*(i+n*WIDTH),o=(i-this.hOffset+WIDTH)%WIDTH+(n-this.vOffset+HEIGHT)%HEIGHT*WIDTH,s=this.pixels[o],a=slicedToArray(this.clut[s],3),u=a[0],c=a[1],l=a[2];this.imageData.data[r]=u,this.imageData.data[r+1]=c,this.imageData.data[r+2]=l,this.imageData.data[r+3]=s===this.keyColor?0:255}return this.imageData}},{key:"renderFrame",value:function(){this.ctx.putImageData(this.generateImageData(),0,0)}}]),t}();function warn(){var t;console&&console.warn&&(t=console).warn.apply(t,arguments)}var CDGInstruction=function(){function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,t),this.bytes=e.slice(i,i+PACKET_SIZE)}return createClass(t,[{key:"instruction",get:function(){return this.constructor.instruction}},{key:"opcode",get:function(){return this.constructor.opcode}}]),createClass(t,[{key:"execute",value:function(){}},{key:"bytecodeToString",value:function(){return this.bytes.map(function(t){return t.toString(16).padStart(2,"0")}).join("")}},{key:"detailsToString",value:function(){return""}},{key:"toString",value:function(){return this.instruction}}]),t}();CDGInstruction.instruction="",CDGInstruction.opcode=null;var CDGNoopInstruction=function(t){function e(){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return inherits(e,CDGInstruction),e}();CDGNoopInstruction.instruction="No-op",CDGNoopInstruction.opcode=CDG_NOOP;var CDGMemoryPresetInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i)),r=i+CDG_DATA;return n.color=15&t[r],n.repeat=15&t[r+1],n}return inherits(e,CDGInstruction),createClass(e,[{key:"execute",value:function(t){t.memoryColor=this.color,t.backgroundColor=this.color,t.pixels.fill(this.color)}},{key:"detailsToString",value:function(){return"color index: "+this.color}}]),e}();CDGMemoryPresetInstruction.instruction="Memory Preset",CDGMemoryPresetInstruction.opcode=CDG_MEMORY_PRESET;var CDGBorderPresetInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i));return n.color=15&t[i+CDG_DATA],n}return inherits(e,CDGInstruction),createClass(e,[{key:"execute",value:function(t){t.borderColor=this.color,t.backgroundColor=this.color;for(var e=slicedToArray(DISPLAY_BOUNDS,4),i=e[0],n=e[1],r=e[2],o=e[3],s=0;s<WIDTH;s++){for(var a=0;a<n;a++)t.setPixel(s,a,this.color);for(var u=o+1;u<HEIGHT;u++)t.setPixel(s,u,this.color)}for(var c=n;c<=o;c++){for(var l=0;l<i;l++)t.setPixel(l,c,this.color);for(var h=r+1;h<WIDTH;h++)t.setPixel(h,c,this.color)}}},{key:"detailsToString",value:function(){return"color index: "+this.color}}]),e}();CDGBorderPresetInstruction.instruction="Border Preset",CDGBorderPresetInstruction.opcode=CDG_BORDER_PRESET;var CDGTileBlockInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i)),r=i+CDG_DATA;return n.colors=[15&t[r],15&t[r+1]],n.row=31&t[r+2],n.column=63&t[r+3],n.pixels=t.slice(r+4,r+16),n}return inherits(e,CDGInstruction),createClass(e,[{key:"execute",value:function(t){var e=this.column*TILE_WIDTH,i=this.row*TILE_HEIGHT;if(e+TILE_WIDTH>WIDTH||i+TILE_HEIGHT>HEIGHT)warn("TileBlock out of bounds ("+this.row+", "+this.column+")");else for(var n=0;n<TILE_HEIGHT;n++)for(var r=this.pixels[n],o=0;o<TILE_WIDTH;o++){var s=this.colors[r>>5-o&1];this.op(t,e+o,i+n,s)}}},{key:"op",value:function(t,e,i,n){t.setPixel(e,i,n)}},{key:"detailsToString",value:function(){return"row: "+this.row+", column: "+this.column+", color indexes: ["+this.colors.join(", ")+"]"}}]),e}();CDGTileBlockInstruction.instruction="Tile Block",CDGTileBlockInstruction.opcode=CDG_TILE_BLOCK;var CDGTileBlockXORInstruction=function(t){function e(){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return inherits(e,CDGTileBlockInstruction),createClass(e,[{key:"op",value:function(t,e,i,n){t.setPixel(e,i,t.getPixel(e,i)^n)}}]),e}();CDGTileBlockXORInstruction.instruction="Tile Block (XOR)",CDGTileBlockXORInstruction.opcode=CDG_TILE_BLOCK_XOR;var CDGScrollPresetInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i)),r=i+CDG_DATA;n.color=15&t[r];var o=63&t[r+1];n.hCmd=(48&o)>>4,n.hOffset=7&o;var s=63&t[r+2];return n.vCmd=(48&s)>>4,n.vOffset=15&s,n}return inherits(e,CDGInstruction),createClass(e,[{key:"execute",value:function(t){t.backgroundColor=this.color,t.hOffset=Math.min(this.hOffset,TILE_WIDTH-1),t.vOffset=Math.min(this.vOffset,TILE_HEIGHT-1);var e=0;switch(this.hCmd){case CDG_SCROLL_RIGHT:e=TILE_WIDTH;break;case CDG_SCROLL_LEFT:e=-TILE_WIDTH}var i=0;switch(this.hCmd){case CDG_SCROLL_DOWN:i=TILE_HEIGHT;break;case CDG_SCROLL_UP:i=-TILE_HEIGHT}if(e||i){for(var n=0;n<WIDTH;n++)for(var r=0;r<HEIGHT;r++)t.buffer[n+r*WIDTH]=this.getPixel(t,n+e,r+i);var o=[t.buffer,t.pixels];t.pixels=o[0],t.buffer=o[1]}}},{key:"getPixel",value:function(t,e,i){return e>0&&e<WIDTH&&i>0&&i<HEIGHT?t.pixels[e+i*WIDTH]:this.color}},{key:"detailsToString",value:function(){var t=!1,e=!1;return this.vCmd===CDG_SCROLL_UP?t="up":this.vCmd===CDG_SCROLL_DOWN&&(t="down"),this.vCmd===CDG_SCROLL_LEFT?e="left":this.vCmd===CDG_SCROLL_RIGHT&&(e="right"),[t,e,"vOffset: "+this.vOffset,"hOffset: "+this.hOffset].filter(function(t){return t}).join(" ")}}]),e}();CDGScrollPresetInstruction.instruction="Scroll Preset",CDGScrollPresetInstruction.opcode=CDG_SCROLL_PRESET;var CDGScrollCopyInstruction=function(t){function e(){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return inherits(e,CDGScrollPresetInstruction),createClass(e,[{key:"getPixel",value:function(t,e,i){return e=(e+WIDTH)%WIDTH,i=(i+HEIGHT)%HEIGHT,t.pixels[e+i*WIDTH]}}]),e}();CDGScrollCopyInstruction.instruction="Scroll Copy",CDGScrollCopyInstruction.opcode=CDG_SCROLL_COPY;var CDGSetKeyColorInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i));return n.color=15&t[i+CDG_DATA],n}return inherits(e,CDGInstruction),createClass(e,[{key:"execute",value:function(t){t.keyColor=this.color}},{key:"detailsToString",value:function(){return"color index: "+this.color}}]),e}();CDGSetKeyColorInstruction.instruction="Set Key Color",CDGSetKeyColorInstruction.opcode=CDG_SET_KEY_COLOR;var CDGLoadCLUTLowInstruction=function(t){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;classCallCheck(this,e);var n=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,i)),r=i+CDG_DATA;n.colors=[];for(var o=0;o<8;o++){var s=r+2*o,a=((63&t[s])<<6)+(63&t[s+1]);n.colors[o]=[a>>8,(240&a)>>4,15&a]}return n}return inherits(e,CDGInstruction),createClass(e,[{key:"clutOffset",get:function(){return 0}}]),createClass(e,[{key:"execute",value:function(t){for(var e=0;e<8;e++)t.setCLUTEntry(e+this.clutOffset,this.colors[e][0],this.colors[e][1],this.colors[e][2])}},{key:"detailsToString",value:function(){var t=this;return"colors: ["+this.colors.map(function(e,i){return i+t.clutOffset+": #"+e.map(function(t){return t.toString(16)}).join("")}).join(", ")+"]"}}]),e}();CDGLoadCLUTLowInstruction.instruction="Load CLUT (Low)",CDGLoadCLUTLowInstruction.opcode=CDG_LOAD_CLUT_LOW;var CDGLoadCLUTHighInstruction=function(t){function e(){return classCallCheck(this,e),possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return inherits(e,CDGLoadCLUTLowInstruction),createClass(e,[{key:"clutOffset",get:function(){return 8}}]),e}();CDGLoadCLUTHighInstruction.instruction="Load CLUT (High)",CDGLoadCLUTHighInstruction.opcode=CDG_LOAD_CLUT_HI;var CDGParser=function(){function t(){classCallCheck(this,t),this.instructionClassByType=this.constructor.instructionClassByType}return createClass(t,[{key:"registerInstruction",value:function(t,e){this.instructionClassByType[t]=e}},{key:"createInstruction",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return t in this.instructionClassByType||warn("Unknown CDG instruction (instruction = "+t+")"),new(this.instructionClassByType[t]||CDGNoopInstruction)(e,i)}},{key:"parseInstruction",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if((t[e]&COMMAND_MASK)===CDG_COMMAND){var i=t[e+1]&COMMAND_MASK;return this.createInstruction(i,t,e)}return new CDGNoopInstruction(t,e)}},{key:"parseInstructions",value:function(t){for(var e=[],i=t.length,n=0;n<i;n+=PACKET_SIZE)e.push(this.parseInstruction(t,n));return e.filter(function(t){return t})}}],[{key:"instructionClassByType",get:function(){var t;return defineProperty(t={},CDG_NOOP,CDGNoopInstruction),defineProperty(t,CDG_MEMORY_PRESET,CDGMemoryPresetInstruction),defineProperty(t,CDG_BORDER_PRESET,CDGBorderPresetInstruction),defineProperty(t,CDG_TILE_BLOCK,CDGTileBlockInstruction),defineProperty(t,CDG_SCROLL_PRESET,CDGScrollPresetInstruction),defineProperty(t,CDG_SCROLL_COPY,CDGScrollCopyInstruction),defineProperty(t,CDG_SET_KEY_COLOR,CDGSetKeyColorInstruction),defineProperty(t,CDG_LOAD_CLUT_LOW,CDGLoadCLUTLowInstruction),defineProperty(t,CDG_LOAD_CLUT_HI,CDGLoadCLUTHighInstruction),defineProperty(t,CDG_TILE_BLOCK_XOR,CDGTileBlockXORInstruction),t}}]),t}();function now(){if("undefined"!=typeof performance&&"function"==typeof performance.now)return performance.now();if("undefined"!=typeof process&&"function"==typeof process.hrtime){var t=process.hrtime(),e=slicedToArray(t,2);return 1e3*e[0]+e[1]/1e6}return Date.now()}function requestFrame(t){return"function"==typeof requestAnimationFrame?window.requestAnimationFrame(t):setTimeout(t,25)}function cancelFrame(t){return"function"==typeof cancelAnimationFrame?cancelAnimationFrame(t):clearTimeout(t)}var CDGPlayer=function(){function t(){var e=this,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=i.contextOptions,r=void 0===n?{}:n,o=i.context,s=void 0===o?this.createContext(r):o,a=i.afterRender;classCallCheck(this,t),this.instructions=[],this.pc=-1,this.frameId=null,this.pos=0,this.lastSyncPos=null,this.lastTimestamp=null,this.update=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:now();if(-1===e.pc)return e;e.frameId=requestFrame(e.update),e.lastSyncPos?e.pos=e.lastSyncPos+(t-e.lastTimestamp):(e.pos+=t-e.lastTimestamp,e.lastTimestamp=t);var i=Math.floor(SECTORS_PER_SECOND*PACKETS_PER_SECTOR*(e.pos/1e3))-e.pc;return i>0&&(e.fastForward(i),e.render()),e},this.context=s,this.afterRender=a}return createClass(t,[{key:"createContext",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new CDGContext(t)}},{key:"load",value:function(t){var e=new CDGParser;return this.instructions=e.parseInstructions(t),this.reset(),this}},{key:"reset",value:function(){return this.pc=0,this.pos=0,this.lastSyncPos=null,this.context.reset(),this}},{key:"render",value:function(){return this.context.renderFrame(),this.afterRender&&this.afterRender(this.context),this}},{key:"executeInstruction",value:function(t){return t&&"function"==typeof t.execute&&t.execute(this.context),this}},{key:"step",value:function(){return this.pc>=0&&this.pc<this.instructions.length?(this.executeInstruction(this.instructions[this.pc]),this.pc+=1):(this.pc=-1,this.stop()),this}},{key:"fastForward",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=this.pc+t;this.pc>=0&&this.pc<e;)this.step();return this}},{key:"play",value:function(){return this.frameId||(this.frameId=requestFrame(this.update),this.lastTimestamp=now()),this}},{key:"stop",value:function(){return cancelFrame(this.frameId),this.frameId=null,this.lastSyncPos=null,this}},{key:"sync",value:function(t){return this.lastSyncPos=t,this.lastTimestamp=now(),this}}]),t}(),Deferred=function(){return"undefined"!=typeof Promise&&Promise.defer?Promise.defer():"undefined"!=typeof PromiseUtils&&PromiseUtils.defer?PromiseUtils.defer():(this.resolve=null,this.reject=null,this.promise=new Promise(function(t,e){this.resolve=t,this.reject=e}.bind(this)),void Object.freeze(this))},getDataFile=function(t){var e=new Deferred;return JSZipUtils.getBinaryContent(t,function(i,n){i?e.reject(new Error("There was an error retrieving "+t,i)):e.resolve(n)}),e.promise},loadZipBuffer=function(t){return JSZip.loadAsync(t).catch(function(t){return Promise.reject(new Error("There was an error reading the zip file.",t))})},loadAudio=function(t){return t.async("arraybuffer").catch(function(){return Promise.reject(new Error("Unable to load the audio file"))})},getFallbackTagData=function(t){var e=t.split(" - "),i={tags:{}};return i.tags.album=e[0].trim(),i.tags.artist=e[1]?e[1].trim():i.tags.album,i.tags.title=e[2]?e[2].trim():i.tags.artist,i},getTagData=function(t){return t.async("blob").then(function(e){return new Promise(function(i){new jsmediatags.Reader(e).setTagsToRead(["title","artist","album","track","year","genre","picture"]).read({onSuccess:function(t){return i(t)},onError:function(){return i(getFallbackTagData(t.name))}})})}).catch(function(){return Promise.reject(new Error("Unable to parse tag data"))})},loadVideo=function(t){return t.async("uint8array").catch(function(){return Promise.reject(new Error("Unable to load the video file"))})},getKaraokeFiles=function(t){var e=t.filter(function(t){return t.endsWith(".cdg")||t.endsWith(".mp3")});return 2===e.length?Promise.resolve(e):Promise.reject("The file is not a karaoke .zip file")},processZip=function(t){var e=t.filter(function(t){return t.name.endsWith(".mp3")}),i=t.filter(function(t){return t.name.endsWith(".cdg")}),n=[];if(e.length&&i.length)return n.push(loadAudio(e[0])),n.push(loadVideo(i[0])),n.push(getTagData(e[0])),Promise.all(n).catch(function(){return Promise.reject(new Error("Processing audio and video failed"))});var r=[];return e.length||r.push("No mp3 audio file present."),i.length||r.push("No cdg video file present."),Promise.reject(new Error(r.join(" ")))},CDGFileLoader=function(){function t(){classCallCheck(this,t)}return createClass(t,null,[{key:"loadZipFile",value:function(t){return getDataFile(t).then(function(t){return loadZipBuffer(t)}).then(function(t){return getKaraokeFiles(t)}).then(function(t){return processZip(t)}).catch(function(t){return Promise.reject(t)})}},{key:"loadFileBuffer",value:function(t){return loadZipBuffer(t).then(function(t){return getKaraokeFiles(t)}).then(function(t){return processZip(t)}).catch(function(t){return Promise.reject(t)})}}]),t}(),classCallCheck$1=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass$1=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),get$1=function t(e,i,n){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,i);if(void 0===r){var o=Object.getPrototypeOf(e);return null===o?void 0:t(o,i,n)}if("value"in r)return r.value;var s=r.get;return void 0!==s?s.call(n):void 0},inherits$1=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+(void 0===e?"undefined":_typeof(e)));t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},possibleConstructorReturn$1=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!==(void 0===e?"undefined":_typeof(e))&&"function"!=typeof e?t:e},FifoSampleBuffer=function(){function t(){classCallCheck$1(this,t),this._vector=new Float32Array,this._position=0,this._frameCount=0}return createClass$1(t,[{key:"clear",value:function(){this.receive(this._frameCount),this.rewind()}},{key:"put",value:function(t){this._frameCount+=t}},{key:"putSamples",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=2*(e=e||0);i>=0||(i=(t.length-n)/2);var r=2*i;this.ensureCapacity(i+this._frameCount);var o=this.endIndex;this.vector.set(t.subarray(n,n+r),o),this._frameCount+=i}},{key:"putBuffer",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;e=e||0,i>=0||(i=t.frameCount-e),this.putSamples(t.vector,t.position+e,i)}},{key:"receive",value:function(t){t>=0&&!(t>this._frameCount)||(t=this.frameCount),this._frameCount-=t,this._position+=t}},{key:"receiveSamples",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=2*e,n=this.startIndex;t.set(this._vector.subarray(n,n+i)),this.receive(e)}},{key:"extract",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=this.startIndex+2*e,r=2*i;t.set(this._vector.subarray(n,n+r))}},{key:"ensureCapacity",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=parseInt(2*t);if(this._vector.length<e){var i=new Float32Array(e);i.set(this._vector.subarray(this.startIndex,this.endIndex)),this._vector=i,this._position=0}else this.rewind()}},{key:"ensureAdditionalCapacity",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.ensureCapacity(this._frameCount+t)}},{key:"rewind",value:function(){this._position>0&&(this._vector.set(this._vector.subarray(this.startIndex,this.endIndex)),this._position=0)}},{key:"vector",get:function(){return this._vector}},{key:"position",get:function(){return this._position}},{key:"startIndex",get:function(){return 2*this._position}},{key:"frameCount",get:function(){return this._frameCount}},{key:"endIndex",get:function(){return 2*(this._position+this._frameCount)}}]),t}(),AbstractFifoSamplePipe=function(){function t(e){classCallCheck$1(this,t),e?(this._inputBuffer=new FifoSampleBuffer,this._outputBuffer=new FifoSampleBuffer):this._inputBuffer=this._outputBuffer=null}return createClass$1(t,[{key:"clear",value:function(){this._inputBuffer.clear(),this._outputBuffer.clear()}},{key:"inputBuffer",get:function(){return this._inputBuffer},set:function(t){this._inputBuffer=t}},{key:"outputBuffer",get:function(){return this._outputBuffer},set:function(t){this._outputBuffer=t}}]),t}(),RateTransposer=function(t){function e(t){classCallCheck$1(this,e);var i=possibleConstructorReturn$1(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.reset(),i._rate=1,i}return inherits$1(e,AbstractFifoSamplePipe),createClass$1(e,[{key:"reset",value:function(){this.slopeCount=0,this.prevSampleL=0,this.prevSampleR=0}},{key:"clone",value:function(){var t=new e;return t.rate=this._rate,t}},{key:"process",value:function(){var t=this._inputBuffer.frameCount;this._outputBuffer.ensureAdditionalCapacity(t/this._rate+1);var e=this.transpose(t);this._inputBuffer.receive(),this._outputBuffer.put(e)}},{key:"transpose",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(0===t)return 0;for(var e=this._inputBuffer.vector,i=this._inputBuffer.startIndex,n=this._outputBuffer.vector,r=this._outputBuffer.endIndex,o=0,s=0;this.slopeCount<1;)n[r+2*s]=(1-this.slopeCount)*this.prevSampleL+this.slopeCount*e[i],n[r+2*s+1]=(1-this.slopeCount)*this.prevSampleR+this.slopeCount*e[i+1],s+=1,this.slopeCount+=this._rate;if(this.slopeCount-=1,1!==t)t:for(;;){for(;this.slopeCount>1;)if(this.slopeCount-=1,(o+=1)>=t-1)break t;var a=i+2*o;n[r+2*s]=(1-this.slopeCount)*e[a]+this.slopeCount*e[a+2],n[r+2*s+1]=(1-this.slopeCount)*e[a+1]+this.slopeCount*e[a+3],s+=1,this.slopeCount+=this._rate}return this.prevSampleL=e[i+2*t-2],this.prevSampleR=e[i+2*t-1],s}},{key:"rate",set:function(t){this._rate=t}}]),e}(),FilterSupport=function(){function t(e){classCallCheck$1(this,t),this._pipe=e}return createClass$1(t,[{key:"fillInputBuffer",value:function(){throw new Error("fillInputBuffer() not overridden")}},{key:"fillOutputBuffer",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.outputBuffer.frameCount<t;){var e=16384-this.inputBuffer.frameCount;if(this.fillInputBuffer(e),this.inputBuffer.frameCount<16384)break;this._pipe.process()}}},{key:"clear",value:function(){this._pipe.clear()}},{key:"pipe",get:function(){return this._pipe}},{key:"inputBuffer",get:function(){return this._pipe.inputBuffer}},{key:"outputBuffer",get:function(){return this._pipe.outputBuffer}}]),t}(),noop=function(){},SimpleFilter=function(t){function e(t,i){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:noop;classCallCheck$1(this,e);var r=possibleConstructorReturn$1(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,i));return r.callback=n,r.sourceSound=t,r.historyBufferSize=22050,r._sourcePosition=0,r.outputBufferPosition=0,r._position=0,r}return inherits$1(e,FilterSupport),createClass$1(e,[{key:"onEnd",value:function(){this.callback()}},{key:"fillInputBuffer",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=new Float32Array(2*t),i=this.sourceSound.extract(e,t,this._sourcePosition);this._sourcePosition+=i,this.inputBuffer.putSamples(e,0,i)}},{key:"extract",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;this.fillOutputBuffer(this.outputBufferPosition+e);var i=Math.min(e,this.outputBuffer.frameCount-this.outputBufferPosition);this.outputBuffer.extract(t,this.outputBufferPosition,i);var n=this.outputBufferPosition+i;return this.outputBufferPosition=Math.min(this.historyBufferSize,n),this.outputBuffer.receive(Math.max(n-this.historyBufferSize,0)),this._position+=i,i}},{key:"handleSampleData",value:function(t){this.extract(t.data,4096)}},{key:"clear",value:function(){get$1(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"clear",this).call(this),this.outputBufferPosition=0}},{key:"position",get:function(){return this._position},set:function(t){if(t>this._position)throw new RangeError("New position may not be greater than current position");var e=this.outputBufferPosition-(this._position-t);if(e<0)throw new RangeError("New position falls outside of history buffer");this.outputBufferPosition=e,this._position=t}},{key:"sourcePosition",get:function(){return this._sourcePosition},set:function(t){this.clear(),this._sourcePosition=t}}]),e}(),USE_AUTO_SEQUENCE_LEN=0,DEFAULT_SEQUENCE_MS=USE_AUTO_SEQUENCE_LEN,USE_AUTO_SEEKWINDOW_LEN=0,DEFAULT_SEEKWINDOW_MS=USE_AUTO_SEEKWINDOW_LEN,DEFAULT_OVERLAP_MS=8,_SCAN_OFFSETS=[[124,186,248,310,372,434,496,558,620,682,744,806,868,930,992,1054,1116,1178,1240,1302,1364,1426,1488,0],[-100,-75,-50,-25,25,50,75,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[-20,-15,-10,-5,5,10,15,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[-4,-3,-2,-1,1,2,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]],AUTOSEQ_TEMPO_LOW=.5,AUTOSEQ_TEMPO_TOP=2,AUTOSEQ_AT_MIN=125,AUTOSEQ_AT_MAX=50,AUTOSEQ_K=(AUTOSEQ_AT_MAX-AUTOSEQ_AT_MIN)/(AUTOSEQ_TEMPO_TOP-AUTOSEQ_TEMPO_LOW),AUTOSEQ_C=AUTOSEQ_AT_MIN-AUTOSEQ_K*AUTOSEQ_TEMPO_LOW,AUTOSEEK_AT_MIN=25,AUTOSEEK_AT_MAX=15,AUTOSEEK_K=(AUTOSEEK_AT_MAX-AUTOSEEK_AT_MIN)/(AUTOSEQ_TEMPO_TOP-AUTOSEQ_TEMPO_LOW),AUTOSEEK_C=AUTOSEEK_AT_MIN-AUTOSEEK_K*AUTOSEQ_TEMPO_LOW,Stretch=function(t){function e(t){classCallCheck$1(this,e);var i=possibleConstructorReturn$1(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i._quickSeek=!0,i.midBufferDirty=!1,i.midBuffer=null,i.overlapLength=0,i.autoSeqSetting=!0,i.autoSeekSetting=!0,i._tempo=1,i.setParameters(44100,DEFAULT_SEQUENCE_MS,DEFAULT_SEEKWINDOW_MS,DEFAULT_OVERLAP_MS),i}return inherits$1(e,AbstractFifoSamplePipe),createClass$1(e,[{key:"clear",value:function(){get$1(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"clear",this).call(this),this.clearMidBuffer()}},{key:"clearMidBuffer",value:function(){this.midBufferDirty&&(this.midBufferDirty=!1,this.midBuffer=null)}},{key:"setParameters",value:function(t,e,i,n){t>0&&(this.sampleRate=t),n>0&&(this.overlapMs=n),e>0?(this.sequenceMs=e,this.autoSeqSetting=!1):this.autoSeqSetting=!0,i>0?(this.seekWindowMs=i,this.autoSeekSetting=!1):this.autoSeekSetting=!0,this.calculateSequenceParameters(),this.calculateOverlapLength(this.overlapMs),this.tempo=this._tempo}},{key:"calculateOverlapLength",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=void 0;e=(e=this.sampleRate*t/1e3)<16?16:e,e-=e%8,this.overlapLength=e,this.refMidBuffer=new Float32Array(2*this.overlapLength),this.midBuffer=new Float32Array(2*this.overlapLength)}},{key:"checkLimits",value:function(t,e,i){return t<e?e:t>i?i:t}},{key:"calculateSequenceParameters",value:function(){var t=void 0,e=void 0;this.autoSeqSetting&&(t=AUTOSEQ_C+AUTOSEQ_K*this._tempo,t=this.checkLimits(t,AUTOSEQ_AT_MAX,AUTOSEQ_AT_MIN),this.sequenceMs=Math.floor(t+.5)),this.autoSeekSetting&&(e=AUTOSEEK_C+AUTOSEEK_K*this._tempo,e=this.checkLimits(e,AUTOSEEK_AT_MAX,AUTOSEEK_AT_MIN),this.seekWindowMs=Math.floor(e+.5)),this.seekWindowLength=Math.floor(this.sampleRate*this.sequenceMs/1e3),this.seekLength=Math.floor(this.sampleRate*this.seekWindowMs/1e3)}},{key:"clone",value:function(){var t=new e;return t.tempo=this._tempo,t.setParameters(this.sampleRate,this.sequenceMs,this.seekWindowMs,this.overlapMs),t}},{key:"seekBestOverlapPosition",value:function(){return this._quickSeek?this.seekBestOverlapPositionStereoQuick():this.seekBestOverlapPositionStereo()}},{key:"seekBestOverlapPositionStereo",value:function(){var t=void 0,e=void 0,i=void 0,n=0;for(this.preCalculateCorrelationReferenceStereo(),t=0,e=Number.MIN_VALUE;n<this.seekLength;n+=1)(i=this.calculateCrossCorrelationStereo(2*n,this.refMidBuffer))>e&&(e=i,t=n);return t}},{key:"seekBestOverlapPositionStereoQuick",value:function(){var t=void 0,e=void 0,i=void 0,n=0,r=void 0,o=void 0;for(this.preCalculateCorrelationReferenceStereo(),e=Number.MIN_VALUE,t=0,r=0,o=0;n<4;n+=1){for(var s=0;_SCAN_OFFSETS[n][s]&&!((o=r+_SCAN_OFFSETS[n][s])>=this.seekLength);)(i=this.calculateCrossCorrelationStereo(2*o,this.refMidBuffer))>e&&(e=i,t=o),s+=1;r=t}return t}},{key:"preCalculateCorrelationReferenceStereo",value:function(){for(var t=0,e=void 0,i=void 0;t<this.overlapLength;t+=1)i=t*(this.overlapLength-t),e=2*t,this.refMidBuffer[e]=this.midBuffer[e]*i,this.refMidBuffer[e+1]=this.midBuffer[e+1]*i}},{key:"calculateCrossCorrelationStereo",value:function(t,e){var i=this._inputBuffer.vector;t+=this._inputBuffer.startIndex;for(var n=0,r=2,o=2*this.overlapLength,s=void 0;r<o;r+=2)n+=i[s=r+t]*e[r]+i[s+1]*e[r+1];return n}},{key:"overlap",value:function(t){this.overlapStereo(2*t)}},{key:"overlapStereo",value:function(t){var e=this._inputBuffer.vector;t+=this._inputBuffer.startIndex;for(var i=this._outputBuffer.vector,n=this._outputBuffer.endIndex,r=0,o=void 0,s=void 0,a=1/this.overlapLength,u=void 0,c=void 0,l=void 0;r<this.overlapLength;r+=1)s=(this.overlapLength-r)*a,u=r*a,c=(o=2*r)+t,i[(l=o+n)+0]=e[c+0]*u+this.midBuffer[o+0]*s,i[l+1]=e[c+1]*u+this.midBuffer[o+1]*s}},{key:"process",value:function(){var t=void 0,e=void 0,i=void 0;if(null===this.midBuffer){if(this._inputBuffer.frameCount<this.overlapLength)return;this.midBuffer=new Float32Array(2*this.overlapLength),this._inputBuffer.receiveSamples(this.midBuffer,this.overlapLength)}for(;this._inputBuffer.frameCount>=this.sampleReq;){t=this.seekBestOverlapPosition(),this._outputBuffer.ensureAdditionalCapacity(this.overlapLength),this.overlap(Math.floor(t)),this._outputBuffer.put(this.overlapLength),(e=this.seekWindowLength-2*this.overlapLength)>0&&this._outputBuffer.putBuffer(this._inputBuffer,t+this.overlapLength,e);var n=this._inputBuffer.startIndex+2*(t+this.seekWindowLength-this.overlapLength);this.midBuffer.set(this._inputBuffer.vector.subarray(n,n+2*this.overlapLength)),this.skipFract+=this.nominalSkip,i=Math.floor(this.skipFract),this.skipFract-=i,this._inputBuffer.receive(i)}}},{key:"tempo",set:function(t){var e;this._tempo=t,this.calculateSequenceParameters(),this.nominalSkip=this._tempo*(this.seekWindowLength-this.overlapLength),this.skipFract=0,e=Math.floor(this.nominalSkip+.5),this.sampleReq=Math.max(e+this.overlapLength,this.seekWindowLength)+this.seekLength},get:function(){return this._tempo}},{key:"inputChunkSize",get:function(){return this.sampleReq}},{key:"outputChunkSize",get:function(){return this.overlapLength+Math.max(0,this.seekWindowLength-2*this.overlapLength)}},{key:"quickSeek",set:function(t){this._quickSeek=t}}]),e}(),testFloatEqual=function(t,e){return(t>e?t-e:e-t)>1e-10},SoundTouch=function(){function t(){classCallCheck$1(this,t),this.transposer=new RateTransposer(!1),this.stretch=new Stretch(!1),this._inputBuffer=new FifoSampleBuffer,this._intermediateBuffer=new FifoSampleBuffer,this._outputBuffer=new FifoSampleBuffer,this._rate=0,this._tempo=0,this.virtualPitch=1,this.virtualRate=1,this.virtualTempo=1,this.calculateEffectiveRateAndTempo()}return createClass$1(t,[{key:"clear",value:function(){this.transposer.clear(),this.stretch.clear()}},{key:"clone",value:function(){var e=new t;return e.rate=this.rate,e.tempo=this.tempo,e}},{key:"calculateEffectiveRateAndTempo",value:function(){var t=this._tempo,e=this._rate;this._tempo=this.virtualTempo/this.virtualPitch,this._rate=this.virtualRate*this.virtualPitch,testFloatEqual(this._tempo,t)&&(this.stretch.tempo=this._tempo),testFloatEqual(this._rate,e)&&(this.transposer.rate=this._rate),this._rate>1?this._outputBuffer!=this.transposer.outputBuffer&&(this.stretch.inputBuffer=this._inputBuffer,this.stretch.outputBuffer=this._intermediateBuffer,this.transposer.inputBuffer=this._intermediateBuffer,this.transposer.outputBuffer=this._outputBuffer):this._outputBuffer!=this.stretch.outputBuffer&&(this.transposer.inputBuffer=this._inputBuffer,this.transposer.outputBuffer=this._intermediateBuffer,this.stretch.inputBuffer=this._intermediateBuffer,this.stretch.outputBuffer=this._outputBuffer)}},{key:"process",value:function(){this._rate>1?(this.stretch.process(),this.transposer.process()):(this.transposer.process(),this.stretch.process())}},{key:"rate",get:function(){return this._rate},set:function(t){this.virtualRate=t,this.calculateEffectiveRateAndTempo()}},{key:"rateChange",set:function(t){this._rate=1+.01*t}},{key:"tempo",get:function(){return this._tempo},set:function(t){this.virtualTempo=t,this.calculateEffectiveRateAndTempo()}},{key:"tempoChange",set:function(t){this.tempo=1+.01*t}},{key:"pitch",set:function(t){this.virtualPitch=t,this.calculateEffectiveRateAndTempo()}},{key:"pitchOctaves",set:function(t){this.pitch=Math.exp(.69314718056*t),this.calculateEffectiveRateAndTempo()}},{key:"pitchSemitones",set:function(t){this.pitchOctaves=t/12}},{key:"inputBuffer",get:function(){return this._inputBuffer}},{key:"outputBuffer",get:function(){return this._outputBuffer}}]),t}(),WebAudioBufferSource=function(){function t(e){classCallCheck$1(this,t),this.buffer=e,this._position=0}return createClass$1(t,[{key:"extract",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;this.position=i;for(var n=this.buffer.getChannelData(0),r=this.dualChannel?this.buffer.getChannelData(1):this.buffer.getChannelData(0),o=0;o<e;o++)t[2*o]=n[o+i],t[2*o+1]=r[o+i];return Math.min(e,n.length-i)}},{key:"dualChannel",get:function(){return this.buffer.numberOfChannels>1}},{key:"position",get:function(){return this._position},set:function(t){this._position=t}}]),t}(),getWebAudioNode=function(t,e,i){var n=i||4096,r=t.createScriptProcessor(n,2,2),o=new Float32Array(2*n);return r.onaudioprocess=function(t){var i=t.outputBuffer.getChannelData(0),r=t.outputBuffer.getChannelData(1),s=e.extract(o,n);0===s&&e.onEnd();for(var a=0;a<s;a++)i[a]=o[2*a],r[a]=o[2*a+1]},r},pad=function(t,e,i){return i=i||"0",(t+="").length>=e?t:new Array(e-t.length+1).join(i)+t},minsSecs=function(t){var e=Math.floor(t/60);return e+":"+pad(parseInt(t-60*e),2)},PitchShifter=function(){function t(e,i,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:noop;classCallCheck$1(this,t),this._soundtouch=new SoundTouch;var o=new WebAudioBufferSource(i);this._filter=new SimpleFilter(o,this._soundtouch,r),this._node=getWebAudioNode(e,this._filter),this.tempo=1,this.rate=1,this.duration=function(){return i.duration},this.sampleRate=function(){return e.sampleRate}}return createClass$1(t,[{key:"connect",value:function(t){this._node.connect(t)}},{key:"disconnect",value:function(){this._node.disconnect()}},{key:"formattedDuration",get:function(){var t=this.duration()||0;return minsSecs(t)}},{key:"formattedTimePlayed",get:function(){return minsSecs(this.timePlayed)}},{key:"timePlayed",get:function(){return this._filter.sourcePosition/this.sampleRate()}},{key:"sourcePosition",get:function(){return this._filter.sourcePosition}},{key:"percentagePlayed",get:function(){var t=this.duration()||0;return 100*this._filter.sourcePosition/(t*this.sampleRate())},set:function(t){var e=this.duration()||0;this._filter.sourcePosition=parseInt(t*e*this.sampleRate())}},{key:"node",get:function(){return this._node}},{key:"pitch",set:function(t){this._soundtouch.pitch=t}},{key:"pitchSemitones",set:function(t){this._soundtouch.pitchSemitones=t}},{key:"rate",set:function(t){this._soundtouch.rate=t}},{key:"tempo",set:function(t){this._soundtouch.tempo=t}}]),t}(),isString=function(t){return"string"==typeof t},PubSub=function(){function t(){classCallCheck(this,t),this.fns={any:[]}}return createClass(t,[{key:"has",value:function(t){return t in this.fns&&this.fns[t].length>0||this.fns.any.length>0}},{key:"on",value:function(t,e){return t in this.fns==!1&&(this.fns[t]=[]),this.fns[t].push(e),e}},{key:"fire",value:function(t,e,i){return this.fns.any.concat(t in this.fns?this.fns[t]:[]).forEach(function(n){return n(e,i,t)}),this}},{key:"off",value:function(t){for(var e in this.fns)for(var i=this.fns[e],n=0;n<i.length;n++)if(i[n]===t)return i.splice(n,1),!0;return!1}},{key:"once",value:function(t,e){var i=this;return this.on(t,function t(n,r,o){e(n,r,o),i.off(t)}),e}}]),t}(),observable=function(t){if(t.on&&t.off)return t;var e=new PubSub,i=new Proxy(t,{get:function(t,n){if(n in t){if(t.constructor===Array){var r=i;"pop"===n?r=t[t.length-1]:"shift"===n&&(r=t[0]),"push"!==n&&"length"!==n&&e.fire(n,r)}return t[n]}return"on"===n?e.on.bind(e):"once"===n?e.once.bind(e):"off"===n?e.off.bind(e):void 0},set:function(t,i,n){return t.constructor===Array?"length"!==i&&e.fire("change",n):e.has(i)&&e.fire(i,n,t[i]),t[i]=n,!0}});return i},createDisplayCanvas=function(t,e){var i=document.createElement("canvas");return i.width=t,i.height=e,i},createCanvasContext=function(t){var e=t.getContext("2d");return e.webkitImageSmoothingEnabled=!1,e.imageSmoothingEnabled=!1,e},copyContextToCanvas=function(t){t.keyColor>=0&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.drawImage(t.canvas,0,0,t.canvas.width,t.canvas.height,0,0,this.canvas.width,this.canvas.height)},clearCanvas=function(t,e){t.clearRect(0,0,e.width,e.height)},loadAudio$1=function(t){var e=this;return this.audio.decodeAudioData(t).then(function(t){e.shifter=new PitchShifter(e.audio,t,1024,function(){e.stop()}),e.shifter.pitch=PITCH_DEFAULT,e.props.trackLength=e.shifter.formattedDuration}).catch(function(t){return Promise.reject(new Error("There was an error decoding the audio file",t))})},loadVideo$1=function(t){var e=new Deferred;return t?(this.player.load(Array.from(t)),e.resolve()):e.reject(new Error("There was an error loading the video file")),e.promise},wrapText=function(t,e,i,n,r,o){for(var s=e.split(" "),a="",u=0;u<s.length;u++){var c=a+s[u]+" ";t.measureText(c).width>r&&u>0?(t.fillText(a.trim(),i,n),a=s[u]+" ",n+=o):a=c}t.fillText(a.trim(),i,n)},drawTag=function(){var t=this.ctx,e=this.canvas,i=e.width-10,n=i/2,r=30;t.font="30px sans-serif",t.fillStyle="#fff",t.textAlign="center",wrapText(t,this.tag.title,n,r,i,30),t.font="20px sans-serif",r=e.height-60,wrapText(t,"by "+this.tag.artist,n,r,i,30)},loadTag=function(t){return console.log("TAG: ",t),this.tag=t.tags,drawTag.call(this)},handleExtractedZip=function(t){var e=this,i=[];return i.push(loadAudio$1.call(this,t[0])),i.push(loadVideo$1.call(this,t[1])),i.push(loadTag.call(this,t[2])),Promise.all(i).then(function(){e.props.status="File Loaded",e.props.loaded=!0}).catch(function(t){return e.props.status="File Loading Failed",Promise.reject(t)}).then(function(){e.props.loading=!1})},updatePlayPosition=function(){this.props.timePlayed=this.shifter.formattedTimePlayed,this.props.percentagePlayed=this.shifter.percentagePlayed,this.player.sync(1e3*this.shifter.timePlayed)},KaraokePlayer=function(){function t(e){var i=this;if(classCallCheck(this,t),this.audio=null,this.gainNode=null,this.shifter=null,this.wrapper=null,this.player=null,this.currentSize=SCALE_DEFAULT,this.canvas=null,this.ctx=null,this.props=observable({status:"",loaded:!1,loading:!1,isPlaying:!1,timePlayed:"0:00",trackLength:"0:00",percentagePlayed:0,destroy:!1}),this.wrapper=document.querySelector(e),!this.wrapper)throw new Error('CDGPlayer: and element was not found with the "'+e+'" selector');this.wrapper.classList.add("cdg-video-wrapper"),this.canvas=createDisplayCanvas(WIDTH,HEIGHT),this.canvas.classList.add("cdg-video-player"),this.ctx=createCanvasContext(this.canvas),this.player=new CDGPlayer({afterRender:function(t){return copyContextToCanvas.call(i,t)}}),this.wrapper.appendChild(this.canvas),this.audio=new(window.AudioContext||window.webkitAudioContext),this.gainNode=this.audio.createGain(),this.gainNode.gain.value=GAIN_DEFAULT}return createClass(t,[{key:"destroy",value:function(){this.wrapper.classList.remove("cdg-video-wrapper"),this.stop(),this.gainNode.disconnect(),this.shifter=null,this.gainNode=null,this.audio=null,this.canvas.remove(),this.props.destroy=!0}},{key:"load",value:function(t){var e=this;this.stop(),clearCanvas(this.ctx,this.canvas),this.props.loading=!0;var i=void 0;if(isString(t)){if(!t.toLowerCase().endsWith(".zip"))return this.props.loading=!1,this.props.status=t+' doesn\'t appear to be a ".zip" file.',Promise.reject(this.props.status);this.props.status="Retrieving File...",i=CDGFileLoader.loadZipFile(t)}else this.props.status="Loading File...",i=CDGFileLoader.loadFileBuffer(t);return i.then(function(t){return handleExtractedZip.call(e,t)}).catch(function(t){return Promise.reject(t)})}},{key:"togglePlay",value:function(){this.props.isPlaying?this.pause():this.start()}},{key:"start",value:function(){var t=this;clearCanvas.call(this,this.ctx,this.canvas),this.shifter.connect(this.gainNode),this.gainNode.connect(this.audio.destination),this.props.isPlaying=!0,this.player.play(),this.timeInterval=setInterval(function(){return updatePlayPosition.call(t)},20)}},{key:"pause",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.props.isPlaying=t,this.shifter.disconnect(),this.timeInterval&&(clearInterval(this.timeInterval),this.timeInterval=null),this.player.stop()}},{key:"stop",value:function(){this.shifter&&(this.pause(),this.changePlayerPosition(0),drawTag.call(this))}},{key:"changePlayerPosition",value:function(t){t=t<0?0:t>100?100:t,this.shifter.percentagePlayed=t,this.props.percentagePlayed=this.shifter.percentagePlayed,this.props.timePlayed=this.shifter.formattedTimePlayed,this.player.reset(),this.props.isPlaying&&updatePlayPosition.call(this)}},{key:"changeKey",value:function(t){t=t<-7?-7:t>7?7:t,this.shifter.pitchSemitones=t,this.shifter.tempo=1}},{key:"volume",value:function(t){var e=+(this.gainNode.gain.value+t).toFixed(2);this.gainNode.gain.value=e>=0?e:0}},{key:"toggleMute",value:function(){var t=this.gainNode.gain.value;this.gainNode.gain.value=t?0:this.fallbackVolume,this.fallbackVolume=t}}]),t}(),ctrlTemplate='<cdg-controls> <button class="playButton" disabled><i class="icofont-play-alt-1"></i></button> <span class="timePlayed"></span> <div class="progress-container"> <progress class="progressMeter" ng-disabled="$ctrls.loading" value="0" max="100"></progress> </div> <span class="trackLength"></span> <span> <input type="number" class="pitch" step="1" min="-7" max="7" value="0" disabled> </span> </cdg-controls>',css$1='@font-face{font-family:IcoFont;font-weight:400;font-style:normal;src:url("data:application/font-woff2;base64,d09GMgABAAAAAANAAAsAAAAABtwAAALxAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHFQGVgCCfgqCHIIeATYCJAMMCwgABCAFhAoHPBsRBhHVk6NkXxaYh0PxNxTNnhifG8s2BnhaP6LjV+5CR+g+Lczng+Cp3+/17N0QkULiKmBUgDKq6DodH5K/LiT8W53aS+hkQHphxR/dg5OS1unLU+KeBQA45La0a4SJ849uHr5C2ttTc+Brm9pegBsw+oDb4CUEdn2Vmg6ck1cE9QKwrKTj6Xp/44HaIorwwvhh7CbKg7gFAVzIohhTWd3Yicfi2IllQrAD1AvE2bI4NzOGk67CriZbcEJwKJmp+9KRgjlpGAG3+e/FRiUBg70C9mqdrpqk9Pj9cW23KP0q8HQ8B4CWhgJp69FId6mpFQ1DaSguTsiOOFjXKIHjlsExylrtHx4YBMQBkOkGQJIYNnAMs2JxkXPGZQqAA7eQ1g1cASDz6ztAgw30fNc2RLeVb1fxS9m9s4PW3XrFd+LrIk8KP/fx+lL0wquPp26KJcKLLYV3DMWlbi0wWLCbv6s6/9z6BcYr/eaTrES1pqKqfBOPMMwmX1Wm03MrJFsLt/FG2cL/c7n4slXfa/WXpNhPs5G8nVr3YhOOJ+02t8HN1g6RFe3Xg4rV8vLVig0vRGe9V8s3Krzkku07gZBBYDat1SfiGAUsUKj1VwIW5RLhHxzG2+hmP+LJjar7BLDr257IaM9ulw5OGHBYbzwB3bcMKM/ligLNs2oYmigQLUr6HQQM4AK9YAGwePG3v01wvDODwVHm3p/FEY8YsEP8Sfa4EkZywJFEkgupZMx3xZc+FLFzRvBgUQAMchJQ5Dpghzwl2RPAO5IDHnwnudDNv3VdSRDuMYymNZqeOB+SuXU0QuewaV90fjUaqrzMXdChRscIJ+B/8OdcEwkQzigYYD+U0oB1ZsOR8oXINkUhyr6Qj0YFw2hao+mJ8yGZW8sRUSFV+kXnV70/qPKyHuhEug0tI5zW4X/w51wTCUkgpJhRsIpxKKUBWz5uw5HypUfANgWsJtqK8tkl6m01AC6AS1SMqNjhsirZP2OSsiq17PAYBAAAAA==") format("woff2"),url("data:application/font-woff;base64,d09GRgABAAAAAASsAAsAAAAABtwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADsAAABUIIslek9TLzIAAAFEAAAAQwAAAFZCxU4eY21hcAAAAYgAAABUAAABfp998U1nbHlmAAAB3AAAAPEAAAEcMf3mymhlYWQAAALQAAAAMwAAADYSUZ1SaGhlYQAAAwQAAAAcAAAAJAc7A1ZobXR4AAADIAAAAAwAAAAMC7j//2xvY2EAAAMsAAAACAAAAAgARACObWF4cAAAAzQAAAAeAAAAIAEQADluYW1lAAADVAAAASsAAAIKNKI0mnBvc3QAAASAAAAAKwAAADxH3y55eJxjYGRgYOBiMGCwY2BycfMJYeDLSSzJY5BiYGGAAJA8MpsxJzM9kYEDxgPKsYBpDiBmg4gCACY7BUgAeJxjYGR+wTiBgZWBgamKaQ8DA0MPhGZ8wGDIyAQUZWBlZsAKAtJcUxgc3ix9s4w56H8WQxRzMMM0oDAjSA4AJPsNaQB4nO2QsQ2AMAwEz4mhQIxBQcEwVGxIpmOH8HYYg5f+5T/ZjYEJqPIhO9iFETpFLXllSe5suePBn9a78o5U1yUluM38WjP3r5X403DObRh7AZXQD1N4nGNg+v//fx7zC2ZfBgkGDQYGQRFxMXE5RnMxM3MgNDVR12NUV+NjZGdTFZNnFBNhZ2XTYzQVNLFj1NTwcNuaEL/VzUNDy93pUUPy9gka2ozTE/aZ8fH9W8Mlxs8vxhiXFRfp4uzOyOjm5BIZl91TktPAxOTeFhlfZVWqyKnMeYGNWZCHcSGPIDMDAxD9zwK6I5hBhEGBQYeBgVGJnY2dTQDoHDEFkFsE1NXU1ZhF2JTUgPabGYmJMiKzv3SUFDq7uDgXljAKwFjXFPUUgYiRBUIzB4EE/31AVfi3SFxRUZzRDET+O4VgMzAwAAAXDj+xAAAAeJxjYGRgYADidaVdE+P5bb4ycDO/AIowXF+65gaM/v//fxbzC+ZgIJeDgQkkCgCi4A+IAHicY2BkYGAO+p8FJF/8/w8iGYAiKIAZAIvIBZgD6AAAA+j//wPoAAAAAAAAAEQAjnicY2BkYGBgZtAFYhBgAmIuIGRg+A/mMwAADUUBSgAAeJxdkE1qwzAQhZ/zS2MIhdKsStGqXRScn2UOkJBtFoYuHUd2HGzLyEogPUFP0BP0FD1A6bH6bKaLRkLSN2+epJEA3OIbHprmYdjOTeuQh8Jd0li4R74X7sPHg/CA+rPwCC8IhH3c4ZUneL0bKmPkwh3ym3CX/C7cI38I9zHBp/CA+pfwCCF+hH08eY+b2KxM6bY6PeWRzWKTMJIl1LbOTKnmwUyUtS61jZzeq91F1ed04VyiEmsK1Ryi89yoypqjjl1wcK5aTqeJ6EFsCmwQw2DFUcJhC40UJ74rgkXW5hLJ/Y9COi1qqk2sMOcfza48a3rK1hcx0tjTt8OFc40z71lQdXQrDss9BemvEs0acrJC1eaOVGLqAQ7trgpLTNmTK3/QVlD8AsE9WlYAeJxjYGKAAC4G7ICZkYmRmZGFgasgJ7FSNzGnRNeQtSCxtDiVgQEAQLEFywA=") format("woff")}[class*=" icofont-"],[class^=icofont-]{font-family:IcoFont!important;speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;white-space:nowrap;word-wrap:normal;direction:ltr;line-height:1;-webkit-font-feature-settings:"liga";-webkit-font-smoothing:antialiased}.icofont-play-alt-1:before{content:"\\eca6"}.icofont-pause:before{content:"\\eca5"}.icofont-md,cdg-controls .playButton>i{font-size:1.25em}.icofont-fw,cdg-controls .playButton>i{text-align:center;width:1.25em}cdg-controls{position:relative;display:-ms-flexbox;display:-webkit-flex;display:-webkit-box;display:flex;height:40px;-webkit-flex-direction:row;-ms-flex-direction:row;-webkit-box-orient:horizontal;-webkit-box-direction:normal;flex-direction:row;-webkit-flex-wrap:nowrap;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;width:100%;font-size:1.25em}cdg-controls>button,cdg-controls>div,cdg-controls>span{margin:3px 5px}cdg-controls>button:first-child,cdg-controls>div:first-child,cdg-controls>span:first-child{margin-left:0}cdg-controls>button:last-child,cdg-controls>div:last-child,cdg-controls>span:last-child{margin-right:0}cdg-controls .playButton{padding:5px;width:34px;height:34px}cdg-controls .playButton[disabled]{cursor:not-allowed}cdg-controls .pitch{height:28px;font-size:.8em;text-align:right}cdg-controls .pitch[disabled]{cursor:not-allowed}cdg-controls .progress-container{position:relative;-webkit-box-flex:0;-webkit-flex:0 1 auto;-ms-flex:0 1 auto;flex:0 1 auto;width:100%;display:inline-block}cdg-controls .progress-container progress{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:100%;height:1em}cdg-controls .progress-container progress::-webkit-progress-bar{background-color:#eee;border-radius:.5em;-webkit-box-shadow:0 2px 5px rgba(0,0,0,.25) inset;box-shadow:inset 0 2px 5px rgba(0,0,0,.25)}cdg-controls .progress-container progress::-webkit-progress-value{background-image:-webkit-linear-gradient(-45deg,transparent 33%,transparent 0,rgba(0,0,0,.1) 66%,transparent 0),-webkit-linear-gradient(top,hsla(0,0%,100%,.25),rgba(0,0,0,.25)),-webkit-linear-gradient(left,#09c,#f44);border-radius:.5em;-webkit-background-size:35px 20px,100% 100%,100% 100%;background-size:35px 20px,100% 100%,100% 100%}';styleInject(css$1);var playIcon="icofont-play-alt-1",pauseIcon="icofont-pause",htmlToElement=function(t){var e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild},setupListeners=function(){var t=this,e=this.player.props;this.onloaded=e.on("loaded",function(e){e?(t.playBtn.removeAttribute("disabled"),t.pitch.removeAttribute("disabled")):(t.playBtn.setAttribute("disabled","disabled"),t.pitch.setAttribute("disabled","disabled"))}),this.ontimeplayed=e.on("timePlayed",function(e,i){e!==i&&(t.timePlayed.innerHTML=e)}),this.onpercentageplayed=e.on("percentagePlayed",function(e,i){e!==i&&(t.progress.value=e)}),this.ontracklength=e.on("trackLength",function(e,i){e!==i&&(t.trackLength.innerHTML=e)}),this.ondestroy=e.on("destroy",function(e){e&&removeListeners.call(t)}),this.onplay=e.on("isPlaying",function(e){t.playIcn.classList.remove(playIcon,pauseIcon),t.playIcn.classList.add(e?pauseIcon:playIcon)}),this.playBtn.addEventListener("click",function(){return t.player.togglePlay()}),this.progress.addEventListener("click",function(e){return changePosition.call(t,e)}),this.pitch.addEventListener("change",function(){return changeKey.call(t)})},removeListeners=function(){var t=this,e=this.player.props;e.off(this.onloaded),e.off(this.ontimeplayed),e.off(this.onpercentageplayed),e.off(this.ontracklength),e.off(this.ondestroy),this.playBtn.removeEventListener("click",function(){return t.player.togglePlay()}),this.progress.removeEventListener("click",function(e){return changePosition.call(t,e)}),this.pitch.removeEventListener("change",function(){return changeKey.call(t)})},changePosition=function(t){var e=t.target.getBoundingClientRect(),i=(t.pageX-e.x)/t.target.offsetWidth;this.player.changePlayerPosition(i)},changeKey=function(){var t=this.pitch.value;isNaN(t)?this.pitch.value=this.fallbackPitch:(this.fallbackPitch=t<-7?-7:t>7?7:t,this.player.changeKey(this.fallbackPitch))},CDGControls=function t(e,i){classCallCheck(this,t),this.controls=htmlToElement(ctrlTemplate),this.player=null,this.playBtn=null,this.playIcn=null,this.timePlayed=null,this.progress=null,this.trackLength=null,this.pitch=null,document.querySelector(e).appendChild(this.controls),this.player=i;var n=this.player.props;this.playBtn=this.controls.querySelector(".playButton"),this.playIcn=this.playBtn.querySelector("i"),this.timePlayed=this.controls.querySelector(".timePlayed"),this.timePlayed.innerHTML=n.timePlayed,this.progress=this.controls.querySelector(".progressMeter"),this.progress.value=n.percentagePlayed,this.trackLength=this.controls.querySelector(".trackLength"),this.trackLength.innerHTML=n.trackLength,this.pitch=this.controls.querySelector(".pitch"),this.fallbackPitch=0,setupListeners.call(this)};export{KaraokePlayer as CDGPlayer,CDGControls}; | ||
//# sourceMappingURL=cdgplayer.js.map |
{ | ||
"name": "cdgplayer", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A browser based HTML5/JS karaoke 'Player', that takes a zip file containing an mp3 and cdg file, allowing the user to render and play directly in the browser.", | ||
@@ -29,6 +29,2 @@ "main": "dist/cdgplayer.js", | ||
], | ||
"peerDependencies": { | ||
"jszip": "^3.1.5", | ||
"jszip-utils": "0.0.2" | ||
}, | ||
"devDependencies": { | ||
@@ -68,2 +64,3 @@ "@fortawesome/fontawesome-free": "^5.2.0", | ||
"dependencies": { | ||
"jsmediatags": "^3.8.1", | ||
"jszip": "^3.1.5", | ||
@@ -70,0 +67,0 @@ "jszip-utils": "0.0.2" |
@@ -14,4 +14,4 @@ # CDGPlayer | ||
The `CDGPlayer` requires that [JSZip](https://stuk.github.io/jszip/) and [JSZipUtils](https://stuk.github.io/jszip-utils/) | ||
be included in your html. | ||
The `CDGPlayer` requires that [JSZip](https://stuk.github.io/jszip/), [JSZipUtils](https://stuk.github.io/jszip-utils/) | ||
and [jsmediatags](https://github.com/aadsm/jsmediatags) be included in your html. | ||
@@ -21,2 +21,3 @@ ```html | ||
<script type="text/javascript" src="my/assets/jszip-utils.min.js"></script> | ||
<script type="text/javascript" src="my/assets/jsmediatags.min.js"></script> | ||
``` | ||
@@ -23,0 +24,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
237456
3
235
269
+ Addedjsmediatags@^3.8.1
+ Addedjsmediatags@3.9.7(transitive)
+ Addedxhr2@0.1.4(transitive)