-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsfplayer.bundle.js
More file actions
1 lines (1 loc) · 16.3 KB
/
sfplayer.bundle.js
File metadata and controls
1 lines (1 loc) · 16.3 KB
1
(()=>{var e={710:(e,t,n)=>{var r,o,a;!function e(t,n,r){function o(i,s){if(!n[i]){if(!t[i]){if(a)return a(i,!0);var u=new Error("Cannot find module '"+i+"'");throw u.code="MODULE_NOT_FOUND",u}var c=n[i]={exports:{}};t[i][0].call(c.exports,(function(e){return o(t[i][1][e]||e)}),c,c.exports,e,t,n,r)}return n[i].exports}for(var a=void 0,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(e,t,n){"use strict";var r=e("audio-loader"),o=e("sample-player");function a(e){return/\.js(\?.*)?$/i.test(e)}function i(e,t,n){return"https://gleitz.github.io/midi-js-soundfonts/"+(t="FluidR3_GM"===t?t:"MusyngKite")+"/"+e+"-"+(n="ogg"===n?n:"mp3")+".js"}var s=e("./legacy");s.instrument=function e(t,n,s){if(1===arguments.length)return function(n,r){return e(t,n,r)};var u=s||{},c=u.isSoundfontURL||a,l=u.nameToUrl||i,f=c(n)?n:l(n,u.soundfont,u.format);return r(t,f,{only:u.only||u.notes}).then((function(e){var r=o(t,e,u).connect(u.destination?u.destination:t.destination);return r.url=f,r.name=n,r}))},s.nameToUrl=i,"object"==typeof t&&t.exports&&(t.exports=s),"undefined"!=typeof window&&(window.Soundfont=s)},{"./legacy":2,"audio-loader":6,"sample-player":10}],2:[function(e,t,n){"use strict";var r=e("note-parser");function o(e,t){if(console.warn("new Soundfont() is deprected"),console.log("Please use Soundfont.instrument() instead of new Soundfont().instrument()"),!(this instanceof o))return new o(e);this.nameToUrl=t||o.nameToUrl,this.ctx=e,this.instruments={},this.promises=[]}function a(e,t){return t=t||{},function(n,o,a,i){console.warn("The oscillator player is deprecated."),console.log("Starting with version 0.9.0 you will have to wait until the soundfont is loaded to play sounds.");var s=n>0&&n<129?+n:r.midi(n),u=s?r.midiToFreq(s,440):null;if(u){a=a||.2;var c=(i=i||{}).destination||t.destination||e.destination,l=i.vcoType||t.vcoType||"sine",f=i.gain||t.gain||.4,d=e.createOscillator();d.type=l,d.frequency.value=u;var p=e.createGain();return p.gain.value=f,d.connect(p),p.connect(c),d.start(o),a>0&&d.stop(o+a),d}}}o.prototype.onready=function(e){console.warn("deprecated API"),console.log("Please use Promise.all(Soundfont.instrument(), Soundfont.instrument()).then() instead of new Soundfont().onready()"),Promise.all(this.promises).then(e)},o.prototype.instrument=function(e,t){console.warn("new Soundfont().instrument() is deprecated."),console.log("Please use Soundfont.instrument() instead.");var n=this.ctx;if((e=e||"default")in this.instruments)return this.instruments[e];var r={name:e,play:a(n,t)};if(this.instruments[e]=r,"default"!==e){var i=o.instrument(n,e,t).then((function(e){return r.play=e.play,r}));this.promises.push(i),r.onready=function(e){console.warn("onready is deprecated. Use Soundfont.instrument().then()"),i.then(e)}}else r.onready=function(e){console.warn("onready is deprecated. Use Soundfont.instrument().then()"),e()};return r},o.loadBuffers=function(e,t,n){return console.warn("Soundfont.loadBuffers is deprecate."),console.log("Use Soundfont.instrument(..) and get buffers properties from the result."),o.instrument(e,t,n).then((function(e){return e.buffers}))},o.noteToMidi=r.midi,t.exports=o},{"note-parser":8}],3:[function(e,t,n){t.exports=function(e){var t=e.createGain(),n=t._voltage=function(e){var t=e.createBufferSource(),n=e.createBuffer(1,2,e.sampleRate);return n.getChannelData(0).set(o),t.buffer=n,t.loop=!0,t}(e),i=a(n),s=a(n),u=a(n);return t._startAmount=a(s),t._endAmount=a(u),t._multiplier=a(i),t._multiplier.connect(t),t._startAmount.connect(t),t._endAmount.connect(t),t.value=i.gain,t.startValue=s.gain,t.endValue=u.gain,t.startValue.value=0,t.endValue.value=0,Object.defineProperties(t,r),t};var r={attack:{value:0,writable:!0},decay:{value:0,writable:!0},sustain:{value:1,writable:!0},release:{value:0,writable:!0},getReleaseDuration:{value:function(){return this.release}},start:{value:function(e){var t=this._multiplier.gain,n=this._startAmount.gain,r=this._endAmount.gain;this._voltage.start(e),this._decayFrom=this._decayFrom=e+this.attack,this._startedAt=e;var o=this.sustain;t.cancelScheduledValues(e),n.cancelScheduledValues(e),r.cancelScheduledValues(e),r.setValueAtTime(0,e),this.attack?(t.setValueAtTime(0,e),t.linearRampToValueAtTime(1,e+this.attack),n.setValueAtTime(1,e),n.linearRampToValueAtTime(0,e+this.attack)):(t.setValueAtTime(1,e),n.setValueAtTime(0,e)),this.decay&&t.setTargetAtTime(o,this._decayFrom,i(this.decay))}},stop:{value:function(e,t){t&&(e-=this.release);var n=e+this.release;if(this.release){var r=this._multiplier.gain,o=this._startAmount.gain,a=this._endAmount.gain;r.cancelScheduledValues(e),o.cancelScheduledValues(e),a.cancelScheduledValues(e);var s=i(this.release);if(this.attack&&e<this._decayFrom){var u=function(e,t,n,r,o){var a=0+(o-n)/(r-n)*1;return a<=0&&(a=0),a>=1&&(a=1),a}(0,0,this._startedAt,this._decayFrom,e);r.linearRampToValueAtTime(u,e),o.linearRampToValueAtTime(1-u,e),o.setTargetAtTime(0,e,s)}a.setTargetAtTime(1,e,s),r.setTargetAtTime(0,e,s)}return this._voltage.stop(n),n}},onended:{get:function(){return this._voltage.onended},set:function(e){this._voltage.onended=e}}},o=new Float32Array([1,1]);function a(e){var t=e.context.createGain();return e.connect(t),t}function i(e){return Math.log(e+1)/Math.log(100)}},{}],4:[function(e,t,n){"use strict";t.exports={decode:function(e,t){for(var n,r,o,a=e.replace(/[^A-Za-z0-9\+\/]/g,""),i=a.length,s=t?Math.ceil((3*i+1>>2)/t)*t:3*i+1>>2,u=new Uint8Array(s),c=0,l=0,f=0;f<i;f++)if(r=3&f,c|=((o=a.charCodeAt(f))>64&&o<91?o-65:o>96&&o<123?o-71:o>47&&o<58?o+4:43===o?62:47===o?63:0)<<18-6*r,3===r||i-f==1){for(n=0;n<3&&l<s;n++,l++)u[l]=c>>>(16>>>n&24)&255;c=0}return u}}},{}],5:[function(e,t,n){"use strict";t.exports=function(e,t){return new Promise((function(n,r){var o=new XMLHttpRequest;t&&(o.responseType=t),o.open("GET",e),o.onload=function(){200===o.status?n(o.response):r(Error(o.statusText))},o.onerror=function(){r(Error("Network Error"))},o.send()}))}},{}],6:[function(e,t,n){"use strict";var r=e("./base64"),o=e("./fetch");function a(e){return function(t){return"string"==typeof t&&e.test(t)}}function i(e,t){return"string"==typeof e?e+t:"function"==typeof e?e(t):t}function s(e,t,n,r){var o,a=t instanceof ArrayBuffer?u:c(t)?l:(o=t)&&"function"==typeof o.then?f:d(t)?p:function(e){return e&&"object"==typeof e}(t)?h:m(t)?v:y(t)?g:b(t)?w:null;return a?a(e,t,n||{}):r?Promise.resolve(r):Promise.reject("Source not valid ("+t+")")}function u(e,t,n){return new Promise((function(n,r){e.decodeAudioData(t,(function(e){n(e)}),(function(){r("Can't decode audio data ("+t.slice(0,30)+"...)")}))}))}s.fetch=o;var c=a(/\.(mp3|wav|ogg)(\?.*)?$/i);function l(e,t,n){var r=i(n.from,t);return s(e,s.fetch(r,"arraybuffer"),n)}function f(e,t,n){return t.then((function(t){return s(e,t,n)}))}var d=Array.isArray;function p(e,t,n){return Promise.all(t.map((function(t){return s(e,t,n,t)})))}function h(e,t,n){var r={},o=Object.keys(t).map((function(o){if(n.only&&-1===n.only.indexOf(o))return null;var a=t[o];return s(e,a,n,a).then((function(e){r[o]=e}))}));return Promise.all(o).then((function(){return r}))}var m=a(/\.json(\?.*)?$/i);function v(e,t,n){var r=i(n.from,t);return s(e,s.fetch(r,"text").then(JSON.parse),n)}var y=a(/^data:audio/);function g(e,t,n){var o=t.indexOf(",");return s(e,r.decode(t.slice(o+1)).buffer,n)}var b=a(/\.js(\?.*)?$/i);function w(e,t,n){var r=i(n.from,t);return s(e,s.fetch(r,"text").then(T),n)}function T(e){var t=e.indexOf("MIDI.Soundfont.");if(t<0)throw Error("Invalid MIDI.js Soundfont format");t=e.indexOf("=",t)+2;var n=e.lastIndexOf(",");return JSON.parse(e.slice(t,n)+"}")}"object"==typeof t&&t.exports&&(t.exports=s),"undefined"!=typeof window&&(window.loadAudio=s)},{"./base64":4,"./fetch":5}],7:[function(e,t,i){(function(n){var s;s=function(){return function t(n,r,o){function a(s,u){if(!r[s]){if(!n[s]){var c="function"==typeof e&&e;if(!u&&c)return c(s,!0);if(i)return i(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var f=r[s]={exports:{}};n[s][0].call(f.exports,(function(e){return a(n[s][1][e]||e)}),f,f.exports,t,n,r,o)}return r[s].exports}for(var i="function"==typeof e&&e,s=0;s<o.length;s++)a(o[s]);return a}({1:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e){return new function(e){if(this._event=e,this._data=e.data,this.receivedTime=e.receivedTime,this._data&&this._data.length<2)console.warn("Illegal MIDI message of length",this._data.length);else switch(this._messageCode=240&e.data[0],this.channel=15&e.data[0],this._messageCode){case 128:this.messageType="noteoff",this.key=127&e.data[1],this.velocity=127&e.data[2];break;case 144:this.messageType="noteon",this.key=127&e.data[1],this.velocity=127&e.data[2];break;case 160:this.messageType="keypressure",this.key=127&e.data[1],this.pressure=127&e.data[2];break;case 176:this.messageType="controlchange",this.controllerNumber=127&e.data[1],this.controllerValue=127&e.data[2],120===this.controllerNumber&&0===this.controllerValue?this.channelModeMessage="allsoundoff":121===this.controllerNumber?this.channelModeMessage="resetallcontrollers":122===this.controllerNumber?0===this.controllerValue?this.channelModeMessage="localcontroloff":this.channelModeMessage="localcontrolon":123===this.controllerNumber&&0===this.controllerValue?this.channelModeMessage="allnotesoff":124===this.controllerNumber&&0===this.controllerValue?this.channelModeMessage="omnimodeoff":125===this.controllerNumber&&0===this.controllerValue?this.channelModeMessage="omnimodeon":126===this.controllerNumber?this.channelModeMessage="monomodeon":127===this.controllerNumber&&(this.channelModeMessage="polymodeon");break;case 192:this.messageType="programchange",this.program=e.data[1];break;case 208:this.messageType="channelpressure",this.pressure=127&e.data[1];break;case 224:this.messageType="pitchbendchange";var t=127&e.data[2],n=127&e.data[1];this.pitchBend=(t<<8)+n}}(e)},t.exports=n.default},{}]},{},[1])(1)},"object"==typeof i&&void 0!==t?t.exports=s():(o=[],void 0===(a="function"==typeof(r=s)?r.apply(i,o):r)||(t.exports=a))}).call(this,void 0!==n.g?n.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],8:[function(e,t,n){var i;i=function(e){"use strict";function t(e,t){return Array(t+1).join(e)}function n(e){return"number"==typeof e}function r(e,t){return Math.pow(2,(e-69)/12)*(t||440)}function o(e,t,n){if("string"!=typeof e)return null;var o=u.exec(e);if(!o||!t&&o[4])return null;var a={letter:o[1].toUpperCase(),acc:o[2].replace(/x/g,"##")};a.pc=a.letter+a.acc,a.step=(a.letter.charCodeAt(0)+3)%7,a.alt="b"===a.acc[0]?-a.acc.length:a.acc.length;var i=c[a.step]+a.alt;return a.chroma=i<0?12+i:i%12,o[3]&&(a.oct=+o[3],a.midi=i+12*(a.oct+1),a.freq=r(a.midi,n)),t&&(a.tonicOf=o[4]),a}function a(e){return n(e)?e<0?t("b",-e):t("#",e):""}function i(e){return n(e)?""+e:""}function s(e){if((n(e)||function(e){return"string"==typeof e}(e))&&e>=0&&e<128)return+e;var t=o(e);return t&&function(e){return void 0!==e}(t.midi)?t.midi:null}var u=/^([a-gA-G])(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)\s*$/,c=[0,2,4,5,7,9,11];e.regex=function(){return u},e.parse=o,e.build=function e(t,n,r){return null==t?null:t.step?e(t.step,t.alt,t.oct):t<0||t>6?null:"CDEFGAB".charAt(t)+a(n)+i(r)},e.midi=s,e.freq=function(e,t){var n=s(e);return null===n?null:r(n,t)},e.letter=function(e){return(o(e)||{}).letter},e.acc=function(e){return(o(e)||{}).acc},e.pc=function(e){return(o(e)||{}).pc},e.step=function(e){return(o(e)||{}).step},e.alt=function(e){return(o(e)||{}).alt},e.chroma=function(e){return(o(e)||{}).chroma},e.oct=function(e){return(o(e)||{}).oct}},"object"==typeof n&&void 0!==t?i(n):(o=[n],void 0===(a="function"==typeof(r=i)?r.apply(n,o):r)||(t.exports=a))},{}],9:[function(e,t,n){t.exports=function(e){return e.on=function(t,n){if(1===arguments.length&&"function"==typeof t)return e.on("event",t);var r,o,a="on"+t,i=e[a];return e[a]=i?(r=i,o=n,function(e,t,n,a){r(e,t,n,a),o(e,t,n,a)}):n,e},e}},{}],10:[function(e,t,n){"use strict";var r=e("./player"),o=e("./events"),a=e("./notes"),i=e("./scheduler"),s=e("./midi");function u(e,t,n){return s(i(a(o(r(e,t,n)))))}"object"==typeof t&&t.exports&&(t.exports=u),"undefined"!=typeof window&&(window.SamplePlayer=u)},{"./events":9,"./midi":11,"./notes":12,"./player":13,"./scheduler":14}],11:[function(e,t,n){var r=e("midimessage");t.exports=function(e){return e.listenToMidi=function(t,n){var o={},a=n||{},i=a.gain||function(e){return e/127};return t.onmidimessage=function(t){var n=t.messageType?t:r(t);if("noteon"===n.messageType&&0===n.velocity&&(n.messageType="noteoff"),!a.channel||n.channel===a.channel)switch(n.messageType){case"noteon":o[n.key]=e.play(n.key,0,{gain:i(n.velocity)});break;case"noteoff":o[n.key]&&(o[n.key].stop(),delete o[n.key])}},e},e}},{midimessage:7}],12:[function(e,t,n){"use strict";var r=e("note-parser"),o=function(e){return function(e){return null!==e&&e!==[]&&e>=0&&e<129}(e)?+e:r.midi(e)};t.exports=function(e){if(e.buffers){var t=e.opts.map,n="function"==typeof t?t:o,r=function(e){return e?n(e)||e:null};e.buffers=function(e,t){return Object.keys(e).reduce((function(n,r){return n[t(r)]=e[r],n}),{})}(e.buffers,r);var a=e.start;e.start=function(e,t,n){var o=r(e),i=o%1;return i&&(o=Math.floor(o),n=Object.assign(n||{},{cents:Math.floor(100*i)})),a(o,t,n)}}return e}},{"note-parser":15}],13:[function(e,t,n){"use strict";var r=e("adsr"),o={},a={gain:1,attack:.01,decay:.1,sustain:.9,release:.3,loop:!1,cents:0,loopStart:0,loopEnd:0};function i(e){return"number"==typeof e}var s=["attack","decay","sustain","release"];t.exports=function(e,t,n){var u=!1,c=0,l={},f=e.createGain();f.gain.value=1;var d=Object.assign({},a,n),p={context:e,out:f,opts:d};return t instanceof AudioBuffer?p.buffer=t:p.buffers=t,p.start=function(t,n,r){if(p.buffer&&null!==t)return p.start(null,t,n);var a=t?p.buffers[t]:p.buffer;if(a){if(u){var i=r||o;n=Math.max(e.currentTime,n||0),p.emit("start",n,t,i);var s=h(t,a,i);return s.id=function(t,n){return n.id=c++,l[n.id]=n,n.source.onended=function(){var t=e.currentTime;n.source.disconnect(),n.env.disconnect(),n.disconnect(),p.emit("ended",t,n.id,n)},n.id}(0,s),s.env.start(n),s.source.start(n),p.emit("started",n,s.id,s),i.duration&&s.stop(n+i.duration),s}console.warn("SamplePlayer not connected to any node.")}else console.warn("Buffer "+t+" not found.")},p.play=function(e,t,n){return p.start(e,t,n)},p.stop=function(e,t){var n;return(t=t||Object.keys(l)).map((function(t){return(n=l[t])?(n.stop(e),n.id):null}))},p.connect=function(e){return u=!0,f.connect(e),p},p.emit=function(e,t,n,r){p.onevent&&p.onevent(e,t,n,r);var o=p["on"+e];o&&o(t,n,r)},p;function h(t,n,o){var a,u=e.createGain();return u.gain.value=0,u.connect(f),u.env=function(e,t,n){var o=r(e),a=t.adsr||n.adsr;return s.forEach((function(e,r){o[e]=a?a[r]:t[e]||n[e]})),o.value.value=i(t.gain)?t.gain:i(n.gain)?n.gain:1,o}(e,o,d),u.env.connect(u.gain),u.source=e.createBufferSource(),u.source.buffer=n,u.source.connect(u),u.source.loop=o.loop||d.loop,u.source.playbackRate.value=(a=o.cents||d.cents)?Math.pow(2,a/1200):1,u.source.loopStart=o.loopStart||d.loopStart,u.source.loopEnd=o.loopEnd||d.loopEnd,u.stop=function(n){var r=n||e.currentTime;p.emit("stop",r,t);var o=u.env.stop(r);u.source.stop(o)},u}}},{adsr:3}],14:[function(e,t,n){"use strict";var r=Array.isArray,o={};t.exports=function(e){return e.schedule=function(t,n){var a,i,s,u,c=e.context.currentTime,l=t<c?c:t;return e.emit("schedule",l,n),n.map((function(t){return t?(r(t)?(a=t[0],i=t[1]):(a=t.time,i=t),function(e){return e&&"object"==typeof e}(i)?(s=i.name||i.key||i.note||i.midi||null,u=i):(s=i,u=o),e.start(s,l+(a||0),u)):null}))},e}},{}],15:[function(e,t,n){"use strict";var r=/^([a-gA-G])(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)\s*$/,o=[0,2,4,5,7,9,11];function a(e,t,n){if("string"!=typeof e)return null;var a=r.exec(e);if(!a||!t&&a[4])return null;var s={letter:a[1].toUpperCase(),acc:a[2].replace(/x/g,"##")};return s.pc=s.letter+s.acc,s.step=(s.letter.charCodeAt(0)+3)%7,s.alt="b"===s.acc[0]?-s.acc.length:s.acc.length,s.chroma=o[s.step]+s.alt,a[3]&&(s.oct=+a[3],s.midi=s.chroma+12*(s.oct+1),s.freq=i(s.midi,n)),t&&(s.tonicOf=a[4]),s}function i(e,t){return Math.pow(2,(e-69)/12)*(t||440)}var s={parse:a,regex:function(){return r},midiToFreq:i};["letter","acc","pc","step","alt","chroma","oct","midi","freq"].forEach((function(e){s[e]=function(t){var n=a(t);return n&&void 0!==n[e]?n[e]:null}})),t.exports=s},{}]},{},[1])}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var a=t[r]={exports:{}};return e[r](a,a.exports,n),a.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n(710)})();