1 line
22 KiB
JavaScript
1 line
22 KiB
JavaScript
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var n;if(typeof window!=="undefined"){n=window}else if(typeof global!=="undefined"){n=global}else if(typeof self!=="undefined"){n=self}else{n=this}n.Ciseaux=e()}})(function(){var e,n,t;return function r(e,n,t){function a(u,s){if(!n[u]){if(!e[u]){var o=typeof require=="function"&&require;if(!s&&o)return o(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[u]={exports:{}};e[u][0].call(c.exports,function(n){var t=e[u][1][n];return a(t?t:n)},c,c.exports,r,e,n,t)}return n[u].exports}var i=typeof require=="function"&&require;for(var u=0;u<t.length;u++)a(t[u]);return a}({1:[function(e,n,t){e("./lib/browser-interface")();n.exports=e("./lib")},{"./lib":5,"./lib/browser-interface":2}],2:[function(e,n,t){(function(t){"use strict";var r=e("audiodata");var a=e("./tape");var i=e("./config");var u=e("./renderer");var s=t.AudioContext||t.webkitAudioContext;function o(e){return new Promise(function(n,r){var a=new t.XMLHttpRequest;a.open("GET",e);a.responseType="arraybuffer";a.onload=function(){if(a.status===200){n(a.response)}else{r(new Error(a.statusText))}};a.onerror=function(){r(new Error(a.statusText))};a.send()})}function f(e){if(i.context===null){i.context=new s}return new Promise(function(n,t){i.context.decodeAudioData(e,function(e){n(c(e))},t)})}function c(e){return r.fromAudioBuffer(e)}function l(e){if(e instanceof a){return Promise.resolve(e.clone())}if(r.isAudioData(e)){return Promise.resolve(new a(e))}if(e instanceof t.AudioBuffer){return Promise.resolve(new a(c(e)))}if(i.context===null){i.context=new s}if(e instanceof ArrayBuffer){return f(e).then(l)}if(typeof e==="string"){return o(e).then(l)}return Promise.reject(new Error("Invalid arguments"))}function h(e){var n=arguments.length<=1||arguments[1]===undefined?0:arguments[1];n=Math.max(n,e.numberOfChannels);e.numberOfChannels=n;if(i.context===null){i.context=new s}return u.render(e).then(function(n){return r.toAudioBuffer({sampleRate:e.sampleRate,channelData:n},i.context)})}n.exports=function(){i.load=o;i.decode=f;i.from=l;i.render=h}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./config":3,"./renderer":7,"./tape":9,audiodata:11}],3:[function(e,n,t){"use strict";n.exports={context:null,sampleRate:0,load:null,decode:null,from:null,render:null}},{}],4:[function(e,n,t){"use strict";var r=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||false;r.configurable=true;if("value"in r)r.writable=true;Object.defineProperty(e,r.key,r)}}return function(n,t,r){if(t)e(n.prototype,t);if(r)e(n,r);return n}}();function a(e,n){if(!(e instanceof n)){throw new TypeError("Cannot call a class as a function")}}var i=function(){function e(n,t,r){a(this,e);this.data=n;this.beginTime=t;this.endTime=r;this.gain=1;this.pan=0;this.reverse=false;this.pitch=1;this.stretch=false}r(e,[{key:"slice",value:function n(e,t){e=this.beginTime+e*this.pitch;var r=e+t*this.pitch;e=Math.max(this.beginTime,e);r=Math.max(e,Math.min(r,this.endTime));return this.clone({beginTime:e,endTime:r})}},{key:"clone",value:function t(n){var t=new e(this.data,this.beginTime,this.endTime);t.gain=this.gain;t.pan=this.pan;t.reverse=this.reverse;t.pitch=this.pitch;t.stretch=this.stretch;if(n){Object.keys(n).forEach(function(e){t[e]=n[e]})}return t}},{key:"toJSON",value:function i(){return{data:this.data,beginTime:this.beginTime,endTime:this.endTime,gain:this.gain,pan:this.pan,reverse:this.reverse,pitch:this.pitch,stretch:this.stretch}}},{key:"duration",get:function u(){return(this.endTime-this.beginTime)/this.pitch}}]);return e}();n.exports=i},{}],5:[function(e,n,t){(function(t){"use strict";var r=e("./sequence");var a=e("./tape");var i=e("./config");var u=t.AudioContext||t.webkitAudioContext;n.exports={get context(){return i.context},set context(e){if(u&&e instanceof u){i.context=e}},load:function s(e){return i.load(e)},decode:function o(e){return i.decode(e)},Sequence:r,Tape:a,from:function f(){for(var e=arguments.length,n=Array(e),t=0;t<e;t++){n[t]=arguments[t]}if(i.from){return i.from.apply(i,n)}return Promise.resolve(new(Function.prototype.bind.apply(a,[null].concat(n))))},silence:a.silence,concat:a.concat,mix:a.mix}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./config":3,"./sequence":8,"./tape":9}],6:[function(e,n,t){(function(e){"use strict";var self=e.self||{};function t(){self.repository=[];self.onmessage=function(e){switch(e.data.type){case"transfer":self.repository[e.data.data]=e.data.buffers.map(function(e){return new Float32Array(e)});break;case"dispose":delete self.repository[e.data.data];break;case"render":self.startRendering(e.data.tape,e.data.callbackId);break;default:}};self.startRendering=function(e,n){var t=self.allocData(e);var r=t.map(function(e){return e.buffer});self.render(e,t);self.postMessage({callbackId:n,buffers:r},r)};self.allocData=function(e){var n=new Array(e.numberOfChannels);var t=Math.floor(e.duration*e.sampleRate);for(var r=0;r<n.length;r++){n[r]=new Float32Array(t)}return n};self.render=function(e,n){for(var t=0;t<e.tracks.length;t++){self.renderTrack(t,e.tracks[t],n,e.sampleRate)}};self.renderTrack=function(e,n,t,r){var a=n.some(function(e){return e.pan!==0});var i=0;for(var u=0,s=n.length;u<s;u++){var o=n[u];var f=self.repository[o.data];var c=(o.endTime-o.beginTime)/o.pitch;var l=Math.floor(c*r);if(!f){i+=l;continue}var h=Math.floor(o.beginTime*r);var m=Math.floor(o.endTime*r);var p=f.length;var d=t.length;var v=self.subarray(f,h,m);var g=self.subarray(t,i,i+l);var y=o.pitch;var b=e===0&&y===1&&!a&&o.gain===1&&!o.reverse&&p<=d&&v[0].length===g[0].length;if(b){self.mix[v.length+"->"+g.length](v,g)}else{self.process(v,g,{gain:o.gain,pan:a?Math.max(-1,Math.min(o.pan,+1)):null,reverse:!!o.reverse})}i+=l}};self.subarray=function(e,n,t){var r=new Array(e.length);for(var a=0;a<r.length;a++){r[a]=e[a].subarray(n,t)}return r};self.process=function(e,n,t){var r=new Array(e.length);var a=e.length;var i=n.length;var u;var s=e[0].length;var o=n[0].length;var f=(s-1)/(o-1);var c,l,h,m,p,d;if(t.pan!==null){p=Math.cos((t.pan+1)*.25*Math.PI);d=Math.sin((t.pan+1)*.25*Math.PI);u=Math.max(a,2)}else{u=a}m=self.mix1[u+"->"+i]||self.mix1.nop;if(t.reverse){c=n[0].length-1;l=-1}else{c=0;l=+1}for(var v=0;v<o;v++,c+=l){var g=v*f;var y=g|0;var b=Math.min(y+1,s-1);for(h=0;h<a;h++){r[h]=e[h][y]+Math.abs(g-y)*(e[h][b]-e[h][y])}if(t.pan!==null){r=self.pan[a](r,p,d)}var k=m(r);for(h=0;h<i;h++){n[h][c]+=(k[h]||0)*t.gain}}};self.pan=[];self.pan[1]=function(e,n,t){return[e[0]*n,e[0]*t]};self.pan[2]=function(e,n,t){var r=(e[0]+e[1])*.5;return[r*n,r*t]};self.pan[4]=function(e,n,t){var r=(e[0]+e[1])*.5;var a=(e[2]+e[3])*.5;return[r*n,r*t,a*n,a*t]};self.pan[6]=function(e,n,t){var r=(e[0]+e[1])*.5;var a=(e[4]+e[5])*.5;return[r*n,r*t,e[2],e[3],a*n,a*t]};self.mix={};self.mix["1->1"]=function(e,n){n[0].set(e[0])};self.mix["1->2"]=function(e,n){n[0].set(e[0]);n[1].set(e[0])};self.mix["1->4"]=function(e,n){n[0].set(e[0]);n[1].set(e[0])};self.mix["1->6"]=function(e,n){n[2].set(e[0])};self.mix["2->2"]=function(e,n){n[0].set(e[0]);n[1].set(e[1])};self.mix["2->4"]=function(e,n){n[0].set(e[0]);n[1].set(e[1])};self.mix["2->6"]=function(e,n){n[0].set(e[0]);n[1].set(e[1])};self.mix["4->4"]=function(e,n){n[0].set(e[0]);n[1].set(e[1]);n[2].set(e[2]);n[3].set(e[3])};self.mix["4->6"]=function(e,n){n[0].set(e[0]);n[1].set(e[1]);n[4].set(e[2]);n[5].set(e[3])};self.mix["6->6"]=function(e,n){n[0].set(e[0]);n[1].set(e[1]);n[2].set(e[2]);n[3].set(e[3]);n[4].set(e[4]);n[5].set(e[5])};self.mix1={};self.mix1.nop=function(e){return e};self.mix1["1->2"]=function(e){return[e[0],e[0]]};self.mix1["1->4"]=function(e){return[e[0],e[0],0,0]};self.mix1["1->6"]=function(e){return[0,0,e[0],0,0,0]};self.mix1["2->4"]=function(e){return[e[0],e[1],0,0]};self.mix1["2->6"]=function(e){return[e[0],e[1],0,0,0,0]};self.mix1["4->6"]=function(e){return[e[0],e[1],0,0,e[2],e[3]]};self.mix1["2->1"]=function(e){return[.5*(e[0]+e[1])]};self.mix1["4->1"]=function(e){return[.25*(e[0]+e[1]+e[2]+e[3])]};self.mix1["6->1"]=function(e){return[.7071*(e[0]+e[1])+e[2]+.5*(e[4]+e[5])]};self.mix1["4->2"]=function(e){return[.5*(e[0]+e[2]),.5*(e[1]+e[3])]};self.mix1["6->2"]=function(e){return[e[0]+.7071*(e[2]+e[4]),e[1]+.7071*(e[2]+e[5])]};self.mix1["6->4"]=function(e){return[e[0]+.7071*e[2],e[1]+.7071*e[2],e[4],e[5]]}}t.self=t.util=self;n.exports=t}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],7:[function(e,n,t){"use strict";var r=e("inline-worker");var a=e("./render-worker");var i=new r(a,a.self);var u=[];var s=1;i.onmessage=function(e){var n=e.data.buffers.map(function(e){return new Float32Array(e)});u[e.data.callbackId](n);u[e.data.callbackId]=null};n.exports={transfer:function o(e){var n=s++;var t=e.channelData.map(function(e){return e.buffer});i.postMessage({type:"transfer",data:n,buffers:t},t);return n},dispose:function f(e){i.postMessage({type:"dispose",data:e})},render:function c(e){var n=u.length;i.postMessage({type:"render",tape:e,callbackId:n});return new Promise(function(e){u[n]=e})},util:a.util}},{"./render-worker":6,"inline-worker":12}],8:[function(e,n,t){"use strict";var r=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||false;r.configurable=true;if("value"in r)r.writable=true;Object.defineProperty(e,r.key,r)}}return function(n,t,r){if(t)e(n.prototype,t);if(r)e(n,r);return n}}();function a(e){return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}function i(e,n){if(!(e instanceof n)){throw new TypeError("Cannot call a class as a function")}}var u=e("./tape");var s=e("./config");function o(e,n){var t=Object.keys(e);for(var r=0;r<t.length;r++){var a=/^\/(.+)?\/(\w*)$/.exec(t[r]);if(a&&new RegExp(a[1],a[2]).test(n)){return e[t[r]]}}return null}function f(e,n,t,r){var a=null;if(e.hasOwnProperty(n)){a=e[n]}else{a=o(e,n)}if(typeof a==="function"){a=a(n,t,r)}return a instanceof u?a:null}var c=function(){function e(){var n=this;i(this,e);this.pattern=this.instruments=this.durationPerStep=null;for(var t=arguments.length,r=Array(t),u=0;u<t;u++){r[u]=arguments[u]}r.forEach(function(e){if(typeof e==="string"){n.pattern=e}else if(typeof e==="number"||Array.isArray(e)){n.durationPerStep=e}else if((typeof e==="undefined"?"undefined":a(e))==="object"){n.instruments=e}})}r(e,[{key:"apply",value:function n(){var e=this.pattern;var n=this.instruments;var t=this.durationPerStep;for(var r=arguments.length,i=Array(r),o=0;o<r;o++){i[o]=arguments[o]}i.forEach(function(r){if(typeof r==="string"){e=r}else if(typeof r==="number"||Array.isArray(r)){t=r}else if((typeof r==="undefined"?"undefined":a(r))==="object"){n=r}});if(e===null||n===null||t===null){return u.silence(0)}var c=Array.isArray(t)?t:[t];return e.split("").reduce(function(e,t,r){var a=f(n,t,r,e);var i=c[r%c.length];i=Math.max(0,+i||0);if(a!==null){if(a.duration<i){e=e.concat(a,u.silence(i-a.duration))}else{e=e.concat(a.slice(0,i))}}else{e=e.concat(u.silence(i))}return e},new u(1,s.sampleRate))}}]);return e}();n.exports=c},{"./config":3,"./tape":9}],9:[function(e,n,t){"use strict";var r=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||false;r.configurable=true;if("value"in r)r.writable=true;Object.defineProperty(e,r.key,r)}}return function(n,t,r){if(t)e(n.prototype,t);if(r)e(n,r);return n}}();function a(self,e){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e&&(typeof e==="object"||typeof e==="function")?e:self}function i(e,n){if(typeof n!=="function"&&n!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof n)}e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,enumerable:false,writable:true,configurable:true}});if(n)Object.setPrototypeOf?Object.setPrototypeOf(e,n):e.__proto__=n}function u(e,n){if(!(e instanceof n)){throw new TypeError("Cannot call a class as a function")}}var s=e("audiodata");var o=e("./track");var f=e("./fragment");var c=e("./config");var l=e("./renderer");var h={};var m=function(){r(e,null,[{key:"silence",value:function n(t){return new e(1,c.sampleRate).silence(t)}},{key:"concat",value:function t(){var n;return(n=new e(1,c.sampleRate)).concat.apply(n,arguments)}},{key:"mix",value:function a(){var n;var t=(n=new e(1,c.sampleRate)).mix.apply(n,arguments);if(1<t.tracks.length){t.tracks.shift()}return t}}]);function e(n,t){u(this,e);if(s.isAudioData(n)){return new p(n)}this.tracks=[new o];this._numberOfChannels=Math.max(1,n|0);this._sampleRate=Math.max(0,t|0)||c.sampleRate}r(e,[{key:"gain",value:function i(){var n=arguments.length<=0||arguments[0]===undefined?1:arguments[0];n=h.toNumber(n);var t=new e(this.numberOfChannels,this.sampleRate);t.tracks=this.tracks.map(function(e){return e.gain(n)});return t}},{key:"pan",value:function f(){var n=arguments.length<=0||arguments[0]===undefined?0:arguments[0];n=h.toNumber(n);var t=new e(this.numberOfChannels,this.sampleRate);t.tracks=this.tracks.map(function(e){return e.pan(n)});return t}},{key:"reverse",value:function l(){var n=new e(this.numberOfChannels,this.sampleRate);n.tracks=this.tracks.map(function(e){return e.reverse()});return n}},{key:"pitch",value:function m(){var n=arguments.length<=0||arguments[0]===undefined?1:arguments[0];n=Math.max(0,h.toNumber(n));var t=new e(this.numberOfChannels,this.sampleRate);t.tracks=this.tracks.map(function(e){return e.pitch(n)});return t}},{key:"stretch",value:function d(){var n=arguments.length<=0||arguments[0]===undefined?1:arguments[0];n=Math.max(0,h.toNumber(n));var t=new e(this.numberOfChannels,this.sampleRate);t.tracks=this.tracks.map(function(e){return e.stretch(n)});return t}},{key:"clone",value:function v(){var n=new e(this.numberOfChannels,this.sampleRate);n.tracks=this.tracks.map(function(e){return e.clone()});return n}},{key:"silence",value:function g(){var n=arguments.length<=0||arguments[0]===undefined?0:arguments[0];n=Math.max(0,h.toNumber(n));var t=new e(this.numberOfChannels,this.sampleRate);if(0<n){t.tracks=this.tracks.map(function(){return o.silence(n)})}return t}},{key:"concat",value:function y(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++){t[r]=arguments[r]}t=Array.prototype.concat.apply([],t);var a=new e(this.numberOfChannels,this.sampleRate);a.tracks=this.tracks.map(function(e){return e.clone()});t.forEach(function(n){if(!(n instanceof e&&0<n.duration)){return}if(a._numberOfChannels<n._numberOfChannels){a._numberOfChannels=n._numberOfChannels}if(a.numberOfTracks<n.numberOfTracks){a=h.adjustNumberOfTracks(a,n.numberOfTracks)}if(n.numberOfTracks<a.numberOfTracks){n=h.adjustNumberOfTracks(n,a.numberOfTracks)}n.tracks.forEach(function(e,n){a.tracks[n].append(e)})});return a}},{key:"slice",value:function b(){var n=arguments.length<=0||arguments[0]===undefined?0:arguments[0];var t=arguments.length<=1||arguments[1]===undefined?Infinity:arguments[1];n=h.toNumber(n);t=Math.max(0,h.toNumber(t));if(n<0){n+=this.duration}n=Math.max(0,n);var r=new e(this.numberOfChannels,this.sampleRate);r.tracks=this.tracks.map(function(e){return e.slice(n,t)});return r}},{key:"loop",value:function k(){var n=arguments.length<=0||arguments[0]===undefined?2:arguments[0];n=Math.max(0,n|0);var t=new Array(n);for(var r=0;r<t.length;r++){t[r]=this}return new e(this.numberOfChannels,this.sampleRate).concat(t)}},{key:"fill",value:function w(){var e=arguments.length<=0||arguments[0]===undefined?this.duration:arguments[0];e=Math.max(0,h.toNumber(e));var n=this.duration;if(n===0){return this.silence(e)}var t=Math.floor(e/n);var r=e%n;return this.loop(t).concat(this.slice(0,r))}},{key:"replace",value:function x(){var e=arguments.length<=0||arguments[0]===undefined?0:arguments[0];var n=arguments.length<=1||arguments[1]===undefined?0:arguments[1];var t=arguments.length<=2||arguments[2]===undefined?null:arguments[2];e=h.toNumber(e);n=Math.max(0,h.toNumber(n));if(e<0){e+=this.duration}e=Math.max(0,e);if(typeof t==="function"){t=t(this.slice(e,n))}return this.slice(0,e).concat(t,this.slice(e+n))}},{key:"split",value:function O(){var e=arguments.length<=0||arguments[0]===undefined?2:arguments[0];e=Math.max(0,e|0);var n=new Array(e);var t=this.duration/e;for(var r=0;r<e;r++){n[r]=this.slice(t*r,t)}return n}},{key:"mix",value:function T(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++){t[r]=arguments[r]}t=Array.prototype.concat.apply([],t);var a=undefined;if(typeof t[t.length-1]==="string"){a=t.pop()}var i=new e(this.numberOfChannels,this.sampleRate);i.tracks=this.tracks.map(function(e){return e.clone()});t.forEach(function(n){if(!(n instanceof e&&0<n.duration)){return}if(i._numberOfChannels<n._numberOfChannels){i._numberOfChannels=n._numberOfChannels}if(i.duration<n.duration){i=h.adjustDuration(i,n.duration,a)}if(n.duration<i.duration){n=h.adjustDuration(n,i.duration,a)}i.tracks=i.tracks.concat(n.tracks)});return i}},{key:"render",value:function R(){if(c.render){for(var e=arguments.length,n=Array(e),t=0;t<e;t++){n[t]=arguments[t]}return c.render.apply(c,[this.toJSON()].concat(n))}return new Promise(function(e,n){n(new Error("not implemented"))})}},{key:"dispose",value:function C(){}},{key:"toJSON",value:function M(){var e=this.tracks.map(function(e){return e.toJSON()});var n=this.duration;var t=this.sampleRate;var r=this.numberOfChannels;var a=e.some(function(e){return e.some(function(e){return e.pan!==0})});if(a){r=Math.max(2,r)}return{tracks:e,duration:n,sampleRate:t,numberOfChannels:r}}},{key:"sampleRate",get:function A(){return this._sampleRate||c.sampleRate}},{key:"length",get:function j(){return Math.floor(this.duration*this.sampleRate)}},{key:"duration",get:function D(){return this.tracks[0].duration}},{key:"numberOfChannels",get:function N(){return this._numberOfChannels}},{key:"numberOfTracks",get:function P(){return this.tracks.length}}]);return e}();var p=function(e){i(n,e);function n(e){u(this,n);var t=a(this,Object.getPrototypeOf(n).call(this,s.getNumberOfChannels(e),e.sampleRate));var r=s.getDuration(e);t._data=l.transfer(e);t.tracks[0].addFragment(new f(t._data,0,r));c.sampleRate=c.sampleRate||e.sampleRate;return t}r(n,[{key:"dispose",value:function t(){l.dispose(this._data)}}]);return n}(m);h.toNumber=function(e){return+e||0};h.adjustNumberOfTracks=function(e,n){var t=new m(e.numberOfChannels,e.sampleRate);t.tracks=e.tracks.map(function(e){return e.clone()});var r=n-t.numberOfTracks;var a=t.duration;for(var i=0;i<r;i++){t.tracks.push(o.silence(a))}return t};h.adjustDuration=function(e,n,t){if(e.duration===0){return e.silence(n)}switch(t){case"fill":return e.fill(n);case"pitch":return e.pitch(e.duration/n);case"stretch":return e.stretch(e.duration/n);default:return e.concat(e.silence(n-e.duration))}};n.exports=m},{"./config":3,"./fragment":4,"./renderer":7,"./track":10,audiodata:11}],10:[function(e,n,t){"use strict";var r=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||false;r.configurable=true;if("value"in r)r.writable=true;Object.defineProperty(e,r.key,r)}}return function(n,t,r){if(t)e(n.prototype,t);if(r)e(n,r);return n}}();function a(e,n){if(!(e instanceof n)){throw new TypeError("Cannot call a class as a function")}}var i=e("./fragment");var u=function(){r(e,null,[{key:"silence",value:function n(t){return new e([new i(0,0,t)],t)}}]);function e(){var n=arguments.length<=0||arguments[0]===undefined?[]:arguments[0];var t=arguments.length<=1||arguments[1]===undefined?0:arguments[1];a(this,e);this.fragments=n;if(n.length!==0&&t===0){t=n.reduce(function(e,n){return e+n.duration},0)}this.duration=t}r(e,[{key:"gain",value:function t(n){return new e(this.fragments.map(function(e){return e.clone({gain:e.gain*n})}),this.duration)}},{key:"pan",value:function u(n){return new e(this.fragments.map(function(e){return e.clone({pan:e.pan+n})}),this.duration)}},{key:"reverse",value:function s(){return new e(this.fragments.map(function(e){return e.clone({reverse:!e.reverse})}).reverse(),this.duration)}},{key:"pitch",value:function o(n){return new e(this.fragments.map(function(e){return e.clone({pitch:e.pitch*n,stretch:false})}),0)}},{key:"stretch",value:function f(n){return new e(this.fragments.map(function(e){return e.clone({pitch:e.pitch*n,stretch:true})}),0)}},{key:"clone",value:function c(){return new e(this.fragments.slice(),this.duration)}},{key:"slice",value:function l(n,t){var r=new e;var a=Math.max(0,n);var i=t;for(var u=0;0<i&&u<this.fragments.length;u++){if(this.fragments[u].duration<=a){a-=this.fragments[u].duration}else{var s=this.fragments[u].slice(a,i);r.addFragment(s);a=0;i-=s.duration}}return r}},{key:"toJSON",value:function h(){return this.fragments.map(function(e){return e.toJSON()})}},{key:"addFragment",value:function m(e){if(e instanceof i&&0<e.duration){this.fragments.push(e);this.duration+=e.duration}return this}},{key:"append",value:function p(n){var t=this;if(n instanceof e){n.fragments.forEach(function(e){t.addFragment(e)})}return this}}]);return e}();n.exports=u},{"./fragment":4}],11:[function(e,n,t){function r(e){return!!(e&&typeof e.sampleRate==="number"&&Array.isArray(e.channelData))}function a(e){return e.sampleRate}function i(e){return e.channelData.length}function u(e){return e.channelData[0].length}function s(e){return e.channelData[0].length/e.sampleRate}function o(e,n){return e.channelData[n]}function f(e,n){var t=i(e);var r=u(e);var s=a(e);var f=n.createBuffer(t,r,s);var c;if(f.copyToChannel){for(c=0;c<t;c++){f.copyToChannel(o(e,c),c)}}else{for(c=0;c<t;c++){f.getChannelData(c).set(o(e,c))}}return f}function c(e){var n=e.sampleRate;var t=new Array(e.numberOfChannels);var r;for(r=0;r<t.length;r++){t[r]=e.getChannelData(r)}return{sampleRate:n,channelData:t}}n.exports={isAudioData:r,getSampleRate:a,getNumberOfChannels:i,getLength:u,getDuration:s,getChannelData:o,toAudioBuffer:f,fromAudioBuffer:c}},{}],12:[function(e,n,t){(function(e){var t=!!(e===e.window&&e.URL&&e.Blob&&e.Worker);function r(n,self){var r=this;var a;self=self||{};if(t){a=n.toString().trim().match(/^function\s*\w*\s*\([\w\s,]*\)\s*{([\w\W]*?)}$/)[1];return new e.Worker(e.URL.createObjectURL(new e.Blob([a],{type:"text/javascript"})))}function i(e){setTimeout(function(){r.onmessage({data:e})},0)}this.self=self;this.self.postMessage=i;setTimeout(function(){n.call(self,self)},0)}r.prototype.postMessage=function a(e){var n=this;setTimeout(function(){n.self.onmessage({data:e})},0)};n.exports=r}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}]},{},[1])(1)}); |