osmd-audio-player
Version:
OSMD audio player
15 lines (13 loc) • 114 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).OsmdAudioPlayer=t()}(this,(function(){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function e(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}c((r=r.apply(e,t||[])).next())}))}class t{constructor(){this.steps=[]}[Symbol.iterator](){return this.steps.values()}createStep(e){let t=this.steps.find(t=>t.tick===e);return t||(t={tick:e,notes:[]},this.steps.push(t)),t}addNote(e,t){var n;(null!=(n=this.steps.find(t=>t.tick===e))?n:this.createStep(e)).notes.push(t)}delete(e){const t=this.steps.findIndex(t=>t.tick===e.tick);null!=t&&this.steps.splice(t,1)}sort(){return this.steps.sort((e,t)=>e.tick-t.tick),this}getFirstEmptyTick(){return this.sort().steps.filter(e=>!e.notes.length)[0].tick}}class n{constructor(e,n,r,o){this.stepQueue=new t,this.stepQueueIndex=0,this.scheduledTicks=new Set,this.currentTick=0,this.currentTickTimestamp=0,this.audioContextStartTime=0,this.schedulerIntervalHandle=null,this.scheduleInterval=200,this.schedulePeriod=500,this.tickDenominator=1024,this.lastTickOffset=300,this.playing=!1,this.noteSchedulingCallback=o,this.denominator=e,this.wholeNoteLength=n,this.audioContext=r}get schedulePeriodTicks(){return this.schedulePeriod/this.tickDuration}get audioContextTime(){return this.audioContext?1e3*(this.audioContext.currentTime-this.audioContextStartTime):0}get tickDuration(){return this.wholeNoteLength/this.tickDenominator}get calculatedTick(){return this.currentTick+Math.round((this.audioContextTime-this.currentTickTimestamp)/this.tickDuration)}start(){this.playing=!0,this.stepQueue.sort(),this.audioContextStartTime=this.audioContext.currentTime,this.currentTickTimestamp=this.audioContextTime,this.schedulerIntervalHandle||(this.schedulerIntervalHandle=window.setInterval(()=>this.scheduleIterationStep(),this.scheduleInterval))}setIterationStep(e){e=Math.min(this.stepQueue.steps.length-1,e),this.stepQueueIndex=e,this.currentTick=this.stepQueue.steps[this.stepQueueIndex].tick}pause(){this.playing=!1}resume(){this.playing=!0,this.currentTickTimestamp=this.audioContextTime}reset(){this.playing=!1,this.currentTick=0,this.currentTickTimestamp=0,this.stepQueueIndex=0,clearInterval(this.scheduleInterval),this.schedulerIntervalHandle=null}loadNotes(e){let t=this.lastTickOffset;this.stepQueue.steps.length>0&&(t=this.stepQueue.getFirstEmptyTick());for(let n of e)if(!n.IsGrace)for(let e of n.Notes)this.stepQueue.addNote(t,e),this.stepQueue.createStep(t+e.Length.RealValue*this.tickDenominator)}scheduleIterationStep(){var e,t;if(!this.playing)return;this.currentTick=this.calculatedTick,this.currentTickTimestamp=this.audioContextTime;let n=null===(e=this.stepQueue.steps[this.stepQueueIndex])||void 0===e?void 0:e.tick;for(;this.nextTickAvailableAndWithinSchedulePeriod(n);){let e=this.stepQueue.steps[this.stepQueueIndex],r=(e.tick-this.currentTick)*this.tickDuration;r<0&&(r=0),this.scheduledTicks.add(e.tick),this.noteSchedulingCallback(r/1e3,e.notes),this.stepQueueIndex++,n=null===(t=this.stepQueue.steps[this.stepQueueIndex])||void 0===t?void 0:t.tick}for(let e of this.scheduledTicks)e<=this.currentTick&&this.scheduledTicks.delete(e)}nextTickAvailableAndWithinSchedulePeriod(e){return e&&this.currentTickTimestamp+(e-this.currentTick)*this.tickDuration<=this.currentTickTimestamp+this.schedulePeriod}}var r;!function(e){e[e.None=0]="None",e[e.Staccato=1]="Staccato",e[e.Legato=2]="Legato"}(r||(r={}));const o=[[0,"Acoustic Grand Piano"],[1,"Bright Acoustic Piano"],[2,"Electric Grand Piano"],[3,"Honky-tonk Piano"],[4,"Electric Piano 1"],[5,"Electric Piano 2"],[6,"Harpsichord"],[7,"Clavi"],[8,"Celesta"],[9,"Glockenspiel"],[10,"Music Box"],[11,"Vibraphone"],[12,"Marimba"],[13,"Xylophone"],[14,"Tubular Bells"],[15,"Dulcimer"],[16,"Drawbar Organ"],[17,"Percussive Organ"],[18,"Rock Organ"],[19,"Church Organ"],[20,"Reed Organ"],[21,"Accordion"],[22,"Harmonica"],[23,"Tango Accordion"],[24,"Acoustic Guitar (nylon)"],[25,"Acoustic Guitar (steel)"],[26,"Electric Guitar (jazz)"],[27,"Electric Guitar (clean)"],[28,"Electric Guitar (muted)"],[29,"Overdriven Guitar"],[30,"Distortion Guitar"],[31,"Guitar harmonics"],[32,"Acoustic Bass"],[33,"Electric Bass (finger)"],[34,"Electric Bass (pick)"],[35,"Fretless Bass"],[36,"Slap Bass 1"],[37,"Slap Bass 2"],[38,"Synth Bass 1"],[39,"Synth Bass 2"],[40,"Violin"],[41,"Viola"],[42,"Cello"],[43,"Contrabass"],[44,"Tremolo Strings"],[45,"Pizzicato Strings"],[46,"Orchestral Harp"],[47,"Timpani"],[48,"String Ensemble 1"],[49,"String Ensemble 2"],[50,"SynthStrings 1"],[51,"SynthStrings 2"],[52,"Choir Aahs"],[53,"Voice Oohs"],[54,"Synth Choir"],[55,"Orchestra Hit"],[56,"Trumpet"],[57,"Trombone"],[58,"Tuba"],[59,"Muted Trumpet"],[60,"French Horn"],[61,"Brass Section"],[62,"SynthBrass 1"],[63,"SynthBrass 2"],[64,"Soprano Sax"],[65,"Alto Sax"],[66,"Tenor Sax"],[67,"Baritone Sax"],[68,"Oboe"],[69,"English Horn"],[70,"Bassoon"],[71,"Clarinet"],[72,"Piccolo"],[73,"Flute"],[74,"Recorder"],[75,"Pan Flute"],[76,"Blown Bottle"],[77,"Shakuhachi"],[78,"Whistle"],[79,"Ocarina"],[80,"Lead 1 (square)"],[81,"Lead 2 (sawtooth)"],[82,"Lead 3 (calliope)"],[83,"Lead 4 (chiff)"],[84,"Lead 5 (charang)"],[85,"Lead 6 (voice)"],[86,"Lead 7 (fifths)"],[87,"Lead 8 (bass + lead)"],[88,"Pad 1 (new age)"],[89,"Pad 2 (warm)"],[90,"Pad 3 (polysynth)"],[91,"Pad 4 (choir)"],[92,"Pad 5 (bowed)"],[93,"Pad 6 (metallic)"],[94,"Pad 7 (halo)"],[95,"Pad 8 (sweep)"],[96,"FX 1 (rain)"],[97,"FX 2 (soundtrack)"],[98,"FX 3 (crystal)"],[99,"FX 4 (atmosphere)"],[100,"FX 5 (brightness)"],[101,"FX 6 (goblins)"],[102,"FX 7 (echoes)"],[103,"FX 8 (sci-fi)"],[104,"Sitar"],[105,"Banjo"],[106,"Shamisen"],[107,"Koto"],[108,"Kalimba"],[109,"Bag pipe"],[110,"Fiddle"],[111,"Shanai"],[112,"Tinkle Bell"],[113,"Agogo"],[114,"Steel Drums"],[115,"Woodblock"],[116,"Taiko Drum"],[117,"Melodic Tom"],[118,"Synth Drum"],[119,"Reverse Cymbal"],[120,"Guitar Fret Noise"],[121,"Breath Noise"],[122,"Seashore"],[123,"Bird Tweet"],[124,"Telephone Ring"],[125,"Helicopter"],[126,"Applause"],[127,"Gunshot"]];var a=["accordion","acoustic_bass","acoustic_grand_piano","acoustic_guitar_nylon","acoustic_guitar_steel","agogo","alto_sax","applause","bagpipe","banjo","baritone_sax","bassoon","bird_tweet","blown_bottle","brass_section","breath_noise","bright_acoustic_piano","celesta","cello","choir_aahs","church_organ","clarinet","clavinet","contrabass","distortion_guitar","drawbar_organ","dulcimer","electric_bass_finger","electric_bass_pick","electric_grand_piano","electric_guitar_clean","electric_guitar_jazz","electric_guitar_muted","electric_piano_1","electric_piano_2","english_horn","fiddle","flute","french_horn","fretless_bass","fx_1_rain","fx_2_soundtrack","fx_3_crystal","fx_4_atmosphere","fx_5_brightness","fx_6_goblins","fx_7_echoes","fx_8_scifi","glockenspiel","guitar_fret_noise","guitar_harmonics","gunshot","harmonica","harpsichord","helicopter","honkytonk_piano","kalimba","koto","lead_1_square","lead_2_sawtooth","lead_3_calliope","lead_4_chiff","lead_5_charang","lead_6_voice","lead_7_fifths","lead_8_bass__lead","marimba","melodic_tom","music_box","muted_trumpet","oboe","ocarina","orchestra_hit","orchestral_harp","overdriven_guitar","pad_1_new_age","pad_2_warm","pad_3_polysynth","pad_4_choir","pad_5_bowed","pad_6_metallic","pad_7_halo","pad_8_sweep","pan_flute","percussive_organ","piccolo","pizzicato_strings","recorder","reed_organ","reverse_cymbal","rock_organ","seashore","shakuhachi","shamisen","shanai","sitar","slap_bass_1","slap_bass_2","soprano_sax","steel_drums","string_ensemble_1","string_ensemble_2","synth_bass_1","synth_bass_2","synth_brass_1","synth_brass_2","synth_choir","synth_drum","synth_strings_1","synth_strings_2","taiko_drum","tango_accordion","telephone_ring","tenor_sax","timpani","tinkle_bell","tremolo_strings","trombone","trumpet","tuba","tubular_bells","vibraphone","viola","violin","voice_oohs","whistle","woodblock","xylophone"];"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function i(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return s(null==t&&n.path)}},n.exports),n.exports}function s(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}var c={decode:function(e,t){for(var n,r,o,a=e.replace(/[^A-Za-z0-9\+\/]/g,""),i=a.length,s=t?Math.ceil((3*i+1>>2)/t)*t:3*i+1>>2,c=new Uint8Array(s),u=0,l=0,h=0;h<i;h++)if(r=3&h,u|=((o=a.charCodeAt(h))>64&&o<91?o-65:o>96&&o<123?o-71:o>47&&o<58?o+4:43===o?62:47===o?63:0)<<18-6*r,3===r||i-h==1){for(n=0;n<3&&l<s;n++,l++)c[l]=u>>>(16>>>n&24)&255;u=0}return c}},u=function(e,t){return new Promise((function(n,r){var o=new XMLHttpRequest;t&&(o.responseType=t),o.open("GET",e),o.onload=function(){200===o.status?n(o.response):r(Error(o.statusText))},o.onerror=function(){r(Error("Network Error"))},o.send()}))},l=i((function(e){function t(e){return function(t){return"string"==typeof t&&e.test(t)}}function n(e,t){return"string"==typeof e?e+t:"function"==typeof e?e(t):t}function r(e,t,n,r){var c=t instanceof ArrayBuffer?o:a(t)?i:function(e){return e&&"function"==typeof e.then}(t)?s:l(t)?h:function(e){return e&&"object"==typeof e}(t)?d:f(t)?p:m(t)?v:g(t)?y:null;return c?c(e,t,n||{}):r?Promise.resolve(r):Promise.reject("Source not valid ("+t+")")}function o(e,t,n){return new Promise((function(n,r){e.decodeAudioData(t,(function(e){n(e)}),(function(){r("Can't decode audio data ("+t.slice(0,30)+"...)")}))}))}r.fetch=u;var a=t(/\.(mp3|wav|ogg)(\?.*)?$/i);function i(e,t,o){var a=n(o.from,t);return r(e,r.fetch(a,"arraybuffer"),o)}function s(e,t,n){return t.then((function(t){return r(e,t,n)}))}var l=Array.isArray;function h(e,t,n){return Promise.all(t.map((function(t){return r(e,t,n,t)})))}function d(e,t,n){var o={},a=Object.keys(t).map((function(a){if(n.only&&-1===n.only.indexOf(a))return null;var i=t[a];return r(e,i,n,i).then((function(e){o[a]=e}))}));return Promise.all(a).then((function(){return o}))}var f=t(/\.json(\?.*)?$/i);function p(e,t,o){var a=n(o.from,t);return r(e,r.fetch(a,"text").then(JSON.parse),o)}var m=t(/^data:audio/);function v(e,t,n){var o=t.indexOf(",");return r(e,c.decode(t.slice(o+1)).buffer,n)}var g=t(/\.js(\?.*)?$/i);function y(e,t,o){var a=n(o.from,t);return r(e,r.fetch(a,"text").then(w),o)}function w(e){var t=e.indexOf("MIDI.Soundfont.");if(t<0)throw Error("Invalid MIDI.js Soundfont format");t=e.indexOf("=",t)+2;var n=e.lastIndexOf(",");return JSON.parse(e.slice(t,n)+"}")}e.exports&&(e.exports=r),"undefined"!=typeof window&&(window.loadAudio=r)})),h=function(e){var t=e.createGain(),n=t._voltage=function(e){var t=e.createBufferSource(),n=e.createBuffer(1,2,e.sampleRate);return n.getChannelData(0).set(f),t.buffer=n,t.loop=!0,t}(e),r=p(n),o=p(n),a=p(n);return t._startAmount=p(o),t._endAmount=p(a),t._multiplier=p(r),t._multiplier.connect(t),t._startAmount.connect(t),t._endAmount.connect(t),t.value=r.gain,t.startValue=o.gain,t.endValue=a.gain,t.startValue.value=0,t.endValue.value=0,Object.defineProperties(t,d),t};var d={attack:{value:0,writable:!0},decay:{value:0,writable:!0},sustain:{value:1,writable:!0},release:{value:0,writable:!0},getReleaseDuration:{value:function(){return this.release}},start:{value:function(e){var t=this._multiplier.gain,n=this._startAmount.gain,r=this._endAmount.gain;this._voltage.start(e),this._decayFrom=this._decayFrom=e+this.attack,this._startedAt=e;var o=this.sustain;t.cancelScheduledValues(e),n.cancelScheduledValues(e),r.cancelScheduledValues(e),r.setValueAtTime(0,e),this.attack?(t.setValueAtTime(0,e),t.linearRampToValueAtTime(1,e+this.attack),n.setValueAtTime(1,e),n.linearRampToValueAtTime(0,e+this.attack)):(t.setValueAtTime(1,e),n.setValueAtTime(0,e)),this.decay&&t.setTargetAtTime(o,this._decayFrom,m(this.decay))}},stop:{value:function(e,t){t&&(e-=this.release);var n=e+this.release;if(this.release){var r=this._multiplier.gain,o=this._startAmount.gain,a=this._endAmount.gain;r.cancelScheduledValues(e),o.cancelScheduledValues(e),a.cancelScheduledValues(e);var i=m(this.release);if(this.attack&&e<this._decayFrom){var s=function(e,t,n,r,o){var a=e+(o-n)/(r-n)*(t-e);a<=e&&(a=e);a>=t&&(a=t);return a}(0,1,this._startedAt,this._decayFrom,e);r.linearRampToValueAtTime(s,e),o.linearRampToValueAtTime(1-s,e),o.setTargetAtTime(0,e,i)}a.setTargetAtTime(1,e,i),r.setTargetAtTime(0,e,i)}return this._voltage.stop(n),n}},onended:{get:function(){return this._voltage.onended},set:function(e){this._voltage.onended=e}}},f=new Float32Array([1,1]);function p(e){var t=e.context.createGain();return e.connect(t),t}function m(e){return Math.log(e+1)/Math.log(100)}var v={},g={gain:1,attack:.01,decay:.1,sustain:.9,release:.3,loop:!1,cents:0,loopStart:0,loopEnd:0};function y(e){return"number"==typeof e}var w=["attack","decay","sustain","release"];var _=function(e,t,n){var r=!1,o=0,a={},i=e.createGain();i.gain.value=1;var s=Object.assign({},g,n),c={context:e,out:i,opts:s};return t instanceof AudioBuffer?c.buffer=t:c.buffers=t,c.start=function(t,n,i){if(c.buffer&&null!==t)return c.start(null,t,n);var s=t?c.buffers[t]:c.buffer;if(s){if(r){var l=i||v;n=Math.max(e.currentTime,n||0),c.emit("start",n,t,l);var h=u(t,s,l);return h.id=function(t,n){return n.id=o++,a[n.id]=n,n.source.onended=function(){var t=e.currentTime;n.source.disconnect(),n.env.disconnect(),n.disconnect(),c.emit("ended",t,n.id,n)},n.id}(0,h),h.env.start(n),h.source.start(n),c.emit("started",n,h.id,h),l.duration&&h.stop(n+l.duration),h}console.warn("SamplePlayer not connected to any node.")}else console.warn("Buffer "+t+" not found.")},c.play=function(e,t,n){return c.start(e,t,n)},c.stop=function(e,t){var n;return(t=t||Object.keys(a)).map((function(t){return(n=a[t])?(n.stop(e),n.id):null}))},c.connect=function(e){return r=!0,i.connect(e),c},c.emit=function(e,t,n,r){c.onevent&&c.onevent(e,t,n,r);var o=c["on"+e];o&&o(t,n,r)},c;function u(t,n,r){var o,a=e.createGain();return a.gain.value=0,a.connect(i),a.env=function(e,t,n){var r=h(e),o=t.adsr||n.adsr;return w.forEach((function(e,a){r[e]=o?o[a]:t[e]||n[e]})),r.value.value=y(t.gain)?t.gain:y(n.gain)?n.gain:1,r}(e,r,s),a.env.connect(a.gain),a.source=e.createBufferSource(),a.source.buffer=n,a.source.connect(a),a.source.loop=r.loop||s.loop,a.source.playbackRate.value=(o=r.cents||s.cents)?Math.pow(2,o/1200):1,a.source.loopStart=r.loopStart||s.loopStart,a.source.loopEnd=r.loopEnd||s.loopEnd,a.stop=function(n){var r=n||e.currentTime;c.emit("stop",r,t);var o=a.env.stop(r);a.source.stop(o)},a}};function C(e,t){return function(n,r,o,a){e(n,r,o,a),t(n,r,o,a)}}var b=/^([a-gA-G])(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)\s*$/;var T=[0,2,4,5,7,9,11];function M(e,t,n){if("string"!=typeof e)return null;var r=b.exec(e);if(!r||!t&&r[4])return null;var o={letter:r[1].toUpperCase(),acc:r[2].replace(/x/g,"##")};return o.pc=o.letter+o.acc,o.step=(o.letter.charCodeAt(0)+3)%7,o.alt="b"===o.acc[0]?-o.acc.length:o.acc.length,o.chroma=T[o.step]+o.alt,r[3]&&(o.oct=+r[3],o.midi=o.chroma+12*(o.oct+1),o.freq=I(o.midi,n)),t&&(o.tonicOf=r[4]),o}function I(e,t){return Math.pow(2,(e-69)/12)*(t||440)}var x={parse:M,regex:function(){return b},midiToFreq:I};["letter","acc","pc","step","alt","chroma","oct","midi","freq"].forEach((function(e){x[e]=function(t){var n=M(t);return n&&void 0!==n[e]?n[e]:null}}));var S=x,A=function(e){return function(e){return null!==e&&e!==[]&&e>=0&&e<129}(e)?+e:S.midi(e)},N=function(e){if(e.buffers){var t=e.opts.map,n="function"==typeof t?t:A,r=function(e){return e?n(e)||e:null};e.buffers=function(e,t){return Object.keys(e).reduce((function(n,r){return n[t(r)]=e[r],n}),{})}(e.buffers,r);var o=e.start;e.start=function(e,t,n){var a=r(e),i=a%1;return i&&(a=Math.floor(a),n=Object.assign(n||{},{cents:Math.floor(100*i)})),o(a,t,n)}}return e};var k=Array.isArray,O={},E=i((function(e,t){e.exports=function e(t,n,r){function o(i,c){if(!n[i]){if(!t[i]){if(!c&&s)return s();if(a)return a(i,!0);var u=new Error("Cannot find module '"+i+"'");throw u.code="MODULE_NOT_FOUND",u}var l=n[i]={exports:{}};t[i][0].call(l.exports,(function(e){var n=t[i][1][e];return o(n||e)}),l,l.exports,e,t,n,r)}return n[i].exports}for(var a=s,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e){function t(e){if(this._event=e,this._data=e.data,this.receivedTime=e.receivedTime,this._data&&this._data.length<2)console.warn("Illegal MIDI message of length",this._data.length);else switch(this._messageCode=240&e.data[0],this.channel=15&e.data[0],this._messageCode){case 128:this.messageType="noteoff",this.key=127&e.data[1],this.velocity=127&e.data[2];break;case 144:this.messageType="noteon",this.key=127&e.data[1],this.velocity=127&e.data[2];break;case 160:this.messageType="keypressure",this.key=127&e.data[1],this.pressure=127&e.data[2];break;case 176:this.messageType="controlchange",this.controllerNumber=127&e.data[1],this.controllerValue=127&e.data[2],120===this.controllerNumber&&0===this.controllerValue?this.channelModeMessage="allsoundoff":121===this.controllerNumber?this.channelModeMessage="resetallcontrollers":122===this.controllerNumber?0===this.controllerValue?this.channelModeMessage="localcontroloff":this.channelModeMessage="localcontrolon":123===this.controllerNumber&&0===this.controllerValue?this.channelModeMessage="allnotesoff":124===this.controllerNumber&&0===this.controllerValue?this.channelModeMessage="omnimodeoff":125===this.controllerNumber&&0===this.controllerValue?this.channelModeMessage="omnimodeon":126===this.controllerNumber?this.channelModeMessage="monomodeon":127===this.controllerNumber&&(this.channelModeMessage="polymodeon");break;case 192:this.messageType="programchange",this.program=e.data[1];break;case 208:this.messageType="channelpressure",this.pressure=127&e.data[1];break;case 224:this.messageType="pitchbendchange";var t=127&e.data[2],n=127&e.data[1];this.pitchBend=(t<<8)+n}}return new t(e)},t.exports=n.default},{}]},{},[1])(1)})),P=i((function(e){function t(e,t,n){return function(e){return e.listenToMidi=function(t,n){var r={},o=n||{},a=o.gain||function(e){return e/127};return t.onmidimessage=function(t){var n=t.messageType?t:E(t);if("noteon"===n.messageType&&0===n.velocity&&(n.messageType="noteoff"),!o.channel||n.channel===o.channel)switch(n.messageType){case"noteon":r[n.key]=e.play(n.key,0,{gain:a(n.velocity)});break;case"noteoff":r[n.key]&&(r[n.key].stop(),delete r[n.key])}},e},e}(function(e){return e.schedule=function(t,n){var r,o,a,i,s=e.context.currentTime,c=t<s?s:t;return e.emit("schedule",c,n),n.map((function(t){return t?(k(t)?(r=t[0],o=t[1]):(r=t.time,o=t),function(e){return e&&"object"==typeof e}(o)?(a=o.name||o.key||o.note||o.midi||null,i=o):(a=o,i=O),e.start(a,c+(r||0),i)):null}))},e}(N(function(e){return e.on=function(t,n){if(1===arguments.length&&"function"==typeof t)return e.on("event",t);var r="on"+t,o=e[r];return e[r]=o?C(o,n):n,e},e}(_(e,t,n)))))}e.exports&&(e.exports=t),"undefined"!=typeof window&&(window.SamplePlayer=t)})),D=i((function(e,t){!function(e){function t(e,t){return Array(t+1).join(e)}function n(e){return"number"==typeof e}function r(e){return"string"==typeof e}function o(e){return void 0!==e}function a(e,t){return Math.pow(2,(e-69)/12)*(t||440)}function i(){return _}function s(e,t,n){if("string"!=typeof e)return null;var r=_.exec(e);if(!r||!t&&r[4])return null;var o={letter:r[1].toUpperCase(),acc:r[2].replace(/x/g,"##")};o.pc=o.letter+o.acc,o.step=(o.letter.charCodeAt(0)+3)%7,o.alt="b"===o.acc[0]?-o.acc.length:o.acc.length;var i=C[o.step]+o.alt;return o.chroma=i<0?12+i:i%12,r[3]&&(o.oct=+r[3],o.midi=i+12*(o.oct+1),o.freq=a(o.midi,n)),t&&(o.tonicOf=r[4]),o}function c(e){return n(e)?e<0?t("b",-e):t("#",e):""}function u(e){return n(e)?""+e:""}function l(e,t,n){return null==e?null:e.step?l(e.step,e.alt,e.oct):e<0||e>6?null:b.charAt(e)+c(t)+u(n)}function h(e){if((n(e)||r(e))&&e>=0&&e<128)return+e;var t=s(e);return t&&o(t.midi)?t.midi:null}function d(e,t){var n=h(e);return null===n?null:a(n,t)}function f(e){return(s(e)||{}).letter}function p(e){return(s(e)||{}).acc}function m(e){return(s(e)||{}).pc}function v(e){return(s(e)||{}).step}function g(e){return(s(e)||{}).alt}function y(e){return(s(e)||{}).chroma}function w(e){return(s(e)||{}).oct}var _=/^([a-gA-G])(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)\s*$/,C=[0,2,4,5,7,9,11],b="CDEFGAB";e.regex=i,e.parse=s,e.build=l,e.midi=h,e.freq=d,e.letter=f,e.acc=p,e.pc=m,e.step=v,e.alt=g,e.chroma=y,e.oct=w}(t)}));function R(e,t){if(console.warn("new Soundfont() is deprected"),console.log("Please use Soundfont.instrument() instead of new Soundfont().instrument()"),!(this instanceof R))return new R(e);this.nameToUrl=t||R.nameToUrl,this.ctx=e,this.instruments={},this.promises=[]}function V(e,t){return t=t||{},function(n,r,o,a){console.warn("The oscillator player is deprecated."),console.log("Starting with version 0.9.0 you will have to wait until the soundfont is loaded to play sounds.");var i=n>0&&n<129?+n:D.midi(n),s=i?D.midiToFreq(i,440):null;if(s){o=o||.2;var c=(a=a||{}).destination||t.destination||e.destination,u=a.vcoType||t.vcoType||"sine",l=a.gain||t.gain||.4,h=e.createOscillator();h.type=u,h.frequency.value=s;var d=e.createGain();return d.gain.value=l,h.connect(d),d.connect(c),h.start(r),o>0&&h.stop(r+o),h}}}R.prototype.onready=function(e){console.warn("deprecated API"),console.log("Please use Promise.all(Soundfont.instrument(), Soundfont.instrument()).then() instead of new Soundfont().onready()"),Promise.all(this.promises).then(e)},R.prototype.instrument=function(e,t){console.warn("new Soundfont().instrument() is deprecated."),console.log("Please use Soundfont.instrument() instead.");var n=this.ctx;if((e=e||"default")in this.instruments)return this.instruments[e];var r={name:e,play:V(n,t)};if(this.instruments[e]=r,"default"!==e){var o=R.instrument(n,e,t).then((function(e){return r.play=e.play,r}));this.promises.push(o),r.onready=function(e){console.warn("onready is deprecated. Use Soundfont.instrument().then()"),o.then(e)}}else r.onready=function(e){console.warn("onready is deprecated. Use Soundfont.instrument().then()"),e()};return r},R.loadBuffers=function(e,t,n){return console.warn("Soundfont.loadBuffers is deprecate."),console.log("Use Soundfont.instrument(..) and get buffers properties from the result."),R.instrument(e,t,n).then((function(e){return e.buffers}))},R.noteToMidi=D.midi;var B=R,F=i((function(e){function t(e){return/\.js(\?.*)?$/i.test(e)}function n(e,t,n){return"https://gleitz.github.io/midi-js-soundfonts/"+(t="FluidR3_GM"===t?t:"MusyngKite")+"/"+e+"-"+(n="ogg"===n?n:"mp3")+".js"}B.instrument=function e(r,o,a){if(1===arguments.length)return function(t,n){return e(r,t,n)};var i=a||{},s=i.isSoundfontURL||t,c=i.nameToUrl||n,u=s(o)?o:c(o,i.soundfont,i.format);return l(r,u,{only:i.only||i.notes}).then((function(e){var t=P(r,e,i).connect(i.destination?i.destination:r.destination);return t.url=u,t.name=o,t}))},B.nameToUrl=n,e.exports&&(e.exports=B),"undefined"!=typeof window&&(window.Soundfont=B)}));class L{constructor(){this.players=new Map,this.instruments=o.filter(e=>a.includes(this.getSoundfontInstrumentName(e[1]))).map(e=>({midiId:e[0],name:e[1],loaded:!1}))}init(e){this.audioContext=e}load(t){return e(this,void 0,void 0,(function*(){const e=this.instruments.find(e=>e.midiId===t);if(!e)throw new Error("SoundfontPlayer does not support midi instrument ID "+t);if(this.players.has(t))return;const n=yield F.instrument(this.audioContext,this.getSoundfontInstrumentName(e.name));this.players.set(t,n)}))}stop(e){this.players.has(e)&&this.players.get(e).stop()}schedule(e,t,n){this.verifyPlayerLoaded(e),this.applyDynamics(n),this.players.get(e).schedule(t,n)}applyDynamics(e){for(const t of e)t.articulation===r.Staccato&&(t.gain=Math.max(t.gain+.3,1.3*t.gain),t.duration=Math.min(.4*t.duration,.4))}verifyPlayerLoaded(e){if(!this.players.has(e))throw new Error("No soundfont player loaded for midi instrument "+e)}getSoundfontInstrumentName(e){return e.toLowerCase().replace(/\s+/g,"_")}}function W(e){return e.ParentVoiceEntry.isStaccato()?r.Staccato:r.None}function j(e,t){let n=e.Length.RealValue*t;return e.NoteTie&&(Object.is(e.NoteTie.StartNote,e)&&e.NoteTie.Notes[1]?n+=e.NoteTie.Notes[1].Length.RealValue*t:n=0),n}function G(e){return e.ParentVoiceEntry.ParentVoice.Volume}class X{constructor(){this.subscribers=new Map}on(e,t){this.subscribers.get(e)||this.subscribers.set(e,[]),this.subscribers.get(e).push(t)}emit(e,...t){const n=this.subscribers.get(e)||[];for(const e of n)e(...t)}}const q=(e,t,n)=>({endTime:t,insertTime:n,type:"exponentialRampToValue",value:e}),z=(e,t,n)=>({endTime:t,insertTime:n,type:"linearRampToValue",value:e}),Y=(e,t)=>({startTime:t,type:"setValue",value:e}),Z=(e,t,n)=>({duration:n,startTime:t,type:"setValueCurve",values:e}),U=(e,t,{startTime:n,target:r,timeConstant:o})=>r+(t-r)*Math.exp((n-e)/o),Q=e=>"exponentialRampToValue"===e.type,H=e=>"linearRampToValue"===e.type,$=e=>Q(e)||H(e),K=e=>"setValue"===e.type,J=e=>"setValueCurve"===e.type,ee=(e,t,n,r)=>{const o=e[t];return void 0===o?r:$(o)||K(o)?o.value:J(o)?o.values[o.values.length-1]:U(n,ee(e,t-1,o.startTime,r),o)},te=(e,t,n,r,o)=>void 0===n?[r.insertTime,o]:$(n)?[n.endTime,n.value]:K(n)?[n.startTime,n.value]:J(n)?[n.startTime+n.duration,n.values[n.values.length-1]]:[n.startTime,ee(e,t-1,n.startTime,o)],ne=e=>"cancelAndHold"===e.type,re=e=>"cancelScheduledValues"===e.type,oe=e=>ne(e)||re(e)?e.cancelTime:Q(e)||H(e)?e.endTime:e.startTime,ae=(e,t,n,{endTime:r,value:o})=>n===o?o:0<n&&0<o||n<0&&o<0?n*(o/n)**((e-t)/(r-t)):0,ie=(e,t,n,{endTime:r,value:o})=>n+(e-t)/(r-t)*(o-n),se=(e,{duration:t,startTime:n,values:r})=>((e,t)=>{const n=Math.floor(t),r=Math.ceil(t);return n===r?e[n]:(1-(t-n))*e[n]+(1-(r-t))*e[r]})(r,(e-n)/t*(r.length-1)),ce=e=>"setTarget"===e.type;class ue{constructor(e){this._automationEvents=[],this._currenTime=0,this._defaultValue=e}[Symbol.iterator](){return this._automationEvents[Symbol.iterator]()}add(e){const t=oe(e);if(ne(e)||re(e)){const n=this._automationEvents.findIndex(e=>oe(e)>=t),r=this._automationEvents[n];if(-1!==n&&(this._automationEvents=this._automationEvents.slice(0,n)),ne(e)){const e=this._automationEvents[this._automationEvents.length-1];if(void 0!==r&&$(r)){if(ce(e))throw new Error("The internal list is malformed.");const n=J(e)?e.startTime+e.duration:oe(e),o=J(e)?e.values[e.values.length-1]:e.value,a=Q(r)?ae(t,n,o,r):ie(t,n,o,r),i=Q(r)?q(a,t,this._currenTime):z(a,t,this._currenTime);this._automationEvents.push(i)}void 0!==e&&ce(e)&&this._automationEvents.push(Y(this.getValue(t),t)),void 0!==e&&J(e)&&e.startTime+e.duration>t&&(this._automationEvents[this._automationEvents.length-1]=Z(new Float32Array([6,7]),e.startTime,t-e.startTime))}}else{const n=this._automationEvents.findIndex(e=>oe(e)>t),r=-1===n?this._automationEvents[this._automationEvents.length-1]:this._automationEvents[n-1];if(void 0!==r&&J(r)&&oe(r)+r.duration>t)return!1;const o=Q(e)?q(e.value,e.endTime,this._currenTime):H(e)?z(e.value,t,this._currenTime):e;if(-1===n)this._automationEvents.push(o);else{if(J(e)&&t+e.duration>oe(this._automationEvents[n]))return!1;this._automationEvents.splice(n,0,o)}}return!0}flush(e){const t=this._automationEvents.findIndex(t=>oe(t)>e);if(t>1){const e=this._automationEvents.slice(t-1),n=e[0];ce(n)&&e.unshift(Y(ee(this._automationEvents,t-2,n.startTime,this._defaultValue),n.startTime)),this._automationEvents=e}}getValue(e){if(0===this._automationEvents.length)return this._defaultValue;const t=this._automationEvents[this._automationEvents.length-1],n=this._automationEvents.findIndex(t=>oe(t)>e),r=this._automationEvents[n],o=oe(t)<=e?t:this._automationEvents[n-1];if(void 0!==o&&ce(o)&&(void 0===r||!$(r)||r.insertTime>e))return U(e,ee(this._automationEvents,n-2,o.startTime,this._defaultValue),o);if(void 0!==o&&K(o)&&(void 0===r||!$(r)))return o.value;if(void 0!==o&&J(o)&&(void 0===r||!$(r)||o.startTime+o.duration>e))return e<o.startTime+o.duration?se(e,o):o.values[o.values.length-1];if(void 0!==o&&$(o)&&(void 0===r||!$(r)))return o.value;if(void 0!==r&&Q(r)){const[t,a]=te(this._automationEvents,n-1,o,r,this._defaultValue);return ae(e,t,a,r)}if(void 0!==r&&H(r)){const[t,a]=te(this._automationEvents,n-1,o,r,this._defaultValue);return ie(e,t,a,r)}return this._defaultValue}}const le=new WeakSet,he=new WeakMap,de=new WeakMap,fe=new WeakMap,pe=new WeakMap,me=new WeakMap,ve=new WeakMap,ge=new WeakMap,ye=new WeakMap,we=new WeakMap,_e={construct:()=>_e},Ce=/^import(?:(?:[\s]+[\w]+|(?:[\s]+[\w]+[\s]*,)?[\s]*\{[\s]*[\w]+(?:[\s]+as[\s]+[\w]+)?(?:[\s]*,[\s]*[\w]+(?:[\s]+as[\s]+[\w]+)?)*[\s]*}|(?:[\s]+[\w]+[\s]*,)?[\s]*\*[\s]+as[\s]+[\w]+)[\s]+from)?(?:[\s]*)("([^"\\]|\\.)+"|'([^'\\]|\\.)+')(?:[\s]*);?/,be=(e,t)=>{const n=[];let r=e.replace(/^[\s]+/,""),o=r.match(Ce);for(;null!==o;){const e=o[1].slice(1,-1),a=o[0].replace(/([\s]+)?;?$/,"").replace(e,new URL(e,t).toString());n.push(a),r=r.slice(o[0].length).replace(/^[\s]+/,""),o=r.match(Ce)}return[n.join(";"),r]},Te=e=>{if(void 0!==e&&!Array.isArray(e))throw new TypeError("The parameterDescriptors property of given value for processorCtor is not an array.")},Me=e=>{if(!(e=>{try{new new Proxy(e,_e)}catch{return!1}return!0})(e))throw new TypeError("The given value for processorCtor should be a constructor.");if(null===e.prototype||"object"!=typeof e.prototype)throw new TypeError("The given value for processorCtor should have a prototype.")},Ie={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",fftSize:2048,maxDecibels:-30,minDecibels:-100,smoothingTimeConstant:.8},xe=(e,t)=>e.context===t,Se=e=>{try{e.copyToChannel(new Float32Array(1),0,-1)}catch{return!1}return!0},Ae=()=>{try{return new DOMException("","IndexSizeError")}catch(e){return e.code=1,e.name="IndexSizeError",e}},Ne=e=>{var t;e.getChannelData=(t=e.getChannelData,n=>{try{return t.call(e,n)}catch(e){if(12===e.code)throw Ae();throw e}})},ke={numberOfChannels:1},Oe=-34028234663852886e22,Ee=-Oe,Pe=(e,t)=>{const n=e.get(t);if(void 0===n)throw new Error("A value with the given key could not be found.");return n},De=e=>Pe(ge,e),Re=e=>{if(le.has(e))throw new Error("The AudioNode is already stored.");le.add(e),De(e).forEach(e=>e(!0))},Ve=e=>{if(!le.has(e))throw new Error("The AudioNode is not stored.");le.delete(e),De(e).forEach(e=>e(!1))},Be={buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1},Fe=e=>"context"in e,Le=e=>Fe(e[0]),We=e=>"port"in e,je=e=>"inputs"in e,Ge=(e,t,n,r)=>{if(je(t)){const o=t.inputs[r];return e.connect(o,n,0),[o,n,0]}return e.connect(t,n,r),[t,n,r]},Xe=(e,t)=>{if(!De(e).delete(t))throw new Error("Missing the expected event listener.")},qe=(e,t,n,r)=>{je(t)?e.disconnect(t.inputs[r],n,0):e.disconnect(t,n,r)},ze=e=>Pe(he,e),Ye=e=>Pe(fe,e),Ze=e=>Pe(de,e),Ue=e=>Pe(pe,e),Qe=(e,t,n,r)=>{for(const t of e)if(n(t)){if(r)return!1;throw Error("The set contains at least one similar element.")}return e.add(t),!0},He=e=>le.has(e),$e=e=>ye.has(e),Ke=e=>!le.has(e),Je=(e,t)=>{const n=Array.from(e).filter(t);if(n.length>1)throw Error("More than one element was found.");if(0===n.length)throw Error("No element was found.");const[r]=n;return e.delete(r),r},et=(e,t)=>{!We(e)&&t.every(e=>0===e.size)&&Ve(e)},tt=e=>new Promise(t=>{const n=e.createScriptProcessor(256,1,1),r=e.createGain(),o=e.createBuffer(1,2,44100),a=o.getChannelData(0);a[0]=1,a[1]=1;const i=e.createBufferSource();i.buffer=o,i.loop=!0,i.connect(n).connect(e.destination),i.connect(r),i.disconnect(r),n.onaudioprocess=r=>{const o=r.inputBuffer.getChannelData(0);Array.prototype.some.call(o,e=>1===e)?t(!0):t(!1),i.stop(),n.onaudioprocess=null,i.disconnect(n),n.disconnect(e.destination)},i.start()}),nt=(e,t)=>{const n=new Map;for(const t of e)for(const e of t){const t=n.get(e);n.set(e,void 0===t?1:t+1)}n.forEach((e,n)=>t(n,e))},rt=e=>"context"in e,ot=e=>{const t=new Map;var n,r;e.connect=(n=e.connect.bind(e),(e,r=0,o=0)=>{const a=rt(e)?n(e,r,o):n(e,r),i=t.get(e);return void 0===i?t.set(e,[{input:o,output:r}]):i.every(e=>e.input!==o||e.output!==r)&&i.push({input:o,output:r}),a}),e.disconnect=(r=e.disconnect,(n,o,a)=>{if(r.apply(e),void 0===n)t.clear();else if("number"==typeof n)for(const[e,r]of t){const o=r.filter(e=>e.output!==n);0===o.length?t.delete(e):t.set(e,o)}else if(t.has(n))if(void 0===o)t.delete(n);else{const e=t.get(n);if(void 0!==e){const r=e.filter(e=>e.output!==o&&(e.input!==a||void 0===a));0===r.length?t.delete(n):t.set(n,r)}}for(const[n,r]of t)r.forEach(t=>{rt(n)?e.connect(n,t.output,t.input):e.connect(n,t.output)})})},at=(e,t,[n,r,o],a)=>{Qe(e[r],[t,n,o],e=>e[0]===t&&e[1]===n,a)},it=(e,t,[n,r],o)=>{Qe(e,[t,n,r],e=>e[0]===t&&e[1]===n,o)},st=(e,t,[n,r,o],a)=>{const i=e.get(n);void 0===i?e.set(n,new Set([[r,t,o]])):Qe(i,[r,t,o],e=>e[0]===r&&e[1]===t,a)},ct=(e,[t,n,r],o)=>{const a=e.get(t);void 0===a?e.set(t,new Set([[n,r]])):Qe(a,[n,r],e=>e[0]===n,o)},ut=(e,t,n,r)=>{const o=Pe(e,t),a=Je(o,e=>e[0]===n&&e[1]===r);return 0===o.size&&e.delete(t),a},lt=(e,t,n)=>{const r=Pe(e,t),o=Je(r,e=>e[0]===n);return 0===r.size&&e.delete(t),o},ht=(e,t,n,r)=>{const{activeInputs:o,passiveInputs:a}=ze(t),{outputs:i}=ze(e),s=De(e),c=i=>{const s=Ze(t),c=Ze(e);if(i){const i=ut(a,e,n,r);at(o,e,i,!1),$e(e)||Ge(c,s,n,r),Ke(t)&&Re(t)}else{const i=((e,t,n,r)=>Je(e[r],e=>e[0]===t&&e[1]===n))(o,e,n,r);st(a,r,i,!1),$e(e)||qe(c,s,n,r),He(t)&&et(t,o)}};return!!Qe(i,[t,n,r],e=>e[0]===t&&e[1]===n&&e[2]===r,!0)&&(s.add(c),He(e)?at(o,e,[n,r,c],!0):st(a,r,[e,n,c],!0),!0)},dt=(e,t,n)=>{const{activeInputs:r,passiveInputs:o}=Ye(t),{outputs:a}=ze(e),i=De(e),s=a=>{const i=Ze(e),s=Ue(t);if(a){const t=lt(o,e,n);it(r,e,t,!1),$e(e)||i.connect(s,n)}else{const t=((e,t,n)=>Je(e,e=>e[0]===t&&e[1]===n))(r,e,n);ct(o,t,!1),$e(e)||i.disconnect(s,n)}};return!!Qe(a,[t,n],e=>e[0]===t&&e[1]===n,!0)&&(i.add(s),He(e)?it(r,e,[n,s],!0):ct(o,[e,n,s],!0),!0)},ft=(e,t,n)=>{for(const r of e)if(r[0]===t&&r[1]===n)return e.delete(r),r;return null},pt=(e,t,n,r)=>{const[o,a]=((e,t,n,r)=>{const{activeInputs:o,passiveInputs:a}=ze(t),i=ft(o[r],e,n);if(null===i)return[ut(a,e,n,r)[2],!1];return[i[2],!0]})(e,t,n,r);if(null!==o&&(Xe(e,o),a&&!$e(e)&&qe(Ze(e),Ze(t),n,r)),He(t)){const{activeInputs:e}=ze(t);et(t,e)}},mt=(e,t,n)=>{const[r,o]=((e,t,n)=>{const{activeInputs:r,passiveInputs:o}=Ye(t),a=ft(r,e,n);if(null===a)return[lt(o,e,n)[1],!1];return[a[2],!0]})(e,t,n);null!==r&&(Xe(e,r),o&&!$e(e)&&Ze(e).disconnect(Ue(t),n))},vt={Q:1,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:350,gain:0,type:"lowpass"},gt={channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:6},yt={channelCount:6,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:6},wt={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",offset:1},_t={buffer:null,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",disableNormalization:!1},Ct={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",delayTime:0,maxDelayTime:1},bt={attack:.003,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",knee:30,ratio:12,release:.25,threshold:-24},Tt={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",gain:1},Mt=()=>{try{return new DOMException("","InvalidStateError")}catch(e){return e.code=11,e.name="InvalidStateError",e}},It=()=>{try{return new DOMException("","InvalidAccessError")}catch(e){return e.code=15,e.name="InvalidAccessError",e}},xt={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers"},St=(e,t,n,r,o,a,i,s,c,u,l)=>{const h=u.length;let d=s;for(let s=0;s<h;s+=1){let h=n[0]*u[s];for(let t=1;t<o;t+=1){const r=d-t&c-1;h+=n[t]*a[r],h-=e[t]*i[r]}for(let e=o;e<r;e+=1)h+=n[e]*a[d-e&c-1];for(let n=o;n<t;n+=1)h-=e[n]*i[d-n&c-1];a[d]=u[s],i[d]=h,d=d+1&c-1,l[s]=h}return d},At={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers"},Nt=e=>{const t=new Uint32Array([1179011410,40,1163280727,544501094,16,131073,44100,176400,1048580,1635017060,4,0]);try{const n=e.decodeAudioData(t.buffer,()=>{});return void 0!==n&&(n.catch(()=>{}),!0)}catch{}return!1},kt=(e,t,n)=>{const r=t[n];void 0!==r&&r!==e[n]&&(e[n]=r)},Ot=(e,t)=>{kt(e,t,"channelCount"),kt(e,t,"channelCountMode"),kt(e,t,"channelInterpretation")},Et=e=>"function"==typeof e.getFloatTimeDomainData,Pt=(e,t,n)=>{const r=t[n];void 0!==r&&r!==e[n].value&&(e[n].value=r)},Dt=e=>{var t;e.start=(t=e.start,(n=0,r=0,o)=>{if("number"==typeof o&&o<0||r<0||n<0)throw new RangeError("The parameters can't be negative.");t.call(e,n,r,o)})},Rt=e=>{var t;e.stop=(t=e.stop,(n=0)=>{if(n<0)throw new RangeError("The parameter can't be negative.");t.call(e,n)})},Vt=(e,t)=>(e.connect=t.connect.bind(t),e.disconnect=t.disconnect.bind(t),e);function Bt(e,t){const n=t[0]*t[0]+t[1]*t[1];return[(e[0]*t[0]+e[1]*t[1])/n,(e[1]*t[0]-e[0]*t[1])/n]}function Ft(e,t){let n=[0,0];for(let a=e.length-1;a>=0;a-=1)o=t,n=[(r=n)[0]*o[0]-r[1]*o[1],r[0]*o[1]+r[1]*o[0]],n[0]+=e[a];var r,o;return n}const Lt=()=>{try{return new DOMException("","NotSupportedError")}catch(e){return e.code=9,e.name="NotSupportedError",e}},Wt={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:440,type:"sine"},jt={channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",coneInnerAngle:360,coneOuterAngle:360,coneOuterGain:0,distanceModel:"inverse",maxDistance:1e4,orientationX:1,orientationY:0,orientationZ:0,panningModel:"equalpower",positionX:0,positionY:0,positionZ:0,refDistance:1,rolloffFactor:1},Gt={disableNormalization:!1},Xt={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",pan:0},qt={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",curve:null,oversample:"none"},zt=e=>{if(null===e)return!1;const t=e.length;return t%2!=0?0!==e[Math.floor(t/2)]:e[t/2-1]+e[t/2]!==0},Yt=(e,t,n,r)=>{let o=Object.getPrototypeOf(e);for(;!o.hasOwnProperty(t);)o=Object.getPrototypeOf(o);const{get:a,set:i}=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(e,t,{get:n(a),set:r(i)})},Zt=(e,t)=>n=>{const r={value:e};return Object.defineProperties(n,{currentTarget:r,target:r}),"function"==typeof t?t.call(e,n):t.handleEvent.call(e,n)},Ut=(Qt=new Map,Ht=new WeakMap,(e,t)=>{const n=Ht.get(e);if(void 0!==n)return n;const r=Qt.get(e);if(void 0!==r)return r;try{const n=t();return n instanceof Promise?(Qt.set(e,n),n.catch(()=>!1).then(t=>(Qt.delete(e),Ht.set(e,t),t))):(Ht.set(e,n),n)}catch{return Ht.set(e,!1),!1}});var Qt,Ht;const $t="undefined"==typeof window?null:window,Kt=(e=>null===e?null:e.hasOwnProperty("OfflineAudioContext")?e.OfflineAudioContext:e.hasOwnProperty("webkitOfflineAudioContext")?e.webkitOfflineAudioContext:null)($t),Jt=(e=>t=>null!==e&&t instanceof e)(Kt),en=(e=>null===e?null:e.hasOwnProperty("AudioContext")?e.AudioContext:e.hasOwnProperty("webkitAudioContext")?e.webkitAudioContext:null)($t),tn=((e,t,n)=>r=>{if("closed"===r.state&&null!==t&&"webkitAudioContext"!==t.name){if(!e(r)){const e=me.get(r);if(void 0!==e)return e;const n=new t;return me.set(r,n),n}{const e=me.get(r);if(void 0!==e)return e;if(null!==n){const e=new n(1,1,44100);return me.set(r,e),e}}}return null})(Jt,en,Kt),nn=(e=>(t,n)=>{const r=e(t);return n(null!==r?r:t)})(tn),rn=((e,t,n)=>(r,o)=>{const a=n(r,e=>e.createAnalyser());if(Ot(a,o),!(o.maxDecibels>o.minDecibels))throw t();return kt(a,o,"fftSize"),kt(a,o,"maxDecibels"),kt(a,o,"minDecibels"),kt(a,o,"smoothingTimeConstant"),e(Et,()=>Et(a))||(e=>{e.getFloatTimeDomainData=t=>{const n=new Uint8Array(t.length);e.getByteTimeDomainData(n);const r=Math.max(n.length,e.fftSize);for(let e=0;e<r;e+=1)t[e]=.0078125*(n[e]-128);return t}})(a),a})(Ut,Ae,nn),on=(e=>t=>{const n=e(t);if(null===n.renderer)throw new Error("Missing the renderer of the given AudioNode in the audio graph.");return n.renderer})(ze),an=((e,t,n)=>async(r,o,a,i)=>{const s=e(r),c=[...i,r];await Promise.all(s.activeInputs.map((e,i)=>Array.from(e).filter(([e])=>!c.includes(e)).map(async([e,s])=>{const u=t(e),l=await u.render(e,o,c),h=r.context.destination;n(e)||r===h&&n(r)||l.connect(a,s,i)})).reduce((e,t)=>[...e,...t],[]))})(ze,on,$e),sn=((e,t,n)=>()=>{const r=new WeakMap;return{render(o,a,i){const s=r.get(a);return void 0!==s?Promise.resolve(s):(async(o,a,i)=>{let s=t(o);if(!xe(s,a)){const t={channelCount:s.channelCount,channelCountMode:s.channelCountMode,channelInterpretation:s.channelInterpretation,fftSize:s.fftSize,maxDecibels:s.maxDecibels,minDecibels:s.minDecibels,smoothingTimeConstant:s.smoothingTimeConstant};s=e(a,t)}return r.set(a,s),await n(o,a,s,i),s})(o,a,i)}}})(rn,Ze,an),cn=new WeakMap,un=(ln=ve,e=>{const t=ln.get(e);if(void 0===t)throw Mt();return t});var ln;const hn=new WeakMap,dn=(e=>class{constructor(e){this._nativeEventTarget=e,this._listeners=new WeakMap}addEventListener(t,n,r){if(null!==n){let o=this._listeners.get(n);void 0===o&&(o=e(this,n),"function"==typeof n&&this._listeners.set(n,o)),this._nativeEventTarget.addEventListener(t,o,r)}}dispatchEvent(e){return this._nativeEventTarget.dispatchEvent(e)}removeEventListener(e,t,n){const r=null===t?void 0:this._listeners.get(t);this._nativeEventTarget.removeEventListener(e,void 0===r?null:r,n)}})(Zt),fn=(e=>t=>null!==e&&t instanceof e)(en),pn=(e=>t=>null!==e&&"function"==typeof e.AudioNode&&t instanceof e.AudioNode)($t),mn=(e=>t=>null!==e&&"function"==typeof e.AudioParam&&t instanceof e.AudioParam)($t),vn=((e,t,n,r,o,a,i,s,c,u,l,h,d,f,p)=>class extends u{constructor(t,r,o,a){super(o),this._context=t,this._nativeAudioNode=o;const i=l(t);h(i)&&!0!==n(tt,()=>tt(i))&&ot(o),de.set(this,o),ge.set(this,new Set),r&&Re(this),e(this,a,o)}get channelCount(){return this._nativeAudioNode.channelCount}set channelCount(e){this._nativeAudioNode.channelCount=e}get channelCountMode(){return this._nativeAudioNode.channelCountMode}set channelCountMode(e){this._nativeAudioNode.channelCountMode=e}get channelInterpretation(){return this._nativeAudioNode.channelInterpretation}set channelInterpretation(e){this._nativeAudioNode.channelInterpretation=e}get context(){return this._context}get numberOfInputs(){return this._nativeAudioNode.numberOfInputs}get numberOfOutputs(){return this._nativeAudioNode.numberOfOutputs}connect(e,n=0,s=0){if(n<0||n>=this._nativeAudioNode.numberOfOutputs)throw o();const u=l(this._context),h=p(u);if(d(e)||f(e))throw a();if(Fe(e)){const o=Ze(e);try{const r=Ge(this._nativeAudioNode,o,n,s);if(h||Ke(this)?this._nativeAudioNode.disconnect(...r):Ke(e)&&Re(e),We(e)){const e=t.get(o);if(void 0===e){const e=u.createGain();e.connect(r[0],0,r[2]),t.set(o,new Map([[s,e]]))}else if(void 0===e.get(s)){const t=u.createGain();t.connect(r[0],0,r[2]),e.set(s,t)}}}catch(e){if(12===e.code)throw a();throw e}if(h?((e,t,n,r)=>{const{outputs:o}=ze(e);if(Qe(o,[t,n,r],e=>e[0]===t&&e[1]===n&&e[2]===r,!0)){const{activeInputs:o}=ze(t);return at(o,e,[n,r,null],!0),!0}return!1})(this,e,n,s):ht(this,e,n,s)){const t=c([this],e);nt(t,r(h))}return e}const m=Ue(e);if("playbackRate"===m.name)throw i();try{this._nativeAudioNode.connect(m,n),(h||Ke(this))&&this._nativeAudioNode.disconnect(m,n)}catch(e){if(12===e.code)throw a();throw e}if(h?((e,t,n)=>{const{outputs:r}=ze(e);if(Qe(r,[t,n],e=>e[0]===t&&e[1]===n,!0)){const{activeInputs:r}=Ye(t);return it(r,e,[n,null],!0),!0}return!1})(this,e,n):dt(this,e,n)){const t=c([this],e);nt(t,r(h))}}disconnect(e,t,n){let r;if(void 0===e)r=(e=>{const t=ze(e),n=[];for(const r of t.outputs)Le(r)?pt(e,...r):mt(e,...r),n.push(r[0]);return t.outputs.clear(),n})(this);else if("number"==typeof e){if(e<0||e>=this.numberOfOutputs)throw o();r=((e,t)=>{const n=ze(e),r=[];for(const o of n.outputs)o[1]===t&&(Le(o)?pt(e,...o):mt(e,...o),r.push(o[0]),n.outputs.delete(o));return r})(this,e)}else{if(void 0!==t&&(t<0||t>=this.numberOfOutputs))throw o();if(Fe(e)&&void 0!==n&&(n<0||n>=e.numberOfInputs))throw o();if(r=((e,t,n,r)=>{const o=ze(e);return Array.from(o.outputs).filter(e=>!(e[0]!==t||void 0!==n&&e[1]!==n||void 0!==r&&e[2]!==r)).map(t=>(Le(t)?pt(e,...t):mt(e,...t),o.outputs.delete(t),t[0]))})(this,e,t,n),0===r.length)throw a()}for(const e of r){const t=c([this],e);nt(t,s)}}})((gn=he,(e,t,n)=>{const r=[];for(let e=0;e<n.numberOfInputs;e+=1)r.push(new Set);gn.set(e,{activeInputs:r,outputs:new Set,passiveInputs:new WeakMap,renderer:t})}),cn,Ut,((e,t,n,r,o,a)=>i=>(s,c)=>{const u=e.get(s);if(void 0===u){if(!i&&a(s)){const e=r(s),{outputs:a}=n(s);for(const n of a)if(Le(n)){const o=r(n[0]);t(e,o,n[1],n[2])}else{const t=o(n[0]);e.disconnect(t,n[1])}}e.set(s,c)}else e.set(s,u+c)})(ye,qe,ze,Ze,Ue,He),Ae,It,Lt,((e,t,n,r,o,a,i,s)=>(c,u)=>{const l=t.get(c);if(void 0===l)throw new Error("Missing the expected cycle count.");const h=a(c.context),d=s(h);if(l===u){if(t.delete(c),!d&&i(c)){const t=r(c),{outputs:a}=n(c);for(const n of a)if(Le(n)){const o=r(n[0]);e(t,o,n[1],n[2])}else{const e=o(n[0]);t.connect(e,n[1])}}}else t.set(c,l-u)})(Ge,ye,ze,Ze,Ue,un,He,Jt),((e,t,n)=>function r(o,a){const i=Fe(a)?a:n(e,a);if((e=>"delayTime"in e)(i))return[];if(o[0]===i)return[o];if(o.includes(i))return[];const{outputs:s}=t(i);return Array.from(s).map(e=>r([...o,i],e[0])).reduce((e,t)=>e.concat(t),[])})(hn,ze,Pe),dn,un,fn,pn,mn,Jt);var gn;const yn=((e,t,n,r,o,a)=>class extends e{constructor(e,n=Ie){const i=o(e),s={...Ie,...n},c=r(i,s);super(e,!1,c,a(i)?t():null),this._nativeAnalyserNode=c}get fftSize(){return this._nativeAnalyserNode.fftSize}set fftSize(e){this._nativeAnalyserNode.fftSize=e}get frequencyBinCount(){return this._nativeAnalyserNode.frequencyBinCount}get maxDecibels(){return this._nativeAnalyserNode.maxDecibels}set maxDecibels(e){const t=this._nativeAnalyserNode.maxDecibels;if(this._nativeAnalyserNode.maxDecibels=e,!(e>this._nativeAnalyserNode.minDecibels))throw this._nativeAnalyserNode.maxDecibels=t,n()}get minDecibels(){return this._nativeAnalyserNode.minDecibels}set minDecibels(e){const t=this._nativeAnalyserNode.minDecibels;if(this._nativeAnalyserNode.minDecibels=e,!(this._nativeAnalyserNode.maxDecibels>e))throw this._nativeAnalyserNode.minDecibels=t,n()}get smoothingTimeConstant(){return this._nativeAnalyserNode.smoothingTimeConstant}set smoothingTimeConstant(e){this._nativeAnalyserNode.smoothingTimeConstant=e}getByteFrequencyData(e){this._nativeAnalyserNode.getByteFrequencyData(e)}getByteTimeDomainData(e){this._nativeAnalyserNode.getByteTimeDomainData(e)}getFloatFrequencyData(e){this._nativeAnalyserNode.getFloatFrequencyData(e)}getFloatTimeDomainData(e){this._nativeAnalyserNode.getFloatTimeDomainData(e)}})(vn,sn,Ae,rn,un,Jt),wn=new WeakSet,_n=(e=>null===e?null:e.hasOwnProperty("AudioBuffer")?e.AudioBuffer:null)($t),Cn=(bn=new Uint32Array(1),e=>(bn[0]=e,bn[0]));var bn;const Tn=((e,t)=>n=>{n.copyFromChannel=(r,o,a=0)=>{const i=e(a),s=e(o);if(s>=n.numberOfChannels)throw t();const c=n.length,u=n.getChannelData(s),l=r.length;for(let e=i<0?-i:0;e+i<c&&e<l;e+=1)r[e]=u[e+i]},n.copyToChannel=(r,o,a=0)=>{const i=e(a),s=e(o);if(s>=n.numberOfChannels)throw t();const c=n.length,u=n.getChannelData(s),l=r.length;for(let e=i<0?-i:0;e+i<c&&e<l;e+=1)u[e+i]=r[e]}})(Cn,Ae),Mn=(e=>t=>{var n,r;t.copyFromChannel=(n=t.copyFromChannel,(r,o,a=0)=>{const i=e(a),s=e(o);if(i<t.length)return n.call(t,r,s,i)}),t.copyToChannel=(r=t.copyToChannel,(n,o,a=0)=>{const i=e(a),s=e(o);if(i<t.length)return r.call(t,n,s,i)})})(Cn),In=((e,t,n,r,o,a,i,s)=>{let c=null;return class u{constructor(u){if(null===o)throw new Error("Missing the native OfflineAudioContext constructor.");const{length:l,numberOfChannels:h,sampleRate:d}={...ke,...u};null===c&&(c=new o(1,1,44100));const f=null!==r&&t(a,a)?new r({length:l,numberOfChannels:h,sampleRate:d}):c.createBuffer(h,l,d);if(0===f.numberOfChannels)throw n();return"function"!=typeof f.copyFromChannel?(i(f),Ne(f)):t(Se,()=>Se(f))||s(f),e.add(f),f}static[Symbol.hasInstance](t){return null!==t&&"object"==typeof t&&Object.getPrototypeOf(t)===u.prototype||e.has(t)}}})(wn,Ut,Lt,_n,Kt,(e=>()=>{if(null===e)return!1;try{new e({length:1,sampleRate:44100})}catch{return!1}return!0})(_n),Tn,Mn),xn=(e=>(t,n)=>{const r=e(t,e=>e.createGain());return Ot(r,n),Pt(r,n,"gain"),r})(nn),Sn=(e=>(t,n)=>{const r=e(t,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});n.connect(r).connect(r.context.destination);const o=()=>{n.removeEventListener("ended",o),n.disconnect(r),r.disconnect()};n.addEventListener("ended",o)})(xn),An=(e=>t=>{const n=e(t,e=>e.createOscillator());try{n.start(-1)}catch(e){return e instanceof RangeError}return!1})(nn),Nn=(e=>t=>{const n=t.createBuffer(1,1,44100),r=e(t,e=>e.createBufferSource());r.buffer=n,r.start(),r.stop();try{return r.stop(),!0}catch{return!1}})(nn),kn=(e=>t=>{const n=e(t,e=>e.createOscillator());try{n.stop(-1)}catch(e){return e instanceof RangeError}return!1})(nn),On=(e=>(t,n)=>{const r=e(n,e=>e.createGain());t.connect(r);const o=(a=t.disconnect,()=>{a.call(t,r),t.removeEventListener("ended",o)});var a;t.addEventListener("