/** * Combined by jsDelivr. * Original files: * - /npm/tone@14.7.58/build/Tone.min.js * - /npm/@magenta/music@1.23.1/es6/core.js * - /npm/focus-visible@5.2.1/dist/focus-visible.min.js * - /npm/html-midi-player@1.4.0/dist/midi-player.min.js * * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files */ /** * Skipped minification because the original files appears to be already minified. * Original file: /npm/tone@14.7.58/build/Tone.js * * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Tone=e():t.Tone=e()}("undefined"!=typeof self?self:this,(function(){return function(t){var e={};function s(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=t,s.c=e,s.d=function(t,e,n){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(s.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)s.d(n,i,function(e){return t[e]}.bind(null,i));return n},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=9)}([function(t,e,s){!function(t,e,s,n){"use strict";function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=i(e),r=i(s),a=i(n),c=function(t,e,s){return{endTime:e,insertTime:s,type:"exponentialRampToValue",value:t}},h=function(t,e,s){return{endTime:e,insertTime:s,type:"linearRampToValue",value:t}},u=function(t,e){return{startTime:e,type:"setValue",value:t}},l=function(t,e,s){return{duration:s,startTime:e,type:"setValueCurve",values:t}},p=function(t,e,s){var n=s.startTime,i=s.target,o=s.timeConstant;return i+(e-i)*Math.exp((n-t)/o)},d=function(t){return"exponentialRampToValue"===t.type},f=function(t){return"linearRampToValue"===t.type},_=function(t){return d(t)||f(t)},m=function(t){return"setValue"===t.type},g=function(t){return"setValueCurve"===t.type},v=function t(e,s,n,i){var o=e[s];return void 0===o?i:_(o)||m(o)?o.value:g(o)?o.values[o.values.length-1]:p(n,t(e,s-1,o.startTime,i),o)},y=function(t,e,s,n,i){return void 0===s?[n.insertTime,i]:_(s)?[s.endTime,s.value]:m(s)?[s.startTime,s.value]:g(s)?[s.startTime+s.duration,s.values[s.values.length-1]]:[s.startTime,v(t,e-1,s.startTime,i)]},x=function(t){return"cancelAndHold"===t.type},w=function(t){return"cancelScheduledValues"===t.type},b=function(t){return x(t)||w(t)?t.cancelTime:d(t)||f(t)?t.endTime:t.startTime},T=function(t,e,s,n){var i=n.endTime,o=n.value;return s===o?o:0=e:b(s)>=e})),n=this._automationEvents[s];if(-1!==s&&(this._automationEvents=this._automationEvents.slice(0,s)),x(t)){var i=this._automationEvents[this._automationEvents.length-1];if(void 0!==n&&_(n)){if(C(i))throw new Error("The internal list is malformed.");var o=g(i)?i.startTime+i.duration:b(i),r=g(i)?i.values[i.values.length-1]:i.value,a=d(n)?T(e,o,r,n):S(e,o,r,n),p=d(n)?c(a,e,this._currenTime):h(a,e,this._currenTime);this._automationEvents.push(p)}void 0!==i&&C(i)&&this._automationEvents.push(u(this.getValue(e),e)),void 0!==i&&g(i)&&i.startTime+i.duration>e&&(this._automationEvents[this._automationEvents.length-1]=l(new Float32Array([6,7]),i.startTime,e-i.startTime))}}else{var m=this._automationEvents.findIndex((function(t){return b(t)>e})),v=-1===m?this._automationEvents[this._automationEvents.length-1]:this._automationEvents[m-1];if(void 0!==v&&g(v)&&b(v)+v.duration>e)return!1;var y=d(t)?c(t.value,t.endTime,this._currenTime):f(t)?h(t.value,e,this._currenTime):t;if(-1===m)this._automationEvents.push(y);else{if(g(t)&&e+t.duration>b(this._automationEvents[m]))return!1;this._automationEvents.splice(m,0,y)}}return!0}},{key:"flush",value:function(t){var e=this._automationEvents.findIndex((function(e){return b(e)>t}));if(e>1){var s=this._automationEvents.slice(e-1),n=s[0];C(n)&&s.unshift(u(v(this._automationEvents,e-2,n.startTime,this._defaultValue),n.startTime)),this._automationEvents=s}}},{key:"getValue",value:function(t){if(0===this._automationEvents.length)return this._defaultValue;var e=this._automationEvents[this._automationEvents.length-1],s=this._automationEvents.findIndex((function(e){return b(e)>t})),n=this._automationEvents[s],i=b(e)<=t?e:this._automationEvents[s-1];if(void 0!==i&&C(i)&&(void 0===n||!_(n)||n.insertTime>t))return p(t,v(this._automationEvents,s-2,i.startTime,this._defaultValue),i);if(void 0!==i&&m(i)&&(void 0===n||!_(n)))return i.value;if(void 0!==i&&g(i)&&(void 0===n||!_(n)||i.startTime+i.duration>t))return tt.length)&&(e=t.length);for(var s=0,n=new Array(e);sg},v=/^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]*);?/,y=(t,e)=>{const s=[];let n=t.replace(/^[\s]+/,""),i=n.match(v);for(;null!==i;){const t=i[1].slice(1,-1),o=i[0].replace(/([\s]+)?;?$/,"").replace(t,new URL(t,e).toString());s.push(o),n=n.slice(i[0].length).replace(/^[\s]+/,""),i=n.match(v)}return[s.join(";"),n]},x=t=>{if(void 0!==t&&!Array.isArray(t))throw new TypeError("The parameterDescriptors property of given value for processorCtor is not an array.")},w=t=>{if(!(t=>{try{new new Proxy(t,g)}catch{return!1}return!0})(t))throw new TypeError("The given value for processorCtor should be a constructor.");if(null===t.prototype||"object"!=typeof t.prototype)throw new TypeError("The given value for processorCtor should have a prototype.")},b={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",fftSize:2048,maxDecibels:-30,minDecibels:-100,smoothingTimeConstant:.8},T=(t,e)=>t.context===e,S=t=>{try{t.copyToChannel(new Float32Array(1),0,-1)}catch{return!1}return!0},k=()=>new DOMException("","IndexSizeError"),C=t=>{var e;t.getChannelData=(e=t.getChannelData,s=>{try{return e.call(t,s)}catch(t){if(12===t.code)throw k();throw t}})},A={numberOfChannels:1},D=-34028234663852886e22,O=-D,M=t=>a.has(t),E=(t,e)=>{const s=t.get(e);if(void 0===s)throw new Error("A value with the given key could not be found.");return s},R=t=>E(d,t),q=t=>{if(a.has(t))throw new Error("The AudioNode is already stored.");a.add(t),R(t).forEach(t=>t(!0))},F=t=>{if(!a.has(t))throw new Error("The AudioNode is not stored.");a.delete(t),R(t).forEach(t=>t(!1))},I={buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1},V=t=>"port"in t,N=t=>E(c,t),P=t=>E(u,t),j=(t,e)=>{const{activeInputs:s}=N(t);s.forEach(s=>s.forEach(([s])=>{e.includes(t)||j(s,[...e,t])}));const n=(t=>"playbackRate"in t)(t)?[t.playbackRate]:V(t)?Array.from(t.parameters.values()):(t=>"frequency"in t&&"gain"in t)(t)?[t.Q,t.detune,t.frequency,t.gain]:(t=>"offset"in t)(t)?[t.offset]:(t=>!("frequency"in t)&&"gain"in t)(t)?[t.gain]:(t=>"detune"in t&&"frequency"in t)(t)?[t.detune,t.frequency]:(t=>"pan"in t)(t)?[t.pan]:[];for(const t of n){const s=P(t);void 0!==s&&s.activeInputs.forEach(([t])=>j(t,e))}M(t)&&F(t)},L=t=>{j(t.destination,[])},z=t=>void 0===t||"number"==typeof t||"string"==typeof t&&("balanced"===t||"interactive"===t||"playback"===t),B=t=>"context"in t,W=t=>B(t[0]),U=t=>"inputs"in t,G=(t,e,s,n)=>{if(U(e)){const i=e.inputs[n];return t.connect(i,s,0),[i,s,0]}return t.connect(e,s,n),[e,s,n]},Q=(t,e)=>{if(!R(t).delete(e))throw new Error("Missing the expected event listener.")},Z=(t,e,s,n)=>{U(e)?t.disconnect(e.inputs[n],s,0):t.disconnect(e,s,n)},X=t=>E(h,t),Y=t=>E(l,t),H=(t,e,s,n)=>{for(const e of t)if(s(e)){if(n)return!1;throw Error("The set contains at least one similar element.")}return t.add(e),!0},$=t=>f.has(t),J=t=>!a.has(t),K=(t,e)=>{const s=Array.from(t).filter(e);if(s.length>1)throw Error("More than one element was found.");if(0===s.length)throw Error("No element was found.");const[n]=s;return t.delete(n),n},tt=(t,e)=>{!V(t)&&e.every(t=>0===t.size)&&F(t)},et=t=>new Promise(e=>{const s=t.createScriptProcessor(256,1,1),n=t.createGain(),i=t.createBuffer(1,2,44100),o=i.getChannelData(0);o[0]=1,o[1]=1;const r=t.createBufferSource();r.buffer=i,r.loop=!0,r.connect(s).connect(t.destination),r.connect(n),r.disconnect(n),s.onaudioprocess=n=>{const i=n.inputBuffer.getChannelData(0);Array.prototype.some.call(i,t=>1===t)?e(!0):e(!1),r.stop(),s.onaudioprocess=null,r.disconnect(s),s.disconnect(t.destination)},r.start()}),st=(t,e)=>{const s=new Map;for(const e of t)for(const t of e){const e=s.get(t);s.set(t,void 0===e?1:e+1)}s.forEach((t,s)=>e(s,t))},nt=t=>"context"in t,it=(t,e,[s,n,i],o)=>{H(t[n],[e,s,i],t=>t[0]===e&&t[1]===s,o)},ot=(t,e,[s,n],i)=>{H(t,[e,s,n],t=>t[0]===e&&t[1]===s,i)},rt=(t,e,[s,n,i],o)=>{const r=t.get(s);void 0===r?t.set(s,new Set([[n,e,i]])):H(r,[n,e,i],t=>t[0]===n&&t[1]===e,o)},at=(t,[e,s,n],i)=>{const o=t.get(e);void 0===o?t.set(e,new Set([[s,n]])):H(o,[s,n],t=>t[0]===s,i)},ct=(t,e,s,n)=>{const i=E(t,e),o=K(i,t=>t[0]===s&&t[1]===n);return 0===i.size&&t.delete(e),o},ht=(t,e,s)=>{const n=E(t,e),i=K(n,t=>t[0]===s);return 0===n.size&&t.delete(e),i},ut=(t,e,s,n,i)=>{const{activeInputs:o,passiveInputs:r}=N(e),{outputs:a}=N(t),c=R(t),h=a=>{const c=X(e),h=X(t);if(a){const a=ct(r,t,s,n);it(o,t,a,!1),i||$(t)||G(h,c,s,n),J(e)&&q(e)}else{const a=((t,e,s,n)=>K(t[n],t=>t[0]===e&&t[1]===s))(o,t,s,n);rt(r,n,a,!1),i||$(t)||Z(h,c,s,n),M(e)&&tt(e,o)}};return!!H(a,[e,s,n],t=>t[0]===e&&t[1]===s&&t[2]===n,!0)&&(c.add(h),M(t)?it(o,t,[s,n,h],!0):rt(r,n,[t,s,h],!0),!0)},lt=(t,e,s,n)=>{const{activeInputs:i,passiveInputs:o}=P(e),{outputs:r}=N(t),a=R(t),c=r=>{const a=X(t),c=Y(e);if(r){const e=ht(o,t,s);ot(i,t,e,!1),n||$(t)||a.connect(c,s)}else{const e=((t,e,s)=>K(t,t=>t[0]===e&&t[1]===s))(i,t,s);at(o,e,!1),n||$(t)||a.disconnect(c,s)}};return!!H(r,[e,s],t=>t[0]===e&&t[1]===s,!0)&&(a.add(c),M(t)?ot(i,t,[s,c],!0):at(o,[t,s,c],!0),!0)},pt=(t,e,s)=>{for(const n of t)if(n[0]===e&&n[1]===s)return t.delete(n),n;return null},dt=(t,e,s,n,i)=>{const[o,r]=((t,e,s,n)=>{const{activeInputs:i,passiveInputs:o}=N(e),r=pt(i[n],t,s);if(null===r){return[ct(o,t,s,n)[2],!1]}return[r[2],!0]})(t,s,n,i);if(null!==o&&(Q(t,o),!r||e||$(t)||Z(X(t),X(s),n,i)),M(s)){const{activeInputs:t}=N(s);tt(s,t)}},ft=(t,e,s,n)=>{const[i,o]=((t,e,s)=>{const{activeInputs:n,passiveInputs:i}=P(e),o=pt(n,t,s);if(null===o){return[ht(i,t,s)[1],!1]}return[o[2],!0]})(t,s,n);null!==i&&(Q(t,i),!o||e||$(t)||X(t).disconnect(Y(s),n))};class _t{constructor(t){this._map=new Map(t)}get size(){return this._map.size}entries(){return this._map.entries()}forEach(t,e=null){return this._map.forEach((s,n)=>t.call(e,s,n,this))}get(t){return this._map.get(t)}has(t){return this._map.has(t)}keys(){return this._map.keys()}values(){return this._map.values()}}const mt={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:1,numberOfOutputs:1,parameterData:{},processorOptions:{}};function gt(t,e,s,n,i){if("function"==typeof t.copyFromChannel)0===e[s].byteLength&&(e[s]=new Float32Array(128)),t.copyFromChannel(e[s],n,i);else{const o=t.getChannelData(n);if(0===e[s].byteLength)e[s]=o.slice(i,i+128);else{const t=new Float32Array(o.buffer,i*Float32Array.BYTES_PER_ELEMENT,128);e[s].set(t)}}}const vt=(t,e,s,n,i)=>{"function"==typeof t.copyToChannel?0!==e[s].byteLength&&t.copyToChannel(e[s],n,i):0!==e[s].byteLength&&t.getChannelData(n).set(e[s],i)},yt=(t,e)=>{const s=[];for(let n=0;n{const a=null===e?128*Math.ceil(t.context.length/128):e.length,c=n.channelCount*n.numberOfInputs,h=i.reduce((t,e)=>t+e,0),u=0===h?null:s.createBuffer(h,a,s.sampleRate);if(void 0===o)throw new Error("Missing the processor constructor.");const l=N(t),p=await((t,e)=>{const s=E(m,t),n=X(e);return E(s,n)})(s,t),d=yt(n.numberOfInputs,n.channelCount),f=yt(n.numberOfOutputs,i),_=Array.from(t.parameters.keys()).reduce((t,e)=>({...t,[e]:new Float32Array(128)}),{});for(let h=0;h0&&null!==e)for(let t=0;t{gt(e,_,t,c+s,h)});for(let t=0;t0===l.activeInputs[e].size?[]:t),e=r(h/s.sampleRate,s.sampleRate,()=>p.process(t,f,_));if(null!==u)for(let t=0,e=0;t{const n=e[s];if(void 0===n)throw t();return n},Dt={attack:.003,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",knee:30,ratio:12,release:.25,threshold:-24},Ot={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",gain:1},Mt=()=>new DOMException("","InvalidStateError"),Et=()=>new DOMException("","InvalidAccessError"),Rt={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers"},qt=(t,e,s,n,i,o,r,a,c,h,u)=>{const l=h.length;let p=a;for(let a=0;a{const e=new Uint32Array([1179011410,40,1163280727,544501094,16,131073,44100,176400,1048580,1635017060,4,0]);try{const s=t.decodeAudioData(e.buffer,()=>{});return void 0!==s&&(s.catch(()=>{}),!0)}catch{}return!1},Vt={numberOfChannels:1},Nt=(t,e,s)=>{const n=e[s];void 0!==n&&n!==t[s]&&(t[s]=n)},Pt=(t,e)=>{Nt(t,e,"channelCount"),Nt(t,e,"channelCountMode"),Nt(t,e,"channelInterpretation")},jt=t=>"function"==typeof t.getFloatTimeDomainData,Lt=(t,e,s)=>{const n=e[s];void 0!==n&&n!==t[s].value&&(t[s].value=n)},zt=t=>{var e;t.start=(e=t.start,(s=0,n=0,i)=>{if("number"==typeof i&&i<0||n<0||s<0)throw new RangeError("The parameters can't be negative.");e.call(t,s,n,i)})},Bt=t=>{var e;t.stop=(e=t.stop,(s=0)=>{if(s<0)throw new RangeError("The parameter can't be negative.");e.call(t,s)})},Wt=(t,e)=>null===t?512:Math.max(512,Math.min(16384,Math.pow(2,Math.round(Math.log2(t*e))))),Ut=async(t,e)=>new t(await(t=>new Promise((e,s)=>{const{port1:n,port2:i}=new MessageChannel;n.onmessage=({data:t})=>{n.close(),i.close(),e(t)},n.onmessageerror=({data:t})=>{n.close(),i.close(),s(t)},i.postMessage(t)}))(e)),Gt=(t,e)=>{const s=t.createBiquadFilter();return Pt(s,e),Lt(s,e,"Q"),Lt(s,e,"detune"),Lt(s,e,"frequency"),Lt(s,e,"gain"),Nt(s,e,"type"),s},Qt=(t,e)=>{const s=t.createChannelSplitter(e.numberOfOutputs);return Pt(s,e),(t=>{const e=t.numberOfOutputs;Object.defineProperty(t,"channelCount",{get:()=>e,set:t=>{if(t!==e)throw Mt()}}),Object.defineProperty(t,"channelCountMode",{get:()=>"explicit",set:t=>{if("explicit"!==t)throw Mt()}}),Object.defineProperty(t,"channelInterpretation",{get:()=>"discrete",set:t=>{if("discrete"!==t)throw Mt()}})})(s),s},Zt=(t,e)=>(t.connect=e.connect.bind(e),t.disconnect=e.disconnect.bind(e),t),Xt=(t,e)=>{const s=t.createDelay(e.maxDelayTime);return Pt(s,e),Lt(s,e,"delayTime"),s},Yt=(t,e)=>{const s=t.createGain();return Pt(s,e),Lt(s,e,"gain"),s};function Ht(t,e){const s=e[0]*e[0]+e[1]*e[1];return[(t[0]*e[0]+t[1]*e[1])/s,(t[1]*e[0]-t[0]*e[1])/s]}function $t(t,e){let s=[0,0];for(let o=t.length-1;o>=0;o-=1)i=e,s=[(n=s)[0]*i[0]-n[1]*i[1],n[0]*i[1]+n[1]*i[0]],s[0]+=t[o];var n,i;return s}const Jt=(t,e,s,n)=>t.createScriptProcessor(e,s,n),Kt=()=>new DOMException("","NotSupportedError"),te={numberOfChannels:1},ee={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:440,periodicWave:void 0,type:"sine"},se={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},ne={disableNormalization:!1},ie={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",pan:0},oe=()=>new DOMException("","UnknownError"),re={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",curve:null,oversample:"none"},ae=t=>{if(null===t)return!1;const e=t.length;return e%2!=0?0!==t[Math.floor(e/2)]:t[e/2-1]+t[e/2]!==0},ce=(t,e,s,n)=>{let i=Object.getPrototypeOf(t);for(;!i.hasOwnProperty(e);)i=Object.getPrototypeOf(i);const{get:o,set:r}=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,{get:s(o),set:n(r)})},he=t=>{const e=t.createOscillator();try{e.start(-1)}catch(t){return t instanceof RangeError}return!1},ue=t=>{const e=t.createBuffer(1,1,44100),s=t.createBufferSource();s.buffer=e,s.start(),s.stop();try{return s.stop(),!0}catch{return!1}},le=t=>{const e=t.createOscillator();try{e.stop(-1)}catch(t){return t instanceof RangeError}return!1},pe=()=>{try{new DOMException}catch{return!1}return!0},de=()=>new Promise(t=>{const e=new ArrayBuffer(0),{port1:s,port2:n}=new MessageChannel;s.onmessage=({data:e})=>t(null!==e),n.postMessage(e,[e])}),fe=(t,e)=>{const s=e.createGain();t.connect(s);const n=(i=t.disconnect,()=>{i.call(t,s),t.removeEventListener("ended",n)});var i;t.addEventListener("ended",n),Zt(t,s),t.stop=(e=>{let n=!1;return(i=0)=>{if(n)try{e.call(t,i)}catch{s.gain.setValueAtTime(0,i)}else e.call(t,i),n=!0}})(t.stop)},_e=(t,e)=>s=>{const n={value:t};return Object.defineProperties(s,{currentTarget:n,target:n}),"function"==typeof e?e.call(t,s):e.handleEvent.call(t,s)},me=(ge=new Map,ve=new WeakMap,(t,e)=>{const s=ve.get(t);if(void 0!==s)return s;const n=ge.get(t);if(void 0!==n)return n;try{const s=e();return s instanceof Promise?(ge.set(t,s),s.catch(()=>!1).then(e=>(ge.delete(t),ve.set(t,e),e))):(ve.set(t,s),s)}catch{return ve.set(t,!1),!1}});var ge,ve;const ye="undefined"==typeof window?null:window,xe=(we=me,be=k,(t,e)=>{const s=t.createAnalyser();if(Pt(s,e),!(e.maxDecibels>e.minDecibels))throw be();return Nt(s,e,"fftSize"),Nt(s,e,"maxDecibels"),Nt(s,e,"minDecibels"),Nt(s,e,"smoothingTimeConstant"),we(jt,()=>jt(s))||(t=>{t.getFloatTimeDomainData=e=>{const s=new Uint8Array(e.length);t.getByteTimeDomainData(s);const n=Math.max(s.length,t.fftSize);for(let t=0;t{const e=Se(t);if(null===e.renderer)throw new Error("Missing the renderer of the given AudioNode in the audio graph.");return e.renderer});var Se;const ke=((t,e,s)=>async(n,i,o,r)=>{const a=t(n),c=[...r,n];await Promise.all(a.activeInputs.map((t,r)=>Array.from(t).filter(([t])=>!c.includes(t)).map(async([t,a])=>{const h=e(t),u=await h.render(t,i,c),l=n.context.destination;s(t)||n===l&&s(n)||u.connect(o,a,r)})).reduce((t,e)=>[...t,...e],[]))})(N,Te,$),Ce=(Ae=xe,De=X,Oe=ke,()=>{const t=new WeakMap;return{render(e,s,n){const i=t.get(s);return void 0!==i?Promise.resolve(i):(async(e,s,n)=>{let i=De(e);if(!T(i,s)){const t={channelCount:i.channelCount,channelCountMode:i.channelCountMode,channelInterpretation:i.channelInterpretation,fftSize:i.fftSize,maxDecibels:i.maxDecibels,minDecibels:i.minDecibels,smoothingTimeConstant:i.smoothingTimeConstant};i=Ae(s,t)}return t.set(s,i),await Oe(e,s,i,n),i})(e,s,n)}}});var Ae,De,Oe;const Me=(Ee=p,t=>{const e=Ee.get(t);if(void 0===e)throw Mt();return e});var Ee;const Re=(t=>null===t?null:t.hasOwnProperty("OfflineAudioContext")?t.OfflineAudioContext:t.hasOwnProperty("webkitOfflineAudioContext")?t.webkitOfflineAudioContext:null)(ye),qe=(Fe=Re,t=>null!==Fe&&t instanceof Fe);var Fe;const Ie=new WeakMap,Ve=(Ne=_e,class{constructor(t){this._nativeEventTarget=t,this._listeners=new WeakMap}addEventListener(t,e,s){if(null!==e){let n=this._listeners.get(e);void 0===n&&(n=Ne(this,e),"function"==typeof e&&this._listeners.set(e,n)),this._nativeEventTarget.addEventListener(t,n,s)}}dispatchEvent(t){return this._nativeEventTarget.dispatchEvent(t)}removeEventListener(t,e,s){const n=null===e?void 0:this._listeners.get(e);this._nativeEventTarget.removeEventListener(t,void 0===n?null:n,s)}});var Ne;const Pe=(t=>null===t?null:t.hasOwnProperty("AudioContext")?t.AudioContext:t.hasOwnProperty("webkitAudioContext")?t.webkitAudioContext:null)(ye),je=(Le=Pe,t=>null!==Le&&t instanceof Le);var Le;const ze=(t=>e=>null!==t&&"function"==typeof t.AudioNode&&e instanceof t.AudioNode)(ye),Be=(t=>e=>null!==t&&"function"==typeof t.AudioParam&&e instanceof t.AudioParam)(ye),We=((t,e,s,n,i,o,r,a,c,u,l,p,f,_)=>class extends c{constructor(s,n,i,o){super(i),this._context=s,this._nativeAudioNode=i;const r=u(s);l(r)&&!0!==e(et,()=>et(r))&&(t=>{const e=new Map;var s,n;t.connect=(s=t.connect.bind(t),(t,n=0,i=0)=>{const o=nt(t)?s(t,n,i):s(t,n),r=e.get(t);return void 0===r?e.set(t,[{input:i,output:n}]):r.every(t=>t.input!==i||t.output!==n)&&r.push({input:i,output:n}),o}),t.disconnect=(n=t.disconnect,(s,i,o)=>{if(n.apply(t),void 0===s)e.clear();else if("number"==typeof s)for(const[t,n]of e){const i=n.filter(t=>t.output!==s);0===i.length?e.delete(t):e.set(t,i)}else if(e.has(s))if(void 0===i)e.delete(s);else{const t=e.get(s);if(void 0!==t){const n=t.filter(t=>t.output!==i&&(t.input!==o||void 0===o));0===n.length?e.delete(s):e.set(s,n)}}for(const[s,n]of e)n.forEach(e=>{nt(s)?t.connect(s,e.output,e.input):t.connect(s,e.output)})})})(i),h.set(this,i),d.set(this,new Set),"closed"!==s.state&&n&&q(this),t(this,o,i)}get channelCount(){return this._nativeAudioNode.channelCount}set channelCount(t){this._nativeAudioNode.channelCount=t}get channelCountMode(){return this._nativeAudioNode.channelCountMode}set channelCountMode(t){this._nativeAudioNode.channelCountMode=t}get channelInterpretation(){return this._nativeAudioNode.channelInterpretation}set channelInterpretation(t){this._nativeAudioNode.channelInterpretation=t}get context(){return this._context}get numberOfInputs(){return this._nativeAudioNode.numberOfInputs}get numberOfOutputs(){return this._nativeAudioNode.numberOfOutputs}connect(t,e=0,r=0){if(e<0||e>=this._nativeAudioNode.numberOfOutputs)throw n();const c=u(this._context),h=_(c);if(p(t)||f(t))throw i();if(B(t)){const n=X(t);try{const s=G(this._nativeAudioNode,n,e,r),i=J(this);(h||i)&&this._nativeAudioNode.disconnect(...s),"closed"!==this.context.state&&!i&&J(t)&&q(t)}catch(t){if(12===t.code)throw i();throw t}if(ut(this,t,e,r,h)){const e=a([this],t);st(e,s(h))}return t}const l=Y(t);if("playbackRate"===l.name)throw o();try{this._nativeAudioNode.connect(l,e),(h||J(this))&&this._nativeAudioNode.disconnect(l,e)}catch(t){if(12===t.code)throw i();throw t}if(lt(this,t,e,h)){const e=a([this],t);st(e,s(h))}}disconnect(t,e,s){let o;const c=u(this._context),h=_(c);if(void 0===t)o=((t,e)=>{const s=N(t),n=[];for(const i of s.outputs)W(i)?dt(t,e,...i):ft(t,e,...i),n.push(i[0]);return s.outputs.clear(),n})(this,h);else if("number"==typeof t){if(t<0||t>=this.numberOfOutputs)throw n();o=((t,e,s)=>{const n=N(t),i=[];for(const o of n.outputs)o[1]===s&&(W(o)?dt(t,e,...o):ft(t,e,...o),i.push(o[0]),n.outputs.delete(o));return i})(this,h,t)}else{if(void 0!==e&&(e<0||e>=this.numberOfOutputs))throw n();if(B(t)&&void 0!==s&&(s<0||s>=t.numberOfInputs))throw n();if(o=((t,e,s,n,i)=>{const o=N(t);return Array.from(o.outputs).filter(t=>!(t[0]!==s||void 0!==n&&t[1]!==n||void 0!==i&&t[2]!==i)).map(s=>(W(s)?dt(t,e,...s):ft(t,e,...s),o.outputs.delete(s),s[0]))})(this,h,t,e,s),0===o.length)throw i()}for(const t of o){const e=a([this],t);st(e,r)}}})((Ue=c,(t,e,s)=>{const n=[];for(let t=0;tr=>(a,c)=>{const h=t.get(a);if(void 0===h){if(!r&&o(a)){const t=n(a),{outputs:o}=s(a);for(const s of o)if(W(s)){const i=n(s[0]);e(t,i,s[1],s[2])}else{const e=i(s[0]);t.disconnect(e,s[1])}}t.set(a,c)}else t.set(a,h+c)})(f,Z,N,X,Y,M),k,Et,Kt,((t,e,s,n,i,o,r,a)=>(c,h)=>{const u=e.get(c);if(void 0===u)throw new Error("Missing the expected cycle count.");const l=o(c.context),p=a(l);if(u===h){if(e.delete(c),!p&&r(c)){const e=n(c),{outputs:o}=s(c);for(const s of o)if(W(s)){const i=n(s[0]);t(e,i,s[1],s[2])}else{const t=i(s[0]);e.connect(t,s[1])}}}else e.set(c,u-h)})(G,f,N,X,Y,Me,M,qe),((t,e,s)=>function n(i,o){const r=B(o)?o:s(t,o);if((t=>"delayTime"in t)(r))return[];if(i[0]===r)return[i];if(i.includes(r))return[];const{outputs:a}=e(r);return Array.from(a).map(t=>n([...i,r],t[0])).reduce((t,e)=>t.concat(e),[])})(Ie,N,E),Ve,Me,je,ze,Be,qe);var Ue;const Ge=((t,e,s,n,i,o)=>class extends t{constructor(t,s){const r=i(t),a={...b,...s},c=n(r,a);super(t,!1,c,o(r)?e():null),this._nativeAnalyserNode=c}get fftSize(){return this._nativeAnalyserNode.fftSize}set fftSize(t){this._nativeAnalyserNode.fftSize=t}get frequencyBinCount(){return this._nativeAnalyserNode.frequencyBinCount}get maxDecibels(){return this._nativeAnalyserNode.maxDecibels}set maxDecibels(t){const e=this._nativeAnalyserNode.maxDecibels;if(this._nativeAnalyserNode.maxDecibels=t,!(t>this._nativeAnalyserNode.minDecibels))throw this._nativeAnalyserNode.maxDecibels=e,s()}get minDecibels(){return this._nativeAnalyserNode.minDecibels}set minDecibels(t){const e=this._nativeAnalyserNode.minDecibels;if(this._nativeAnalyserNode.minDecibels=t,!(this._nativeAnalyserNode.maxDecibels>t))throw this._nativeAnalyserNode.minDecibels=e,s()}get smoothingTimeConstant(){return this._nativeAnalyserNode.smoothingTimeConstant}set smoothingTimeConstant(t){this._nativeAnalyserNode.smoothingTimeConstant=t}getByteFrequencyData(t){this._nativeAnalyserNode.getByteFrequencyData(t)}getByteTimeDomainData(t){this._nativeAnalyserNode.getByteTimeDomainData(t)}getFloatFrequencyData(t){this._nativeAnalyserNode.getFloatFrequencyData(t)}getFloatTimeDomainData(t){this._nativeAnalyserNode.getFloatTimeDomainData(t)}})(We,Ce,k,xe,Me,qe),Qe=new WeakSet,Ze=(t=>null===t?null:t.hasOwnProperty("AudioBuffer")?t.AudioBuffer:null)(ye),Xe=(Ye=new Uint32Array(1),t=>(Ye[0]=t,Ye[0]));var Ye;const He=((t,e)=>s=>{s.copyFromChannel=(n,i,o=0)=>{const r=t(o),a=t(i);if(a>=s.numberOfChannels)throw e();const c=s.length,h=s.getChannelData(a),u=n.length;for(let t=r<0?-r:0;t+r{const r=t(o),a=t(i);if(a>=s.numberOfChannels)throw e();const c=s.length,h=s.getChannelData(a),u=n.length;for(let t=r<0?-r:0;t+re=>{e.copyFromChannel=(s=>(n,i,o=0)=>{const r=t(o),a=t(i);if(r(n,i,o=0)=>{const r=t(o),a=t(i);if(r{let c=null;return class h{constructor(h){if(null===i)throw new Error("Missing the native OfflineAudioContext constructor.");const{length:u,numberOfChannels:l,sampleRate:p}={...A,...h};null===c&&(c=new i(1,1,44100));const d=null!==n&&e(o,o)?new n({length:u,numberOfChannels:l,sampleRate:p}):c.createBuffer(l,u,p);if(0===d.numberOfChannels)throw s();return"function"!=typeof d.copyFromChannel?(r(d),C(d)):e(S,()=>S(d))||a(d),t.add(d),d}static[Symbol.hasInstance](e){return null!==e&&"object"==typeof e&&Object.getPrototypeOf(e)===h.prototype||t.has(e)}}})(Qe,me,Kt,Ze,Re,(Ke=Ze,()=>{if(null===Ke)return!1;try{new Ke({length:1,sampleRate:44100})}catch{return!1}return!0}),He,$e);var Ke;const ts=(es=Yt,(t,e)=>{const s=es(t,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});e.connect(s).connect(t.destination);const n=()=>{e.removeEventListener("ended",n),e.disconnect(s),s.disconnect()};e.addEventListener("ended",n)});var es;const ss=((t,e,s)=>async(n,i,o,r)=>{const a=e(n);await Promise.all(Array.from(a.activeInputs).map(async([e,n])=>{const a=t(e),c=await a.render(e,i,r);s(e)||c.connect(o,n)}))})(Te,P,$),ns=(t=>(e,s,n,i)=>t(s,e,n,i))(ss),is=((t,e,s,n,i,o,r,a,c,h,u)=>(l,p)=>{const d=l.createBufferSource();return Pt(d,p),Lt(d,p,"playbackRate"),Nt(d,p,"buffer"),Nt(d,p,"loop"),Nt(d,p,"loopEnd"),Nt(d,p,"loopStart"),e(s,()=>s(l))||(t=>{t.start=(e=>{let s=!1;return(n=0,i=0,o)=>{if(s)throw Mt();e.call(t,n,i,o),s=!0}})(t.start)})(d),e(n,()=>n(l))||c(d),e(i,()=>i(l))||h(d,l),e(o,()=>o(l))||zt(d),e(r,()=>r(l))||u(d,l),e(a,()=>a(l))||Bt(d),t(l,d),d})(ts,me,t=>{const e=t.createBufferSource();e.start();try{e.start()}catch{return!0}return!1},t=>{const e=t.createBufferSource(),s=t.createBuffer(1,1,44100);e.buffer=s;try{e.start(0,1)}catch{return!1}return!0},t=>{const e=t.createBufferSource();e.start();try{e.stop()}catch{return!1}return!0},he,ue,le,t=>{var e;t.start=(e=t.start,(s=0,n=0,i)=>{const o=t.buffer,r=null===o?n:Math.min(o.duration,n);null!==o&&r>o.duration-.5/t.context.sampleRate?e.call(t,s,0,0):e.call(t,s,r,i)})},(os=ce,(t,e)=>{const s=e.createBuffer(1,1,e.sampleRate);null===t.buffer&&(t.buffer=s),os(t,"buffer",e=>()=>{const n=e.call(t);return n===s?null:n},e=>n=>e.call(t,null===n?s:n))}),fe);var os;const rs=((t,e)=>(s,n,i,o)=>(t(n).replay(i),e(n,s,i,o)))((t=>e=>{const s=t(e);if(null===s.renderer)throw new Error("Missing the renderer of the given AudioParam in the audio graph.");return s.renderer})(P),ss),as=((t,e,s,n,i)=>()=>{const o=new WeakMap;let r=null,a=null;return{set start(t){r=t},set stop(t){a=t},render(c,h,u){const l=o.get(h);return void 0!==l?Promise.resolve(l):(async(c,h,u)=>{let l=s(c);const p=T(l,h);if(!p){const t={buffer:l.buffer,channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,loop:l.loop,loopEnd:l.loopEnd,loopStart:l.loopStart,playbackRate:l.playbackRate.value};l=e(h,t),null!==r&&l.start(...r),null!==a&&l.stop(a)}return o.set(h,l),p?await t(h,c.playbackRate,l.playbackRate,u):await n(h,c.playbackRate,l.playbackRate,u),await i(c,h,l,u),l})(c,h,u)}}})(ns,is,X,rs,ke),cs=((t,e,s,n,i,o,a,c,h,u,l,p)=>(d,f,_,m=null,g=null)=>{const v=new r.AutomationEventList(_.defaultValue),y=f?n(v):null,x={get defaultValue(){return _.defaultValue},get maxValue(){return null===m?_.maxValue:m},get minValue(){return null===g?_.minValue:g},get value(){return _.value},set value(t){_.value=t,x.setValueAtTime(t,d.context.currentTime)},cancelAndHoldAtTime(t){if("function"==typeof _.cancelAndHoldAtTime)null===y&&v.flush(d.context.currentTime),v.add(i(t)),_.cancelAndHoldAtTime(t);else{const e=Array.from(v).pop();null===y&&v.flush(d.context.currentTime),v.add(i(t));const s=Array.from(v).pop();_.cancelScheduledValues(t),e!==s&&void 0!==s&&("exponentialRampToValue"===s.type?_.exponentialRampToValueAtTime(s.value,s.endTime):"linearRampToValue"===s.type?_.linearRampToValueAtTime(s.value,s.endTime):"setValue"===s.type?_.setValueAtTime(s.value,s.startTime):"setValueCurve"===s.type&&_.setValueCurveAtTime(s.values,s.startTime,s.duration))}return x},cancelScheduledValues:t=>(null===y&&v.flush(d.context.currentTime),v.add(o(t)),_.cancelScheduledValues(t),x),exponentialRampToValueAtTime(t,e){if(0===t)throw new RangeError;if(!Number.isFinite(e)||e<0)throw new RangeError;return null===y&&v.flush(d.context.currentTime),v.add(a(t,e)),_.exponentialRampToValueAtTime(t,e),x},linearRampToValueAtTime:(t,e)=>(null===y&&v.flush(d.context.currentTime),v.add(c(t,e)),_.linearRampToValueAtTime(t,e),x),setTargetAtTime:(t,e,s)=>(null===y&&v.flush(d.context.currentTime),v.add(h(t,e,s)),_.setTargetAtTime(t,e,s),x),setValueAtTime:(t,e)=>(null===y&&v.flush(d.context.currentTime),v.add(u(t,e)),_.setValueAtTime(t,e),x),setValueCurveAtTime(t,e,s){const n=t instanceof Float32Array?t:new Float32Array(t);if(null!==p&&"webkitAudioContext"===p.name){const t=e+s,i=d.context.sampleRate,o=Math.ceil(e*i),r=Math.floor(t*i),a=r-o,c=new Float32Array(a);for(let t=0;t{hs.set(t,{activeInputs:new Set,passiveInputs:new WeakMap,renderer:e})}),Ie,l,t=>({replay(e){for(const s of t)if("exponentialRampToValue"===s.type){const{endTime:t,value:n}=s;e.exponentialRampToValueAtTime(n,t)}else if("linearRampToValue"===s.type){const{endTime:t,value:n}=s;e.linearRampToValueAtTime(n,t)}else if("setTarget"===s.type){const{startTime:t,target:n,timeConstant:i}=s;e.setTargetAtTime(n,t,i)}else if("setValue"===s.type){const{startTime:t,value:n}=s;e.setValueAtTime(n,t)}else{if("setValueCurve"!==s.type)throw new Error("Can't apply an unknown automation.");{const{duration:t,startTime:n,values:i}=s;e.setValueCurveAtTime(i,n,t)}}}}),r.createCancelAndHoldAutomationEvent,r.createCancelScheduledValuesAutomationEvent,r.createExponentialRampToValueAutomationEvent,r.createLinearRampToValueAutomationEvent,r.createSetTargetAutomationEvent,r.createSetValueAutomationEvent,r.createSetValueCurveAutomationEvent,Pe);var hs;const us=((t,e,s,n,i,o,r,a)=>class extends t{constructor(t,n){const a=o(t),c={...I,...n},h=i(a,c),u=r(a),l=u?e():null;super(t,!1,h,l),this._audioBufferSourceNodeRenderer=l,this._isBufferNullified=!1,this._isBufferSet=null!==c.buffer,this._nativeAudioBufferSourceNode=h,this._onended=null,this._playbackRate=s(this,u,h.playbackRate,O,D)}get buffer(){return this._isBufferNullified?null:this._nativeAudioBufferSourceNode.buffer}set buffer(t){if(this._nativeAudioBufferSourceNode.buffer=t,null!==t){if(this._isBufferSet)throw n();this._isBufferSet=!0}}get loop(){return this._nativeAudioBufferSourceNode.loop}set loop(t){this._nativeAudioBufferSourceNode.loop=t}get loopEnd(){return this._nativeAudioBufferSourceNode.loopEnd}set loopEnd(t){this._nativeAudioBufferSourceNode.loopEnd=t}get loopStart(){return this._nativeAudioBufferSourceNode.loopStart}set loopStart(t){this._nativeAudioBufferSourceNode.loopStart=t}get onended(){return this._onended}set onended(t){const e="function"==typeof t?a(this,t):null;this._nativeAudioBufferSourceNode.onended=e;const s=this._nativeAudioBufferSourceNode.onended;this._onended=null!==s&&s===e?t:s}get playbackRate(){return this._playbackRate}start(t=0,e=0,s){if(this._nativeAudioBufferSourceNode.start(t,e,s),null!==this._audioBufferSourceNodeRenderer&&(this._audioBufferSourceNodeRenderer.start=void 0===s?[t,e]:[t,e,s]),"closed"!==this.context.state){q(this);const t=()=>{this._nativeAudioBufferSourceNode.removeEventListener("ended",t),setTimeout(()=>{M(this)&&F(this)},1e3)};this._nativeAudioBufferSourceNode.addEventListener("ended",t)}}stop(t=0){this._nativeAudioBufferSourceNode.stop(t),null!==this._audioBufferSourceNodeRenderer&&(this._audioBufferSourceNodeRenderer.stop=t)}})(We,as,cs,Mt,is,Me,qe,_e),ls=((t,e,s,n,i,o,r,a)=>class extends t{constructor(t,s){const n=o(t),c=r(n),h=i(n,s,c);super(t,!1,h,c?e(a):null),this._isNodeOfNativeOfflineAudioContext=c,this._nativeAudioDestinationNode=h}get channelCount(){return this._nativeAudioDestinationNode.channelCount}set channelCount(t){if(this._isNodeOfNativeOfflineAudioContext)throw n();if(t>this._nativeAudioDestinationNode.maxChannelCount)throw s();this._nativeAudioDestinationNode.channelCount=t}get channelCountMode(){return this._nativeAudioDestinationNode.channelCountMode}set channelCountMode(t){if(this._isNodeOfNativeOfflineAudioContext)throw n();this._nativeAudioDestinationNode.channelCountMode=t}get maxChannelCount(){return this._nativeAudioDestinationNode.maxChannelCount}})(We,t=>{let e=null;return{render:(s,n,i)=>(null===e&&(e=(async(e,s,n)=>{const i=s.destination;return await t(e,s,i,n),i})(s,n,i)),e)}},k,Mt,((t,e)=>(s,n,i)=>{const o=s.destination;if(o.channelCount!==n)try{o.channelCount=n}catch{}i&&"explicit"!==o.channelCountMode&&(o.channelCountMode="explicit"),0===o.maxChannelCount&&Object.defineProperty(o,"maxChannelCount",{value:n});const r=t(s,{channelCount:n,channelCountMode:o.channelCountMode,channelInterpretation:o.channelInterpretation,gain:1});return e(r,"channelCount",t=>()=>t.call(r),t=>e=>{t.call(r,e);try{o.channelCount=e}catch(t){if(e>o.maxChannelCount)throw t}}),e(r,"channelCountMode",t=>()=>t.call(r),t=>e=>{t.call(r,e),o.channelCountMode=e}),e(r,"channelInterpretation",t=>()=>t.call(r),t=>e=>{t.call(r,e),o.channelInterpretation=e}),Object.defineProperty(r,"maxChannelCount",{get:()=>o.maxChannelCount}),r.connect(o),r})(Yt,ce),Me,qe,ke),ps=((t,e,s,n,i)=>()=>{const o=new WeakMap;return{render(r,a,c){const h=o.get(a);return void 0!==h?Promise.resolve(h):(async(r,a,c)=>{let h=s(r);const u=T(h,a);if(!u){const t={Q:h.Q.value,channelCount:h.channelCount,channelCountMode:h.channelCountMode,channelInterpretation:h.channelInterpretation,detune:h.detune.value,frequency:h.frequency.value,gain:h.gain.value,type:h.type};h=e(a,t)}return o.set(a,h),u?(await t(a,r.Q,h.Q,c),await t(a,r.detune,h.detune,c),await t(a,r.frequency,h.frequency,c),await t(a,r.gain,h.gain,c)):(await n(a,r.Q,h.Q,c),await n(a,r.detune,h.detune,c),await n(a,r.frequency,h.frequency,c),await n(a,r.gain,h.gain,c)),await i(r,a,h,c),h})(r,a,c)}}})(ns,Gt,X,rs,ke),ds=(fs=We,_s=cs,ms=ps,gs=Et,vs=Gt,ys=Me,xs=qe,class extends fs{constructor(t,e){const s=ys(t),n={...wt,...e},i=vs(s,n),o=xs(s);super(t,!1,i,o?ms():null),this._Q=_s(this,o,i.Q,O,D),this._detune=_s(this,o,i.detune,1200*Math.log2(O),-1200*Math.log2(O)),this._frequency=_s(this,o,i.frequency,t.sampleRate/2,0),this._gain=_s(this,o,i.gain,40*Math.log10(O),D),this._nativeBiquadFilterNode=i}get detune(){return this._detune}get frequency(){return this._frequency}get gain(){return this._gain}get Q(){return this._Q}get type(){return this._nativeBiquadFilterNode.type}set type(t){this._nativeBiquadFilterNode.type=t}getFrequencyResponse(t,e,s){if(this._nativeBiquadFilterNode.getFrequencyResponse(t,e,s),t.length!==e.length||e.length!==s.length)throw gs()}});var fs,_s,ms,gs,vs,ys,xs;const ws=((t,e)=>(s,n,i)=>{const o=new Set;var r,a;return s.connect=(r=s.connect,(i,a=0,c=0)=>{const h=0===o.size;if(e(i))return r.call(s,i,a,c),t(o,[i,a,c],t=>t[0]===i&&t[1]===a&&t[2]===c,!0),h&&n(),i;r.call(s,i,a),t(o,[i,a],t=>t[0]===i&&t[1]===a,!0),h&&n()}),s.disconnect=(a=s.disconnect,(t,n,r)=>{const c=o.size>0;if(void 0===t)a.apply(s),o.clear();else if("number"==typeof t){a.call(s,t);for(const e of o)e[1]===t&&o.delete(e)}else{e(t)?a.call(s,t,n,r):a.call(s,t,n);for(const e of o)e[0]!==t||void 0!==n&&e[1]!==n||void 0!==r&&e[2]!==r||o.delete(e)}const h=0===o.size;c&&h&&i()}),s})(H,ze),bs=(Ts=Mt,Ss=ws,(t,e)=>{e.channelCount=1,e.channelCountMode="explicit",Object.defineProperty(e,"channelCount",{get:()=>1,set:()=>{throw Ts()}}),Object.defineProperty(e,"channelCountMode",{get:()=>"explicit",set:()=>{throw Ts()}});const s=t.createBufferSource();Ss(e,()=>{const t=e.numberOfInputs;for(let n=0;ns.disconnect(e))});var Ts,Ss;const ks=((t,e)=>(s,n)=>{const i=s.createChannelMerger(n.numberOfInputs);return null!==t&&"webkitAudioContext"===t.name&&e(s,i),Pt(i,n),i})(Pe,bs),Cs=((t,e,s,n,i)=>class extends t{constructor(t,o){const r=n(t),a={...bt,...o};super(t,!1,s(r,a),i(r)?e():null)}})(We,((t,e,s)=>()=>{const n=new WeakMap;return{render(i,o,r){const a=n.get(o);return void 0!==a?Promise.resolve(a):(async(i,o,r)=>{let a=e(i);if(!T(a,o)){const e={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,numberOfInputs:a.numberOfInputs};a=t(o,e)}return n.set(o,a),await s(i,o,a,r),a})(i,o,r)}}})(ks,X,ke),ks,Me,qe),As=((t,e,s,n,i,o)=>class extends t{constructor(t,r){const a=n(t),c=o({...Tt,...r});super(t,!1,s(a,c),i(a)?e():null)}})(We,((t,e,s)=>()=>{const n=new WeakMap;return{render(i,o,r){const a=n.get(o);return void 0!==a?Promise.resolve(a):(async(i,o,r)=>{let a=e(i);if(!T(a,o)){const e={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,numberOfOutputs:a.numberOfOutputs};a=t(o,e)}return n.set(o,a),await s(i,o,a,r),a})(i,o,r)}}})(Qt,X,ke),Qt,Me,qe,t=>({...t,channelCount:t.numberOfOutputs})),Ds=((t,e,s,n)=>(i,{offset:o,...r})=>{const a=i.createBuffer(1,2,i.sampleRate),c=e(i,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),h=s(i,{...r,gain:o}),u=a.getChannelData(0);u[0]=1,u[1]=1,c.buffer=a,c.loop=!0;const l={get bufferSize(){},get channelCount(){return h.channelCount},set channelCount(t){h.channelCount=t},get channelCountMode(){return h.channelCountMode},set channelCountMode(t){h.channelCountMode=t},get channelInterpretation(){return h.channelInterpretation},set channelInterpretation(t){h.channelInterpretation=t},get context(){return h.context},get inputs(){return[]},get numberOfInputs(){return c.numberOfInputs},get numberOfOutputs(){return h.numberOfOutputs},get offset(){return h.gain},get onended(){return c.onended},set onended(t){c.onended=t},addEventListener:(...t)=>c.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>c.dispatchEvent(t[0]),removeEventListener:(...t)=>c.removeEventListener(t[0],t[1],t[2]),start(t=0){c.start.call(c,t)},stop(t=0){c.stop.call(c,t)}};return t(i,c),n(Zt(l,h),()=>c.connect(h),()=>c.disconnect(h))})(ts,is,Yt,ws),Os=((t,e,s,n,i)=>(o,r)=>{if(void 0===o.createConstantSource)return s(o,r);const a=o.createConstantSource();return Pt(a,r),Lt(a,r,"offset"),e(n,()=>n(o))||zt(a),e(i,()=>i(o))||Bt(a),t(o,a),a})(ts,me,Ds,he,le),Ms=((t,e,s,n,i,o,r)=>class extends t{constructor(t,r){const a=i(t),c={...St,...r},h=n(a,c),u=o(a),l=u?s():null;super(t,!1,h,l),this._constantSourceNodeRenderer=l,this._nativeConstantSourceNode=h,this._offset=e(this,u,h.offset,O,D),this._onended=null}get offset(){return this._offset}get onended(){return this._onended}set onended(t){const e="function"==typeof t?r(this,t):null;this._nativeConstantSourceNode.onended=e;const s=this._nativeConstantSourceNode.onended;this._onended=null!==s&&s===e?t:s}start(t=0){if(this._nativeConstantSourceNode.start(t),null!==this._constantSourceNodeRenderer&&(this._constantSourceNodeRenderer.start=t),"closed"!==this.context.state){q(this);const t=()=>{this._nativeConstantSourceNode.removeEventListener("ended",t),setTimeout(()=>{M(this)&&F(this)},1e3)};this._nativeConstantSourceNode.addEventListener("ended",t)}}stop(t=0){this._nativeConstantSourceNode.stop(t),null!==this._constantSourceNodeRenderer&&(this._constantSourceNodeRenderer.stop=t)}})(We,cs,((t,e,s,n,i)=>()=>{const o=new WeakMap;let r=null,a=null;return{set start(t){r=t},set stop(t){a=t},render(c,h,u){const l=o.get(h);return void 0!==l?Promise.resolve(l):(async(c,h,u)=>{let l=s(c);const p=T(l,h);if(!p){const t={channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,offset:l.offset.value};l=e(h,t),null!==r&&l.start(r),null!==a&&l.stop(a)}return o.set(h,l),p?await t(h,c.offset,l.offset,u):await n(h,c.offset,l.offset,u),await i(c,h,l,u),l})(c,h,u)}}})(ns,Os,X,rs,ke),Os,Me,qe,_e),Es=((t,e)=>(s,n)=>{const i=s.createConvolver();if(Pt(i,n),n.disableNormalization===i.normalize&&(i.normalize=!n.disableNormalization),Nt(i,n,"buffer"),n.channelCount>2)throw t();if(e(i,"channelCount",t=>()=>t.call(i),e=>s=>{if(s>2)throw t();return e.call(i,s)}),"max"===n.channelCountMode)throw t();return e(i,"channelCountMode",t=>()=>t.call(i),e=>s=>{if("max"===s)throw t();return e.call(i,s)}),i})(Kt,ce),Rs=((t,e,s,n,i)=>class extends t{constructor(t,o){const r=n(t),a={...kt,...o},c=s(r,a);super(t,!1,c,i(r)?e():null),this._isBufferNullified=!1,this._nativeConvolverNode=c}get buffer(){return this._isBufferNullified?null:this._nativeConvolverNode.buffer}set buffer(t){if(this._nativeConvolverNode.buffer=t,null===t&&null!==this._nativeConvolverNode.buffer){const t=this._nativeConvolverNode.context;this._nativeConvolverNode.buffer=t.createBuffer(1,1,t.sampleRate),this._isBufferNullified=!0}else this._isBufferNullified=!1}get normalize(){return this._nativeConvolverNode.normalize}set normalize(t){this._nativeConvolverNode.normalize=t}})(We,((t,e,s)=>()=>{const n=new WeakMap;return{render(i,o,r){const a=n.get(o);return void 0!==a?Promise.resolve(a):(async(i,o,r)=>{let a=e(i);if(!T(a,o)){const e={buffer:a.buffer,channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,disableNormalization:!a.normalize};a=t(o,e)}return n.set(o,a),U(a)?await s(i,o,a.inputs[0],r):await s(i,o,a,r),a})(i,o,r)}}})(Es,X,ke),Es,Me,qe),qs=((t,e,s,n,i,o)=>class extends t{constructor(t,r){const a=i(t),c={...Ct,...r},h=n(a,c),u=o(a);super(t,!1,h,u?s(c.maxDelayTime):null),this._delayTime=e(this,u,h.delayTime)}get delayTime(){return this._delayTime}})(We,cs,((t,e,s,n,i)=>o=>{const r=new WeakMap;return{render(a,c,h){const u=r.get(c);return void 0!==u?Promise.resolve(u):(async(a,c,h)=>{let u=s(a);const l=T(u,c);if(!l){const t={channelCount:u.channelCount,channelCountMode:u.channelCountMode,channelInterpretation:u.channelInterpretation,delayTime:u.delayTime.value,maxDelayTime:o};u=e(c,t)}return r.set(c,u),l?await t(c,a.delayTime,u.delayTime,h):await n(c,a.delayTime,u.delayTime,h),await i(a,c,u,h),u})(a,c,h)}}})(ns,Xt,X,rs,ke),Xt,Me,qe),Fs=(Is=Kt,(t,e)=>{const s=t.createDynamicsCompressor();if(Pt(s,e),e.channelCount>2)throw Is();if("max"===e.channelCountMode)throw Is();return Lt(s,e,"attack"),Lt(s,e,"knee"),Lt(s,e,"ratio"),Lt(s,e,"release"),Lt(s,e,"threshold"),s});var Is;const Vs=((t,e,s,n,i,o,r)=>class extends t{constructor(t,i){const a=o(t),c={...Dt,...i},h=n(a,c),u=r(a);super(t,!1,h,u?s():null),this._attack=e(this,u,h.attack),this._knee=e(this,u,h.knee),this._nativeDynamicsCompressorNode=h,this._ratio=e(this,u,h.ratio),this._release=e(this,u,h.release),this._threshold=e(this,u,h.threshold)}get attack(){return this._attack}get channelCount(){return this._nativeDynamicsCompressorNode.channelCount}set channelCount(t){const e=this._nativeDynamicsCompressorNode.channelCount;if(this._nativeDynamicsCompressorNode.channelCount=t,t>2)throw this._nativeDynamicsCompressorNode.channelCount=e,i()}get channelCountMode(){return this._nativeDynamicsCompressorNode.channelCountMode}set channelCountMode(t){const e=this._nativeDynamicsCompressorNode.channelCountMode;if(this._nativeDynamicsCompressorNode.channelCountMode=t,"max"===t)throw this._nativeDynamicsCompressorNode.channelCountMode=e,i()}get knee(){return this._knee}get ratio(){return this._ratio}get reduction(){return"number"==typeof this._nativeDynamicsCompressorNode.reduction.value?this._nativeDynamicsCompressorNode.reduction.value:this._nativeDynamicsCompressorNode.reduction}get release(){return this._release}get threshold(){return this._threshold}})(We,cs,((t,e,s,n,i)=>()=>{const o=new WeakMap;return{render(r,a,c){const h=o.get(a);return void 0!==h?Promise.resolve(h):(async(r,a,c)=>{let h=s(r);const u=T(h,a);if(!u){const t={attack:h.attack.value,channelCount:h.channelCount,channelCountMode:h.channelCountMode,channelInterpretation:h.channelInterpretation,knee:h.knee.value,ratio:h.ratio.value,release:h.release.value,threshold:h.threshold.value};h=e(a,t)}return o.set(a,h),u?(await t(a,r.attack,h.attack,c),await t(a,r.knee,h.knee,c),await t(a,r.ratio,h.ratio,c),await t(a,r.release,h.release,c),await t(a,r.threshold,h.threshold,c)):(await n(a,r.attack,h.attack,c),await n(a,r.knee,h.knee,c),await n(a,r.ratio,h.ratio,c),await n(a,r.release,h.release,c),await n(a,r.threshold,h.threshold,c)),await i(r,a,h,c),h})(r,a,c)}}})(ns,Fs,X,rs,ke),Fs,Kt,Me,qe),Ns=((t,e,s,n,i,o)=>class extends t{constructor(t,r){const a=i(t),c={...Ot,...r},h=n(a,c),u=o(a);super(t,!1,h,u?s():null),this._gain=e(this,u,h.gain,O,D)}get gain(){return this._gain}})(We,cs,((t,e,s,n,i)=>()=>{const o=new WeakMap;return{render(r,a,c){const h=o.get(a);return void 0!==h?Promise.resolve(h):(async(r,a,c)=>{let h=s(r);const u=T(h,a);if(!u){const t={channelCount:h.channelCount,channelCountMode:h.channelCountMode,channelInterpretation:h.channelInterpretation,gain:h.gain.value};h=e(a,t)}return o.set(a,h),u?await t(a,r.gain,h.gain,c):await n(a,r.gain,h.gain,c),await i(r,a,h,c),h})(r,a,c)}}})(ns,Yt,X,rs,ke),Yt,Me,qe),Ps=((t,e,s,n)=>(i,o,{channelCount:r,channelCountMode:a,channelInterpretation:c,feedback:h,feedforward:u})=>{const l=Wt(o,i.sampleRate),p=h instanceof Float64Array?h:new Float64Array(h),d=u instanceof Float64Array?u:new Float64Array(u),f=p.length,_=d.length,m=Math.min(f,_);if(0===f||f>20)throw n();if(0===p[0])throw e();if(0===_||_>20)throw n();if(0===d[0])throw e();if(1!==p[0]){for(let t=0;t<_;t+=1)d[t]/=p[0];for(let t=1;t{const e=t.inputBuffer,s=t.outputBuffer,n=e.numberOfChannels;for(let t=0;tg.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>g.dispatchEvent(t[0]),getFrequencyResponse(e,s,n){if(e.length!==s.length||s.length!==n.length)throw t();const i=e.length;for(let t=0;tg.removeEventListener(t[0],t[1],t[2])},g)})(Et,Mt,Jt,Kt),js=((t,e,s,n)=>i=>t(It,()=>It(i))?Promise.resolve(t(n,n)).then(t=>{if(!t){const t=s(i,512,0,1);i.oncomplete=()=>{t.onaudioprocess=null,t.disconnect()},t.onaudioprocess=()=>i.currentTime,t.connect(i.destination)}return i.startRendering()}):new Promise(t=>{const s=e(i,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});i.oncomplete=e=>{s.disconnect(),t(e.renderedBuffer)},s.connect(i.destination),i.startRendering()}))(me,Yt,Jt,((t,e)=>()=>{if(null===e)return Promise.resolve(!1);const s=new e(1,1,44100),n=t(s,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});return new Promise(t=>{s.oncomplete=()=>{n.disconnect(),t(0!==s.currentTime)},s.startRendering()})})(Yt,Re)),Ls=((t,e,s,n,i)=>(o,r)=>{const a=new WeakMap;let c=null;const h=async(h,u,l)=>{let p=null,d=e(h);const f=T(d,u);if(void 0===u.createIIRFilter?p=t(u,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}):f||(d=u.createIIRFilter(r,o)),a.set(u,null===p?d:p),null!==p){if(null===c){if(null===s)throw new Error("Missing the native OfflineAudioContext constructor.");const t=new s(h.context.destination.channelCount,h.context.length,u.sampleRate);c=(async()=>{await n(h,t,t.destination,l);return((t,e,s,n)=>{const i=s instanceof Float64Array?s:new Float64Array(s),o=n instanceof Float64Array?n:new Float64Array(n),r=i.length,a=o.length,c=Math.min(r,a);if(1!==i[0]){for(let t=0;tclass extends t{constructor(t,o){const r=n(t),a=i(r),c={...Rt,...o},h=e(r,a?null:t.baseLatency,c);super(t,!1,h,a?s(c.feedback,c.feedforward):null),(t=>{var e;t.getFrequencyResponse=(e=t.getFrequencyResponse,(s,n,i)=>{if(s.length!==n.length||n.length!==i.length)throw Et();return e.call(t,s,n,i)})})(h),this._nativeIIRFilterNode=h}getFrequencyResponse(t,e,s){return this._nativeIIRFilterNode.getFrequencyResponse(t,e,s)}})(We,(zs=Ps,(t,e,s)=>{if(void 0===t.createIIRFilter)return zs(t,e,s);const n=t.createIIRFilter(s.feedforward,s.feedback);return Pt(n,s),n}),Ls,Me,qe),Ws=((t,e,s,n,i)=>(o,r)=>{const a=r.listener,{forwardX:c,forwardY:h,forwardZ:u,positionX:l,positionY:p,positionZ:d,upX:f,upY:_,upZ:m}=void 0===a.forwardX?(()=>{const c=e(r,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:9}),h=i(r),u=n(r,256,9,0),l=(e,n)=>{const i=s(r,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:n});return i.connect(c,0,e),i.start(),Object.defineProperty(i.offset,"defaultValue",{get:()=>n}),t({context:o},h,i.offset,O,D)};let p=[0,0,-1,0,1,0],d=[0,0,0];return u.onaudioprocess=({inputBuffer:t})=>{const e=[t.getChannelData(0)[0],t.getChannelData(1)[0],t.getChannelData(2)[0],t.getChannelData(3)[0],t.getChannelData(4)[0],t.getChannelData(5)[0]];e.some((t,e)=>t!==p[e])&&(a.setOrientation(...e),p=e);const s=[t.getChannelData(6)[0],t.getChannelData(7)[0],t.getChannelData(8)[0]];s.some((t,e)=>t!==d[e])&&(a.setPosition(...s),d=s)},c.connect(u),{forwardX:l(0,0),forwardY:l(1,0),forwardZ:l(2,-1),positionX:l(6,0),positionY:l(7,0),positionZ:l(8,0),upX:l(3,0),upY:l(4,1),upZ:l(5,0)}})():a;return{get forwardX(){return c},get forwardY(){return h},get forwardZ(){return u},get positionX(){return l},get positionY(){return p},get positionZ(){return d},get upX(){return f},get upY(){return _},get upZ(){return m}}})(cs,ks,Os,Jt,qe),Us=new WeakMap,Gs=((t,e,s,n,i,o)=>class extends s{constructor(s,o){super(s),this._nativeContext=s,p.set(this,s),n(s)&&i.set(s,new Set),this._destination=new t(this,o),this._listener=e(this,s),this._onstatechange=null}get currentTime(){return this._nativeContext.currentTime}get destination(){return this._destination}get listener(){return this._listener}get onstatechange(){return this._onstatechange}set onstatechange(t){const e="function"==typeof t?o(this,t):null;this._nativeContext.onstatechange=e;const s=this._nativeContext.onstatechange;this._onstatechange=null!==s&&s===e?t:s}get sampleRate(){return this._nativeContext.sampleRate}get state(){return this._nativeContext.state}})(ls,Ws,Ve,qe,Us,_e),Qs=((t,e,s,n,i,o)=>(r,a)=>{const c=r.createOscillator();return Pt(c,a),Lt(c,a,"detune"),Lt(c,a,"frequency"),void 0!==a.periodicWave?c.setPeriodicWave(a.periodicWave):Nt(c,a,"type"),e(s,()=>s(r))||zt(c),e(n,()=>n(r))||o(c,r),e(i,()=>i(r))||Bt(c),t(r,c),c})(ts,me,he,ue,le,fe),Zs=((t,e,s,n,i,o,r)=>class extends t{constructor(t,r){const a=i(t),c={...ee,...r},h=s(a,c),u=o(a),l=u?n():null,p=t.sampleRate/2;super(t,!1,h,l),this._detune=e(this,u,h.detune,153600,-153600),this._frequency=e(this,u,h.frequency,p,-p),this._nativeOscillatorNode=h,this._onended=null,this._oscillatorNodeRenderer=l,null!==this._oscillatorNodeRenderer&&void 0!==c.periodicWave&&(this._oscillatorNodeRenderer.periodicWave=c.periodicWave)}get detune(){return this._detune}get frequency(){return this._frequency}get onended(){return this._onended}set onended(t){const e="function"==typeof t?r(this,t):null;this._nativeOscillatorNode.onended=e;const s=this._nativeOscillatorNode.onended;this._onended=null!==s&&s===e?t:s}get type(){return this._nativeOscillatorNode.type}set type(t){this._nativeOscillatorNode.type=t,null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.periodicWave=null)}setPeriodicWave(t){this._nativeOscillatorNode.setPeriodicWave(t),null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.periodicWave=t)}start(t=0){if(this._nativeOscillatorNode.start(t),null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.start=t),"closed"!==this.context.state){q(this);const t=()=>{this._nativeOscillatorNode.removeEventListener("ended",t),setTimeout(()=>{M(this)&&F(this)},1e3)};this._nativeOscillatorNode.addEventListener("ended",t)}}stop(t=0){this._nativeOscillatorNode.stop(t),null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.stop=t)}})(We,cs,Qs,((t,e,s,n,i)=>()=>{const o=new WeakMap;let r=null,a=null,c=null;return{set periodicWave(t){r=t},set start(t){a=t},set stop(t){c=t},render(h,u,l){const p=o.get(u);return void 0!==p?Promise.resolve(p):(async(h,u,l)=>{let p=s(h);const d=T(p,u);if(!d){const t={channelCount:p.channelCount,channelCountMode:p.channelCountMode,channelInterpretation:p.channelInterpretation,detune:p.detune.value,frequency:p.frequency.value,periodicWave:null===r?void 0:r,type:p.type};p=e(u,t),null!==a&&p.start(a),null!==c&&p.stop(c)}return o.set(u,p),d?(await t(u,h.detune,p.detune,l),await t(u,h.frequency,p.frequency,l)):(await n(u,h.detune,p.detune,l),await n(u,h.frequency,p.frequency,l)),await i(h,u,p,l),p})(h,u,l)}}})(ns,Qs,X,rs,ke),Me,qe,_e),Xs=(Ys=is,(t,e)=>{const s=Ys(t,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),n=t.createBuffer(1,2,t.sampleRate);return s.buffer=n,s.loop=!0,s.connect(e),s.start(),()=>{s.stop(),s.disconnect(e)}});var Ys;const Hs=((t,e,s,n,i)=>(o,{curve:r,oversample:a,...c})=>{const h=o.createWaveShaper(),u=o.createWaveShaper();Pt(h,c),Pt(u,c);const l=s(o,{...c,gain:1}),p=s(o,{...c,gain:-1}),d=s(o,{...c,gain:1}),f=s(o,{...c,gain:-1});let _=null,m=!1,g=null;const v={get bufferSize(){},get channelCount(){return h.channelCount},set channelCount(t){l.channelCount=t,p.channelCount=t,h.channelCount=t,d.channelCount=t,u.channelCount=t,f.channelCount=t},get channelCountMode(){return h.channelCountMode},set channelCountMode(t){l.channelCountMode=t,p.channelCountMode=t,h.channelCountMode=t,d.channelCountMode=t,u.channelCountMode=t,f.channelCountMode=t},get channelInterpretation(){return h.channelInterpretation},set channelInterpretation(t){l.channelInterpretation=t,p.channelInterpretation=t,h.channelInterpretation=t,d.channelInterpretation=t,u.channelInterpretation=t,f.channelInterpretation=t},get context(){return h.context},get curve(){return g},set curve(s){if(null!==s&&s.length<2)throw e();if(null===s)h.curve=s,u.curve=s;else{const t=s.length,e=new Float32Array(t+2-t%2),n=new Float32Array(t+2-t%2);e[0]=s[0],n[0]=-s[t-1];const i=Math.ceil((t+1)/2),o=(t+1)/2-1;for(let r=1;rl.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>l.dispatchEvent(t[0]),removeEventListener:(...t)=>l.removeEventListener(t[0],t[1],t[2])};null!==r&&(v.curve=r instanceof Float32Array?r:new Float32Array(r)),a!==v.oversample&&(v.oversample=a);return i(Zt(v,d),()=>{l.connect(h).connect(d),l.connect(p).connect(u).connect(f).connect(d),m=!0,n(g)&&(_=t(o,l))},()=>{l.disconnect(h),h.disconnect(d),l.disconnect(p),p.disconnect(u),u.disconnect(f),f.disconnect(d),m=!1,null!==_&&(_(),_=null)})})(Xs,Mt,Yt,ae,ws),$s=((t,e,s,n,i,o,r)=>(a,c)=>{const h=a.createWaveShaper();if(null!==o&&"webkitAudioContext"===o.name)return s(a,c);Pt(h,c);const u=null===c.curve||c.curve instanceof Float32Array?c.curve:new Float32Array(c.curve);if(null!==u&&u.length<2)throw e();Nt(h,{curve:u},"curve"),Nt(h,c,"oversample");let l=null,p=!1;r(h,"curve",t=>()=>t.call(h),e=>s=>(e.call(h,s),p&&(n(s)&&null===l?l=t(a,h):n(s)||null===l||(l(),l=null)),s));return i(h,()=>{p=!0,n(h.curve)&&(l=t(a,h))},()=>{p=!1,null!==l&&(l(),l=null)})})(Xs,Mt,Hs,ae,ws,Pe,ce),Js=((t,e,s,n,i,o,r,a,c)=>(h,{coneInnerAngle:u,coneOuterAngle:l,coneOuterGain:p,distanceModel:d,maxDistance:f,orientationX:_,orientationY:m,orientationZ:g,panningModel:v,positionX:y,positionY:x,positionZ:w,refDistance:b,rolloffFactor:T,...S})=>{const k=h.createPanner();if(S.channelCount>2)throw r();if("max"===S.channelCountMode)throw r();Pt(k,S);const C={channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete"},A=s(h,{...C,channelInterpretation:"speakers",numberOfInputs:6}),D=n(h,{...S,gain:1}),O=n(h,{...C,gain:1}),M=n(h,{...C,gain:0}),E=n(h,{...C,gain:0}),R=n(h,{...C,gain:0}),q=n(h,{...C,gain:0}),F=n(h,{...C,gain:0}),I=i(h,256,6,1),V=o(h,{...C,curve:new Float32Array([1,1]),oversample:"none"});let N=[_,m,g],P=[y,x,w];I.onaudioprocess=({inputBuffer:t})=>{const e=[t.getChannelData(0)[0],t.getChannelData(1)[0],t.getChannelData(2)[0]];e.some((t,e)=>t!==N[e])&&(k.setOrientation(...e),N=e);const s=[t.getChannelData(3)[0],t.getChannelData(4)[0],t.getChannelData(5)[0]];s.some((t,e)=>t!==P[e])&&(k.setPosition(...s),P=s)},Object.defineProperty(M.gain,"defaultValue",{get:()=>0}),Object.defineProperty(E.gain,"defaultValue",{get:()=>0}),Object.defineProperty(R.gain,"defaultValue",{get:()=>0}),Object.defineProperty(q.gain,"defaultValue",{get:()=>0}),Object.defineProperty(F.gain,"defaultValue",{get:()=>0});const j={get bufferSize(){},get channelCount(){return k.channelCount},set channelCount(t){if(t>2)throw r();D.channelCount=t,k.channelCount=t},get channelCountMode(){return k.channelCountMode},set channelCountMode(t){if("max"===t)throw r();D.channelCountMode=t,k.channelCountMode=t},get channelInterpretation(){return k.channelInterpretation},set channelInterpretation(t){D.channelInterpretation=t,k.channelInterpretation=t},get coneInnerAngle(){return k.coneInnerAngle},set coneInnerAngle(t){k.coneInnerAngle=t},get coneOuterAngle(){return k.coneOuterAngle},set coneOuterAngle(t){k.coneOuterAngle=t},get coneOuterGain(){return k.coneOuterGain},set coneOuterGain(t){if(t<0||t>1)throw e();k.coneOuterGain=t},get context(){return k.context},get distanceModel(){return k.distanceModel},set distanceModel(t){k.distanceModel=t},get inputs(){return[D]},get maxDistance(){return k.maxDistance},set maxDistance(t){if(t<0)throw new RangeError;k.maxDistance=t},get numberOfInputs(){return k.numberOfInputs},get numberOfOutputs(){return k.numberOfOutputs},get orientationX(){return O.gain},get orientationY(){return M.gain},get orientationZ(){return E.gain},get panningModel(){return k.panningModel},set panningModel(t){k.panningModel=t},get positionX(){return R.gain},get positionY(){return q.gain},get positionZ(){return F.gain},get refDistance(){return k.refDistance},set refDistance(t){if(t<0)throw new RangeError;k.refDistance=t},get rolloffFactor(){return k.rolloffFactor},set rolloffFactor(t){if(t<0)throw new RangeError;k.rolloffFactor=t},addEventListener:(...t)=>D.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>D.dispatchEvent(t[0]),removeEventListener:(...t)=>D.removeEventListener(t[0],t[1],t[2])};u!==j.coneInnerAngle&&(j.coneInnerAngle=u),l!==j.coneOuterAngle&&(j.coneOuterAngle=l),p!==j.coneOuterGain&&(j.coneOuterGain=p),d!==j.distanceModel&&(j.distanceModel=d),f!==j.maxDistance&&(j.maxDistance=f),_!==j.orientationX.value&&(j.orientationX.value=_),m!==j.orientationY.value&&(j.orientationY.value=m),g!==j.orientationZ.value&&(j.orientationZ.value=g),v!==j.panningModel&&(j.panningModel=v),y!==j.positionX.value&&(j.positionX.value=y),x!==j.positionY.value&&(j.positionY.value=x),w!==j.positionZ.value&&(j.positionZ.value=w),b!==j.refDistance&&(j.refDistance=b),T!==j.rolloffFactor&&(j.rolloffFactor=T),1===N[0]&&0===N[1]&&0===N[2]||k.setOrientation(...N),0===P[0]&&0===P[1]&&0===P[2]||k.setPosition(...P);return c(Zt(j,k),()=>{D.connect(k),t(D,V,0,0),V.connect(O).connect(A,0,0),V.connect(M).connect(A,0,1),V.connect(E).connect(A,0,2),V.connect(R).connect(A,0,3),V.connect(q).connect(A,0,4),V.connect(F).connect(A,0,5),A.connect(I).connect(h.destination)},()=>{D.disconnect(k),a(D,V,0,0),V.disconnect(O),O.disconnect(A),V.disconnect(M),M.disconnect(A),V.disconnect(E),E.disconnect(A),V.disconnect(R),R.disconnect(A),V.disconnect(q),q.disconnect(A),V.disconnect(F),F.disconnect(A),A.disconnect(I),I.disconnect(h.destination)})})(G,Mt,ks,Yt,Jt,$s,Kt,Z,ws),Ks=(tn=Js,(t,e)=>{const s=t.createPanner();return void 0===s.orientationX?tn(t,e):(Pt(s,e),Lt(s,e,"orientationX"),Lt(s,e,"orientationY"),Lt(s,e,"orientationZ"),Lt(s,e,"positionX"),Lt(s,e,"positionY"),Lt(s,e,"positionZ"),Nt(s,e,"coneInnerAngle"),Nt(s,e,"coneOuterAngle"),Nt(s,e,"coneOuterGain"),Nt(s,e,"distanceModel"),Nt(s,e,"maxDistance"),Nt(s,e,"panningModel"),Nt(s,e,"refDistance"),Nt(s,e,"rolloffFactor"),s)});var tn;const en=((t,e,s,n,i,o)=>class extends t{constructor(t,r){const a=i(t),c={...se,...r},h=s(a,c),u=o(a);super(t,!1,h,u?n():null),this._nativePannerNode=h,this._orientationX=e(this,u,h.orientationX,O,D),this._orientationY=e(this,u,h.orientationY,O,D),this._orientationZ=e(this,u,h.orientationZ,O,D),this._positionX=e(this,u,h.positionX,O,D),this._positionY=e(this,u,h.positionY,O,D),this._positionZ=e(this,u,h.positionZ,O,D)}get coneInnerAngle(){return this._nativePannerNode.coneInnerAngle}set coneInnerAngle(t){this._nativePannerNode.coneInnerAngle=t}get coneOuterAngle(){return this._nativePannerNode.coneOuterAngle}set coneOuterAngle(t){this._nativePannerNode.coneOuterAngle=t}get coneOuterGain(){return this._nativePannerNode.coneOuterGain}set coneOuterGain(t){this._nativePannerNode.coneOuterGain=t}get distanceModel(){return this._nativePannerNode.distanceModel}set distanceModel(t){this._nativePannerNode.distanceModel=t}get maxDistance(){return this._nativePannerNode.maxDistance}set maxDistance(t){this._nativePannerNode.maxDistance=t}get orientationX(){return this._orientationX}get orientationY(){return this._orientationY}get orientationZ(){return this._orientationZ}get panningModel(){return this._nativePannerNode.panningModel}set panningModel(t){this._nativePannerNode.panningModel=t}get positionX(){return this._positionX}get positionY(){return this._positionY}get positionZ(){return this._positionZ}get refDistance(){return this._nativePannerNode.refDistance}set refDistance(t){this._nativePannerNode.refDistance=t}get rolloffFactor(){return this._nativePannerNode.rolloffFactor}set rolloffFactor(t){this._nativePannerNode.rolloffFactor=t}})(We,cs,Ks,((t,e,s,n,i,o,r,a,c,h)=>()=>{const u=new WeakMap;let l=null;return{render(p,d,f){const _=u.get(d);return void 0!==_?Promise.resolve(_):(async(p,d,f)=>{let _=null,m=o(p);const g={channelCount:m.channelCount,channelCountMode:m.channelCountMode,channelInterpretation:m.channelInterpretation},v={...g,coneInnerAngle:m.coneInnerAngle,coneOuterAngle:m.coneOuterAngle,coneOuterGain:m.coneOuterGain,distanceModel:m.distanceModel,maxDistance:m.maxDistance,panningModel:m.panningModel,refDistance:m.refDistance,rolloffFactor:m.rolloffFactor},y=T(m,d);if("bufferSize"in m)_=n(d,{...g,gain:1});else if(!y){const t={...v,orientationX:m.orientationX.value,orientationY:m.orientationY.value,orientationZ:m.orientationZ.value,positionX:m.positionX.value,positionY:m.positionY.value,positionZ:m.positionZ.value};m=i(d,t)}if(u.set(d,null===_?m:_),null!==_){if(null===l){if(null===r)throw new Error("Missing the native OfflineAudioContext constructor.");const t=new r(6,p.context.length,d.sampleRate),n=e(t,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:6});n.connect(t.destination),l=(async()=>{const e=await Promise.all([p.orientationX,p.orientationY,p.orientationZ,p.positionX,p.positionY,p.positionZ].map(async(e,n)=>{const i=s(t,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:0===n?1:0});return await a(t,e,i.offset,f),i}));for(let t=0;t<6;t+=1)e[t].connect(n,0,t),e[t].start(0);return h(t)})()}const t=await l,o=n(d,{...g,gain:1});await c(p,d,o,f);const u=[];for(let e=0;et!==m[e])||s.some((t,e)=>t!==y[e])){m=t,y=s;const r=e/d.sampleRate;x.gain.setValueAtTime(0,r),x=n(d,{...g,gain:0}),w=i(d,{...v,orientationX:m[0],orientationY:m[1],orientationZ:m[2],positionX:y[0],positionY:y[1],positionZ:y[2]}),x.gain.setValueAtTime(1,r),o.connect(x).connect(w.inputs[0]),w.connect(_)}}return _}return y?(await t(d,p.orientationX,m.orientationX,f),await t(d,p.orientationY,m.orientationY,f),await t(d,p.orientationZ,m.orientationZ,f),await t(d,p.positionX,m.positionX,f),await t(d,p.positionY,m.positionY,f),await t(d,p.positionZ,m.positionZ,f)):(await a(d,p.orientationX,m.orientationX,f),await a(d,p.orientationY,m.orientationY,f),await a(d,p.orientationZ,m.orientationZ,f),await a(d,p.positionX,m.positionX,f),await a(d,p.positionY,m.positionY,f),await a(d,p.positionZ,m.positionZ,f)),U(m)?await c(p,d,m.inputs[0],f):await c(p,d,m,f),m})(p,d,f)}}})(ns,ks,Os,Yt,Ks,X,Re,rs,ke,js),Me,qe),sn=((t,e,s,n)=>class i{constructor(i,o){const r=e(i),a=n({...ne,...o}),c=t(r,a);return s.add(c),c}static[Symbol.hasInstance](t){return null!==t&&"object"==typeof t&&Object.getPrototypeOf(t)===i.prototype||s.has(t)}})((t=>(e,{disableNormalization:s,imag:n,real:i})=>{const o=n instanceof Float32Array?n:new Float32Array(n),r=i instanceof Float32Array?i:new Float32Array(i),a=e.createPeriodicWave(r,o,{disableNormalization:s});if(Array.from(n).length<2)throw t();return a})(k),Me,new WeakSet,t=>{const{imag:e,real:s}=t;return void 0===e?void 0===s?{...t,imag:[0,0],real:[0,0]}:{...t,imag:Array.from(s,()=>0),real:s}:void 0===s?{...t,imag:e,real:Array.from(e,()=>0)}:{...t,imag:e,real:s}}),nn=((t,e)=>(s,n)=>{const i=n.channelCountMode;if("clamped-max"===i)throw e();if(void 0===s.createStereoPanner)return t(s,n);const o=s.createStereoPanner();return Pt(o,n),Lt(o,n,"pan"),Object.defineProperty(o,"channelCountMode",{get:()=>i,set:t=>{if(t!==i)throw e()}}),o})(((t,e,s,n,i,o)=>{const r=new Float32Array([1,1]),a=Math.PI/2,c={channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete"},h={...c,oversample:"none"},u=(t,o,u,l,p)=>{if(1===o)return((t,e,i,o)=>{const u=new Float32Array(16385),l=new Float32Array(16385);for(let t=0;t<16385;t+=1){const e=t/16384*a;u[t]=Math.cos(e),l[t]=Math.sin(e)}const p=s(t,{...c,gain:0}),d=n(t,{...h,curve:u}),f=n(t,{...h,curve:r}),_=s(t,{...c,gain:0}),m=n(t,{...h,curve:l});return{connectGraph(){e.connect(p),e.connect(f.inputs[0]),e.connect(_),f.connect(i),i.connect(d.inputs[0]),i.connect(m.inputs[0]),d.connect(p.gain),m.connect(_.gain),p.connect(o,0,0),_.connect(o,0,1)},disconnectGraph(){e.disconnect(p),e.disconnect(f.inputs[0]),e.disconnect(_),f.disconnect(i),i.disconnect(d.inputs[0]),i.disconnect(m.inputs[0]),d.disconnect(p.gain),m.disconnect(_.gain),p.disconnect(o,0,0),_.disconnect(o,0,1)}}})(t,u,l,p);if(2===o)return((t,i,o,u)=>{const l=new Float32Array(16385),p=new Float32Array(16385),d=new Float32Array(16385),f=new Float32Array(16385),_=Math.floor(8192.5);for(let t=0;t<16385;t+=1)if(t>_){const e=(t-_)/(16384-_)*a;l[t]=Math.cos(e),p[t]=Math.sin(e),d[t]=0,f[t]=1}else{const e=t/(16384-_)*a;l[t]=1,p[t]=0,d[t]=Math.cos(e),f[t]=Math.sin(e)}const m=e(t,{channelCount:2,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:2}),g=s(t,{...c,gain:0}),v=n(t,{...h,curve:l}),y=s(t,{...c,gain:0}),x=n(t,{...h,curve:p}),w=n(t,{...h,curve:r}),b=s(t,{...c,gain:0}),T=n(t,{...h,curve:d}),S=s(t,{...c,gain:0}),k=n(t,{...h,curve:f});return{connectGraph(){i.connect(m),i.connect(w.inputs[0]),m.connect(g,0),m.connect(y,0),m.connect(b,1),m.connect(S,1),w.connect(o),o.connect(v.inputs[0]),o.connect(x.inputs[0]),o.connect(T.inputs[0]),o.connect(k.inputs[0]),v.connect(g.gain),x.connect(y.gain),T.connect(b.gain),k.connect(S.gain),g.connect(u,0,0),b.connect(u,0,0),y.connect(u,0,1),S.connect(u,0,1)},disconnectGraph(){i.disconnect(m),i.disconnect(w.inputs[0]),m.disconnect(g,0),m.disconnect(y,0),m.disconnect(b,1),m.disconnect(S,1),w.disconnect(o),o.disconnect(v.inputs[0]),o.disconnect(x.inputs[0]),o.disconnect(T.inputs[0]),o.disconnect(k.inputs[0]),v.disconnect(g.gain),x.disconnect(y.gain),T.disconnect(b.gain),k.disconnect(S.gain),g.disconnect(u,0,0),b.disconnect(u,0,0),y.disconnect(u,0,1),S.disconnect(u,0,1)}}})(t,u,l,p);throw i()};return(e,{channelCount:n,channelCountMode:r,pan:a,...c})=>{if("max"===r)throw i();const h=t(e,{...c,channelCount:1,channelCountMode:r,numberOfInputs:2}),l=s(e,{...c,channelCount:n,channelCountMode:r,gain:1}),p=s(e,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:a});let{connectGraph:d,disconnectGraph:f}=u(e,n,l,p,h);Object.defineProperty(p.gain,"defaultValue",{get:()=>0}),Object.defineProperty(p.gain,"minValue",{get:()=>-1});const _={get bufferSize(){},get channelCount(){return l.channelCount},set channelCount(t){l.channelCount!==t&&(m&&f(),({connectGraph:d,disconnectGraph:f}=u(e,t,l,p,h)),m&&d()),l.channelCount=t},get channelCountMode(){return l.channelCountMode},set channelCountMode(t){if("clamped-max"===t||"max"===t)throw i();l.channelCountMode=t},get channelInterpretation(){return l.channelInterpretation},set channelInterpretation(t){l.channelInterpretation=t},get context(){return l.context},get inputs(){return[l]},get numberOfInputs(){return l.numberOfInputs},get numberOfOutputs(){return l.numberOfOutputs},get pan(){return p.gain},addEventListener:(...t)=>l.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>l.dispatchEvent(t[0]),removeEventListener:(...t)=>l.removeEventListener(t[0],t[1],t[2])};let m=!1;return o(Zt(_,h),()=>{d(),m=!0},()=>{f(),m=!1})}})(ks,Qt,Yt,$s,Kt,ws),Kt),on=((t,e,s,n,i,o)=>class extends t{constructor(t,r){const a=i(t),c={...ie,...r},h=s(a,c),u=o(a);super(t,!1,h,u?n():null),this._pan=e(this,u,h.pan)}get pan(){return this._pan}})(We,cs,nn,((t,e,s,n,i)=>()=>{const o=new WeakMap;return{render(r,a,c){const h=o.get(a);return void 0!==h?Promise.resolve(h):(async(r,a,c)=>{let h=s(r);const u=T(h,a);if(!u){const t={channelCount:h.channelCount,channelCountMode:h.channelCountMode,channelInterpretation:h.channelInterpretation,pan:h.pan.value};h=e(a,t)}return o.set(a,h),u?await t(a,r.pan,h.pan,c):await n(a,r.pan,h.pan,c),U(h)?await i(r,a,h.inputs[0],c):await i(r,a,h,c),h})(r,a,c)}}})(ns,nn,X,rs,ke),Me,qe),rn=((t,e,s)=>()=>{const n=new WeakMap;return{render(i,o,r){const a=n.get(o);return void 0!==a?Promise.resolve(a):(async(i,o,r)=>{let a=e(i);if(!T(a,o)){const e={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,curve:a.curve,oversample:a.oversample};a=t(o,e)}return n.set(o,a),U(a)?await s(i,o,a.inputs[0],r):await s(i,o,a,r),a})(i,o,r)}}})($s,X,ke),an=((t,e,s,n,i,o)=>class extends t{constructor(t,e){const r=i(t),a={...re,...e},c=s(r,a);super(t,!0,c,o(r)?n():null),this._isCurveNullified=!1,this._nativeWaveShaperNode=c}get curve(){return this._isCurveNullified?null:this._nativeWaveShaperNode.curve}set curve(t){if(null===t)this._isCurveNullified=!0,this._nativeWaveShaperNode.curve=new Float32Array([0,0]);else{if(t.length<2)throw e();this._isCurveNullified=!1,this._nativeWaveShaperNode.curve=t}}get oversample(){return this._nativeWaveShaperNode.oversample}set oversample(t){this._nativeWaveShaperNode.oversample=t}})(We,Mt,$s,rn,Me,qe),cn=(t=>null!==t&&t.isSecureContext)(ye),hn=(t=>(e,s,n)=>{Object.defineProperties(t,{currentFrame:{configurable:!0,get:()=>Math.round(e*s)},currentTime:{configurable:!0,get:()=>e}});try{return n()}finally{null!==t&&(delete t.currentFrame,delete t.currentTime)}})(ye),un=new WeakMap,ln=((t,e)=>s=>{let n=t.get(s);if(void 0!==n)return n;if(null===e)throw new Error("Missing the native OfflineAudioContext constructor.");return n=new e(1,1,8e3),t.set(s,n),n})(un,Re),pn=(t=>null===t?null:t.hasOwnProperty("AudioWorkletNode")?t.AudioWorkletNode:null)(ye),dn=cn?((t,e,s,n,i,o,r,a,c,h,u,l)=>(p,d,f={credentials:"omit"})=>{const m=o(p),g=new URL(d,l.location.href).toString();if(void 0!==m.audioWorklet)return Promise.all([i(d),Promise.resolve(t(u,u))]).then(([t,e])=>{const[s,n]=y(t,g),i=e?n:n.replace(/\s+extends\s+AudioWorkletProcessor\s*{/," extends (class extends AudioWorkletProcessor {__b=new WeakSet();constructor(){super();(p=>p.postMessage=(q=>(m,t)=>q.call(p,m,t?t.filter(u=>!this.__b.has(u)):t))(p.postMessage))(this.port)}}){"),o=new Blob([`${s};(registerProcessor=>{${i}\n})((n,p)=>registerProcessor(n,class extends p{${e?"":"__c = (a) => a.forEach(e=>this.__b.add(e.buffer));"}process(i,o,p){${e?"":"i.forEach(this.__c);o.forEach(this.__c);this.__c(Object.values(p));"}return super.process(i.map(j=>j.some(k=>k.length===0)?[]:j),o,p)}}))`],{type:"application/javascript; charset=utf-8"}),c=URL.createObjectURL(o);return m.audioWorklet.addModule(c,f).then(()=>{if(a(m))return;return r(m).audioWorklet.addModule(c,f)}).finally(()=>URL.revokeObjectURL(c))});const v=h.get(p);if(void 0!==v&&v.has(d))return Promise.resolve();const b=c.get(p);if(void 0!==b){const t=b.get(d);if(void 0!==t)return t}const T=i(d).then(t=>{const[e,n]=y(t,g);return s(`${e};((a,b)=>{(a[b]=a[b]||[]).push((AudioWorkletProcessor,global,registerProcessor,sampleRate,self,window)=>{${n}\n})})(window,'_AWGS')`)}).then(()=>{const t=l._AWGS.pop();if(void 0===t)throw new SyntaxError;n(m.currentTime,m.sampleRate,()=>t(class{},void 0,(t,s)=>{if(""===t.trim())throw e();const n=_.get(m);if(void 0!==n){if(n.has(t))throw e();w(s),x(s.parameterDescriptors),n.set(t,s)}else w(s),x(s.parameterDescriptors),_.set(m,new Map([[t,s]]))},m.sampleRate,void 0,void 0))});return void 0===b?c.set(p,new Map([[d,T]])):b.set(d,T),T.then(()=>{const t=h.get(p);void 0===t?h.set(p,new Set([d])):t.add(d)}).finally(()=>{const t=c.get(p);void 0!==t&&t.delete(d)}),T})(me,Kt,(t=>e=>new Promise((s,n)=>{if(null===t)return void n(new SyntaxError);const i=t.document.head;if(null===i)n(new SyntaxError);else{const o=t.document.createElement("script"),r=new Blob([e],{type:"application/javascript"}),a=URL.createObjectURL(r),c=t.onerror,h=()=>{t.onerror=c,URL.revokeObjectURL(a)};t.onerror=(e,s,i,o,r)=>s===a||s===t.location.href&&1===i&&1===o?(h(),n(r),!1):null!==c?c(e,s,i,o,r):void 0,o.onerror=()=>{h(),n(new SyntaxError)},o.onload=()=>{h(),s()},o.src=a,o.type="module",i.appendChild(o)}}))(ye),hn,(t=>async e=>{try{const t=await fetch(e);if(t.ok)return t.text()}catch{}throw t()})(()=>new DOMException("","AbortError")),Me,ln,qe,new WeakMap,new WeakMap,((t,e)=>async()=>{if(null===t)return!0;if(null===e)return!1;const s=new Blob(['class A extends AudioWorkletProcessor{process(i){this.port.postMessage(i,[i[0][0].buffer])}}registerProcessor("a",A)'],{type:"application/javascript; charset=utf-8"}),n=new e(1,128,8e3),i=URL.createObjectURL(s);let o=!1,r=!1;try{await n.audioWorklet.addModule(i);const e=new t(n,"a",{numberOfOutputs:0}),s=n.createOscillator();e.port.onmessage=()=>o=!0,e.onprocessorerror=()=>r=!0,s.connect(e),await n.startRendering()}catch{}finally{URL.revokeObjectURL(i)}return o&&!r})(pn,Re),ye):void 0,fn=((t,e)=>s=>t(s)||e(s))(je,qe),_n=((t,e,s,n,i,o,r,a,c,h,u,l,p,d,f,_,m,g,v,y)=>class extends f{constructor(e,s){super(e,s),this._nativeContext=e,this._audioWorklet=void 0===t?void 0:{addModule:(e,s)=>t(this,e,s)}}get audioWorklet(){return this._audioWorklet}createAnalyser(){return new e(this)}createBiquadFilter(){return new i(this)}createBuffer(t,e,n){return new s({length:e,numberOfChannels:t,sampleRate:n})}createBufferSource(){return new n(this)}createChannelMerger(t=6){return new o(this,{numberOfInputs:t})}createChannelSplitter(t=6){return new r(this,{numberOfOutputs:t})}createConstantSource(){return new a(this)}createConvolver(){return new c(this)}createDelay(t=1){return new u(this,{maxDelayTime:t})}createDynamicsCompressor(){return new l(this)}createGain(){return new p(this)}createIIRFilter(t,e){return new d(this,{feedback:e,feedforward:t})}createOscillator(){return new _(this)}createPanner(){return new m(this)}createPeriodicWave(t,e,s={disableNormalization:!1}){return new g(this,{...s,imag:e,real:t})}createStereoPanner(){return new v(this)}createWaveShaper(){return new y(this)}decodeAudioData(t,e,s){return h(this._nativeContext,t).then(t=>("function"==typeof e&&e(t),t)).catch(t=>{throw"function"==typeof s&&s(t),t})}})(dn,Ge,Je,us,ds,Cs,As,Ms,Rs,((t,e,s,n,i,o,r,a,c,h,u)=>(l,p)=>{const d=r(l)?l:o(l);if(i.has(p)){const t=s();return Promise.reject(t)}try{i.add(p)}catch{}return e(c,()=>c(d))?d.decodeAudioData(p).then(s=>(e(a,()=>a(s))||u(s),t.add(s),s)):new Promise((e,s)=>{const i=()=>{try{(t=>{const{port1:e}=new MessageChannel;e.postMessage(t,[t])})(p)}catch{}},o=t=>{s(t),i()};try{d.decodeAudioData(p,s=>{"function"!=typeof s.copyFromChannel&&(h(s),C(s)),t.add(s),i(),e(s)},t=>{o(null===t?n():t)})}catch(t){o(t)}})})(Qe,me,()=>new DOMException("","DataCloneError"),()=>new DOMException("","EncodingError"),new WeakSet,Me,fn,S,It,He,$e),qs,Vs,Ns,Bs,Gs,Zs,en,sn,on,an),mn=((t,e,s,n)=>class extends t{constructor(t,i){const o=s(t),r=e(o,i);if(n(o))throw TypeError();super(t,!0,r,null),this._nativeMediaElementAudioSourceNode=r}get mediaElement(){return this._nativeMediaElementAudioSourceNode.mediaElement}})(We,(t,e)=>t.createMediaElementSource(e.mediaElement),Me,qe),gn=((t,e,s,n)=>class extends t{constructor(t,i){const o=s(t);if(n(o))throw new TypeError;const r={...Ft,...i},a=e(o,r);super(t,!1,a,null),this._nativeMediaStreamAudioDestinationNode=a}get stream(){return this._nativeMediaStreamAudioDestinationNode.stream}})(We,(t,e)=>{const s=t.createMediaStreamDestination();return Pt(s,e),1===s.numberOfOutputs&&Object.defineProperty(s,"numberOfOutputs",{get:()=>0}),s},Me,qe),vn=((t,e,s,n)=>class extends t{constructor(t,i){const o=s(t),r=e(o,i);if(n(o))throw new TypeError;super(t,!0,r,null),this._nativeMediaStreamAudioSourceNode=r}get mediaStream(){return this._nativeMediaStreamAudioSourceNode.mediaStream}})(We,(t,{mediaStream:e})=>{const s=e.getAudioTracks();s.sort((t,e)=>t.ide.id?1:0);const n=s.slice(0,1),i=t.createMediaStreamSource(new MediaStream(n));return Object.defineProperty(i,"mediaStream",{value:e}),i},Me,qe),yn=((t,e,s)=>class extends t{constructor(t,n){const i=s(t);super(t,!0,e(i,n),null)}})(We,((t,e)=>(s,{mediaStreamTrack:n})=>{if("function"==typeof s.createMediaStreamTrackSource)return s.createMediaStreamTrackSource(n);const i=new MediaStream([n]),o=s.createMediaStreamSource(i);if("audio"!==n.kind)throw t();if(e(s))throw new TypeError;return o})(Mt,qe),Me),xn=((t,e,s,n,i,o,r,a,c)=>class extends t{constructor(t={}){if(null===c)throw new Error("Missing the native AudioContext constructor.");const e=new c(t);if(null===e)throw n();if(!z(t.latencyHint))throw new TypeError(`The provided value '${t.latencyHint}' is not a valid enum value of type AudioContextLatencyCategory.`);if(void 0!==t.sampleRate&&e.sampleRate!==t.sampleRate)throw s();super(e,2);const{latencyHint:i}=t,{sampleRate:o}=e;if(this._baseLatency="number"==typeof e.baseLatency?e.baseLatency:"balanced"===i?512/o:"interactive"===i||void 0===i?256/o:"playback"===i?1024/o:128*Math.max(2,Math.min(128,Math.round(i*o/128)))/o,this._nativeAudioContext=e,"webkitAudioContext"===c.name?(this._nativeGainNode=e.createGain(),this._nativeOscillatorNode=e.createOscillator(),this._nativeGainNode.gain.value=1e-37,this._nativeOscillatorNode.connect(this._nativeGainNode).connect(e.destination),this._nativeOscillatorNode.start()):(this._nativeGainNode=null,this._nativeOscillatorNode=null),this._state=null,"running"===e.state){this._state="suspended";const t=()=>{"suspended"===this._state&&(this._state=null),e.removeEventListener("statechange",t)};e.addEventListener("statechange",t)}}get baseLatency(){return this._baseLatency}get state(){return null!==this._state?this._state:this._nativeAudioContext.state}close(){return"closed"===this.state?this._nativeAudioContext.close().then(()=>{throw e()}):("suspended"===this._state&&(this._state=null),this._nativeAudioContext.close().then(()=>{null!==this._nativeGainNode&&null!==this._nativeOscillatorNode&&(this._nativeOscillatorNode.stop(),this._nativeGainNode.disconnect(),this._nativeOscillatorNode.disconnect()),L(this)}))}createMediaElementSource(t){return new i(this,{mediaElement:t})}createMediaStreamDestination(){return new o(this)}createMediaStreamSource(t){return new r(this,{mediaStream:t})}createMediaStreamTrackSource(t){return new a(this,{mediaStreamTrack:t})}resume(){return"suspended"===this._state?new Promise((t,e)=>{const s=()=>{this._nativeAudioContext.removeEventListener("statechange",s),"running"===this._nativeAudioContext.state?t():this.resume().then(t,e)};this._nativeAudioContext.addEventListener("statechange",s)}):this._nativeAudioContext.resume().catch(t=>{if(void 0===t||15===t.code)throw e();throw t})}suspend(){return this._nativeAudioContext.suspend().catch(t=>{if(void 0===t)throw e();throw t})}})(_n,Mt,Kt,oe,mn,gn,vn,yn,Pe),wn=(bn=Us,t=>{const e=bn.get(t);if(void 0===e)throw new Error("The context has no set of AudioWorkletNodes.");return e});var bn;const Tn=(Sn=wn,(t,e)=>{Sn(t).add(e)});var Sn;const kn=(t=>(e,s,n=0,i=0)=>{const o=e[n];if(void 0===o)throw t();return nt(s)?o.connect(s,0,i):o.connect(s,0)})(k),Cn=(t=>(e,s)=>{t(e).delete(s)})(wn),An=(t=>(e,s,n,i=0)=>void 0===s?e.forEach(t=>t.disconnect()):"number"==typeof s?At(t,e,s).disconnect():nt(s)?void 0===n?e.forEach(t=>t.disconnect(s)):void 0===i?At(t,e,n).disconnect(s,0):At(t,e,n).disconnect(s,0,i):void 0===n?e.forEach(t=>t.disconnect(s)):At(t,e,n).disconnect(s,0))(k),Dn=new WeakMap,On=((t,e)=>s=>e(t,s))(Dn,E),Mn=((t,e,s,n,i,o,r,a,c,h,u,l,p)=>(d,f,_,g)=>{if(0===g.numberOfInputs&&0===g.numberOfOutputs)throw c();const v=Array.isArray(g.outputChannelCount)?g.outputChannelCount:Array.from(g.outputChannelCount);if(v.some(t=>t<1))throw c();if(v.length!==g.numberOfOutputs)throw e();if("explicit"!==g.channelCountMode)throw c();const y=g.channelCount*g.numberOfInputs,x=v.reduce((t,e)=>t+e,0),w=void 0===_.parameterDescriptors?0:_.parameterDescriptors.length;if(y+w>6||x>6)throw c();const b=new MessageChannel,T=[],S=[];for(let t=0;tvoid 0===t?0:t},maxValue:{get:()=>void 0===e?O:e},minValue:{get:()=>void 0===s?D:s}}),k.push(i)}const C=n(d,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:Math.max(1,y+w)}),A=Wt(f,d.sampleRate),M=a(d,A,y+w,Math.max(1,x)),E=i(d,{channelCount:Math.max(1,x),channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:Math.max(1,x)}),R=[];for(let t=0;t{const s=k[e];return s.connect(C,0,y+e),s.start(0),[t,s.offset]}));C.connect(M);let F=g.channelInterpretation,I=null;const V=0===g.numberOfOutputs?[M]:R,N={get bufferSize(){return A},get channelCount(){return g.channelCount},set channelCount(t){throw s()},get channelCountMode(){return g.channelCountMode},set channelCountMode(t){throw s()},get channelInterpretation(){return F},set channelInterpretation(t){for(const e of T)e.channelInterpretation=t;F=t},get context(){return M.context},get inputs(){return T},get numberOfInputs(){return g.numberOfInputs},get numberOfOutputs(){return g.numberOfOutputs},get onprocessorerror(){return I},set onprocessorerror(t){"function"==typeof I&&N.removeEventListener("processorerror",I),I="function"==typeof t?t:null,"function"==typeof I&&N.addEventListener("processorerror",I)},get parameters(){return q},get port(){return b.port2},addEventListener:(...t)=>M.addEventListener(t[0],t[1],t[2]),connect:t.bind(null,V),disconnect:h.bind(null,V),dispatchEvent:(...t)=>M.dispatchEvent(t[0]),removeEventListener:(...t)=>M.removeEventListener(t[0],t[1],t[2])},P=new Map;var j,L;b.port1.addEventListener=(j=b.port1.addEventListener,(...t)=>{if("message"===t[0]){const e="function"==typeof t[1]?t[1]:"object"==typeof t[1]&&null!==t[1]&&"function"==typeof t[1].handleEvent?t[1].handleEvent:null;if(null!==e){const s=P.get(t[1]);void 0!==s?t[1]=s:(t[1]=t=>{u(d.currentTime,d.sampleRate,()=>e(t))},P.set(e,t[1]))}}return j.call(b.port1,t[0],t[1],t[2])}),b.port1.removeEventListener=(L=b.port1.removeEventListener,(...t)=>{if("message"===t[0]){const e=P.get(t[1]);void 0!==e&&(P.delete(t[1]),t[1]=e)}return L.call(b.port1,t[0],t[1],t[2])});let z=null;Object.defineProperty(b.port1,"onmessage",{get:()=>z,set:t=>{"function"==typeof z&&b.port1.removeEventListener("message",z),z="function"==typeof t?t:null,"function"==typeof z&&(b.port1.addEventListener("message",z),b.port1.start())}}),_.prototype.port=b.port1;let B=null;((t,e,s,n)=>{let i=m.get(t);void 0===i&&(i=new WeakMap,m.set(t,i));const o=Ut(s,n);return i.set(e,o),o})(d,N,_,g).then(t=>B=t);const W=yt(g.numberOfInputs,g.channelCount),U=yt(g.numberOfOutputs,v),G=void 0===_.parameterDescriptors?[]:_.parameterDescriptors.reduce((t,{name:e})=>({...t,[e]:new Float32Array(128)}),{});let Q=!0;const Z=()=>{g.numberOfOutputs>0&&M.disconnect(E);for(let t=0,e=0;t{if(null!==B)for(let s=0;s{gt(t,G,e,y+n,s)});for(let t=0;tt[s].size>0?e:[]),i=u(d.currentTime+s/d.sampleRate,d.sampleRate,()=>B.process(n,U,G));Q=i;for(let t=0,n=0;tM.connect(Y).connect(d.destination),$=()=>{M.disconnect(Y),Y.disconnect()};return H(),p(N,()=>{if(Q){$(),g.numberOfOutputs>0&&M.connect(E);for(let t=0,e=0;t{Q&&(H(),Z()),X=!1})})(kn,k,Mt,ks,Qt,Os,Yt,Jt,Kt,An,hn,On,ws),En=((t,e,s,n,i)=>(o,r,a,c,h,u)=>{if(null!==a)try{const e=new a(o,c,u),n=new Map;let r=null;if(Object.defineProperties(e,{channelCount:{get:()=>u.channelCount,set:()=>{throw t()}},channelCountMode:{get:()=>"explicit",set:()=>{throw t()}},onprocessorerror:{get:()=>r,set:t=>{"function"==typeof r&&e.removeEventListener("processorerror",r),r="function"==typeof t?t:null,"function"==typeof r&&e.addEventListener("processorerror",r)}}}),e.addEventListener=(p=e.addEventListener,(...t)=>{if("processorerror"===t[0]){const e="function"==typeof t[1]?t[1]:"object"==typeof t[1]&&null!==t[1]&&"function"==typeof t[1].handleEvent?t[1].handleEvent:null;if(null!==e){const s=n.get(t[1]);void 0!==s?t[1]=s:(t[1]=s=>{"error"===s.type?(Object.defineProperties(s,{type:{value:"processorerror"}}),e(s)):e(new ErrorEvent(t[0],{...s}))},n.set(e,t[1]))}}return p.call(e,"error",t[1],t[2]),p.call(e,...t)}),e.removeEventListener=(l=e.removeEventListener,(...t)=>{if("processorerror"===t[0]){const e=n.get(t[1]);void 0!==e&&(n.delete(t[1]),t[1]=e)}return l.call(e,"error",t[1],t[2]),l.call(e,t[0],t[1],t[2])}),0!==u.numberOfOutputs){const t=s(o,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});e.connect(t).connect(o.destination);return i(e,()=>t.disconnect(),()=>t.connect(o.destination))}return e}catch(t){if(11===t.code)throw n();throw t}var l,p;if(void 0===h)throw n();return(t=>{const{port1:e}=new MessageChannel;try{e.postMessage(t)}finally{e.close()}})(u),e(o,r,h,u)})(Mt,Mn,Yt,Kt,ws),Rn=((t,e,s,n,i,o,r,a,c,h,u,l,p,d,f,_)=>(m,g,v)=>{const y=new WeakMap;let x=null;return{render(w,b,S){a(b,w);const k=y.get(b);return void 0!==k?Promise.resolve(k):(async(a,w,b)=>{let S=u(a),k=null;const C=T(S,w),A=Array.isArray(g.outputChannelCount)?g.outputChannelCount:Array.from(g.outputChannelCount);if(null===l){const t=A.reduce((t,e)=>t+e,0),s=i(w,{channelCount:Math.max(1,t),channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:Math.max(1,t)}),o=[];for(let t=0;t{const c=new p(s,128*Math.ceil(a.context.length/128),w.sampleRate),h=[],u=[];for(let t=0;t{const e=o(c,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:t.value});return await d(c,t,e.offset,b),e})),m=n(c,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:Math.max(1,t+e)});for(let t=0;tf(a,c,t,b))),_(c)};x=xt(a,0===s?null:await c(),w,g,A,v,h)}const t=await x,e=s(w,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),[c,u,l]=k;null!==t&&(e.buffer=t,e.start(0)),e.connect(c);for(let t=0,e=0;te=>t.get(e))(un),Fn=(t=>(e,s)=>{t.set(e,s)})(Dn),In=cn?((t,e,s,n,i,o,r,a,c,h,u,l,p)=>class extends e{constructor(e,p,d){var f;const m=a(e),g=c(m),v=u({...mt,...d}),y=_.get(m),x=null==y?void 0:y.get(p),w=g||"closed"!==m.state?m:null!==(f=r(m))&&void 0!==f?f:m,b=i(w,g?null:e.baseLatency,h,p,x,v);super(e,!0,b,g?n(p,v,x):null);const T=[];b.parameters.forEach((t,e)=>{const n=s(this,g,t);T.push([e,n])}),this._nativeAudioWorkletNode=b,this._onprocessorerror=null,this._parameters=new _t(T),g&&t(m,this);const{activeInputs:S}=o(this);l(b,S)}get onprocessorerror(){return this._onprocessorerror}set onprocessorerror(t){const e="function"==typeof t?p(this,t):null;this._nativeAudioWorkletNode.onprocessorerror=e;const s=this._nativeAudioWorkletNode.onprocessorerror;this._onprocessorerror=null!==s&&s===e?t:s}get parameters(){return null===this._parameters?this._nativeAudioWorkletNode.parameters:this._parameters}get port(){return this._nativeAudioWorkletNode.port}})(Tn,We,cs,Rn,En,N,qn,Me,qe,pn,t=>({...t,outputChannelCount:void 0!==t.outputChannelCount?t.outputChannelCount:1===t.numberOfInputs&&1===t.numberOfOutputs?[t.channelCount]:Array.from({length:t.numberOfOutputs},()=>1)}),Fn,_e):void 0,Vn=(((t,e,s,n,i)=>{})(Mt,Kt,oe,Gs,Pe),((t,e)=>(s,n,i)=>{if(null===e)throw new Error("Missing the native OfflineAudioContext constructor.");try{return new e(s,n,i)}catch(e){if("SyntaxError"===e.name)throw t();throw e}})(Kt,Re)),Nn=((t,e,s,n,i,o,r,a)=>{const c=[];return(h,u)=>s(h).render(h,u,c).then(()=>Promise.all(Array.from(n(u)).map(t=>s(t).render(t,u,c)))).then(()=>i(u)).then(s=>("function"!=typeof s.copyFromChannel?(r(s),C(s)):e(o,()=>o(s))||a(s),t.add(s),s))})(Qe,me,Te,wn,js,S,He,$e),Pn=(((t,e,s,n,i)=>{})(me,Mt,Vn,Gs,Nn),((t,e,s,n,i)=>class extends t{constructor(t,s,i){let o;if("number"==typeof t&&void 0!==s&&void 0!==i)o={length:s,numberOfChannels:t,sampleRate:i};else{if("object"!=typeof t)throw new Error("The given parameters are not valid.");o=t}const{length:r,numberOfChannels:a,sampleRate:c}={...te,...o},h=n(a,r,c);e(It,()=>It(h))||h.addEventListener("statechange",(()=>{let t=0;const e=s=>{"running"===this._state&&(t>0?(h.removeEventListener("statechange",e),s.stopImmediatePropagation(),this._waitForThePromiseToSettle(s)):t+=1)};return e})()),super(h,a),this._length=r,this._nativeOfflineAudioContext=h,this._state=null}get length(){return void 0===this._nativeOfflineAudioContext.length?this._length:this._nativeOfflineAudioContext.length}get state(){return null===this._state?this._nativeOfflineAudioContext.state:this._state}startRendering(){return"running"===this._state?Promise.reject(s()):(this._state="running",i(this.destination,this._nativeOfflineAudioContext).finally(()=>{this._state=null,L(this)}))}_waitForThePromiseToSettle(t){null===this._state?this._nativeOfflineAudioContext.dispatchEvent(t):setTimeout(()=>this._waitForThePromiseToSettle(t))}})(_n,me,Mt,Vn,Nn)),jn=((t,e)=>s=>{const n=t.get(s);return e(n)||e(s)})(p,je),Ln=(zn=h,Bn=ze,t=>zn.has(t)||Bn(t));var zn,Bn;const Wn=(Un=l,Gn=Be,t=>Un.has(t)||Gn(t));var Un,Gn;const Qn=((t,e)=>s=>{const n=t.get(s);return e(n)||e(s)})(p,qe),Zn=()=>(async(t,e,s,n,i,o,r,a,c,h,u,l,p,d,f,_)=>{if(t(e,e)&&t(s,s)&&t(i,i)&&t(o,o)&&t(a,a)&&t(c,c)&&t(h,h)&&t(u,u)&&t(l,l)&&t(p,p)&&t(d,d)){return(await Promise.all([t(n,n),t(r,r),t(f,f),t(_,_)])).every(t=>t)}return!1})(me,(t=>()=>{if(null===t)return!1;const e=new t(1,1,44100).createBuffer(1,1,44100);if(void 0===e.copyToChannel)return!0;const s=new Float32Array(2);try{e.copyFromChannel(s,0,0)}catch{return!1}return!0})(Re),(t=>()=>{if(null===t)return!1;if(void 0!==t.prototype&&void 0!==t.prototype.close)return!0;const e=new t,s=void 0!==e.close;try{e.close()}catch{}return s})(Pe),(t=>()=>{if(null===t)return Promise.resolve(!1);const e=new t(1,1,44100);return new Promise(t=>{let s=!0;const n=n=>{s&&(s=!1,e.startRendering(),t(n instanceof TypeError))};let i;try{i=e.decodeAudioData(null,()=>{},n)}catch(t){n(t)}void 0!==i&&i.catch(n)})})(Re),(t=>()=>{if(null===t)return!1;let e;try{e=new t({latencyHint:"balanced"})}catch{return!1}return e.close(),!0})(Pe),(t=>()=>{if(null===t)return!1;const e=new t(1,1,44100).createGain(),s=e.connect(e)===e;return e.disconnect(e),s})(Re),((t,e)=>async()=>{if(null===t)return!0;if(null===e)return!1;const s=new Blob(['class A extends AudioWorkletProcessor{process(){this.port.postMessage(0)}}registerProcessor("a",A)'],{type:"application/javascript; charset=utf-8"}),n=new e(1,128,8e3),i=URL.createObjectURL(s);let o=!1;try{await n.audioWorklet.addModule(i);const e=new t(n,"a",{numberOfOutputs:0}),s=n.createOscillator();e.port.onmessage=()=>o=!0,s.connect(e),s.start(0),await n.startRendering(),o||await new Promise(t=>setTimeout(t,5))}catch{}finally{URL.revokeObjectURL(i)}return o})(pn,Re),(t=>()=>{if(null===t)return!1;const e=new t(1,1,44100).createChannelMerger();if("max"===e.channelCountMode)return!0;try{e.channelCount=2}catch{return!0}return!1})(Re),(t=>()=>{if(null===t)return!1;const e=new t(1,1,44100);if(void 0===e.createConstantSource)return!0;return e.createConstantSource().offset.maxValue!==Number.POSITIVE_INFINITY})(Re),(t=>()=>{if(null===t)return!1;const e=new t(1,1,44100),s=e.createConvolver();s.buffer=e.createBuffer(1,1,e.sampleRate);try{s.buffer=e.createBuffer(1,1,e.sampleRate)}catch{return!1}return!0})(Re),(t=>()=>{if(null===t)return!1;const e=new t(1,1,44100).createConvolver();try{e.channelCount=1}catch{return!1}return!0})(Re),pe,(t=>()=>null!==t&&t.hasOwnProperty("isSecureContext"))(ye),(t=>()=>{if(null===t)return!1;const e=new t;try{return e.createMediaStreamSource(new MediaStream),!1}catch(t){return!0}})(Pe),(t=>()=>{if(null===t)return Promise.resolve(!1);const e=new t(1,1,44100);if(void 0===e.createStereoPanner)return Promise.resolve(!0);if(void 0===e.createConstantSource)return Promise.resolve(!0);const s=e.createConstantSource(),n=e.createStereoPanner();return s.channelCount=1,s.offset.value=1,n.channelCount=1,s.start(),s.connect(n).connect(e.destination),e.startRendering().then(t=>1!==t.getChannelData(0)[0])})(Re),de);function Xn(t,e){if(!t)throw new Error(e)}function Yn(t,e,s=1/0){if(!(e<=t&&t<=s))throw new RangeError(`Value must be within [${e}, ${s}], got: ${t}`)}function Hn(t){t.isOffline||"running"===t.state||ti('The AudioContext is "suspended". Invoke Tone.start() from a user action to start the audio.')}let $n=console;function Jn(t){$n=t}function Kn(...t){$n.log(...t)}function ti(...t){$n.warn(...t)}function ei(t){return void 0===t}function si(t){return!ei(t)}function ni(t){return"function"==typeof t}function ii(t){return"number"==typeof t}function oi(t){return"[object Object]"===Object.prototype.toString.call(t)&&t.constructor===Object}function ri(t){return"boolean"==typeof t}function ai(t){return Array.isArray(t)}function ci(t){return"string"==typeof t}function hi(t){return ci(t)&&/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i.test(t)}const ui="object"==typeof self?self:null,li=ui&&(ui.hasOwnProperty("AudioContext")||ui.hasOwnProperty("webkitAudioContext"));function pi(t,e,s,n){var i,o=arguments.length,r=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,s):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,s,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(r=(o<3?i(r):o>3?i(e,s,r):i(e,s))||r);return o>3&&r&&Object.defineProperty(e,s,r),r}function di(t,e,s,n){return new(s||(s=Promise))((function(i,o){function r(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(r,a)}c((n=n.apply(t,e||[])).next())}))}Object.create;Object.create;class fi{constructor(t,e,s){this._callback=t,this._type=e,this._updateInterval=s,this._createClock()}_createWorker(){const t=new Blob([`\n\t\t\t// the initial timeout time\n\t\t\tlet timeoutTime = ${(1e3*this._updateInterval).toFixed(1)};\n\t\t\t// onmessage callback\n\t\t\tself.onmessage = function(msg){\n\t\t\t\ttimeoutTime = parseInt(msg.data);\n\t\t\t};\n\t\t\t// the tick function which posts a message\n\t\t\t// and schedules a new tick\n\t\t\tfunction tick(){\n\t\t\t\tsetTimeout(tick, timeoutTime);\n\t\t\t\tself.postMessage('tick');\n\t\t\t}\n\t\t\t// call tick initially\n\t\t\ttick();\n\t\t\t`],{type:"text/javascript"}),e=URL.createObjectURL(t),s=new Worker(e);s.onmessage=this._callback.bind(this),this._worker=s}_createTimeout(){this._timeout=setTimeout(()=>{this._createTimeout(),this._callback()},1e3*this._updateInterval)}_createClock(){if("worker"===this._type)try{this._createWorker()}catch(t){this._type="timeout",this._createClock()}else"timeout"===this._type&&this._createTimeout()}_disposeClock(){this._timeout&&(clearTimeout(this._timeout),this._timeout=0),this._worker&&(this._worker.terminate(),this._worker.onmessage=null)}get updateInterval(){return this._updateInterval}set updateInterval(t){this._updateInterval=Math.max(t,128/44100),"worker"===this._type&&this._worker.postMessage(Math.max(1e3*t,1))}get type(){return this._type}set type(t){this._disposeClock(),this._type=t,this._createClock()}dispose(){this._disposeClock()}}function _i(t){return Wn(t)}function mi(t){return Ln(t)}function gi(t){return Qn(t)}function vi(t){return jn(t)}function yi(t){return t instanceof AudioBuffer}function xi(t,e){return"value"===t||_i(e)||mi(e)||yi(e)}function wi(t,...e){if(!e.length)return t;const s=e.shift();if(oi(t)&&oi(s))for(const e in s)xi(e,s[e])?t[e]=s[e]:oi(s[e])?(t[e]||Object.assign(t,{[e]:{}}),wi(t[e],s[e])):Object.assign(t,{[e]:s[e]});return wi(t,...e)}function bi(t,e,s=[],n){const i={},o=Array.from(e);if(oi(o[0])&&n&&!Reflect.has(o[0],n)){Object.keys(o[0]).some(e=>Reflect.has(t,e))||(wi(i,{[n]:o[0]}),s.splice(s.indexOf(n),1),o.shift())}if(1===o.length&&oi(o[0]))wi(i,o[0]);else for(let t=0;t{Reflect.has(t,e)&&delete t[e]}),t} /** * Tone.js * @author Yotam Mann * @license http://opensource.org/licenses/MIT MIT License * @copyright 2014-2019 Yotam Mann */class ki{constructor(){this.debug=!1,this._wasDisposed=!1}static getDefaults(){return{}}log(...t){(this.debug||ui&&this.toString()===ui.TONE_DEBUG_CLASS)&&Kn(this,...t)}dispose(){return this._wasDisposed=!0,this}get disposed(){return this._wasDisposed}toString(){return this.name}}ki.version=o;function Ci(t,e){return t>e+1e-6}function Ai(t,e){return Ci(t,e)||Oi(t,e)}function Di(t,e){return t+1e-6this.memory){const t=this.length-this.memory;this._timeline.splice(0,t)}return this}remove(t){const e=this._timeline.indexOf(t);return-1!==e&&this._timeline.splice(e,1),this}get(t,e="time"){const s=this._search(t,e);return-1!==s?this._timeline[s]:null}peek(){return this._timeline[0]}shift(){return this._timeline.shift()}getAfter(t,e="time"){const s=this._search(t,e);return s+10&&this._timeline[e-1].time=0?this._timeline[s-1]:null}cancel(t){if(this._timeline.length>1){let e=this._search(t);if(e>=0)if(Oi(this._timeline[e].time,t)){for(let s=e;s>=0&&Oi(this._timeline[s].time,t);s--)e=s;this._timeline=this._timeline.slice(0,e)}else this._timeline=this._timeline.slice(0,e+1);else this._timeline=[]}else 1===this._timeline.length&&Ai(this._timeline[0].time,t)&&(this._timeline=[]);return this}cancelBefore(t){const e=this._search(t);return e>=0&&(this._timeline=this._timeline.slice(e+1)),this}previousEvent(t){const e=this._timeline.indexOf(t);return e>0?this._timeline[e-1]:null}_search(t,e="time"){if(0===this._timeline.length)return-1;let s=0;const n=this._timeline.length;let i=n;if(n>0&&this._timeline[n-1][e]<=t)return n-1;for(;s=0&&this._timeline[s].time>=t;)s--;return this._iterate(e,s+1),this}forEachAtTime(t,e){const s=this._search(t);if(-1!==s&&Oi(this._timeline[s].time,t)){let n=s;for(let e=s;e>=0&&Oi(this._timeline[e].time,t);e--)n=e;this._iterate(t=>{e(t)},n,s)}return this}dispose(){return super.dispose(),this._timeline=[],this}}const Ri=[];function qi(t){Ri.push(t)}const Fi=[];function Ii(t){Fi.push(t)}class Vi extends ki{constructor(){super(...arguments),this.name="Emitter"}on(t,e){return t.split(/\W+/).forEach(t=>{ei(this._events)&&(this._events={}),this._events.hasOwnProperty(t)||(this._events[t]=[]),this._events[t].push(e)}),this}once(t,e){const s=(...n)=>{e(...n),this.off(t,s)};return this.on(t,s),this}off(t,e){return t.split(/\W+/).forEach(s=>{if(ei(this._events)&&(this._events={}),this._events.hasOwnProperty(t))if(ei(e))this._events[t]=[];else{const s=this._events[t];for(let t=s.length-1;t>=0;t--)s[t]===e&&s.splice(t,1)}}),this}emit(t,...e){if(this._events&&this._events.hasOwnProperty(t)){const s=this._events[t].slice(0);for(let t=0,n=s.length;t{const s=Object.getOwnPropertyDescriptor(Vi.prototype,e);Object.defineProperty(t.prototype,e,s)})}dispose(){return super.dispose(),this._events=void 0,this}}class Ni extends Vi{constructor(){super(...arguments),this.isOffline=!1}}class Pi extends Ni{constructor(){super(),this.name="Context",this._constants=new Map,this._timeouts=new Ei,this._timeoutIds=0,this._initialized=!1,this.isOffline=!1,this._workletModules=new Map;const t=bi(Pi.getDefaults(),arguments,["context"]);t.context?this._context=t.context:this._context=function(t){return new xn(t)}({latencyHint:t.latencyHint}),this._ticker=new fi(this.emit.bind(this,"tick"),t.clockSource,t.updateInterval),this.on("tick",this._timeoutLoop.bind(this)),this._context.onstatechange=()=>{this.emit("statechange",this.state)},this._setLatencyHint(t.latencyHint),this.lookAhead=t.lookAhead}static getDefaults(){return{clockSource:"worker",latencyHint:"interactive",lookAhead:.1,updateInterval:.05}}initialize(){var t;return this._initialized||(t=this,Ri.forEach(e=>e(t)),this._initialized=!0),this}createAnalyser(){return this._context.createAnalyser()}createOscillator(){return this._context.createOscillator()}createBufferSource(){return this._context.createBufferSource()}createBiquadFilter(){return this._context.createBiquadFilter()}createBuffer(t,e,s){return this._context.createBuffer(t,e,s)}createChannelMerger(t){return this._context.createChannelMerger(t)}createChannelSplitter(t){return this._context.createChannelSplitter(t)}createConstantSource(){return this._context.createConstantSource()}createConvolver(){return this._context.createConvolver()}createDelay(t){return this._context.createDelay(t)}createDynamicsCompressor(){return this._context.createDynamicsCompressor()}createGain(){return this._context.createGain()}createIIRFilter(t,e){return this._context.createIIRFilter(t,e)}createPanner(){return this._context.createPanner()}createPeriodicWave(t,e,s){return this._context.createPeriodicWave(t,e,s)}createStereoPanner(){return this._context.createStereoPanner()}createWaveShaper(){return this._context.createWaveShaper()}createMediaStreamSource(t){Xn(vi(this._context),"Not available if OfflineAudioContext");return this._context.createMediaStreamSource(t)}createMediaStreamDestination(){Xn(vi(this._context),"Not available if OfflineAudioContext");return this._context.createMediaStreamDestination()}decodeAudioData(t){return this._context.decodeAudioData(t)}get currentTime(){return this._context.currentTime}get state(){return this._context.state}get sampleRate(){return this._context.sampleRate}get listener(){return this.initialize(),this._listener}set listener(t){Xn(!this._initialized,"The listener cannot be set after initialization."),this._listener=t}get transport(){return this.initialize(),this._transport}set transport(t){Xn(!this._initialized,"The transport cannot be set after initialization."),this._transport=t}get draw(){return this.initialize(),this._draw}set draw(t){Xn(!this._initialized,"Draw cannot be set after initialization."),this._draw=t}get destination(){return this.initialize(),this._destination}set destination(t){Xn(!this._initialized,"The destination cannot be set after initialization."),this._destination=t}createAudioWorkletNode(t,e){return function(t,e,s){return Xn(si(In),"This node only works in a secure context (https or localhost)"),new In(t,e,s)} /*! ***************************************************************************** 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. ***************************************************************************** */(this.rawContext,t,e)}addAudioWorkletModule(t,e){return di(this,void 0,void 0,(function*(){Xn(si(this.rawContext.audioWorklet),"AudioWorkletNode is only available in a secure context (https or localhost)"),this._workletModules.has(e)||this._workletModules.set(e,this.rawContext.audioWorklet.addModule(t)),yield this._workletModules.get(e)}))}workletsAreReady(){return di(this,void 0,void 0,(function*(){const t=[];this._workletModules.forEach(e=>t.push(e)),yield Promise.all(t)}))}get updateInterval(){return this._ticker.updateInterval}set updateInterval(t){this._ticker.updateInterval=t}get clockSource(){return this._ticker.type}set clockSource(t){this._ticker.type=t}get latencyHint(){return this._latencyHint}_setLatencyHint(t){let e=0;if(this._latencyHint=t,ci(t))switch(t){case"interactive":e=.1;break;case"playback":e=.5;break;case"balanced":e=.25}this.lookAhead=e,this.updateInterval=e/2}get rawContext(){return this._context}now(){return this._context.currentTime+this.lookAhead}immediate(){return this._context.currentTime}resume(){return"suspended"===this._context.state&&vi(this._context)?this._context.resume():Promise.resolve()}close(){return di(this,void 0,void 0,(function*(){var t;vi(this._context)&&(yield this._context.close()),this._initialized&&(t=this,Fi.forEach(e=>e(t)))}))}getConstant(t){if(this._constants.has(t))return this._constants.get(t);{const e=this._context.createBuffer(1,128,this._context.sampleRate),s=e.getChannelData(0);for(let e=0;ethis._constants[t].disconnect()),this}_timeoutLoop(){const t=this.now();let e=this._timeouts.peek();for(;this._timeouts.length&&e&&e.time<=t;)e.callback(),this._timeouts.shift(),e=this._timeouts.peek()}setTimeout(t,e){this._timeoutIds++;const s=this.now();return this._timeouts.add({callback:t,id:this._timeoutIds,time:s+e}),this._timeoutIds}clearTimeout(t){return this._timeouts.forEach(e=>{e.id===t&&this._timeouts.remove(e)}),this}clearInterval(t){return this.clearTimeout(t)}setInterval(t,e){const s=++this._timeoutIds,n=()=>{const i=this.now();this._timeouts.add({callback:()=>{t(),n()},id:s,time:i+e})};return n(),s}}function ji(t,e){ai(e)?e.forEach(e=>ji(t,e)):Object.defineProperty(t,e,{enumerable:!0,writable:!1})}function Li(t,e){ai(e)?e.forEach(e=>Li(t,e)):Object.defineProperty(t,e,{writable:!0})}const zi=()=>{};class Bi extends ki{constructor(){super(),this.name="ToneAudioBuffer",this.onload=zi;const t=bi(Bi.getDefaults(),arguments,["url","onload","onerror"]);this.reverse=t.reverse,this.onload=t.onload,t.url&&yi(t.url)||t.url instanceof Bi?this.set(t.url):ci(t.url)&&this.load(t.url).catch(t.onerror)}static getDefaults(){return{onerror:zi,onload:zi,reverse:!1}}get sampleRate(){return this._buffer?this._buffer.sampleRate:Qi().sampleRate}set(t){return t instanceof Bi?t.loaded?this._buffer=t.get():t.onload=()=>{this.set(t),this.onload(this)}:this._buffer=t,this._reversed&&this._reverse(),this}get(){return this._buffer}load(t){return di(this,void 0,void 0,(function*(){const e=Bi.load(t).then(t=>{this.set(t),this.onload(this)});Bi.downloads.push(e);try{yield e}finally{const t=Bi.downloads.indexOf(e);Bi.downloads.splice(t,1)}return this}))}dispose(){return super.dispose(),this._buffer=void 0,this}fromArray(t){const e=ai(t)&&t[0].length>0,s=e?t.length:1,n=e?t[0].length:t.length,i=Qi(),o=i.createBuffer(s,n,i.sampleRate),r=e||1!==s?t:[t];for(let t=0;tt/e),this.fromArray(t)}return this}toArray(t){if(ii(t))return this.getChannelData(t);if(1===this.numberOfChannels)return this.toArray(0);{const t=[];for(let e=0;e0}get duration(){return this._buffer?this._buffer.duration:0}get length(){return this._buffer?this._buffer.length:0}get numberOfChannels(){return this._buffer?this._buffer.numberOfChannels:0}get reverse(){return this._reversed}set reverse(t){this._reversed!==t&&(this._reversed=t,this._reverse())}static fromArray(t){return(new Bi).fromArray(t)}static fromUrl(t){return di(this,void 0,void 0,(function*(){const e=new Bi;return yield e.load(t)}))}static load(t){return di(this,void 0,void 0,(function*(){const e=t.match(/\[(.+\|?)+\]$/);if(e){const s=e[1].split("|");let n=s[0];for(const t of s)if(Bi.supportsType(t)){n=t;break}t=t.replace(e[0],n)}const s=""===Bi.baseUrl||Bi.baseUrl.endsWith("/")?Bi.baseUrl:Bi.baseUrl+"/",n=yield fetch(s+t);if(!n.ok)throw new Error("could not load url: "+t);const i=yield n.arrayBuffer();return yield Qi().decodeAudioData(i)}))}static supportsType(t){const e=t.split("."),s=e[e.length-1];return""!==document.createElement("audio").canPlayType("audio/"+s)}static loaded(){return di(this,void 0,void 0,(function*(){for(yield Promise.resolve();Bi.downloads.length;)yield Bi.downloads[0]}))}}Bi.baseUrl="",Bi.downloads=[];class Wi extends Pi{constructor(){var t,e,s;super({clockSource:"offline",context:gi(arguments[0])?arguments[0]:(t=arguments[0],e=arguments[1]*arguments[2],s=arguments[2],new Pn(t,e,s)),lookAhead:0,updateInterval:gi(arguments[0])?128/arguments[0].sampleRate:128/arguments[2]}),this.name="OfflineContext",this._currentTime=0,this.isOffline=!0,this._duration=gi(arguments[0])?arguments[0].length/arguments[0].sampleRate:arguments[1]}now(){return this._currentTime}get currentTime(){return this._currentTime}_renderClock(t){return di(this,void 0,void 0,(function*(){let e=0;for(;this._duration-this._currentTime>=0;){this.emit("tick"),this._currentTime+=128/this.sampleRate,e++;const s=Math.floor(this.sampleRate/128);t&&e%s==0&&(yield new Promise(t=>setTimeout(t,1)))}}))}render(t=!0){return di(this,void 0,void 0,(function*(){yield this.workletsAreReady(),yield this._renderClock(t);const e=yield this._context.startRendering();return new Bi(e)}))}close(){return Promise.resolve()}}const Ui=new class extends Ni{constructor(){super(...arguments),this.lookAhead=0,this.latencyHint=0,this.isOffline=!1}createAnalyser(){return{}}createOscillator(){return{}}createBufferSource(){return{}}createBiquadFilter(){return{}}createBuffer(t,e,s){return{}}createChannelMerger(t){return{}}createChannelSplitter(t){return{}}createConstantSource(){return{}}createConvolver(){return{}}createDelay(t){return{}}createDynamicsCompressor(){return{}}createGain(){return{}}createIIRFilter(t,e){return{}}createPanner(){return{}}createPeriodicWave(t,e,s){return{}}createStereoPanner(){return{}}createWaveShaper(){return{}}createMediaStreamSource(t){return{}}createMediaStreamDestination(){return{}}decodeAudioData(t){return Promise.resolve({})}createAudioWorkletNode(t,e){return{}}get rawContext(){return{}}addAudioWorkletModule(t,e){return di(this,void 0,void 0,(function*(){return Promise.resolve()}))}resume(){return Promise.resolve()}setTimeout(t,e){return 0}clearTimeout(t){return this}setInterval(t,e){return 0}clearInterval(t){return this}getConstant(t){return{}}get currentTime(){return 0}get state(){return{}}get sampleRate(){return 0}get listener(){return{}}get transport(){return{}}get draw(){return{}}set draw(t){}get destination(){return{}}set destination(t){}now(){return 0}immediate(){return 0}};let Gi=Ui;function Qi(){return Gi===Ui&&li&&Zi(new Pi),Gi}function Zi(t){Gi=vi(t)?new Pi(t):gi(t)?new Wi(t):t}function Xi(){return Gi.resume()}if(ui&&!ui.TONE_SILENCE_LOGGING){let t="v";"dev"===o&&(t="");const e=` * Tone.js ${t}${o} * `;console.log("%c"+e,"background: #000; color: #fff")}function Yi(t){return Math.pow(10,t/20)}function Hi(t){return Math.log(t)/Math.LN10*20}function $i(t){return Math.pow(2,t/12)}let Ji=440;function Ki(t){return Math.round(to(t))}function to(t){return 69+12*Math.log2(t/Ji)}function eo(t){return Ji*Math.pow(2,(t-69)/12)}class so extends ki{constructor(t,e,s){super(),this.defaultUnits="s",this._val=e,this._units=s,this.context=t,this._expressions=this._getExpressions()}_getExpressions(){return{hz:{method:t=>this._frequencyToUnits(parseFloat(t)),regexp:/^(\d+(?:\.\d+)?)hz$/i},i:{method:t=>this._ticksToUnits(parseInt(t,10)),regexp:/^(\d+)i$/i},m:{method:t=>this._beatsToUnits(parseInt(t,10)*this._getTimeSignature()),regexp:/^(\d+)m$/i},n:{method:(t,e)=>{const s=parseInt(t,10),n="."===e?1.5:1;return 1===s?this._beatsToUnits(this._getTimeSignature())*n:this._beatsToUnits(4/s)*n},regexp:/^(\d+)n(\.?)$/i},number:{method:t=>this._expressions[this.defaultUnits].method.call(this,t),regexp:/^(\d+(?:\.\d+)?)$/},s:{method:t=>this._secondsToUnits(parseFloat(t)),regexp:/^(\d+(?:\.\d+)?)s$/},samples:{method:t=>parseInt(t,10)/this.context.sampleRate,regexp:/^(\d+)samples$/},t:{method:t=>{const e=parseInt(t,10);return this._beatsToUnits(8/(3*Math.floor(e)))},regexp:/^(\d+)t$/i},tr:{method:(t,e,s)=>{let n=0;return t&&"0"!==t&&(n+=this._beatsToUnits(this._getTimeSignature()*parseFloat(t))),e&&"0"!==e&&(n+=this._beatsToUnits(parseFloat(e))),s&&"0"!==s&&(n+=this._beatsToUnits(parseFloat(s)/4)),n},regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?$/}}}valueOf(){if(this._val instanceof so&&this.fromType(this._val),ei(this._val))return this._noArg();if(ci(this._val)&&ei(this._units)){for(const t in this._expressions)if(this._expressions[t].regexp.test(this._val.trim())){this._units=t;break}}else if(oi(this._val)){let t=0;for(const e in this._val)if(si(this._val[e])){const s=this._val[e];t+=new this.constructor(this.context,e).valueOf()*s}return t}if(si(this._units)){const t=this._expressions[this._units],e=this._val.toString().trim().match(t.regexp);return e?t.method.apply(this,e.slice(1)):t.method.call(this,this._val)}return ci(this._val)?parseFloat(this._val):this._val}_frequencyToUnits(t){return 1/t}_beatsToUnits(t){return 60/this._getBpm()*t}_secondsToUnits(t){return t}_ticksToUnits(t){return t*this._beatsToUnits(1)/this._getPPQ()}_noArg(){return this._now()}_getBpm(){return this.context.transport.bpm.value}_getTimeSignature(){return this.context.transport.timeSignature}_getPPQ(){return this.context.transport.PPQ}fromType(t){switch(this._units=void 0,this.defaultUnits){case"s":this._val=t.toSeconds();break;case"i":this._val=t.toTicks();break;case"hz":this._val=t.toFrequency();break;case"midi":this._val=t.toMidi()}return this}toFrequency(){return 1/this.toSeconds()}toSamples(){return this.toSeconds()*this.context.sampleRate}toMilliseconds(){return 1e3*this.toSeconds()}}class no extends so{constructor(){super(...arguments),this.name="TimeClass"}_getExpressions(){return Object.assign(super._getExpressions(),{now:{method:t=>this._now()+new this.constructor(this.context,t).valueOf(),regexp:/^\+(.+)/},quantize:{method:t=>{const e=new no(this.context,t).valueOf();return this._secondsToUnits(this.context.transport.nextSubdivision(e))},regexp:/^@(.+)/}})}quantize(t,e=1){const s=new this.constructor(this.context,t).valueOf(),n=this.valueOf();return n+(Math.round(n/s)*s-n)*e}toNotation(){const t=this.toSeconds(),e=["1m"];for(let t=1;t<9;t++){const s=Math.pow(2,t);e.push(s+"n."),e.push(s+"n"),e.push(s+"t")}e.push("0");let s=e[0],n=new no(this.context,e[0]).toSeconds();return e.forEach(e=>{const i=new no(this.context,e).toSeconds();Math.abs(i-t)3&&(n=parseFloat(parseFloat(i).toFixed(3)));return[s,e,n].join(":")}toTicks(){const t=this._beatsToUnits(1),e=this.valueOf()/t;return Math.round(e*this._getPPQ())}toSeconds(){return this.valueOf()}toMidi(){return Ki(this.toFrequency())}_now(){return this.context.now()}}function io(t,e){return new no(Qi(),t,e)}class oo extends no{constructor(){super(...arguments),this.name="Frequency",this.defaultUnits="hz"}static get A4(){return Ji}static set A4(t){!function(t){Ji=t}(t)}_getExpressions(){return Object.assign({},super._getExpressions(),{midi:{regexp:/^(\d+(?:\.\d+)?midi)/,method(t){return"midi"===this.defaultUnits?t:oo.mtof(t)}},note:{regexp:/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i,method(t,e){const s=ro[t.toLowerCase()]+12*(parseInt(e,10)+1);return"midi"===this.defaultUnits?s:oo.mtof(s)}},tr:{regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?/,method(t,e,s){let n=1;return t&&"0"!==t&&(n*=this._beatsToUnits(this._getTimeSignature()*parseFloat(t))),e&&"0"!==e&&(n*=this._beatsToUnits(parseFloat(e))),s&&"0"!==s&&(n*=this._beatsToUnits(parseFloat(s)/4)),n}}})}transpose(t){return new oo(this.context,this.valueOf()*$i(t))}harmonize(t){return t.map(t=>this.transpose(t))}toMidi(){return Ki(this.valueOf())}toNote(){const t=this.toFrequency(),e=Math.log2(t/oo.A4);let s=Math.round(12*e)+57;const n=Math.floor(s/12);n<0&&(s+=-12*n);return ao[s%12]+n.toString()}toSeconds(){return 1/super.toSeconds()}toTicks(){const t=this._beatsToUnits(1),e=this.valueOf()/t;return Math.floor(e*this._getPPQ())}_noArg(){return 0}_frequencyToUnits(t){return t}_ticksToUnits(t){return 1/(60*t/(this._getBpm()*this._getPPQ()))}_beatsToUnits(t){return 1/super._beatsToUnits(t)}_secondsToUnits(t){return 1/t}static mtof(t){return eo(t)}static ftom(t){return Ki(t)}}const ro={cbb:-2,cb:-1,c:0,"c#":1,cx:2,dbb:0,db:1,d:2,"d#":3,dx:4,ebb:2,eb:3,e:4,"e#":5,ex:6,fbb:3,fb:4,f:5,"f#":6,fx:7,gbb:5,gb:6,g:7,"g#":8,gx:9,abb:7,ab:8,a:9,"a#":10,ax:11,bbb:9,bb:10,b:11,"b#":12,bx:13},ao=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];function co(t,e){return new oo(Qi(),t,e)}class ho extends no{constructor(){super(...arguments),this.name="TransportTime"}_now(){return this.context.transport.seconds}}function uo(t,e){return new ho(Qi(),t,e)}class lo extends ki{constructor(){super();const t=bi(lo.getDefaults(),arguments,["context"]);this.defaultContext?this.context=this.defaultContext:this.context=t.context}static getDefaults(){return{context:Qi()}}now(){return this.context.currentTime+this.context.lookAhead}immediate(){return this.context.currentTime}get sampleTime(){return 1/this.context.sampleRate}get blockTime(){return 128/this.context.sampleRate}toSeconds(t){return new no(this.context,t).toSeconds()}toFrequency(t){return new oo(this.context,t).toFrequency()}toTicks(t){return new ho(this.context,t).toTicks()}_getPartialProperties(t){const e=this.get();return Object.keys(e).forEach(s=>{ei(t[s])&&delete e[s]}),e}get(){const t=this.constructor.getDefaults();return Object.keys(t).forEach(e=>{if(Reflect.has(this,e)){const s=this[e];si(s)&&si(s.value)&&si(s.setValueAtTime)?t[e]=s.value:s instanceof lo?t[e]=s._getPartialProperties(t[e]):ai(s)||ii(s)||ci(s)||ri(s)?t[e]=s:delete t[e]}}),t}set(t){return Object.keys(t).forEach(e=>{Reflect.has(this,e)&&si(this[e])&&(this[e]&&si(this[e].value)&&si(this[e].setValueAtTime)?this[e].value!==t[e]&&(this[e].value=t[e]):this[e]instanceof lo?this[e].set(t[e]):this[e]=t[e])}),this}}class po extends Ei{constructor(t="stopped"){super(),this.name="StateTimeline",this._initial=t,this.setStateAtTime(this._initial,0)}getValueAtTime(t){const e=this.get(t);return null!==e?e.state:this._initial}setStateAtTime(t,e,s){return Yn(e,0),this.add(Object.assign({},s,{state:t,time:e})),this}getLastState(t,e){for(let s=this._search(e);s>=0;s--){const e=this._timeline[s];if(e.state===t)return e}}getNextState(t,e){const s=this._search(e);if(-1!==s)for(let e=s;e0,"timeConstant must be a number greater than 0");const i=this.toSeconds(e);return this._assertRange(n),Xn(isFinite(n)&&isFinite(i),`Invalid argument(s) to setTargetAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._events.add({constant:s,time:i,type:"setTargetAtTime",value:n}),this.log(this.units,"setTargetAtTime",t,i,s),this._param.setTargetAtTime(n,i,s),this}setValueCurveAtTime(t,e,s,n=1){s=this.toSeconds(s),e=this.toSeconds(e);const i=this._fromType(t[0])*n;this.setValueAtTime(this._toType(i),e);const o=s/(t.length-1);for(let s=1;s{"cancelScheduledValues"===e.type?t.cancelScheduledValues(e.time):"setTargetAtTime"===e.type?t.setTargetAtTime(e.value,e.time,e.constant):t[e.type](e.value,e.time)}),this}setParam(t){Xn(this._swappable,"The Param must be assigned as 'swappable' in the constructor");const e=this.input;return e.disconnect(this._param),this.apply(t),this._param=t,e.connect(this._param),this}dispose(){return super.dispose(),this._events.dispose(),this}get defaultValue(){return this._toType(this._param.defaultValue)}_exponentialApproach(t,e,s,n,i){return s+(e-s)*Math.exp(-(i-t)/n)}_linearInterpolate(t,e,s,n,i){return e+(i-t)/(s-t)*(n-e)}_exponentialInterpolate(t,e,s,n,i){return e*Math.pow(n/e,(i-t)/(s-t))}}class _o extends lo{constructor(){super(...arguments),this.name="ToneAudioNode",this._internalChannels=[]}get numberOfInputs(){return si(this.input)?_i(this.input)||this.input instanceof fo?1:this.input.numberOfInputs:0}get numberOfOutputs(){return si(this.output)?this.output.numberOfOutputs:0}_isAudioNode(t){return si(t)&&(t instanceof _o||mi(t))}_getInternalNodes(){const t=this._internalChannels.slice(0);return this._isAudioNode(this.input)&&t.push(this.input),this._isAudioNode(this.output)&&this.input!==this.output&&t.push(this.output),t}_setChannelProperties(t){this._getInternalNodes().forEach(e=>{e.channelCount=t.channelCount,e.channelCountMode=t.channelCountMode,e.channelInterpretation=t.channelInterpretation})}_getChannelProperties(){const t=this._getInternalNodes();Xn(t.length>0,"ToneAudioNode does not have any internal nodes");const e=t[0];return{channelCount:e.channelCount,channelCountMode:e.channelCountMode,channelInterpretation:e.channelInterpretation}}get channelCount(){return this._getChannelProperties().channelCount}set channelCount(t){const e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelCount:t}))}get channelCountMode(){return this._getChannelProperties().channelCountMode}set channelCountMode(t){const e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelCountMode:t}))}get channelInterpretation(){return this._getChannelProperties().channelInterpretation}set channelInterpretation(t){const e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelInterpretation:t}))}connect(t,e=0,s=0){return go(this,t,e,s),this}toDestination(){return this.connect(this.context.destination),this}toMaster(){return ti("toMaster() has been renamed toDestination()"),this.toDestination()}disconnect(t,e=0,s=0){return vo(this,t,e,s),this}chain(...t){return mo(this,...t),this}fan(...t){return t.forEach(t=>this.connect(t)),this}dispose(){return super.dispose(),si(this.input)&&(this.input instanceof _o?this.input.dispose():mi(this.input)&&this.input.disconnect()),si(this.output)&&(this.output instanceof _o?this.output.dispose():mi(this.output)&&this.output.disconnect()),this._internalChannels=[],this}}function mo(...t){const e=t.shift();t.reduce((t,e)=>(t instanceof _o?t.connect(e):mi(t)&&go(t,e),e),e)}function go(t,e,s=0,n=0){for(Xn(si(t),"Cannot connect from undefined node"),Xn(si(e),"Cannot connect to undefined node"),(e instanceof _o||mi(e))&&Xn(e.numberOfInputs>0,"Cannot connect to node with no inputs"),Xn(t.numberOfOutputs>0,"Cannot connect from node with no outputs");e instanceof _o||e instanceof fo;)si(e.input)&&(e=e.input);for(;t instanceof _o;)si(t.output)&&(t=t.output);_i(e)?t.connect(e,s):t.connect(e,s,n)}function vo(t,e,s=0,n=0){if(si(e))for(;e instanceof _o;)e=e.input;for(;!mi(t);)si(t.output)&&(t=t.output);_i(e)?t.disconnect(e,s):mi(e)?t.disconnect(e,s,n):t.disconnect()}class yo extends _o{constructor(){super(bi(yo.getDefaults(),arguments,["gain","units"])),this.name="Gain",this._gainNode=this.context.createGain(),this.input=this._gainNode,this.output=this._gainNode;const t=bi(yo.getDefaults(),arguments,["gain","units"]);this.gain=new fo({context:this.context,convert:t.convert,param:this._gainNode.gain,units:t.units,value:t.gain,minValue:t.minValue,maxValue:t.maxValue}),ji(this,"gain")}static getDefaults(){return Object.assign(_o.getDefaults(),{convert:!0,gain:1,units:"gain"})}dispose(){return super.dispose(),this._gainNode.disconnect(),this.gain.dispose(),this}}class xo extends _o{constructor(t){super(t),this.onended=zi,this._startTime=-1,this._stopTime=-1,this._timeout=-1,this.output=new yo({context:this.context,gain:0}),this._gainNode=this.output,this.getStateAtTime=function(t){const e=this.toSeconds(t);return-1!==this._startTime&&e>=this._startTime&&(-1===this._stopTime||e<=this._stopTime)?"started":"stopped"},this._fadeIn=t.fadeIn,this._fadeOut=t.fadeOut,this._curve=t.curve,this.onended=t.onended}static getDefaults(){return Object.assign(_o.getDefaults(),{curve:"linear",fadeIn:0,fadeOut:0,onended:zi})}_startGain(t,e=1){Xn(-1===this._startTime,"Source cannot be started more than once");const s=this.toSeconds(this._fadeIn);return this._startTime=t+s,this._startTime=Math.max(this._startTime,this.context.currentTime),s>0?(this._gainNode.gain.setValueAtTime(0,t),"linear"===this._curve?this._gainNode.gain.linearRampToValueAtTime(e,t+s):this._gainNode.gain.exponentialApproachValueAtTime(e,t,s)):this._gainNode.gain.setValueAtTime(e,t),this}stop(t){return this.log("stop",t),this._stopGain(this.toSeconds(t)),this}_stopGain(t){Xn(-1!==this._startTime,"'start' must be called before 'stop'"),this.cancelStop();const e=this.toSeconds(this._fadeOut);return this._stopTime=this.toSeconds(t)+e,this._stopTime=Math.max(this._stopTime,this.context.currentTime),e>0?"linear"===this._curve?this._gainNode.gain.linearRampTo(0,e,t):this._gainNode.gain.targetRampTo(0,e,t):(this._gainNode.gain.cancelAndHoldAtTime(t),this._gainNode.gain.setValueAtTime(0,t)),this.context.clearTimeout(this._timeout),this._timeout=this.context.setTimeout(()=>{const t="exponential"===this._curve?2*e:0;this._stopSource(this.now()+t),this._onended()},this._stopTime-this.context.currentTime),this}_onended(){if(this.onended!==zi&&(this.onended(this),this.onended=zi,!this.context.isOffline)){const t=()=>this.dispose();void 0!==window.requestIdleCallback?window.requestIdleCallback(t):setTimeout(t,1e3)}}get state(){return this.getStateAtTime(this.now())}cancelStop(){return this.log("cancelStop"),Xn(-1!==this._startTime,"Source is not started"),this._gainNode.gain.cancelScheduledValues(this._startTime+this.sampleTime),this.context.clearTimeout(this._timeout),this._stopTime=-1,this}dispose(){return super.dispose(),this._gainNode.disconnect(),this}}class wo extends xo{constructor(){super(bi(wo.getDefaults(),arguments,["offset"])),this.name="ToneConstantSource",this._source=this.context.createConstantSource();const t=bi(wo.getDefaults(),arguments,["offset"]);go(this._source,this._gainNode),this.offset=new fo({context:this.context,convert:t.convert,param:this._source.offset,units:t.units,value:t.offset,minValue:t.minValue,maxValue:t.maxValue})}static getDefaults(){return Object.assign(xo.getDefaults(),{convert:!0,offset:1,units:"number"})}start(t){const e=this.toSeconds(t);return this.log("start",e),this._startGain(e),this._source.start(e),this}_stopSource(t){this._source.stop(t)}dispose(){return super.dispose(),"started"===this.state&&this.stop(),this._source.disconnect(),this.offset.dispose(),this}}class bo extends _o{constructor(){super(bi(bo.getDefaults(),arguments,["value","units"])),this.name="Signal",this.override=!0;const t=bi(bo.getDefaults(),arguments,["value","units"]);this.output=this._constantSource=new wo({context:this.context,convert:t.convert,offset:t.value,units:t.units,minValue:t.minValue,maxValue:t.maxValue}),this._constantSource.start(0),this.input=this._param=this._constantSource.offset}static getDefaults(){return Object.assign(_o.getDefaults(),{convert:!0,units:"number",value:0})}connect(t,e=0,s=0){return To(this,t,e,s),this}dispose(){return super.dispose(),this._param.dispose(),this._constantSource.dispose(),this}setValueAtTime(t,e){return this._param.setValueAtTime(t,e),this}getValueAtTime(t){return this._param.getValueAtTime(t)}setRampPoint(t){return this._param.setRampPoint(t),this}linearRampToValueAtTime(t,e){return this._param.linearRampToValueAtTime(t,e),this}exponentialRampToValueAtTime(t,e){return this._param.exponentialRampToValueAtTime(t,e),this}exponentialRampTo(t,e,s){return this._param.exponentialRampTo(t,e,s),this}linearRampTo(t,e,s){return this._param.linearRampTo(t,e,s),this}targetRampTo(t,e,s){return this._param.targetRampTo(t,e,s),this}exponentialApproachValueAtTime(t,e,s){return this._param.exponentialApproachValueAtTime(t,e,s),this}setTargetAtTime(t,e,s){return this._param.setTargetAtTime(t,e,s),this}setValueCurveAtTime(t,e,s,n){return this._param.setValueCurveAtTime(t,e,s,n),this}cancelScheduledValues(t){return this._param.cancelScheduledValues(t),this}cancelAndHoldAtTime(t){return this._param.cancelAndHoldAtTime(t),this}rampTo(t,e,s){return this._param.rampTo(t,e,s),this}get value(){return this._param.value}set value(t){this._param.value=t}get convert(){return this._param.convert}set convert(t){this._param.convert=t}get units(){return this._param.units}get overridden(){return this._param.overridden}set overridden(t){this._param.overridden=t}get maxValue(){return this._param.maxValue}get minValue(){return this._param.minValue}apply(t){return this._param.apply(t),this}}function To(t,e,s,n){(e instanceof fo||_i(e)||e instanceof bo&&e.override)&&(e.cancelScheduledValues(0),e.setValueAtTime(0,0),e instanceof bo&&(e.overridden=!0)),go(t,e,s,n)}class So extends fo{constructor(){super(bi(So.getDefaults(),arguments,["value"])),this.name="TickParam",this._events=new Ei(1/0),this._multiplier=1;const t=bi(So.getDefaults(),arguments,["value"]);this._multiplier=t.multiplier,this._events.cancel(0),this._events.add({ticks:0,time:0,type:"setValueAtTime",value:this._fromType(t.value)}),this.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign(fo.getDefaults(),{multiplier:1,units:"hertz",value:1})}setTargetAtTime(t,e,s){e=this.toSeconds(e),this.setRampPoint(e);const n=this._fromType(t),i=this._events.get(e),o=Math.round(Math.max(1/s,1));for(let t=0;t<=o;t++){const o=s*t+e,r=this._exponentialApproach(i.time,i.value,n,s,o);this.linearRampToValueAtTime(this._toType(r),o)}return this}setValueAtTime(t,e){const s=this.toSeconds(e);super.setValueAtTime(t,e);const n=this._events.get(s),i=this._events.previousEvent(n),o=this._getTicksUntilEvent(i,s);return n.ticks=Math.max(o,0),this}linearRampToValueAtTime(t,e){const s=this.toSeconds(e);super.linearRampToValueAtTime(t,e);const n=this._events.get(s),i=this._events.previousEvent(n),o=this._getTicksUntilEvent(i,s);return n.ticks=Math.max(o,0),this}exponentialRampToValueAtTime(t,e){e=this.toSeconds(e);const s=this._fromType(t),n=this._events.get(e),i=Math.round(Math.max(10*(e-n.time),1)),o=(e-n.time)/i;for(let t=0;t<=i;t++){const i=o*t+n.time,r=this._exponentialInterpolate(n.time,n.value,e,s,i);this.linearRampToValueAtTime(this._toType(r),i)}return this}_getTicksUntilEvent(t,e){if(null===t)t={ticks:0,time:0,type:"setValueAtTime",value:0};else if(ei(t.ticks)){const e=this._events.previousEvent(t);t.ticks=this._getTicksUntilEvent(e,t.time)}const s=this._fromType(this.getValueAtTime(t.time));let n=this._fromType(this.getValueAtTime(e));const i=this._events.get(e);return i&&i.time===e&&"setValueAtTime"===i.type&&(n=this._fromType(this.getValueAtTime(e-this.sampleTime))),.5*(e-t.time)*(s+n)+t.ticks}getTicksAtTime(t){const e=this.toSeconds(t),s=this._events.get(e);return Math.max(this._getTicksUntilEvent(s,e),0)}getDurationOfTicks(t,e){const s=this.toSeconds(e),n=this.getTicksAtTime(e);return this.getTimeOfTick(n+t)-s}getTimeOfTick(t){const e=this._events.get(t,"ticks"),s=this._events.getAfter(t,"ticks");if(e&&e.ticks===t)return e.time;if(e&&s&&"linearRampToValueAtTime"===s.type&&e.value!==s.value){const n=this._fromType(this.getValueAtTime(e.time)),i=(this._fromType(this.getValueAtTime(s.time))-n)/(s.time-e.time),o=Math.sqrt(Math.pow(n,2)-2*i*(e.ticks-t)),r=(-n+o)/i,a=(-n-o)/i;return(r>0?r:a)+e.time}return e?0===e.value?1/0:e.time+(t-e.ticks)/e.value:t/this._initialValue}ticksToTime(t,e){return this.getDurationOfTicks(t,e)}timeToTicks(t,e){const s=this.toSeconds(e),n=this.toSeconds(t),i=this.getTicksAtTime(s);return this.getTicksAtTime(s+n)-i}_fromType(t){return"bpm"===this.units&&this.multiplier?1/(60/t/this.multiplier):super._fromType(t)}_toType(t){return"bpm"===this.units&&this.multiplier?t/this.multiplier*60:super._toType(t)}get multiplier(){return this._multiplier}set multiplier(t){const e=this.value;this._multiplier=t,this.cancelScheduledValues(0),this.setValueAtTime(e,0)}}class ko extends bo{constructor(){super(bi(ko.getDefaults(),arguments,["value"])),this.name="TickSignal";const t=bi(ko.getDefaults(),arguments,["value"]);this.input=this._param=new So({context:this.context,convert:t.convert,multiplier:t.multiplier,param:this._constantSource.offset,units:t.units,value:t.value})}static getDefaults(){return Object.assign(bo.getDefaults(),{multiplier:1,units:"hertz",value:1})}ticksToTime(t,e){return this._param.ticksToTime(t,e)}timeToTicks(t,e){return this._param.timeToTicks(t,e)}getTimeOfTick(t){return this._param.getTimeOfTick(t)}getDurationOfTicks(t,e){return this._param.getDurationOfTicks(t,e)}getTicksAtTime(t){return this._param.getTicksAtTime(t)}get multiplier(){return this._param.multiplier}set multiplier(t){this._param.multiplier=t}dispose(){return super.dispose(),this._param.dispose(),this}}class Co extends lo{constructor(){super(bi(Co.getDefaults(),arguments,["frequency"])),this.name="TickSource",this._state=new po,this._tickOffset=new Ei;const t=bi(Co.getDefaults(),arguments,["frequency"]);this.frequency=new ko({context:this.context,units:t.units,value:t.frequency}),ji(this,"frequency"),this._state.setStateAtTime("stopped",0),this.setTicksAtTime(0,0)}static getDefaults(){return Object.assign({frequency:1,units:"hertz"},lo.getDefaults())}get state(){return this.getStateAtTime(this.now())}start(t,e){const s=this.toSeconds(t);return"started"!==this._state.getValueAtTime(s)&&(this._state.setStateAtTime("started",s),si(e)&&this.setTicksAtTime(e,s)),this}stop(t){const e=this.toSeconds(t);if("stopped"===this._state.getValueAtTime(e)){const t=this._state.get(e);t&&t.time>0&&(this._tickOffset.cancel(t.time),this._state.cancel(t.time))}return this._state.cancel(e),this._state.setStateAtTime("stopped",e),this.setTicksAtTime(0,e),this}pause(t){const e=this.toSeconds(t);return"started"===this._state.getValueAtTime(e)&&this._state.setStateAtTime("paused",e),this}cancel(t){return t=this.toSeconds(t),this._state.cancel(t),this._tickOffset.cancel(t),this}getTicksAtTime(t){const e=this.toSeconds(t),s=this._state.getLastState("stopped",e),n={state:"paused",time:e};this._state.add(n);let i=s,o=0;return this._state.forEachBetween(s.time,e+this.sampleTime,t=>{let e=i.time;const s=this._tickOffset.get(t.time);s&&s.time>=i.time&&(o=s.ticks,e=s.time),"started"===i.state&&"started"!==t.state&&(o+=this.frequency.getTicksAtTime(t.time)-this.frequency.getTicksAtTime(e)),i=t}),this._state.remove(n),o}get ticks(){return this.getTicksAtTime(this.now())}set ticks(t){this.setTicksAtTime(t,this.now())}get seconds(){return this.getSecondsAtTime(this.now())}set seconds(t){const e=this.now(),s=this.frequency.timeToTicks(t,e);this.setTicksAtTime(s,e)}getSecondsAtTime(t){t=this.toSeconds(t);const e=this._state.getLastState("stopped",t),s={state:"paused",time:t};this._state.add(s);let n=e,i=0;return this._state.forEachBetween(e.time,t+this.sampleTime,t=>{let e=n.time;const s=this._tickOffset.get(t.time);s&&s.time>=n.time&&(i=s.seconds,e=s.time),"started"===n.state&&"started"!==t.state&&(i+=t.time-e),n=t}),this._state.remove(s),i}setTicksAtTime(t,e){return e=this.toSeconds(e),this._tickOffset.cancel(e),this._tickOffset.add({seconds:this.frequency.getDurationOfTicks(t,e),ticks:t,time:e}),this}getStateAtTime(t){return t=this.toSeconds(t),this._state.getValueAtTime(t)}getTimeOfTick(t,e=this.now()){const s=this._tickOffset.get(e),n=this._state.get(e),i=Math.max(s.time,n.time),o=this.frequency.getTicksAtTime(i)+t-s.ticks;return this.frequency.getTimeOfTick(o)}forEachTickBetween(t,e,s){let n=this._state.get(t);this._state.forEachBetween(t,e,e=>{n&&"started"===n.state&&"started"!==e.state&&this.forEachTickBetween(Math.max(n.time,t),e.time-this.sampleTime,s),n=e});let i=null;if(n&&"started"===n.state){const o=Math.max(n.time,t),r=this.frequency.getTicksAtTime(o),a=r-this.frequency.getTicksAtTime(n.time);let c=Math.ceil(a)-a;c=Oi(c,1)?0:c;let h=this.frequency.getTimeOfTick(r+c);for(;h{switch(t.state){case"started":const e=this._tickSource.getTicksAtTime(t.time);this.emit("start",t.time,e);break;case"stopped":0!==t.time&&this.emit("stop",t.time);break;case"paused":this.emit("pause",t.time)}}),this._tickSource.forEachTickBetween(t,e,(t,e)=>{this.callback(t,e)}))}getStateAtTime(t){const e=this.toSeconds(t);return this._state.getValueAtTime(e)}dispose(){return super.dispose(),this.context.off("tick",this._boundLoop),this._tickSource.dispose(),this._state.dispose(),this}}Vi.mixin(Ao);class Do extends _o{constructor(){super(bi(Do.getDefaults(),arguments,["delayTime","maxDelay"])),this.name="Delay";const t=bi(Do.getDefaults(),arguments,["delayTime","maxDelay"]),e=this.toSeconds(t.maxDelay);this._maxDelay=Math.max(e,this.toSeconds(t.delayTime)),this._delayNode=this.input=this.output=this.context.createDelay(e),this.delayTime=new fo({context:this.context,param:this._delayNode.delayTime,units:"time",value:t.delayTime,minValue:0,maxValue:this.maxDelay}),ji(this,"delayTime")}static getDefaults(){return Object.assign(_o.getDefaults(),{delayTime:0,maxDelay:1})}get maxDelay(){return this._maxDelay}dispose(){return super.dispose(),this._delayNode.disconnect(),this.delayTime.dispose(),this}}function Oo(t,e,s=2,n=Qi().sampleRate){return di(this,void 0,void 0,(function*(){const i=Qi(),o=new Wi(s,e,n);Zi(o),yield t(o);const r=o.render();Zi(i);const a=yield r;return new Bi(a)}))}class Mo extends ki{constructor(){super(),this.name="ToneAudioBuffers",this._buffers=new Map,this._loadingCount=0;const t=bi(Mo.getDefaults(),arguments,["urls","onload","baseUrl"],"urls");this.baseUrl=t.baseUrl,Object.keys(t.urls).forEach(e=>{this._loadingCount++;const s=t.urls[e];this.add(e,s,this._bufferLoaded.bind(this,t.onload),t.onerror)})}static getDefaults(){return{baseUrl:"",onerror:zi,onload:zi,urls:{}}}has(t){return this._buffers.has(t.toString())}get(t){return Xn(this.has(t),"ToneAudioBuffers has no buffer named: "+t),this._buffers.get(t.toString())}_bufferLoaded(t){this._loadingCount--,0===this._loadingCount&&t&&t()}get loaded(){return Array.from(this._buffers).every(([t,e])=>e.loaded)}add(t,e,s=zi,n=zi){return ci(e)?this._buffers.set(t.toString(),new Bi(this.baseUrl+e,s,n)):this._buffers.set(t.toString(),new Bi(e,s,n)),this}dispose(){return super.dispose(),this._buffers.forEach(t=>t.dispose()),this._buffers.clear(),this}}class Eo extends oo{constructor(){super(...arguments),this.name="MidiClass",this.defaultUnits="midi"}_frequencyToUnits(t){return Ki(super._frequencyToUnits(t))}_ticksToUnits(t){return Ki(super._ticksToUnits(t))}_beatsToUnits(t){return Ki(super._beatsToUnits(t))}_secondsToUnits(t){return Ki(super._secondsToUnits(t))}toMidi(){return this.valueOf()}toFrequency(){return eo(this.toMidi())}transpose(t){return new Eo(this.context,this.toMidi()+t)}}function Ro(t,e){return new Eo(Qi(),t,e)}class qo extends ho{constructor(){super(...arguments),this.name="Ticks",this.defaultUnits="i"}_now(){return this.context.transport.ticks}_beatsToUnits(t){return this._getPPQ()*t}_secondsToUnits(t){return Math.floor(t/(60/this._getBpm())*this._getPPQ())}_ticksToUnits(t){return t}toTicks(){return this.valueOf()}toSeconds(){return this.valueOf()/this._getPPQ()*(60/this._getBpm())}}function Fo(t,e){return new qo(Qi(),t,e)}class Io extends lo{constructor(){super(...arguments),this.name="Draw",this.expiration=.25,this.anticipation=.008,this._events=new Ei,this._boundDrawLoop=this._drawLoop.bind(this),this._animationFrame=-1}schedule(t,e){return this._events.add({callback:t,time:this.toSeconds(e)}),1===this._events.length&&(this._animationFrame=requestAnimationFrame(this._boundDrawLoop)),this}cancel(t){return this._events.cancel(this.toSeconds(t)),this}_drawLoop(){const t=this.context.currentTime;for(;this._events.length&&this._events.peek().time-this.anticipation<=t;){const e=this._events.shift();e&&t-e.time<=this.expiration&&e.callback()}this._events.length>0&&(this._animationFrame=requestAnimationFrame(this._boundDrawLoop))}dispose(){return super.dispose(),this._events.dispose(),cancelAnimationFrame(this._animationFrame),this}}qi(t=>{t.draw=new Io({context:t})}),Ii(t=>{t.draw.dispose()});class Vo extends ki{constructor(){super(...arguments),this.name="IntervalTimeline",this._root=null,this._length=0}add(t){Xn(si(t.time),"Events must have a time property"),Xn(si(t.duration),"Events must have a duration parameter"),t.time=t.time.valueOf();let e=new No(t.time,t.time+t.duration,t);for(null===this._root?this._root=e:this._root.insert(e),this._length++;null!==e;)e.updateHeight(),e.updateMax(),this._rebalance(e),e=e.parent;return this}remove(t){if(null!==this._root){const e=[];this._root.search(t.time,e);for(const s of e)if(s.event===t){this._removeNode(s),this._length--;break}}return this}get length(){return this._length}cancel(t){return this.forEachFrom(t,t=>this.remove(t)),this}_setRoot(t){this._root=t,null!==this._root&&(this._root.parent=null)}_replaceNodeInParent(t,e){null!==t.parent?(t.isLeftChild()?t.parent.left=e:t.parent.right=e,this._rebalance(t.parent)):this._setRoot(e)}_removeNode(t){if(null===t.left&&null===t.right)this._replaceNodeInParent(t,null);else if(null===t.right)this._replaceNodeInParent(t,t.left);else if(null===t.left)this._replaceNodeInParent(t,t.right);else{let e,s=null;if(t.getBalance()>0)if(null===t.left.right)e=t.left,e.right=t.right,s=e;else{for(e=t.left.right;null!==e.right;)e=e.right;e.parent&&(e.parent.right=e.left,s=e.parent,e.left=t.left,e.right=t.right)}else if(null===t.right.left)e=t.right,e.left=t.left,s=e;else{for(e=t.right.left;null!==e.left;)e=e.left;e.parent&&(e.parent.left=e.right,s=e.parent,e.left=t.left,e.right=t.right)}null!==t.parent?t.isLeftChild()?t.parent.left=e:t.parent.right=e:this._setRoot(e),s&&this._rebalance(s)}t.dispose()}_rotateLeft(t){const e=t.parent,s=t.isLeftChild(),n=t.right;n&&(t.right=n.left,n.left=t),null!==e?s?e.left=n:e.right=n:this._setRoot(n)}_rotateRight(t){const e=t.parent,s=t.isLeftChild(),n=t.left;n&&(t.left=n.right,n.right=t),null!==e?s?e.left=n:e.right=n:this._setRoot(n)}_rebalance(t){const e=t.getBalance();e>1&&t.left?t.left.getBalance()<0?this._rotateLeft(t.left):this._rotateRight(t):e<-1&&t.right&&(t.right.getBalance()>0?this._rotateRight(t.right):this._rotateLeft(t))}get(t){if(null!==this._root){const e=[];if(this._root.search(t,e),e.length>0){let t=e[0];for(let s=1;st.low&&(t=e[s]);return t.event}}return null}forEach(t){if(null!==this._root){const e=[];this._root.traverse(t=>e.push(t)),e.forEach(e=>{e.event&&t(e.event)})}return this}forEachAtTime(t,e){if(null!==this._root){const s=[];this._root.search(t,s),s.forEach(t=>{t.event&&e(t.event)})}return this}forEachFrom(t,e){if(null!==this._root){const s=[];this._root.searchAfter(t,s),s.forEach(t=>{t.event&&e(t.event)})}return this}dispose(){return super.dispose(),null!==this._root&&this._root.traverse(t=>t.dispose()),this._root=null,this}}class No{constructor(t,e,s){this._left=null,this._right=null,this.parent=null,this.height=0,this.event=s,this.low=t,this.high=e,this.max=this.high}insert(t){t.low<=this.low?null===this.left?this.left=t:this.left.insert(t):null===this.right?this.right=t:this.right.insert(t)}search(t,e){t>this.max||(null!==this.left&&this.left.search(t,e),this.low<=t&&this.high>t&&e.push(this),this.low>t||null!==this.right&&this.right.search(t,e))}searchAfter(t,e){this.low>=t&&(e.push(this),null!==this.left&&this.left.searchAfter(t,e)),null!==this.right&&this.right.searchAfter(t,e)}traverse(t){t(this),null!==this.left&&this.left.traverse(t),null!==this.right&&this.right.traverse(t)}updateHeight(){null!==this.left&&null!==this.right?this.height=Math.max(this.left.height,this.right.height)+1:null!==this.right?this.height=this.right.height+1:null!==this.left?this.height=this.left.height+1:this.height=0}updateMax(){this.max=this.high,null!==this.left&&(this.max=Math.max(this.max,this.left.max)),null!==this.right&&(this.max=Math.max(this.max,this.right.max))}getBalance(){let t=0;return null!==this.left&&null!==this.right?t=this.left.height-this.right.height:null!==this.left?t=this.left.height+1:null!==this.right&&(t=-(this.right.height+1)),t}isLeftChild(){return null!==this.parent&&this.parent.left===this}get left(){return this._left}set left(t){this._left=t,null!==t&&(t.parent=this),this.updateHeight(),this.updateMax()}get right(){return this._right}set right(t){this._right=t,null!==t&&(t.parent=this),this.updateHeight(),this.updateMax()}dispose(){this.parent=null,this._left=null,this._right=null,this.event=null}}class Po extends _o{constructor(){super(bi(Po.getDefaults(),arguments,["volume"])),this.name="Volume";const t=bi(Po.getDefaults(),arguments,["volume"]);this.input=this.output=new yo({context:this.context,gain:t.volume,units:"decibels"}),this.volume=this.output.gain,ji(this,"volume"),this._unmutedVolume=t.volume,this.mute=t.mute}static getDefaults(){return Object.assign(_o.getDefaults(),{mute:!1,volume:0})}get mute(){return this.volume.value===-1/0}set mute(t){!this.mute&&t?(this._unmutedVolume=this.volume.value,this.volume.value=-1/0):this.mute&&!t&&(this.volume.value=this._unmutedVolume)}dispose(){return super.dispose(),this.input.dispose(),this.volume.dispose(),this}}class jo extends _o{constructor(){super(bi(jo.getDefaults(),arguments)),this.name="Destination",this.input=new Po({context:this.context}),this.output=new yo({context:this.context}),this.volume=this.input.volume;const t=bi(jo.getDefaults(),arguments);mo(this.input,this.output,this.context.rawContext.destination),this.mute=t.mute,this._internalChannels=[this.input,this.context.rawContext.destination,this.output]}static getDefaults(){return Object.assign(_o.getDefaults(),{mute:!1,volume:0})}get mute(){return this.input.mute}set mute(t){this.input.mute=t}chain(...t){return this.input.disconnect(),t.unshift(this.input),t.push(this.output),mo(...t),this}get maxChannelCount(){return this.context.rawContext.destination.maxChannelCount}dispose(){return super.dispose(),this.volume.dispose(),this}}qi(t=>{t.destination=new jo({context:t})}),Ii(t=>{t.destination.dispose()});class Lo extends ki{constructor(t){super(),this.name="TimelineValue",this._timeline=new Ei({memory:10}),this._initialValue=t}set(t,e){return this._timeline.add({value:t,time:e}),this}get(t){const e=this._timeline.get(t);return e?e.value:this._initialValue}}class zo{constructor(t,e){this.id=zo._eventId++;const s=Object.assign(zo.getDefaults(),e);this.transport=t,this.callback=s.callback,this._once=s.once,this.time=s.time}static getDefaults(){return{callback:zi,once:!1,time:0}}invoke(t){this.callback&&(this.callback(t),this._once&&this.transport.clear(this.id))}dispose(){return this.callback=void 0,this}}zo._eventId=0;class Bo extends zo{constructor(t,e){super(t,e),this._currentId=-1,this._nextId=-1,this._nextTick=this.time,this._boundRestart=this._restart.bind(this);const s=Object.assign(Bo.getDefaults(),e);this.duration=new qo(t.context,s.duration).valueOf(),this._interval=new qo(t.context,s.interval).valueOf(),this._nextTick=s.time,this.transport.on("start",this._boundRestart),this.transport.on("loopStart",this._boundRestart),this.context=this.transport.context,this._restart()}static getDefaults(){return Object.assign({},zo.getDefaults(),{duration:1/0,interval:1,once:!1})}invoke(t){this._createEvents(t),super.invoke(t)}_createEvents(t){const e=this.transport.getTicksAtTime(t);e>=this.time&&e>=this._nextTick&&this._nextTick+this._intervalthis.time&&(this._nextTick=this.time+Math.ceil((e-this.time)/this._interval)*this._interval),this._currentId=this.transport.scheduleOnce(this.invoke.bind(this),new qo(this.context,this._nextTick).toSeconds()),this._nextTick+=this._interval,this._nextId=this.transport.scheduleOnce(this.invoke.bind(this),new qo(this.context,this._nextTick).toSeconds())}dispose(){return super.dispose(),this.transport.clear(this._currentId),this.transport.clear(this._nextId),this.transport.off("start",this._boundRestart),this.transport.off("loopStart",this._boundRestart),this}}class Wo extends lo{constructor(){super(bi(Wo.getDefaults(),arguments)),this.name="Transport",this._loop=new Lo(!1),this._loopStart=0,this._loopEnd=0,this._scheduledEvents={},this._timeline=new Ei,this._repeatedEvents=new Vo,this._syncedSignals=[],this._swingAmount=0;const t=bi(Wo.getDefaults(),arguments);this._ppq=t.ppq,this._clock=new Ao({callback:this._processTick.bind(this),context:this.context,frequency:0,units:"bpm"}),this._bindClockEvents(),this.bpm=this._clock.frequency,this._clock.frequency.multiplier=t.ppq,this.bpm.setValueAtTime(t.bpm,0),ji(this,"bpm"),this._timeSignature=t.timeSignature,this._swingTicks=t.ppq/2}static getDefaults(){return Object.assign(lo.getDefaults(),{bpm:120,loopEnd:"4m",loopStart:0,ppq:192,swing:0,swingSubdivision:"8n",timeSignature:4})}_processTick(t,e){if(this._swingAmount>0&&e%this._ppq!=0&&e%(2*this._swingTicks)!=0){const s=e%(2*this._swingTicks)/(2*this._swingTicks),n=Math.sin(s*Math.PI)*this._swingAmount;t+=new qo(this.context,2*this._swingTicks/3).toSeconds()*n}this._loop.get(t)&&e>=this._loopEnd&&(this.emit("loopEnd",t),this._clock.setTicksAtTime(this._loopStart,t),e=this._loopStart,this.emit("loopStart",t,this._clock.getSecondsAtTime(t)),this.emit("loop",t)),this._timeline.forEachAtTime(e,e=>e.invoke(t))}schedule(t,e){const s=new zo(this,{callback:t,time:new ho(this.context,e).toTicks()});return this._addEvent(s,this._timeline)}scheduleRepeat(t,e,s,n=1/0){const i=new Bo(this,{callback:t,duration:new no(this.context,n).toTicks(),interval:new no(this.context,e).toTicks(),time:new ho(this.context,s).toTicks()});return this._addEvent(i,this._repeatedEvents)}scheduleOnce(t,e){const s=new zo(this,{callback:t,once:!0,time:new ho(this.context,e).toTicks()});return this._addEvent(s,this._timeline)}clear(t){if(this._scheduledEvents.hasOwnProperty(t)){const e=this._scheduledEvents[t.toString()];e.timeline.remove(e.event),e.event.dispose(),delete this._scheduledEvents[t.toString()]}return this}_addEvent(t,e){return this._scheduledEvents[t.id.toString()]={event:t,timeline:e},e.add(t),t.id}cancel(t=0){const e=this.toTicks(t);return this._timeline.forEachFrom(e,t=>this.clear(t.id)),this._repeatedEvents.forEachFrom(e,t=>this.clear(t.id)),this}_bindClockEvents(){this._clock.on("start",(t,e)=>{e=new qo(this.context,e).toSeconds(),this.emit("start",t,e)}),this._clock.on("stop",t=>{this.emit("stop",t)}),this._clock.on("pause",t=>{this.emit("pause",t)})}get state(){return this._clock.getStateAtTime(this.now())}start(t,e){let s;return si(e)&&(s=this.toTicks(e)),this._clock.start(t,s),this}stop(t){return this._clock.stop(t),this}pause(t){return this._clock.pause(t),this}toggle(t){return t=this.toSeconds(t),"started"!==this._clock.getStateAtTime(t)?this.start(t):this.stop(t),this}get timeSignature(){return this._timeSignature}set timeSignature(t){ai(t)&&(t=t[0]/t[1]*4),this._timeSignature=t}get loopStart(){return new no(this.context,this._loopStart,"i").toSeconds()}set loopStart(t){this._loopStart=this.toTicks(t)}get loopEnd(){return new no(this.context,this._loopEnd,"i").toSeconds()}set loopEnd(t){this._loopEnd=this.toTicks(t)}get loop(){return this._loop.get(this.now())}set loop(t){this._loop.set(t,this.now())}setLoopPoints(t,e){return this.loopStart=t,this.loopEnd=e,this}get swing(){return this._swingAmount}set swing(t){this._swingAmount=t}get swingSubdivision(){return new qo(this.context,this._swingTicks).toNotation()}set swingSubdivision(t){this._swingTicks=this.toTicks(t)}get position(){const t=this.now(),e=this._clock.getTicksAtTime(t);return new qo(this.context,e).toBarsBeatsSixteenths()}set position(t){const e=this.toTicks(t);this.ticks=e}get seconds(){return this._clock.seconds}set seconds(t){const e=this.now(),s=this._clock.frequency.timeToTicks(t,e);this.ticks=s}get progress(){if(this.loop){const t=this.now();return(this._clock.getTicksAtTime(t)-this._loopStart)/(this._loopEnd-this._loopStart)}return 0}get ticks(){return this._clock.ticks}set ticks(t){if(this._clock.ticks!==t){const e=this.now();if("started"===this.state){const s=this._clock.getTicksAtTime(e),n=this._clock.getTimeOfTick(Math.ceil(s));this.emit("stop",n),this._clock.setTicksAtTime(t,n),this.emit("start",n,this._clock.getSecondsAtTime(n))}else this._clock.setTicksAtTime(t,e)}}getTicksAtTime(t){return Math.round(this._clock.getTicksAtTime(t))}getSecondsAtTime(t){return this._clock.getSecondsAtTime(t)}get PPQ(){return this._clock.frequency.multiplier}set PPQ(t){this._clock.frequency.multiplier=t}nextSubdivision(t){if(t=this.toTicks(t),"started"!==this.state)return 0;{const e=this.now(),s=t-this.getTicksAtTime(e)%t;return this._clock.nextTickTime(s,e)}}syncSignal(t,e){if(!e){const s=this.now();if(0!==t.getValueAtTime(s)){const n=1/(60/this.bpm.getValueAtTime(s)/this.PPQ);e=t.getValueAtTime(s)/n}else e=0}const s=new yo(e);return this.bpm.connect(s),s.connect(t._param),this._syncedSignals.push({initial:t.value,ratio:s,signal:t}),t.value=0,this}unsyncSignal(t){for(let e=this._syncedSignals.length-1;e>=0;e--){const s=this._syncedSignals[e];s.signal===t&&(s.ratio.dispose(),s.signal.value=s.initial,this._syncedSignals.splice(e,1))}return this}dispose(){return super.dispose(),this._clock.dispose(),Li(this,"bpm"),this._timeline.dispose(),this._repeatedEvents.dispose(),this}}Vi.mixin(Wo),qi(t=>{t.transport=new Wo({context:t})}),Ii(t=>{t.transport.dispose()});class Uo extends _o{constructor(t){super(t),this.input=void 0,this._state=new po("stopped"),this._synced=!1,this._scheduled=[],this._syncedStart=zi,this._syncedStop=zi,this._state.memory=100,this._state.increasing=!0,this._volume=this.output=new Po({context:this.context,mute:t.mute,volume:t.volume}),this.volume=this._volume.volume,ji(this,"volume"),this.onstop=t.onstop}static getDefaults(){return Object.assign(_o.getDefaults(),{mute:!1,onstop:zi,volume:0})}get state(){return this._synced?"started"===this.context.transport.state?this._state.getValueAtTime(this.context.transport.seconds):"stopped":this._state.getValueAtTime(this.now())}get mute(){return this._volume.mute}set mute(t){this._volume.mute=t}_clampToCurrentTime(t){return this._synced?t:Math.max(t,this.context.currentTime)}start(t,e,s){let n=ei(t)&&this._synced?this.context.transport.seconds:this.toSeconds(t);if(n=this._clampToCurrentTime(n),this._synced||"started"!==this._state.getValueAtTime(n))if(this.log("start",n),this._state.setStateAtTime("started",n),this._synced){const t=this._state.get(n);t&&(t.offset=this.toSeconds(Ti(e,0)),t.duration=s?this.toSeconds(s):void 0);const i=this.context.transport.schedule(t=>{this._start(t,e,s)},n);this._scheduled.push(i),"started"===this.context.transport.state&&this.context.transport.getSecondsAtTime(this.immediate())>n&&this._syncedStart(this.now(),this.context.transport.seconds)}else Hn(this.context),this._start(n,e,s);else Xn(Ci(n,this._state.get(n).time),"Start time must be strictly greater than previous start time"),this._state.cancel(n),this._state.setStateAtTime("started",n),this.log("restart",n),this.restart(n,e,s);return this}stop(t){let e=ei(t)&&this._synced?this.context.transport.seconds:this.toSeconds(t);if(e=this._clampToCurrentTime(e),"started"===this._state.getValueAtTime(e)||si(this._state.getNextState("started",e))){if(this.log("stop",e),this._synced){const t=this.context.transport.schedule(this._stop.bind(this),e);this._scheduled.push(t)}else this._stop(e);this._state.cancel(e),this._state.setStateAtTime("stopped",e)}return this}restart(t,e,s){return t=this.toSeconds(t),"started"===this._state.getValueAtTime(t)&&(this._state.cancel(t),this._restart(t,e,s)),this}sync(){return this._synced||(this._synced=!0,this._syncedStart=(t,e)=>{if(e>0){const s=this._state.get(e);if(s&&"started"===s.state&&s.time!==e){const n=e-this.toSeconds(s.time);let i;s.duration&&(i=this.toSeconds(s.duration)-n),this._start(t,this.toSeconds(s.offset)+n,i)}}},this._syncedStop=t=>{const e=this.context.transport.getSecondsAtTime(Math.max(t-this.sampleTime,0));"started"===this._state.getValueAtTime(e)&&this._stop(t)},this.context.transport.on("start",this._syncedStart),this.context.transport.on("loopStart",this._syncedStart),this.context.transport.on("stop",this._syncedStop),this.context.transport.on("pause",this._syncedStop),this.context.transport.on("loopEnd",this._syncedStop)),this}unsync(){return this._synced&&(this.context.transport.off("stop",this._syncedStop),this.context.transport.off("pause",this._syncedStop),this.context.transport.off("loopEnd",this._syncedStop),this.context.transport.off("start",this._syncedStart),this.context.transport.off("loopStart",this._syncedStart)),this._synced=!1,this._scheduled.forEach(t=>this.context.transport.clear(t)),this._scheduled=[],this._state.cancel(0),this._stop(0),this}dispose(){return super.dispose(),this.onstop=zi,this.unsync(),this._volume.dispose(),this._state.dispose(),this}}class Go extends xo{constructor(){super(bi(Go.getDefaults(),arguments,["url","onload"])),this.name="ToneBufferSource",this._source=this.context.createBufferSource(),this._internalChannels=[this._source],this._sourceStarted=!1,this._sourceStopped=!1;const t=bi(Go.getDefaults(),arguments,["url","onload"]);go(this._source,this._gainNode),this._source.onended=()=>this._stopSource(),this.playbackRate=new fo({context:this.context,param:this._source.playbackRate,units:"positive",value:t.playbackRate}),this.loop=t.loop,this.loopStart=t.loopStart,this.loopEnd=t.loopEnd,this._buffer=new Bi(t.url,t.onload,t.onerror),this._internalChannels.push(this._source)}static getDefaults(){return Object.assign(xo.getDefaults(),{url:new Bi,loop:!1,loopEnd:0,loopStart:0,onload:zi,onerror:zi,playbackRate:1})}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t}get curve(){return this._curve}set curve(t){this._curve=t}start(t,e,s,n=1){Xn(this.buffer.loaded,"buffer is either not set or not loaded");const i=this.toSeconds(t);this._startGain(i,n),e=this.loop?Ti(e,this.loopStart):Ti(e,0);let o=Math.max(this.toSeconds(e),0);if(this.loop){const t=this.toSeconds(this.loopEnd)||this.buffer.duration,e=this.toSeconds(this.loopStart),s=t-e;Ai(o,t)&&(o=(o-e)%s+e),Oi(o,this.buffer.duration)&&(o=0)}if(this._source.buffer=this.buffer.get(),this._source.loopEnd=this.toSeconds(this.loopEnd)||this.buffer.duration,Di(o,this.buffer.duration)&&(this._sourceStarted=!0,this._source.start(i,o)),si(s)){let t=this.toSeconds(s);t=Math.max(t,0),this.stop(i+t)}return this}_stopSource(t){!this._sourceStopped&&this._sourceStarted&&(this._sourceStopped=!0,this._source.stop(this.toSeconds(t)),this._onended())}get loopStart(){return this._source.loopStart}set loopStart(t){this._source.loopStart=this.toSeconds(t)}get loopEnd(){return this._source.loopEnd}set loopEnd(t){this._source.loopEnd=this.toSeconds(t)}get buffer(){return this._buffer}set buffer(t){this._buffer.set(t)}get loop(){return this._source.loop}set loop(t){this._source.loop=t,this._sourceStarted&&this.cancelStop()}dispose(){return super.dispose(),this._source.onended=null,this._source.disconnect(),this._buffer.dispose(),this.playbackRate.dispose(),this}}class Qo extends Uo{constructor(){super(bi(Qo.getDefaults(),arguments,["type"])),this.name="Noise",this._source=null;const t=bi(Qo.getDefaults(),arguments,["type"]);this._playbackRate=t.playbackRate,this.type=t.type,this._fadeIn=t.fadeIn,this._fadeOut=t.fadeOut}static getDefaults(){return Object.assign(Uo.getDefaults(),{fadeIn:0,fadeOut:0,playbackRate:1,type:"white"})}get type(){return this._type}set type(t){if(Xn(t in Xo,"Noise: invalid type: "+t),this._type!==t&&(this._type=t,"started"===this.state)){const t=this.now();this._stop(t),this._start(t)}}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this._source&&(this._source.playbackRate.value=t)}_start(t){const e=Xo[this._type];this._source=new Go({url:e,context:this.context,fadeIn:this._fadeIn,fadeOut:this._fadeOut,loop:!0,onended:()=>this.onstop(this),playbackRate:this._playbackRate}).connect(this.output),this._source.start(this.toSeconds(t),Math.random()*(e.duration-.001))}_stop(t){this._source&&(this._source.stop(this.toSeconds(t)),this._source=null)}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t,this._source&&(this._source.fadeIn=this._fadeIn)}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t,this._source&&(this._source.fadeOut=this._fadeOut)}_restart(t){this._stop(t),this._start(t)}dispose(){return super.dispose(),this._source&&this._source.disconnect(),this}}const Zo={brown:null,pink:null,white:null},Xo={get brown(){if(!Zo.brown){const t=[];for(let e=0;e<2;e++){const s=new Float32Array(220500);t[e]=s;let n=0;for(let t=0;t<220500;t++){const e=2*Math.random()-1;s[t]=(n+.02*e)/1.02,n=s[t],s[t]*=3.5}}Zo.brown=(new Bi).fromArray(t)}return Zo.brown},get pink(){if(!Zo.pink){const t=[];for(let e=0;e<2;e++){const s=new Float32Array(220500);let n,i,o,r,a,c,h;t[e]=s,n=i=o=r=a=c=h=0;for(let t=0;t<220500;t++){const e=2*Math.random()-1;n=.99886*n+.0555179*e,i=.99332*i+.0750759*e,o=.969*o+.153852*e,r=.8665*r+.3104856*e,a=.55*a+.5329522*e,c=-.7616*c-.016898*e,s[t]=n+i+o+r+a+c+h+.5362*e,s[t]*=.11,h=.115926*e}}Zo.pink=(new Bi).fromArray(t)}return Zo.pink},get white(){if(!Zo.white){const t=[];for(let e=0;e<2;e++){const s=new Float32Array(220500);t[e]=s;for(let t=0;t<220500;t++)s[t]=2*Math.random()-1}Zo.white=(new Bi).fromArray(t)}return Zo.white}};class Yo extends _o{constructor(){super(bi(Yo.getDefaults(),arguments,["volume"])),this.name="UserMedia";const t=bi(Yo.getDefaults(),arguments,["volume"]);this._volume=this.output=new Po({context:this.context,volume:t.volume}),this.volume=this._volume.volume,ji(this,"volume"),this.mute=t.mute}static getDefaults(){return Object.assign(_o.getDefaults(),{mute:!1,volume:0})}open(t){return di(this,void 0,void 0,(function*(){Xn(Yo.supported,"UserMedia is not supported"),"started"===this.state&&this.close();const e=yield Yo.enumerateDevices();ii(t)?this._device=e[t]:(this._device=e.find(e=>e.label===t||e.deviceId===t),!this._device&&e.length>0&&(this._device=e[0]),Xn(si(this._device),"No matching device "+t));const s={audio:{echoCancellation:!1,sampleRate:this.context.sampleRate,noiseSuppression:!1,mozNoiseSuppression:!1}};this._device&&(s.audio.deviceId=this._device.deviceId);const n=yield navigator.mediaDevices.getUserMedia(s);if(!this._stream){this._stream=n;const t=this.context.createMediaStreamSource(n);go(t,this.output),this._mediaStream=t}return this}))}close(){return this._stream&&this._mediaStream&&(this._stream.getAudioTracks().forEach(t=>{t.stop()}),this._stream=void 0,this._mediaStream.disconnect(),this._mediaStream=void 0),this._device=void 0,this}static enumerateDevices(){return di(this,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter(t=>"audioinput"===t.kind)}))}get state(){return this._stream&&this._stream.active?"started":"stopped"}get deviceId(){return this._device?this._device.deviceId:void 0}get groupId(){return this._device?this._device.groupId:void 0}get label(){return this._device?this._device.label:void 0}get mute(){return this._volume.mute}set mute(t){this._volume.mute=t}dispose(){return super.dispose(),this.close(),this._volume.dispose(),this.volume.dispose(),this}static get supported(){return si(navigator.mediaDevices)&&si(navigator.mediaDevices.getUserMedia)}}function Ho(t,e){return di(this,void 0,void 0,(function*(){const s=e/t.context.sampleRate,n=new Wi(1,s,t.context.sampleRate);new t.constructor(Object.assign(t.get(),{frequency:2/s,detune:0,context:n})).toDestination().start(0);return(yield n.render()).getChannelData(0)}))}class $o extends xo{constructor(){super(bi($o.getDefaults(),arguments,["frequency","type"])),this.name="ToneOscillatorNode",this._oscillator=this.context.createOscillator(),this._internalChannels=[this._oscillator];const t=bi($o.getDefaults(),arguments,["frequency","type"]);go(this._oscillator,this._gainNode),this.type=t.type,this.frequency=new fo({context:this.context,param:this._oscillator.frequency,units:"frequency",value:t.frequency}),this.detune=new fo({context:this.context,param:this._oscillator.detune,units:"cents",value:t.detune}),ji(this,["frequency","detune"])}static getDefaults(){return Object.assign(xo.getDefaults(),{detune:0,frequency:440,type:"sine"})}start(t){const e=this.toSeconds(t);return this.log("start",e),this._startGain(e),this._oscillator.start(e),this}_stopSource(t){this._oscillator.stop(t)}setPeriodicWave(t){return this._oscillator.setPeriodicWave(t),this}get type(){return this._oscillator.type}set type(t){this._oscillator.type=t}dispose(){return super.dispose(),"started"===this.state&&this.stop(),this._oscillator.disconnect(),this.frequency.dispose(),this.detune.dispose(),this}}class Jo extends Uo{constructor(){super(bi(Jo.getDefaults(),arguments,["frequency","type"])),this.name="Oscillator",this._oscillator=null;const t=bi(Jo.getDefaults(),arguments,["frequency","type"]);this.frequency=new bo({context:this.context,units:"frequency",value:t.frequency}),ji(this,"frequency"),this.detune=new bo({context:this.context,units:"cents",value:t.detune}),ji(this,"detune"),this._partials=t.partials,this._partialCount=t.partialCount,this._type=t.type,t.partialCount&&"custom"!==t.type&&(this._type=this.baseType+t.partialCount.toString()),this.phase=t.phase}static getDefaults(){return Object.assign(Uo.getDefaults(),{detune:0,frequency:440,partialCount:0,partials:[],phase:0,type:"sine"})}_start(t){const e=this.toSeconds(t),s=new $o({context:this.context,onended:()=>this.onstop(this)});this._oscillator=s,this._wave?this._oscillator.setPeriodicWave(this._wave):this._oscillator.type=this._type,this._oscillator.connect(this.output),this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.start(e)}_stop(t){const e=this.toSeconds(t);this._oscillator&&this._oscillator.stop(e)}_restart(t){const e=this.toSeconds(t);return this.log("restart",e),this._oscillator&&this._oscillator.cancelStop(),this._state.cancel(e),this}syncFrequency(){return this.context.transport.syncSignal(this.frequency),this}unsyncFrequency(){return this.context.transport.unsyncSignal(this.frequency),this}_getCachedPeriodicWave(){if("custom"===this._type){return Jo._periodicWaveCache.find(t=>{return t.phase===this._phase&&(e=t.partials,s=this._partials,e.length===s.length&&e.every((t,e)=>s[e]===t));var e,s})}{const t=Jo._periodicWaveCache.find(t=>t.type===this._type&&t.phase===this._phase);return this._partialCount=t?t.partialCount:this._partialCount,t}}get type(){return this._type}set type(t){this._type=t;const e=-1!==["sine","square","sawtooth","triangle"].indexOf(t);if(0===this._phase&&e)this._wave=void 0,this._partialCount=0,null!==this._oscillator&&(this._oscillator.type=t);else{const e=this._getCachedPeriodicWave();if(si(e)){const{partials:t,wave:s}=e;this._wave=s,this._partials=t,null!==this._oscillator&&this._oscillator.setPeriodicWave(this._wave)}else{const[e,s]=this._getRealImaginary(t,this._phase),n=this.context.createPeriodicWave(e,s);this._wave=n,null!==this._oscillator&&this._oscillator.setPeriodicWave(this._wave),Jo._periodicWaveCache.push({imag:s,partialCount:this._partialCount,partials:this._partials,phase:this._phase,real:e,type:this._type,wave:this._wave}),Jo._periodicWaveCache.length>100&&Jo._periodicWaveCache.shift()}}}get baseType(){return this._type.replace(this.partialCount.toString(),"")}set baseType(t){this.partialCount&&"custom"!==this._type&&"custom"!==t?this.type=t+this.partialCount:this.type=t}get partialCount(){return this._partialCount}set partialCount(t){Yn(t,0);let e=this._type;const s=/^(sine|triangle|square|sawtooth)(\d+)$/.exec(this._type);if(s&&(e=s[1]),"custom"!==this._type)this.type=0===t?e:e+t.toString();else{const e=new Float32Array(t);this._partials.forEach((t,s)=>e[s]=t),this._partials=Array.from(e),this.type=this._type}}_getRealImaginary(t,e){let s=2048;const n=new Float32Array(s),i=new Float32Array(s);let o=1;if("custom"===t){if(o=this._partials.length+1,this._partialCount=this._partials.length,s=o,0===this._partials.length)return[n,i]}else{const e=/^(sine|triangle|square|sawtooth)(\d+)$/.exec(t);e?(o=parseInt(e[2],10)+1,this._partialCount=parseInt(e[2],10),t=e[1],o=Math.max(o,2),s=o):this._partialCount=0,this._partials=[]}for(let r=1;r>1&1?-1:1):0,this._partials[r-1]=a;break;case"custom":a=this._partials[r-1];break;default:throw new TypeError("Oscillator: invalid type: "+t)}0!==a?(n[r]=-a*Math.sin(e*r),i[r]=a*Math.cos(e*r)):(n[r]=0,i[r]=0)}return[n,i]}_inverseFFT(t,e,s){let n=0;const i=t.length;for(let o=0;oe.includes(t)),"oversampling must be either 'none', '2x', or '4x'"),this._shaper.oversample=t}dispose(){return super.dispose(),this._shaper.disconnect(),this}}class er extends Ko{constructor(){super(...arguments),this.name="AudioToGain",this._norm=new tr({context:this.context,mapping:t=>(t+1)/2}),this.input=this._norm,this.output=this._norm}dispose(){return super.dispose(),this._norm.dispose(),this}}class sr extends bo{constructor(){super(Object.assign(bi(sr.getDefaults(),arguments,["value"]))),this.name="Multiply",this.override=!1;const t=bi(sr.getDefaults(),arguments,["value"]);this._mult=this.input=this.output=new yo({context:this.context,minValue:t.minValue,maxValue:t.maxValue}),this.factor=this._param=this._mult.gain,this.factor.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign(bo.getDefaults(),{value:0})}dispose(){return super.dispose(),this._mult.dispose(),this}}class nr extends Uo{constructor(){super(bi(nr.getDefaults(),arguments,["frequency","type","modulationType"])),this.name="AMOscillator",this._modulationScale=new er({context:this.context}),this._modulationNode=new yo({context:this.context});const t=bi(nr.getDefaults(),arguments,["frequency","type","modulationType"]);this._carrier=new Jo({context:this.context,detune:t.detune,frequency:t.frequency,onstop:()=>this.onstop(this),phase:t.phase,type:t.type}),this.frequency=this._carrier.frequency,this.detune=this._carrier.detune,this._modulator=new Jo({context:this.context,phase:t.phase,type:t.modulationType}),this.harmonicity=new sr({context:this.context,units:"positive",value:t.harmonicity}),this.frequency.chain(this.harmonicity,this._modulator.frequency),this._modulator.chain(this._modulationScale,this._modulationNode.gain),this._carrier.chain(this._modulationNode,this.output),ji(this,["frequency","detune","harmonicity"])}static getDefaults(){return Object.assign(Jo.getDefaults(),{harmonicity:1,modulationType:"square"})}_start(t){this._modulator.start(t),this._carrier.start(t)}_stop(t){this._modulator.stop(t),this._carrier.stop(t)}_restart(t){this._modulator.restart(t),this._carrier.restart(t)}get type(){return this._carrier.type}set type(t){this._carrier.type=t}get baseType(){return this._carrier.baseType}set baseType(t){this._carrier.baseType=t}get partialCount(){return this._carrier.partialCount}set partialCount(t){this._carrier.partialCount=t}get modulationType(){return this._modulator.type}set modulationType(t){this._modulator.type=t}get phase(){return this._carrier.phase}set phase(t){this._carrier.phase=t,this._modulator.phase=t}get partials(){return this._carrier.partials}set partials(t){this._carrier.partials=t}asArray(t=1024){return di(this,void 0,void 0,(function*(){return Ho(this,t)}))}dispose(){return super.dispose(),this.frequency.dispose(),this.detune.dispose(),this.harmonicity.dispose(),this._carrier.dispose(),this._modulator.dispose(),this._modulationNode.dispose(),this._modulationScale.dispose(),this}}class ir extends Uo{constructor(){super(bi(ir.getDefaults(),arguments,["frequency","type","modulationType"])),this.name="FMOscillator",this._modulationNode=new yo({context:this.context,gain:0});const t=bi(ir.getDefaults(),arguments,["frequency","type","modulationType"]);this._carrier=new Jo({context:this.context,detune:t.detune,frequency:0,onstop:()=>this.onstop(this),phase:t.phase,type:t.type}),this.detune=this._carrier.detune,this.frequency=new bo({context:this.context,units:"frequency",value:t.frequency}),this._modulator=new Jo({context:this.context,phase:t.phase,type:t.modulationType}),this.harmonicity=new sr({context:this.context,units:"positive",value:t.harmonicity}),this.modulationIndex=new sr({context:this.context,units:"positive",value:t.modulationIndex}),this.frequency.connect(this._carrier.frequency),this.frequency.chain(this.harmonicity,this._modulator.frequency),this.frequency.chain(this.modulationIndex,this._modulationNode),this._modulator.connect(this._modulationNode.gain),this._modulationNode.connect(this._carrier.frequency),this._carrier.connect(this.output),this.detune.connect(this._modulator.detune),ji(this,["modulationIndex","frequency","detune","harmonicity"])}static getDefaults(){return Object.assign(Jo.getDefaults(),{harmonicity:1,modulationIndex:2,modulationType:"square"})}_start(t){this._modulator.start(t),this._carrier.start(t)}_stop(t){this._modulator.stop(t),this._carrier.stop(t)}_restart(t){return this._modulator.restart(t),this._carrier.restart(t),this}get type(){return this._carrier.type}set type(t){this._carrier.type=t}get baseType(){return this._carrier.baseType}set baseType(t){this._carrier.baseType=t}get partialCount(){return this._carrier.partialCount}set partialCount(t){this._carrier.partialCount=t}get modulationType(){return this._modulator.type}set modulationType(t){this._modulator.type=t}get phase(){return this._carrier.phase}set phase(t){this._carrier.phase=t,this._modulator.phase=t}get partials(){return this._carrier.partials}set partials(t){this._carrier.partials=t}asArray(t=1024){return di(this,void 0,void 0,(function*(){return Ho(this,t)}))}dispose(){return super.dispose(),this.frequency.dispose(),this.harmonicity.dispose(),this._carrier.dispose(),this._modulator.dispose(),this._modulationNode.dispose(),this.modulationIndex.dispose(),this}}class or extends Uo{constructor(){super(bi(or.getDefaults(),arguments,["frequency","width"])),this.name="PulseOscillator",this._widthGate=new yo({context:this.context,gain:0}),this._thresh=new tr({context:this.context,mapping:t=>t<=0?-1:1});const t=bi(or.getDefaults(),arguments,["frequency","width"]);this.width=new bo({context:this.context,units:"audioRange",value:t.width}),this._triangle=new Jo({context:this.context,detune:t.detune,frequency:t.frequency,onstop:()=>this.onstop(this),phase:t.phase,type:"triangle"}),this.frequency=this._triangle.frequency,this.detune=this._triangle.detune,this._triangle.chain(this._thresh,this.output),this.width.chain(this._widthGate,this._thresh),ji(this,["width","frequency","detune"])}static getDefaults(){return Object.assign(Uo.getDefaults(),{detune:0,frequency:440,phase:0,type:"pulse",width:.2})}_start(t){t=this.toSeconds(t),this._triangle.start(t),this._widthGate.gain.setValueAtTime(1,t)}_stop(t){t=this.toSeconds(t),this._triangle.stop(t),this._widthGate.gain.cancelScheduledValues(t),this._widthGate.gain.setValueAtTime(0,t)}_restart(t){this._triangle.restart(t),this._widthGate.gain.cancelScheduledValues(t),this._widthGate.gain.setValueAtTime(1,t)}get phase(){return this._triangle.phase}set phase(t){this._triangle.phase=t}get type(){return"pulse"}get baseType(){return"pulse"}get partials(){return[]}get partialCount(){return 0}set carrierType(t){this._triangle.type=t}asArray(t=1024){return di(this,void 0,void 0,(function*(){return Ho(this,t)}))}dispose(){return super.dispose(),this._triangle.dispose(),this.width.dispose(),this._widthGate.dispose(),this._thresh.dispose(),this}}class rr extends Uo{constructor(){super(bi(rr.getDefaults(),arguments,["frequency","type","spread"])),this.name="FatOscillator",this._oscillators=[];const t=bi(rr.getDefaults(),arguments,["frequency","type","spread"]);this.frequency=new bo({context:this.context,units:"frequency",value:t.frequency}),this.detune=new bo({context:this.context,units:"cents",value:t.detune}),this._spread=t.spread,this._type=t.type,this._phase=t.phase,this._partials=t.partials,this._partialCount=t.partialCount,this.count=t.count,ji(this,["frequency","detune"])}static getDefaults(){return Object.assign(Jo.getDefaults(),{count:3,spread:20,type:"sawtooth"})}_start(t){t=this.toSeconds(t),this._forEach(e=>e.start(t))}_stop(t){t=this.toSeconds(t),this._forEach(e=>e.stop(t))}_restart(t){this._forEach(e=>e.restart(t))}_forEach(t){for(let e=0;ee.type=t)}get spread(){return this._spread}set spread(t){if(this._spread=t,this._oscillators.length>1){const e=-t/2,s=t/(this._oscillators.length-1);this._forEach((t,n)=>t.detune.value=e+s*n)}}get count(){return this._oscillators.length}set count(t){if(Yn(t,1),this._oscillators.length!==t){this._forEach(t=>t.dispose()),this._oscillators=[];for(let e=0;ethis.onstop(this):zi});"custom"===this.type&&(s.partials=this._partials),this.frequency.connect(s.frequency),this.detune.connect(s.detune),s.detune.overridden=!1,s.connect(this.output),this._oscillators[e]=s}this.spread=this._spread,"started"===this.state&&this._forEach(t=>t.start())}}get phase(){return this._phase}set phase(t){this._phase=t,this._forEach((t,e)=>t.phase=this._phase+e/this.count*360)}get baseType(){return this._oscillators[0].baseType}set baseType(t){this._forEach(e=>e.baseType=t),this._type=this._oscillators[0].type}get partials(){return this._oscillators[0].partials}set partials(t){this._partials=t,this._partialCount=this._partials.length,t.length&&(this._type="custom",this._forEach(e=>e.partials=t))}get partialCount(){return this._oscillators[0].partialCount}set partialCount(t){this._partialCount=t,this._forEach(e=>e.partialCount=t),this._type=this._oscillators[0].type}asArray(t=1024){return di(this,void 0,void 0,(function*(){return Ho(this,t)}))}dispose(){return super.dispose(),this.frequency.dispose(),this.detune.dispose(),this._forEach(t=>t.dispose()),this}}class ar extends Uo{constructor(){super(bi(ar.getDefaults(),arguments,["frequency","modulationFrequency"])),this.name="PWMOscillator",this.sourceType="pwm",this._scale=new sr({context:this.context,value:2});const t=bi(ar.getDefaults(),arguments,["frequency","modulationFrequency"]);this._pulse=new or({context:this.context,frequency:t.modulationFrequency}),this._pulse.carrierType="sine",this.modulationFrequency=this._pulse.frequency,this._modulator=new Jo({context:this.context,detune:t.detune,frequency:t.frequency,onstop:()=>this.onstop(this),phase:t.phase}),this.frequency=this._modulator.frequency,this.detune=this._modulator.detune,this._modulator.chain(this._scale,this._pulse.width),this._pulse.connect(this.output),ji(this,["modulationFrequency","frequency","detune"])}static getDefaults(){return Object.assign(Uo.getDefaults(),{detune:0,frequency:440,modulationFrequency:.4,phase:0,type:"pwm"})}_start(t){t=this.toSeconds(t),this._modulator.start(t),this._pulse.start(t)}_stop(t){t=this.toSeconds(t),this._modulator.stop(t),this._pulse.stop(t)}_restart(t){this._modulator.restart(t),this._pulse.restart(t)}get type(){return"pwm"}get baseType(){return"pwm"}get partials(){return[]}get partialCount(){return 0}get phase(){return this._modulator.phase}set phase(t){this._modulator.phase=t}asArray(t=1024){return di(this,void 0,void 0,(function*(){return Ho(this,t)}))}dispose(){return super.dispose(),this._pulse.dispose(),this._scale.dispose(),this._modulator.dispose(),this}}const cr={am:nr,fat:rr,fm:ir,oscillator:Jo,pulse:or,pwm:ar};class hr extends Uo{constructor(){super(bi(hr.getDefaults(),arguments,["frequency","type"])),this.name="OmniOscillator";const t=bi(hr.getDefaults(),arguments,["frequency","type"]);this.frequency=new bo({context:this.context,units:"frequency",value:t.frequency}),this.detune=new bo({context:this.context,units:"cents",value:t.detune}),ji(this,["frequency","detune"]),this.set(t)}static getDefaults(){return Object.assign(Jo.getDefaults(),ir.getDefaults(),nr.getDefaults(),rr.getDefaults(),or.getDefaults(),ar.getDefaults())}_start(t){this._oscillator.start(t)}_stop(t){this._oscillator.stop(t)}_restart(t){return this._oscillator.restart(t),this}get type(){let t="";return["am","fm","fat"].some(t=>this._sourceType===t)&&(t=this._sourceType),t+this._oscillator.type}set type(t){"fm"===t.substr(0,2)?(this._createNewOscillator("fm"),this._oscillator=this._oscillator,this._oscillator.type=t.substr(2)):"am"===t.substr(0,2)?(this._createNewOscillator("am"),this._oscillator=this._oscillator,this._oscillator.type=t.substr(2)):"fat"===t.substr(0,3)?(this._createNewOscillator("fat"),this._oscillator=this._oscillator,this._oscillator.type=t.substr(3)):"pwm"===t?(this._createNewOscillator("pwm"),this._oscillator=this._oscillator):"pulse"===t?this._createNewOscillator("pulse"):(this._createNewOscillator("oscillator"),this._oscillator=this._oscillator,this._oscillator.type=t)}get partials(){return this._oscillator.partials}set partials(t){this._getOscType(this._oscillator,"pulse")||this._getOscType(this._oscillator,"pwm")||(this._oscillator.partials=t)}get partialCount(){return this._oscillator.partialCount}set partialCount(t){this._getOscType(this._oscillator,"pulse")||this._getOscType(this._oscillator,"pwm")||(this._oscillator.partialCount=t)}set(t){return Reflect.has(t,"type")&&t.type&&(this.type=t.type),super.set(t),this}_createNewOscillator(t){if(t!==this._sourceType){this._sourceType=t;const e=cr[t],s=this.now();if(this._oscillator){const t=this._oscillator;t.stop(s),this.context.setTimeout(()=>t.dispose(),this.blockTime)}this._oscillator=new e({context:this.context}),this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.connect(this.output),this._oscillator.onstop=()=>this.onstop(this),"started"===this.state&&this._oscillator.start(s)}}get phase(){return this._oscillator.phase}set phase(t){this._oscillator.phase=t}get sourceType(){return this._sourceType}set sourceType(t){let e="sine";"pwm"!==this._oscillator.type&&"pulse"!==this._oscillator.type&&(e=this._oscillator.type),"fm"===t?this.type="fm"+e:"am"===t?this.type="am"+e:"fat"===t?this.type="fat"+e:"oscillator"===t?this.type=e:"pulse"===t?this.type="pulse":"pwm"===t&&(this.type="pwm")}_getOscType(t,e){return t instanceof cr[e]}get baseType(){return this._oscillator.baseType}set baseType(t){this._getOscType(this._oscillator,"pulse")||this._getOscType(this._oscillator,"pwm")||"pulse"===t||"pwm"===t||(this._oscillator.baseType=t)}get width(){return this._getOscType(this._oscillator,"pulse")?this._oscillator.width:void 0}get count(){return this._getOscType(this._oscillator,"fat")?this._oscillator.count:void 0}set count(t){this._getOscType(this._oscillator,"fat")&&ii(t)&&(this._oscillator.count=t)}get spread(){return this._getOscType(this._oscillator,"fat")?this._oscillator.spread:void 0}set spread(t){this._getOscType(this._oscillator,"fat")&&ii(t)&&(this._oscillator.spread=t)}get modulationType(){return this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am")?this._oscillator.modulationType:void 0}set modulationType(t){(this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am"))&&ci(t)&&(this._oscillator.modulationType=t)}get modulationIndex(){return this._getOscType(this._oscillator,"fm")?this._oscillator.modulationIndex:void 0}get harmonicity(){return this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am")?this._oscillator.harmonicity:void 0}get modulationFrequency(){return this._getOscType(this._oscillator,"pwm")?this._oscillator.modulationFrequency:void 0}asArray(t=1024){return di(this,void 0,void 0,(function*(){return Ho(this,t)}))}dispose(){return super.dispose(),this.detune.dispose(),this.frequency.dispose(),this._oscillator.dispose(),this}}class ur extends bo{constructor(){super(Object.assign(bi(ur.getDefaults(),arguments,["value"]))),this.override=!1,this.name="Add",this._sum=new yo({context:this.context}),this.input=this._sum,this.output=this._sum,this.addend=this._param,mo(this._constantSource,this._sum)}static getDefaults(){return Object.assign(bo.getDefaults(),{value:0})}dispose(){return super.dispose(),this._sum.dispose(),this}}class lr extends Ko{constructor(){super(Object.assign(bi(lr.getDefaults(),arguments,["min","max"]))),this.name="Scale";const t=bi(lr.getDefaults(),arguments,["min","max"]);this._mult=this.input=new sr({context:this.context,value:t.max-t.min}),this._add=this.output=new ur({context:this.context,value:t.min}),this._min=t.min,this._max=t.max,this.input.connect(this.output)}static getDefaults(){return Object.assign(Ko.getDefaults(),{max:1,min:0})}get min(){return this._min}set min(t){this._min=t,this._setRange()}get max(){return this._max}set max(t){this._max=t,this._setRange()}_setRange(){this._add.value=this._min,this._mult.value=this._max-this._min}dispose(){return super.dispose(),this._add.dispose(),this._mult.dispose(),this}}class pr extends Ko{constructor(){super(Object.assign(bi(pr.getDefaults(),arguments))),this.name="Zero",this._gain=new yo({context:this.context}),this.output=this._gain,this.input=void 0,go(this.context.getConstant(0),this._gain)}dispose(){return super.dispose(),vo(this.context.getConstant(0),this._gain),this}}class dr extends _o{constructor(){super(bi(dr.getDefaults(),arguments,["frequency","min","max"])),this.name="LFO",this._stoppedValue=0,this._units="number",this.convert=!0,this._fromType=fo.prototype._fromType,this._toType=fo.prototype._toType,this._is=fo.prototype._is,this._clampValue=fo.prototype._clampValue;const t=bi(dr.getDefaults(),arguments,["frequency","min","max"]);this._oscillator=new Jo({context:this.context,frequency:t.frequency,type:t.type}),this.frequency=this._oscillator.frequency,this._amplitudeGain=new yo({context:this.context,gain:t.amplitude,units:"normalRange"}),this.amplitude=this._amplitudeGain.gain,this._stoppedSignal=new bo({context:this.context,units:"audioRange",value:0}),this._zeros=new pr({context:this.context}),this._a2g=new er({context:this.context}),this._scaler=this.output=new lr({context:this.context,max:t.max,min:t.min}),this.units=t.units,this.min=t.min,this.max=t.max,this._oscillator.chain(this._a2g,this._amplitudeGain,this._scaler),this._zeros.connect(this._a2g),this._stoppedSignal.connect(this._a2g),ji(this,["amplitude","frequency"]),this.phase=t.phase}static getDefaults(){return Object.assign(_o.getDefaults(),{amplitude:1,frequency:"4n",max:1,min:0,phase:0,type:"sine",units:"number"})}start(t){return t=this.toSeconds(t),this._stoppedSignal.setValueAtTime(0,t),this._oscillator.start(t),this}stop(t){return t=this.toSeconds(t),this._stoppedSignal.setValueAtTime(this._stoppedValue,t),this._oscillator.stop(t),this}sync(){return this._oscillator.sync(),this._oscillator.syncFrequency(),this}unsync(){return this._oscillator.unsync(),this._oscillator.unsyncFrequency(),this}get min(){return this._toType(this._scaler.min)}set min(t){t=this._fromType(t),this._scaler.min=t}get max(){return this._toType(this._scaler.max)}set max(t){t=this._fromType(t),this._scaler.max=t}get type(){return this._oscillator.type}set type(t){this._oscillator.type=t,this._stoppedValue=this._oscillator.getInitialValue(),this._stoppedSignal.value=this._stoppedValue}get phase(){return this._oscillator.phase}set phase(t){this._oscillator.phase=t,this._stoppedValue=this._oscillator.getInitialValue(),this._stoppedSignal.value=this._stoppedValue}get units(){return this._units}set units(t){const e=this.min,s=this.max;this._units=t,this.min=e,this.max=s}get state(){return this._oscillator.state}connect(t,e,s){return(t instanceof fo||t instanceof bo)&&(this.convert=t.convert,this.units=t.units),To(this,t,e,s),this}dispose(){return super.dispose(),this._oscillator.dispose(),this._stoppedSignal.dispose(),this._zeros.dispose(),this._scaler.dispose(),this._a2g.dispose(),this._amplitudeGain.dispose(),this.amplitude.dispose(),this}}function fr(t,e=1/0){const s=new WeakMap;return function(n,i){Reflect.defineProperty(n,i,{configurable:!0,enumerable:!0,get:function(){return s.get(this)},set:function(n){Yn(n,t,e),s.set(this,n)}})}}function _r(t,e=1/0){const s=new WeakMap;return function(n,i){Reflect.defineProperty(n,i,{configurable:!0,enumerable:!0,get:function(){return s.get(this)},set:function(n){Yn(this.toSeconds(n),t,e),s.set(this,n)}})}}class mr extends Uo{constructor(){super(bi(mr.getDefaults(),arguments,["url","onload"])),this.name="Player",this._activeSources=new Set;const t=bi(mr.getDefaults(),arguments,["url","onload"]);this._buffer=new Bi({onload:this._onload.bind(this,t.onload),onerror:t.onerror,reverse:t.reverse,url:t.url}),this.autostart=t.autostart,this._loop=t.loop,this._loopStart=t.loopStart,this._loopEnd=t.loopEnd,this._playbackRate=t.playbackRate,this.fadeIn=t.fadeIn,this.fadeOut=t.fadeOut}static getDefaults(){return Object.assign(Uo.getDefaults(),{autostart:!1,fadeIn:0,fadeOut:0,loop:!1,loopEnd:0,loopStart:0,onload:zi,onerror:zi,playbackRate:1,reverse:!1})}load(t){return di(this,void 0,void 0,(function*(){return yield this._buffer.load(t),this._onload(),this}))}_onload(t=zi){t(),this.autostart&&this.start()}_onSourceEnd(t){this.onstop(this),this._activeSources.delete(t),0!==this._activeSources.size||this._synced||"started"!==this._state.getValueAtTime(this.now())||(this._state.cancel(this.now()),this._state.setStateAtTime("stopped",this.now()))}start(t,e,s){return super.start(t,e,s),this}_start(t,e,s){e=this._loop?Ti(e,this._loopStart):Ti(e,0);let n=this.toSeconds(e);this._synced&&(n*=this._playbackRate);const i=s;s=Ti(s,Math.max(this._buffer.duration-n,0));let o=this.toSeconds(s);o/=this._playbackRate,t=this.toSeconds(t);const r=new Go({url:this._buffer,context:this.context,fadeIn:this.fadeIn,fadeOut:this.fadeOut,loop:this._loop,loopEnd:this._loopEnd,loopStart:this._loopStart,onended:this._onSourceEnd.bind(this),playbackRate:this._playbackRate}).connect(this.output);this._loop||this._synced||(this._state.cancel(t+o),this._state.setStateAtTime("stopped",t+o,{implicitEnd:!0})),this._activeSources.add(r),this._loop&&ei(i)?r.start(t,n):r.start(t,n,o-this.toSeconds(this.fadeOut))}_stop(t){const e=this.toSeconds(t);this._activeSources.forEach(t=>t.stop(e))}restart(t,e,s){return super.restart(t,e,s),this}_restart(t,e,s){this._stop(t),this._start(t,e,s)}seek(t,e){const s=this.toSeconds(e);if("started"===this._state.getValueAtTime(s)){const e=this.toSeconds(t);this._stop(s),this._start(s,e)}return this}setLoopPoints(t,e){return this.loopStart=t,this.loopEnd=e,this}get loopStart(){return this._loopStart}set loopStart(t){this._loopStart=t,this.buffer.loaded&&Yn(this.toSeconds(t),0,this.buffer.duration),this._activeSources.forEach(e=>{e.loopStart=t})}get loopEnd(){return this._loopEnd}set loopEnd(t){this._loopEnd=t,this.buffer.loaded&&Yn(this.toSeconds(t),0,this.buffer.duration),this._activeSources.forEach(e=>{e.loopEnd=t})}get buffer(){return this._buffer}set buffer(t){this._buffer.set(t)}get loop(){return this._loop}set loop(t){if(this._loop!==t&&(this._loop=t,this._activeSources.forEach(e=>{e.loop=t}),t)){const t=this._state.getNextState("stopped",this.now());t&&this._state.cancel(t.time)}}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t;const e=this.now(),s=this._state.getNextState("stopped",e);s&&s.implicitEnd&&(this._state.cancel(s.time),this._activeSources.forEach(t=>t.cancelStop())),this._activeSources.forEach(s=>{s.playbackRate.setValueAtTime(t,e)})}get reverse(){return this._buffer.reverse}set reverse(t){this._buffer.reverse=t}get loaded(){return this._buffer.loaded}dispose(){return super.dispose(),this._activeSources.forEach(t=>t.dispose()),this._activeSources.clear(),this._buffer.dispose(),this}}pi([_r(0)],mr.prototype,"fadeIn",void 0),pi([_r(0)],mr.prototype,"fadeOut",void 0);class gr extends _o{constructor(){super(bi(gr.getDefaults(),arguments,["urls","onload"],"urls")),this.name="Players",this.input=void 0,this._players=new Map;const t=bi(gr.getDefaults(),arguments,["urls","onload"],"urls");this._volume=this.output=new Po({context:this.context,volume:t.volume}),this.volume=this._volume.volume,ji(this,"volume"),this._buffers=new Mo({urls:t.urls,onload:t.onload,baseUrl:t.baseUrl,onerror:t.onerror}),this.mute=t.mute,this._fadeIn=t.fadeIn,this._fadeOut=t.fadeOut}static getDefaults(){return Object.assign(Uo.getDefaults(),{baseUrl:"",fadeIn:0,fadeOut:0,mute:!1,onload:zi,onerror:zi,urls:{},volume:0})}get mute(){return this._volume.mute}set mute(t){this._volume.mute=t}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t,this._players.forEach(e=>{e.fadeIn=t})}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t,this._players.forEach(e=>{e.fadeOut=t})}get state(){return Array.from(this._players).some(([t,e])=>"started"===e.state)?"started":"stopped"}has(t){return this._buffers.has(t)}player(t){if(Xn(this.has(t),`No Player with the name ${t} exists on this object`),!this._players.has(t)){const e=new mr({context:this.context,fadeIn:this._fadeIn,fadeOut:this._fadeOut,url:this._buffers.get(t)}).connect(this.output);this._players.set(t,e)}return this._players.get(t)}get loaded(){return this._buffers.loaded}add(t,e,s){return Xn(!this._buffers.has(t),"A buffer with that name already exists on this object"),this._buffers.add(t,e,s),this}stopAll(t){return this._players.forEach(e=>e.stop(t)),this}dispose(){return super.dispose(),this._volume.dispose(),this.volume.dispose(),this._players.forEach(t=>t.dispose()),this._buffers.dispose(),this}}class vr extends Uo{constructor(){super(bi(vr.getDefaults(),arguments,["url","onload"])),this.name="GrainPlayer",this._loopStart=0,this._loopEnd=0,this._activeSources=[];const t=bi(vr.getDefaults(),arguments,["url","onload"]);this.buffer=new Bi({onload:t.onload,onerror:t.onerror,reverse:t.reverse,url:t.url}),this._clock=new Ao({context:this.context,callback:this._tick.bind(this),frequency:1/t.grainSize}),this._playbackRate=t.playbackRate,this._grainSize=t.grainSize,this._overlap=t.overlap,this.detune=t.detune,this.overlap=t.overlap,this.loop=t.loop,this.playbackRate=t.playbackRate,this.grainSize=t.grainSize,this.loopStart=t.loopStart,this.loopEnd=t.loopEnd,this.reverse=t.reverse,this._clock.on("stop",this._onstop.bind(this))}static getDefaults(){return Object.assign(Uo.getDefaults(),{onload:zi,onerror:zi,overlap:.1,grainSize:.2,playbackRate:1,detune:0,loop:!1,loopStart:0,loopEnd:0,reverse:!1})}_start(t,e,s){e=Ti(e,0),e=this.toSeconds(e),t=this.toSeconds(t);const n=1/this._clock.frequency.getValueAtTime(t);this._clock.start(t,e/n),s&&this.stop(t+this.toSeconds(s))}restart(t,e,s){return super.restart(t,e,s),this}_restart(t,e,s){this._stop(t),this._start(t,e,s)}_stop(t){this._clock.stop(t)}_onstop(t){this._activeSources.forEach(e=>{e.fadeOut=0,e.stop(t)}),this.onstop(this)}_tick(t){const e=this._clock.getTicksAtTime(t),s=e*this._grainSize;if(this.log("offset",s),!this.loop&&s>this.buffer.duration)return void this.stop(t);const n=s{const t=this._activeSources.indexOf(i);-1!==t&&this._activeSources.splice(t,1)}}get playbackRate(){return this._playbackRate}set playbackRate(t){Yn(t,.001),this._playbackRate=t,this.grainSize=this._grainSize}get loopStart(){return this._loopStart}set loopStart(t){this.buffer.loaded&&Yn(this.toSeconds(t),0,this.buffer.duration),this._loopStart=this.toSeconds(t)}get loopEnd(){return this._loopEnd}set loopEnd(t){this.buffer.loaded&&Yn(this.toSeconds(t),0,this.buffer.duration),this._loopEnd=this.toSeconds(t)}get reverse(){return this.buffer.reverse}set reverse(t){this.buffer.reverse=t}get grainSize(){return this._grainSize}set grainSize(t){this._grainSize=this.toSeconds(t),this._clock.frequency.setValueAtTime(this._playbackRate/this._grainSize,this.now())}get overlap(){return this._overlap}set overlap(t){const e=this.toSeconds(t);Yn(e,0),this._overlap=e}get loaded(){return this.buffer.loaded}dispose(){return super.dispose(),this.buffer.dispose(),this._clock.dispose(),this._activeSources.forEach(t=>t.dispose()),this}}class yr extends Ko{constructor(){super(...arguments),this.name="Abs",this._abs=new tr({context:this.context,mapping:t=>Math.abs(t)<.001?0:Math.abs(t)}),this.input=this._abs,this.output=this._abs}dispose(){return super.dispose(),this._abs.dispose(),this}}class xr extends Ko{constructor(){super(...arguments),this.name="GainToAudio",this._norm=new tr({context:this.context,mapping:t=>2*Math.abs(t)-1}),this.input=this._norm,this.output=this._norm}dispose(){return super.dispose(),this._norm.dispose(),this}}class wr extends Ko{constructor(){super(...arguments),this.name="Negate",this._multiply=new sr({context:this.context,value:-1}),this.input=this._multiply,this.output=this._multiply}dispose(){return super.dispose(),this._multiply.dispose(),this}}class br extends bo{constructor(){super(Object.assign(bi(br.getDefaults(),arguments,["value"]))),this.override=!1,this.name="Subtract",this._sum=new yo({context:this.context}),this.input=this._sum,this.output=this._sum,this._neg=new wr({context:this.context}),this.subtrahend=this._param,mo(this._constantSource,this._neg,this._sum)}static getDefaults(){return Object.assign(bo.getDefaults(),{value:0})}dispose(){return super.dispose(),this._neg.dispose(),this._sum.dispose(),this}}class Tr extends Ko{constructor(){super(Object.assign(bi(Tr.getDefaults(),arguments))),this.name="GreaterThanZero",this._thresh=this.output=new tr({context:this.context,length:127,mapping:t=>t<=0?0:1}),this._scale=this.input=new sr({context:this.context,value:1e4}),this._scale.connect(this._thresh)}dispose(){return super.dispose(),this._scale.dispose(),this._thresh.dispose(),this}}class Sr extends bo{constructor(){super(Object.assign(bi(Sr.getDefaults(),arguments,["value"]))),this.name="GreaterThan",this.override=!1;const t=bi(Sr.getDefaults(),arguments,["value"]);this._subtract=this.input=new br({context:this.context,value:t.value}),this._gtz=this.output=new Tr({context:this.context}),this.comparator=this._param=this._subtract.subtrahend,ji(this,"comparator"),this._subtract.connect(this._gtz)}static getDefaults(){return Object.assign(bo.getDefaults(),{value:0})}dispose(){return super.dispose(),this._gtz.dispose(),this._subtract.dispose(),this.comparator.dispose(),this}}class kr extends Ko{constructor(){super(Object.assign(bi(kr.getDefaults(),arguments,["value"]))),this.name="Pow";const t=bi(kr.getDefaults(),arguments,["value"]);this._exponentScaler=this.input=this.output=new tr({context:this.context,mapping:this._expFunc(t.value),length:8192}),this._exponent=t.value}static getDefaults(){return Object.assign(Ko.getDefaults(),{value:1})}_expFunc(t){return e=>Math.pow(Math.abs(e),t)}get value(){return this._exponent}set value(t){this._exponent=t,this._exponentScaler.setMap(this._expFunc(this._exponent))}dispose(){return super.dispose(),this._exponentScaler.dispose(),this}}class Cr extends lr{constructor(){super(Object.assign(bi(Cr.getDefaults(),arguments,["min","max","exponent"]))),this.name="ScaleExp";const t=bi(Cr.getDefaults(),arguments,["min","max","exponent"]);this.input=this._exp=new kr({context:this.context,value:t.exponent}),this._exp.connect(this._mult)}static getDefaults(){return Object.assign(lr.getDefaults(),{exponent:1})}get exponent(){return this._exp.value}set exponent(t){this._exp.value=t}dispose(){return super.dispose(),this._exp.dispose(),this}}class Ar extends bo{constructor(){super(bi(bo.getDefaults(),arguments,["value","units"])),this.name="SyncedSignal",this.override=!1;const t=bi(bo.getDefaults(),arguments,["value","units"]);this._lastVal=t.value,this._synced=this.context.transport.scheduleRepeat(this._onTick.bind(this),"1i"),this._syncedCallback=this._anchorValue.bind(this),this.context.transport.on("start",this._syncedCallback),this.context.transport.on("pause",this._syncedCallback),this.context.transport.on("stop",this._syncedCallback),this._constantSource.disconnect(),this._constantSource.stop(0),this._constantSource=this.output=new wo({context:this.context,offset:t.value,units:t.units}).start(0),this.setValueAtTime(t.value,0)}_onTick(t){const e=super.getValueAtTime(this.context.transport.seconds);this._lastVal!==e&&(this._lastVal=e,this._constantSource.offset.setValueAtTime(e,t))}_anchorValue(t){const e=super.getValueAtTime(this.context.transport.seconds);this._lastVal=e,this._constantSource.offset.cancelAndHoldAtTime(t),this._constantSource.offset.setValueAtTime(e,t)}getValueAtTime(t){const e=new ho(this.context,t).toSeconds();return super.getValueAtTime(e)}setValueAtTime(t,e){const s=new ho(this.context,e).toSeconds();return super.setValueAtTime(t,s),this}linearRampToValueAtTime(t,e){const s=new ho(this.context,e).toSeconds();return super.linearRampToValueAtTime(t,s),this}exponentialRampToValueAtTime(t,e){const s=new ho(this.context,e).toSeconds();return super.exponentialRampToValueAtTime(t,s),this}setTargetAtTime(t,e,s){const n=new ho(this.context,e).toSeconds();return super.setTargetAtTime(t,n,s),this}cancelScheduledValues(t){const e=new ho(this.context,t).toSeconds();return super.cancelScheduledValues(e),this}setValueCurveAtTime(t,e,s,n){const i=new ho(this.context,e).toSeconds();return s=this.toSeconds(s),super.setValueCurveAtTime(t,i,s,n),this}cancelAndHoldAtTime(t){const e=new ho(this.context,t).toSeconds();return super.cancelAndHoldAtTime(e),this}setRampPoint(t){const e=new ho(this.context,t).toSeconds();return super.setRampPoint(e),this}exponentialRampTo(t,e,s){const n=new ho(this.context,s).toSeconds();return super.exponentialRampTo(t,e,n),this}linearRampTo(t,e,s){const n=new ho(this.context,s).toSeconds();return super.linearRampTo(t,e,n),this}targetRampTo(t,e,s){const n=new ho(this.context,s).toSeconds();return super.targetRampTo(t,e,n),this}dispose(){return super.dispose(),this.context.transport.clear(this._synced),this.context.transport.off("start",this._syncedCallback),this.context.transport.off("pause",this._syncedCallback),this.context.transport.off("stop",this._syncedCallback),this._constantSource.dispose(),this}}class Dr extends _o{constructor(){super(bi(Dr.getDefaults(),arguments,["attack","decay","sustain","release"])),this.name="Envelope",this._sig=new bo({context:this.context,value:0}),this.output=this._sig,this.input=void 0;const t=bi(Dr.getDefaults(),arguments,["attack","decay","sustain","release"]);this.attack=t.attack,this.decay=t.decay,this.sustain=t.sustain,this.release=t.release,this.attackCurve=t.attackCurve,this.releaseCurve=t.releaseCurve,this.decayCurve=t.decayCurve}static getDefaults(){return Object.assign(_o.getDefaults(),{attack:.01,attackCurve:"linear",decay:.1,decayCurve:"exponential",release:1,releaseCurve:"exponential",sustain:.5})}get value(){return this.getValueAtTime(this.now())}_getCurve(t,e){if(ci(t))return t;{let s;for(s in Or)if(Or[s][e]===t)return s;return t}}_setCurve(t,e,s){if(ci(s)&&Reflect.has(Or,s)){const n=Or[s];oi(n)?"_decayCurve"!==t&&(this[t]=n[e]):this[t]=n}else{if(!ai(s)||"_decayCurve"===t)throw new Error("Envelope: invalid curve: "+s);this[t]=s}}get attackCurve(){return this._getCurve(this._attackCurve,"In")}set attackCurve(t){this._setCurve("_attackCurve","In",t)}get releaseCurve(){return this._getCurve(this._releaseCurve,"Out")}set releaseCurve(t){this._setCurve("_releaseCurve","Out",t)}get decayCurve(){return this._decayCurve}set decayCurve(t){Xn(["linear","exponential"].some(e=>e===t),"Invalid envelope curve: "+t),this._decayCurve=t}triggerAttack(t,e=1){this.log("triggerAttack",t,e),t=this.toSeconds(t);let s=this.toSeconds(this.attack);const n=this.toSeconds(this.decay),i=this.getValueAtTime(t);if(i>0){s=(1-i)/(1/s)}if(s0){const s=this.toSeconds(this.release);s{let t,e;const s=[];for(t=0;t<128;t++)s[t]=Math.sin(t/127*(Math.PI/2));const n=[];for(t=0;t<127;t++){e=t/127;const s=Math.sin(e*(2*Math.PI)*6.4-Math.PI/2)+1;n[t]=s/10+.83*e}n[127]=1;const i=[];for(t=0;t<128;t++)i[t]=Math.ceil(t/127*5)/5;const o=[];for(t=0;t<128;t++)e=t/127,o[t]=.5*(1-Math.cos(Math.PI*e));const r=[];for(t=0;t<128;t++){e=t/127;const s=4*Math.pow(e,3)+.2,n=Math.cos(s*Math.PI*2*e);r[t]=Math.abs(n*(1-e))}function a(t){const e=new Array(t.length);for(let s=0;s{const n=t[e],i=this.context.transport.schedule(n=>{t[e]=n,s.apply(this,t)},n);this._scheduledEvents.push(i)}}unsync(){return this._scheduledEvents.forEach(t=>this.context.transport.clear(t)),this._scheduledEvents=[],this._synced&&(this._synced=!1,this.triggerAttack=this._original_triggerAttack,this.triggerRelease=this._original_triggerRelease),this}triggerAttackRelease(t,e,s,n){const i=this.toSeconds(s),o=this.toSeconds(e);return this.triggerAttack(t,i,n),this.triggerRelease(i+o),this}dispose(){return super.dispose(),this._volume.dispose(),this.unsync(),this._scheduledEvents=[],this}}class Er extends Mr{constructor(){super(bi(Er.getDefaults(),arguments));const t=bi(Er.getDefaults(),arguments);this.portamento=t.portamento,this.onsilence=t.onsilence}static getDefaults(){return Object.assign(Mr.getDefaults(),{detune:0,onsilence:zi,portamento:0})}triggerAttack(t,e,s=1){this.log("triggerAttack",t,e,s);const n=this.toSeconds(e);return this._triggerEnvelopeAttack(n,s),this.setNote(t,n),this}triggerRelease(t){this.log("triggerRelease",t);const e=this.toSeconds(t);return this._triggerEnvelopeRelease(e),this}setNote(t,e){const s=this.toSeconds(e),n=t instanceof oo?t.toFrequency():t;if(this.portamento>0&&this.getLevelAtTime(s)>.05){const t=this.toSeconds(this.portamento);this.frequency.exponentialRampTo(n,t,s)}else this.frequency.setValueAtTime(n,s);return this}}pi([_r(0)],Er.prototype,"portamento",void 0);class Rr extends Dr{constructor(){super(bi(Rr.getDefaults(),arguments,["attack","decay","sustain","release"])),this.name="AmplitudeEnvelope",this._gainNode=new yo({context:this.context,gain:0}),this.output=this._gainNode,this.input=this._gainNode,this._sig.connect(this._gainNode.gain),this.output=this._gainNode,this.input=this._gainNode}dispose(){return super.dispose(),this._gainNode.dispose(),this}}class qr extends Er{constructor(){super(bi(qr.getDefaults(),arguments)),this.name="Synth";const t=bi(qr.getDefaults(),arguments);this.oscillator=new hr(Object.assign({context:this.context,detune:t.detune,onstop:()=>this.onsilence(this)},t.oscillator)),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.envelope=new Rr(Object.assign({context:this.context},t.envelope)),this.oscillator.chain(this.envelope,this.output),ji(this,["oscillator","frequency","detune","envelope"])}static getDefaults(){return Object.assign(Er.getDefaults(),{envelope:Object.assign(Si(Dr.getDefaults(),Object.keys(_o.getDefaults())),{attack:.005,decay:.1,release:1,sustain:.3}),oscillator:Object.assign(Si(hr.getDefaults(),[...Object.keys(Uo.getDefaults()),"frequency","detune"]),{type:"triangle"})})}_triggerEnvelopeAttack(t,e){if(this.envelope.triggerAttack(t,e),this.oscillator.start(t),0===this.envelope.sustain){const e=this.toSeconds(this.envelope.attack),s=this.toSeconds(this.envelope.decay);this.oscillator.stop(t+e+s)}}_triggerEnvelopeRelease(t){this.envelope.triggerRelease(t),this.oscillator.stop(t+this.toSeconds(this.envelope.release))}getLevelAtTime(t){return t=this.toSeconds(t),this.envelope.getValueAtTime(t)}dispose(){return super.dispose(),this.oscillator.dispose(),this.envelope.dispose(),this}}class Fr extends Er{constructor(){super(bi(Fr.getDefaults(),arguments)),this.name="ModulationSynth";const t=bi(Fr.getDefaults(),arguments);this._carrier=new qr({context:this.context,oscillator:t.oscillator,envelope:t.envelope,onsilence:()=>this.onsilence(this),volume:-10}),this._modulator=new qr({context:this.context,oscillator:t.modulation,envelope:t.modulationEnvelope,volume:-10}),this.oscillator=this._carrier.oscillator,this.envelope=this._carrier.envelope,this.modulation=this._modulator.oscillator,this.modulationEnvelope=this._modulator.envelope,this.frequency=new bo({context:this.context,units:"frequency"}),this.detune=new bo({context:this.context,value:t.detune,units:"cents"}),this.harmonicity=new sr({context:this.context,value:t.harmonicity,minValue:0}),this._modulationNode=new yo({context:this.context,gain:0}),ji(this,["frequency","harmonicity","oscillator","envelope","modulation","modulationEnvelope","detune"])}static getDefaults(){return Object.assign(Er.getDefaults(),{harmonicity:3,oscillator:Object.assign(Si(hr.getDefaults(),[...Object.keys(Uo.getDefaults()),"frequency","detune"]),{type:"sine"}),envelope:Object.assign(Si(Dr.getDefaults(),Object.keys(_o.getDefaults())),{attack:.01,decay:.01,sustain:1,release:.5}),modulation:Object.assign(Si(hr.getDefaults(),[...Object.keys(Uo.getDefaults()),"frequency","detune"]),{type:"square"}),modulationEnvelope:Object.assign(Si(Dr.getDefaults(),Object.keys(_o.getDefaults())),{attack:.5,decay:0,sustain:1,release:.5})})}_triggerEnvelopeAttack(t,e){this._carrier._triggerEnvelopeAttack(t,e),this._modulator._triggerEnvelopeAttack(t,e)}_triggerEnvelopeRelease(t){return this._carrier._triggerEnvelopeRelease(t),this._modulator._triggerEnvelopeRelease(t),this}getLevelAtTime(t){return t=this.toSeconds(t),this.envelope.getValueAtTime(t)}dispose(){return super.dispose(),this._carrier.dispose(),this._modulator.dispose(),this.frequency.dispose(),this.detune.dispose(),this.harmonicity.dispose(),this._modulationNode.dispose(),this}}class Ir extends Fr{constructor(){super(bi(Ir.getDefaults(),arguments)),this.name="AMSynth",this._modulationScale=new er({context:this.context}),this.frequency.connect(this._carrier.frequency),this.frequency.chain(this.harmonicity,this._modulator.frequency),this.detune.fan(this._carrier.detune,this._modulator.detune),this._modulator.chain(this._modulationScale,this._modulationNode.gain),this._carrier.chain(this._modulationNode,this.output)}dispose(){return super.dispose(),this._modulationScale.dispose(),this}}class Vr extends _o{constructor(){super(bi(Vr.getDefaults(),arguments,["frequency","type"])),this.name="BiquadFilter";const t=bi(Vr.getDefaults(),arguments,["frequency","type"]);this._filter=this.context.createBiquadFilter(),this.input=this.output=this._filter,this.Q=new fo({context:this.context,units:"number",value:t.Q,param:this._filter.Q}),this.frequency=new fo({context:this.context,units:"frequency",value:t.frequency,param:this._filter.frequency}),this.detune=new fo({context:this.context,units:"cents",value:t.detune,param:this._filter.detune}),this.gain=new fo({context:this.context,units:"gain",value:t.gain,param:this._filter.gain}),this.type=t.type}static getDefaults(){return Object.assign(_o.getDefaults(),{Q:1,type:"lowpass",frequency:350,detune:0,gain:0})}get type(){return this._filter.type}set type(t){Xn(-1!==["lowpass","highpass","bandpass","lowshelf","highshelf","notch","allpass","peaking"].indexOf(t),"Invalid filter type: "+t),this._filter.type=t}getFrequencyResponse(t=128){const e=new Float32Array(t);for(let s=0;se.type=t)}get rolloff(){return this._rolloff}set rolloff(t){const e=ii(t)?t:parseInt(t,10),s=[-12,-24,-48,-96];let n=s.indexOf(e);Xn(-1!==n,"rolloff can only be "+s.join(", ")),n+=1,this._rolloff=e,this.input.disconnect(),this._filters.forEach(t=>t.disconnect()),this._filters=new Array(n);for(let t=0;t1);return this._filters.forEach(()=>{e.getFrequencyResponse(t).forEach((t,e)=>s[e]*=t)}),e.dispose(),s}dispose(){return super.dispose(),this._filters.forEach(t=>{t.dispose()}),Li(this,["detune","frequency","gain","Q"]),this.frequency.dispose(),this.Q.dispose(),this.detune.dispose(),this.gain.dispose(),this}}class Pr extends Dr{constructor(){super(bi(Pr.getDefaults(),arguments,["attack","decay","sustain","release"])),this.name="FrequencyEnvelope";const t=bi(Pr.getDefaults(),arguments,["attack","decay","sustain","release"]);this._octaves=t.octaves,this._baseFrequency=this.toFrequency(t.baseFrequency),this._exponent=this.input=new kr({context:this.context,value:t.exponent}),this._scale=this.output=new lr({context:this.context,min:this._baseFrequency,max:this._baseFrequency*Math.pow(2,this._octaves)}),this._sig.chain(this._exponent,this._scale)}static getDefaults(){return Object.assign(Dr.getDefaults(),{baseFrequency:200,exponent:1,octaves:4})}get baseFrequency(){return this._baseFrequency}set baseFrequency(t){const e=this.toFrequency(t);Yn(e,0),this._baseFrequency=e,this._scale.min=this._baseFrequency,this.octaves=this._octaves}get octaves(){return this._octaves}set octaves(t){Yn(t,0),this._octaves=t,this._scale.max=this._baseFrequency*Math.pow(2,t)}get exponent(){return this._exponent.value}set exponent(t){this._exponent.value=t}dispose(){return super.dispose(),this._exponent.dispose(),this._scale.dispose(),this}}class jr extends Er{constructor(){super(bi(jr.getDefaults(),arguments)),this.name="MonoSynth";const t=bi(jr.getDefaults(),arguments);this.oscillator=new hr(Object.assign(t.oscillator,{context:this.context,detune:t.detune,onstop:()=>this.onsilence(this)})),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.filter=new Nr(Object.assign(t.filter,{context:this.context})),this.filterEnvelope=new Pr(Object.assign(t.filterEnvelope,{context:this.context})),this.envelope=new Rr(Object.assign(t.envelope,{context:this.context})),this.oscillator.chain(this.filter,this.envelope,this.output),this.filterEnvelope.connect(this.filter.frequency),ji(this,["oscillator","frequency","detune","filter","filterEnvelope","envelope"])}static getDefaults(){return Object.assign(Er.getDefaults(),{envelope:Object.assign(Si(Dr.getDefaults(),Object.keys(_o.getDefaults())),{attack:.005,decay:.1,release:1,sustain:.9}),filter:Object.assign(Si(Nr.getDefaults(),Object.keys(_o.getDefaults())),{Q:1,rolloff:-12,type:"lowpass"}),filterEnvelope:Object.assign(Si(Pr.getDefaults(),Object.keys(_o.getDefaults())),{attack:.6,baseFrequency:200,decay:.2,exponent:2,octaves:3,release:2,sustain:.5}),oscillator:Object.assign(Si(hr.getDefaults(),Object.keys(Uo.getDefaults())),{type:"sawtooth"})})}_triggerEnvelopeAttack(t,e=1){if(this.envelope.triggerAttack(t,e),this.filterEnvelope.triggerAttack(t),this.oscillator.start(t),0===this.envelope.sustain){const e=this.toSeconds(this.envelope.attack),s=this.toSeconds(this.envelope.decay);this.oscillator.stop(t+e+s)}}_triggerEnvelopeRelease(t){this.envelope.triggerRelease(t),this.filterEnvelope.triggerRelease(t),this.oscillator.stop(t+this.toSeconds(this.envelope.release))}getLevelAtTime(t){return t=this.toSeconds(t),this.envelope.getValueAtTime(t)}dispose(){return super.dispose(),this.oscillator.dispose(),this.envelope.dispose(),this.filterEnvelope.dispose(),this.filter.dispose(),this}}class Lr extends Er{constructor(){super(bi(Lr.getDefaults(),arguments)),this.name="DuoSynth";const t=bi(Lr.getDefaults(),arguments);this.voice0=new jr(Object.assign(t.voice0,{context:this.context,onsilence:()=>this.onsilence(this)})),this.voice1=new jr(Object.assign(t.voice1,{context:this.context})),this.harmonicity=new sr({context:this.context,units:"positive",value:t.harmonicity}),this._vibrato=new dr({frequency:t.vibratoRate,context:this.context,min:-50,max:50}),this._vibrato.start(),this.vibratoRate=this._vibrato.frequency,this._vibratoGain=new yo({context:this.context,units:"normalRange",gain:t.vibratoAmount}),this.vibratoAmount=this._vibratoGain.gain,this.frequency=new bo({context:this.context,units:"frequency",value:440}),this.detune=new bo({context:this.context,units:"cents",value:t.detune}),this.frequency.connect(this.voice0.frequency),this.frequency.chain(this.harmonicity,this.voice1.frequency),this._vibrato.connect(this._vibratoGain),this._vibratoGain.fan(this.voice0.detune,this.voice1.detune),this.detune.fan(this.voice0.detune,this.voice1.detune),this.voice0.connect(this.output),this.voice1.connect(this.output),ji(this,["voice0","voice1","frequency","vibratoAmount","vibratoRate"])}getLevelAtTime(t){return t=this.toSeconds(t),this.voice0.envelope.getValueAtTime(t)+this.voice1.envelope.getValueAtTime(t)}static getDefaults(){return wi(Er.getDefaults(),{vibratoAmount:.5,vibratoRate:5,harmonicity:1.5,voice0:wi(Si(jr.getDefaults(),Object.keys(Er.getDefaults())),{filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5},envelope:{attack:.01,decay:0,sustain:1,release:.5}}),voice1:wi(Si(jr.getDefaults(),Object.keys(Er.getDefaults())),{filterEnvelope:{attack:.01,decay:0,sustain:1,release:.5},envelope:{attack:.01,decay:0,sustain:1,release:.5}})})}_triggerEnvelopeAttack(t,e){this.voice0._triggerEnvelopeAttack(t,e),this.voice1._triggerEnvelopeAttack(t,e)}_triggerEnvelopeRelease(t){return this.voice0._triggerEnvelopeRelease(t),this.voice1._triggerEnvelopeRelease(t),this}dispose(){return super.dispose(),this.voice0.dispose(),this.voice1.dispose(),this.frequency.dispose(),this.detune.dispose(),this._vibrato.dispose(),this.vibratoRate.dispose(),this._vibratoGain.dispose(),this.harmonicity.dispose(),this}}class zr extends Fr{constructor(){super(bi(zr.getDefaults(),arguments)),this.name="FMSynth";const t=bi(zr.getDefaults(),arguments);this.modulationIndex=new sr({context:this.context,value:t.modulationIndex}),this.frequency.connect(this._carrier.frequency),this.frequency.chain(this.harmonicity,this._modulator.frequency),this.frequency.chain(this.modulationIndex,this._modulationNode),this.detune.fan(this._carrier.detune,this._modulator.detune),this._modulator.connect(this._modulationNode.gain),this._modulationNode.connect(this._carrier.frequency),this._carrier.connect(this.output)}static getDefaults(){return Object.assign(Fr.getDefaults(),{modulationIndex:10})}dispose(){return super.dispose(),this.modulationIndex.dispose(),this}}const Br=[1,1.483,1.932,2.546,2.63,3.897];class Wr extends Er{constructor(){super(bi(Wr.getDefaults(),arguments)),this.name="MetalSynth",this._oscillators=[],this._freqMultipliers=[];const t=bi(Wr.getDefaults(),arguments);this.detune=new bo({context:this.context,units:"cents",value:t.detune}),this.frequency=new bo({context:this.context,units:"frequency"}),this._amplitude=new yo({context:this.context,gain:0}).connect(this.output),this._highpass=new Nr({Q:0,context:this.context,type:"highpass"}).connect(this._amplitude);for(let e=0;ethis.onsilence(this):zi,type:"square"});s.connect(this._highpass),this._oscillators[e]=s;const n=new sr({context:this.context,value:Br[e]});this._freqMultipliers[e]=n,this.frequency.chain(n,s.frequency),this.detune.connect(s.detune)}this._filterFreqScaler=new lr({context:this.context,max:7e3,min:this.toFrequency(t.resonance)}),this.envelope=new Dr({attack:t.envelope.attack,attackCurve:"linear",context:this.context,decay:t.envelope.decay,release:t.envelope.release,sustain:0}),this.envelope.chain(this._filterFreqScaler,this._highpass.frequency),this.envelope.connect(this._amplitude.gain),this._octaves=t.octaves,this.octaves=t.octaves}static getDefaults(){return wi(Er.getDefaults(),{envelope:Object.assign(Si(Dr.getDefaults(),Object.keys(_o.getDefaults())),{attack:.001,decay:1.4,release:.2}),harmonicity:5.1,modulationIndex:32,octaves:1.5,resonance:4e3})}_triggerEnvelopeAttack(t,e=1){return this.envelope.triggerAttack(t,e),this._oscillators.forEach(e=>e.start(t)),0===this.envelope.sustain&&this._oscillators.forEach(e=>{e.stop(t+this.toSeconds(this.envelope.attack)+this.toSeconds(this.envelope.decay))}),this}_triggerEnvelopeRelease(t){return this.envelope.triggerRelease(t),this._oscillators.forEach(e=>e.stop(t+this.toSeconds(this.envelope.release))),this}getLevelAtTime(t){return t=this.toSeconds(t),this.envelope.getValueAtTime(t)}get modulationIndex(){return this._oscillators[0].modulationIndex.value}set modulationIndex(t){this._oscillators.forEach(e=>e.modulationIndex.value=t)}get harmonicity(){return this._oscillators[0].harmonicity.value}set harmonicity(t){this._oscillators.forEach(e=>e.harmonicity.value=t)}get resonance(){return this._filterFreqScaler.min}set resonance(t){this._filterFreqScaler.min=this.toFrequency(t),this.octaves=this._octaves}get octaves(){return this._octaves}set octaves(t){this._octaves=t,this._filterFreqScaler.max=this._filterFreqScaler.min*Math.pow(2,t)}dispose(){return super.dispose(),this._oscillators.forEach(t=>t.dispose()),this._freqMultipliers.forEach(t=>t.dispose()),this.frequency.dispose(),this.detune.dispose(),this._filterFreqScaler.dispose(),this._amplitude.dispose(),this.envelope.dispose(),this._highpass.dispose(),this}}class Ur extends qr{constructor(){super(bi(Ur.getDefaults(),arguments)),this.name="MembraneSynth",this.portamento=0;const t=bi(Ur.getDefaults(),arguments);this.pitchDecay=t.pitchDecay,this.octaves=t.octaves,ji(this,["oscillator","envelope"])}static getDefaults(){return wi(Er.getDefaults(),qr.getDefaults(),{envelope:{attack:.001,attackCurve:"exponential",decay:.4,release:1.4,sustain:.01},octaves:10,oscillator:{type:"sine"},pitchDecay:.05})}setNote(t,e){const s=this.toSeconds(e),n=this.toFrequency(t instanceof oo?t.toFrequency():t),i=n*this.octaves;return this.oscillator.frequency.setValueAtTime(i,s),this.oscillator.frequency.exponentialRampToValueAtTime(n,s+this.toSeconds(this.pitchDecay)),this}dispose(){return super.dispose(),this}}pi([fr(0)],Ur.prototype,"octaves",void 0),pi([_r(0)],Ur.prototype,"pitchDecay",void 0);class Gr extends Mr{constructor(){super(bi(Gr.getDefaults(),arguments)),this.name="NoiseSynth";const t=bi(Gr.getDefaults(),arguments);this.noise=new Qo(Object.assign({context:this.context},t.noise)),this.envelope=new Rr(Object.assign({context:this.context},t.envelope)),this.noise.chain(this.envelope,this.output)}static getDefaults(){return Object.assign(Mr.getDefaults(),{envelope:Object.assign(Si(Dr.getDefaults(),Object.keys(_o.getDefaults())),{decay:.1,sustain:0}),noise:Object.assign(Si(Qo.getDefaults(),Object.keys(Uo.getDefaults())),{type:"white"})})}triggerAttack(t,e=1){return t=this.toSeconds(t),this.envelope.triggerAttack(t,e),this.noise.start(t),0===this.envelope.sustain&&this.noise.stop(t+this.toSeconds(this.envelope.attack)+this.toSeconds(this.envelope.decay)),this}triggerRelease(t){return t=this.toSeconds(t),this.envelope.triggerRelease(t),this.noise.stop(t+this.toSeconds(this.envelope.release)),this}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",0),this._syncMethod("triggerRelease",0)),this}triggerAttackRelease(t,e,s=1){return e=this.toSeconds(e),t=this.toSeconds(t),this.triggerAttack(e,s),this.triggerRelease(e+t),this}dispose(){return super.dispose(),this.noise.dispose(),this.envelope.dispose(),this}}const Qr=new Set;function Zr(t){Qr.add(t)}function Xr(t,e){const s=`registerProcessor("${t}", ${e})`;Qr.add(s)}class Yr extends _o{constructor(t){super(t),this.name="ToneAudioWorklet",this.workletOptions={},this.onprocessorerror=zi;const e=URL.createObjectURL(new Blob([Array.from(Qr).join("\n")],{type:"text/javascript"})),s=this._audioWorkletName();this._dummyGain=this.context.createGain(),this._dummyParam=this._dummyGain.gain,this.context.addAudioWorkletModule(e,s).then(()=>{this.disposed||(this._worklet=this.context.createAudioWorkletNode(s,this.workletOptions),this._worklet.onprocessorerror=this.onprocessorerror.bind(this),this.onReady(this._worklet))})}dispose(){return super.dispose(),this._dummyGain.disconnect(),this._worklet&&(this._worklet.port.postMessage("dispose"),this._worklet.disconnect()),this}}Zr('\n\t/**\n\t * The base AudioWorkletProcessor for use in Tone.js. Works with the [[ToneAudioWorklet]]. \n\t */\n\tclass ToneAudioWorkletProcessor extends AudioWorkletProcessor {\n\n\t\tconstructor(options) {\n\t\t\t\n\t\t\tsuper(options);\n\t\t\t/**\n\t\t\t * If the processor was disposed or not. Keep alive until it\'s disposed.\n\t\t\t */\n\t\t\tthis.disposed = false;\n\t\t \t/** \n\t\t\t * The number of samples in the processing block\n\t\t\t */\n\t\t\tthis.blockSize = 128;\n\t\t\t/**\n\t\t\t * the sample rate\n\t\t\t */\n\t\t\tthis.sampleRate = sampleRate;\n\n\t\t\tthis.port.onmessage = (event) => {\n\t\t\t\t// when it receives a dispose \n\t\t\t\tif (event.data === "dispose") {\n\t\t\t\t\tthis.disposed = true;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t}\n');Zr("\n\t/**\n\t * Abstract class for a single input/output processor. \n\t * has a 'generate' function which processes one sample at a time\n\t */\n\tclass SingleIOProcessor extends ToneAudioWorkletProcessor {\n\n\t\tconstructor(options) {\n\t\t\tsuper(Object.assign(options, {\n\t\t\t\tnumberOfInputs: 1,\n\t\t\t\tnumberOfOutputs: 1\n\t\t\t}));\n\t\t\t/**\n\t\t\t * Holds the name of the parameter and a single value of that\n\t\t\t * parameter at the current sample\n\t\t\t * @type { [name: string]: number }\n\t\t\t */\n\t\t\tthis.params = {}\n\t\t}\n\n\t\t/**\n\t\t * Generate an output sample from the input sample and parameters\n\t\t * @abstract\n\t\t * @param input number\n\t\t * @param channel number\n\t\t * @param parameters { [name: string]: number }\n\t\t * @returns number\n\t\t */\n\t\tgenerate(){}\n\n\t\t/**\n\t\t * Update the private params object with the \n\t\t * values of the parameters at the given index\n\t\t * @param parameters { [name: string]: Float32Array },\n\t\t * @param index number\n\t\t */\n\t\tupdateParams(parameters, index) {\n\t\t\tfor (const paramName in parameters) {\n\t\t\t\tconst param = parameters[paramName];\n\t\t\t\tif (param.length > 1) {\n\t\t\t\t\tthis.params[paramName] = parameters[paramName][index];\n\t\t\t\t} else {\n\t\t\t\t\tthis.params[paramName] = parameters[paramName][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Process a single frame of the audio\n\t\t * @param inputs Float32Array[][]\n\t\t * @param outputs Float32Array[][]\n\t\t */\n\t\tprocess(inputs, outputs, parameters) {\n\t\t\tconst input = inputs[0];\n\t\t\tconst output = outputs[0];\n\t\t\t// get the parameter values\n\t\t\tconst channelCount = Math.max(input && input.length || 0, output.length);\n\t\t\tfor (let sample = 0; sample < this.blockSize; sample++) {\n\t\t\t\tthis.updateParams(parameters, sample);\n\t\t\t\tfor (let channel = 0; channel < channelCount; channel++) {\n\t\t\t\t\tconst inputSample = input && input.length ? input[channel][sample] : 0;\n\t\t\t\t\toutput[channel][sample] = this.generate(inputSample, channel, this.params);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn !this.disposed;\n\t\t}\n\t};\n");Zr("\n\t/**\n\t * A multichannel buffer for use within an AudioWorkletProcessor as a delay line\n\t */\n\tclass DelayLine {\n\t\t\n\t\tconstructor(size, channels) {\n\t\t\tthis.buffer = [];\n\t\t\tthis.writeHead = []\n\t\t\tthis.size = size;\n\n\t\t\t// create the empty channels\n\t\t\tfor (let i = 0; i < channels; i++) {\n\t\t\t\tthis.buffer[i] = new Float32Array(this.size);\n\t\t\t\tthis.writeHead[i] = 0;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Push a value onto the end\n\t\t * @param channel number\n\t\t * @param value number\n\t\t */\n\t\tpush(channel, value) {\n\t\t\tthis.writeHead[channel] += 1;\n\t\t\tif (this.writeHead[channel] > this.size) {\n\t\t\t\tthis.writeHead[channel] = 0;\n\t\t\t}\n\t\t\tthis.buffer[channel][this.writeHead[channel]] = value;\n\t\t}\n\n\t\t/**\n\t\t * Get the recorded value of the channel given the delay\n\t\t * @param channel number\n\t\t * @param delay number delay samples\n\t\t */\n\t\tget(channel, delay) {\n\t\t\tlet readHead = this.writeHead[channel] - Math.floor(delay);\n\t\t\tif (readHead < 0) {\n\t\t\t\treadHead += this.size;\n\t\t\t}\n\t\t\treturn this.buffer[channel][readHead];\n\t\t}\n\t}\n");Xr("feedback-comb-filter",'\n\tclass FeedbackCombFilterWorklet extends SingleIOProcessor {\n\n\t\tconstructor(options) {\n\t\t\tsuper(options);\n\t\t\tthis.delayLine = new DelayLine(this.sampleRate, options.channelCount || 2);\n\t\t}\n\n\t\tstatic get parameterDescriptors() {\n\t\t\treturn [{\n\t\t\t\tname: "delayTime",\n\t\t\t\tdefaultValue: 0.1,\n\t\t\t\tminValue: 0,\n\t\t\t\tmaxValue: 1,\n\t\t\t\tautomationRate: "k-rate"\n\t\t\t}, {\n\t\t\t\tname: "feedback",\n\t\t\t\tdefaultValue: 0.5,\n\t\t\t\tminValue: 0,\n\t\t\t\tmaxValue: 0.9999,\n\t\t\t\tautomationRate: "k-rate"\n\t\t\t}];\n\t\t}\n\n\t\tgenerate(input, channel, parameters) {\n\t\t\tconst delayedSample = this.delayLine.get(channel, parameters.delayTime * this.sampleRate);\n\t\t\tthis.delayLine.push(channel, input + delayedSample * parameters.feedback);\n\t\t\treturn delayedSample;\n\t\t}\n\t}\n');class Hr extends Yr{constructor(){super(bi(Hr.getDefaults(),arguments,["delayTime","resonance"])),this.name="FeedbackCombFilter";const t=bi(Hr.getDefaults(),arguments,["delayTime","resonance"]);this.input=new yo({context:this.context}),this.output=new yo({context:this.context}),this.delayTime=new fo({context:this.context,value:t.delayTime,units:"time",minValue:0,maxValue:1,param:this._dummyParam,swappable:!0}),this.resonance=new fo({context:this.context,value:t.resonance,units:"normalRange",param:this._dummyParam,swappable:!0}),ji(this,["resonance","delayTime"])}_audioWorkletName(){return"feedback-comb-filter"}static getDefaults(){return Object.assign(_o.getDefaults(),{delayTime:.1,resonance:.5})}onReady(t){mo(this.input,t,this.output);const e=t.parameters.get("delayTime");this.delayTime.setParam(e);const s=t.parameters.get("feedback");this.resonance.setParam(s)}dispose(){return super.dispose(),this.input.dispose(),this.output.dispose(),this.delayTime.dispose(),this.resonance.dispose(),this}}class $r extends _o{constructor(){super(bi($r.getDefaults(),arguments,["frequency","type"])),this.name="OnePoleFilter";const t=bi($r.getDefaults(),arguments,["frequency","type"]);this._frequency=t.frequency,this._type=t.type,this.input=new yo({context:this.context}),this.output=new yo({context:this.context}),this._createFilter()}static getDefaults(){return Object.assign(_o.getDefaults(),{frequency:880,type:"lowpass"})}_createFilter(){const t=this._filter,e=this.toFrequency(this._frequency),s=1/(2*Math.PI*e);if("lowpass"===this._type){const t=1/(s*this.context.sampleRate),e=t-1;this._filter=this.context.createIIRFilter([t,0],[1,e])}else{const t=1/(s*this.context.sampleRate)-1;this._filter=this.context.createIIRFilter([1,-1],[1,t])}this.input.chain(this._filter,this.output),t&&this.context.setTimeout(()=>{this.disposed||(this.input.disconnect(t),t.disconnect())},this.blockTime)}get frequency(){return this._frequency}set frequency(t){this._frequency=t,this._createFilter()}get type(){return this._type}set type(t){this._type=t,this._createFilter()}getFrequencyResponse(t=128){const e=new Float32Array(t);for(let s=0;se.voice===t);this._activeVoices.splice(e,1)}_getNextAvailableVoice(){if(this._availableVoices.length)return this._availableVoices.shift();if(this._voices.lengthMath.ceil(this._averageActiveVoices+1)){const t=this._availableVoices.shift(),e=this._voices.indexOf(t);this._voices.splice(e,1),this.context.isOffline||t.dispose()}}_triggerAttack(t,e,s){t.forEach(t=>{const n=new Eo(this.context,t).toMidi(),i=this._getNextAvailableVoice();i&&(i.triggerAttack(t,e,s),this._activeVoices.push({midi:n,voice:i,released:!1}),this.log("triggerAttack",t,e))})}_triggerRelease(t,e){t.forEach(t=>{const s=new Eo(this.context,t).toMidi(),n=this._activeVoices.find(({midi:t,released:e})=>t===s&&!e);n&&(n.voice.triggerRelease(e),n.released=!0,this.log("triggerRelease",t,e))})}_scheduleEvent(t,e,s,n){Xn(!this.disposed,"Synth was already disposed"),s<=this.now()?"attack"===t?this._triggerAttack(e,s,n):this._triggerRelease(e,s):this.context.setTimeout(()=>{this._scheduleEvent(t,e,s,n)},s-this.now())}triggerAttack(t,e,s){Array.isArray(t)||(t=[t]);const n=this.toSeconds(e);return this._scheduleEvent("attack",t,n,s),this}triggerRelease(t,e){Array.isArray(t)||(t=[t]);const s=this.toSeconds(e);return this._scheduleEvent("release",t,s),this}triggerAttackRelease(t,e,s,n){const i=this.toSeconds(s);if(this.triggerAttack(t,i,n),ai(e)){Xn(ai(t),"If the duration is an array, the notes must also be an array"),t=t;for(let s=0;s0,"The duration must be greater than 0"),this.triggerRelease(t[s],i+o)}}else{const s=this.toSeconds(e);Xn(s>0,"The duration must be greater than 0"),this.triggerRelease(t,i+s)}return this}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",1),this._syncMethod("triggerRelease",1)),this}set(t){const e=Si(t,["onsilence","context"]);return this.options=wi(this.options,e),this._voices.forEach(t=>t.set(e)),this._dummyVoice.set(e),this}get(){return this._dummyVoice.get()}releaseAll(t){const e=this.toSeconds(t);return this._activeVoices.forEach(({voice:t})=>{t.triggerRelease(e)}),this}dispose(){return super.dispose(),this._dummyVoice.dispose(),this._voices.forEach(t=>t.dispose()),this._activeVoices=[],this._availableVoices=[],this.context.clearInterval(this._gcTimeout),this}}class ea extends Mr{constructor(){super(bi(ea.getDefaults(),arguments,["urls","onload","baseUrl"],"urls")),this.name="Sampler",this._activeSources=new Map;const t=bi(ea.getDefaults(),arguments,["urls","onload","baseUrl"],"urls"),e={};Object.keys(t.urls).forEach(s=>{const n=parseInt(s,10);if(Xn(hi(s)||ii(n)&&isFinite(n),"url key is neither a note or midi pitch: "+s),hi(s)){const n=new oo(this.context,s).toMidi();e[n]=t.urls[s]}else ii(n)&&isFinite(n)&&(e[n]=t.urls[n])}),this._buffers=new Mo({urls:e,onload:t.onload,baseUrl:t.baseUrl,onerror:t.onerror}),this.attack=t.attack,this.release=t.release,this.curve=t.curve,this._buffers.loaded&&Promise.resolve().then(t.onload)}static getDefaults(){return Object.assign(Mr.getDefaults(),{attack:0,baseUrl:"",curve:"exponential",onload:zi,onerror:zi,release:.1,urls:{}})}_findClosest(t){let e=0;for(;e<96;){if(this._buffers.has(t+e))return-e;if(this._buffers.has(t-e))return e;e++}throw new Error("No available buffers for note: "+t)}triggerAttack(t,e,s=1){return this.log("triggerAttack",t,e,s),Array.isArray(t)||(t=[t]),t.forEach(t=>{const n=to(new oo(this.context,t).toFrequency()),i=Math.round(n),o=n-i,r=this._findClosest(i),a=i-r,c=this._buffers.get(a),h=$i(r+o),u=new Go({url:c,context:this.context,curve:this.curve,fadeIn:this.attack,fadeOut:this.release,playbackRate:h}).connect(this.output);u.start(e,0,c.duration/h,s),ai(this._activeSources.get(i))||this._activeSources.set(i,[]),this._activeSources.get(i).push(u),u.onended=()=>{if(this._activeSources&&this._activeSources.has(i)){const t=this._activeSources.get(i),e=t.indexOf(u);-1!==e&&t.splice(e,1)}}}),this}triggerRelease(t,e){return this.log("triggerRelease",t,e),Array.isArray(t)||(t=[t]),t.forEach(t=>{const s=new oo(this.context,t).toMidi();if(this._activeSources.has(s)&&this._activeSources.get(s).length){const t=this._activeSources.get(s);e=this.toSeconds(e),t.forEach(t=>{t.stop(e)}),this._activeSources.set(s,[])}}),this}releaseAll(t){const e=this.toSeconds(t);return this._activeSources.forEach(t=>{for(;t.length;){t.shift().stop(e)}}),this}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",1),this._syncMethod("triggerRelease",1)),this}triggerAttackRelease(t,e,s,n=1){const i=this.toSeconds(s);return this.triggerAttack(t,i,n),ai(e)?(Xn(ai(t),"notes must be an array when duration is array"),t.forEach((t,s)=>{const n=e[Math.min(s,e.length-1)];this.triggerRelease(t,i+this.toSeconds(n))})):this.triggerRelease(t,i+this.toSeconds(e)),this}add(t,e,s){if(Xn(hi(t)||isFinite(t),"note must be a pitch or midi: "+t),hi(t)){const n=new oo(this.context,t).toMidi();this._buffers.add(n,e,s)}else this._buffers.add(t,e,s);return this}get loaded(){return this._buffers.loaded}dispose(){return super.dispose(),this._buffers.dispose(),this._activeSources.forEach(t=>{t.forEach(t=>t.dispose())}),this._activeSources.clear(),this}}pi([_r(0)],ea.prototype,"attack",void 0),pi([_r(0)],ea.prototype,"release",void 0);class sa extends lo{constructor(){super(bi(sa.getDefaults(),arguments,["callback","value"])),this.name="ToneEvent",this._state=new po("stopped"),this._startOffset=0;const t=bi(sa.getDefaults(),arguments,["callback","value"]);this._loop=t.loop,this.callback=t.callback,this.value=t.value,this._loopStart=this.toTicks(t.loopStart),this._loopEnd=this.toTicks(t.loopEnd),this._playbackRate=t.playbackRate,this._probability=t.probability,this._humanize=t.humanize,this.mute=t.mute,this._playbackRate=t.playbackRate,this._state.increasing=!0,this._rescheduleEvents()}static getDefaults(){return Object.assign(lo.getDefaults(),{callback:zi,humanize:!1,loop:!1,loopEnd:"1m",loopStart:0,mute:!1,playbackRate:1,probability:1,value:null})}_rescheduleEvents(t=-1){this._state.forEachFrom(t,t=>{let e;if("started"===t.state){-1!==t.id&&this.context.transport.clear(t.id);const s=t.time+Math.round(this.startOffset/this._playbackRate);if(!0===this._loop||ii(this._loop)&&this._loop>1){e=1/0,ii(this._loop)&&(e=this._loop*this._getLoopDuration());const n=this._state.getAfter(s);null!==n&&(e=Math.min(e,n.time-s)),e!==1/0&&(this._state.setStateAtTime("stopped",s+e+1,{id:-1}),e=new qo(this.context,e));const i=new qo(this.context,this._getLoopDuration());t.id=this.context.transport.scheduleRepeat(this._tick.bind(this),i,new qo(this.context,s),e)}else t.id=this.context.transport.schedule(this._tick.bind(this),new qo(this.context,s))}})}get state(){return this._state.getValueAtTime(this.context.transport.ticks)}get startOffset(){return this._startOffset}set startOffset(t){this._startOffset=t}get probability(){return this._probability}set probability(t){this._probability=t}get humanize(){return this._humanize}set humanize(t){this._humanize=t}start(t){const e=this.toTicks(t);return"stopped"===this._state.getValueAtTime(e)&&(this._state.add({id:-1,state:"started",time:e}),this._rescheduleEvents(e)),this}stop(t){this.cancel(t);const e=this.toTicks(t);if("started"===this._state.getValueAtTime(e)){this._state.setStateAtTime("stopped",e,{id:-1});const t=this._state.getBefore(e);let s=e;null!==t&&(s=t.time),this._rescheduleEvents(s)}return this}cancel(t){t=Ti(t,-1/0);const e=this.toTicks(t);return this._state.forEachFrom(e,t=>{this.context.transport.clear(t.id)}),this._state.cancel(e),this}_tick(t){const e=this.context.transport.getTicksAtTime(t);if(!this.mute&&"started"===this._state.getValueAtTime(e)){if(this.probability<1&&Math.random()>this.probability)return;if(this.humanize){let e=.02;ri(this.humanize)||(e=this.toSeconds(this.humanize)),t+=(2*Math.random()-1)*e}this.callback(t,this.value)}}_getLoopDuration(){return Math.round((this._loopEnd-this._loopStart)/this._playbackRate)}get loop(){return this._loop}set loop(t){this._loop=t,this._rescheduleEvents()}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this._rescheduleEvents()}get loopEnd(){return new qo(this.context,this._loopEnd).toSeconds()}set loopEnd(t){this._loopEnd=this.toTicks(t),this._loop&&this._rescheduleEvents()}get loopStart(){return new qo(this.context,this._loopStart).toSeconds()}set loopStart(t){this._loopStart=this.toTicks(t),this._loop&&this._rescheduleEvents()}get progress(){if(this._loop){const t=this.context.transport.ticks,e=this._state.get(t);if(null!==e&&"started"===e.state){const s=this._getLoopDuration();return(t-e.time)%s/s}return 0}return 0}dispose(){return super.dispose(),this.cancel(),this._state.dispose(),this}}class na extends lo{constructor(){super(bi(na.getDefaults(),arguments,["callback","interval"])),this.name="Loop";const t=bi(na.getDefaults(),arguments,["callback","interval"]);this._event=new sa({context:this.context,callback:this._tick.bind(this),loop:!0,loopEnd:t.interval,playbackRate:t.playbackRate,probability:t.probability}),this.callback=t.callback,this.iterations=t.iterations}static getDefaults(){return Object.assign(lo.getDefaults(),{interval:"4n",callback:zi,playbackRate:1,iterations:1/0,probability:1,mute:!1,humanize:!1})}start(t){return this._event.start(t),this}stop(t){return this._event.stop(t),this}cancel(t){return this._event.cancel(t),this}_tick(t){this.callback(t)}get state(){return this._event.state}get progress(){return this._event.progress}get interval(){return this._event.loopEnd}set interval(t){this._event.loopEnd=t}get playbackRate(){return this._event.playbackRate}set playbackRate(t){this._event.playbackRate=t}get humanize(){return this._event.humanize}set humanize(t){this._event.humanize=t}get probability(){return this._event.probability}set probability(t){this._event.probability=t}get mute(){return this._event.mute}set mute(t){this._event.mute=t}get iterations(){return!0===this._event.loop?1/0:this._event.loop}set iterations(t){this._event.loop=t===1/0||t}dispose(){return super.dispose(),this._event.dispose(),this}}class ia extends sa{constructor(){super(bi(ia.getDefaults(),arguments,["callback","events"])),this.name="Part",this._state=new po("stopped"),this._events=new Set;const t=bi(ia.getDefaults(),arguments,["callback","events"]);this._state.increasing=!0,t.events.forEach(t=>{ai(t)?this.add(t[0],t[1]):this.add(t)})}static getDefaults(){return Object.assign(sa.getDefaults(),{events:[]})}start(t,e){const s=this.toTicks(t);if("started"!==this._state.getValueAtTime(s)){e=Ti(e,this._loop?this._loopStart:0),e=this._loop?Ti(e,this._loopStart):Ti(e,0);const t=this.toTicks(e);this._state.add({id:-1,offset:t,state:"started",time:s}),this._forEach(e=>{this._startNote(e,s,t)})}return this}_startNote(t,e,s){e-=s,this._loop?t.startOffset>=this._loopStart&&t.startOffset=s&&(t.loop=!1,t.start(new qo(this.context,e))):t.startOffset>=s&&t.start(new qo(this.context,e))}get startOffset(){return this._startOffset}set startOffset(t){this._startOffset=t,this._forEach(t=>{t.startOffset+=this._startOffset})}stop(t){const e=this.toTicks(t);return this._state.cancel(e),this._state.setStateAtTime("stopped",e),this._forEach(e=>{e.stop(t)}),this}at(t,e){const s=new ho(this.context,t).toTicks(),n=new qo(this.context,1).toSeconds(),i=this._events.values();let o=i.next();for(;!o.done;){const t=o.value;if(Math.abs(s-t.startOffset){"started"===e.state?this._startNote(t,e.time,e.offset):t.stop(new qo(this.context,e.time))})}remove(t,e){return oi(t)&&t.hasOwnProperty("time")&&(t=(e=t).time),t=this.toTicks(t),this._events.forEach(s=>{s.startOffset===t&&(ei(e)||si(e)&&s.value===e)&&(this._events.delete(s),s.dispose())}),this}clear(){return this._forEach(t=>t.dispose()),this._events.clear(),this}cancel(t){return this._forEach(e=>e.cancel(t)),this._state.cancel(this.toTicks(t)),this}_forEach(t){return this._events&&this._events.forEach(e=>{e instanceof ia?e._forEach(t):t(e)}),this}_setAll(t,e){this._forEach(s=>{s[t]=e})}_tick(t,e){this.mute||this.callback(t,e)}_testLoopBoundries(t){this._loop&&(t.startOffset=this._loopEnd)?t.cancel(0):"stopped"===t.state&&this._restartEvent(t)}get probability(){return this._probability}set probability(t){this._probability=t,this._setAll("probability",t)}get humanize(){return this._humanize}set humanize(t){this._humanize=t,this._setAll("humanize",t)}get loop(){return this._loop}set loop(t){this._loop=t,this._forEach(e=>{e.loopStart=this.loopStart,e.loopEnd=this.loopEnd,e.loop=t,this._testLoopBoundries(e)})}get loopEnd(){return new qo(this.context,this._loopEnd).toSeconds()}set loopEnd(t){this._loopEnd=this.toTicks(t),this._loop&&this._forEach(e=>{e.loopEnd=t,this._testLoopBoundries(e)})}get loopStart(){return new qo(this.context,this._loopStart).toSeconds()}set loopStart(t){this._loopStart=this.toTicks(t),this._loop&&this._forEach(t=>{t.loopStart=this.loopStart,this._testLoopBoundries(t)})}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this._setAll("playbackRate",t)}get length(){return this._events.size}dispose(){return super.dispose(),this.clear(),this}}function*oa(t){let e=0;for(;e=0;)e=ca(e,t),yield t[e],e--}function*aa(t,e){for(;;)yield*e(t)}function ca(t,e){return Mi(t,0,e.length-1)}function*ha(t,e){let s=e?0:t.length-1;for(;;)s=ca(s,t),yield t[s],e?(s++,s>=t.length-1&&(e=!1)):(s--,s<=0&&(e=!0))}function*ua(t){let e=0,s=0;for(;e=0;)e=ca(e,t),yield t[e],s++,e+=s%2?-2:1}function*pa(t){const e=[];for(let s=0;s0;){const s=ca(e.splice(Math.floor(e.length*Math.random()),1)[0],t);yield t[s]}}function*da(t,e="up",s=0){switch(Xn(t.length>0,"The array must have more than one value in it"),e){case"up":yield*aa(t,oa);case"down":yield*aa(t,ra);case"upDown":yield*ha(t,!0);case"downUp":yield*ha(t,!1);case"alternateUp":yield*aa(t,ua);case"alternateDown":yield*aa(t,la);case"random":yield*function*(t){for(;;){const e=Math.floor(Math.random()*t.length);yield t[e]}}(t);case"randomOnce":yield*aa(t,pa);case"randomWalk":yield*function*(t){let e=Math.floor(Math.random()*t.length);for(;;)0===e?e++:e===t.length-1||Math.random()<.5?e--:e++,yield t[e]}(t)}}class fa extends na{constructor(){super(bi(fa.getDefaults(),arguments,["callback","values","pattern"])),this.name="Pattern";const t=bi(fa.getDefaults(),arguments,["callback","values","pattern"]);this.callback=t.callback,this._values=t.values,this._pattern=da(t.values,t.pattern),this._type=t.pattern}static getDefaults(){return Object.assign(na.getDefaults(),{pattern:"up",values:[],callback:zi})}_tick(t){const e=this._pattern.next();this._value=e.value,this.callback(t,this._value)}get values(){return this._values}set values(t){this._values=t,this.pattern=this._type}get value(){return this._value}get pattern(){return this._type}set pattern(t){this._type=t,this._pattern=da(this._values,this._type)}}class _a extends sa{constructor(){super(bi(_a.getDefaults(),arguments,["callback","events","subdivision"])),this.name="Sequence",this._part=new ia({callback:this._seqCallback.bind(this),context:this.context}),this._events=[],this._eventsArray=[];const t=bi(_a.getDefaults(),arguments,["callback","events","subdivision"]);this._subdivision=this.toTicks(t.subdivision),this.events=t.events,this.loop=t.loop,this.loopStart=t.loopStart,this.loopEnd=t.loopEnd,this.playbackRate=t.playbackRate,this.probability=t.probability,this.humanize=t.humanize,this.mute=t.mute,this.playbackRate=t.playbackRate}static getDefaults(){return Object.assign(Si(sa.getDefaults(),["value"]),{events:[],loop:!0,loopEnd:0,loopStart:0,subdivision:"8n"})}_seqCallback(t,e){null!==e&&this.callback(t,e)}get events(){return this._events}set events(t){this.clear(),this._eventsArray=t,this._events=this._createSequence(this._eventsArray),this._eventsUpdated()}start(t,e){return this._part.start(t,e?this._indexTime(e):e),this}stop(t){return this._part.stop(t),this}get subdivision(){return new qo(this.context,this._subdivision).toSeconds()}_createSequence(t){return new Proxy(t,{get:(t,e)=>t[e],set:(t,e,s)=>(ci(e)&&isFinite(parseInt(e,10))&&ai(s)?t[e]=this._createSequence(s):t[e]=s,this._eventsUpdated(),!0)})}_eventsUpdated(){this._part.clear(),this._rescheduleSequence(this._eventsArray,this._subdivision,this.startOffset),this.loopEnd=this.loopEnd}_rescheduleSequence(t,e,s){t.forEach((t,n)=>{const i=n*e+s;if(ai(t))this._rescheduleSequence(t,e/t.length,i);else{const e=new qo(this.context,i,"i").toSeconds();this._part.add(e,t)}})}_indexTime(t){return new qo(this.context,t*this._subdivision+this.startOffset).toSeconds()}clear(){return this._part.clear(),this}dispose(){return super.dispose(),this._part.dispose(),this}get loop(){return this._part.loop}set loop(t){this._part.loop=t}get loopStart(){return this._loopStart}set loopStart(t){this._loopStart=t,this._part.loopStart=this._indexTime(t)}get loopEnd(){return this._loopEnd}set loopEnd(t){this._loopEnd=t,this._part.loopEnd=0===t?this._indexTime(this._eventsArray.length):this._indexTime(t)}get startOffset(){return this._part.startOffset}set startOffset(t){this._part.startOffset=t}get playbackRate(){return this._part.playbackRate}set playbackRate(t){this._part.playbackRate=t}get probability(){return this._part.probability}set probability(t){this._part.probability=t}get progress(){return this._part.progress}get humanize(){return this._part.humanize}set humanize(t){this._part.humanize=t}get length(){return this._part.length}}class ma extends _o{constructor(){super(Object.assign(bi(ma.getDefaults(),arguments,["fade"]))),this.name="CrossFade",this._panner=this.context.createStereoPanner(),this._split=this.context.createChannelSplitter(2),this._g2a=new xr({context:this.context}),this.a=new yo({context:this.context,gain:0}),this.b=new yo({context:this.context,gain:0}),this.output=new yo({context:this.context}),this._internalChannels=[this.a,this.b];const t=bi(ma.getDefaults(),arguments,["fade"]);this.fade=new bo({context:this.context,units:"normalRange",value:t.fade}),ji(this,"fade"),this.context.getConstant(1).connect(this._panner),this._panner.connect(this._split),this._panner.channelCount=1,this._panner.channelCountMode="explicit",go(this._split,this.a.gain,0),go(this._split,this.b.gain,1),this.fade.chain(this._g2a,this._panner.pan),this.a.connect(this.output),this.b.connect(this.output)}static getDefaults(){return Object.assign(_o.getDefaults(),{fade:.5})}dispose(){return super.dispose(),this.a.dispose(),this.b.dispose(),this.output.dispose(),this.fade.dispose(),this._g2a.dispose(),this._panner.disconnect(),this._split.disconnect(),this}}class ga extends _o{constructor(t){super(t),this.name="Effect",this._dryWet=new ma({context:this.context}),this.wet=this._dryWet.fade,this.effectSend=new yo({context:this.context}),this.effectReturn=new yo({context:this.context}),this.input=new yo({context:this.context}),this.output=this._dryWet,this.input.fan(this._dryWet.a,this.effectSend),this.effectReturn.connect(this._dryWet.b),this.wet.setValueAtTime(t.wet,0),this._internalChannels=[this.effectReturn,this.effectSend],ji(this,"wet")}static getDefaults(){return Object.assign(_o.getDefaults(),{wet:1})}connectEffect(t){return this._internalChannels.push(t),this.effectSend.chain(t,this.effectReturn),this}dispose(){return super.dispose(),this._dryWet.dispose(),this.effectSend.dispose(),this.effectReturn.dispose(),this.wet.dispose(),this}}class va extends ga{constructor(t){super(t),this.name="LFOEffect",this._lfo=new dr({context:this.context,frequency:t.frequency,amplitude:t.depth}),this.depth=this._lfo.amplitude,this.frequency=this._lfo.frequency,this.type=t.type,ji(this,["frequency","depth"])}static getDefaults(){return Object.assign(ga.getDefaults(),{frequency:1,type:"sine",depth:1})}start(t){return this._lfo.start(t),this}stop(t){return this._lfo.stop(t),this}sync(){return this._lfo.sync(),this}unsync(){return this._lfo.unsync(),this}get type(){return this._lfo.type}set type(t){this._lfo.type=t}dispose(){return super.dispose(),this._lfo.dispose(),this.frequency.dispose(),this.depth.dispose(),this}}class ya extends va{constructor(){super(bi(ya.getDefaults(),arguments,["frequency","baseFrequency","octaves"])),this.name="AutoFilter";const t=bi(ya.getDefaults(),arguments,["frequency","baseFrequency","octaves"]);this.filter=new Nr(Object.assign(t.filter,{context:this.context})),this.connectEffect(this.filter),this._lfo.connect(this.filter.frequency),this.octaves=t.octaves,this.baseFrequency=t.baseFrequency}static getDefaults(){return Object.assign(va.getDefaults(),{baseFrequency:200,octaves:2.6,filter:{type:"lowpass",rolloff:-12,Q:1}})}get baseFrequency(){return this._lfo.min}set baseFrequency(t){this._lfo.min=this.toFrequency(t),this.octaves=this._octaves}get octaves(){return this._octaves}set octaves(t){this._octaves=t,this._lfo.max=this._lfo.min*Math.pow(2,t)}dispose(){return super.dispose(),this.filter.dispose(),this}}class xa extends _o{constructor(){super(Object.assign(bi(xa.getDefaults(),arguments,["pan"]))),this.name="Panner",this._panner=this.context.createStereoPanner(),this.input=this._panner,this.output=this._panner;const t=bi(xa.getDefaults(),arguments,["pan"]);this.pan=new fo({context:this.context,param:this._panner.pan,value:t.pan,minValue:-1,maxValue:1}),this._panner.channelCount=t.channelCount,this._panner.channelCountMode="explicit",ji(this,"pan")}static getDefaults(){return Object.assign(_o.getDefaults(),{pan:0,channelCount:1})}dispose(){return super.dispose(),this._panner.disconnect(),this.pan.dispose(),this}}class wa extends va{constructor(){super(bi(wa.getDefaults(),arguments,["frequency"])),this.name="AutoPanner";const t=bi(wa.getDefaults(),arguments,["frequency"]);this._panner=new xa({context:this.context,channelCount:t.channelCount}),this.connectEffect(this._panner),this._lfo.connect(this._panner.pan),this._lfo.min=-1,this._lfo.max=1}static getDefaults(){return Object.assign(va.getDefaults(),{channelCount:1})}dispose(){return super.dispose(),this._panner.dispose(),this}}class ba extends _o{constructor(){super(bi(ba.getDefaults(),arguments,["smoothing"])),this.name="Follower";const t=bi(ba.getDefaults(),arguments,["smoothing"]);this._abs=this.input=new yr({context:this.context}),this._lowpass=this.output=new $r({context:this.context,frequency:1/this.toSeconds(t.smoothing),type:"lowpass"}),this._abs.connect(this._lowpass),this._smoothing=t.smoothing}static getDefaults(){return Object.assign(_o.getDefaults(),{smoothing:.05})}get smoothing(){return this._smoothing}set smoothing(t){this._smoothing=t,this._lowpass.frequency=1/this.toSeconds(this.smoothing)}dispose(){return super.dispose(),this._abs.dispose(),this._lowpass.dispose(),this}}class Ta extends ga{constructor(){super(bi(Ta.getDefaults(),arguments,["baseFrequency","octaves","sensitivity"])),this.name="AutoWah";const t=bi(Ta.getDefaults(),arguments,["baseFrequency","octaves","sensitivity"]);this._follower=new ba({context:this.context,smoothing:t.follower}),this._sweepRange=new Cr({context:this.context,min:0,max:1,exponent:.5}),this._baseFrequency=this.toFrequency(t.baseFrequency),this._octaves=t.octaves,this._inputBoost=new yo({context:this.context}),this._bandpass=new Nr({context:this.context,rolloff:-48,frequency:0,Q:t.Q}),this._peaking=new Nr({context:this.context,type:"peaking"}),this._peaking.gain.value=t.gain,this.gain=this._peaking.gain,this.Q=this._bandpass.Q,this.effectSend.chain(this._inputBoost,this._follower,this._sweepRange),this._sweepRange.connect(this._bandpass.frequency),this._sweepRange.connect(this._peaking.frequency),this.effectSend.chain(this._bandpass,this._peaking,this.effectReturn),this._setSweepRange(),this.sensitivity=t.sensitivity,ji(this,["gain","Q"])}static getDefaults(){return Object.assign(ga.getDefaults(),{baseFrequency:100,octaves:6,sensitivity:0,Q:2,gain:2,follower:.2})}get octaves(){return this._octaves}set octaves(t){this._octaves=t,this._setSweepRange()}get follower(){return this._follower.smoothing}set follower(t){this._follower.smoothing=t}get baseFrequency(){return this._baseFrequency}set baseFrequency(t){this._baseFrequency=this.toFrequency(t),this._setSweepRange()}get sensitivity(){return Hi(1/this._inputBoost.gain.value)}set sensitivity(t){this._inputBoost.gain.value=1/Yi(t)}_setSweepRange(){this._sweepRange.min=this._baseFrequency,this._sweepRange.max=Math.min(this._baseFrequency*Math.pow(2,this._octaves),this.context.sampleRate/2)}dispose(){return super.dispose(),this._follower.dispose(),this._sweepRange.dispose(),this._bandpass.dispose(),this._peaking.dispose(),this._inputBoost.dispose(),this}}Xr("bit-crusher","\n\tclass BitCrusherWorklet extends SingleIOProcessor {\n\n\t\tstatic get parameterDescriptors() {\n\t\t\treturn [{\n\t\t\t\tname: \"bits\",\n\t\t\t\tdefaultValue: 12,\n\t\t\t\tminValue: 1,\n\t\t\t\tmaxValue: 16,\n\t\t\t\tautomationRate: 'k-rate'\n\t\t\t}];\n\t\t}\n\n\t\tgenerate(input, _channel, parameters) {\n\t\t\tconst step = Math.pow(0.5, parameters.bits - 1);\n\t\t\tconst val = step * Math.floor(input / step + 0.5);\n\t\t\treturn val;\n\t\t}\n\t}\n");class Sa extends ga{constructor(){super(bi(Sa.getDefaults(),arguments,["bits"])),this.name="BitCrusher";const t=bi(Sa.getDefaults(),arguments,["bits"]);this._bitCrusherWorklet=new ka({context:this.context,bits:t.bits}),this.connectEffect(this._bitCrusherWorklet),this.bits=this._bitCrusherWorklet.bits}static getDefaults(){return Object.assign(ga.getDefaults(),{bits:4})}dispose(){return super.dispose(),this._bitCrusherWorklet.dispose(),this}}class ka extends Yr{constructor(){super(bi(ka.getDefaults(),arguments)),this.name="BitCrusherWorklet";const t=bi(ka.getDefaults(),arguments);this.input=new yo({context:this.context}),this.output=new yo({context:this.context}),this.bits=new fo({context:this.context,value:t.bits,units:"positive",minValue:1,maxValue:16,param:this._dummyParam,swappable:!0})}static getDefaults(){return Object.assign(Yr.getDefaults(),{bits:12})}_audioWorkletName(){return"bit-crusher"}onReady(t){mo(this.input,t,this.output);const e=t.parameters.get("bits");this.bits.setParam(e)}dispose(){return super.dispose(),this.input.dispose(),this.output.dispose(),this.bits.dispose(),this}}class Ca extends ga{constructor(){super(bi(Ca.getDefaults(),arguments,["order"])),this.name="Chebyshev";const t=bi(Ca.getDefaults(),arguments,["order"]);this._shaper=new tr({context:this.context,length:4096}),this._order=t.order,this.connectEffect(this._shaper),this.order=t.order,this.oversample=t.oversample}static getDefaults(){return Object.assign(ga.getDefaults(),{order:1,oversample:"none"})}_getCoefficient(t,e,s){return s.has(e)||(0===e?s.set(e,0):1===e?s.set(e,t):s.set(e,2*t*this._getCoefficient(t,e-1,s)-this._getCoefficient(t,e-2,s))),s.get(e)}get order(){return this._order}set order(t){this._order=t,this._shaper.setMap(e=>this._getCoefficient(e,t,new Map))}get oversample(){return this._shaper.oversample}set oversample(t){this._shaper.oversample=t}dispose(){return super.dispose(),this._shaper.dispose(),this}}class Aa extends _o{constructor(){super(bi(Aa.getDefaults(),arguments,["channels"])),this.name="Split";const t=bi(Aa.getDefaults(),arguments,["channels"]);this._splitter=this.input=this.output=this.context.createChannelSplitter(t.channels),this._internalChannels=[this._splitter]}static getDefaults(){return Object.assign(_o.getDefaults(),{channels:2})}dispose(){return super.dispose(),this._splitter.disconnect(),this}}class Da extends _o{constructor(){super(bi(Da.getDefaults(),arguments,["channels"])),this.name="Merge";const t=bi(Da.getDefaults(),arguments,["channels"]);this._merger=this.output=this.input=this.context.createChannelMerger(t.channels)}static getDefaults(){return Object.assign(_o.getDefaults(),{channels:2})}dispose(){return super.dispose(),this._merger.disconnect(),this}}class Oa extends _o{constructor(t){super(t),this.name="StereoEffect",this.input=new yo({context:this.context}),this.input.channelCount=2,this.input.channelCountMode="explicit",this._dryWet=this.output=new ma({context:this.context,fade:t.wet}),this.wet=this._dryWet.fade,this._split=new Aa({context:this.context,channels:2}),this._merge=new Da({context:this.context,channels:2}),this.input.connect(this._split),this.input.connect(this._dryWet.a),this._merge.connect(this._dryWet.b),ji(this,["wet"])}connectEffectLeft(...t){this._split.connect(t[0],0,0),mo(...t),go(t[t.length-1],this._merge,0,0)}connectEffectRight(...t){this._split.connect(t[0],1,0),mo(...t),go(t[t.length-1],this._merge,0,1)}static getDefaults(){return Object.assign(_o.getDefaults(),{wet:1})}dispose(){return super.dispose(),this._dryWet.dispose(),this._split.dispose(),this._merge.dispose(),this}}class Ma extends Oa{constructor(t){super(t),this.feedback=new bo({context:this.context,value:t.feedback,units:"normalRange"}),this._feedbackL=new yo({context:this.context}),this._feedbackR=new yo({context:this.context}),this._feedbackSplit=new Aa({context:this.context,channels:2}),this._feedbackMerge=new Da({context:this.context,channels:2}),this._merge.connect(this._feedbackSplit),this._feedbackMerge.connect(this._split),this._feedbackSplit.connect(this._feedbackL,0,0),this._feedbackL.connect(this._feedbackMerge,0,0),this._feedbackSplit.connect(this._feedbackR,1,0),this._feedbackR.connect(this._feedbackMerge,0,1),this.feedback.fan(this._feedbackL.gain,this._feedbackR.gain),ji(this,["feedback"])}static getDefaults(){return Object.assign(Oa.getDefaults(),{feedback:.5})}dispose(){return super.dispose(),this.feedback.dispose(),this._feedbackL.dispose(),this._feedbackR.dispose(),this._feedbackSplit.dispose(),this._feedbackMerge.dispose(),this}}class Ea extends Ma{constructor(){super(bi(Ea.getDefaults(),arguments,["frequency","delayTime","depth"])),this.name="Chorus";const t=bi(Ea.getDefaults(),arguments,["frequency","delayTime","depth"]);this._depth=t.depth,this._delayTime=t.delayTime/1e3,this._lfoL=new dr({context:this.context,frequency:t.frequency,min:0,max:1}),this._lfoR=new dr({context:this.context,frequency:t.frequency,min:0,max:1,phase:180}),this._delayNodeL=new Do({context:this.context}),this._delayNodeR=new Do({context:this.context}),this.frequency=this._lfoL.frequency,ji(this,["frequency"]),this._lfoL.frequency.connect(this._lfoR.frequency),this.connectEffectLeft(this._delayNodeL),this.connectEffectRight(this._delayNodeR),this._lfoL.connect(this._delayNodeL.delayTime),this._lfoR.connect(this._delayNodeR.delayTime),this.depth=this._depth,this.type=t.type,this.spread=t.spread}static getDefaults(){return Object.assign(Ma.getDefaults(),{frequency:1.5,delayTime:3.5,depth:.7,type:"sine",spread:180,feedback:0,wet:.5})}get depth(){return this._depth}set depth(t){this._depth=t;const e=this._delayTime*t;this._lfoL.min=Math.max(this._delayTime-e,0),this._lfoL.max=this._delayTime+e,this._lfoR.min=Math.max(this._delayTime-e,0),this._lfoR.max=this._delayTime+e}get delayTime(){return 1e3*this._delayTime}set delayTime(t){this._delayTime=t/1e3,this.depth=this._depth}get type(){return this._lfoL.type}set type(t){this._lfoL.type=t,this._lfoR.type=t}get spread(){return this._lfoR.phase-this._lfoL.phase}set spread(t){this._lfoL.phase=90-t/2,this._lfoR.phase=t/2+90}start(t){return this._lfoL.start(t),this._lfoR.start(t),this}stop(t){return this._lfoL.stop(t),this._lfoR.stop(t),this}sync(){return this._lfoL.sync(),this._lfoR.sync(),this}unsync(){return this._lfoL.unsync(),this._lfoR.unsync(),this}dispose(){return super.dispose(),this._lfoL.dispose(),this._lfoR.dispose(),this._delayNodeL.dispose(),this._delayNodeR.dispose(),this.frequency.dispose(),this}}class Ra extends ga{constructor(){super(bi(Ra.getDefaults(),arguments,["distortion"])),this.name="Distortion";const t=bi(Ra.getDefaults(),arguments,["distortion"]);this._shaper=new tr({context:this.context,length:4096}),this._distortion=t.distortion,this.connectEffect(this._shaper),this.distortion=t.distortion,this.oversample=t.oversample}static getDefaults(){return Object.assign(ga.getDefaults(),{distortion:.4,oversample:"none"})}get distortion(){return this._distortion}set distortion(t){this._distortion=t;const e=100*t,s=Math.PI/180;this._shaper.setMap(t=>Math.abs(t)<.001?0:(3+e)*t*20*s/(Math.PI+e*Math.abs(t)))}get oversample(){return this._shaper.oversample}set oversample(t){this._shaper.oversample=t}dispose(){return super.dispose(),this._shaper.dispose(),this}}class qa extends ga{constructor(t){super(t),this.name="FeedbackEffect",this._feedbackGain=new yo({context:this.context,gain:t.feedback,units:"normalRange"}),this.feedback=this._feedbackGain.gain,ji(this,"feedback"),this.effectReturn.chain(this._feedbackGain,this.effectSend)}static getDefaults(){return Object.assign(ga.getDefaults(),{feedback:.125})}dispose(){return super.dispose(),this._feedbackGain.dispose(),this.feedback.dispose(),this}}class Fa extends qa{constructor(){super(bi(Fa.getDefaults(),arguments,["delayTime","feedback"])),this.name="FeedbackDelay";const t=bi(Fa.getDefaults(),arguments,["delayTime","feedback"]);this._delayNode=new Do({context:this.context,delayTime:t.delayTime,maxDelay:t.maxDelay}),this.delayTime=this._delayNode.delayTime,this.connectEffect(this._delayNode),ji(this,"delayTime")}static getDefaults(){return Object.assign(qa.getDefaults(),{delayTime:.25,maxDelay:1})}dispose(){return super.dispose(),this._delayNode.dispose(),this.delayTime.dispose(),this}}class Ia extends _o{constructor(t){super(t),this.name="PhaseShiftAllpass",this.input=new yo({context:this.context}),this.output=new yo({context:this.context}),this.offset90=new yo({context:this.context});this._bank0=this._createAllPassFilterBank([.6923878,.9360654322959,.988229522686,.9987488452737]),this._bank1=this._createAllPassFilterBank([.4021921162426,.856171088242,.9722909545651,.9952884791278]),this._oneSampleDelay=this.context.createIIRFilter([0,1],[1,0]),mo(this.input,...this._bank0,this._oneSampleDelay,this.output),mo(this.input,...this._bank1,this.offset90)}_createAllPassFilterBank(t){return t.map(t=>{const e=[[t*t,0,-1],[1,0,-t*t]];return this.context.createIIRFilter(e[0],e[1])})}dispose(){return super.dispose(),this.input.dispose(),this.output.dispose(),this.offset90.dispose(),this._bank0.forEach(t=>t.disconnect()),this._bank1.forEach(t=>t.disconnect()),this._oneSampleDelay.disconnect(),this}}class Va extends ga{constructor(){super(bi(Va.getDefaults(),arguments,["frequency"])),this.name="FrequencyShifter";const t=bi(Va.getDefaults(),arguments,["frequency"]);this.frequency=new bo({context:this.context,units:"frequency",value:t.frequency,minValue:-this.context.sampleRate/2,maxValue:this.context.sampleRate/2}),this._sine=new $o({context:this.context,type:"sine"}),this._cosine=new Jo({context:this.context,phase:-90,type:"sine"}),this._sineMultiply=new sr({context:this.context}),this._cosineMultiply=new sr({context:this.context}),this._negate=new wr({context:this.context}),this._add=new ur({context:this.context}),this._phaseShifter=new Ia({context:this.context}),this.effectSend.connect(this._phaseShifter),this.frequency.fan(this._sine.frequency,this._cosine.frequency),this._phaseShifter.offset90.connect(this._cosineMultiply),this._cosine.connect(this._cosineMultiply.factor),this._phaseShifter.connect(this._sineMultiply),this._sine.connect(this._sineMultiply.factor),this._sineMultiply.connect(this._negate),this._cosineMultiply.connect(this._add),this._negate.connect(this._add.addend),this._add.connect(this.effectReturn);const e=this.immediate();this._sine.start(e),this._cosine.start(e)}static getDefaults(){return Object.assign(ga.getDefaults(),{frequency:0})}dispose(){return super.dispose(),this.frequency.dispose(),this._add.dispose(),this._cosine.dispose(),this._cosineMultiply.dispose(),this._negate.dispose(),this._phaseShifter.dispose(),this._sine.dispose(),this._sineMultiply.dispose(),this}}const Na=[1557/44100,1617/44100,1491/44100,1422/44100,1277/44100,1356/44100,1188/44100,1116/44100],Pa=[225,556,441,341];class ja extends Oa{constructor(){super(bi(ja.getDefaults(),arguments,["roomSize","dampening"])),this.name="Freeverb",this._combFilters=[],this._allpassFiltersL=[],this._allpassFiltersR=[];const t=bi(ja.getDefaults(),arguments,["roomSize","dampening"]);this.roomSize=new bo({context:this.context,value:t.roomSize,units:"normalRange"}),this._allpassFiltersL=Pa.map(t=>{const e=this.context.createBiquadFilter();return e.type="allpass",e.frequency.value=t,e}),this._allpassFiltersR=Pa.map(t=>{const e=this.context.createBiquadFilter();return e.type="allpass",e.frequency.value=t,e}),this._combFilters=Na.map((e,s)=>{const n=new Jr({context:this.context,dampening:t.dampening,delayTime:e});return se.dampening=t)}dispose(){return super.dispose(),this._allpassFiltersL.forEach(t=>t.disconnect()),this._allpassFiltersR.forEach(t=>t.disconnect()),this._combFilters.forEach(t=>t.dispose()),this.roomSize.dispose(),this}}const La=[.06748,.06404,.08212,.09004],za=[.773,.802,.753,.733],Ba=[347,113,37];class Wa extends Oa{constructor(){super(bi(Wa.getDefaults(),arguments,["roomSize"])),this.name="JCReverb",this._allpassFilters=[],this._feedbackCombFilters=[];const t=bi(Wa.getDefaults(),arguments,["roomSize"]);this.roomSize=new bo({context:this.context,value:t.roomSize,units:"normalRange"}),this._scaleRoomSize=new lr({context:this.context,min:-.733,max:.197}),this._allpassFilters=Ba.map(t=>{const e=this.context.createBiquadFilter();return e.type="allpass",e.frequency.value=t,e}),this._feedbackCombFilters=La.map((t,e)=>{const s=new Hr({context:this.context,delayTime:t});return this._scaleRoomSize.connect(s.resonance),s.resonance.value=za[e],et.disconnect()),this._feedbackCombFilters.forEach(t=>t.dispose()),this.roomSize.dispose(),this._scaleRoomSize.dispose(),this}}class Ua extends Ma{constructor(t){super(t),this._feedbackL.disconnect(),this._feedbackL.connect(this._feedbackMerge,0,1),this._feedbackR.disconnect(),this._feedbackR.connect(this._feedbackMerge,0,0),ji(this,["feedback"])}}class Ga extends Ua{constructor(){super(bi(Ga.getDefaults(),arguments,["delayTime","feedback"])),this.name="PingPongDelay";const t=bi(Ga.getDefaults(),arguments,["delayTime","feedback"]);this._leftDelay=new Do({context:this.context,maxDelay:t.maxDelay}),this._rightDelay=new Do({context:this.context,maxDelay:t.maxDelay}),this._rightPreDelay=new Do({context:this.context,maxDelay:t.maxDelay}),this.delayTime=new bo({context:this.context,units:"time",value:t.delayTime}),this.connectEffectLeft(this._leftDelay),this.connectEffectRight(this._rightPreDelay,this._rightDelay),this.delayTime.fan(this._leftDelay.delayTime,this._rightDelay.delayTime,this._rightPreDelay.delayTime),this._feedbackL.disconnect(),this._feedbackL.connect(this._rightDelay),ji(this,["delayTime"])}static getDefaults(){return Object.assign(Ua.getDefaults(),{delayTime:.25,maxDelay:1})}dispose(){return super.dispose(),this._leftDelay.dispose(),this._rightDelay.dispose(),this._rightPreDelay.dispose(),this.delayTime.dispose(),this}}class Qa extends qa{constructor(){super(bi(Qa.getDefaults(),arguments,["pitch"])),this.name="PitchShift";const t=bi(Qa.getDefaults(),arguments,["pitch"]);this._frequency=new bo({context:this.context}),this._delayA=new Do({maxDelay:1,context:this.context}),this._lfoA=new dr({context:this.context,min:0,max:.1,type:"sawtooth"}).connect(this._delayA.delayTime),this._delayB=new Do({maxDelay:1,context:this.context}),this._lfoB=new dr({context:this.context,min:0,max:.1,type:"sawtooth",phase:180}).connect(this._delayB.delayTime),this._crossFade=new ma({context:this.context}),this._crossFadeLFO=new dr({context:this.context,min:0,max:1,type:"triangle",phase:90}).connect(this._crossFade.fade),this._feedbackDelay=new Do({delayTime:t.delayTime,context:this.context}),this.delayTime=this._feedbackDelay.delayTime,ji(this,"delayTime"),this._pitch=t.pitch,this._windowSize=t.windowSize,this._delayA.connect(this._crossFade.a),this._delayB.connect(this._crossFade.b),this._frequency.fan(this._lfoA.frequency,this._lfoB.frequency,this._crossFadeLFO.frequency),this.effectSend.fan(this._delayA,this._delayB),this._crossFade.chain(this._feedbackDelay,this.effectReturn);const e=this.now();this._lfoA.start(e),this._lfoB.start(e),this._crossFadeLFO.start(e),this.windowSize=this._windowSize}static getDefaults(){return Object.assign(qa.getDefaults(),{pitch:0,windowSize:.1,delayTime:0,feedback:0})}get pitch(){return this._pitch}set pitch(t){this._pitch=t;let e=0;t<0?(this._lfoA.min=0,this._lfoA.max=this._windowSize,this._lfoB.min=0,this._lfoB.max=this._windowSize,e=$i(t-1)+1):(this._lfoA.min=this._windowSize,this._lfoA.max=0,this._lfoB.min=this._windowSize,this._lfoB.max=0,e=$i(t)-1),this._frequency.value=e*(1.2/this._windowSize)}get windowSize(){return this._windowSize}set windowSize(t){this._windowSize=this.toSeconds(t),this.pitch=this._pitch}dispose(){return super.dispose(),this._frequency.dispose(),this._delayA.dispose(),this._delayB.dispose(),this._lfoA.dispose(),this._lfoB.dispose(),this._crossFade.dispose(),this._crossFadeLFO.dispose(),this._feedbackDelay.dispose(),this}}class Za extends Oa{constructor(){super(bi(Za.getDefaults(),arguments,["frequency","octaves","baseFrequency"])),this.name="Phaser";const t=bi(Za.getDefaults(),arguments,["frequency","octaves","baseFrequency"]);this._lfoL=new dr({context:this.context,frequency:t.frequency,min:0,max:1}),this._lfoR=new dr({context:this.context,frequency:t.frequency,min:0,max:1,phase:180}),this._baseFrequency=this.toFrequency(t.baseFrequency),this._octaves=t.octaves,this.Q=new bo({context:this.context,value:t.Q,units:"positive"}),this._filtersL=this._makeFilters(t.stages,this._lfoL),this._filtersR=this._makeFilters(t.stages,this._lfoR),this.frequency=this._lfoL.frequency,this.frequency.value=t.frequency,this.connectEffectLeft(...this._filtersL),this.connectEffectRight(...this._filtersR),this._lfoL.frequency.connect(this._lfoR.frequency),this.baseFrequency=t.baseFrequency,this.octaves=t.octaves,this._lfoL.start(),this._lfoR.start(),ji(this,["frequency","Q"])}static getDefaults(){return Object.assign(Oa.getDefaults(),{frequency:.5,octaves:3,stages:10,Q:10,baseFrequency:350})}_makeFilters(t,e){const s=[];for(let n=0;nt.disconnect()),this._filtersR.forEach(t=>t.disconnect()),this.frequency.dispose(),this}}class Xa extends ga{constructor(){super(bi(Xa.getDefaults(),arguments,["decay"])),this.name="Reverb",this._convolver=this.context.createConvolver(),this.ready=Promise.resolve();const t=bi(Xa.getDefaults(),arguments,["decay"]);this._decay=t.decay,this._preDelay=t.preDelay,this.generate(),this.connectEffect(this._convolver)}static getDefaults(){return Object.assign(ga.getDefaults(),{decay:1.5,preDelay:.01})}get decay(){return this._decay}set decay(t){Yn(t=this.toSeconds(t),.001),this._decay=t,this.generate()}get preDelay(){return this._preDelay}set preDelay(t){Yn(t=this.toSeconds(t),0),this._preDelay=t,this.generate()}generate(){return di(this,void 0,void 0,(function*(){const t=this.ready,e=new Wi(2,this._decay+this._preDelay,this.context.sampleRate),s=new Qo({context:e}),n=new Qo({context:e}),i=new Da({context:e});s.connect(i,0,0),n.connect(i,0,1);const o=new yo({context:e}).toDestination();i.connect(o),s.start(0),n.start(0),o.gain.setValueAtTime(0,0),o.gain.setValueAtTime(1,this._preDelay),o.gain.exponentialApproachValueAtTime(0,this._preDelay,this.decay);const r=e.render();return this.ready=r.then(zi),yield t,this._convolver.buffer=(yield r).get(),this}))}dispose(){return super.dispose(),this._convolver.disconnect(),this}}class Ya extends _o{constructor(){super(bi(Ya.getDefaults(),arguments)),this.name="MidSideSplit",this._split=this.input=new Aa({channels:2,context:this.context}),this._midAdd=new ur({context:this.context}),this.mid=new sr({context:this.context,value:Math.SQRT1_2}),this._sideSubtract=new br({context:this.context}),this.side=new sr({context:this.context,value:Math.SQRT1_2}),this._split.connect(this._midAdd,0),this._split.connect(this._midAdd.addend,1),this._split.connect(this._sideSubtract,0),this._split.connect(this._sideSubtract.subtrahend,1),this._midAdd.connect(this.mid),this._sideSubtract.connect(this.side)}dispose(){return super.dispose(),this.mid.dispose(),this.side.dispose(),this._midAdd.dispose(),this._sideSubtract.dispose(),this._split.dispose(),this}}class Ha extends _o{constructor(){super(bi(Ha.getDefaults(),arguments)),this.name="MidSideMerge",this.mid=new yo({context:this.context}),this.side=new yo({context:this.context}),this._left=new ur({context:this.context}),this._leftMult=new sr({context:this.context,value:Math.SQRT1_2}),this._right=new br({context:this.context}),this._rightMult=new sr({context:this.context,value:Math.SQRT1_2}),this._merge=this.output=new Da({context:this.context}),this.mid.fan(this._left),this.side.connect(this._left.addend),this.mid.connect(this._right),this.side.connect(this._right.subtrahend),this._left.connect(this._leftMult),this._right.connect(this._rightMult),this._leftMult.connect(this._merge,0,0),this._rightMult.connect(this._merge,0,1)}dispose(){return super.dispose(),this.mid.dispose(),this.side.dispose(),this._leftMult.dispose(),this._rightMult.dispose(),this._left.dispose(),this._right.dispose(),this}}class $a extends ga{constructor(t){super(t),this.name="MidSideEffect",this._midSideMerge=new Ha({context:this.context}),this._midSideSplit=new Ya({context:this.context}),this._midSend=this._midSideSplit.mid,this._sideSend=this._midSideSplit.side,this._midReturn=this._midSideMerge.mid,this._sideReturn=this._midSideMerge.side,this.effectSend.connect(this._midSideSplit),this._midSideMerge.connect(this.effectReturn)}connectEffectMid(...t){this._midSend.chain(...t,this._midReturn)}connectEffectSide(...t){this._sideSend.chain(...t,this._sideReturn)}dispose(){return super.dispose(),this._midSideSplit.dispose(),this._midSideMerge.dispose(),this._midSend.dispose(),this._sideSend.dispose(),this._midReturn.dispose(),this._sideReturn.dispose(),this}}class Ja extends $a{constructor(){super(bi(Ja.getDefaults(),arguments,["width"])),this.name="StereoWidener";const t=bi(Ja.getDefaults(),arguments,["width"]);this.width=new bo({context:this.context,value:t.width,units:"normalRange"}),ji(this,["width"]),this._twoTimesWidthMid=new sr({context:this.context,value:2}),this._twoTimesWidthSide=new sr({context:this.context,value:2}),this._midMult=new sr({context:this.context}),this._twoTimesWidthMid.connect(this._midMult.factor),this.connectEffectMid(this._midMult),this._oneMinusWidth=new br({context:this.context}),this._oneMinusWidth.connect(this._twoTimesWidthMid),go(this.context.getConstant(1),this._oneMinusWidth),this.width.connect(this._oneMinusWidth.subtrahend),this._sideMult=new sr({context:this.context}),this.width.connect(this._twoTimesWidthSide),this._twoTimesWidthSide.connect(this._sideMult.factor),this.connectEffectSide(this._sideMult)}static getDefaults(){return Object.assign($a.getDefaults(),{width:.5})}dispose(){return super.dispose(),this.width.dispose(),this._midMult.dispose(),this._sideMult.dispose(),this._twoTimesWidthMid.dispose(),this._twoTimesWidthSide.dispose(),this._oneMinusWidth.dispose(),this}}class Ka extends Oa{constructor(){super(bi(Ka.getDefaults(),arguments,["frequency","depth"])),this.name="Tremolo";const t=bi(Ka.getDefaults(),arguments,["frequency","depth"]);this._lfoL=new dr({context:this.context,type:t.type,min:1,max:0}),this._lfoR=new dr({context:this.context,type:t.type,min:1,max:0}),this._amplitudeL=new yo({context:this.context}),this._amplitudeR=new yo({context:this.context}),this.frequency=new bo({context:this.context,value:t.frequency,units:"frequency"}),this.depth=new bo({context:this.context,value:t.depth,units:"normalRange"}),ji(this,["frequency","depth"]),this.connectEffectLeft(this._amplitudeL),this.connectEffectRight(this._amplitudeR),this._lfoL.connect(this._amplitudeL.gain),this._lfoR.connect(this._amplitudeR.gain),this.frequency.fan(this._lfoL.frequency,this._lfoR.frequency),this.depth.fan(this._lfoR.amplitude,this._lfoL.amplitude),this.spread=t.spread}static getDefaults(){return Object.assign(Oa.getDefaults(),{frequency:10,type:"sine",depth:.5,spread:180})}start(t){return this._lfoL.start(t),this._lfoR.start(t),this}stop(t){return this._lfoL.stop(t),this._lfoR.stop(t),this}sync(){return this._lfoL.sync(),this._lfoR.sync(),this.context.transport.syncSignal(this.frequency),this}unsync(){return this._lfoL.unsync(),this._lfoR.unsync(),this.context.transport.unsyncSignal(this.frequency),this}get type(){return this._lfoL.type}set type(t){this._lfoL.type=t,this._lfoR.type=t}get spread(){return this._lfoR.phase-this._lfoL.phase}set spread(t){this._lfoL.phase=90-t/2,this._lfoR.phase=t/2+90}dispose(){return super.dispose(),this._lfoL.dispose(),this._lfoR.dispose(),this._amplitudeL.dispose(),this._amplitudeR.dispose(),this.frequency.dispose(),this.depth.dispose(),this}}class tc extends ga{constructor(){super(bi(tc.getDefaults(),arguments,["frequency","depth"])),this.name="Vibrato";const t=bi(tc.getDefaults(),arguments,["frequency","depth"]);this._delayNode=new Do({context:this.context,delayTime:0,maxDelay:t.maxDelay}),this._lfo=new dr({context:this.context,type:t.type,min:0,max:t.maxDelay,frequency:t.frequency,phase:-90}).start().connect(this._delayNode.delayTime),this.frequency=this._lfo.frequency,this.depth=this._lfo.amplitude,this.depth.value=t.depth,ji(this,["frequency","depth"]),this.effectSend.chain(this._delayNode,this.effectReturn)}static getDefaults(){return Object.assign(ga.getDefaults(),{maxDelay:.005,frequency:5,depth:.1,type:"sine"})}get type(){return this._lfo.type}set type(t){this._lfo.type=t}dispose(){return super.dispose(),this._delayNode.dispose(),this._lfo.dispose(),this.frequency.dispose(),this.depth.dispose(),this}}class ec extends _o{constructor(){super(bi(ec.getDefaults(),arguments,["type","size"])),this.name="Analyser",this._analysers=[],this._buffers=[];const t=bi(ec.getDefaults(),arguments,["type","size"]);this.input=this.output=this._gain=new yo({context:this.context}),this._split=new Aa({context:this.context,channels:t.channels}),this.input.connect(this._split),Yn(t.channels,1);for(let e=0;e{const s=this._buffers[e];"fft"===this._type?t.getFloatFrequencyData(s):"waveform"===this._type&&t.getFloatTimeDomainData(s)}),1===this.channels?this._buffers[0]:this._buffers}get size(){return this._analysers[0].frequencyBinCount}set size(t){this._analysers.forEach((e,s)=>{e.fftSize=2*t,this._buffers[s]=new Float32Array(t)})}get channels(){return this._analysers.length}get type(){return this._type}set type(t){Xn("waveform"===t||"fft"===t,"Analyser: invalid type: "+t),this._type=t}get smoothing(){return this._analysers[0].smoothingTimeConstant}set smoothing(t){this._analysers.forEach(e=>e.smoothingTimeConstant=t)}dispose(){return super.dispose(),this._analysers.forEach(t=>t.disconnect()),this._split.dispose(),this._gain.dispose(),this}}class sc extends _o{constructor(){super(bi(sc.getDefaults(),arguments)),this.name="MeterBase",this.input=this.output=this._analyser=new ec({context:this.context,size:256,type:"waveform"})}dispose(){return super.dispose(),this._analyser.dispose(),this}}class nc extends sc{constructor(){super(bi(nc.getDefaults(),arguments,["smoothing"])),this.name="Meter",this._rms=0;const t=bi(nc.getDefaults(),arguments,["smoothing"]);this.input=this.output=this._analyser=new ec({context:this.context,size:256,type:"waveform",channels:t.channels}),this.smoothing=t.smoothing,this.normalRange=t.normalRange}static getDefaults(){return Object.assign(sc.getDefaults(),{smoothing:.8,normalRange:!1,channels:1})}getLevel(){return ti("'getLevel' has been changed to 'getValue'"),this.getValue()}getValue(){const t=this._analyser.getValue(),e=(1===this.channels?[t]:t).map(t=>{const e=t.reduce((t,e)=>t+e*e,0),s=Math.sqrt(e/t.length);return this._rms=Math.max(s,this._rms*this.smoothing),this.normalRange?this._rms:Hi(this._rms)});return 1===this.channels?e[0]:e}get channels(){return this._analyser.channels}dispose(){return super.dispose(),this._analyser.dispose(),this}}class ic extends sc{constructor(){super(bi(ic.getDefaults(),arguments,["size"])),this.name="FFT";const t=bi(ic.getDefaults(),arguments,["size"]);this.normalRange=t.normalRange,this._analyser.type="fft",this.size=t.size}static getDefaults(){return Object.assign(_o.getDefaults(),{normalRange:!1,size:1024,smoothing:.8})}getValue(){return this._analyser.getValue().map(t=>this.normalRange?Yi(t):t)}get size(){return this._analyser.size}set size(t){this._analyser.size=t}get smoothing(){return this._analyser.smoothing}set smoothing(t){this._analyser.smoothing=t}getFrequencyOfIndex(t){return Xn(0<=t&&tt._updateSolo())}get muted(){return 0===this.input.gain.value}_addSolo(){ac._soloed.has(this.context)||ac._soloed.set(this.context,new Set),ac._soloed.get(this.context).add(this)}_removeSolo(){ac._soloed.has(this.context)&&ac._soloed.get(this.context).delete(this)}_isSoloed(){return ac._soloed.has(this.context)&&ac._soloed.get(this.context).has(this)}_noSolos(){return!ac._soloed.has(this.context)||ac._soloed.has(this.context)&&0===ac._soloed.get(this.context).size}_updateSolo(){this._isSoloed()||this._noSolos()?this.input.gain.value=1:this.input.gain.value=0}dispose(){return super.dispose(),ac._allSolos.get(this.context).delete(this),this._removeSolo(),this}}ac._allSolos=new Map,ac._soloed=new Map;class cc extends _o{constructor(){super(bi(cc.getDefaults(),arguments,["pan","volume"])),this.name="PanVol";const t=bi(cc.getDefaults(),arguments,["pan","volume"]);this._panner=this.input=new xa({context:this.context,pan:t.pan,channelCount:t.channelCount}),this.pan=this._panner.pan,this._volume=this.output=new Po({context:this.context,volume:t.volume}),this.volume=this._volume.volume,this._panner.connect(this._volume),this.mute=t.mute,ji(this,["pan","volume"])}static getDefaults(){return Object.assign(_o.getDefaults(),{mute:!1,pan:0,volume:0,channelCount:1})}get mute(){return this._volume.mute}set mute(t){this._volume.mute=t}dispose(){return super.dispose(),this._panner.dispose(),this.pan.dispose(),this._volume.dispose(),this.volume.dispose(),this}}class hc extends _o{constructor(){super(bi(hc.getDefaults(),arguments,["volume","pan"])),this.name="Channel";const t=bi(hc.getDefaults(),arguments,["volume","pan"]);this._solo=this.input=new ac({solo:t.solo,context:this.context}),this._panVol=this.output=new cc({context:this.context,pan:t.pan,volume:t.volume,mute:t.mute,channelCount:t.channelCount}),this.pan=this._panVol.pan,this.volume=this._panVol.volume,this._solo.connect(this._panVol),ji(this,["pan","volume"])}static getDefaults(){return Object.assign(_o.getDefaults(),{pan:0,volume:0,mute:!1,solo:!1,channelCount:1})}get solo(){return this._solo.solo}set solo(t){this._solo.solo=t}get muted(){return this._solo.muted||this.mute}get mute(){return this._panVol.mute}set mute(t){this._panVol.mute=t}_getBus(t){return hc.buses.has(t)||hc.buses.set(t,new yo({context:this.context})),hc.buses.get(t)}send(t,e=0){const s=this._getBus(t),n=new yo({context:this.context,units:"decibels",gain:e});return this.connect(n),n.connect(s),n}receive(t){return this._getBus(t).connect(this),this}dispose(){return super.dispose(),this._panVol.dispose(),this.pan.dispose(),this.volume.dispose(),this._solo.dispose(),this}}hc.buses=new Map;class uc extends _o{constructor(){super(bi(uc.getDefaults(),arguments,["lowFrequency","highFrequency"])),this.name="MultibandSplit",this.input=new yo({context:this.context}),this.output=void 0,this.low=new Nr({context:this.context,frequency:0,type:"lowpass"}),this._lowMidFilter=new Nr({context:this.context,frequency:0,type:"highpass"}),this.mid=new Nr({context:this.context,frequency:0,type:"lowpass"}),this.high=new Nr({context:this.context,frequency:0,type:"highpass"}),this._internalChannels=[this.low,this.mid,this.high];const t=bi(uc.getDefaults(),arguments,["lowFrequency","highFrequency"]);this.lowFrequency=new bo({context:this.context,units:"frequency",value:t.lowFrequency}),this.highFrequency=new bo({context:this.context,units:"frequency",value:t.highFrequency}),this.Q=new bo({context:this.context,units:"positive",value:t.Q}),this.input.fan(this.low,this.high),this.input.chain(this._lowMidFilter,this.mid),this.lowFrequency.fan(this.low.frequency,this._lowMidFilter.frequency),this.highFrequency.fan(this.mid.frequency,this.high.frequency),this.Q.connect(this.low.Q),this.Q.connect(this._lowMidFilter.Q),this.Q.connect(this.mid.Q),this.Q.connect(this.high.Q),ji(this,["high","mid","low","highFrequency","lowFrequency"])}static getDefaults(){return Object.assign(_o.getDefaults(),{Q:1,highFrequency:2500,lowFrequency:400})}dispose(){return super.dispose(),Li(this,["high","mid","low","highFrequency","lowFrequency"]),this.low.dispose(),this._lowMidFilter.dispose(),this.mid.dispose(),this.high.dispose(),this.lowFrequency.dispose(),this.highFrequency.dispose(),this.Q.dispose(),this}}class lc extends _o{constructor(){super(...arguments),this.name="Listener",this.positionX=new fo({context:this.context,param:this.context.rawContext.listener.positionX}),this.positionY=new fo({context:this.context,param:this.context.rawContext.listener.positionY}),this.positionZ=new fo({context:this.context,param:this.context.rawContext.listener.positionZ}),this.forwardX=new fo({context:this.context,param:this.context.rawContext.listener.forwardX}),this.forwardY=new fo({context:this.context,param:this.context.rawContext.listener.forwardY}),this.forwardZ=new fo({context:this.context,param:this.context.rawContext.listener.forwardZ}),this.upX=new fo({context:this.context,param:this.context.rawContext.listener.upX}),this.upY=new fo({context:this.context,param:this.context.rawContext.listener.upY}),this.upZ=new fo({context:this.context,param:this.context.rawContext.listener.upZ})}static getDefaults(){return Object.assign(_o.getDefaults(),{positionX:0,positionY:0,positionZ:0,forwardX:0,forwardY:0,forwardZ:-1,upX:0,upY:1,upZ:0})}dispose(){return super.dispose(),this.positionX.dispose(),this.positionY.dispose(),this.positionZ.dispose(),this.forwardX.dispose(),this.forwardY.dispose(),this.forwardZ.dispose(),this.upX.dispose(),this.upY.dispose(),this.upZ.dispose(),this}}qi(t=>{t.listener=new lc({context:t})}),Ii(t=>{t.listener.dispose()});class pc extends _o{constructor(){super(bi(pc.getDefaults(),arguments,["positionX","positionY","positionZ"])),this.name="Panner3D";const t=bi(pc.getDefaults(),arguments,["positionX","positionY","positionZ"]);this._panner=this.input=this.output=this.context.createPanner(),this.panningModel=t.panningModel,this.maxDistance=t.maxDistance,this.distanceModel=t.distanceModel,this.coneOuterGain=t.coneOuterGain,this.coneOuterAngle=t.coneOuterAngle,this.coneInnerAngle=t.coneInnerAngle,this.refDistance=t.refDistance,this.rolloffFactor=t.rolloffFactor,this.positionX=new fo({context:this.context,param:this._panner.positionX,value:t.positionX}),this.positionY=new fo({context:this.context,param:this._panner.positionY,value:t.positionY}),this.positionZ=new fo({context:this.context,param:this._panner.positionZ,value:t.positionZ}),this.orientationX=new fo({context:this.context,param:this._panner.orientationX,value:t.orientationX}),this.orientationY=new fo({context:this.context,param:this._panner.orientationY,value:t.orientationY}),this.orientationZ=new fo({context:this.context,param:this._panner.orientationZ,value:t.orientationZ})}static getDefaults(){return Object.assign(_o.getDefaults(),{coneInnerAngle:360,coneOuterAngle:360,coneOuterGain:0,distanceModel:"inverse",maxDistance:1e4,orientationX:0,orientationY:0,orientationZ:0,panningModel:"equalpower",positionX:0,positionY:0,positionZ:0,refDistance:1,rolloffFactor:1})}setPosition(t,e,s){return this.positionX.value=t,this.positionY.value=e,this.positionZ.value=s,this}setOrientation(t,e,s){return this.orientationX.value=t,this.orientationY.value=e,this.orientationZ.value=s,this}get panningModel(){return this._panner.panningModel}set panningModel(t){this._panner.panningModel=t}get refDistance(){return this._panner.refDistance}set refDistance(t){this._panner.refDistance=t}get rolloffFactor(){return this._panner.rolloffFactor}set rolloffFactor(t){this._panner.rolloffFactor=t}get distanceModel(){return this._panner.distanceModel}set distanceModel(t){this._panner.distanceModel=t}get coneInnerAngle(){return this._panner.coneInnerAngle}set coneInnerAngle(t){this._panner.coneInnerAngle=t}get coneOuterAngle(){return this._panner.coneOuterAngle}set coneOuterAngle(t){this._panner.coneOuterAngle=t}get coneOuterGain(){return this._panner.coneOuterGain}set coneOuterGain(t){this._panner.coneOuterGain=t}get maxDistance(){return this._panner.maxDistance}set maxDistance(t){this._panner.maxDistance=t}dispose(){return super.dispose(),this._panner.disconnect(),this.orientationX.dispose(),this.orientationY.dispose(),this.orientationZ.dispose(),this.positionX.dispose(),this.positionY.dispose(),this.positionZ.dispose(),this}}class dc extends _o{constructor(){super(bi(dc.getDefaults(),arguments)),this.name="Recorder";const t=bi(dc.getDefaults(),arguments);this.input=new yo({context:this.context}),Xn(dc.supported,"Media Recorder API is not available"),this._stream=this.context.createMediaStreamDestination(),this.input.connect(this._stream),this._recorder=new MediaRecorder(this._stream.stream,{mimeType:t.mimeType})}static getDefaults(){return _o.getDefaults()}get mimeType(){return this._recorder.mimeType}static get supported(){return null!==ui&&Reflect.has(ui,"MediaRecorder")}get state(){return"inactive"===this._recorder.state?"stopped":"paused"===this._recorder.state?"paused":"started"}start(){return di(this,void 0,void 0,(function*(){Xn("started"!==this.state,"Recorder is already started");const t=new Promise(t=>{const e=()=>{this._recorder.removeEventListener("start",e,!1),t()};this._recorder.addEventListener("start",e,!1)});return this._recorder.start(),yield t}))}stop(){return di(this,void 0,void 0,(function*(){Xn("stopped"!==this.state,"Recorder is not started");const t=new Promise(t=>{const e=s=>{this._recorder.removeEventListener("dataavailable",e,!1),t(s.data)};this._recorder.addEventListener("dataavailable",e,!1)});return this._recorder.stop(),yield t}))}pause(){return Xn("started"===this.state,"Recorder must be started"),this._recorder.pause(),this}dispose(){return super.dispose(),this.input.dispose(),this._stream.disconnect(),this}}class fc extends _o{constructor(){super(bi(fc.getDefaults(),arguments,["threshold","ratio"])),this.name="Compressor",this._compressor=this.context.createDynamicsCompressor(),this.input=this._compressor,this.output=this._compressor;const t=bi(fc.getDefaults(),arguments,["threshold","ratio"]);this.threshold=new fo({minValue:this._compressor.threshold.minValue,maxValue:this._compressor.threshold.maxValue,context:this.context,convert:!1,param:this._compressor.threshold,units:"decibels",value:t.threshold}),this.attack=new fo({minValue:this._compressor.attack.minValue,maxValue:this._compressor.attack.maxValue,context:this.context,param:this._compressor.attack,units:"time",value:t.attack}),this.release=new fo({minValue:this._compressor.release.minValue,maxValue:this._compressor.release.maxValue,context:this.context,param:this._compressor.release,units:"time",value:t.release}),this.knee=new fo({minValue:this._compressor.knee.minValue,maxValue:this._compressor.knee.maxValue,context:this.context,convert:!1,param:this._compressor.knee,units:"decibels",value:t.knee}),this.ratio=new fo({minValue:this._compressor.ratio.minValue,maxValue:this._compressor.ratio.maxValue,context:this.context,convert:!1,param:this._compressor.ratio,units:"positive",value:t.ratio}),ji(this,["knee","release","attack","ratio","threshold"])}static getDefaults(){return Object.assign(_o.getDefaults(),{attack:.003,knee:30,ratio:12,release:.25,threshold:-24})}get reduction(){return this._compressor.reduction}dispose(){return super.dispose(),this._compressor.disconnect(),this.attack.dispose(),this.release.dispose(),this.threshold.dispose(),this.ratio.dispose(),this.knee.dispose(),this}}class _c extends _o{constructor(){super(Object.assign(bi(_c.getDefaults(),arguments,["threshold","smoothing"]))),this.name="Gate";const t=bi(_c.getDefaults(),arguments,["threshold","smoothing"]);this._follower=new ba({context:this.context,smoothing:t.smoothing}),this._gt=new Sr({context:this.context,value:Yi(t.threshold)}),this.input=new yo({context:this.context}),this._gate=this.output=new yo({context:this.context}),this.input.connect(this._gate),this.input.chain(this._follower,this._gt,this._gate.gain)}static getDefaults(){return Object.assign(_o.getDefaults(),{smoothing:.1,threshold:-40})}get threshold(){return Hi(this._gt.value)}set threshold(t){this._gt.value=Yi(t)}get smoothing(){return this._follower.smoothing}set smoothing(t){this._follower.smoothing=t}dispose(){return super.dispose(),this.input.dispose(),this._follower.dispose(),this._gt.dispose(),this._gate.dispose(),this}}class mc extends _o{constructor(){super(Object.assign(bi(mc.getDefaults(),arguments,["threshold"]))),this.name="Limiter";const t=bi(mc.getDefaults(),arguments,["threshold"]);this._compressor=this.input=this.output=new fc({context:this.context,ratio:20,attack:0,release:0,threshold:t.threshold}),this.threshold=this._compressor.threshold,ji(this,"threshold")}static getDefaults(){return Object.assign(_o.getDefaults(),{threshold:-12})}get reduction(){return this._compressor.reduction}dispose(){return super.dispose(),this._compressor.dispose(),this.threshold.dispose(),this}}class gc extends _o{constructor(){super(Object.assign(bi(gc.getDefaults(),arguments))),this.name="MidSideCompressor";const t=bi(gc.getDefaults(),arguments);this._midSideSplit=this.input=new Ya({context:this.context}),this._midSideMerge=this.output=new Ha({context:this.context}),this.mid=new fc(Object.assign(t.mid,{context:this.context})),this.side=new fc(Object.assign(t.side,{context:this.context})),this._midSideSplit.mid.chain(this.mid,this._midSideMerge.mid),this._midSideSplit.side.chain(this.side,this._midSideMerge.side),ji(this,["mid","side"])}static getDefaults(){return Object.assign(_o.getDefaults(),{mid:{ratio:3,threshold:-24,release:.03,attack:.02,knee:16},side:{ratio:6,threshold:-30,release:.25,attack:.03,knee:10}})}dispose(){return super.dispose(),this.mid.dispose(),this.side.dispose(),this._midSideSplit.dispose(),this._midSideMerge.dispose(),this}}class vc extends _o{constructor(){super(Object.assign(bi(vc.getDefaults(),arguments))),this.name="MultibandCompressor";const t=bi(vc.getDefaults(),arguments);this._splitter=this.input=new uc({context:this.context,lowFrequency:t.lowFrequency,highFrequency:t.highFrequency}),this.lowFrequency=this._splitter.lowFrequency,this.highFrequency=this._splitter.highFrequency,this.output=new yo({context:this.context}),this.low=new fc(Object.assign(t.low,{context:this.context})),this.mid=new fc(Object.assign(t.mid,{context:this.context})),this.high=new fc(Object.assign(t.high,{context:this.context})),this._splitter.low.chain(this.low,this.output),this._splitter.mid.chain(this.mid,this.output),this._splitter.high.chain(this.high,this.output),ji(this,["high","mid","low","highFrequency","lowFrequency"])}static getDefaults(){return Object.assign(_o.getDefaults(),{lowFrequency:250,highFrequency:2e3,low:{ratio:6,threshold:-30,release:.25,attack:.03,knee:10},mid:{ratio:3,threshold:-24,release:.03,attack:.02,knee:16},high:{ratio:3,threshold:-24,release:.03,attack:.02,knee:16}})}dispose(){return super.dispose(),this._splitter.dispose(),this.low.dispose(),this.mid.dispose(),this.high.dispose(),this.output.dispose(),this}}class yc extends _o{constructor(){super(bi(yc.getDefaults(),arguments,["low","mid","high"])),this.name="EQ3",this.output=new yo({context:this.context}),this._internalChannels=[];const t=bi(yc.getDefaults(),arguments,["low","mid","high"]);this.input=this._multibandSplit=new uc({context:this.context,highFrequency:t.highFrequency,lowFrequency:t.lowFrequency}),this._lowGain=new yo({context:this.context,gain:t.low,units:"decibels"}),this._midGain=new yo({context:this.context,gain:t.mid,units:"decibels"}),this._highGain=new yo({context:this.context,gain:t.high,units:"decibels"}),this.low=this._lowGain.gain,this.mid=this._midGain.gain,this.high=this._highGain.gain,this.Q=this._multibandSplit.Q,this.lowFrequency=this._multibandSplit.lowFrequency,this.highFrequency=this._multibandSplit.highFrequency,this._multibandSplit.low.chain(this._lowGain,this.output),this._multibandSplit.mid.chain(this._midGain,this.output),this._multibandSplit.high.chain(this._highGain,this.output),ji(this,["low","mid","high","lowFrequency","highFrequency"]),this._internalChannels=[this._multibandSplit]}static getDefaults(){return Object.assign(_o.getDefaults(),{high:0,highFrequency:2500,low:0,lowFrequency:400,mid:0})}dispose(){return super.dispose(),Li(this,["low","mid","high","lowFrequency","highFrequency"]),this._multibandSplit.dispose(),this.lowFrequency.dispose(),this.highFrequency.dispose(),this._lowGain.dispose(),this._midGain.dispose(),this._highGain.dispose(),this.low.dispose(),this.mid.dispose(),this.high.dispose(),this.Q.dispose(),this}}class xc extends _o{constructor(){super(bi(xc.getDefaults(),arguments,["url","onload"])),this.name="Convolver",this._convolver=this.context.createConvolver();const t=bi(xc.getDefaults(),arguments,["url","onload"]);this._buffer=new Bi(t.url,e=>{this.buffer=e,t.onload()}),this.input=new yo({context:this.context}),this.output=new yo({context:this.context}),this._buffer.loaded&&(this.buffer=this._buffer),this.normalize=t.normalize,this.input.chain(this._convolver,this.output)}static getDefaults(){return Object.assign(_o.getDefaults(),{normalize:!0,onload:zi})}load(t){return di(this,void 0,void 0,(function*(){this.buffer=yield this._buffer.load(t)}))}get buffer(){return this._buffer.length?this._buffer:null}set buffer(t){t&&this._buffer.set(t),this._convolver.buffer&&(this.input.disconnect(),this._convolver.disconnect(),this._convolver=this.context.createConvolver(),this.input.chain(this._convolver,this.output));const e=this._buffer.get();this._convolver.buffer=e||null}get normalize(){return this._convolver.normalize}set normalize(t){this._convolver.normalize=t}dispose(){return super.dispose(),this._buffer.dispose(),this._convolver.disconnect(),this}}function wc(){return Qi().now()}function bc(){return Qi().immediate()}const Tc=Qi().transport;function Sc(){return Qi().transport}const kc=Qi().destination,Cc=Qi().destination;function Ac(){return Qi().destination}const Dc=Qi().listener;function Oc(){return Qi().listener}const Mc=Qi().draw;function Ec(){return Qi().draw}const Rc=Qi();function qc(){return Bi.loaded()}const Fc=Bi,Ic=Mo,Vc=Go}])})); ; !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@tensorflow/tfjs"),require("tone")):"function"==typeof define&&define.amd?define(["tf","Tone"],e):"object"==typeof exports?exports.core=e(require("@tensorflow/tfjs"),require("tone")):t.core=e(t.tf,t.Tone)}(self,(function(__WEBPACK_EXTERNAL_MODULE__2__,__WEBPACK_EXTERNAL_MODULE__9__){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=73)}([,,function(t,e){t.exports=__WEBPACK_EXTERNAL_MODULE__2__},,,,,,function(t,e,n){"use strict";n.r(e),n.d(e,"DEFAULT_QUARTERS_PER_MINUTE",(function(){return r})),n.d(e,"DEFAULT_STEPS_PER_BAR",(function(){return i})),n.d(e,"DEFAULT_STEPS_PER_QUARTER",(function(){return o})),n.d(e,"DEFAULT_STEPS_PER_SECOND",(function(){return s})),n.d(e,"DEFAULT_VELOCITY",(function(){return a})),n.d(e,"DEFAULT_PROGRAM",(function(){return u})),n.d(e,"DEFAULT_TICKS_PER_QUARTER",(function(){return c})),n.d(e,"DEFAULT_CHANNEL",(function(){return l})),n.d(e,"DRUM_CHANNEL",(function(){return h})),n.d(e,"NON_DRUM_CHANNELS",(function(){return p})),n.d(e,"DEFAULT_DRUM_PITCH_CLASSES",(function(){return f})),n.d(e,"MIN_MIDI_VELOCITY",(function(){return m})),n.d(e,"MAX_MIDI_VELOCITY",(function(){return d})),n.d(e,"MIDI_VELOCITIES",(function(){return g})),n.d(e,"NO_CHORD",(function(){return S})),n.d(e,"NUM_PITCH_CLASSES",(function(){return y})),n.d(e,"MIN_MIDI_PITCH",(function(){return b})),n.d(e,"MAX_MIDI_PITCH",(function(){return w})),n.d(e,"MIDI_PITCHES",(function(){return P})),n.d(e,"MIN_PIANO_PITCH",(function(){return v})),n.d(e,"MAX_PIANO_PITCH",(function(){return N})),n.d(e,"MIN_DRUM_PITCH",(function(){return T})),n.d(e,"MAX_DRUM_PITCH",(function(){return O})),n.d(e,"MIN_MIDI_PROGRAM",(function(){return I})),n.d(e,"MAX_MIDI_PROGRAM",(function(){return M})),n.d(e,"LO_CLICK_PITCH",(function(){return A})),n.d(e,"HI_CLICK_PITCH",(function(){return k})),n.d(e,"LO_CLICK_CLASS",(function(){return q})),n.d(e,"HI_CLICK_CLASS",(function(){return E}));const r=120,i=16,o=4,s=100,a=80,u=0,c=220,l=0,h=9,p=[0,1,2,3,4,5,6,7,8,10,11,12,13,14,15],f=[[36,35],[38,27,28,31,32,33,34,37,39,40,56,65,66,75,85],[42,44,54,68,69,70,71,73,78,80],[46,67,72,74,79,81],[45,29,41,61,64,84],[48,47,60,63,77,86,87],[50,30,43,62,76,83],[49,55,57,58],[51,52,53,59,82]],m=0,d=127,g=d-m+1,S="N.C.",y=12,b=0,w=127,P=w-b+1,v=21,N=108,T=35,O=81,I=0,M=127,A=89,k=90,q=9,E=10},function(t,e){t.exports=__WEBPACK_EXTERNAL_MODULE__9__},function(t,e,n){"use strict";n.d(e,"a",(function(){return i}));var r=n(35),i=r.tensorflow.magenta.NoteSequence},,function(t,e,n){"use strict";n.r(e),n.d(e,"Level",(function(){return r})),n.d(e,"verbosity",(function(){return o})),n.d(e,"setVerbosity",(function(){return s})),n.d(e,"log",(function(){return a})),n.d(e,"logWithDuration",(function(){return u}));var r,i=n(15);!function(t){t[t.NONE=0]="NONE",t[t.WARN=5]="WARN",t[t.INFO=10]="INFO",t[t.DEBUG=20]="DEBUG"}(r||(r={}));let o=10;function s(t){t=t}function a(t,e="Magenta.js",n=10){if(0===n)throw Error("Logging level cannot be NONE.");if(o>=n){(5===n?console.warn:console.log)(`%c ${e} `,"background:magenta; color:white",t)}}function u(t,e,n="Magenta.js",r=10){a(`${t} in ${((i.d.now()-e)/1e3).toPrecision(3)}s`,n,r)}},function(t,e,n){"use strict";n.r(e),n.d(e,"MultipleTimeSignatureException",(function(){return o})),n.d(e,"BadTimeSignatureException",(function(){return s})),n.d(e,"NegativeTimeException",(function(){return a})),n.d(e,"MultipleTempoException",(function(){return u})),n.d(e,"QuantizationStatusException",(function(){return c})),n.d(e,"clone",(function(){return l})),n.d(e,"stepsPerQuarterToStepsPerSecond",(function(){return h})),n.d(e,"quantizeToStep",(function(){return p})),n.d(e,"quantizeNoteSequence",(function(){return d})),n.d(e,"isQuantizedSequence",(function(){return g})),n.d(e,"assertIsQuantizedSequence",(function(){return S})),n.d(e,"isRelativeQuantizedSequence",(function(){return y})),n.d(e,"assertIsRelativeQuantizedSequence",(function(){return b})),n.d(e,"isAbsoluteQuantizedSequence",(function(){return w})),n.d(e,"assertIsAbsoluteQuantizedSequence",(function(){return P})),n.d(e,"unquantizeSequence",(function(){return v})),n.d(e,"createQuantizedNoteSequence",(function(){return N})),n.d(e,"mergeInstruments",(function(){return T})),n.d(e,"replaceInstruments",(function(){return O})),n.d(e,"mergeConsecutiveNotes",(function(){return I})),n.d(e,"applySustainControlChanges",(function(){return M})),n.d(e,"concatenate",(function(){return A})),n.d(e,"trim",(function(){return k})),n.d(e,"split",(function(){return _}));var r=n(10),i=n(8);class o extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}class s extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}class a extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}class u extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}class c extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}function l(t){return r.a.decode(r.a.encode(t).finish())}function h(t,e){return t*e/60}function p(t,e,n=.5){const r=t*e;return Math.floor(r+(1-n))}function f(t){return t.controlChanges.concat(t.textAnnotations)}function m(t){if(t.tempos&&0!==t.tempos.length){if(t.tempos.sort((t,e)=>t.time-e.time),0!==t.tempos[0].time&&t.tempos[0].qpm!==i.DEFAULT_QUARTERS_PER_MINUTE)throw new u("NoteSequence has an implicit tempo change from initial "+i.DEFAULT_QUARTERS_PER_MINUTE+" qpm to "+`${t.tempos[0].qpm} qpm at ${t.tempos[0].time} seconds.`);for(let e=1;e0){if(n.timeSignatures.sort((t,e)=>t.time-e.time),0!==n.timeSignatures[0].time&&(4!==n.timeSignatures[0].numerator||4!==n.timeSignatures[0].denominator))throw new o(`NoteSequence has an implicit change from initial 4/4 time signature to ${n.timeSignatures[0].numerator}/`+n.timeSignatures[0].denominator+" at "+n.timeSignatures[0].time+" seconds.");for(let t=1;t0)m(n),n.tempos[0].time=0,n.tempos=[n.tempos[0]];else{const t=r.a.Tempo.create({qpm:i.DEFAULT_QUARTERS_PER_MINUTE,time:0});n.tempos.push(t)}const d=h(e,n.tempos[0].qpm);return n.totalQuantizedSteps=p(t.totalTime,d),function(t,e){for(const n of t.notes){if(n.quantizedStartStep=p(n.startTime,e),n.quantizedEndStep=p(n.endTime,e),n.quantizedEndStep===n.quantizedStartStep&&(n.quantizedEndStep+=1),n.quantizedStartStep<0||n.quantizedEndStep<0)throw new a("Got negative note time: start_step = "+n.quantizedStartStep+", end_step = "+n.quantizedEndStep);n.quantizedEndStep>t.totalQuantizedSteps&&(t.totalQuantizedSteps=n.quantizedEndStep)}f(t).forEach(t=>{if(t.quantizedStep=p(t.time,e),t.quantizedStep<0)throw new a("Got negative event time: step = "+t.quantizedStep)})}(n,d),n}function g(t){return t.quantizationInfo&&(t.quantizationInfo.stepsPerQuarter>0||t.quantizationInfo.stepsPerSecond>0)}function S(t){if(!g(t))throw new c(`NoteSequence ${t.id} is not quantized (missing quantizationInfo)`)}function y(t){return t.quantizationInfo&&t.quantizationInfo.stepsPerQuarter>0}function b(t){if(!y(t))throw new c(`NoteSequence ${t.id} is not quantized or is quantized based on absolute timing`)}function w(t){return t.quantizationInfo&&t.quantizationInfo.stepsPerSecond>0}function P(t){if(!w(t))throw new c(`NoteSequence ${t.id} is not quantized or is quantized based on relative timing`)}function v(t,e){b(t),m(t);const n=l(t);e?n.tempos&&n.tempos.length>0?n.tempos[0].qpm=e:n.tempos.push(r.a.Tempo.create({time:0,qpm:e})):e=t.tempos&&t.tempos.length>0?n.tempos[0].qpm:i.DEFAULT_QUARTERS_PER_MINUTE;const o=t=>t/n.quantizationInfo.stepsPerQuarter*(60/e);return n.totalTime=o(n.totalQuantizedSteps),n.notes.forEach(t=>{t.startTime=o(t.quantizedStartStep),t.endTime=o(t.quantizedEndStep),n.totalTime=Math.max(n.totalTime,t.endTime),delete t.quantizedStartStep,delete t.quantizedEndStep}),f(n).forEach(t=>{t.time=o(t.time)}),delete n.totalQuantizedSteps,delete n.quantizationInfo,n}function N(t=i.DEFAULT_STEPS_PER_QUARTER,e=i.DEFAULT_QUARTERS_PER_MINUTE){return r.a.create({quantizationInfo:{stepsPerQuarter:t},tempos:[{qpm:e}]})}function T(t){const e=l(t),n=e.notes.concat(e.pitchBends).concat(e.controlChanges),r=Array.from(new Set(n.filter(t=>!t.isDrum).map(t=>t.program)));return n.forEach(t=>{t.isDrum?(t.program=0,t.instrument=r.length):t.instrument=r.indexOf(t.program)}),e}function O(t,e){const n=new Set(t.notes.map(t=>t.instrument)),i=new Set(e.notes.map(t=>t.instrument)),o=[];t.notes.forEach(t=>{i.has(t.instrument)||o.push(r.a.Note.create(t))}),e.notes.forEach(t=>{n.has(t.instrument)&&o.push(r.a.Note.create(t))});const s=l(t);return s.notes=o.sort((t,e)=>{const n=t.instrument-e.instrument;return n||t.quantizedStartStep-e.quantizedStartStep}),s}function I(t){S(t);const e=l(t);e.notes=[];const n=t.notes.sort((t,e)=>{const n=t.instrument-e.instrument;return n||t.quantizedStartStep-e.quantizedStartStep}),i=new r.a.Note;i.pitch=n[0].pitch,i.instrument=n[0].instrument,i.quantizedStartStep=n[0].quantizedStartStep,i.quantizedEndStep=n[0].quantizedEndStep,e.notes.push(i);let o=0;for(let t=1;t=64?i.push({time:t.time,type:n.SUSTAIN_ON,event:t}):e<64&&i.push({time:t.time,type:n.SUSTAIN_OFF,event:t})}i.sort((t,e)=>t.time-e.time);const o={},s={};let a=0;for(const t of i){a=t.time;const e=t.type,i=t.event;if(e===n.SUSTAIN_ON)s[i.instrument]=!0;else if(e===n.SUSTAIN_OFF){s[i.instrument]=!1;const t=[];i.instrument in o||(o[i.instrument]=[]);for(const e of o[i.instrument])e.endTimer.totalTime&&(r.totalTime=a)):t.push(e);o[i.instrument]=t}else if(e===n.NOTE_ON){if(!0===s[i.instrument]){const t=[];i.instrument in o||(o[i.instrument]=[]);for(const e of o[i.instrument])e.pitch===i.pitch?(e.endTime=a,e.startTime===e.endTime&&r.notes.push(e)):t.push(e);o[i.instrument]=t}i.instrument in o||(o[i.instrument]=[]),o[i.instrument].push(i)}else if(e===n.NOTE_OFF)if(!0===s[i.instrument]);else{const t=o[i.instrument].indexOf(i);t>-1&&o[i.instrument].splice(t,1)}}for(const t of Object.values(o))for(const e of t)e.endTime=a,r.totalTime=a;return r}function A(t,e){if(e&&e.length!==t.length)throw new Error("Number of sequences to concatenate and their individual\n durations does not match.");if(g(t[0])){for(let e=0;e{const e=r.a.Note.create(t);return e[n]+=a,e[i]+=a,e})),a+=c}return s[e]=a,s}function E(t,e,n,r,i,o,s){const a=l(t);a[r]=n,a.notes=a.notes.filter(t=>t[i]>=e&&t[i]<=n&&(s||t[o]<=n)),a[r]-=e;for(let t=0;tt.quantizedStartStep-e.quantizedStartStep),o=[];let s=0,a=[];for(let t=0;te||u.quantizedStartStep>e)&&(t-=1),0!==a.length){const t=l(n);t.notes=a,t.totalQuantizedSteps=e,o.push(t)}a=[],s+=e}}if(0!==a.length){const t=l(n);t.notes=a,t.totalQuantizedSteps=e,o.push(t)}return o}},,function(t,e,n){"use strict";(function(t){n.d(e,"a",(function(){return i})),n.d(e,"d",(function(){return o})),n.d(e,"c",(function(){return s})),n.d(e,"b",(function(){return u}));const r=function(){if("undefined"!=typeof globalThis)return globalThis;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==t)return t;throw new Error("cannot find the global object")}(),i=r.fetch.bind(r),o=r.performance,s=(r.navigator,!!r.webkitOfflineAudioContext),a=void 0!==r.WorkerGlobalScope;function u(t){if(t=s?44100:t,a)throw new Error("Cannot use offline audio context in a web worker.");const e=r.webkitOfflineAudioContext;return s?new e(1,t,t):new r.OfflineAudioContext(1,t,t)}}).call(this,n(21))},,,function(t,e,n){"use strict";(function(t){var r=e;function i(t,e,n){for(var r=Object.keys(e),i=0;i0)},r.Buffer=function(){try{var t=r.inquire("buffer").Buffer;return t.prototype.utf8Write?t:null}catch(t){return null}}(),r._Buffer_from=null,r._Buffer_allocUnsafe=null,r.newBuffer=function(t){return"number"==typeof t?r.Buffer?r._Buffer_allocUnsafe(t):new r.Array(t):r.Buffer?r._Buffer_from(t):"undefined"==typeof Uint8Array?t:new Uint8Array(t)},r.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,r.Long=r.global.dcodeIO&&r.global.dcodeIO.Long||r.global.Long||r.inquire("long"),r.key2Re=/^true|false|0|1$/,r.key32Re=/^-?(?:0|[1-9][0-9]*)$/,r.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,r.longToHash=function(t){return t?r.LongBits.from(t).toHash():r.LongBits.zeroHash},r.longFromHash=function(t,e){var n=r.LongBits.fromHash(t);return r.Long?r.Long.fromBits(n.lo,n.hi,e):n.toNumber(Boolean(e))},r.merge=i,r.lcFirst=function(t){return t.charAt(0).toLowerCase()+t.substring(1)},r.newError=o,r.ProtocolError=o("ProtocolError"),r.oneOfGetter=function(t){for(var e={},n=0;n-1;--n)if(1===e[t[n]]&&void 0!==this[t[n]]&&null!==this[t[n]])return t[n]}},r.oneOfSetter=function(t){return function(e){for(var n=0;nt.quantizedStartStep===e.quantizedStartStep?e.pitch-t.pitch:t.quantizedStartStep-e.quantizedStartStep),c=new Int32Array(i||t.totalQuantizedSteps);let l=-1;return s.forEach(t=>{if(t.quantizedStartStep===l){if(r)return;throw new Error("`NoteSequence` is not monophonic.")}if(t.pitchn)throw Error("`NoteSequence` has a pitch outside of the valid range: "+t.pitch);c[t.quantizedStartStep]=t.pitch-e+2,c[t.quantizedEndStep]=a,l=t.quantizedStartStep}),new u(c,e,n)}toNoteSequence(t,e){const n=o.createQuantizedNoteSequence(t,e);let r=null;for(let t=0;t=2?1:0,r,0);return n.toTensor().as2D(e,1)}}class l{constructor(){this.depth=3}extract(t){const e=t.events.length,n=r.buffer([e,3]);let i=null,o=null;for(let r=0;r=2){if(null!==i){let e;0===n.get(i,0)&&0===n.get(i,1)&&0===n.get(i,2)&&(i=-1),e=t.events[r]o?2:1;for(let t=r;t>i;--t)n.set(1,t,e)}i=r,o=t.events[r]}if(i!==e-1)if(null===i||0===n.get(i,0)&&0===n.get(i,1)&&0===n.get(i,2))for(let t=0;ti;--t)for(let e=0;e<3;e++)n.set(n.get(i,e),t,e);return n.toTensor().as2D(e,3)}}class h{constructor(t){this.boundaryPitches=t,this.depth=t.length+1}meanMelodyPitch(t){let e=0,n=0,r=null;for(let i=0;i=2&&(r=t.minPitch+t.events[i]-2),null!==r&&(e+=r,n+=1);return n?e/n:null}extract(t){const e=t.events.length,n=this.meanMelodyPitch(t);if(null===n)return r.zeros([e,this.depth]);let i=0;for(;i=this.boundaryPitches[i];)i++;const o=r.buffer([e,this.depth]);for(let t=0;tvoid 0===r||t.instrument===r),u=s.sort((t,e)=>t.startTime===e.startTime?t.pitch-e.pitch:t.startTime-e.startTime),c=u.map((t,e)=>({step:t.quantizedStartStep,index:e,isOffset:0})),l=u.map((t,e)=>({step:t.quantizedEndStep,index:e,isOffset:1})),h=c.concat(l).sort((t,e)=>t.step===e.step?t.index===e.index?t.isOffset-e.isOffset:t.index-e.index:t.step-e.step),p=n?Math.ceil((i.MIDI_VELOCITIES-1)/n):void 0,f=[];let m=0,d=n;for(const t of h){if(t.step>m){for(;t.step>m+e;)f.push({type:"time-shift",steps:e}),m+=e;f.push({type:"time-shift",steps:t.step-m}),m=t.step}if(t.isOffset)f.push({type:"note-off",pitch:u[t.index].pitch});else{if(p){const e=Math.floor((u[t.index].velocity-i.MIN_MIDI_VELOCITY-1)/p)+1;e!==d&&(f.push({type:"velocity-change",velocityBin:e}),d=e)}f.push({type:"note-on",pitch:u[t.index].pitch})}}const g=!!s.some(t=>t.isDrum)&&(!s.some(t=>!t.isDrum)||void 0),S=Array.from(new Set(s.map(t=>t.program))),y=g||1!==S.length?void 0:S[0],b=new a(f,e,n,y,g);return b.setNumSteps(t.totalQuantizedSteps),b}getNumSteps(){return this.events.filter(t=>"time-shift"===t.type).map(t=>t.steps).reduce((t,e)=>t+e,0)}setNumSteps(t){let e=this.getNumSteps();if(et?(this.events.push({type:"time-shift",steps:t-e}),e=t):(this.events.push({type:"time-shift",steps:this.maxShiftSteps}),e+=this.maxShiftSteps)}else if(e>t)for(;this.events.length&&e>t;){const n=this.events[this.events.length-1];"time-shift"===n.type?e-n.stepse?n.notes.push(r.a.Note.create({pitch:c.pitch,velocity:i,instrument:t,quantizedStartStep:e,quantizedEndStep:o,program:this.program,isDrum:this.isDrum})):s.log(`Ignoring zero-length note: (pitch = ${c.pitch}, step = ${o})`,"Performance")}else s.log(`Ignoring note-off with no previous note-on:(pitch = ${c.pitch}, step = ${o})`,"Performance");break;case"time-shift":o+=c.steps;break;case"velocity-change":if(!e)throw new Error("Unexpected velocity change event: "+c);a=i.MIN_MIDI_VELOCITY+(c.velocityBin-1)*e+1;break;default:throw new Error("Unrecognized performance event: "+c)}return u.forEach((e,i)=>{for(const[a,u]of e)o>a?n.notes.push(r.a.Note.create({pitch:i,velocity:u,instrument:t,quantizedStartStep:a,quantizedEndStep:o,program:this.program,isDrum:this.isDrum})):s.log(`Ignoring zero-length note: (pitch = ${i}, step = ${o})`,"Performance")}),n.totalQuantizedSteps=o,n}}},,,,function(t,e,n){"use strict";t.exports=h;var r,i=n(18),o=i.LongBits,s=i.base64,a=i.utf8;function u(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}function c(){}function l(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}function h(){this.len=0,this.head=new u(c,0,0),this.tail=this.head,this.states=null}var p=function(){return i.Buffer?function(){return(h.create=function(){return new r})()}:function(){return new h}};function f(t,e,n){e[n]=255&t}function m(t,e){this.len=t,this.next=void 0,this.val=e}function d(t,e,n){for(;t.hi;)e[n++]=127&t.lo|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[n++]=127&t.lo|128,t.lo=t.lo>>>7;e[n++]=t.lo}function g(t,e,n){e[n]=255&t,e[n+1]=t>>>8&255,e[n+2]=t>>>16&255,e[n+3]=t>>>24}h.create=p(),h.alloc=function(t){return new i.Array(t)},i.Array!==Array&&(h.alloc=i.pool(h.alloc,i.Array.prototype.subarray)),h.prototype._push=function(t,e,n){return this.tail=this.tail.next=new u(t,e,n),this.len+=e,this},m.prototype=Object.create(u.prototype),m.prototype.fn=function(t,e,n){for(;t>127;)e[n++]=127&t|128,t>>>=7;e[n]=t},h.prototype.uint32=function(t){return this.len+=(this.tail=this.tail.next=new m((t>>>=0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this},h.prototype.int32=function(t){return t<0?this._push(d,10,o.fromNumber(t)):this.uint32(t)},h.prototype.sint32=function(t){return this.uint32((t<<1^t>>31)>>>0)},h.prototype.uint64=function(t){var e=o.from(t);return this._push(d,e.length(),e)},h.prototype.int64=h.prototype.uint64,h.prototype.sint64=function(t){var e=o.from(t).zzEncode();return this._push(d,e.length(),e)},h.prototype.bool=function(t){return this._push(f,1,t?1:0)},h.prototype.fixed32=function(t){return this._push(g,4,t>>>0)},h.prototype.sfixed32=h.prototype.fixed32,h.prototype.fixed64=function(t){var e=o.from(t);return this._push(g,4,e.lo)._push(g,4,e.hi)},h.prototype.sfixed64=h.prototype.fixed64,h.prototype.float=function(t){return this._push(i.float.writeFloatLE,4,t)},h.prototype.double=function(t){return this._push(i.float.writeDoubleLE,8,t)};var S=i.Array.prototype.set?function(t,e,n){e.set(t,n)}:function(t,e,n){for(var r=0;r>>0;if(!e)return this._push(f,1,0);if(i.isString(t)){var n=h.alloc(e=s.length(t));s.decode(t,n,0),t=n}return this.uint32(e)._push(S,e,t)},h.prototype.string=function(t){var e=a.length(t);return e?this.uint32(e)._push(a.write,e,t):this._push(f,1,0)},h.prototype.fork=function(){return this.states=new l(this),this.head=this.tail=new u(c,0,0),this.len=0,this},h.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new u(c,0,0),this.len=0),this},h.prototype.ldelim=function(){var t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n&&(this.tail.next=t.next,this.tail=e,this.len+=n),this},h.prototype.finish=function(){for(var t=this.head.next,e=this.constructor.alloc(this.len),n=0;t;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e},h._configure=function(t){r=t,h.create=p(),r._configure()}},function(t,e,n){"use strict";t.exports=u;var r,i=n(18),o=i.LongBits,s=i.utf8;function a(t,e){return RangeError("index out of range: "+t.pos+" + "+(e||1)+" > "+t.len)}function u(t){this.buf=t,this.pos=0,this.len=t.length}var c,l="undefined"!=typeof Uint8Array?function(t){if(t instanceof Uint8Array||Array.isArray(t))return new u(t);throw Error("illegal buffer")}:function(t){if(Array.isArray(t))return new u(t);throw Error("illegal buffer")},h=function(){return i.Buffer?function(t){return(u.create=function(t){return i.Buffer.isBuffer(t)?new r(t):l(t)})(t)}:l};function p(){var t=new o(0,0),e=0;if(!(this.len-this.pos>4)){for(;e<3;++e){if(this.pos>=this.len)throw a(this);if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*e)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(127&this.buf[this.pos++])<<7*e)>>>0,t}for(;e<4;++e)if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*e)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(127&this.buf[this.pos])<<28)>>>0,t.hi=(t.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return t;if(e=0,this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*e+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw a(this);if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*e+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}function f(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}function m(){if(this.pos+8>this.len)throw a(this,8);return new o(f(this.buf,this.pos+=4),f(this.buf,this.pos+=4))}u.create=h(),u.prototype._slice=i.Array.prototype.subarray||i.Array.prototype.slice,u.prototype.uint32=(c=4294967295,function(){if(c=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return c;if(c=(c|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return c;if((this.pos+=5)>this.len)throw this.pos=this.len,a(this,10);return c}),u.prototype.int32=function(){return 0|this.uint32()},u.prototype.sint32=function(){var t=this.uint32();return t>>>1^-(1&t)|0},u.prototype.bool=function(){return 0!==this.uint32()},u.prototype.fixed32=function(){if(this.pos+4>this.len)throw a(this,4);return f(this.buf,this.pos+=4)},u.prototype.sfixed32=function(){if(this.pos+4>this.len)throw a(this,4);return 0|f(this.buf,this.pos+=4)},u.prototype.float=function(){if(this.pos+4>this.len)throw a(this,4);var t=i.float.readFloatLE(this.buf,this.pos);return this.pos+=4,t},u.prototype.double=function(){if(this.pos+8>this.len)throw a(this,4);var t=i.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,t},u.prototype.bytes=function(){var t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw a(this,t);return this.pos+=t,Array.isArray(this.buf)?this.buf.slice(e,n):e===n?new this.buf.constructor(0):this._slice.call(this.buf,e,n)},u.prototype.string=function(){var t=this.bytes();return s.read(t,0,t.length)},u.prototype.skip=function(t){if("number"==typeof t){if(this.pos+t>this.len)throw a(this,t);this.pos+=t}else do{if(this.pos>=this.len)throw a(this)}while(128&this.buf[this.pos++]);return this},u.prototype.skipType=function(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(t=7&this.uint32());)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+t+" at offset "+this.pos)}return this},u._configure=function(t){r=t,u.create=h(),r._configure();var e=i.Long?"toLong":"toNumber";i.merge(u.prototype,{int64:function(){return p.call(this)[e](!1)},uint64:function(){return p.call(this)[e](!0)},sint64:function(){return p.call(this).zzDecode()[e](!1)},fixed64:function(){return m.call(this)[e](!0)},sfixed64:function(){return m.call(this)[e](!1)}})}},function(t,e,n){"use strict";var r,i,o=n(49),s=o.Reader,a=o.Writer,u=o.util,c=o.roots.default||(o.roots.default={});c.tensorflow=((i={}).magenta=((r={}).NoteSequence=function(){function t(t){if(this.timeSignatures=[],this.keySignatures=[],this.tempos=[],this.notes=[],this.pitchBends=[],this.controlChanges=[],this.partInfos=[],this.textAnnotations=[],this.sectionAnnotations=[],this.sectionGroups=[],t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.id=t.string();break;case 2:r.filename=t.string();break;case 18:r.referenceNumber=u.Long?t.int64().toNumber():t.int64();break;case 3:r.collectionName=t.string();break;case 4:r.ticksPerQuarter=t.int32();break;case 5:r.timeSignatures&&r.timeSignatures.length||(r.timeSignatures=[]),r.timeSignatures.push(c.tensorflow.magenta.NoteSequence.TimeSignature.decode(t,t.uint32()));break;case 6:r.keySignatures&&r.keySignatures.length||(r.keySignatures=[]),r.keySignatures.push(c.tensorflow.magenta.NoteSequence.KeySignature.decode(t,t.uint32()));break;case 7:r.tempos&&r.tempos.length||(r.tempos=[]),r.tempos.push(c.tensorflow.magenta.NoteSequence.Tempo.decode(t,t.uint32()));break;case 8:r.notes&&r.notes.length||(r.notes=[]),r.notes.push(c.tensorflow.magenta.NoteSequence.Note.decode(t,t.uint32()));break;case 9:r.totalTime=t.double();break;case 16:r.totalQuantizedSteps=u.Long?t.int64().toNumber():t.int64();break;case 10:r.pitchBends&&r.pitchBends.length||(r.pitchBends=[]),r.pitchBends.push(c.tensorflow.magenta.NoteSequence.PitchBend.decode(t,t.uint32()));break;case 11:r.controlChanges&&r.controlChanges.length||(r.controlChanges=[]),r.controlChanges.push(c.tensorflow.magenta.NoteSequence.ControlChange.decode(t,t.uint32()));break;case 12:r.partInfos&&r.partInfos.length||(r.partInfos=[]),r.partInfos.push(c.tensorflow.magenta.NoteSequence.PartInfo.decode(t,t.uint32()));break;case 13:r.sourceInfo=c.tensorflow.magenta.NoteSequence.SourceInfo.decode(t,t.uint32());break;case 14:r.textAnnotations&&r.textAnnotations.length||(r.textAnnotations=[]),r.textAnnotations.push(c.tensorflow.magenta.NoteSequence.TextAnnotation.decode(t,t.uint32()));break;case 20:r.sectionAnnotations&&r.sectionAnnotations.length||(r.sectionAnnotations=[]),r.sectionAnnotations.push(c.tensorflow.magenta.NoteSequence.SectionAnnotation.decode(t,t.uint32()));break;case 21:r.sectionGroups&&r.sectionGroups.length||(r.sectionGroups=[]),r.sectionGroups.push(c.tensorflow.magenta.NoteSequence.SectionGroup.decode(t,t.uint32()));break;case 15:r.quantizationInfo=c.tensorflow.magenta.NoteSequence.QuantizationInfo.decode(t,t.uint32());break;case 17:r.subsequenceInfo=c.tensorflow.magenta.NoteSequence.SubsequenceInfo.decode(t,t.uint32());break;case 19:r.sequenceMetadata=c.tensorflow.magenta.SequenceMetadata.decode(t,t.uint32());break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.id&&t.hasOwnProperty("id")&&!u.isString(t.id))return"id: string expected";if(null!=t.filename&&t.hasOwnProperty("filename")&&!u.isString(t.filename))return"filename: string expected";if(null!=t.referenceNumber&&t.hasOwnProperty("referenceNumber")&&!(u.isInteger(t.referenceNumber)||t.referenceNumber&&u.isInteger(t.referenceNumber.low)&&u.isInteger(t.referenceNumber.high)))return"referenceNumber: integer|Long expected";if(null!=t.collectionName&&t.hasOwnProperty("collectionName")&&!u.isString(t.collectionName))return"collectionName: string expected";if(null!=t.ticksPerQuarter&&t.hasOwnProperty("ticksPerQuarter")&&!u.isInteger(t.ticksPerQuarter))return"ticksPerQuarter: integer expected";if(null!=t.timeSignatures&&t.hasOwnProperty("timeSignatures")){if(!Array.isArray(t.timeSignatures))return"timeSignatures: array expected";for(var e=0;e>>0,t.referenceNumber.high>>>0).toNumber())),null!=t.collectionName&&(e.collectionName=String(t.collectionName)),null!=t.ticksPerQuarter&&(e.ticksPerQuarter=0|t.ticksPerQuarter),t.timeSignatures){if(!Array.isArray(t.timeSignatures))throw TypeError(".tensorflow.magenta.NoteSequence.timeSignatures: array expected");e.timeSignatures=[];for(var n=0;n>>0,t.totalQuantizedSteps.high>>>0).toNumber())),t.pitchBends){if(!Array.isArray(t.pitchBends))throw TypeError(".tensorflow.magenta.NoteSequence.pitchBends: array expected");for(e.pitchBends=[],n=0;n>>0,t.totalQuantizedSteps.high>>>0).toNumber():t.totalQuantizedSteps),null!=t.subsequenceInfo&&t.hasOwnProperty("subsequenceInfo")&&(n.subsequenceInfo=c.tensorflow.magenta.NoteSequence.SubsequenceInfo.toObject(t.subsequenceInfo,e)),null!=t.referenceNumber&&t.hasOwnProperty("referenceNumber")&&("number"==typeof t.referenceNumber?n.referenceNumber=e.longs===String?String(t.referenceNumber):t.referenceNumber:n.referenceNumber=e.longs===String?u.Long.prototype.toString.call(t.referenceNumber):e.longs===Number?new u.LongBits(t.referenceNumber.low>>>0,t.referenceNumber.high>>>0).toNumber():t.referenceNumber),null!=t.sequenceMetadata&&t.hasOwnProperty("sequenceMetadata")&&(n.sequenceMetadata=c.tensorflow.magenta.SequenceMetadata.toObject(t.sequenceMetadata,e)),t.sectionAnnotations&&t.sectionAnnotations.length)for(n.sectionAnnotations=[],i=0;i>>3){case 1:r.pitch=t.int32();break;case 11:r.pitchName=t.int32();break;case 2:r.velocity=t.int32();break;case 3:r.startTime=t.double();break;case 13:r.quantizedStartStep=u.Long?t.int64().toNumber():t.int64();break;case 4:r.endTime=t.double();break;case 14:r.quantizedEndStep=u.Long?t.int64().toNumber():t.int64();break;case 5:r.numerator=t.int32();break;case 6:r.denominator=t.int32();break;case 7:r.instrument=t.int32();break;case 8:r.program=t.int32();break;case 9:r.isDrum=t.bool();break;case 10:r.part=t.int32();break;case 12:r.voice=t.int32();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.pitch&&t.hasOwnProperty("pitch")&&!u.isInteger(t.pitch))return"pitch: integer expected";if(null!=t.pitchName&&t.hasOwnProperty("pitchName"))switch(t.pitchName){default:return"pitchName: enum value expected";case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:case 24:case 25:case 26:case 27:case 28:case 29:case 30:case 31:case 32:case 33:case 34:case 35:}return null!=t.velocity&&t.hasOwnProperty("velocity")&&!u.isInteger(t.velocity)?"velocity: integer expected":null!=t.startTime&&t.hasOwnProperty("startTime")&&"number"!=typeof t.startTime?"startTime: number expected":null!=t.quantizedStartStep&&t.hasOwnProperty("quantizedStartStep")&&!(u.isInteger(t.quantizedStartStep)||t.quantizedStartStep&&u.isInteger(t.quantizedStartStep.low)&&u.isInteger(t.quantizedStartStep.high))?"quantizedStartStep: integer|Long expected":null!=t.endTime&&t.hasOwnProperty("endTime")&&"number"!=typeof t.endTime?"endTime: number expected":null!=t.quantizedEndStep&&t.hasOwnProperty("quantizedEndStep")&&!(u.isInteger(t.quantizedEndStep)||t.quantizedEndStep&&u.isInteger(t.quantizedEndStep.low)&&u.isInteger(t.quantizedEndStep.high))?"quantizedEndStep: integer|Long expected":null!=t.numerator&&t.hasOwnProperty("numerator")&&!u.isInteger(t.numerator)?"numerator: integer expected":null!=t.denominator&&t.hasOwnProperty("denominator")&&!u.isInteger(t.denominator)?"denominator: integer expected":null!=t.instrument&&t.hasOwnProperty("instrument")&&!u.isInteger(t.instrument)?"instrument: integer expected":null!=t.program&&t.hasOwnProperty("program")&&!u.isInteger(t.program)?"program: integer expected":null!=t.isDrum&&t.hasOwnProperty("isDrum")&&"boolean"!=typeof t.isDrum?"isDrum: boolean expected":null!=t.part&&t.hasOwnProperty("part")&&!u.isInteger(t.part)?"part: integer expected":null!=t.voice&&t.hasOwnProperty("voice")&&!u.isInteger(t.voice)?"voice: integer expected":null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.Note)return t;var e=new c.tensorflow.magenta.NoteSequence.Note;switch(null!=t.pitch&&(e.pitch=0|t.pitch),t.pitchName){case"UNKNOWN_PITCH_NAME":case 0:e.pitchName=0;break;case"F_FLAT_FLAT":case 1:e.pitchName=1;break;case"C_FLAT_FLAT":case 2:e.pitchName=2;break;case"G_FLAT_FLAT":case 3:e.pitchName=3;break;case"D_FLAT_FLAT":case 4:e.pitchName=4;break;case"A_FLAT_FLAT":case 5:e.pitchName=5;break;case"E_FLAT_FLAT":case 6:e.pitchName=6;break;case"B_FLAT_FLAT":case 7:e.pitchName=7;break;case"F_FLAT":case 8:e.pitchName=8;break;case"C_FLAT":case 9:e.pitchName=9;break;case"G_FLAT":case 10:e.pitchName=10;break;case"D_FLAT":case 11:e.pitchName=11;break;case"A_FLAT":case 12:e.pitchName=12;break;case"E_FLAT":case 13:e.pitchName=13;break;case"B_FLAT":case 14:e.pitchName=14;break;case"F":case 15:e.pitchName=15;break;case"C":case 16:e.pitchName=16;break;case"G":case 17:e.pitchName=17;break;case"D":case 18:e.pitchName=18;break;case"A":case 19:e.pitchName=19;break;case"E":case 20:e.pitchName=20;break;case"B":case 21:e.pitchName=21;break;case"F_SHARP":case 22:e.pitchName=22;break;case"C_SHARP":case 23:e.pitchName=23;break;case"G_SHARP":case 24:e.pitchName=24;break;case"D_SHARP":case 25:e.pitchName=25;break;case"A_SHARP":case 26:e.pitchName=26;break;case"E_SHARP":case 27:e.pitchName=27;break;case"B_SHARP":case 28:e.pitchName=28;break;case"F_SHARP_SHARP":case 29:e.pitchName=29;break;case"C_SHARP_SHARP":case 30:e.pitchName=30;break;case"G_SHARP_SHARP":case 31:e.pitchName=31;break;case"D_SHARP_SHARP":case 32:e.pitchName=32;break;case"A_SHARP_SHARP":case 33:e.pitchName=33;break;case"E_SHARP_SHARP":case 34:e.pitchName=34;break;case"B_SHARP_SHARP":case 35:e.pitchName=35}return null!=t.velocity&&(e.velocity=0|t.velocity),null!=t.startTime&&(e.startTime=Number(t.startTime)),null!=t.quantizedStartStep&&(u.Long?(e.quantizedStartStep=u.Long.fromValue(t.quantizedStartStep)).unsigned=!1:"string"==typeof t.quantizedStartStep?e.quantizedStartStep=parseInt(t.quantizedStartStep,10):"number"==typeof t.quantizedStartStep?e.quantizedStartStep=t.quantizedStartStep:"object"==typeof t.quantizedStartStep&&(e.quantizedStartStep=new u.LongBits(t.quantizedStartStep.low>>>0,t.quantizedStartStep.high>>>0).toNumber())),null!=t.endTime&&(e.endTime=Number(t.endTime)),null!=t.quantizedEndStep&&(u.Long?(e.quantizedEndStep=u.Long.fromValue(t.quantizedEndStep)).unsigned=!1:"string"==typeof t.quantizedEndStep?e.quantizedEndStep=parseInt(t.quantizedEndStep,10):"number"==typeof t.quantizedEndStep?e.quantizedEndStep=t.quantizedEndStep:"object"==typeof t.quantizedEndStep&&(e.quantizedEndStep=new u.LongBits(t.quantizedEndStep.low>>>0,t.quantizedEndStep.high>>>0).toNumber())),null!=t.numerator&&(e.numerator=0|t.numerator),null!=t.denominator&&(e.denominator=0|t.denominator),null!=t.instrument&&(e.instrument=0|t.instrument),null!=t.program&&(e.program=0|t.program),null!=t.isDrum&&(e.isDrum=Boolean(t.isDrum)),null!=t.part&&(e.part=0|t.part),null!=t.voice&&(e.voice=0|t.voice),e},t.toObject=function(t,e){e||(e={});var n={};if(e.defaults){if(n.pitch=0,n.velocity=0,n.startTime=0,n.endTime=0,n.numerator=0,n.denominator=0,n.instrument=0,n.program=0,n.isDrum=!1,n.part=0,n.pitchName=e.enums===String?"UNKNOWN_PITCH_NAME":0,n.voice=0,u.Long){var r=new u.Long(0,0,!1);n.quantizedStartStep=e.longs===String?r.toString():e.longs===Number?r.toNumber():r}else n.quantizedStartStep=e.longs===String?"0":0;u.Long?(r=new u.Long(0,0,!1),n.quantizedEndStep=e.longs===String?r.toString():e.longs===Number?r.toNumber():r):n.quantizedEndStep=e.longs===String?"0":0}return null!=t.pitch&&t.hasOwnProperty("pitch")&&(n.pitch=t.pitch),null!=t.velocity&&t.hasOwnProperty("velocity")&&(n.velocity=t.velocity),null!=t.startTime&&t.hasOwnProperty("startTime")&&(n.startTime=e.json&&!isFinite(t.startTime)?String(t.startTime):t.startTime),null!=t.endTime&&t.hasOwnProperty("endTime")&&(n.endTime=e.json&&!isFinite(t.endTime)?String(t.endTime):t.endTime),null!=t.numerator&&t.hasOwnProperty("numerator")&&(n.numerator=t.numerator),null!=t.denominator&&t.hasOwnProperty("denominator")&&(n.denominator=t.denominator),null!=t.instrument&&t.hasOwnProperty("instrument")&&(n.instrument=t.instrument),null!=t.program&&t.hasOwnProperty("program")&&(n.program=t.program),null!=t.isDrum&&t.hasOwnProperty("isDrum")&&(n.isDrum=t.isDrum),null!=t.part&&t.hasOwnProperty("part")&&(n.part=t.part),null!=t.pitchName&&t.hasOwnProperty("pitchName")&&(n.pitchName=e.enums===String?c.tensorflow.magenta.NoteSequence.PitchName[t.pitchName]:t.pitchName),null!=t.voice&&t.hasOwnProperty("voice")&&(n.voice=t.voice),null!=t.quantizedStartStep&&t.hasOwnProperty("quantizedStartStep")&&("number"==typeof t.quantizedStartStep?n.quantizedStartStep=e.longs===String?String(t.quantizedStartStep):t.quantizedStartStep:n.quantizedStartStep=e.longs===String?u.Long.prototype.toString.call(t.quantizedStartStep):e.longs===Number?new u.LongBits(t.quantizedStartStep.low>>>0,t.quantizedStartStep.high>>>0).toNumber():t.quantizedStartStep),null!=t.quantizedEndStep&&t.hasOwnProperty("quantizedEndStep")&&("number"==typeof t.quantizedEndStep?n.quantizedEndStep=e.longs===String?String(t.quantizedEndStep):t.quantizedEndStep:n.quantizedEndStep=e.longs===String?u.Long.prototype.toString.call(t.quantizedEndStep):e.longs===Number?new u.LongBits(t.quantizedEndStep.low>>>0,t.quantizedEndStep.high>>>0).toNumber():t.quantizedEndStep),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),t.PitchName=(e={},(n=Object.create(e))[e[0]="UNKNOWN_PITCH_NAME"]=0,n[e[1]="F_FLAT_FLAT"]=1,n[e[2]="C_FLAT_FLAT"]=2,n[e[3]="G_FLAT_FLAT"]=3,n[e[4]="D_FLAT_FLAT"]=4,n[e[5]="A_FLAT_FLAT"]=5,n[e[6]="E_FLAT_FLAT"]=6,n[e[7]="B_FLAT_FLAT"]=7,n[e[8]="F_FLAT"]=8,n[e[9]="C_FLAT"]=9,n[e[10]="G_FLAT"]=10,n[e[11]="D_FLAT"]=11,n[e[12]="A_FLAT"]=12,n[e[13]="E_FLAT"]=13,n[e[14]="B_FLAT"]=14,n[e[15]="F"]=15,n[e[16]="C"]=16,n[e[17]="G"]=17,n[e[18]="D"]=18,n[e[19]="A"]=19,n[e[20]="E"]=20,n[e[21]="B"]=21,n[e[22]="F_SHARP"]=22,n[e[23]="C_SHARP"]=23,n[e[24]="G_SHARP"]=24,n[e[25]="D_SHARP"]=25,n[e[26]="A_SHARP"]=26,n[e[27]="E_SHARP"]=27,n[e[28]="B_SHARP"]=28,n[e[29]="F_SHARP_SHARP"]=29,n[e[30]="C_SHARP_SHARP"]=30,n[e[31]="G_SHARP_SHARP"]=31,n[e[32]="D_SHARP_SHARP"]=32,n[e[33]="A_SHARP_SHARP"]=33,n[e[34]="E_SHARP_SHARP"]=34,n[e[35]="B_SHARP_SHARP"]=35,n),t.TimeSignature=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.time=t.double();break;case 2:r.numerator=t.int32();break;case 3:r.denominator=t.int32();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.time&&t.hasOwnProperty("time")&&"number"!=typeof t.time?"time: number expected":null!=t.numerator&&t.hasOwnProperty("numerator")&&!u.isInteger(t.numerator)?"numerator: integer expected":null!=t.denominator&&t.hasOwnProperty("denominator")&&!u.isInteger(t.denominator)?"denominator: integer expected":null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.TimeSignature)return t;var e=new c.tensorflow.magenta.NoteSequence.TimeSignature;return null!=t.time&&(e.time=Number(t.time)),null!=t.numerator&&(e.numerator=0|t.numerator),null!=t.denominator&&(e.denominator=0|t.denominator),e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.time=0,n.numerator=0,n.denominator=0),null!=t.time&&t.hasOwnProperty("time")&&(n.time=e.json&&!isFinite(t.time)?String(t.time):t.time),null!=t.numerator&&t.hasOwnProperty("numerator")&&(n.numerator=t.numerator),null!=t.denominator&&t.hasOwnProperty("denominator")&&(n.denominator=t.denominator),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),t.KeySignature=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.time=t.double();break;case 2:r.key=t.int32();break;case 3:r.mode=t.int32();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.time&&t.hasOwnProperty("time")&&"number"!=typeof t.time)return"time: number expected";if(null!=t.key&&t.hasOwnProperty("key"))switch(t.key){default:return"key: enum value expected";case 0:case 1:case 1:case 2:case 3:case 3:case 4:case 5:case 6:case 6:case 7:case 8:case 8:case 9:case 10:case 10:case 11:}if(null!=t.mode&&t.hasOwnProperty("mode"))switch(t.mode){default:return"mode: enum value expected";case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:}return null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.KeySignature)return t;var e=new c.tensorflow.magenta.NoteSequence.KeySignature;switch(null!=t.time&&(e.time=Number(t.time)),t.key){case"C":case 0:e.key=0;break;case"C_SHARP":case 1:e.key=1;break;case"D_FLAT":case 1:e.key=1;break;case"D":case 2:e.key=2;break;case"D_SHARP":case 3:e.key=3;break;case"E_FLAT":case 3:e.key=3;break;case"E":case 4:e.key=4;break;case"F":case 5:e.key=5;break;case"F_SHARP":case 6:e.key=6;break;case"G_FLAT":case 6:e.key=6;break;case"G":case 7:e.key=7;break;case"G_SHARP":case 8:e.key=8;break;case"A_FLAT":case 8:e.key=8;break;case"A":case 9:e.key=9;break;case"A_SHARP":case 10:e.key=10;break;case"B_FLAT":case 10:e.key=10;break;case"B":case 11:e.key=11}switch(t.mode){case"MAJOR":case 0:e.mode=0;break;case"MINOR":case 1:e.mode=1;break;case"NOT_SPECIFIED":case 2:e.mode=2;break;case"MIXOLYDIAN":case 3:e.mode=3;break;case"DORIAN":case 4:e.mode=4;break;case"PHRYGIAN":case 5:e.mode=5;break;case"LYDIAN":case 6:e.mode=6;break;case"LOCRIAN":case 7:e.mode=7}return e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.time=0,n.key=e.enums===String?"C":0,n.mode=e.enums===String?"MAJOR":0),null!=t.time&&t.hasOwnProperty("time")&&(n.time=e.json&&!isFinite(t.time)?String(t.time):t.time),null!=t.key&&t.hasOwnProperty("key")&&(n.key=e.enums===String?c.tensorflow.magenta.NoteSequence.KeySignature.Key[t.key]:t.key),null!=t.mode&&t.hasOwnProperty("mode")&&(n.mode=e.enums===String?c.tensorflow.magenta.NoteSequence.KeySignature.Mode[t.mode]:t.mode),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t.Key=function(){var t={},e=Object.create(t);return e[t[0]="C"]=0,e[t[1]="C_SHARP"]=1,e.D_FLAT=1,e[t[2]="D"]=2,e[t[3]="D_SHARP"]=3,e.E_FLAT=3,e[t[4]="E"]=4,e[t[5]="F"]=5,e[t[6]="F_SHARP"]=6,e.G_FLAT=6,e[t[7]="G"]=7,e[t[8]="G_SHARP"]=8,e.A_FLAT=8,e[t[9]="A"]=9,e[t[10]="A_SHARP"]=10,e.B_FLAT=10,e[t[11]="B"]=11,e}(),t.Mode=function(){var t={},e=Object.create(t);return e[t[0]="MAJOR"]=0,e[t[1]="MINOR"]=1,e[t[2]="NOT_SPECIFIED"]=2,e[t[3]="MIXOLYDIAN"]=3,e[t[4]="DORIAN"]=4,e[t[5]="PHRYGIAN"]=5,e[t[6]="LYDIAN"]=6,e[t[7]="LOCRIAN"]=7,e}(),t}(),t.Tempo=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.time=t.double();break;case 2:r.qpm=t.double();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.time&&t.hasOwnProperty("time")&&"number"!=typeof t.time?"time: number expected":null!=t.qpm&&t.hasOwnProperty("qpm")&&"number"!=typeof t.qpm?"qpm: number expected":null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.Tempo)return t;var e=new c.tensorflow.magenta.NoteSequence.Tempo;return null!=t.time&&(e.time=Number(t.time)),null!=t.qpm&&(e.qpm=Number(t.qpm)),e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.time=0,n.qpm=0),null!=t.time&&t.hasOwnProperty("time")&&(n.time=e.json&&!isFinite(t.time)?String(t.time):t.time),null!=t.qpm&&t.hasOwnProperty("qpm")&&(n.qpm=e.json&&!isFinite(t.qpm)?String(t.qpm):t.qpm),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),t.PitchBend=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.time=t.double();break;case 2:r.bend=t.int32();break;case 3:r.instrument=t.int32();break;case 4:r.program=t.int32();break;case 5:r.isDrum=t.bool();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.time&&t.hasOwnProperty("time")&&"number"!=typeof t.time?"time: number expected":null!=t.bend&&t.hasOwnProperty("bend")&&!u.isInteger(t.bend)?"bend: integer expected":null!=t.instrument&&t.hasOwnProperty("instrument")&&!u.isInteger(t.instrument)?"instrument: integer expected":null!=t.program&&t.hasOwnProperty("program")&&!u.isInteger(t.program)?"program: integer expected":null!=t.isDrum&&t.hasOwnProperty("isDrum")&&"boolean"!=typeof t.isDrum?"isDrum: boolean expected":null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.PitchBend)return t;var e=new c.tensorflow.magenta.NoteSequence.PitchBend;return null!=t.time&&(e.time=Number(t.time)),null!=t.bend&&(e.bend=0|t.bend),null!=t.instrument&&(e.instrument=0|t.instrument),null!=t.program&&(e.program=0|t.program),null!=t.isDrum&&(e.isDrum=Boolean(t.isDrum)),e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.time=0,n.bend=0,n.instrument=0,n.program=0,n.isDrum=!1),null!=t.time&&t.hasOwnProperty("time")&&(n.time=e.json&&!isFinite(t.time)?String(t.time):t.time),null!=t.bend&&t.hasOwnProperty("bend")&&(n.bend=t.bend),null!=t.instrument&&t.hasOwnProperty("instrument")&&(n.instrument=t.instrument),null!=t.program&&t.hasOwnProperty("program")&&(n.program=t.program),null!=t.isDrum&&t.hasOwnProperty("isDrum")&&(n.isDrum=t.isDrum),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),t.ControlChange=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.time=t.double();break;case 7:r.quantizedStep=u.Long?t.int64().toNumber():t.int64();break;case 2:r.controlNumber=t.int32();break;case 3:r.controlValue=t.int32();break;case 4:r.instrument=t.int32();break;case 5:r.program=t.int32();break;case 6:r.isDrum=t.bool();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.time&&t.hasOwnProperty("time")&&"number"!=typeof t.time?"time: number expected":null!=t.quantizedStep&&t.hasOwnProperty("quantizedStep")&&!(u.isInteger(t.quantizedStep)||t.quantizedStep&&u.isInteger(t.quantizedStep.low)&&u.isInteger(t.quantizedStep.high))?"quantizedStep: integer|Long expected":null!=t.controlNumber&&t.hasOwnProperty("controlNumber")&&!u.isInteger(t.controlNumber)?"controlNumber: integer expected":null!=t.controlValue&&t.hasOwnProperty("controlValue")&&!u.isInteger(t.controlValue)?"controlValue: integer expected":null!=t.instrument&&t.hasOwnProperty("instrument")&&!u.isInteger(t.instrument)?"instrument: integer expected":null!=t.program&&t.hasOwnProperty("program")&&!u.isInteger(t.program)?"program: integer expected":null!=t.isDrum&&t.hasOwnProperty("isDrum")&&"boolean"!=typeof t.isDrum?"isDrum: boolean expected":null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.ControlChange)return t;var e=new c.tensorflow.magenta.NoteSequence.ControlChange;return null!=t.time&&(e.time=Number(t.time)),null!=t.quantizedStep&&(u.Long?(e.quantizedStep=u.Long.fromValue(t.quantizedStep)).unsigned=!1:"string"==typeof t.quantizedStep?e.quantizedStep=parseInt(t.quantizedStep,10):"number"==typeof t.quantizedStep?e.quantizedStep=t.quantizedStep:"object"==typeof t.quantizedStep&&(e.quantizedStep=new u.LongBits(t.quantizedStep.low>>>0,t.quantizedStep.high>>>0).toNumber())),null!=t.controlNumber&&(e.controlNumber=0|t.controlNumber),null!=t.controlValue&&(e.controlValue=0|t.controlValue),null!=t.instrument&&(e.instrument=0|t.instrument),null!=t.program&&(e.program=0|t.program),null!=t.isDrum&&(e.isDrum=Boolean(t.isDrum)),e},t.toObject=function(t,e){e||(e={});var n={};if(e.defaults)if(n.time=0,n.controlNumber=0,n.controlValue=0,n.instrument=0,n.program=0,n.isDrum=!1,u.Long){var r=new u.Long(0,0,!1);n.quantizedStep=e.longs===String?r.toString():e.longs===Number?r.toNumber():r}else n.quantizedStep=e.longs===String?"0":0;return null!=t.time&&t.hasOwnProperty("time")&&(n.time=e.json&&!isFinite(t.time)?String(t.time):t.time),null!=t.controlNumber&&t.hasOwnProperty("controlNumber")&&(n.controlNumber=t.controlNumber),null!=t.controlValue&&t.hasOwnProperty("controlValue")&&(n.controlValue=t.controlValue),null!=t.instrument&&t.hasOwnProperty("instrument")&&(n.instrument=t.instrument),null!=t.program&&t.hasOwnProperty("program")&&(n.program=t.program),null!=t.isDrum&&t.hasOwnProperty("isDrum")&&(n.isDrum=t.isDrum),null!=t.quantizedStep&&t.hasOwnProperty("quantizedStep")&&("number"==typeof t.quantizedStep?n.quantizedStep=e.longs===String?String(t.quantizedStep):t.quantizedStep:n.quantizedStep=e.longs===String?u.Long.prototype.toString.call(t.quantizedStep):e.longs===Number?new u.LongBits(t.quantizedStep.low>>>0,t.quantizedStep.high>>>0).toNumber():t.quantizedStep),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),t.PartInfo=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.part=t.int32();break;case 2:r.name=t.string();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.part&&t.hasOwnProperty("part")&&!u.isInteger(t.part)?"part: integer expected":null!=t.name&&t.hasOwnProperty("name")&&!u.isString(t.name)?"name: string expected":null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.PartInfo)return t;var e=new c.tensorflow.magenta.NoteSequence.PartInfo;return null!=t.part&&(e.part=0|t.part),null!=t.name&&(e.name=String(t.name)),e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.part=0,n.name=""),null!=t.part&&t.hasOwnProperty("part")&&(n.part=t.part),null!=t.name&&t.hasOwnProperty("name")&&(n.name=t.name),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),t.SourceInfo=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.sourceType=t.int32();break;case 2:r.encodingType=t.int32();break;case 3:r.parser=t.int32();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.sourceType&&t.hasOwnProperty("sourceType"))switch(t.sourceType){default:return"sourceType: enum value expected";case 0:case 1:case 2:}if(null!=t.encodingType&&t.hasOwnProperty("encodingType"))switch(t.encodingType){default:return"encodingType: enum value expected";case 0:case 1:case 2:case 3:case 4:}if(null!=t.parser&&t.hasOwnProperty("parser"))switch(t.parser){default:return"parser: enum value expected";case 0:case 1:case 2:case 3:case 4:case 5:case 6:}return null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.SourceInfo)return t;var e=new c.tensorflow.magenta.NoteSequence.SourceInfo;switch(t.sourceType){case"UNKNOWN_SOURCE_TYPE":case 0:e.sourceType=0;break;case"SCORE_BASED":case 1:e.sourceType=1;break;case"PERFORMANCE_BASED":case 2:e.sourceType=2}switch(t.encodingType){case"UNKNOWN_ENCODING_TYPE":case 0:e.encodingType=0;break;case"MUSIC_XML":case 1:e.encodingType=1;break;case"ABC":case 2:e.encodingType=2;break;case"MIDI":case 3:e.encodingType=3;break;case"MUSICNET":case 4:e.encodingType=4}switch(t.parser){case"UNKNOWN_PARSER":case 0:e.parser=0;break;case"MUSIC21":case 1:e.parser=1;break;case"PRETTY_MIDI":case 2:e.parser=2;break;case"MAGENTA_MUSIC_XML":case 3:e.parser=3;break;case"MAGENTA_MUSICNET":case 4:e.parser=4;break;case"MAGENTA_ABC":case 5:e.parser=5;break;case"TONEJS_MIDI_CONVERT":case 6:e.parser=6}return e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.sourceType=e.enums===String?"UNKNOWN_SOURCE_TYPE":0,n.encodingType=e.enums===String?"UNKNOWN_ENCODING_TYPE":0,n.parser=e.enums===String?"UNKNOWN_PARSER":0),null!=t.sourceType&&t.hasOwnProperty("sourceType")&&(n.sourceType=e.enums===String?c.tensorflow.magenta.NoteSequence.SourceInfo.SourceType[t.sourceType]:t.sourceType),null!=t.encodingType&&t.hasOwnProperty("encodingType")&&(n.encodingType=e.enums===String?c.tensorflow.magenta.NoteSequence.SourceInfo.EncodingType[t.encodingType]:t.encodingType),null!=t.parser&&t.hasOwnProperty("parser")&&(n.parser=e.enums===String?c.tensorflow.magenta.NoteSequence.SourceInfo.Parser[t.parser]:t.parser),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t.SourceType=function(){var t={},e=Object.create(t);return e[t[0]="UNKNOWN_SOURCE_TYPE"]=0,e[t[1]="SCORE_BASED"]=1,e[t[2]="PERFORMANCE_BASED"]=2,e}(),t.EncodingType=function(){var t={},e=Object.create(t);return e[t[0]="UNKNOWN_ENCODING_TYPE"]=0,e[t[1]="MUSIC_XML"]=1,e[t[2]="ABC"]=2,e[t[3]="MIDI"]=3,e[t[4]="MUSICNET"]=4,e}(),t.Parser=function(){var t={},e=Object.create(t);return e[t[0]="UNKNOWN_PARSER"]=0,e[t[1]="MUSIC21"]=1,e[t[2]="PRETTY_MIDI"]=2,e[t[3]="MAGENTA_MUSIC_XML"]=3,e[t[4]="MAGENTA_MUSICNET"]=4,e[t[5]="MAGENTA_ABC"]=5,e[t[6]="TONEJS_MIDI_CONVERT"]=6,e}(),t}(),t.TextAnnotation=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.time=t.double();break;case 4:r.quantizedStep=u.Long?t.int64().toNumber():t.int64();break;case 2:r.text=t.string();break;case 3:r.annotationType=t.int32();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.time&&t.hasOwnProperty("time")&&"number"!=typeof t.time)return"time: number expected";if(null!=t.quantizedStep&&t.hasOwnProperty("quantizedStep")&&!(u.isInteger(t.quantizedStep)||t.quantizedStep&&u.isInteger(t.quantizedStep.low)&&u.isInteger(t.quantizedStep.high)))return"quantizedStep: integer|Long expected";if(null!=t.text&&t.hasOwnProperty("text")&&!u.isString(t.text))return"text: string expected";if(null!=t.annotationType&&t.hasOwnProperty("annotationType"))switch(t.annotationType){default:return"annotationType: enum value expected";case 0:case 1:case 2:}return null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.TextAnnotation)return t;var e=new c.tensorflow.magenta.NoteSequence.TextAnnotation;switch(null!=t.time&&(e.time=Number(t.time)),null!=t.quantizedStep&&(u.Long?(e.quantizedStep=u.Long.fromValue(t.quantizedStep)).unsigned=!1:"string"==typeof t.quantizedStep?e.quantizedStep=parseInt(t.quantizedStep,10):"number"==typeof t.quantizedStep?e.quantizedStep=t.quantizedStep:"object"==typeof t.quantizedStep&&(e.quantizedStep=new u.LongBits(t.quantizedStep.low>>>0,t.quantizedStep.high>>>0).toNumber())),null!=t.text&&(e.text=String(t.text)),t.annotationType){case"UNKNOWN":case 0:e.annotationType=0;break;case"CHORD_SYMBOL":case 1:e.annotationType=1;break;case"BEAT":case 2:e.annotationType=2}return e},t.toObject=function(t,e){e||(e={});var n={};if(e.defaults)if(n.time=0,n.text="",n.annotationType=e.enums===String?"UNKNOWN":0,u.Long){var r=new u.Long(0,0,!1);n.quantizedStep=e.longs===String?r.toString():e.longs===Number?r.toNumber():r}else n.quantizedStep=e.longs===String?"0":0;return null!=t.time&&t.hasOwnProperty("time")&&(n.time=e.json&&!isFinite(t.time)?String(t.time):t.time),null!=t.text&&t.hasOwnProperty("text")&&(n.text=t.text),null!=t.annotationType&&t.hasOwnProperty("annotationType")&&(n.annotationType=e.enums===String?c.tensorflow.magenta.NoteSequence.TextAnnotation.TextAnnotationType[t.annotationType]:t.annotationType),null!=t.quantizedStep&&t.hasOwnProperty("quantizedStep")&&("number"==typeof t.quantizedStep?n.quantizedStep=e.longs===String?String(t.quantizedStep):t.quantizedStep:n.quantizedStep=e.longs===String?u.Long.prototype.toString.call(t.quantizedStep):e.longs===Number?new u.LongBits(t.quantizedStep.low>>>0,t.quantizedStep.high>>>0).toNumber():t.quantizedStep),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t.TextAnnotationType=function(){var t={},e=Object.create(t);return e[t[0]="UNKNOWN"]=0,e[t[1]="CHORD_SYMBOL"]=1,e[t[2]="BEAT"]=2,e}(),t}(),t.QuantizationInfo=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.stepsPerQuarter=t.int32();break;case 2:r.stepsPerSecond=t.int32();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";var e={};if(null!=t.stepsPerQuarter&&t.hasOwnProperty("stepsPerQuarter")&&(e.resolution=1,!u.isInteger(t.stepsPerQuarter)))return"stepsPerQuarter: integer expected";if(null!=t.stepsPerSecond&&t.hasOwnProperty("stepsPerSecond")){if(1===e.resolution)return"resolution: multiple values";if(e.resolution=1,!u.isInteger(t.stepsPerSecond))return"stepsPerSecond: integer expected"}return null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.QuantizationInfo)return t;var e=new c.tensorflow.magenta.NoteSequence.QuantizationInfo;return null!=t.stepsPerQuarter&&(e.stepsPerQuarter=0|t.stepsPerQuarter),null!=t.stepsPerSecond&&(e.stepsPerSecond=0|t.stepsPerSecond),e},t.toObject=function(t,e){e||(e={});var n={};return null!=t.stepsPerQuarter&&t.hasOwnProperty("stepsPerQuarter")&&(n.stepsPerQuarter=t.stepsPerQuarter,e.oneofs&&(n.resolution="stepsPerQuarter")),null!=t.stepsPerSecond&&t.hasOwnProperty("stepsPerSecond")&&(n.stepsPerSecond=t.stepsPerSecond,e.oneofs&&(n.resolution="stepsPerSecond")),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),t.SubsequenceInfo=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.startTimeOffset=t.double();break;case 2:r.endTimeOffset=t.double();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.startTimeOffset&&t.hasOwnProperty("startTimeOffset")&&"number"!=typeof t.startTimeOffset?"startTimeOffset: number expected":null!=t.endTimeOffset&&t.hasOwnProperty("endTimeOffset")&&"number"!=typeof t.endTimeOffset?"endTimeOffset: number expected":null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.SubsequenceInfo)return t;var e=new c.tensorflow.magenta.NoteSequence.SubsequenceInfo;return null!=t.startTimeOffset&&(e.startTimeOffset=Number(t.startTimeOffset)),null!=t.endTimeOffset&&(e.endTimeOffset=Number(t.endTimeOffset)),e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.startTimeOffset=0,n.endTimeOffset=0),null!=t.startTimeOffset&&t.hasOwnProperty("startTimeOffset")&&(n.startTimeOffset=e.json&&!isFinite(t.startTimeOffset)?String(t.startTimeOffset):t.startTimeOffset),null!=t.endTimeOffset&&t.hasOwnProperty("endTimeOffset")&&(n.endTimeOffset=e.json&&!isFinite(t.endTimeOffset)?String(t.endTimeOffset):t.endTimeOffset),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),t.SectionAnnotation=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.time=t.double();break;case 4:r.sectionId=u.Long?t.int64().toNumber():t.int64();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.time&&t.hasOwnProperty("time")&&"number"!=typeof t.time?"time: number expected":null!=t.sectionId&&t.hasOwnProperty("sectionId")&&!(u.isInteger(t.sectionId)||t.sectionId&&u.isInteger(t.sectionId.low)&&u.isInteger(t.sectionId.high))?"sectionId: integer|Long expected":null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.SectionAnnotation)return t;var e=new c.tensorflow.magenta.NoteSequence.SectionAnnotation;return null!=t.time&&(e.time=Number(t.time)),null!=t.sectionId&&(u.Long?(e.sectionId=u.Long.fromValue(t.sectionId)).unsigned=!1:"string"==typeof t.sectionId?e.sectionId=parseInt(t.sectionId,10):"number"==typeof t.sectionId?e.sectionId=t.sectionId:"object"==typeof t.sectionId&&(e.sectionId=new u.LongBits(t.sectionId.low>>>0,t.sectionId.high>>>0).toNumber())),e},t.toObject=function(t,e){e||(e={});var n={};if(e.defaults)if(n.time=0,u.Long){var r=new u.Long(0,0,!1);n.sectionId=e.longs===String?r.toString():e.longs===Number?r.toNumber():r}else n.sectionId=e.longs===String?"0":0;return null!=t.time&&t.hasOwnProperty("time")&&(n.time=e.json&&!isFinite(t.time)?String(t.time):t.time),null!=t.sectionId&&t.hasOwnProperty("sectionId")&&("number"==typeof t.sectionId?n.sectionId=e.longs===String?String(t.sectionId):t.sectionId:n.sectionId=e.longs===String?u.Long.prototype.toString.call(t.sectionId):e.longs===Number?new u.LongBits(t.sectionId.low>>>0,t.sectionId.high>>>0).toNumber():t.sectionId),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),t.Section=function(){function t(t){if(t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.sectionId=u.Long?t.int64().toNumber():t.int64();break;case 2:r.sectionGroup=c.tensorflow.magenta.NoteSequence.SectionGroup.decode(t,t.uint32());break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";var e={};if(null!=t.sectionId&&t.hasOwnProperty("sectionId")&&(e.sectionType=1,!(u.isInteger(t.sectionId)||t.sectionId&&u.isInteger(t.sectionId.low)&&u.isInteger(t.sectionId.high))))return"sectionId: integer|Long expected";if(null!=t.sectionGroup&&t.hasOwnProperty("sectionGroup")){if(1===e.sectionType)return"sectionType: multiple values";e.sectionType=1;var n=c.tensorflow.magenta.NoteSequence.SectionGroup.verify(t.sectionGroup);if(n)return"sectionGroup."+n}return null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.NoteSequence.Section)return t;var e=new c.tensorflow.magenta.NoteSequence.Section;if(null!=t.sectionId&&(u.Long?(e.sectionId=u.Long.fromValue(t.sectionId)).unsigned=!1:"string"==typeof t.sectionId?e.sectionId=parseInt(t.sectionId,10):"number"==typeof t.sectionId?e.sectionId=t.sectionId:"object"==typeof t.sectionId&&(e.sectionId=new u.LongBits(t.sectionId.low>>>0,t.sectionId.high>>>0).toNumber())),null!=t.sectionGroup){if("object"!=typeof t.sectionGroup)throw TypeError(".tensorflow.magenta.NoteSequence.Section.sectionGroup: object expected");e.sectionGroup=c.tensorflow.magenta.NoteSequence.SectionGroup.fromObject(t.sectionGroup)}return e},t.toObject=function(t,e){e||(e={});var n={};return null!=t.sectionId&&t.hasOwnProperty("sectionId")&&("number"==typeof t.sectionId?n.sectionId=e.longs===String?String(t.sectionId):t.sectionId:n.sectionId=e.longs===String?u.Long.prototype.toString.call(t.sectionId):e.longs===Number?new u.LongBits(t.sectionId.low>>>0,t.sectionId.high>>>0).toNumber():t.sectionId,e.oneofs&&(n.sectionType="sectionId")),null!=t.sectionGroup&&t.hasOwnProperty("sectionGroup")&&(n.sectionGroup=c.tensorflow.magenta.NoteSequence.SectionGroup.toObject(t.sectionGroup,e),e.oneofs&&(n.sectionType="sectionGroup")),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),t.SectionGroup=function(){function t(t){if(this.sections=[],t)for(var e=Object.keys(t),n=0;n>>3){case 1:r.sections&&r.sections.length||(r.sections=[]),r.sections.push(c.tensorflow.magenta.NoteSequence.Section.decode(t,t.uint32()));break;case 2:r.numTimes=t.int32();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.sections&&t.hasOwnProperty("sections")){if(!Array.isArray(t.sections))return"sections: array expected";for(var e=0;e>>3){case 1:r.title=t.string();break;case 2:r.artist=t.string();break;case 3:r.genre&&r.genre.length||(r.genre=[]),r.genre.push(t.string());break;case 4:r.composers&&r.composers.length||(r.composers=[]),r.composers.push(t.string());break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){if("object"!=typeof t||null===t)return"object expected";if(null!=t.title&&t.hasOwnProperty("title")&&!u.isString(t.title))return"title: string expected";if(null!=t.artist&&t.hasOwnProperty("artist")&&!u.isString(t.artist))return"artist: string expected";if(null!=t.genre&&t.hasOwnProperty("genre")){if(!Array.isArray(t.genre))return"genre: array expected";for(var e=0;e>>3){case 1:r.min=t.int32();break;case 2:r.max=t.int32();break;default:t.skipType(7&i)}}return r},t.decodeDelimited=function(t){return t instanceof s||(t=new s(t)),this.decode(t,t.uint32())},t.verify=function(t){return"object"!=typeof t||null===t?"object expected":null!=t.min&&t.hasOwnProperty("min")&&!u.isInteger(t.min)?"min: integer expected":null!=t.max&&t.hasOwnProperty("max")&&!u.isInteger(t.max)?"max: integer expected":null},t.fromObject=function(t){if(t instanceof c.tensorflow.magenta.VelocityRange)return t;var e=new c.tensorflow.magenta.VelocityRange;return null!=t.min&&(e.min=0|t.min),null!=t.max&&(e.max=0|t.max),e},t.toObject=function(t,e){e||(e={});var n={};return e.defaults&&(n.min=0,n.max=0),null!=t.min&&t.hasOwnProperty("min")&&(n.min=t.min),null!=t.max&&t.hasOwnProperty("max")&&(n.max=t.max),n},t.prototype.toJSON=function(){return this.constructor.toObject(this,o.util.toJSONOptions)},t}(),r),i),t.exports=c},function(t,e,n){"use strict";n.r(e),n.d(e,"converterFromSpec",(function(){return l})),n.d(e,"DataConverter",(function(){return h})),n.d(e,"DrumsConverter",(function(){return p})),n.d(e,"DrumRollConverter",(function(){return f})),n.d(e,"DrumsOneHotConverter",(function(){return m})),n.d(e,"MelodyConverter",(function(){return d})),n.d(e,"MelodyRhythmConverter",(function(){return S})),n.d(e,"MelodyShapeConverter",(function(){return y})),n.d(e,"TrioConverter",(function(){return b})),n.d(e,"TrioRhythmConverter",(function(){return w})),n.d(e,"MultitrackConverter",(function(){return P})),n.d(e,"GrooveConverter",(function(){return v}));var r=n(2),i=n(10),o=n(8);n.d(e,"DEFAULT_DRUM_PITCH_CLASSES",(function(){return o.DEFAULT_DRUM_PITCH_CLASSES}));var s=n(12),a=n(23),u=n(29),c=n(13);function l(t){switch(t.type){case"MelodyConverter":return new d(t.args);case"MelodyRhythmConverter":return new S(t.args);case"MelodyShapeConverter":return new y(t.args);case"DrumsConverter":return new p(t.args);case"DrumRollConverter":return new f(t.args);case"TrioConverter":return new b(t.args);case"TrioRhythmConverter":return new w(t.args);case"DrumsOneHotConverter":return new m(t.args);case"MultitrackConverter":return new P(t.args);case"GrooveConverter":return new v(t.args);default:throw new Error("Unknown DataConverter type: "+t)}}class h{constructor(t){this.NUM_SPLITS=0,this.SEGMENTED_BY_TRACK=!1,this.numSteps=t.numSteps,this.numSegments=t.numSegments}tensorSteps(t){return r.scalar(t.shape[0],"int32")}}class p extends h{constructor(t){super(t),this.pitchClasses=t.pitchClasses||o.DEFAULT_DRUM_PITCH_CLASSES,this.pitchToClass=new Map;for(let t=0;t{this.pitchToClass.set(e,t)});this.depth=this.pitchClasses.length+1}toTensor(t){c.assertIsQuantizedSequence(t);const e=this.numSteps||t.totalQuantizedSteps,n=r.buffer([e,this.pitchClasses.length+1],"int32");for(let t=0;t{n.set(1,t.quantizedStartStep,this.pitchToClass.get(t.pitch)),n.set(0,t.quantizedStartStep,-1)}),n.toTensor()}async toNoteSequence(t,e,n){const r=c.createQuantizedNoteSequence(e,n),o=t.argMax(1),s=await o.data();o.dispose();for(let t=0;t>e&1&&r.notes.push(i.a.Note.create({pitch:this.pitchClasses[e][0],quantizedStartStep:t,quantizedEndStep:t+1,isDrum:!0}));return r.totalQuantizedSteps=s.length,r}}class f extends p{async toNoteSequence(t,e,n){const r=c.createQuantizedNoteSequence(e,n),o=await t.data();for(let e=0;er.oneHot(r.tensor1d(n,"int32"),this.depth))}}class d extends h{constructor(t){super(t),this.NOTE_OFF=1,this.FIRST_PITCH=2,this.minPitch=t.minPitch,this.maxPitch=t.maxPitch,this.ignorePolyphony=t.ignorePolyphony,this.depth=t.maxPitch-t.minPitch+1+this.FIRST_PITCH}toTensor(t){const e=a.Melody.fromNoteSequence(t,this.minPitch,this.maxPitch,this.ignorePolyphony,this.numSteps);return r.tidy(()=>r.oneHot(r.tensor(e.events,[e.events.length],"int32"),this.depth))}async toNoteSequence(t,e,n){const r=t.argMax(1),i=await r.data();r.dispose();return new a.Melody(i,this.minPitch,this.maxPitch).toNoteSequence(e,n)}}class g extends h{constructor(t,e){super(t),this.minPitch=t.minPitch,this.maxPitch=t.maxPitch,this.ignorePolyphony=t.ignorePolyphony,this.melodyControl=e,this.depth=e.depth}toTensor(t){const e=a.Melody.fromNoteSequence(t,this.minPitch,this.maxPitch,this.ignorePolyphony,this.numSteps);return this.melodyControl.extract(e)}}class S extends g{constructor(t){super(t,new a.MelodyRhythm)}async toNoteSequence(t,e,n){const r=c.createQuantizedNoteSequence(e,n),s=await t.data();for(let t=0;tthis.maxPitch&&(u=this.maxPitch,s.log("Pitch range exceeded when creating NoteSequence from shape.","MelodyShapeConverter"))}r.notes.push(i.a.Note.create({pitch:u,quantizedStartStep:t,quantizedEndStep:t+1}))}return r.totalQuantizedSteps=a.length,r}}class b extends h{constructor(t){super(t),this.NUM_SPLITS=3,this.MEL_PROG_RANGE=[0,31],this.BASS_PROG_RANGE=[32,39],t.melArgs.numSteps=t.numSteps,t.bassArgs.numSteps=t.numSteps,t.drumsArgs.numSteps=t.numSteps,this.melConverter=new d(t.melArgs),this.bassConverter=new d(t.bassArgs),this.drumsConverter=new m(t.drumsArgs),this.depth=this.melConverter.depth+this.bassConverter.depth+this.drumsConverter.depth}toTensor(t){c.assertIsQuantizedSequence(t);const e=c.clone(t),n=c.clone(t),i=c.clone(t);return e.notes=t.notes.filter(t=>!t.isDrum&&t.program>=this.MEL_PROG_RANGE[0]&&t.program<=this.MEL_PROG_RANGE[1]),n.notes=t.notes.filter(t=>!t.isDrum&&t.program>=this.BASS_PROG_RANGE[0]&&t.program<=this.BASS_PROG_RANGE[1]),i.notes=t.notes.filter(t=>t.isDrum),r.tidy(()=>r.concat([this.melConverter.toTensor(e),this.bassConverter.toTensor(n),this.drumsConverter.toTensor(i)],-1))}async toNoteSequence(t,e,n){const i=r.split(t,[this.melConverter.depth,this.bassConverter.depth,this.drumsConverter.depth],-1),o=await this.melConverter.toNoteSequence(i[0],e,n);o.notes.forEach(t=>{t.instrument=0,t.program=0});const s=await this.bassConverter.toNoteSequence(i[1],e,n);o.notes.push(...s.notes.map(t=>(t.instrument=1,t.program=this.BASS_PROG_RANGE[0],t)));const a=await this.drumsConverter.toNoteSequence(i[2],e,n);return o.notes.push(...a.notes.map(t=>(t.instrument=2,t))),i.forEach(t=>t.dispose()),o}}class w extends h{constructor(t){super(t),this.NUM_SPLITS=3,this.trioConverter=new b(t),this.depth=3}toTensor(t){return r.tidy(()=>{const e=this.trioConverter.toTensor(t),n=r.split(e,[this.trioConverter.melConverter.depth,this.trioConverter.bassConverter.depth,this.trioConverter.drumsConverter.depth],1),i=r.argMax(n[0],1),o=r.argMax(n[1],1),s=r.argMax(n[2],1),a=r.greater(i,1),u=r.greater(o,1),c=r.greater(s,0);return r.stack([a,u,c],1)})}async toNoteSequence(t,e,n){const s=r.split(t,3,1),a=await Promise.all(s.map(t=>t.data())),u=c.createQuantizedNoteSequence(e,n);for(let t=0;tr.oneHot(r.tensor1d([this.endToken],"int32"),this.depth).as1D())}trackToTensor(t){const e=this.numSteps/this.numSegments;let n=void 0;if(t){for(;t.events.length>e-2;)t.events.pop();n=r.buffer([t.events.length+2],"int32"),n.set(this.performanceEventDepth+(t.isDrum?this.numPrograms-1:t.program),0),t.events.forEach((t,e)=>{switch(t.type){case"note-on":n.set(t.pitch-this.minPitch,e+1);break;case"note-off":n.set(this.numPitches+t.pitch-this.minPitch,e+1);break;case"time-shift":n.set(2*this.numPitches+t.steps-1,e+1);break;case"velocity-change":n.set(2*this.numPitches+this.totalSteps+t.velocityBin-1,e+1);break;default:throw new Error("Unrecognized performance event: "+t)}}),n.set(this.endToken,t.events.length+1)}else n=r.buffer([1],"int32",new Int32Array([this.endToken]));return r.tidy(()=>{const t=r.oneHot(n.toTensor(),this.depth);return t.pad([[0,e-t.shape[0]],[0,0]])})}toTensor(t){if(c.assertIsRelativeQuantizedSequence(t),t.quantizationInfo.stepsPerQuarter!==this.stepsPerQuarter)throw new Error(`Steps per quarter note mismatch: ${t.quantizationInfo.stepsPerQuarter} != ${this.stepsPerQuarter}`);const e=c.clone(t);e.notes=t.notes.filter(t=>t.pitch>=this.minPitch&&t.pitch<=this.maxPitch);const n=new Set(e.notes.map(t=>t.instrument)),i=Array.from(n).map(t=>u.Performance.fromNoteSequence(e,this.totalSteps,this.numVelocityBins,t)).sort((t,e)=>e.isDrum?-1:t.isDrum?1:t.program-e.program);for(;i.length>this.numSegments;)i.pop();for(i.forEach(t=>t.setNumSteps(this.totalSteps));i.lengthr.concat(i.map(t=>this.trackToTensor(t)),0))}tokensToTrack(t){const e=t.indexOf(this.endToken),n=e>=0?e:t.length,r=t.slice(0,n),i=r.filter(t=>tt>=this.performanceEventDepth),[s,a]=o.length?o[0]-this.performanceEventDepth{if(tr.split(t.argMax(1),this.numSegments));return(await Promise.all(o.map(async t=>{const e=await t.data(),n=this.tokensToTrack(e);return t.dispose(),n}))).forEach((t,e)=>{t.setNumSteps(this.totalSteps),i.notes.push(...t.toNoteSequence(e).notes)}),i}}class v extends h{constructor(t){super(t),this.TAPIFY_CHANNEL=3,this.stepsPerQuarter=t.stepsPerQuarter||o.DEFAULT_STEPS_PER_QUARTER,this.pitchClasses=t.pitchClasses||o.DEFAULT_DRUM_PITCH_CLASSES,this.pitchToClass=new Map;for(let t=0;t{this.pitchToClass.set(e,t)});this.humanize=t.humanize||!1,this.tapify=t.tapify||!1,this.splitInstruments=t.splitInstruments||!1,this.depth=3}toTensor(t){const e=c.isRelativeQuantizedSequence(t)?t:c.quantizeNoteSequence(t,this.stepsPerQuarter),n=this.numSteps,i=e.tempos&&e.tempos.length?e.tempos[0].qpm:o.DEFAULT_QUARTERS_PER_MINUTE,s=60/i/this.stepsPerQuarter,a=[];for(let t=0;t{if(!this.tapify&&!this.pitchToClass.has(t.pitch))return;const e=t.quantizedStartStep;if(e>=a.length)throw Error(`Model does not support sequences with more than ${n} steps (${n*s} seconds at qpm ${i}).`);const r=this.tapify?this.TAPIFY_CHANNEL:this.pitchToClass.get(t.pitch);(!a[e].has(r)||a[e].get(r).velocity{const t=l.toTensor(),e=h.toTensor(),i=p.toTensor(),o=this.splitInstruments?n*u:n;return r.concat([t.as2D(o,-1),e.as2D(o,-1),i.as2D(o,-1)],1)})}async toNoteSequence(t,e,n=o.DEFAULT_QUARTERS_PER_MINUTE){if(e&&e!==this.stepsPerQuarter)throw Error("`stepsPerQuarter` is set by the model.");e=this.stepsPerQuarter;const r=this.splitInstruments?t.shape[0]/this.pitchClasses.length:t.shape[0],s=60/n/this.stepsPerQuarter,a=i.a.create({totalTime:r*s,tempos:[{qpm:n}]}),u=await t.data();function c(t,e,n){return Math.min(Math.max(t,e),n)}const l=this.pitchClasses.length;for(let t=0;t.5){const e=c(Math.round(u*o.MAX_MIDI_VELOCITY),o.MIN_MIDI_VELOCITY,o.MAX_MIDI_VELOCITY),r=c(h/2,-.5,.5);a.notes.push(i.a.Note.create({pitch:this.pitchClasses[n][0],startTime:(t-r)*s,endTime:(t-r+1)*s,velocity:e,isDrum:!0}))}}}return a}}},function(t,e,n){"use strict";n.r(e),n.d(e,"ChordQuality",(function(){return vt})),n.d(e,"ChordSymbolException",(function(){return Nt})),n.d(e,"ChordEncodingException",(function(){return Tt})),n.d(e,"ChordSymbols",(function(){return Ot})),n.d(e,"ChordEncoder",(function(){return It})),n.d(e,"chordEncoderFromType",(function(){return Mt})),n.d(e,"MajorMinorChordEncoder",(function(){return At})),n.d(e,"TriadChordEncoder",(function(){return kt})),n.d(e,"PitchChordEncoder",(function(){return qt}));var r={};n.r(r),n.d(r,"names",(function(){return a})),n.d(r,"tokenize",(function(){return h})),n.d(r,"props",(function(){return m})),n.d(r,"name",(function(){return d})),n.d(r,"pc",(function(){return g})),n.d(r,"midi",(function(){return S})),n.d(r,"midiToFreq",(function(){return y})),n.d(r,"freq",(function(){return b})),n.d(r,"freqToMidi",(function(){return v})),n.d(r,"chroma",(function(){return N})),n.d(r,"oct",(function(){return T})),n.d(r,"stepToLetter",(function(){return O})),n.d(r,"altToAcc",(function(){return M})),n.d(r,"from",(function(){return A})),n.d(r,"build",(function(){return k})),n.d(r,"fromMidi",(function(){return q})),n.d(r,"simplify",(function(){return E})),n.d(r,"enharmonic",(function(){return _}));var i={};n.r(i),n.d(i,"names",(function(){return lt})),n.d(i,"props",(function(){return pt})),n.d(i,"intervals",(function(){return ft})),n.d(i,"notes",(function(){return mt})),n.d(i,"exists",(function(){return dt})),n.d(i,"supersets",(function(){return gt})),n.d(i,"subsets",(function(){return St})),n.d(i,"tokenize",(function(){return bt}));var o=n(2),s="C C# Db D D# Eb E F F# Gb G G# Ab A A# Bb B".split(" "),a=function(t){return"string"!=typeof t?s.slice():s.filter((function(e){var n=e[1]||" ";return-1!==t.indexOf(n)}))},u=a(" #"),c=a(" b"),l=/^([a-gA-G]?)(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)$/;function h(t){"string"!=typeof t&&(t="");var e=l.exec(t);return[e[1].toUpperCase(),e[2].replace(/x/g,"##"),e[3],e[4]]}var p=Object.freeze({pc:null,name:null,step:null,alt:null,oct:null,octStr:null,chroma:null,midi:null,freq:null}),f=[0,2,4,5,7,9,11],m=function(t,e){return void 0===e&&(e={}),function(n){return e[n]||(e[n]=t(n))}}((function(t){var e=h(t);if(""===e[0]||""!==e[3])return p;var n=e[0],r=e[1],i=e[2],o={letter:n,acc:r,octStr:i,pc:n+r,name:n+r+i,step:(n.charCodeAt(0)+3)%7,alt:"b"===r[0]?-r.length:r.length,oct:i.length?+i:null,chroma:0,midi:null,freq:null};return o.chroma=(f[o.step]+o.alt+120)%12,o.midi=null!==o.oct?f[o.step]+o.alt+12*(o.oct+1):null,o.freq=y(o.midi),Object.freeze(o)})),d=function(t){return m(t).name},g=function(t){return m(t).pc},S=function(t){if("number"!=typeof t&&"string"!=typeof t)return null;var e,n=m(t).midi,r=n||0===n?n:+t;return(e=r)>=0&&e<=127?r:null},y=function(t,e){return void 0===e&&(e=440),"number"==typeof t?Math.pow(2,(t-69)/12)*e:null},b=function(t){return m(t).freq||y(t)},w=Math.log(2),P=Math.log(440),v=function(t){var e=12*(Math.log(t)-P)/w+69;return Math.round(100*e)/100},N=function(t){return m(t).chroma},T=function(t){return m(t).oct},O=function(t){return"CDEFGAB"[t]},I=function(t,e){return Array(e+1).join(t)},M=function(t){return function(t,e){return"number"!=typeof t?"":e(t)}(t,(function(t){return t<0?I("b",-t):I("#",t)}))},A=function(t,e){void 0===t&&(t={}),void 0===e&&(e=null);var n=e?Object.assign({},m(e),t):t,r=n.step,i=n.alt,o=n.oct;if("number"!=typeof r)return null;var s=O(r);if(!s)return null;var a=s+M(i);return o||0===o?a+o:a},k=A;function q(t,e){return void 0===e&&(e=!1),t=Math.round(t),(!0===e?u:c)[t%12]+(Math.floor(t/12)-1)}var E=function(t,e){void 0===e&&(e=!0);var n=m(t),r=n.alt,i=n.chroma,o=n.midi;if(null===i)return null;var s=!1===e?r<0:r>0;return null===o?g(q(i,s)):q(o,s)},_=function(t){return E(t,!1)};var C=new RegExp("^([-+]?\\d+)(d{1,4}|m|M|P|A{1,4})|(AA|A|P|M|m|d|dd)([-+]?\\d+)$"),x=[0,2,4,5,7,9,11],z=("1P 2m 2M 3m 3M 4P 5P 6m 6M 7m 7M 8P".split(" "),Object.freeze({name:null,num:null,q:null,step:null,alt:null,dir:null,type:null,simple:null,semitones:null,chroma:null,oct:null})),D=function(t){return(Math.abs(t)-1)%7},j=function(t){var e=function(t){var e=C.exec(""+t);return null===e?null:e[1]?[e[1],e[2]]:[e[4],e[3]]}(t);if(null===e)return z;var n,r,i={num:0,q:"d",name:"",type:"M",step:0,dir:-1,simple:1,alt:0,oct:0,semitones:0,chroma:0,ic:0};return i.num=+e[0],i.q=e[1],i.step=D(i.num),i.type="PMMPPMM"[i.step],"M"===i.type&&"P"===i.q?z:(i.name=""+i.num+i.q,i.dir=i.num<0?-1:1,i.simple=8===i.num||-8===i.num?i.num:i.dir*(i.step+1),i.alt=(n=i.type,"M"===(r=i.q)&&"M"===n||"P"===r&&"P"===n?0:"m"===r&&"M"===n?-1:/^A+$/.test(r)?r.length:/^d+$/.test(r)?"P"===n?-r.length:-r.length-1:null),i.oct=Math.floor((Math.abs(i.num)-1)/7),i.semitones=i.dir*(x[i.step]+i.alt+12*i.oct),i.chroma=(i.dir*(x[i.step]+i.alt)%12+12)%12,Object.freeze(i))},L={};function R(t){return"string"!=typeof t?z:L[t]||(L[t]=j(t))}"P m M m M P d P m M m M".split(" ");var B=[0,2,4,-1,1,3,5],U=B.map((function(t){return Math.floor(7*t/12)})),G=[3,0,4,1,5,2,6];var F=function(t,e,n){var r=G[function(t){var e=(t+1)%7;return e<0?7+e:e}(t)],i=Math.floor((t+1)/7);return void 0===e?{step:r,alt:i,dir:n}:{step:r,alt:i,oct:e+4*i+U[r],dir:n}},V=function(t){return function(t,e){return void 0===e&&(e={}),function(n){return e[n]||(e[n]=t(n))}}((function(e){var n=t(e);return null===n.name?null:function(t){var e=t.step,n=t.alt,r=t.oct,i=t.dir;void 0===i&&(i=1);var o=B[e]+7*n;return null===r?[i*o]:[i*o,i*(r-U[e]-4*n)]}(n)}))},H=V(m),Q=V(R);function $(t,e){if(1===arguments.length)return function(e){return $(t,e)};var n=H(t),r=Q(e);if(null===n||null===r)return null;var i=1===n.length?[n[0]+r[0]]:[n[0]+r[0],n[1]+r[1]];return k(F(i[0],i[1]))}var K=n(64),W=n(65),J=function(t){return N(t)||function(t){return R(t).chroma}(t)||0},Y=function(t){return parseInt(X(t),2)};function X(t){if(tt(t))return t;if(!Array.isArray(t))return"";var e=[0,0,0,0,0,0,0,0,0,0,0,0];return t.map(J).forEach((function(t){e[t]=1})),e.join("")}var Z=/^[01]{12}$/;function tt(t){return Z.test(t)}"1P 2m 2M 3m 3M 4P 5d 5P 6m 6M 7m 7M".split(" ");function et(t,e){return arguments.length>1?et(t)(e):(t=Y(t),function(e){return(e=Y(e))!==t&&(e&t)===e})}function nt(t,e){return arguments.length>1?nt(t)(e):(t=Y(t),function(e){return(e=Y(e))!==t&&(e|t)===e})}var rt,it,ot,st=function(t){var e=Object.keys(t).sort(),n=[],r=[],i=function(t,e,i){n[t]=e,r[i]=r[i]||[],r[i].push(t)};e.forEach((function(e){var n=t[e][0].split(" "),r=t[e][1],o=X(n);i(e,n,o),r&&r.forEach((function(t){return i(t,n,o)}))}));var o=Object.keys(n).sort(),s=function(t){return n[t]};return s.names=function(t){return"string"==typeof t?(r[t]||[]).slice():(!0===t?o:e).slice()},s},at=st(K),ut=st(W),ct=(rt=at,it=ut,(ot=function(t){return rt(t)||it(t)}).names=function(t){return rt.names(t).concat(it.names(t))},Object.freeze({name:null,intervals:[],names:[],chroma:null,setnum:null}));at.names;var lt=ut.names,ht=Object.freeze({name:null,names:[],intervals:[],chroma:null,setnum:null}),pt=function(t,e){return void 0===e&&(e={}),function(n){return e[n]||(e[n]=t(n))}}((function(t){var e=ut(t);if(!e)return ht;var n={intervals:e,name:t};return n.chroma=X(e),n.setnum=parseInt(n.chroma,2),n.names=ut.names(n.chroma),n})),ft=function(t){return pt(bt(t)[1]).intervals};function mt(t,e){if(e)return pt(e).intervals.map($(t));var n=bt(t),r=n[0],i=n[1];return pt(i).intervals.map($(r))}var dt=function(t){return void 0!==ut(bt(t)[1])},gt=function(t){if(!ft(t).length)return[];var e=nt(ft(t));return ut.names().filter((function(t){return e(ut(t))}))},St=function(t){var e=et(ft(t));return ut.names().filter((function(t){return e(ut(t))}))},yt=/^(6|64|7|9|11|13)$/;function bt(t){var e=h(t);return""===e[0]?["",t]:"A"===e[0]&&"ug"===e[3]?["","aug"]:yt.test(e[2])?[e[0]+e[1],e[2]+e[3]]:[e[0]+e[1]+e[2],e[3]]}var wt=n(8);const Pt=[["1P","3M","5P"],["1P","3m","5P"],["1P","3M","5A"],["1P","3m","5d"]];var vt;!function(t){t[t.Major=0]="Major",t[t.Minor=1]="Minor",t[t.Augmented=2]="Augmented",t[t.Diminished=3]="Diminished",t[t.Other=4]="Other"}(vt||(vt={}));class Nt extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}class Tt extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}class Ot{static pitches(t){if(!i.tokenize(t)[0]||!i.exists(t))throw new Nt("Unrecognized chord symbol: "+t);return i.notes(t).map(r.chroma)}static root(t){const e=i.tokenize(t)[0];if(!e)throw new Nt("Chord symbol has unknown root: "+t);return r.chroma(e)}static quality(t){if(!i.exists(t))throw new Nt("Unrecognized chord symbol: "+t);const e=i.intervals(t),n=Pt.map(t=>t.every(t=>e.includes(t))),r=n.indexOf(!0),o=n.lastIndexOf(!0);return r>=0&&r===o?r:vt.Other}}class It{encodeProgression(t,e){const n=t.map(t=>this.encode(t)),r=Array.from(Array(e).keys()).map(t=>Math.floor(t*n.length/e));return o.stack(r.map(t=>n[t]))}}function Mt(t){switch(t){case"MajorMinorChordEncoder":return new At;case"TriadChordEncoder":return new kt;case"PitchChordEncoder":return new qt;default:throw new Error("Unknown chord encoder type: "+t)}}class At extends It{constructor(){super(...arguments),this.depth=1+2*wt.NUM_PITCH_CLASSES}index(t){if(t===wt.NO_CHORD)return 0;const e=Ot.root(t),n=1+Ot.quality(t)*wt.NUM_PITCH_CLASSES+e;if(n>=this.depth)throw new Tt("Chord is neither major nor minor: "+t);return n}encode(t){return o.tidy(()=>o.oneHot(o.tensor1d([this.index(t)],"int32"),this.depth).as1D())}}class kt extends It{constructor(){super(...arguments),this.depth=1+4*wt.NUM_PITCH_CLASSES}index(t){if(t===wt.NO_CHORD)return 0;const e=Ot.root(t),n=1+Ot.quality(t)*wt.NUM_PITCH_CLASSES+e;if(n>=this.depth)throw new Tt("Chord is not a standard triad: "+t);return n}encode(t){return o.tidy(()=>o.oneHot(o.tensor1d([this.index(t)],"int32"),this.depth).as1D())}}class qt extends It{constructor(){super(...arguments),this.depth=1+3*wt.NUM_PITCH_CLASSES}encode(t){return o.tidy(()=>{if(t===wt.NO_CHORD)return o.oneHot(o.tensor1d([0],"int32"),this.depth).as1D();const e=Ot.root(t),n=o.oneHot(o.tensor1d([e],"int32"),wt.NUM_PITCH_CLASSES).as1D(),r=o.buffer([wt.NUM_PITCH_CLASSES]);Ot.pitches(t).forEach(t=>r.set(1,t));const i=r.toTensor().as1D(),s=n;return o.concat1d([o.tensor1d([0]),n,i,s])})}}},,,,,,,,,,,function(t,e,n){"use strict";n.r(e),n.d(e,"auxiliaryInputFromSpec",(function(){return i})),n.d(e,"AuxiliaryInput",(function(){return o})),n.d(e,"BinaryCounter",(function(){return s}));var r=n(2);function i(t){switch(t.type){case"BinaryCounter":return new s(t.args);default:throw new Error("Unknown auxiliary input: "+t)}}class o{constructor(t){this.depth=t}}class s extends o{constructor(t){super(t.numBits)}getTensors(t){const e=r.buffer([t,this.depth]);for(let n=0;n1&&"="===t.charAt(e);)++n;return Math.ceil(3*t.length)/4-n};for(var i=new Array(64),o=new Array(123),s=0;s<64;)o[i[s]=s<26?s+65:s<52?s+71:s<62?s-4:s-59|43]=s++;r.encode=function(t,e,n){for(var r,o=null,s=[],a=0,u=0;e>2],r=(3&c)<<4,u=1;break;case 1:s[a++]=i[r|c>>4],r=(15&c)<<2,u=2;break;case 2:s[a++]=i[r|c>>6],s[a++]=i[63&c],u=0}a>8191&&((o||(o=[])).push(String.fromCharCode.apply(String,s)),a=0)}return u&&(s[a++]=i[r],s[a++]=61,1===u&&(s[a++]=61)),o?(a&&o.push(String.fromCharCode.apply(String,s.slice(0,a))),o.join("")):String.fromCharCode.apply(String,s.slice(0,a))};r.decode=function(t,e,n){for(var r,i=n,s=0,a=0;a1)break;if(void 0===(u=o[u]))throw Error("invalid encoding");switch(s){case 0:r=u,s=1;break;case 1:e[n++]=r<<2|(48&u)>>4,r=u,s=2;break;case 2:e[n++]=(15&r)<<4|(60&u)>>2,r=u,s=3;break;case 3:e[n++]=(3&r)<<6|u,s=0}}if(1===s)throw Error("invalid encoding");return n-i},r.test=function(t){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t)}},function(t,e,n){"use strict";function r(){this._listeners={}}t.exports=r,r.prototype.on=function(t,e,n){return(this._listeners[t]||(this._listeners[t]=[])).push({fn:e,ctx:n||this}),this},r.prototype.off=function(t,e){if(void 0===t)this._listeners={};else if(void 0===e)this._listeners[t]=[];else for(var n=this._listeners[t],r=0;r0?0:2147483648,n,r);else if(isNaN(e))t(2143289344,n,r);else if(e>34028234663852886e22)t((i<<31|2139095040)>>>0,n,r);else if(e<11754943508222875e-54)t((i<<31|Math.round(e/1401298464324817e-60))>>>0,n,r);else{var o=Math.floor(Math.log(e)/Math.LN2);t((i<<31|o+127<<23|8388607&Math.round(e*Math.pow(2,-o)*8388608))>>>0,n,r)}}function n(t,e,n){var r=t(e,n),i=2*(r>>31)+1,o=r>>>23&255,s=8388607&r;return 255===o?s?NaN:i*(1/0):0===o?1401298464324817e-60*i*s:i*Math.pow(2,o-150)*(s+8388608)}t.writeFloatLE=e.bind(null,i),t.writeFloatBE=e.bind(null,o),t.readFloatLE=n.bind(null,s),t.readFloatBE=n.bind(null,a)}(),"undefined"!=typeof Float64Array?function(){var e=new Float64Array([-0]),n=new Uint8Array(e.buffer),r=128===n[7];function i(t,r,i){e[0]=t,r[i]=n[0],r[i+1]=n[1],r[i+2]=n[2],r[i+3]=n[3],r[i+4]=n[4],r[i+5]=n[5],r[i+6]=n[6],r[i+7]=n[7]}function o(t,r,i){e[0]=t,r[i]=n[7],r[i+1]=n[6],r[i+2]=n[5],r[i+3]=n[4],r[i+4]=n[3],r[i+5]=n[2],r[i+6]=n[1],r[i+7]=n[0]}function s(t,r){return n[0]=t[r],n[1]=t[r+1],n[2]=t[r+2],n[3]=t[r+3],n[4]=t[r+4],n[5]=t[r+5],n[6]=t[r+6],n[7]=t[r+7],e[0]}function a(t,r){return n[7]=t[r],n[6]=t[r+1],n[5]=t[r+2],n[4]=t[r+3],n[3]=t[r+4],n[2]=t[r+5],n[1]=t[r+6],n[0]=t[r+7],e[0]}t.writeDoubleLE=r?i:o,t.writeDoubleBE=r?o:i,t.readDoubleLE=r?s:a,t.readDoubleBE=r?a:s}():function(){function e(t,e,n,r,i,o){var s=r<0?1:0;if(s&&(r=-r),0===r)t(0,i,o+e),t(1/r>0?0:2147483648,i,o+n);else if(isNaN(r))t(0,i,o+e),t(2146959360,i,o+n);else if(r>17976931348623157e292)t(0,i,o+e),t((s<<31|2146435072)>>>0,i,o+n);else{var a;if(r<22250738585072014e-324)t((a=r/5e-324)>>>0,i,o+e),t((s<<31|a/4294967296)>>>0,i,o+n);else{var u=Math.floor(Math.log(r)/Math.LN2);1024===u&&(u=1023),t(4503599627370496*(a=r*Math.pow(2,-u))>>>0,i,o+e),t((s<<31|u+1023<<20|1048576*a&1048575)>>>0,i,o+n)}}}function n(t,e,n,r,i){var o=t(r,i+e),s=t(r,i+n),a=2*(s>>31)+1,u=s>>>20&2047,c=4294967296*(1048575&s)+o;return 2047===u?c?NaN:a*(1/0):0===u?5e-324*a*c:a*Math.pow(2,u-1075)*(c+4503599627370496)}t.writeDoubleLE=e.bind(null,i,0,4),t.writeDoubleBE=e.bind(null,o,4,0),t.readDoubleLE=n.bind(null,s,0,4),t.readDoubleBE=n.bind(null,a,4,0)}(),t}function i(t,e,n){e[n]=255&t,e[n+1]=t>>>8&255,e[n+2]=t>>>16&255,e[n+3]=t>>>24}function o(t,e,n){e[n]=t>>>24,e[n+1]=t>>>16&255,e[n+2]=t>>>8&255,e[n+3]=255&t}function s(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0}function a(t,e){return(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0}t.exports=r(r)},function(module,exports,__webpack_require__){"use strict";function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(t){}return null}module.exports=inquire},function(t,e,n){"use strict";var r=e;r.length=function(t){for(var e=0,n=0,r=0;r191&&r<224?o[s++]=(31&r)<<6|63&t[e++]:r>239&&r<365?(r=((7&r)<<18|(63&t[e++])<<12|(63&t[e++])<<6|63&t[e++])-65536,o[s++]=55296+(r>>10),o[s++]=56320+(1023&r)):o[s++]=(15&r)<<12|(63&t[e++])<<6|63&t[e++],s>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i?(s&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))},r.write=function(t,e,n){for(var r,i,o=n,s=0;s>6|192,e[n++]=63&r|128):55296==(64512&r)&&56320==(64512&(i=t.charCodeAt(s+1)))?(r=65536+((1023&r)<<10)+(1023&i),++s,e[n++]=r>>18|240,e[n++]=r>>12&63|128,e[n++]=r>>6&63|128,e[n++]=63&r|128):(e[n++]=r>>12|224,e[n++]=r>>6&63|128,e[n++]=63&r|128);return n-o}},function(t,e,n){"use strict";t.exports=function(t,e,n){var r=n||8192,i=r>>>1,o=null,s=r;return function(n){if(n<1||n>i)return t(n);s+n>r&&(o=t(r),s=0);var a=e.call(o,s,s+=n);return 7&s&&(s=1+(7|s)),a}}},function(t,e,n){"use strict";t.exports=i;var r=n(18);function i(t,e){this.lo=t>>>0,this.hi=e>>>0}var o=i.zero=new i(0,0);o.toNumber=function(){return 0},o.zzEncode=o.zzDecode=function(){return this},o.length=function(){return 1};var s=i.zeroHash="\0\0\0\0\0\0\0\0";i.fromNumber=function(t){if(0===t)return o;var e=t<0;e&&(t=-t);var n=t>>>0,r=(t-n)/4294967296>>>0;return e&&(r=~r>>>0,n=~n>>>0,++n>4294967295&&(n=0,++r>4294967295&&(r=0))),new i(n,r)},i.from=function(t){if("number"==typeof t)return i.fromNumber(t);if(r.isString(t)){if(!r.Long)return i.fromNumber(parseInt(t,10));t=r.Long.fromString(t)}return t.low||t.high?new i(t.low>>>0,t.high>>>0):o},i.prototype.toNumber=function(t){if(!t&&this.hi>>>31){var e=1+~this.lo>>>0,n=~this.hi>>>0;return e||(n=n+1>>>0),-(e+4294967296*n)}return this.lo+4294967296*this.hi},i.prototype.toLong=function(t){return r.Long?new r.Long(0|this.lo,0|this.hi,Boolean(t)):{low:0|this.lo,high:0|this.hi,unsigned:Boolean(t)}};var a=String.prototype.charCodeAt;i.fromHash=function(t){return t===s?o:new i((a.call(t,0)|a.call(t,1)<<8|a.call(t,2)<<16|a.call(t,3)<<24)>>>0,(a.call(t,4)|a.call(t,5)<<8|a.call(t,6)<<16|a.call(t,7)<<24)>>>0)},i.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},i.prototype.zzEncode=function(){var t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this},i.prototype.zzDecode=function(){var t=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this},i.prototype.length=function(){var t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return 0===n?0===e?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}},function(t,e,n){"use strict";t.exports=o;var r=n(33);(o.prototype=Object.create(r.prototype)).constructor=o;var i=n(18);function o(){r.call(this)}function s(t,e,n){t.length<40?i.utf8.write(t,e,n):e.utf8Write?e.utf8Write(t,n):e.write(t,n)}o._configure=function(){o.alloc=i._Buffer_allocUnsafe,o.writeBytesBuffer=i.Buffer&&i.Buffer.prototype instanceof Uint8Array&&"set"===i.Buffer.prototype.set.name?function(t,e,n){e.set(t,n)}:function(t,e,n){if(t.copy)t.copy(e,n,0,t.length);else for(var r=0;r>>0;return this.uint32(e),e&&this._push(o.writeBytesBuffer,e,t),this},o.prototype.string=function(t){var e=i.Buffer.byteLength(t);return this.uint32(e),e&&this._push(s,e,t),this},o._configure()},function(t,e,n){"use strict";t.exports=o;var r=n(34);(o.prototype=Object.create(r.prototype)).constructor=o;var i=n(18);function o(t){r.call(this,t)}o._configure=function(){i.Buffer&&(o.prototype._slice=i.Buffer.prototype.slice)},o.prototype.string=function(){var t=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+t,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+t,this.len))},o._configure()},function(t,e,n){"use strict";e.Service=n(62)},function(t,e,n){"use strict";t.exports=i;var r=n(18);function i(t,e,n){if("function"!=typeof t)throw TypeError("rpcImpl must be a function");r.EventEmitter.call(this),this.rpcImpl=t,this.requestDelimited=Boolean(e),this.responseDelimited=Boolean(n)}(i.prototype=Object.create(r.EventEmitter.prototype)).constructor=i,i.prototype.rpcCall=function t(e,n,i,o,s){if(!o)throw TypeError("request must be specified");var a=this;if(!s)return r.asPromise(t,a,e,n,i,o);if(a.rpcImpl)try{return a.rpcImpl(e,n[a.requestDelimited?"encodeDelimited":"encode"](o).finish(),(function(t,n){if(t)return a.emit("error",t,e),s(t);if(null!==n){if(!(n instanceof i))try{n=i[a.responseDelimited?"decodeDelimited":"decode"](n)}catch(t){return a.emit("error",t,e),s(t)}return a.emit("data",n,e),s(null,n)}a.end(!0)}))}catch(t){return a.emit("error",t,e),void setTimeout((function(){s(t)}),0)}else setTimeout((function(){s(Error("already ended"))}),0)},i.prototype.end=function(t){return this.rpcImpl&&(t||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}},function(t,e,n){"use strict";t.exports={}},function(t){t.exports=JSON.parse('{"chromatic":["1P 2m 2M 3m 3M 4P 4A 5P 6m 6M 7m 7M"],"lydian":["1P 2M 3M 4A 5P 6M 7M"],"major":["1P 2M 3M 4P 5P 6M 7M",["ionian"]],"mixolydian":["1P 2M 3M 4P 5P 6M 7m",["dominant"]],"dorian":["1P 2M 3m 4P 5P 6M 7m"],"aeolian":["1P 2M 3m 4P 5P 6m 7m",["minor"]],"phrygian":["1P 2m 3m 4P 5P 6m 7m"],"locrian":["1P 2m 3m 4P 5d 6m 7m"],"melodic minor":["1P 2M 3m 4P 5P 6M 7M"],"melodic minor second mode":["1P 2m 3m 4P 5P 6M 7m"],"lydian augmented":["1P 2M 3M 4A 5A 6M 7M"],"lydian dominant":["1P 2M 3M 4A 5P 6M 7m",["lydian b7"]],"melodic minor fifth mode":["1P 2M 3M 4P 5P 6m 7m",["hindu","mixolydian b6M"]],"locrian #2":["1P 2M 3m 4P 5d 6m 7m",["half-diminished"]],"altered":["1P 2m 3m 3M 5d 6m 7m",["super locrian","diminished whole tone","pomeroy"]],"harmonic minor":["1P 2M 3m 4P 5P 6m 7M"],"phrygian dominant":["1P 2m 3M 4P 5P 6m 7m",["spanish","phrygian major"]],"half-whole diminished":["1P 2m 3m 3M 4A 5P 6M 7m",["dominant diminished"]],"diminished":["1P 2M 3m 4P 5d 6m 6M 7M",["whole-half diminished"]],"major pentatonic":["1P 2M 3M 5P 6M",["pentatonic"]],"lydian pentatonic":["1P 3M 4A 5P 7M",["chinese"]],"mixolydian pentatonic":["1P 3M 4P 5P 7m",["indian"]],"locrian pentatonic":["1P 3m 4P 5d 7m",["minor seven flat five pentatonic"]],"minor pentatonic":["1P 3m 4P 5P 7m"],"minor six pentatonic":["1P 3m 4P 5P 6M"],"minor hexatonic":["1P 2M 3m 4P 5P 7M"],"flat three pentatonic":["1P 2M 3m 5P 6M",["kumoi"]],"flat six pentatonic":["1P 2M 3M 5P 6m"],"major flat two pentatonic":["1P 2m 3M 5P 6M"],"whole tone pentatonic":["1P 3M 5d 6m 7m"],"ionian pentatonic":["1P 3M 4P 5P 7M"],"lydian #5P pentatonic":["1P 3M 4A 5A 7M"],"lydian dominant pentatonic":["1P 3M 4A 5P 7m"],"minor #7M pentatonic":["1P 3m 4P 5P 7M"],"super locrian pentatonic":["1P 3m 4d 5d 7m"],"in-sen":["1P 2m 4P 5P 7m"],"iwato":["1P 2m 4P 5d 7m"],"hirajoshi":["1P 2M 3m 5P 6m"],"kumoijoshi":["1P 2m 4P 5P 6m"],"pelog":["1P 2m 3m 5P 6m"],"vietnamese 1":["1P 3m 4P 5P 6m"],"vietnamese 2":["1P 3m 4P 5P 7m"],"prometheus":["1P 2M 3M 4A 6M 7m"],"prometheus neopolitan":["1P 2m 3M 4A 6M 7m"],"ritusen":["1P 2M 4P 5P 6M"],"scriabin":["1P 2m 3M 5P 6M"],"piongio":["1P 2M 4P 5P 6M 7m"],"major blues":["1P 2M 3m 3M 5P 6M"],"minor blues":["1P 3m 4P 5d 5P 7m",["blues"]],"composite blues":["1P 2M 3m 3M 4P 5d 5P 6M 7m"],"augmented":["1P 2A 3M 5P 5A 7M"],"augmented heptatonic":["1P 2A 3M 4P 5P 5A 7M"],"dorian #4":["1P 2M 3m 4A 5P 6M 7m"],"lydian diminished":["1P 2M 3m 4A 5P 6M 7M"],"whole tone":["1P 2M 3M 4A 5A 7m"],"leading whole tone":["1P 2M 3M 4A 5A 7m 7M"],"lydian minor":["1P 2M 3M 4A 5P 6m 7m"],"locrian major":["1P 2M 3M 4P 5d 6m 7m",["arabian"]],"neopolitan":["1P 2m 3m 4P 5P 6m 7M"],"neopolitan minor":["1P 2m 3m 4P 5P 6m 7M"],"neopolitan major":["1P 2m 3m 4P 5P 6M 7M",["dorian b2"]],"neopolitan major pentatonic":["1P 3M 4P 5d 7m"],"romanian minor":["1P 2M 3m 5d 5P 6M 7m"],"double harmonic lydian":["1P 2m 3M 4A 5P 6m 7M"],"harmonic major":["1P 2M 3M 4P 5P 6m 7M"],"double harmonic major":["1P 2m 3M 4P 5P 6m 7M",["gypsy"]],"egyptian":["1P 2M 4P 5P 7m"],"hungarian minor":["1P 2M 3m 4A 5P 6m 7M"],"hungarian major":["1P 2A 3M 4A 5P 6M 7m"],"oriental":["1P 2m 3M 4P 5d 6M 7m"],"spanish heptatonic":["1P 2m 3m 3M 4P 5P 6m 7m"],"flamenco":["1P 2m 3m 3M 4A 5P 7m"],"balinese":["1P 2m 3m 4P 5P 6m 7M"],"todi raga":["1P 2m 3m 4A 5P 6m 7M"],"malkos raga":["1P 3m 4P 6m 7m"],"kafi raga":["1P 3m 3M 4P 5P 6M 7m 7M"],"purvi raga":["1P 2m 3M 4P 4A 5P 6m 7M"],"persian":["1P 2m 3M 4P 5d 6m 7M"],"bebop":["1P 2M 3M 4P 5P 6M 7m 7M"],"bebop dominant":["1P 2M 3M 4P 5P 6M 7m 7M"],"bebop minor":["1P 2M 3m 3M 4P 5P 6M 7m"],"bebop major":["1P 2M 3M 4P 5P 5A 6M 7M"],"bebop locrian":["1P 2m 3m 4P 5d 5P 6m 7m"],"minor bebop":["1P 2M 3m 4P 5P 6m 7m 7M"],"mystery #1":["1P 2m 3M 5d 6m 7m"],"enigmatic":["1P 2m 3M 5d 6m 7m 7M"],"minor six diminished":["1P 2M 3m 4P 5P 6m 6M 7M"],"ionian augmented":["1P 2M 3M 4P 5A 6M 7M"],"lydian #9":["1P 2m 3M 4A 5P 6M 7M"],"ichikosucho":["1P 2M 3M 4P 5d 5P 6M 7M"],"six tone symmetric":["1P 2m 3M 4P 5A 6M"]}')},function(t){t.exports=JSON.parse('{"4":["1P 4P 7m 10m",["quartal"]],"5":["1P 5P"],"7":["1P 3M 5P 7m",["Dominant","Dom"]],"9":["1P 3M 5P 7m 9M",["79"]],"11":["1P 5P 7m 9M 11P"],"13":["1P 3M 5P 7m 9M 13M",["13_"]],"64":["5P 8P 10M"],"M":["1P 3M 5P",["Major",""]],"M#5":["1P 3M 5A",["augmented","maj#5","Maj#5","+","aug"]],"M#5add9":["1P 3M 5A 9M",["+add9"]],"M13":["1P 3M 5P 7M 9M 13M",["maj13","Maj13"]],"M13#11":["1P 3M 5P 7M 9M 11A 13M",["maj13#11","Maj13#11","M13+4","M13#4"]],"M6":["1P 3M 5P 13M",["6"]],"M6#11":["1P 3M 5P 6M 11A",["M6b5","6#11","6b5"]],"M69":["1P 3M 5P 6M 9M",["69"]],"M69#11":["1P 3M 5P 6M 9M 11A"],"M7#11":["1P 3M 5P 7M 11A",["maj7#11","Maj7#11","M7+4","M7#4"]],"M7#5":["1P 3M 5A 7M",["maj7#5","Maj7#5","maj9#5","M7+"]],"M7#5sus4":["1P 4P 5A 7M"],"M7#9#11":["1P 3M 5P 7M 9A 11A"],"M7add13":["1P 3M 5P 6M 7M 9M"],"M7b5":["1P 3M 5d 7M"],"M7b6":["1P 3M 6m 7M"],"M7b9":["1P 3M 5P 7M 9m"],"M7sus4":["1P 4P 5P 7M"],"M9":["1P 3M 5P 7M 9M",["maj9","Maj9"]],"M9#11":["1P 3M 5P 7M 9M 11A",["maj9#11","Maj9#11","M9+4","M9#4"]],"M9#5":["1P 3M 5A 7M 9M",["Maj9#5"]],"M9#5sus4":["1P 4P 5A 7M 9M"],"M9b5":["1P 3M 5d 7M 9M"],"M9sus4":["1P 4P 5P 7M 9M"],"Madd9":["1P 3M 5P 9M",["2","add9","add2"]],"Maj7":["1P 3M 5P 7M",["maj7","M7"]],"Mb5":["1P 3M 5d"],"Mb6":["1P 3M 13m"],"Msus2":["1P 2M 5P",["add9no3","sus2"]],"Msus4":["1P 4P 5P",["sus","sus4"]],"Maddb9":["1P 3M 5P 9m"],"11b9":["1P 5P 7m 9m 11P"],"13#11":["1P 3M 5P 7m 9M 11A 13M",["13+4","13#4"]],"13#9":["1P 3M 5P 7m 9A 13M",["13#9_"]],"13#9#11":["1P 3M 5P 7m 9A 11A 13M"],"13b5":["1P 3M 5d 6M 7m 9M"],"13b9":["1P 3M 5P 7m 9m 13M"],"13b9#11":["1P 3M 5P 7m 9m 11A 13M"],"13no5":["1P 3M 7m 9M 13M"],"13sus4":["1P 4P 5P 7m 9M 13M",["13sus"]],"69#11":["1P 3M 5P 6M 9M 11A"],"7#11":["1P 3M 5P 7m 11A",["7+4","7#4","7#11_","7#4_"]],"7#11b13":["1P 3M 5P 7m 11A 13m",["7b5b13"]],"7#5":["1P 3M 5A 7m",["+7","7aug","aug7"]],"7#5#9":["1P 3M 5A 7m 9A",["7alt","7#5#9_","7#9b13_"]],"7#5b9":["1P 3M 5A 7m 9m"],"7#5b9#11":["1P 3M 5A 7m 9m 11A"],"7#5sus4":["1P 4P 5A 7m"],"7#9":["1P 3M 5P 7m 9A",["7#9_"]],"7#9#11":["1P 3M 5P 7m 9A 11A",["7b5#9"]],"7#9#11b13":["1P 3M 5P 7m 9A 11A 13m"],"7#9b13":["1P 3M 5P 7m 9A 13m"],"7add6":["1P 3M 5P 7m 13M",["67","7add13"]],"7b13":["1P 3M 7m 13m"],"7b5":["1P 3M 5d 7m"],"7b6":["1P 3M 5P 6m 7m"],"7b9":["1P 3M 5P 7m 9m"],"7b9#11":["1P 3M 5P 7m 9m 11A",["7b5b9"]],"7b9#9":["1P 3M 5P 7m 9m 9A"],"7b9b13":["1P 3M 5P 7m 9m 13m"],"7b9b13#11":["1P 3M 5P 7m 9m 11A 13m",["7b9#11b13","7b5b9b13"]],"7no5":["1P 3M 7m"],"7sus4":["1P 4P 5P 7m",["7sus"]],"7sus4b9":["1P 4P 5P 7m 9m",["susb9","7susb9","7b9sus","7b9sus4","phryg"]],"7sus4b9b13":["1P 4P 5P 7m 9m 13m",["7b9b13sus4"]],"9#11":["1P 3M 5P 7m 9M 11A",["9+4","9#4","9#11_","9#4_"]],"9#11b13":["1P 3M 5P 7m 9M 11A 13m",["9b5b13"]],"9#5":["1P 3M 5A 7m 9M",["9+"]],"9#5#11":["1P 3M 5A 7m 9M 11A"],"9b13":["1P 3M 7m 9M 13m"],"9b5":["1P 3M 5d 7m 9M"],"9no5":["1P 3M 7m 9M"],"9sus4":["1P 4P 5P 7m 9M",["9sus"]],"m":["1P 3m 5P"],"m#5":["1P 3m 5A",["m+","mb6"]],"m11":["1P 3m 5P 7m 9M 11P",["_11"]],"m11A 5":["1P 3m 6m 7m 9M 11P"],"m11b5":["1P 3m 7m 12d 2M 4P",["h11","_11b5"]],"m13":["1P 3m 5P 7m 9M 11P 13M",["_13"]],"m6":["1P 3m 4P 5P 13M",["_6"]],"m69":["1P 3m 5P 6M 9M",["_69"]],"m7":["1P 3m 5P 7m",["minor7","_","_7"]],"m7#5":["1P 3m 6m 7m"],"m7add11":["1P 3m 5P 7m 11P",["m7add4"]],"m7b5":["1P 3m 5d 7m",["half-diminished","h7","_7b5"]],"m9":["1P 3m 5P 7m 9M",["_9"]],"m9#5":["1P 3m 6m 7m 9M"],"m9b5":["1P 3m 7m 12d 2M",["h9","-9b5"]],"mMaj7":["1P 3m 5P 7M",["mM7","_M7"]],"mMaj7b6":["1P 3m 5P 6m 7M",["mM7b6"]],"mM9":["1P 3m 5P 7M 9M",["mMaj9","-M9"]],"mM9b6":["1P 3m 5P 6m 7M 9M",["mMaj9b6"]],"mb6M7":["1P 3m 6m 7M"],"mb6b9":["1P 3m 6m 9m"],"o":["1P 3m 5d",["mb5","dim"]],"o7":["1P 3m 5d 13M",["diminished","m6b5","dim7"]],"o7M7":["1P 3m 5d 6M 7M"],"oM7":["1P 3m 5d 7M"],"sus24":["1P 2M 4P 5P",["sus4add9"]],"+add#9":["1P 3M 5A 9A"],"madd4":["1P 3m 4P 5P"],"madd9":["1P 3m 5P 9M"]}')},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(80),i=new WeakMap;e.keySignatureKeys=["Cb","Gb","Db","Ab","Eb","Bb","F","C","G","D","A","E","B","F#","C#"];var o=function(){function t(t){var n=this;this.tempos=[],this.timeSignatures=[],this.keySignatures=[],this.meta=[],this.name="",i.set(this,480),t&&(i.set(this,t.header.ticksPerBeat),t.tracks.forEach((function(t){return t.forEach((function(t){t.meta&&("timeSignature"===t.type?n.timeSignatures.push({ticks:t.absoluteTime,timeSignature:[t.numerator,t.denominator]}):"setTempo"===t.type?n.tempos.push({bpm:6e7/t.microsecondsPerBeat,ticks:t.absoluteTime}):"keySignature"===t.type&&n.keySignatures.push({key:e.keySignatureKeys[t.key+7],scale:0===t.scale?"major":"minor",ticks:t.absoluteTime}))}))})),t.tracks[0].forEach((function(t){t.meta&&("trackName"===t.type?n.name=t.text:"text"!==t.type&&"cuePoint"!==t.type&&"marker"!==t.type&&"lyrics"!==t.type||n.meta.push({text:t.text,ticks:t.absoluteTime,type:t.type}))})),this.update())}return t.prototype.update=function(){var t=this,e=0,n=0;this.tempos.sort((function(t,e){return t.ticks-e.ticks})),this.tempos.forEach((function(r,i){var o=i>0?t.tempos[i-1].bpm:t.tempos[0].bpm,s=r.ticks/t.ppq-n,a=60/o*s;r.time=a+e,e=r.time,n+=s})),this.timeSignatures.sort((function(t,e){return t.ticks-e.ticks})),this.timeSignatures.forEach((function(e,n){var r=n>0?t.timeSignatures[n-1]:t.timeSignatures[0],i=(e.ticks-r.ticks)/t.ppq/r.timeSignature[0]/(r.timeSignature[1]/4);r.measures=r.measures||0,e.measures=i+r.measures}))},t.prototype.ticksToSeconds=function(t){var e=r.search(this.tempos,t);if(-1!==e){var n=this.tempos[e],i=n.time,o=(t-n.ticks)/this.ppq;return i+60/n.bpm*o}return.5*(t/this.ppq)},t.prototype.ticksToMeasures=function(t){var e=r.search(this.timeSignatures,t);if(-1!==e){var n=this.timeSignatures[e],i=(t-n.ticks)/this.ppq;return n.measures+i/(n.timeSignature[0]/n.timeSignature[1])/4}return t/this.ppq/4},Object.defineProperty(t.prototype,"ppq",{get:function(){return i.get(this)},enumerable:!0,configurable:!0}),t.prototype.secondsToTicks=function(t){var e=r.search(this.tempos,t,"time");if(-1!==e){var n=this.tempos[e],i=(t-n.time)/(60/n.bpm);return Math.round(n.ticks+i*this.ppq)}var o=t/.5;return Math.round(o*this.ppq)},t.prototype.toJSON=function(){return{keySignatures:this.keySignatures,meta:this.meta,name:this.name,ppq:this.ppq,tempos:this.tempos.map((function(t){return{bpm:t.bpm,ticks:t.ticks}})),timeSignatures:this.timeSignatures}},t.prototype.fromJSON=function(t){this.name=t.name,this.tempos=t.tempos.map((function(t){return Object.assign({},t)})),this.timeSignatures=t.timeSignatures.map((function(t){return Object.assign({},t)})),this.keySignatures=t.keySignatures.map((function(t){return Object.assign({},t)})),this.meta=t.meta.map((function(t){return Object.assign({},t)})),i.set(this,t.ppq),this.update()},t.prototype.setTempo=function(t){this.tempos=[{bpm:t,ticks:0}],this.update()},t}();e.Header=o},function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))},i=this&&this.__generator||function(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]{}),this.callbackObject.quarter||(this.callbackObject.quarter=()=>{}),this.callbackObject.bar||(this.callbackObject.bar=()=>{});let e=0;const n=4*this.clicksPerQuarter;h.Transport.scheduleRepeat(t=>{this.startedAt||(this.startedAt=t);const r=t-this.startedAt;this.step++;const i=this.step%n,o=Math.floor(i/this.clicksPerQuarter),s=i%this.clicksPerQuarter;this.callbackObject.click(r,i),0===s&&this.callbackObject.quarter(r,o),this.muted||(0===i?this.hiClick.triggerAttack(this.hiClickNote,t,.1):this.loClick.triggerAttack(this.loClickNote,t,.1)),0===i&&(this.callbackObject.bar(r,e),e++)},n+"n"),h.Transport.bpm.value=t,h.Transport.start()}stop(){this.ticking=!1,h.Transport.cancel(),h.Transport.stop()}reset(){this.muted=!1,this.ticking=!1,this.step=-1,this.startedAt=null}}var m=n(67),d=n(15),g=n(10);class S extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype)}}function y(t){const e=new m.Midi(t),n=g.a.create();n.ticksPerQuarter=e.header.ppq,n.sourceInfo=g.a.SourceInfo.create({parser:g.a.SourceInfo.Parser.TONEJS_MIDI_CONVERT,encodingType:g.a.SourceInfo.EncodingType.MIDI});for(const t of e.header.timeSignatures)n.timeSignatures.push(g.a.TimeSignature.create({time:e.header.ticksToSeconds(t.ticks),numerator:t.timeSignature[0],denominator:t.timeSignature[1]}));n.timeSignatures.length||n.timeSignatures.push(g.a.TimeSignature.create({time:0,numerator:4,denominator:4}));for(const t of e.header.tempos)n.tempos.push(g.a.Tempo.create({time:t.time,qpm:t.bpm}));let r=-1;for(const t of e.tracks){t.notes.length>0&&(r+=1);for(const e of t.notes){const i=e.time,s=i+e.duration;n.notes.push(g.a.Note.create({instrument:r,program:t.instrument.number,startTime:i,endTime:s,pitch:e.midi,velocity:Math.floor(e.velocity*o.MIDI_VELOCITIES),isDrum:t.instrument.percussion})),s>n.totalTime&&(n.totalTime=s)}const e=Object.values(t.controlChanges),i=[].concat.apply([],e);for(const e of i)n.controlChanges.push(g.a.ControlChange.create({time:e.time,controlNumber:e.number,controlValue:Math.floor(e.value*(o.MIDI_VELOCITIES-1)),instrument:r,program:t.instrument.number,isDrum:t.instrument.percussion}))}return n}function b(t){l.isQuantizedSequence(t)&&(t=l.unquantizeSequence(t));const e=new m.Midi;e.fromJSON({header:{name:"",ppq:t.ticksPerQuarter||o.DEFAULT_TICKS_PER_QUARTER,tempos:[],timeSignatures:[],keySignatures:[],meta:[]},tracks:[]});const n=Array.from(t.tempos||[]);0===n.length&&n.push({time:0,qpm:o.DEFAULT_QUARTERS_PER_MINUTE}),n.sort((t,e)=>t.time-e.time);for(const t of n)e.header.tempos.push({ticks:e.header.secondsToTicks(t.time),bpm:t.qpm}),e.header.update();if(t.timeSignatures&&0!==t.timeSignatures.length)for(const n of t.timeSignatures)e.header.timeSignatures.push({ticks:e.header.secondsToTicks(n.time),timeSignature:[n.numerator,n.denominator]});else e.header.timeSignatures.push({ticks:0,timeSignature:[4,4]});e.header.update();const r=new Map;for(const e of t.notes){const t=e.instrument?e.instrument:0,n=void 0===e.program?o.DEFAULT_PROGRAM:e.program,i=!!e.isDrum,s=JSON.stringify([t,n,i]);r.has(s)||r.set(s,{notes:[],controlChanges:[]}),r.get(s).notes.push(e)}for(const e of t.controlChanges){const t=e.instrument?e.instrument:0,n=void 0===e.program?o.DEFAULT_PROGRAM:e.program,i=!!e.isDrum,s=JSON.stringify([t,n,i]);r.has(s)||r.set(s,{notes:[],controlChanges:[]}),r.get(s).controlChanges.push(e)}return r.forEach((t,n)=>{const[r,i]=JSON.parse(n).slice(1),s=e.addTrack();s.channel=i?o.DRUM_CHANNEL:o.NON_DRUM_CHANNELS[(e.tracks.length-1)%o.NON_DRUM_CHANNELS.length],s.instrument.number=r;for(const e of t.notes){const t=void 0===e.velocity?o.DEFAULT_VELOCITY:e.velocity;s.addNote({midi:e.pitch,time:e.startTime,duration:e.endTime-e.startTime,velocity:(t+1)/o.MIDI_VELOCITIES})}for(const e of t.controlChanges)s.addCC({number:e.controlNumber,value:e.controlValue,time:e.time})}),e.toArray()}function w(t){return new Promise((e,n)=>{Object(d.a)(t).then(t=>t.blob()).then(t=>{e(t)}).catch(t=>n(t))})}function P(t){return new Promise((e,n)=>{const r=new FileReader;r.onload=t=>{try{const t=y(r.result);e(t)}catch(t){n(t)}},r.onerror=t=>n(t),r.readAsArrayBuffer(t)})}function v(t){return w(t).then(P)}class N{constructor(t){this.FADE_SECONDS=.1,this.baseURL=t,this.buffers=new h.ToneAudioBuffers,this.sourceMap=new Map,this.initialized=!1}async initialize(){await Object(d.a)(this.baseURL+"/instrument.json").then(t=>t.json()).then(t=>{this.name=t.name,this.minPitch=t.minPitch,this.maxPitch=t.maxPitch,this.durationSeconds=t.durationSeconds,this.releaseSeconds=t.releaseSeconds,this.percussive=t.percussive,this.velocities=t.velocities,this.initialized=!0})}sampleInfoToName(t){return this.velocities?`p${t.pitch}_v${t.velocity}`:"p"+t.pitch}sampleNameToURL(t){return`${this.baseURL}/${t}.mp3`}nearestVelocity(t){if(!this.velocities)return t;t||(t=o.DEFAULT_VELOCITY);let e=void 0,n=o.MIDI_VELOCITIES;return this.velocities.forEach(r=>{const i=Math.abs(r-t);i!(t.pitchthis.maxPitch)||(a.log(`Pitch ${t.pitch} is outside the valid range for ${this.name}, ignoring.`,"SoundFont"),!1)).map(t=>this.sampleInfoToName({pitch:t.pitch,velocity:this.nearestVelocity(t.velocity)})),n=Array.from(new Set(e)).filter(t=>!this.buffers.has(t)).map(t=>({name:t,url:this.sampleNameToURL(t)}));n.length>0&&(n.forEach(t=>this.buffers.add(t.name,t.url)),await h.loaded(),a.log(`Loaded samples for ${this.name}.`,"SoundFont"))}playNote(t,e,n,r,i){const o=this.getBuffer(t,e);if(!o)return;r>this.durationSeconds&&a.log(`Requested note duration longer than sample duration: ${r} > ${this.durationSeconds}`,"SoundFont");const s=new h.ToneBufferSource({url:o,fadeOut:this.FADE_SECONDS}).connect(i);if(s.start(n,0,void 0,1),!this.percussive&&rthis.maxPitch)return void a.log(`Pitch ${t} is outside the valid range for ${this.name} (${this.minPitch}-${this.maxPitch})`,"SoundFont");const n=this.sampleInfoToName({pitch:t,velocity:this.nearestVelocity(e)});if(!this.buffers.has(n))throw new Error(`Buffer not found for ${this.name}: ${n}`);const r=this.buffers.get(n);if(!r.loaded)throw new Error(`Buffer not loaded for ${this.name}: ${n}`);return r}}class T{constructor(t){this.baseURL=t,this.instruments=new Map,this.initialized=!1}async initialize(){await Object(d.a)(this.baseURL+"/soundfont.json").then(t=>t.json()).then(t=>{this.name=t.name;for(const e in t.instruments){const n=`${this.baseURL}/${t.instruments[e]}`;this.instruments.set("drums"===e?"drums":+e,new N(n))}this.initialized=!0})}async loadSamples(t){this.initialized||await this.initialize();const e=new Map;t.forEach(t=>{t.isDrum=t.isDrum||!1,t.program=t.program||0;const n=t.isDrum?"drums":t.program,r={pitch:t.pitch,velocity:t.velocity};e.has(n)?e.get(n).push(r):this.instruments.has(n)?e.set(n,[r]):a.log(`No instrument in ${this.name} for: program=${t.program}, isDrum=${t.isDrum}`,"SoundFont")}),await Promise.all(Array.from(e.keys()).map(t=>this.instruments.get(t).loadSamples(e.get(t))))}playNote(t,e,n,r,i=0,o=!1,s){const u=o?"drums":i;if(!this.initialized)throw new Error("SoundFont is not initialized.");this.instruments.has(u)?this.instruments.get(u).playNote(t,e,n,r,s):a.log(`No instrument in ${this.name} for: program=${i}, isDrum=${o}`,"SoundFont")}playNoteDown(t,e,n=0,r=!1,i){const o=r?"drums":n;if(!this.initialized)throw new Error("SoundFont is not initialized.");this.instruments.has(o)?this.instruments.get(o).playNoteDown(t,e,i):a.log(`No instrument in ${this.name} for: program=${n}, isDrum=${r}`,"SoundFont")}playNoteUp(t,e,n=0,r=!1,i){const o=r?"drums":n;if(!this.initialized)throw new Error("SoundFont is not initialized.");this.instruments.has(o)?this.instruments.get(o).playNoteUp(t,e,i):a.log(`No instrument in ${this.name} for: program=${n}, isDrum=${r}`,"SoundFont")}}function O(t,e){return t.quantizedStartStepe.quantizedStartStep?1:t.pitcht.quantizedEndStep),r=Math.max(...n);for(let t=0;t0&&t.tempos[0].qpm>0?h.Transport.bpm.value=t.tempos[0].qpm:h.Transport.bpm.value=o.DEFAULT_QUARTERS_PER_MINUTE,r)t=l.unquantizeSequence(t,e);else if(e)throw new Error("Cannot specify a `qpm` for a non-quantized sequence.");const i=new h.Part((t,e)=>{this.currentPart===i&&(this.playNote(t,e),this.callbackObject&&h.Draw.schedule(()=>{this.callbackObject.run(e,t)},t))},t.notes.map(t=>[t.startTime,t]));return this.currentPart=i,this.desiredQPM&&(h.Transport.bpm.value=this.desiredQPM),this.currentPart.start(void 0,n),"started"!==h.Transport.state&&h.Transport.start(),new Promise(e=>{this.scheduledStop=h.Transport.schedule(()=>{this.stop(),e(),this.callbackObject&&this.callbackObject.stop()},"+"+t.totalTime)})}stop(){this.isPlaying()&&(this.currentPart.stop(),h.Transport.stop(),this.currentPart=null),h.Transport.clear(this.scheduledStop),this.scheduledStop=void 0,this.desiredQPM=void 0}pause(){if(!this.isPlaying())throw new Error("Cannot pause playback while the player is stopped.");h.Transport.pause()}resume(){if("paused"!==this.getPlayState())throw new Error(`Cannot resume playback while "${this.getPlayState()}".`);h.Transport.start()}seekTo(t){if(!this.isPlaying())throw new Error("Cannot seek while the player is stopped.");h.Transport.seconds=t}isPlaying(){return!!this.currentPart}getPlayState(){return this.isPlaying()?h.Transport.state:"stopped"}}class A{constructor(){this.DRUM_PITCH_TO_CLASS=new Map,this.kick=(new h.MembraneSynth).toDestination(),this.tomLow=new h.MembraneSynth({pitchDecay:.008,envelope:{attack:.01,decay:.5,sustain:0}}).toDestination(),this.tomMid=new h.MembraneSynth({pitchDecay:.008,envelope:{attack:.01,decay:.5,sustain:0}}).toDestination(),this.tomHigh=new h.MembraneSynth({pitchDecay:.008,envelope:{attack:.01,decay:.5,sustain:0}}).toDestination(),this.closedHihat=new h.MetalSynth({frequency:400,envelope:{attack:.001,decay:.1,release:.8},harmonicity:5.1,modulationIndex:32,resonance:4e3,octaves:1}).toDestination(),this.openHihat=new h.MetalSynth({frequency:400,envelope:{attack:.001,decay:.5,release:.8,sustain:1},harmonicity:5.1,modulationIndex:32,resonance:4e3,octaves:1}).toDestination(),this.ride=(new h.MetalSynth).toDestination(),this.crash=new h.MetalSynth({frequency:300,envelope:{attack:.001,decay:1,release:3},harmonicity:5.1,modulationIndex:64,resonance:4e3,octaves:1.5}).toDestination(),this.snare=new h.NoiseSynth({noise:{type:"white"},envelope:{attack:.005,decay:.05,sustain:.1,release:.4}}).toDestination(),this.loClick=new h.MembraneSynth({pitchDecay:.008,envelope:{attack:.001,decay:.3,sustain:0}}).toDestination(),this.hiClick=new h.MembraneSynth({pitchDecay:.008,envelope:{attack:.001,decay:.3,sustain:0}}).toDestination(),this.pitchPlayers=[(t,e=1)=>this.kick.triggerAttackRelease("C2","8n",t,e),(t,e=1)=>this.snare.triggerAttackRelease("16n",t,e),(t,e=1)=>this.closedHihat.triggerAttack(t,.3,e),(t,e=1)=>this.openHihat.triggerAttack(t,.3,e),(t,e=.5)=>this.tomLow.triggerAttack("G3",t,e),(t,e=.5)=>this.tomMid.triggerAttack("C4",t,e),(t,e=.5)=>this.tomHigh.triggerAttack("F4",t,e),(t,e=1)=>this.crash.triggerAttack(t,1,e),(t,e=1)=>this.ride.triggerAttack(t,.5,e),(t,e=.5)=>this.loClick.triggerAttack("G5",t,e),(t,e=.5)=>this.hiClick.triggerAttack("C6",t,e)];for(let t=0;t{this.DRUM_PITCH_TO_CLASS.set(e,t)});this.DRUM_PITCH_TO_CLASS.set(o.LO_CLICK_PITCH,o.LO_CLICK_CLASS),this.DRUM_PITCH_TO_CLASS.set(o.HI_CLICK_PITCH,o.HI_CLICK_CLASS)}static getInstance(){return A.instance||(A.instance=new A),A.instance}playNote(t,e,n){this.pitchPlayers[this.DRUM_PITCH_TO_CLASS.get(t)](e,n)}}class k extends M{constructor(){super(...arguments),this.drumKit=A.getInstance(),this.bassSynth=new h.Synth({volume:5,oscillator:{type:"triangle"}}).toDestination(),this.polySynth=(new h.PolySynth).toDestination()}playNote(t,e){const n=e.hasOwnProperty("velocity")?e.velocity/o.MAX_MIDI_VELOCITY:void 0;if(e.isDrum)this.drumKit.playNote(e.pitch,t,n);else{const r=h.Frequency(e.pitch,"midi").toFrequency(),i=e.endTime-e.startTime;this.getSynth(e.instrument,e.program).triggerAttackRelease(r,i,t,n)}}getSynth(t,e){return void 0!==e&&e>=32&&e<=39?this.bassSynth:this.polySynth}}k.tone=h;class q extends M{constructor(t,e=h.Master,n,r,i){super(!1,i),this.soundFont=new T(t),this.output=e,this.programOutputs=n,this.drumOutputs=r}async loadSamples(t){await this.soundFont.loadSamples(t.notes.map(t=>({pitch:t.pitch,velocity:t.velocity,program:t.program||0,isDrum:t.isDrum||!1})))}async loadAllSamples(t=0,e=!1){const n=g.a.create(),r=e?o.MIN_DRUM_PITCH:o.MIN_PIANO_PITCH,i=e?o.MAX_DRUM_PITCH:o.MAX_PIANO_PITCH;for(let s=r;s<=i;s++)for(let r=o.MIN_MIDI_VELOCITY;rsuper.start(t,e,n))}playNote(t,e){this.soundFont.playNote(e.pitch,e.velocity,t,e.endTime-e.startTime,e.program,e.isDrum,this.getAudioNodeOutput(e))}playNoteDown(t){this.soundFont.playNoteDown(t.pitch,t.velocity,t.program,t.isDrum,this.getAudioNodeOutput(t))}playNoteUp(t){this.soundFont.playNoteUp(t.pitch,t.velocity,t.program,t.isDrum,this.getAudioNodeOutput(t))}getAudioNodeOutput(t){let e=this.output;return this.programOutputs&&!t.isDrum?this.programOutputs.has(t.program)&&(e=this.programOutputs.get(t.program)):this.drumOutputs&&t.isDrum&&this.drumOutputs.has(t.pitch)&&(e=this.drumOutputs.get(t.pitch)),e}}class E extends k{constructor(t){super(!0,t)}}class _ extends M{constructor(t){super(!1,t),this.outputs=[],this.outputChannel=0,this.availableOutputs=[],this.NOTE_ON=144,this.NOTE_OFF=128}async requestMIDIAccess(){return navigator.requestMIDIAccess?new Promise((t,e)=>{navigator.requestMIDIAccess().then(e=>{e.addEventListener("statechange",t=>this.initOutputs(e)),t(this.initOutputs(e))},t=>console.log("Something went wrong",e(t)))}):null}initOutputs(t){const e=t.outputs.values();for(let t=e.next();t&&!t.done;t=e.next())this.availableOutputs.push(t.value);return this.availableOutputs}playNote(t,e){const n=e.velocity||100,r=1e3*(e.endTime-e.startTime),i=[this.NOTE_ON+this.outputChannel,e.pitch,n],o=[this.NOTE_OFF+this.outputChannel,e.pitch,n],s=this.outputs?this.outputs:this.availableOutputs;for(let t=0;tthis.midiReady(t),t=>console.log("Something went wrong",t))}midiReady(t){a.log("Initialized Recorder","Recorder");const e=t.inputs.values();for(let t=e.next();t&&!t.done;t=e.next())this.midiInputs.push(t.value)}isRecording(){return this.recording}setTempo(t){this.config.qpm=t,"started"===h.Transport.state&&(h.Transport.bpm.value=t)}enablePlayClick(t){this.config.playClick=t}enablePlayCountIn(t){this.config.playCountIn=t}initClickLoop(){let t=0;this.clickLoop=new h.Loop(e=>{t%4==0?this.loClick.triggerAttack("G5",e):this.hiClick.triggerAttack("C6",e),t++,this.config.playCountIn&&4===t&&(h.Transport.stop(),this.clickLoop.stop())},"4n")}getMIDIInputs(){return this.midiInputs}start(t){const e=t||this.midiInputs;for(const t of e)t.onmidimessage=t=>{this.midiMessageReceived(t)};if(this.config.playClick||this.config.playCountIn?(this.initClickLoop(),h.Transport.bpm.value=this.config.qpm,h.Transport.start(),this.clickLoop.start()):this.clickLoop=null,this.recording=!0,this.firstNoteTimestamp=void 0,this.notes=[],this.onNotes=new Map,!this.startRecordingAtFirstNote){const t=Date.now();this.firstNoteTimestamp=t}}stop(){this.recording=!1;const t=Date.now();this.onNotes.forEach((e,n)=>{this.noteOff(n,t)});for(const t of this.midiInputs)t.onmidimessage=null;return this.clickLoop&&(h.Transport.stop(),this.clickLoop.stop()),0===this.notes.length?null:this.getNoteSequence()}getNoteSequence(){return 0===this.notes.length?null:g.a.create({notes:this.notes,totalTime:this.notes[this.notes.length-1].endTime})}reset(){const t=this.stop();return this.firstNoteTimestamp=void 0,this.notes=[],this.onNotes=new Map,t}midiMessageReceived(t){if(!this.recording)return;let e;e=void 0!==t.timeStamp&&0!==t.timeStamp?t.timeStamp:d.d.now();const n=e+d.d.timing.navigationStart;void 0===this.firstNoteTimestamp&&(this.firstNoteTimestamp=n);const r=t.data[0]>>4,i=t.data[1],o=t.data.length>2?t.data[2]:1,s=t.srcElement;8===r||9===r&&0===o?(this.callbackObject&&this.callbackObject.noteOff&&this.callbackObject.noteOff(i,o,s),this.noteOff(i,n),this.callbackObject&&this.callbackObject.run&&this.callbackObject.run(this.getNoteSequence())):9===r&&(this.callbackObject&&this.callbackObject.noteOn&&this.callbackObject.noteOn(i,o,s),this.noteOn(i,o,n))}noteOn(t,e,n){const r=new g.a.Note;r.pitch=t,r.startTime=(n-this.firstNoteTimestamp)/1e3,r.velocity=e,this.onNotes.set(t,r)}noteOff(t,e){const n=this.onNotes.get(t);n&&(n.endTime=(e-this.firstNoteTimestamp)/1e3,this.notes.push(n)),this.onNotes.delete(t)}}var z=n(83);class D{constructor(t,e={}){const n=l.isQuantizedSequence(t),r=t.tempos&&t.tempos.length>0?t.tempos[0].qpm:void 0;this.noteSequence=n?l.unquantizeSequence(t,r):t;this.config={noteHeight:e.noteHeight||6,noteSpacing:e.noteSpacing||1,pixelsPerTimeStep:e.pixelsPerTimeStep||30,noteRGB:e.noteRGB||"8, 41, 64",activeNoteRGB:e.activeNoteRGB||"240, 84, 119",minPitch:e.minPitch,maxPitch:e.maxPitch};const i=this.getSize();this.width=i.width,this.height=i.height}updateMinMaxPitches(t=!1){if(!this.config.minPitch||!this.config.maxPitch){void 0===this.config.minPitch&&(this.config.minPitch=o.MAX_MIDI_PITCH),void 0===this.config.maxPitch&&(this.config.maxPitch=o.MIN_MIDI_PITCH);for(const t of this.noteSequence.notes)this.config.minPitch=Math.min(t.pitch,this.config.minPitch),this.config.maxPitch=Math.max(t.pitch,this.config.maxPitch);t||(this.config.minPitch-=2,this.config.maxPitch+=2)}}getSize(){this.updateMinMaxPitches();const t=(this.config.maxPitch-this.config.minPitch)*this.config.noteHeight,e=this.noteSequence.totalTime;if(!e)throw new Error("The sequence you are using with the visualizer does not have a totalQuantizedSteps or totalTime field set, so the visualizer can't be horizontally sized correctly.");return{width:e*this.config.pixelsPerTimeStep,height:t}}getNotePosition(t,e){const n=this.getNoteEndTime(t)-this.getNoteStartTime(t),r=this.getNoteStartTime(t)*this.config.pixelsPerTimeStep,i=Math.max(this.config.pixelsPerTimeStep*n-this.config.noteSpacing,1);return{x:r,y:this.height-(t.pitch-this.config.minPitch)*this.config.noteHeight,w:i,h:this.config.noteHeight}}scrollIntoViewIfNeeded(t,e){if(t&&this.parentElement){const t=this.parentElement.getBoundingClientRect().width;e>this.parentElement.scrollLeft+t&&(this.parentElement.scrollLeft=e-20)}}getNoteStartTime(t){return Math.round(1e8*t.startTime)/1e8}getNoteEndTime(t){return Math.round(1e8*t.endTime)/1e8}isPaintingActiveNote(t,e){const n=this.getNoteStartTime(t)===this.getNoteStartTime(e),r=this.getNoteStartTime(t)<=this.getNoteStartTime(e)&&this.getNoteEndTime(t)>=this.getNoteEndTime(e);return n||r}}class j extends D{constructor(t,e,n={}){super(t,n),this.ctx=e.getContext("2d"),this.parentElement=e.parentElement;const r=window.devicePixelRatio||1;this.ctx&&(this.ctx.canvas.width=r*this.width,this.ctx.canvas.height=r*this.height,e.style.width=this.width+"px",e.style.height=this.height+"px",this.ctx.scale(r,r)),this.redraw()}redraw(t,e){let n;this.clear();for(let e=0;e{void 0!==e&&(a.dataset[t]=""+e)}),s.forEach(([t,e])=>{a.style.setProperty(t,e)}),this.svg.appendChild(a)}clear(){this.svg.innerHTML="",this.drawn=!1}clearActiveNotes(){this.unfillActiveRect(this.svg)}}class B extends R{constructor(t,e,n={}){if(super(t,n),!(e instanceof SVGSVGElement))throw new Error("This visualizer requires an element to display the visualization");this.svg=e,this.parentElement=e.parentElement;const r=this.getSize();this.width=r.width,this.height=r.height,this.svg.style.width=this.width+"px",this.svg.style.height=this.height+"px",this.clear(),this.draw()}}class U extends R{constructor(t,e,n={}){if(super(t,n),this.NOTES_PER_OCTAVE=12,this.WHITE_NOTES_PER_OCTAVE=7,this.LOW_C=24,this.firstDrawnOctave=0,this.lastDrawnOctave=6,!(e instanceof HTMLDivElement))throw new Error("This visualizer requires a
element to display the visualization");this.config.whiteNoteWidth=n.whiteNoteWidth||20,this.config.blackNoteWidth=n.blackNoteWidth||2*this.config.whiteNoteWidth/3,this.config.whiteNoteHeight=n.whiteNoteHeight||70,this.config.blackNoteHeight=n.blackNoteHeight||140/3,this.config.showOnlyOctavesUsed=n.showOnlyOctavesUsed,this.setupDOM(e);const r=this.getSize();this.width=r.width,this.height=r.height,this.svg.style.width=this.width+"px",this.svg.style.height=this.height+"px",this.svgPiano.style.width=this.width+"px",this.svgPiano.style.height=this.config.whiteNoteHeight+"px",this.parentElement.style.width=this.width+this.config.whiteNoteWidth+"px",this.parentElement.scrollTop=this.parentElement.scrollHeight,this.clear(),this.drawPiano(),this.draw()}setupDOM(t){this.parentElement=document.createElement("div"),this.parentElement.classList.add("waterfall-notes-container");const e=Math.max(t.getBoundingClientRect().height,200);this.parentElement.style.paddingTop=e-this.config.whiteNoteHeight+"px",this.parentElement.style.height=e-this.config.whiteNoteHeight+"px",this.parentElement.style.boxSizing="border-box",this.parentElement.style.overflowX="hidden",this.parentElement.style.overflowY="auto",this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svgPiano=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.classList.add("waterfall-notes"),this.svgPiano.classList.add("waterfall-piano"),this.parentElement.appendChild(this.svg),t.innerHTML="",t.appendChild(this.parentElement),t.appendChild(this.svgPiano)}redraw(t,e){if(this.drawn||this.draw(),!t)return null;this.clearActiveNotes(),this.parentElement.style.paddingTop=this.parentElement.style.height;for(let e=0;ethis.config.minPitch&&(this.firstDrawnOctave=t-1,e=!0),!n&&r>this.config.maxPitch&&(this.lastDrawnOctave=t-1,n=!0)}t=(this.lastDrawnOctave-this.firstDrawnOctave+1)*this.WHITE_NOTES_PER_OCTAVE}const e=t*this.config.whiteNoteWidth,n=this.noteSequence.totalTime;if(!n)throw new Error("The sequence you are using with the visualizer does not have a totalQuantizedSteps or totalTime field set, so the visualizer can't be horizontally sized correctly.");return{width:e,height:Math.max(n*this.config.pixelsPerTimeStep,1)}}getNotePosition(t,e){const n=this.svgPiano.querySelector(`rect[data-pitch="${t.pitch}"]`);if(!n)return null;const r=this.getNoteEndTime(t)-this.getNoteStartTime(t),i=Number(n.getAttribute("x")),o=Number(n.getAttribute("width")),s=Math.max(this.config.pixelsPerTimeStep*r-this.config.noteSpacing,1);return{x:i,y:this.height-this.getNoteStartTime(t)*this.config.pixelsPerTimeStep-s,w:o,h:s}}drawPiano(){this.svgPiano.innerHTML="";const t=this.config.whiteNoteWidth-this.config.blackNoteWidth/2,e=[1,3,6,8,10];let n=0,r=0;this.config.showOnlyOctavesUsed?r=this.firstDrawnOctave*this.NOTES_PER_OCTAVE+this.LOW_C:(r=this.LOW_C-3,this.drawWhiteKey(r,n),this.drawWhiteKey(r+2,this.config.whiteNoteWidth),r+=3,n=2*this.config.whiteNoteWidth);for(let t=this.firstDrawnOctave;t<=this.lastDrawnOctave;t++)for(let t=0;t=0}timeToQuarters(t){const e=t*this.noteSequence.tempos[0].qpm/60;return Math.round(16*e)/16}getNoteInfo(t){const e=this.timeToQuarters(t.startTime);return{start:e,length:this.timeToQuarters(t.endTime)-e,pitch:t.pitch,intensity:t.velocity}}getScoreInfo(t){const e=[];return t.notes.forEach(t=>{this.isNoteInInstruments(t)&&e.push(this.getNoteInfo(t))}),{notes:e,tempos:t.tempos?t.tempos.map(t=>({start:this.timeToQuarters(t.time),qpm:t.qpm})):[],keySignatures:t.keySignatures?t.keySignatures.map(t=>({start:this.timeToQuarters(t.time),key:t.key})):[],timeSignatures:t.timeSignatures?t.timeSignatures.map(t=>({start:this.timeToQuarters(t.time),numerator:t.numerator,denominator:t.denominator})):[]}}clearActiveNotes(){this.redraw()}}},,,,,,function(t,e,n){e.parseMidi=n(172),e.writeMidi=n(173)},function(t,e,n){"use strict";function r(t,e,n){void 0===n&&(n="ticks");var r=0,i=t.length,o=i;if(i>0&&t[i-1][n]<=e)return i-1;for(;re)return s;a[n]>e?o=s:a[n]=t.absoluteTime}));if(-1!==e){var n=s.splice(e,1)[0];l.addNote({durationTicks:n.absoluteTime-t.absoluteTime,midi:t.noteNumber,noteOffVelocity:n.velocity/127,ticks:t.absoluteTime,velocity:t.velocity/127})}},l=this;i.length;)u();t.filter((function(t){return"controller"===t.type})).forEach((function(t){n.addCC({number:t.controllerType,ticks:t.absoluteTime,value:t.value/127})})),t.filter((function(t){return"pitchBend"===t.type})).forEach((function(t){n.addPitchBend({ticks:t.absoluteTime,value:t.value/Math.pow(2,13)})}))}}return t.prototype.addNote=function(t){var e=c.get(this),n=new u.Note({midi:0,ticks:0,velocity:1},{ticks:0,velocity:0},e);return Object.assign(n,t),r.insert(this.notes,n,"ticks"),this},t.prototype.addCC=function(t){var e=c.get(this),n=new i.ControlChange({controllerType:t.number},e);return delete t.number,Object.assign(n,t),Array.isArray(this.controlChanges[n.number])||(this.controlChanges[n.number]=[]),r.insert(this.controlChanges[n.number],n,"ticks"),this},t.prototype.addPitchBend=function(t){var e=c.get(this),n=new s.PitchBend({},e);return Object.assign(n,t),r.insert(this.pitchBends,n,"ticks"),this},Object.defineProperty(t.prototype,"duration",{get:function(){if(!this.notes.length)return 0;for(var t=this.notes[this.notes.length-1].time+this.notes[this.notes.length-1].duration,e=0;e{this.lastKnownScrollLeft=this.parentElement.scrollLeft,this.ticking||window.requestAnimationFrame(()=>{this.changeAndDrawSignaturesIfNeeded(this.lastKnownScrollLeft),this.ticking=!1}),this.ticking=!0},this.scoreInfo=t,this.config={noteHeight:e.noteHeight||6,noteSpacing:e.noteSpacing||1,pixelsPerTimeStep:e.pixelsPerTimeStep||30,noteRGB:e.noteRGB||"8, 41, 64",activeNoteRGB:e.activeNoteRGB||"240, 84, 119"},this.div=n,this.timeSignatureNumerator=4,this.timeSignatureDenominator=4,this.key=e.defaultKey||0,this.scrollType=e.scrollType||c.PAGE,this.scale=this.config.noteHeight/o.PATH_SCALE,(void 0===e.pixelsPerTimeStep||e.pixelsPerTimeStep<=0)&&(this.config.pixelsPerTimeStep=0,this.config.noteSpacing=r.COMPACT_SPACING*this.scale),this.clear(),this.redraw()}clear(){for(;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.overflow="visible",this.div.style.position="relative",this.overlaySVG=document.createElementNS(i.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.div.appendChild(this.overlaySVG),this.overlayG=Object(i.createSVGGroupChild)(this.overlaySVG,"overlay"),this.signaturesBlinking=!1,this.signaturesQuarters=0,this.parentElement=document.createElement("div"),this.parentElement.style.overflow="auto",this.div.appendChild(this.parentElement),this.ticking=!1,this.lastKnownScrollLeft=0,this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.staffSVG=document.createElementNS(i.SVGNS,"svg"),this.parentElement.appendChild(this.staffSVG),this.staffG=Object(i.createSVGGroupChild)(this.staffSVG,"staff"),this.linesG=Object(i.createSVGGroupChild)(this.staffSVG,"lines"),this.setStroke(this.linesG),this.staffG.appendChild(this.linesG),this.musicG=Object(i.createSVGGroupChild)(this.staffSVG,"music"),this.setFill(this.musicG),this.setStroke(this.musicG,0),this.staffG.appendChild(this.musicG),this.signaturesG=Object(i.createSVGGroupChild)(this.staffSVG,"signatures"),this.staffG.appendChild(this.signaturesG);let t=0,e=0;this.scoreInfo.notes.forEach(n=>{t+=n.pitch,++e});const n=t/e;this.clef=n<60?50:71,this.signaturesList=[{x:0,q:0}],this.signatureCurrent=0,this.signatureNext=0,this.changeKeySignatureIfNeeded(0),this.changeTimeSignatureIfNeeded(0),this.vStepSize=this.config.noteHeight/2,this.hStepSize=this.config.pixelsPerTimeStep,this.staffOffset=0,this.height=0,this.width=0,this.musicBlockMap=new Map,this.playingNotes=[],this.lastBar=0,this.barAccidentals={},this.lastQ=-1}isPaintingActiveNote(t,e){const n=t.start===e.start,r=t.start<=e.start&&t.start+t.length>=e.start+e.length;return n||r}redraw(t,e){let n=-1;const r=0===this.config.pixelsPerTimeStep;if(t){const o=[];this.playingNotes.forEach(e=>{this.isPaintingActiveNote(e,t)?o.push(e):this.highlightElement(this.getGroup(e),!1)}),this.playingNotes=o;const s=this.getGroup(t);if(s){this.playingNotes.push(t),this.highlightElement(s,!0),n=s.getBoundingClientRect().left-this.staffSVG.getBoundingClientRect().left;const o=t.start,a=s.getAttribute("data-is-bar-beginning");(this.scrollType!==c.BAR||a)&&this.scrollIntoViewIfNeeded(e,n),!r&&this.signaturesBlinking&&o>=this.signaturesQuarters&&(this.signaturesBlinking=!1,Object(i.setFade)(this.overlayG,this.signaturesBlinking))}}else{this.setDetails();const t=-1===this.lastQ;let e=0,n=0;t?(n=this.drawSignatures(this.overlayG,e,!0,!0,!0),r&&(this.width=0,n+=this.config.noteSpacing),n+=this.drawRests(this.initialRest,e+n)):e=this.width,this.musicBlockMap.forEach((t,i)=>{r||(e=this.quartersToTime(i)*this.hStepSize),i>this.lastQ?(n+=this.drawMusicBlock(t,e+n),this.lastQ=i):i===this.lastQ&&(n+=this.drawRests(t,e+n))});const i=this.staffSVG.getBoundingClientRect(),o=this.musicG.getBoundingClientRect();if(this.updateVerticalBoundaries(o.top-i.top,o.bottom-i.top),r)this.width+=n;else{const t=this.musicBlockMap.get(this.lastQ),e=this.quartersToTime(this.lastQ+t.notes[0].length);this.width=e*this.config.pixelsPerTimeStep}this.staffSVG.setAttributeNS(null,"width",""+this.width),this.redrawStaff(this.linesG,0,this.width)}return n}drawMusicBlock(t,e){const n=t.notes[0].start;let s=this.drawBarIfNeeded(n,e);s+=this.drawSignaturesIfNeeded(n,e+s);let a=0;for(let e=4;e>=r.MIN_RESOLUTION&&!a;e/=2)e<=t.notes[0].length&&(a=e);if(0===a){const e=0===t.notes[0].length?"[infinite]":""+4/t.notes[0].length;console.warn(" StaffRender ","background:orange; color:white",`StaffRender does not handle notes shorther than 1/${4/r.MIN_RESOLUTION}th, and this score tries to draw a 1/${e}th. Shortest possible note will be drawn instead.`),a=r.MIN_RESOLUTION}const u=o.NOTE_PATHS[a];let c;if(u.stemAnchor&&(c=Object(i.createSVGGroupChild)(this.musicG,"stem")),t.notes.forEach(n=>{const r=n.vSteps*this.vStepSize,c=2*(n.vSteps>0?Math.floor(n.vSteps/2):Math.ceil(n.vSteps/2)),l=n.vSteps>0?-2:2;for(let t=c;Math.abs(t)>4;t+=l)Object(i.drawSVGPath)(this.linesG,o.extraLinePath,e+s,t*this.vStepSize,this.scale,1);if(n.g=n.tiedFrom?n.tiedFrom.g:Object(i.createSVGGroupChild)(this.musicG,`${n.start}-${n.pitch}`),t.isBarBeginning&&n.g.setAttribute("data-is-bar-beginning","true"),n.tiedFrom){const t=e+s-n.tiedFrom.xHeadRight;Object(i.drawSVGPath)(n.g,o.tiePath,n.tiedFrom.xHeadRight,r,t/o.PATH_SCALE,this.scale*(n.vSteps<0?-1:1),n.opacity)}Object(i.drawSVGPath)(n.g,u.path,e+s,r,this.scale,this.scale,n.opacity),n.xHeadRight=e+s+u.width*this.scale,1.5*a<=n.length&&Object(i.drawSVGPath)(n.g,o.dotPath,e+s+u.width*this.scale+this.vStepSize/2,r-this.vStepSize/2,this.scale,this.scale,n.opacity),0!==n.accidental&&Object(i.drawSVGPath)(n.g,o.ACCIDENTAL_PATHS[n.accidental],e+s,r,this.scale,this.scale,n.opacity)}),u.stemAnchor){let n,a,l=e+s;const h=u.stemAnchor*this.scale,p=t.minVStep+t.maxVStep<0,f=u.flags>2?2*(u.flags-2):0;if(p?(n=t.maxVStep*this.vStepSize-h,a=(t.minVStep+7+f)*this.vStepSize):(l+=(u.width-r.STEM_WIDTH)*this.scale,n=t.minVStep*this.vStepSize+h,a=(t.maxVStep-7-f)*this.vStepSize),Object(i.drawSVGPath)(c,o.stemPath,l,n,this.scale,(a-n)/o.PATH_SCALE),1===u.flags)Object(i.drawSVGPath)(c,o.singleFlagPath,l,a,this.scale,this.scale*(p?-1:1),1);else if(u.flags>1)for(let t=0;t=r&&(this.config.pixelsPerTimeStep>0?e-=this.config.noteSpacing:n=this.config.noteSpacing,Object(i.drawSVGPath)(this.linesG,o.barPath,e,0,1,this.scale),this.lastBar=r),n}drawRests(t,e){let n=0,s=t.restToNextLength;if(s){this.config.pixelsPerTimeStep>0&&(e+=this.quartersToTime(t.notes[0].length)*this.hStepSize);let a=t.notes[0].start+t.notes[0].length,u=0;const c=this.lastBar+this.getBarLength()-a;let l;for(s>c&&(u=s-c,s=c),l=4;l>this.getBarLength()&&l>=r.MIN_RESOLUTION;l/=2);let h=l;for(;(s||u)&&h>=r.MIN_RESOLUTION;){if(h<=s){n+=this.drawBarIfNeeded(a,e+n),n+=this.drawSignaturesIfNeeded(a,e+n);const t=Object(i.drawSVGPath)(this.musicG,o.REST_PATHS[h],e+n,0,this.scale,this.scale);this.config.pixelsPerTimeStep>0?e+=this.quartersToTime(h)*this.hStepSize:(n+=t.getBoundingClientRect().width,n+=this.config.noteSpacing),a+=h,s-=h}if(u&&s<=0){const t=this.getBarLength();for(u>t?(s=t,u-=t):(s=u,u=0),l=4;l>this.getBarLength()&&l>=r.MIN_RESOLUTION;l/=2);h=l}s0?3:2);this.signaturesList.push({x:e-a,q:t}),null===this.signatureNext&&(this.signatureNext=e);const u=t>0?Object(i.createSVGGroupChild)(this.signaturesG,"signatures"):this.overlayG;n+=this.drawSignatures(u,e+n,!1,o,s)}return 0===this.config.pixelsPerTimeStep?n:0}drawSignatures(t,e,n,s,u){const c=r.COMPACT_SPACING*this.scale;let l,h=c;const p=t===this.overlayG||this.config.pixelsPerTimeStep>0;if(p){(l=document.createElementNS(i.SVGNS,"rect")).setAttributeNS(null,"x",""+e),l.setAttributeNS(null,"y","0"),l.setAttributeNS(null,"width","1"),l.setAttributeNS(null,"height","1"),l.setAttribute("data-id","background"),t.appendChild(l);const n=document.defaultView.getComputedStyle(this.div.parentElement);l.setAttributeNS(null,"fill",n.getPropertyValue("background-color"))}if(n){const n=Object(i.drawSVGPath)(t,o.CLEF_PATHS[this.clef].path,e+h,0,this.scale,this.scale);this.setFill(n),h+=3*c}if(s){const n=a[this.key].accidental,r=71===this.clef?0:14;a[this.key].pitches.forEach(s=>{const a=this.getPitchDetails(s).vSteps,u=Object(i.drawSVGPath)(t,o.ACCIDENTAL_PATHS[n],e+h,(r+a)*this.vStepSize,this.scale,this.scale);this.setFill(u),h+=u.getBoundingClientRect().width})}if(u){const n=Object(i.createSVGGroupChild)(t,"time-key"),r=2.85*this.config.noteHeight+"px";Object(i.drawSVGText)(n,""+this.timeSignatureNumerator,e+h,-.5,r,!0),Object(i.drawSVGText)(n,""+this.timeSignatureDenominator,e+h,4*this.vStepSize-.5,r,!0),this.setFill(n),h+=n.getBoundingClientRect().width+c}const f=this.redrawStaff(t,e,h);this.setStroke(f);const m=this.div.getBoundingClientRect(),d=t.getBoundingClientRect();if(this.updateVerticalBoundaries(d.top-m.top,d.bottom-m.top),p&&(l.setAttributeNS(null,"y",""+-this.staffOffset),l.setAttributeNS(null,"height",""+this.height),l.setAttributeNS(null,"width",""+h)),t===this.overlayG){this.overlaySVG.setAttributeNS(null,"width",""+(h+5));for(let e=0;e<5;++e){const n=Object(i.drawSVGPath)(t,o.stemPath,h+e,e*e-this.staffOffset,1/r.STEM_WIDTH,(this.height-2*e*e)/o.PATH_SCALE,(e-5)*(e-5)*2/o.PATH_SCALE);this.setFill(n)}}if(this.config.pixelsPerTimeStep>0){const n=0===this.signaturesQuarters;return n&&(this.signaturesQuarters=this.timeToQuarters(h/this.hStepSize)),(n||e>0)&&(this.signaturesBlinking=!0,Object(i.setFade)(t,this.signaturesBlinking)),0}return h}changeKeySignatureIfNeeded(t){if(this.scoreInfo.keySignatures){let e=this.key;for(let n=0;n0&&0===t&&(this.signatureNext=0,this.signaturesBlinking=!0,Object(i.setFade)(this.overlayG,this.signaturesBlinking))}getBarLength(){return 4*this.timeSignatureNumerator/this.timeSignatureDenominator}scrollIntoViewIfNeeded(t,e){if(t)if(this.scrollType===c.PAGE){const t=this.parentElement.getBoundingClientRect().width;e>this.parentElement.scrollLeft+t&&(this.parentElement.scrollLeft=e-20)}else{const t=this.parentElement.getBoundingClientRect().width;this.parentElement.scrollLeft=e-.5*t}}updateVerticalBoundaries(t,e){let n=0;if(t<0){this.staffOffset-=t;const e=`translate(0, ${this.staffOffset})`;this.overlayG.setAttributeNS(null,"transform",e),this.staffG.setAttributeNS(null,"transform",e),n=this.height-t}if((n=Math.max(n,e-t))>this.height){this.height=n,this.overlaySVG.setAttributeNS(null,"height",""+this.height),this.staffSVG.setAttributeNS(null,"height",""+this.height);const t=this.div.querySelectorAll('rect[data-id="background"]');for(let e=0;e{t.start+t.length>e&&(e=t.start+t.length)});const n=this.scoreInfo.timeSignatures?this.scoreInfo.timeSignatures.slice(0):[{start:0,numerator:4,denominator:4}];n.sort((t,e)=>t.start-e.start);let r=0;for(let i=0;it.start-e.start).forEach(e=>{const r=this.getQNote(e);n.add(r.start),n.add(r.start+r.length),t.has(r.start)?t.get(r.start).push(r):t.set(r.start,[r])}),Array.from(n).sort((t,e)=>t-e).forEach(e=>{const n=[];t.forEach(t=>{t.forEach(t=>{const r=this.splitQNote(t,e);r&&n.push(r)})}),n.forEach(e=>{t.has(e.start)?t.get(e.start).push(e):t.set(e.start,[e])})}),t=new Map(Array.from(t).sort((t,e)=>t[0]-e[0]));const r=this.key;let i=null,o=0;const s=e[Symbol.iterator]();let a=s.next();t.forEach((t,e)=>{const n={maxVStep:Number.MAX_SAFE_INTEGER,minVStep:Number.MIN_SAFE_INTEGER,restToNextLength:0,isBarBeginning:!1,notes:[]};this.changeKeySignatureIfNeeded(e);const r=a.value+this.getBarLength();!a.done&&e>=r&&(a=s.next(),this.barAccidentals={},n.isBarBeginning=!0),t.forEach(t=>{this.analyzePitch(t,e),n.minVStep=Math.max(t.vSteps,n.minVStep),n.maxVStep=Math.min(t.vSteps,n.maxVStep),n.notes.push(t)}),i&&(i.restToNextLength=e-o),this.musicBlockMap.set(e,n),i=n,o=e+n.notes[0].length}),this.initialRest={maxVStep:0,minVStep:0,restToNextLength:this.musicBlockMap.values().next().value.notes[0].start,isBarBeginning:!0,notes:[{start:0,length:0,vSteps:0,accidental:0,opacity:0,pitch:0,xHeadRight:0}]},this.key=r}getQNote(t){return{start:t.start,length:t.length,vSteps:0,accidental:0,opacity:this.getOpacity(t.intensity),pitch:t.pitch,xHeadRight:0}}splitQNote(t,e){const n=t.start+t.length-e;return e>t.start&&n>0?(t.length-=n,{start:e,length:n,vSteps:t.vSteps,accidental:t.accidental,opacity:t.opacity,pitch:t.pitch,xHeadRight:0,tiedFrom:t}):null}analyzePitch(t,e){const n=this.getPitchDetails(t.pitch);n.vSteps in this.barAccidentals?n.accidental===this.barAccidentals[n.vSteps]?n.accidental=0:(3===this.barAccidentals[n.vSteps]?n.accidental=n.keyAccidental:0===n.accidental&&(n.accidental=3),this.barAccidentals[n.vSteps]=n.accidental):(t.tiedFrom&&(n.accidental=0),this.barAccidentals[n.vSteps]=n.accidental),t.vSteps=n.vSteps,t.accidental=n.accidental}getPitchDetails(t){const e=t-60,n=Math.floor(e/12),r=e-12*n,i=s[this.key].steps[r],o=71===this.clef?6:-6,u=1===a[this.key].accidental?69+(r+3)%12:64+(r+8)%12;return{vSteps:o-7*n+i,accidental:s[this.key].accidental[r],keyAccidental:a[this.key].pitches.indexOf(u)>-1?a[this.key].accidental:0}}}},function(t,e,n){"use strict";n.r(e);var r=n(3);n.d(e,"MAX_QUARTER_DIVISION",(function(){return r.MAX_QUARTER_DIVISION})),n.d(e,"ScrollType",(function(){return r.ScrollType})),n.d(e,"StaffSVGRender",(function(){return r.StaffSVGRender}))}])},,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,function(t,e){function n(t){for(var e,n=new r(t),i=[];!n.eof();){var o=s();i.push(o)}return i;function s(){var t={};t.deltaTime=n.readVarInt();var r=n.readUInt8();if(240==(240&r)){if(255!==r){if(240==r){t.type="sysEx";o=n.readVarInt();return t.data=n.readBytes(o),t}if(247==r){t.type="endSysEx";o=n.readVarInt();return t.data=n.readBytes(o),t}throw"Unrecognised MIDI event type byte: "+r}t.meta=!0;var i=n.readUInt8(),o=n.readVarInt();switch(i){case 0:if(t.type="sequenceNumber",2!==o)throw"Expected length for sequenceNumber event is 2, got "+o;return t.number=n.readUInt16(),t;case 1:return t.type="text",t.text=n.readString(o),t;case 2:return t.type="copyrightNotice",t.text=n.readString(o),t;case 3:return t.type="trackName",t.text=n.readString(o),t;case 4:return t.type="instrumentName",t.text=n.readString(o),t;case 5:return t.type="lyrics",t.text=n.readString(o),t;case 6:return t.type="marker",t.text=n.readString(o),t;case 7:return t.type="cuePoint",t.text=n.readString(o),t;case 32:if(t.type="channelPrefix",1!=o)throw"Expected length for channelPrefix event is 1, got "+o;return t.channel=n.readUInt8(),t;case 33:if(t.type="portPrefix",1!=o)throw"Expected length for portPrefix event is 1, got "+o;return t.port=n.readUInt8(),t;case 47:if(t.type="endOfTrack",0!=o)throw"Expected length for endOfTrack event is 0, got "+o;return t;case 81:if(t.type="setTempo",3!=o)throw"Expected length for setTempo event is 3, got "+o;return t.microsecondsPerBeat=n.readUInt24(),t;case 84:if(t.type="smpteOffset",5!=o)throw"Expected length for smpteOffset event is 5, got "+o;var s=n.readUInt8();return t.frameRate={0:24,32:25,64:29,96:30}[96&s],t.hour=31&s,t.min=n.readUInt8(),t.sec=n.readUInt8(),t.frame=n.readUInt8(),t.subFrame=n.readUInt8(),t;case 88:if(t.type="timeSignature",4!=o)throw"Expected length for timeSignature event is 4, got "+o;return t.numerator=n.readUInt8(),t.denominator=1<>4;switch(t.channel=15&r,u){case 8:return t.type="noteOff",t.noteNumber=a,t.velocity=n.readUInt8(),t;case 9:var c=n.readUInt8();return t.type=0===c?"noteOff":"noteOn",t.noteNumber=a,t.velocity=c,0===c&&(t.byte9=!0),t;case 10:return t.type="noteAftertouch",t.noteNumber=a,t.amount=n.readUInt8(),t;case 11:return t.type="controller",t.controllerType=a,t.value=n.readUInt8(),t;case 12:return t.type="programChange",t.programNumber=a,t;case 13:return t.type="channelAftertouch",t.amount=a,t;case 14:return t.type="pitchBend",t.value=a+(n.readUInt8()<<7)-8192,t;default:throw"Unrecognised MIDI event type: "+u}}}}function r(t){this.buffer=t,this.bufferLen=this.buffer.length,this.pos=0}r.prototype.eof=function(){return this.pos>=this.bufferLen},r.prototype.readUInt8=function(){var t=this.buffer[this.pos];return this.pos+=1,t},r.prototype.readInt8=function(){var t=this.readUInt8();return 128&t?t-256:t},r.prototype.readUInt16=function(){return(this.readUInt8()<<8)+this.readUInt8()},r.prototype.readInt16=function(){var t=this.readUInt16();return 32768&t?t-65536:t},r.prototype.readUInt24=function(){return(this.readUInt8()<<16)+(this.readUInt8()<<8)+this.readUInt8()},r.prototype.readInt24=function(){var t=this.readUInt24();return 8388608&t?t-16777216:t},r.prototype.readUInt32=function(){return(this.readUInt8()<<24)+(this.readUInt8()<<16)+(this.readUInt8()<<8)+this.readUInt8()},r.prototype.readBytes=function(t){var e=this.buffer.slice(this.pos,this.pos+t);return this.pos+=t,e},r.prototype.readString=function(t){var e=this.readBytes(t);return String.fromCharCode.apply(null,e)},r.prototype.readVarInt=function(){for(var t=0;!this.eof();){var e=this.readUInt8();if(!(128&e))return t+e;t+=127&e,t<<=7}return t},r.prototype.readChunk=function(){var t=this.readString(4),e=this.readUInt32();return{id:t,length:e,data:this.readBytes(e)}},t.exports=function(t){var e=new r(t),i=e.readChunk();if("MThd"!=i.id)throw"Bad MIDI file. Expected 'MHdr', got: '"+i.id+"'";for(var o=function(t){var e=new r(t),n=e.readUInt16(),i=e.readUInt16(),o={format:n,numTracks:i},s=e.readUInt16();32768&s?(o.framesPerSecond=256-(s>>8),o.ticksPerFrame=255&s):o.ticksPerBeat=s;return o}(i.data),s=[],a=0;!e.eof()&&a>7&127;t.writeUInt8(p),t.writeUInt8(f);break;default:throw"Unrecognized event type: "+i}return u}function i(){this.buffer=[]}i.prototype.writeUInt8=function(t){this.buffer.push(255&t)},i.prototype.writeInt8=i.prototype.writeUInt8,i.prototype.writeUInt16=function(t){var e=t>>8&255,n=255&t;this.writeUInt8(e),this.writeUInt8(n)},i.prototype.writeInt16=i.prototype.writeUInt16,i.prototype.writeUInt24=function(t){var e=t>>16&255,n=t>>8&255,r=255&t;this.writeUInt8(e),this.writeUInt8(n),this.writeUInt8(r)},i.prototype.writeInt24=i.prototype.writeUInt24,i.prototype.writeUInt32=function(t){var e=t>>24&255,n=t>>16&255,r=t>>8&255,i=255&t;this.writeUInt8(e),this.writeUInt8(n),this.writeUInt8(r),this.writeUInt8(i)},i.prototype.writeInt32=i.prototype.writeUInt32,i.prototype.writeBytes=function(t){this.buffer=this.buffer.concat(Array.prototype.slice.call(t,0))},i.prototype.writeString=function(t){var e,n=t.length,r=[];for(e=0;e>=7;e;){var r=127&e|128;n.push(r),e>>=7}this.writeBytes(n.reverse())}},i.prototype.writeChunk=function(t,e){this.writeString(t),this.writeUInt32(e.length),this.writeBytes(e)},t.exports=function(t,e){if("object"!=typeof t)throw"Invalid MIDI data";e=e||{};var r,o=t.header||{},s=t.tracks||[],a=s.length,u=new i;for(function(t,e,n){var r=null==e.format?1:e.format,o=128;e.timeDivision?o=e.timeDivision:e.ticksPerFrame&&e.framesPerSecond?o=-(255&e.framesPerSecond)<<8|255&e.ticksPerFrame:e.ticksPerBeat&&(o=32767&e.ticksPerBeat);var s=new i;s.writeUInt16(r),s.writeUInt16(n),s.writeUInt16(o),t.writeChunk("MThd",s.buffer)}(u,o,a),r=0;r-1&&Array.isArray(o)?t(o,n,r):n.push(o)}return n}(t,[],e)}t.exports=function(t){if(!Array.isArray(t))throw new TypeError("Expected value to be an array");return r(t)},t.exports.from=r,t.exports.depth=function(t,e){if(!Array.isArray(t))throw new TypeError("Expected value to be an array");return i(t,e)},t.exports.fromDepth=i},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(82);e.createControlChanges=function(){return new Proxy({},{get:function(t,e){return t[e]?t[e]:r.controlChangeIds.hasOwnProperty(e)?t[r.controlChangeIds[e]]:void 0},set:function(t,e,n){return r.controlChangeIds.hasOwnProperty(e)?t[r.controlChangeIds[e]]=n:t[e]=n,!0}})}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=new WeakMap,i=function(){function t(t,e){r.set(this,e),this.ticks=t.absoluteTime,this.value=t.value}return Object.defineProperty(t.prototype,"time",{get:function(){return r.get(this).ticksToSeconds(this.ticks)},set:function(t){var e=r.get(this);this.ticks=e.secondsToTicks(t)},enumerable:!0,configurable:!0}),t.prototype.toJSON=function(){return{ticks:this.ticks,time:this.time,value:this.value}},t}();e.PitchBend=i},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(179),i=new WeakMap,o=function(){function t(t,e){if(this.number=0,i.set(this,e),this.number=0,t){var n=t.find((function(t){return"programChange"===t.type}));n&&(this.number=n.programNumber)}}return Object.defineProperty(t.prototype,"name",{get:function(){return this.percussion?r.DrumKitByPatchID[this.number]:r.instrumentByPatchID[this.number]},set:function(t){var e=r.instrumentByPatchID.indexOf(t);-1!==e&&(this.number=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"family",{get:function(){return this.percussion?"drums":r.InstrumentFamilyByID[Math.floor(this.number/8)]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"percussion",{get:function(){return 9===i.get(this).channel},enumerable:!0,configurable:!0}),t.prototype.toJSON=function(){return{family:this.family,name:this.name,number:this.number}},t.prototype.fromJSON=function(t){this.number=t.number},t}();e.Instrument=o},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.instrumentByPatchID=["acoustic grand piano","bright acoustic piano","electric grand piano","honky-tonk piano","electric piano 1","electric piano 2","harpsichord","clavi","celesta","glockenspiel","music box","vibraphone","marimba","xylophone","tubular bells","dulcimer","drawbar organ","percussive organ","rock organ","church organ","reed organ","accordion","harmonica","tango accordion","acoustic guitar (nylon)","acoustic guitar (steel)","electric guitar (jazz)","electric guitar (clean)","electric guitar (muted)","overdriven guitar","distortion guitar","guitar harmonics","acoustic bass","electric bass (finger)","electric bass (pick)","fretless bass","slap bass 1","slap bass 2","synth bass 1","synth bass 2","violin","viola","cello","contrabass","tremolo strings","pizzicato strings","orchestral harp","timpani","string ensemble 1","string ensemble 2","synthstrings 1","synthstrings 2","choir aahs","voice oohs","synth voice","orchestra hit","trumpet","trombone","tuba","muted trumpet","french horn","brass section","synthbrass 1","synthbrass 2","soprano sax","alto sax","tenor sax","baritone sax","oboe","english horn","bassoon","clarinet","piccolo","flute","recorder","pan flute","blown bottle","shakuhachi","whistle","ocarina","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)","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)","fx 1 (rain)","fx 2 (soundtrack)","fx 3 (crystal)","fx 4 (atmosphere)","fx 5 (brightness)","fx 6 (goblins)","fx 7 (echoes)","fx 8 (sci-fi)","sitar","banjo","shamisen","koto","kalimba","bag pipe","fiddle","shanai","tinkle bell","agogo","steel drums","woodblock","taiko drum","melodic tom","synth drum","reverse cymbal","guitar fret noise","breath noise","seashore","bird tweet","telephone ring","helicopter","applause","gunshot"],e.InstrumentFamilyByID=["piano","chromatic percussion","organ","guitar","bass","strings","ensemble","brass","reed","pipe","synth lead","synth pad","synth effects","world","percussive","sound effects"],e.DrumKitByPatchID={0:"standard kit",8:"room kit",16:"power kit",24:"electronic kit",25:"tr-808 kit",32:"jazz kit",40:"brush kit",48:"orchestra kit",56:"sound fx kit"}},function(t,e,n){"use strict";function r(t){return["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"][t%12]}Object.defineProperty(e,"__esModule",{value:!0});var i,o,s=(i=/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i,o={cbb:-2,cb:-1,c:0,"c#":1,cx:2,dbb:0,db:1,d:2,"d#":3,dx:4,ebb:2,eb:3,e:4,"e#":5,ex:6,fbb:3,fb:4,f:5,"f#":6,fx:7,gbb:5,gb:6,g:7,"g#":8,gx:9,abb:7,ab:8,a:9,"a#":10,ax:11,bbb:9,bb:10,b:11,"b#":12,bx:13},function(t){var e=i.exec(t),n=e[1],r=e[2];return o[n.toLowerCase()]+12*(parseInt(r,10)+1)}),a=new WeakMap,u=function(){function t(t,e,n){a.set(this,n),this.midi=t.midi,this.velocity=t.velocity,this.noteOffVelocity=e.velocity,this.ticks=t.ticks,this.durationTicks=e.ticks-t.ticks}return Object.defineProperty(t.prototype,"name",{get:function(){return t=this.midi,e=Math.floor(t/12)-1,r(t)+e.toString();var t,e},set:function(t){this.midi=s(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"octave",{get:function(){return Math.floor(this.midi/12)-1},set:function(t){var e=t-this.octave;this.midi+=12*e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pitch",{get:function(){return r(this.midi)},set:function(t){this.midi=12*(this.octave+1)+["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"].indexOf(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"duration",{get:function(){var t=a.get(this);return t.ticksToSeconds(this.ticks+this.durationTicks)-t.ticksToSeconds(this.ticks)},set:function(t){var e=a.get(this).secondsToTicks(this.time+t);this.durationTicks=e-this.ticks},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"time",{get:function(){return a.get(this).ticksToSeconds(this.ticks)},set:function(t){var e=a.get(this);this.ticks=e.secondsToTicks(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bars",{get:function(){return a.get(this).ticksToMeasures(this.ticks)},enumerable:!0,configurable:!0}),t.prototype.toJSON=function(){return{duration:this.duration,durationTicks:this.durationTicks,midi:this.midi,name:this.name,ticks:this.ticks,time:this.time,velocity:this.velocity}},t}();e.Note=u}])}));; !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";function e(e){var t=!0,n=!1,o=null,d={text:!0,search:!0,url:!0,tel:!0,email:!0,password:!0,number:!0,date:!0,month:!0,week:!0,time:!0,datetime:!0,"datetime-local":!0};function i(e){return!!(e&&e!==document&&"HTML"!==e.nodeName&&"BODY"!==e.nodeName&&"classList"in e&&"contains"in e.classList)}function s(e){e.classList.contains("focus-visible")||(e.classList.add("focus-visible"),e.setAttribute("data-focus-visible-added",""))}function u(e){t=!1}function a(){document.addEventListener("mousemove",c),document.addEventListener("mousedown",c),document.addEventListener("mouseup",c),document.addEventListener("pointermove",c),document.addEventListener("pointerdown",c),document.addEventListener("pointerup",c),document.addEventListener("touchmove",c),document.addEventListener("touchstart",c),document.addEventListener("touchend",c)}function c(e){e.target.nodeName&&"html"===e.target.nodeName.toLowerCase()||(t=!1,document.removeEventListener("mousemove",c),document.removeEventListener("mousedown",c),document.removeEventListener("mouseup",c),document.removeEventListener("pointermove",c),document.removeEventListener("pointerdown",c),document.removeEventListener("pointerup",c),document.removeEventListener("touchmove",c),document.removeEventListener("touchstart",c),document.removeEventListener("touchend",c))}document.addEventListener("keydown",function(n){n.metaKey||n.altKey||n.ctrlKey||(i(e.activeElement)&&s(e.activeElement),t=!0)},!0),document.addEventListener("mousedown",u,!0),document.addEventListener("pointerdown",u,!0),document.addEventListener("touchstart",u,!0),document.addEventListener("visibilitychange",function(e){"hidden"===document.visibilityState&&(n&&(t=!0),a())},!0),a(),e.addEventListener("focus",function(e){var n,o,u;i(e.target)&&(t||(n=e.target,o=n.type,"INPUT"===(u=n.tagName)&&d[o]&&!n.readOnly||"TEXTAREA"===u&&!n.readOnly||n.isContentEditable))&&s(e.target)},!0),e.addEventListener("blur",function(e){var t;i(e.target)&&(e.target.classList.contains("focus-visible")||e.target.hasAttribute("data-focus-visible-added"))&&(n=!0,window.clearTimeout(o),o=window.setTimeout(function(){n=!1},100),(t=e.target).hasAttribute("data-focus-visible-added")&&(t.classList.remove("focus-visible"),t.removeAttribute("data-focus-visible-added")))},!0),e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&e.host?e.host.setAttribute("data-js-focus-visible",""):e.nodeType===Node.DOCUMENT_NODE&&(document.documentElement.classList.add("js-focus-visible"),document.documentElement.setAttribute("data-js-focus-visible",""))}if("undefined"!=typeof window&&"undefined"!=typeof document){var t;window.applyFocusVisiblePolyfill=e;try{t=new CustomEvent("focus-visible-polyfill-ready")}catch(e){(t=document.createEvent("CustomEvent")).initCustomEvent("focus-visible-polyfill-ready",!1,!1,{})}window.dispatchEvent(t)}"undefined"!=typeof document&&e(document)}); ; /** * html-midi-player@1.4.0 * https://github.com/cifkao/html-midi-player.git * @author Ondřej Cífka (@cifkao) * @license BSD-2-Clause */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@magenta/music/esm/core.js")):"function"==typeof define&&define.amd?define(["exports","@magenta/music/esm/core.js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).midiPlayer={},t.core)}(this,(function(t,e){"use strict";function n(t,e,n,i,s,r,o){try{var a=t[r](o),l=a.value}catch(t){return void n(t)}a.done?e(l):Promise.resolve(l).then(i,s)}function i(t){return function(){var e=this,i=arguments;return new Promise((function(s,r){var o=t.apply(e,i);function a(t){n(o,s,r,a,l,"next",t)}function l(t){n(o,s,r,a,l,"throw",t)}a(void 0)}))}}var s=document.createElement("template");s.innerHTML="\n\n
\n \n
0:00 / 0:00
\n \n
\n
\n');var r=document.createElement("template");function o(t){var e=t<0,n=(t=Math.floor(Math.abs(t||0)))%60,i=(t-n)/60,s=(t-n-60*i)/3600,r=n>9?"".concat(n):"0".concat(n),o=i>9||!s?"".concat(i,":"):"0".concat(i,":");return(e?"-":"")+(s?"".concat(s,":"):"")+o+r}r.innerHTML="\n\n\n\n");var a=["piano-roll","waterfall","staff"];class l extends HTMLElement{constructor(){super(...arguments),this.domInitialized=!1,this.ns=null,this._config={}}static get observedAttributes(){return["src","type"]}connectedCallback(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(r.content.cloneNode(!0)),this.domInitialized||(this.domInitialized=!0,this.wrapper=document.createElement("div"),this.appendChild(this.wrapper),this.initVisualizerNow())}attributeChangedCallback(t,e,n){"src"!==t&&"type"!==t||this.initVisualizer()}initVisualizer(){null==this.initTimeout&&(this.initTimeout=window.setTimeout(()=>this.initVisualizerNow()))}initVisualizerNow(){var t=this;return i((function*(){if(t.initTimeout=null,t.domInitialized&&(t.src&&(t.ns=null,t.ns=yield e.urlToNoteSequence(t.src)),t.wrapper.innerHTML="",t.ns))if("piano-roll"===t.type){t.wrapper.classList.add("piano-roll-visualizer");var n=document.createElementNS("http://www.w3.org/2000/svg","svg");t.wrapper.appendChild(n),t.visualizer=new e.PianoRollSVGVisualizer(t.ns,n,t._config)}else if("waterfall"===t.type)t.wrapper.classList.add("waterfall-visualizer"),t.visualizer=new e.WaterfallSVGVisualizer(t.ns,t.wrapper,t._config);else if("staff"===t.type){t.wrapper.classList.add("staff-visualizer");var i=document.createElement("div");t.wrapper.appendChild(i),t.visualizer=new e.StaffSVGVisualizer(t.ns,i,t._config)}}))()}redraw(t){this.visualizer&&this.visualizer.redraw(t,null!=t)}clearActiveNotes(){this.visualizer&&this.visualizer.clearActiveNotes()}get noteSequence(){return this.ns}set noteSequence(t){this.ns=t,this.removeAttribute("src"),this.initVisualizer()}get src(){return this.getAttribute("src")}set src(t){this.ns=null,this.setOrRemoveAttribute("src",t),this.initVisualizer()}get type(){var t=this.getAttribute("type");return a.indexOf(t)<0&&(t="piano-roll"),t}set type(t){if(null!=t&&a.indexOf(t)<0)throw new Error("Unknown visualizer type ".concat(t,". Allowed values: ").concat(a.join(", ")));this.setOrRemoveAttribute("type",t)}get config(){return this._config}set config(t){this._config=t,this.initVisualizer()}setOrRemoveAttribute(t,e){null==e?this.removeAttribute(t):this.setAttribute(t,e)}}var c=["start","stop","note"],d=null;class u extends HTMLElement{constructor(){super(),this.domInitialized=!1,this.needInitNs=!1,this.visualizerListeners=new Map,this.ns=null,this._playing=!1,this.seeking=!1,this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(s.content.cloneNode(!0)),this.controlPanel=this.shadowRoot.querySelector(".controls"),this.playButton=this.controlPanel.querySelector(".play"),this.currentTimeLabel=this.controlPanel.querySelector(".current-time"),this.totalTimeLabel=this.controlPanel.querySelector(".total-time"),this.seekBar=this.controlPanel.querySelector(".seek-bar")}static get observedAttributes(){return["sound-font","src","visualizer"]}connectedCallback(){if(!this.domInitialized){this.domInitialized=!0;var t=window.applyFocusVisiblePolyfill;null!=t&&t(this.shadowRoot),this.playButton.addEventListener("click",()=>{this.player.isPlaying()?this.stop():this.start()}),this.seekBar.addEventListener("input",()=>{this.seeking=!0,this.player&&"started"===this.player.getPlayState()&&this.player.pause()}),this.seekBar.addEventListener("change",()=>{var t=this.currentTime;this.currentTimeLabel.textContent=o(t),this.player&&this.player.isPlaying()&&(this.player.seekTo(t),"paused"===this.player.getPlayState()&&this.player.resume()),this.seeking=!1}),this.initPlayerNow()}}attributeChangedCallback(t,e,n){if(this.hasAttribute(t)||(n=null),"sound-font"===t||"src"===t)this.initPlayer();else if("visualizer"===t){var i=()=>{this.setVisualizerSelector(n)};"loading"===document.readyState?window.addEventListener("DOMContentLoaded",i):i()}}initPlayer(t=!0){this.needInitNs=this.needInitNs||t,null==this.initTimeout&&(this.stop(),this.setLoading(),this.initTimeout=window.setTimeout(()=>this.initPlayerNow(this.needInitNs)))}initPlayerNow(t=!0){var n=this;return i((function*(){if(n.initTimeout=null,n.needInitNs=!1,n.domInitialized)try{var i;if(t&&(n.src&&(n.ns=null,n.ns=yield e.urlToNoteSequence(n.src)),n.currentTime=0,n.ns||n.setError("No content loaded")),!(i=n.ns))return n.seekBar.max="0",void(n.totalTimeLabel.textContent=o(0));n.seekBar.max=String(i.totalTime),n.totalTimeLabel.textContent=o(i.totalTime);var s=n.soundFont,r={run:t=>n.ns===i&&n.noteCallback(t),stop:()=>{}};if(null===s?n.player=new e.Player(!1,r):(""===s&&(s="https://storage.googleapis.com/magentadata/js/soundfonts/sgm_plus"),n.player=new e.SoundFontPlayer(s,void 0,void 0,void 0,r),yield n.player.loadSamples(i)),n.ns!==i)return;n.setLoaded(),n.dispatchEvent(new CustomEvent("load"))}catch(t){throw n.setError(String(t)),t}}))()}start(){var t=this;i((function*(){if(t.player)if("stopped"==t.player.getPlayState()){d&&d.playing&&d.stop(),d=t,t._playing=!0;var e=t.currentTime;0==t.ns.notes.filter(t=>t.startTime>e).length&&(e=0),t.currentTime=e,t.controlPanel.classList.remove("stopped"),t.controlPanel.classList.add("playing");try{var n=t.player.start(t.ns,void 0,e);t.dispatchEvent(new CustomEvent("start")),yield n,t.handleStop(!0)}catch(e){throw t.handleStop(),e}}else"paused"==t.player.getPlayState()&&t.player.resume()}))()}stop(){this.player&&this.player.isPlaying()&&this.player.stop(),this.handleStop(!1)}addVisualizer(t){var e={start:()=>{t.noteSequence=this.noteSequence},stop:()=>{t.clearActiveNotes()},note:e=>{t.redraw(e.detail.note)}};for(var n of c)this.addEventListener(n,e[n]);this.visualizerListeners.set(t,e)}removeVisualizer(t){var e=this.visualizerListeners.get(t);for(var n of c)this.removeEventListener(n,e[n]);this.visualizerListeners.delete(t)}noteCallback(t){this.playing&&(this.dispatchEvent(new CustomEvent("note",{detail:{note:t}})),this.seeking||(this.seekBar.value=String(t.startTime),this.currentTimeLabel.textContent=o(t.startTime)))}handleStop(t=!1){t&&(this.currentTime=this.duration),this.controlPanel.classList.remove("playing"),this.controlPanel.classList.add("stopped"),this._playing&&(this._playing=!1,this.dispatchEvent(new CustomEvent("stop",{detail:{finished:t}})))}setVisualizerSelector(t){for(var e of this.visualizerListeners.values())for(var n of c)this.removeEventListener(n,e[n]);if(this.visualizerListeners.clear(),null!=t)for(var i of document.querySelectorAll(t))i instanceof l?this.addVisualizer(i):console.warn("Selector ".concat(t," matched non-visualizer element"),i)}setLoading(){this.playButton.disabled=!0,this.seekBar.disabled=!0,this.controlPanel.classList.remove("error"),this.controlPanel.classList.add("loading","frozen"),this.controlPanel.removeAttribute("title")}setLoaded(){this.controlPanel.classList.remove("loading","frozen"),this.playButton.disabled=!1,this.seekBar.disabled=!1}setError(t){this.playButton.disabled=!0,this.seekBar.disabled=!0,this.controlPanel.classList.remove("loading","stopped","playing"),this.controlPanel.classList.add("error","frozen"),this.controlPanel.title=t}get noteSequence(){return this.ns}set noteSequence(t){this.ns=t,this.removeAttribute("src"),this.initPlayer()}get src(){return this.getAttribute("src")}set src(t){this.ns=null,this.setOrRemoveAttribute("src",t),this.initPlayer()}get soundFont(){return this.getAttribute("sound-font")}set soundFont(t){this.setOrRemoveAttribute("sound-font",t)}get currentTime(){return parseFloat(this.seekBar.value)}set currentTime(t){this.seekBar.value=String(t),this.currentTimeLabel.textContent=o(this.currentTime),this.player&&this.player.isPlaying()&&this.player.seekTo(t)}get duration(){return parseFloat(this.seekBar.max)}get playing(){return this._playing}setOrRemoveAttribute(t,e){null==e?this.removeAttribute(t):this.setAttribute(t,e)}}window.customElements.define("midi-player",u),window.customElements.define("midi-visualizer",l),t.PlayerElement=u,t.VisualizerElement=l,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=/sm/10f9c031b44c59988e22eb6eefece11c61e5f35ffb444da8d65f343bc7476cd4.map