gitbook-plugin-webpd
Version:
A webpd plugin for gitbooks
3 lines (2 loc) • 90.8 kB
JavaScript
!function(t,e,n){"use strict";function i(t){t&&(t.setTargetAtTime||(t.setTargetAtTime=t.setTargetValueAtTime))}window.hasOwnProperty("webkitAudioContext")&&!window.hasOwnProperty("AudioContext")&&(window.AudioContext=webkitAudioContext,AudioContext.prototype.hasOwnProperty("createGain")||(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),AudioContext.prototype.hasOwnProperty("createDelay")||(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),AudioContext.prototype.hasOwnProperty("createScriptProcessor")||(AudioContext.prototype.createScriptProcessor=AudioContext.prototype.createJavaScriptNode),AudioContext.prototype.hasOwnProperty("createPeriodicWave")||(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),AudioContext.prototype.internal_createGain=AudioContext.prototype.createGain,AudioContext.prototype.createGain=function(){var t=this.internal_createGain();return i(t.gain),t},AudioContext.prototype.internal_createDelay=AudioContext.prototype.createDelay,AudioContext.prototype.createDelay=function(t){var e=t?this.internal_createDelay(t):this.internal_createDelay();return i(e.delayTime),e},AudioContext.prototype.internal_createBufferSource=AudioContext.prototype.createBufferSource,AudioContext.prototype.createBufferSource=function(){var t=this.internal_createBufferSource();return t.start?(t.internal_start=t.start,t.start=function(e,n,i){"undefined"!=typeof i?t.internal_start(e||0,n,i):t.internal_start(e||0,n||0)}):t.start=function(t,e,n){e||n?this.noteGrainOn(t||0,e,n):this.noteOn(t||0)},t.stop?(t.internal_stop=t.stop,t.stop=function(e){t.internal_stop(e||0)}):t.stop=function(t){this.noteOff(t||0)},i(t.playbackRate),t},AudioContext.prototype.internal_createDynamicsCompressor=AudioContext.prototype.createDynamicsCompressor,AudioContext.prototype.createDynamicsCompressor=function(){var t=this.internal_createDynamicsCompressor();return i(t.threshold),i(t.knee),i(t.ratio),i(t.reduction),i(t.attack),i(t.release),t},AudioContext.prototype.internal_createBiquadFilter=AudioContext.prototype.createBiquadFilter,AudioContext.prototype.createBiquadFilter=function(){var t=this.internal_createBiquadFilter();return i(t.frequency),i(t.detune),i(t.Q),i(t.gain),t},AudioContext.prototype.hasOwnProperty("createOscillator")&&(AudioContext.prototype.internal_createOscillator=AudioContext.prototype.createOscillator,AudioContext.prototype.createOscillator=function(){var t=this.internal_createOscillator();return t.start?(t.internal_start=t.start,t.start=function(e){t.internal_start(e||0)}):t.start=function(t){this.noteOn(t||0)},t.stop?(t.internal_stop=t.stop,t.stop=function(e){t.internal_stop(e||0)}):t.stop=function(t){this.noteOff(t||0)},t.setPeriodicWave||(t.setPeriodicWave=t.setWaveTable),i(t.frequency),i(t.detune),t})),window.hasOwnProperty("webkitOfflineAudioContext")&&!window.hasOwnProperty("OfflineAudioContext")&&(window.OfflineAudioContext=webkitOfflineAudioContext)}(window),function t(e,n,i){function o(r,a){if(!n[r]){if(!e[r]){var u="function"==typeof require&&require;if(!a&&u)return u(r,!0);if(s)return s(r,!0);var c=new Error("Cannot find module '"+r+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[r]={exports:{}};e[r][0].call(l.exports,function(t){var n=e[r][1][t];return o(n?n:t)},l,l.exports,t,e,n,i)}return n[r].exports}for(var s="function"==typeof require&&require,r=0;r<i.length;r++)o(i[r]);return o}({1:[function(t,e,n){var i=t("underscore"),o=t("pd-fileutils.parser"),s=t("./lib/core/Patch"),r=t("./lib/core/PdObject"),a=t("./lib/core/mixins"),u=t("./lib/waa/portlets"),c=t("./lib/waa/interfaces"),l=t("./lib/global"),h=t("./lib/core/interfaces"),f=i.extend({},a.UniqueIdsMixin);t("./lib/index").declareObjects(l.library);var d=e.exports={start:function(t){if(t=t||{},!l.isStarted){"undefined"!=typeof AudioContext?(l.audio=t.audio||new c.Audio({channelCount:l.settings.channelCount,audioContext:t.audioContext}),l.clock=t.clock||new c.Clock({audioContext:l.audio.context,waaClock:t.waaClock})):(l.audio=t.audio||h.Audio,l.clock=t.clock||h.Clock),l.storage=t.storage?t.storage:"undefined"!=typeof window?new c.Storage:h.Storage,l.audio.start();for(var e in l.patches)l.patches[e].start();l.isStarted=!0}},stop:function(){if(l.isStarted){l.isStarted=!1;for(var t in l.patches)l.patches[t].stop();l.audio.stop()}},isStarted:function(){return l.isStarted},getAudio:function(){return l.audio},send:function(t,e){l.emitter.emit("msg:"+t,e)},receive:function(t,e){l.emitter.on("msg:"+t,e)},registerAbstraction:function(t,e){i.isString(e)&&(e=o.parse(e));var n=function(t,n,i){var t=new s(t,n,i);return t.patchId=f._generateId(),d._preparePatch(t,e),t};n.prototype=s.prototype,this.registerExternal(t,n)},registerExternal:function(t,e){l.library[t]=e},createPatch:function(){var t=this._createPatch();return l.isStarted&&t.start(),t},destroyPatch:function(t){t.stop(),t.destroy(),delete l.patches[t.patchId]},loadPatch:function(t){var e=this._createPatch();return i.isString(t)&&(t=o.parse(t)),this._preparePatch(e,t),l.isStarted&&e.start(),e},_createPatch:function(){var t=new s;return t.patchId=f._generateId(),l.patches[t.patchId]=t,t},_preparePatch:function(t,e){var n={};e.nodes.forEach(function(e){var i,o=e.proto;if("graph"===o){var s=e.subpatch.nodes[0];i=t._createObject("array",s.args||[]),i.setData(new Float32Array(s.data),!0),o="array"}else i=t._createObject(o,e.args||[]);"pd"===o&&d._preparePatch(i,e.subpatch),n[e.id]=i}),e.connections.forEach(function(t){var e=n[t.source.id],i=n[t.sink.id];if(!e||!i)throw new Error("invalid connection");e.o(t.source.port).connect(i.i(t.sink.port))})},core:{PdObject:r,portlets:u},_glob:l};"undefined"!=typeof window&&(window.Pd=d)},{"./lib/core/Patch":4,"./lib/core/PdObject":5,"./lib/core/interfaces":6,"./lib/core/mixins":7,"./lib/global":10,"./lib/index":12,"./lib/waa/interfaces":14,"./lib/waa/portlets":15,"pd-fileutils.parser":21,underscore:22}],2:[function(t,e,n){var i=(t("events").EventEmitter,t("underscore")),o=t("./core/utils"),s=t("./core/mixins"),r=t("./core/PdObject"),a=(t("./core/Patch"),t("./global")),u=t("./waa/portlets");n.declareObjects=function(t){var e=r.extend({inletDefs:[u.Inlet.extend({message:function(t){this.obj._onMessageReceived(t)}})],outletDefs:[u.Outlet],init:function(t,e,n,i,o){if(this._eventReceiver=new s.EventReceiver,this.value=n?o:i,t&&"-"!==t&&"empty"!==t&&(this.receiveName=t,this._onMessageReceived&&(this._onMessageReceived=this._onMessageReceived.bind(this),this._eventReceiver.on(a.emitter,"msg:"+this.receiveName,this._onMessageReceived))),e&&"-"!==e&&"empty"!==e&&(this.sendName=e),n&&this.patch){var r=this;this._onPatchStarted=function(){r._sendMessage([r.value])},this._eventReceiver.on(this.patch,"started",this._onPatchStarted)}},destroy:function(){this._eventReceiver.destroy()},_sendMessage:function(t){this.o(0).message(t),this.sendName&&a.emitter.emit("msg:"+this.sendName,t)}});t.symbolatom=e.extend({type:"symbolatom",init:function(t){var n=(t[0]||void 0,t[1]||void 0,t[2]),i=t[3];e.prototype.init.apply(this,[n,i,0,"symbol",0])},_onMessageReceived:function(t){var e=t[0];return"bang"===e||i.isNumber(e)||"symbol"===e?(i.isNumber(e)?this.value="float":"symbol"===e&&(this.value=t[1]),void this._sendMessage(o.timeTag(["symbol",this.value],t))):console.error("invalid "+e)}});var n=e.extend({init:function(t,n,o,s,r,a){this._limitInput=function(t){return i.isNumber(r)&&(t=Math.min(t,r)),i.isNumber(s)&&(t=Math.max(t,s)),t},e.prototype.init.apply(this,[n,o,t,0,a])},_onMessageReceived:function(t){var e=t[0];return"bang"===e||i.isNumber(e)?(i.isNumber(e)&&(this.value=e),void this._sendMessage(o.timeTag([this._limitInput(this.value)],t))):console.error("invalid "+e)}});t.floatatom=n.extend({type:"floatatom",init:function(t){var e=t[0]||void 0,i=t[1]||void 0,o=t[2],s=t[3];n.prototype.init.apply(this,[0,o,s,e,i,0])}}),t.nbx=n.extend({type:"nbx",init:function(t){var e=t[0]||void 0,i=t[1]||void 0,o=t[2]||0,s=t[3],r=t[4],a=t[5]||0;n.prototype.init.apply(this,[o,s,r,e,i,a])}}),t.bng=e.extend({type:"bng",init:function(t){var n=t[0]||0,i=t[1],o=t[2];e.prototype.init.apply(this,[i,o,n,"bang","bang"])},_onMessageReceived:function(t){this._sendMessage(o.timeTag(["bang"],t))}}),t.tgl=e.extend({type:"tgl",init:function(t){var n=t[0]||0,o=t[1],s=t[2],r=t[3]||0,a=i.isNumber(t[4])?t[4]:1;e.prototype.init.apply(this,[o,s,n,0,r]),this.nonZeroValue=a},_onMessageReceived:function(t){var e=t[0];if("bang"===e)this.value=0===this.value?this.nonZeroValue:0,this._sendMessage(o.timeTag([this.value],t));else{if(!i.isNumber(e))return console.error("invalid message received "+t);this.value=0===e?0:this.nonZeroValue,this._sendMessage(o.timeTag([e],t))}}});var c=n.extend({init:function(t){var e=t[0]||0,o=i.isNumber(t[1])?t[1]:127,s=t[2]||0,r=t[3],a=t[4],u=t[5]||0;n.prototype.init.apply(this,[s,r,a,e,o,u])}});t.hsl=c.extend({type:"hsl"}),t.vsl=c.extend({type:"vsl"});var l=e.extend({init:function(t){var n=(t[0],t[1]),o=i.isNumber(t[2])?t[2]:8,s=t[3],r=t[4],a=t[5]||0;this._limitInput=function(t){return Math.floor(Math.min(Math.max(t,0),o-1))},e.prototype.init.apply(this,[s,r,n,0,a])},_onMessageReceived:function(t){var e=t[0];return"bang"===e||i.isNumber(e)?(i.isNumber(e)&&(this.value=e),void this._sendMessage(o.timeTag([this._limitInput(this.value)],t))):console.error("invalid "+e)}});t.hradio=l.extend({type:"hradio"}),t.vradio=l.extend({type:"vradio"}),t.vu=e.extend({init:function(t){var n=t[0];e.prototype.init.apply(this,[n,void 0,0,0,0])},_onMessageReceived:function(t){this._sendMessage(t)}})}},{"./core/Patch":4,"./core/PdObject":5,"./core/mixins":7,"./core/utils":9,"./global":10,"./waa/portlets":15,events:16,underscore:22}],3:[function(t,e,n){var i=t("underscore"),o=(t("util").inherits,t("./portlets"),t("./utils"),e.exports=function(t,e,n){n=n||[];var i=this;this.id=e,this.patch=t,this.inlets=this.inletDefs.map(function(t,e){return new t(i,e)}),this.outlets=this.outletDefs.map(function(t,e){return new t(i,e)}),this.init(n)});i.extend(o.prototype,{endPoint:!1,doResolveArgs:!1,outletDefs:[],inletDefs:[],init:function(){},start:function(){},stop:function(){},destroy:function(){},i:function(t){if(t<this.inlets.length)return this.inlets[t];throw new Error("invalid inlet "+t)},o:function(t){if(t<this.outlets.length)return this.outlets[t];throw new Error("invalid outlet "+t)},startPortlets:function(){this.outlets.forEach(function(t){t.start()}),this.inlets.forEach(function(t){t.start()})},stopPortlets:function(){this.outlets.forEach(function(t){t.stop()}),this.inlets.forEach(function(t){t.stop()})}})},{"./portlets":8,"./utils":9,underscore:22,util:20}],4:[function(t,e,n){var i=t("underscore"),o=t("events").EventEmitter,s=t("./mixins"),r=t("./utils"),a=t("./BaseNode"),u=t("../global"),c=e.exports=function(){a.apply(this,arguments),this.objects=[],this.endPoints=[],this.patchId=null,this.blockSize=u.settings.blockSize};i.extend(c.prototype,a.prototype,s.UniqueIdsMixin,o.prototype,{type:"patch",init:function(t){this.args=t},start:function(){this._startStopGeneric("start","startPortlets","started")},stop:function(){this._startStopGeneric("stop","stopPortlets","stopped")},destroy:function(){this.objects.forEach(function(t){t.destroy()})},_startStopGeneric:function(t,e,n){var i=function(e){e instanceof c?(o.push(e),e.objects.forEach(i)):e[t]()},o=[this];this.objects.forEach(i),o.forEach(function(t){t.objects.forEach(function(t){t instanceof c||t[e]()})}),o.forEach(function(t){t.emit(n)})},createObject:function(t,e){var n=this._createObject(t,e);return u.isStarted&&(n.start(),n.startPortlets()),n},_createObject:function(t,e){var n;if(e=e||[],!u.library.hasOwnProperty(t))throw new Error("unknown object "+t);var i=u.library[t];return i.prototype.doResolveArgs&&(e=this.resolveArgs(e)),n=new i(this,this._generateId(),e),this.objects[n.id]=n,n.endPoint&&this.endPoints.push(n),l(n)&&this.inlets.push(n.inlets[0]),h(n)&&this.outlets.push(n.outlets[0]),n},resolveArgs:function(t){var e,n=t.slice(0),i=this.getPatchRoot().patchId;return e=[i].concat(this.args),t.forEach(function(t,e){"b"===t?n[e]="bang":"f"===t?n[e]="float":"s"===t?n[e]="symbol":"a"===t?n[e]="anything":"l"===t&&(n[e]="list")}),r.getDollarResolver(n)(e)},getPatchRoot:function(){for(var t=this;t.patch;)t=t.patch;return t}});var l=function(t){return[u.library.inlet,u.library["inlet~"]].some(function(e){return t instanceof e})},h=function(t){return[u.library.outlet,u.library["outlet~"]].some(function(e){return t instanceof e})}},{"../global":10,"./BaseNode":3,"./mixins":7,"./utils":9,events:16,underscore:22}],5:[function(t,e,n){var i=t("underscore"),o=(t("util").inherits,t("./portlets"),t("./utils")),s=t("./BaseNode"),r=(t("./Patch"),t("../global"),e.exports=function(){s.apply(this,arguments)});r.extend=o.chainExtend,i.extend(r.prototype,s.prototype,{doResolveArgs:!0})},{"../global":10,"./BaseNode":3,"./Patch":4,"./portlets":8,"./utils":9,underscore:22,util:20}],6:[function(t,e,n){n.Clock={time:0,schedule:function(t,e,n){},unschedule:function(t){}},n.Audio={sampleRate:44100,start:function(){},stop:function(){},decode:function(t,e){e(null,t)}},n.Storage={get:function(t,e){}}},{}],7:[function(t,e,n){var i=t("events").EventEmitter,o=t("underscore"),s=t("../global");n.NamedMixin={nameIsUnique:!1,setName:function(t){if(!o.isString(t))return console.error("expected ["+this.type+"] name to be a string, got "+t);var e=this.name;this.emit("changing:name",e,t),this.name=t,s.namedObjects.register(this,this.type,t,this.nameIsUnique,e),this.emit("changed:name",e,t)},destroy:function(){s.namedObjects.unregister(this,this.type,this.name)}};var r=n.EventEmitterMixin=o.extend({},i.prototype,{destroy:function(){this.removeAllListeners()}}),a=n.Reference=function(t){this.referencedType=t,this._onNewObject=null,this._onChangedName=null,this.resolved=null,this._eventName="namedObjects:registered:"+this.referencedType,this._eventReceiver=new u};o.extend(a.prototype,r,{set:function(t){var e=this,n=s.namedObjects.get(this.referencedType,t)[0];this.name=t,this._stopListening(),n?this._setResolved(n):(this._setResolved(null),this._onNewObject=function(n){n.name===t&&(e._stopListening(),e._setResolved(n))},this._eventReceiver.on(s.emitter,this._eventName,this._onNewObject))},destroy:function(){this._eventReceiver.destroy(),r.destroy.apply(this)},_setResolved:function(t){var e=this,n=this.resolved;this.resolved=t,n&&n.removeListener("changing:name",e._onChangedName),t&&(this._onChangedName=function(){e._setResolved(null)},this._eventReceiver.on(t,"changing:name",this._onChangedName)),this.emit("changed",t,n)},_stopListening:function(){this._onNewObject&&(this._eventReceiver.removeListener(s.emitter,this._eventName,this._onNewObject),this._onNewObject=null)}}),n.UniqueIdsMixin={_generateId:function(){return this._idCounter++,this._idCounter},_idCounter:-1};var u=n.EventReceiver=function(){this._handlers=[]};o.extend(u.prototype,{addListener:function(t,e,n){this._handlers.push([t,e,n]),t.addListener(e,n)},once:function(t,e,n){var i=[t,e,n];this._handlers.push(i),t.once(e,n)},removeListener:function(t,e,n){this._handlers=o.reject(this._handlers,function(i){var o=i[0]===t&&i[1]===e&&i[2]===n;return o&&t.removeListener(e,n),o})},destroy:function(){this._handlers.forEach(function(t){t[0].removeListener(t[1],t[2])}),this._handlers=[]}}),u.prototype.on=u.prototype.addListener},{"../global":10,events:16,underscore:22}],8:[function(t,e,n){var i=t("underscore"),o=t("./utils"),s=n.Portlet=function(t,e){this.obj=t,this.id=e,this.connections=[],this.init()};i.extend(s.prototype,{crossPatch:!1,init:function(){},start:function(){},stop:function(){},message:function(t){},connection:function(t){},disconnection:function(t){},connect:function(t){if(-1!==this.connections.indexOf(t))return!1;if(!this.crossPatch&&!t.crossPatch&&this.obj.patch!==t.obj.patch)throw new Error("cannot connect objects that belong to different patches");return this.connections.push(t),t.connect(this),this.connection(t),!0},disconnect:function(t){var e=this.connections.indexOf(t);return-1===e?!1:(this.connections.splice(e,1),t.disconnect(this),this.disconnection(t),!0)}}),s.extend=o.chainExtend;n.Inlet=s.extend({}),n.Outlet=s.extend({})},{"./utils":9,underscore:22}],9:[function(t,e,n){var i=t("underscore"),o=t("../global"),s=/\$(\d+)/,r=/\$(\d+)/g;n.getDollarResolver=function(t){t=t.slice(0);var e=function(t,e){if(e>=t.length||0>e)throw new Error("$"+(e+1)+": argument number out of range");return t[e]},n=t.map(function(t){var n=s.exec(t);return n&&n[0]===t?function(t){var i=parseInt(n[1],10);return function(t){return e(t,i)}}(t):n?function(t){for(var n,i=[];n=r.exec(t);)i.push([n[0],parseInt(n[1],10)]);return function(n){var o=t.substr(0);return i.forEach(function(t){o=o.replace(t[0],e(n,t[1]))}),o}}(t):function(t){return function(){return t}}(t)});return function(t){return n.map(function(e,n){return e(t)})}},n.chainExtend=function(){var t=Array.prototype.slice.call(arguments,0),e=this,n=function(){e.apply(this,arguments)};return n.prototype=new e,i.extend.apply(this,[n.prototype,e.prototype].concat(t)),n.extend=this.extend,n},n.timeTag=function(t,e){return e?(t.timeTag=i.isNumber(e)?e:e.timeTag,t):t},n.getTimeTag=function(t){return t&&t.timeTag||o.clock&&o.clock.time||0}},{"../global":10,underscore:22}],10:[function(t,e,n){var i=t("underscore"),o=t("events").EventEmitter;n.settings={blockSize:16384,channelCount:2},n.isStarted=!1;var s=n.emitter=new o;s.emit=function(t){if(!i.contains([],t)&&0!==t.indexOf("msg:")&&0!==t.indexOf("namedObjects:registered")&&0!==t.indexOf("namedObjects:unregistered"))throw new Error("unknown event : "+t);o.prototype.emit.apply(this,arguments)},n.library={},n.patches={},n.audio=null,n.clock=null,n.storage=null,n.namedObjects={register:function(t,e,i,o,s){var r,a;if(this._store[e]=r=this._store[e]||{},r[i]=a=r[i]||[],-1===a.indexOf(t)){if(o&&a.length>0)throw new Error("there is already a "+e+' with name "'+i+'"');a.push(t)}s&&(a=r[s],a.splice(a.indexOf(t),1)),n.emitter.emit("namedObjects:registered:"+e,t)},unregister:function(t,e,i){var o,s=this._store[e],r=s?s[i]:null;r&&(o=r.indexOf(t),-1!==o&&(r.splice(o,1),n.emitter.emit("namedObjects:unregistered:"+e,t)))},get:function(t,e){return(this._store[t]||{})[e]||[]},reset:function(){this._store={}},_store:{}}},{events:16,underscore:22}],11:[function(t,e,n){var i=t("underscore"),o=t("./core/utils"),s=t("./core/mixins"),r=t("./core/PdObject"),a=t("./core/Patch"),u=t("./global"),c=t("./waa/portlets");n.declareObjects=function(t){t.receive=t.r=r.extend(s.NamedMixin,s.EventEmitterMixin,{type:"receive",outletDefs:[c.Outlet],abbreviations:["r"],init:function(t){var e=t[0],n=this;this._eventReceiver=new s.EventReceiver,this._onMessageReceived=this._onMessageReceived.bind(this),this._eventReceiver.on(this,"changed:name",function(t,e){t&&n._eventReceiver.removeListener(u.emitter,"msg:"+t,n._onMessageReceived),n._eventReceiver.on(u.emitter,"msg:"+e,n._onMessageReceived)}),this.setName(e)},destroy:function(){s.NamedMixin.destroy.apply(this,arguments),this._eventReceiver.destroy(),s.EventEmitterMixin.destroy.apply(this,arguments)},_onMessageReceived:function(t){this.o(0).message(t)}}),t.send=t.s=r.extend(s.NamedMixin,s.EventEmitterMixin,{type:"send",inletDefs:[c.Inlet.extend({message:function(t){u.emitter.emit("msg:"+this.obj.name,t)}})],abbreviations:["s"],init:function(t){this.setName(t[0])},destroy:function(){s.NamedMixin.destroy.apply(this,arguments),s.EventEmitterMixin.destroy.apply(this,arguments)}}),t.msg=r.extend({type:"msg",doResolveArgs:!1,inletDefs:[c.Inlet.extend({message:function(t){var e=t.timeTag;t=t.slice(0),t.unshift(0),this.obj.outlets[0].message(o.timeTag(this.obj.resolver(t),e))}})],outletDefs:[c.Outlet],init:function(t){this.resolver=o.getDollarResolver(t)}}),t.print=r.extend({type:"print",inletDefs:[c.Inlet.extend({message:function(t){console.log(this.obj.prefix?[this.obj.prefix].concat(t):t)}})],init:function(t){this.prefix=t[0]||"print"}}),t.text=r.extend({type:"text",init:function(t){this.text=t[0]}}),t.loadbang=r.extend({type:"loadbang",outletDefs:[c.Outlet],init:function(){var t=this;this._eventReceiver=new s.EventReceiver,this._onPatchStarted=function(){t.o(0).message(["bang"])},this._eventReceiver.on(this.patch,"started",this._onPatchStarted)},destroy:function(){this._eventReceiver.destroy()}});var e=r.extend({inletDefs:[c.Inlet.extend({message:function(t){var e=t[0];"bang"!==e&&this.obj.setVal(e),this.obj.o(0).message(o.timeTag([this.obj.val],t))}}),c.Inlet.extend({message:function(t){var e=t[0];this.obj.setVal(e)}})],outletDefs:[c.Outlet],init:function(t){var e=t[0];this.setVal(e||0)},setVal:function(t){this.val=t}});t["float"]=t.f=e.extend({type:"float",setVal:function(t){return i.isNumber(t)?void(this.val=t):console.error("invalid [float] value "+t)}}),t["int"]=t.i=e.extend({type:"int",setVal:function(t){return i.isNumber(t)?void(this.val=Math.floor(t)):console.error("invalid [int] value "+t)}});var n=r.extend({inletDefs:[c.Inlet.extend({message:function(t){var e=t[0];i.isNumber(e)?this.obj.valLeft=e:"bang"!==e&&console.error("invalid message : "+t),this.obj.o(0).message(o.timeTag([this.obj.compute()],t))}}),c.Inlet.extend({message:function(t){var e=t[0];return i.isNumber(e)?void(this.obj.valRight=e):console.error("invalid operand for ["+this.obj.type+"] "+e)}})],outletDefs:[c.Outlet],init:function(t){this.valRight=t[0]||0,this.valLeft=0},compute:function(){}});t["+"]=n.extend({type:"+",compute:function(){return this.valLeft+this.valRight}}),t["-"]=n.extend({type:"-",compute:function(){return this.valLeft-this.valRight}}),t["*"]=n.extend({type:"*",compute:function(){return this.valLeft*this.valRight}}),t["/"]=n.extend({type:"/",compute:function(){return this.valLeft/this.valRight}}),t.mod=t["%"]=n.extend({type:"mod",compute:function(){return this.valLeft%this.valRight}}),t.pow=n.extend({type:"pow",compute:function(){return Math.pow(this.valLeft,this.valRight)}});var l=r.extend({inletDefs:[c.Inlet.extend({message:function(t){var e=t[0];this.obj.checkInput(e),this.obj.o(0).message(o.timeTag([this.obj.compute(e)],t))}})],outletDefs:[c.Outlet],checkInput:function(t){},compute:function(){}}),h=l.extend({checkInput:function(t){return i.isNumber(t)?void 0:console.error("invalid ["+this.type+"] value "+t)}});t.cos=h.extend({type:"cos",compute:function(t){return Math.cos(t)}}),t.sin=h.extend({type:"sin",compute:function(t){return Math.sin(t)}}),t.tan=h.extend({type:"tan",compute:function(t){return Math.tan(t)}}),t.atan=h.extend({type:"atan",compute:function(t){return Math.atan(t)}}),t.exp=h.extend({type:"exp",compute:function(t){return Math.exp(t)}}),t.log=h.extend({type:"log",compute:function(t){return Math.log(t)}}),t.abs=h.extend({type:"abs",compute:function(t){return Math.abs(t)}}),t.sqrt=h.extend({type:"sqrt",compute:function(t){return Math.sqrt(t)}}),t.mtof=h.extend({type:"mtof",maxMidiNote:8.17579891564*Math.exp(86.585635235),compute:function(t){var e=0;return i.isNumber(t)?e=-1500>=t?0:t>1499?this.maxMidiNote:8.17579891564*Math.exp(.057762265*t):console.error("invalid [mtof] value "+t)}}),t["samplerate~"]=l.extend({type:"samplerate~",compute:function(){return u.audio.sampleRate}}),t.spigot=r.extend({type:"spigot",inletDefs:[c.Inlet.extend({message:function(t){this.obj.passing&&this.obj.o(0).message(t)}}),c.Inlet.extend({message:function(t){var e=t[0];this.obj.setPassing(e)}})],outletDefs:[c.Outlet],init:function(t){var e=t[0];this.setPassing(e||0)},setPassing:function(t){return i.isNumber(t)?void(this.passing=Boolean(t)):console.error("invalid [spigot] value "+t)}}),t.trigger=t.t=r.extend({type:"trigger",inletDefs:[c.Inlet.extend({message:function(t){var e,n,s;for(e=this.obj.filters.length-1;e>=0;e--)if(n=this.obj.filters[e],"bang"===n)this.obj.o(e).message(o.timeTag(["bang"],t));else if("list"===n||"anything"===n)this.obj.o(e).message(t);else if("float"===n||i.isNumber(n))s=t[0],this.obj.o(e).message(i.isNumber(s)?o.timeTag([s],t):o.timeTag([0],t));else if("symbol"===n)if(s=t[0],"bang"===s)this.obj.o(e).message(o.timeTag(["symbol"],t));else if(i.isNumber(s))this.obj.o(e).message(o.timeTag(["float"],t));else{if(!i.isString(s))throw new Error("Got unexpected input "+t);this.obj.o(e).message(o.timeTag([s],t))}else this.obj.o(e).message(o.timeTag(["bang"],t))}})],init:function(t){var e,n;for(0===t.length&&(t=["bang","bang"]),e=0,n=t.length;n>e;e++)this.outlets.push(new c.Outlet(this,e));this.filters=t}});var f=c.Inlet.extend({message:function(t){var e=t[0];"bang"!==e&&(this.obj.memory[0]=e),this.obj.o(0).message(o.timeTag(this.obj.memory.slice(0),t))}}),d=c.Inlet.extend({message:function(t){var e=t[0];this.obj.memory[this.id]=e}});t.pack=r.extend({type:"pack",outletDefs:[c.Outlet],init:function(t){var e,n=t.length;for(0===n&&(t=["float","float"]),n=t.length,this.filters=t,this.memory=new Array(n),e=0;n>e;e++)this.inlets[e]=0===e?new f(this,e):new d(this,e),this.memory[e]="float"===t[e]?0:"symbol"===t[e]?"symbol":t[e]}}),t.select=t.sel=r.extend({type:"select",inletDefs:[c.Inlet.extend({message:function(t){var e,n=t[0];-1!==(e=this.obj.filters.indexOf(n))?this.obj.o(e).message(o.timeTag(["bang"],t)):this.obj.outlets.slice(-1)[0].message(o.timeTag([n],t))}}),c.Inlet.extend({message:function(t){this.obj.filters.length<=1&&(this.obj.filters=t)}})],init:function(t){var e,n;for(0===t.length&&(t=[0]),t.length>1&&this.inlets.pop(),e=0,n=t.length;n>e;e++)this.outlets[e]=new c.Outlet(this,e);this.outlets[e]=new c.Outlet(this,e),this.filters=t}}),t.moses=r.extend({type:"moses",inletDefs:[c.Inlet.extend({message:function(t){var e=t[0];return i.isNumber(e)?void(e<this.obj.val?this.obj.o(0).message(o.timeTag([e],t)):this.obj.o(1).message(o.timeTag([e],t))):console.error("invalid [moses] value "+e)}}),c.Inlet.extend({message:function(t){var e=t[0];this.obj.setVal(e)}})],outletDefs:[c.Outlet,c.Outlet],init:function(t){var e=t[0];this.setVal(e||0)},setVal:function(t){return i.isNumber(t)?void(this.val=t):console.error("invalid [moses] value "+t)}}),t.until=r.extend({type:"until",inletDefs:[c.Inlet.extend({message:function(t){var e=t[0];if("bang"===e)this.obj._startLoop(t.timeTag);else{if(!i.isNumber(e))return console.error("invalid [until] value "+e);this.obj._startLoop(t.timeTag,e)}}}),c.Inlet.extend({message:function(t){var e=t[0];return"bang"!==e?console.error("invalid command for [until] "+e):void this.obj._stopLoop()}})],outletDefs:[c.Outlet],init:function(){this._looping=!1},_startLoop:function(t,e){this._looping=!0;var n=this,s=0,r=function(){n.o(0).message(o.timeTag(["bang"],t))};if(i.isNumber(e))for(;this._looping&&e>s;)r(),s++;else for(;this._looping;)r();this._looping=!1},_stopLoop:function(){this._looping=!1}}),t.random=r.extend({type:"random",inletDefs:[c.Inlet.extend({message:function(t){var e=t[0];"bang"===e&&this.obj.o(0).message(o.timeTag([Math.floor(Math.random()*this.obj.max)],t))}}),c.Inlet.extend({message:function(t){var e=t[0];this.obj.setMax(e)}})],outletDefs:[c.Outlet],init:function(t){var e=t[0];this.setMax(e||1)},setMax:function(t){return i.isNumber(t)?void(this.max=t):console.error("invalid [random] value "+t)}}),t.metro=r.extend({type:"metro",inletDefs:[c.Inlet.extend({message:function(t){var e=t[0];if("bang"===e)this.obj._restartMetroTick(o.getTimeTag(t));else if("stop"===e)this.obj._stopMetroTick();else{if(!i.isNumber(e))return console.error("invalid [metro] value "+e);0===e?this.obj._stopMetroTick():this.obj._restartMetroTick(o.getTimeTag(t))}}}),c.Inlet.extend({message:function(t){var e=t[0];this.obj.setRate(e),this.obj._metroTick=this.obj._metroTickRateChange}})],outletDefs:[c.Outlet],init:function(t){var e=t[0];this.setRate(e||0),this._metroHandle=null,this._metroTick=this._metroTickNormal},setRate:function(t){return i.isNumber(t)?void(this.rate=Math.max(t,1)):console.error("invalid [metro] rate "+t)},destroy:function(){this._stopMetroTick()},_startMetroTick:function(t){var e=this;null===this._metroHandle&&(this._metroHandle=u.clock.schedule(function(t){e._metroTick(t.timeTag)},t,this.rate))},_stopMetroTick:function(){null!==this._metroHandle&&(u.clock.unschedule(this._metroHandle),this._metroHandle=null)},_restartMetroTick:function(t){this._metroTick===this._metroTickRateChange&&(this._metroTick=this._metroTickNormal),this._stopMetroTick(),this._startMetroTick(t)},_metroTickNormal:function(t){this.outlets[0].message(o.timeTag(["bang"],t))},_metroTickRateChange:function(t){this._metroTick=this._metroTickNormal,this._restartMetroTick(t)}}),t.delay=t.del=r.extend({type:"delay",inletDefs:[c.Inlet.extend({message:function(t){var e=t[0];"bang"===e?(this.obj._stopDelay(),this.obj._startDelay(o.getTimeTag(t))):"stop"===e?this.obj._stopDelay():(this.obj.setDelay(e),this.obj._stopDelay(),this.obj._startDelay(o.getTimeTag(t)))}}),c.Inlet.extend({message:function(t){var e=t[0];this.obj.setDelay(e)}})],outletDefs:[c.Outlet],init:function(t){var e=t[0];this.setDelay(e||0),this._delayHandle=null},setDelay:function(t){return i.isNumber(t)?void(this.delay=t):console.error("invalid [delay] length "+t)},destroy:function(){this._stopDelay()},_startDelay:function(t){var e=this;null===this._delayHandle&&(this._delayHandle=u.clock.schedule(function(){e.outlets[0].message(["bang"])},t+this.delay))},_stopDelay:function(){null!==this._delayHandle&&(u.clock.unschedule(this._delayHandle),this._delayHandle=null)}}),t.timer=r.extend({type:"timer",inletDefs:[c.Inlet.extend({message:function(t){var e=t[0];return"bang"!==e?console.error("invalid command for [timer] "+e):void(this.obj.refTime=o.getTimeTag(t))}}),c.Inlet.extend({message:function(t){var e=t[0];return"bang"!==e?console.error("invalid command for [timer] "+e):void this.obj.outlets[0].message(o.timeTag([o.getTimeTag(t)-this.obj.refTime],t))}})],outletDefs:[c.Outlet],init:function(){this.refTime=0}}),t.change=r.extend({type:"change",inletDefs:[c.Inlet.extend({message:function(t){var e=t[0];e!==this.obj.last&&(this.obj.last=e,this.obj.o(0).message(o.timeTag([e],t)))}})],outletDefs:[c.Outlet],init:function(){this.last=null}}),t.array=t.table=r.extend(s.NamedMixin,s.EventEmitterMixin,{type:"array",nameIsUnique:!0,init:function(t){var e=t[0],n=t[1]||100;e&&this.setName(e),this.size=n,this.data=new Float32Array(n)},destroy:function(){s.NamedMixin.destroy.apply(this,arguments),s.EventEmitterMixin.destroy.apply(this,arguments)},setData:function(t,e){e&&(this.data=new Float32Array(t.length)),this.data.set(t.subarray(0,Math.min(this.data.length,t.length))),this.size=this.data.length,this.emit("changed:data")}}),t.soundfiler=r.extend({type:"soundfiler",inletDefs:[c.Inlet.extend({message:function(t){var e,n,o,s=this,r=t[0],a=!1;if(t=t.slice(1),"read"===r){for(;t.length&&"-"===t[0][0];){if(e=t.shift(),"-resize"!==e)return console.error("-wave"===e&&"-aiff"===e&&"-nextstep"===e&&"-raw"===e&&"-bytes"===e&&"-nframes"===e?e+" not supported":e+" not understood");a=!0}n=t.shift(),o=t,u.storage.get(n,function(t,e){return t?console.error("could not load file : "+t):void u.audio.decode(e,function(t,e){if(t)return console.error("Could not decode file : "+t);var n,r,c;r=o.map(function(t){return n=u.namedObjects.get("array",t)[0],n?n:(console.error('array "'+t+'" not found'),null)}),i.contains(r,null)||(1!==i.uniq(i.pluck(r,"size")).length&&(a=!0),r.forEach(function(t,n){c=e[n],c&&t.setData(c,a)}),s.obj.o(0).message([Math.min(r[0].size,e[0].length)]))})})}else console.error('command "'+r+'" is not supported')}})],outletDefs:[c.Outlet]}),t.pd=a}},{"./core/Patch":4,"./core/PdObject":5,"./core/mixins":7,"./core/utils":9,"./global":10,"./waa/portlets":15,underscore:22}],12:[function(t,e,n){t("underscore");n.declareObjects=function(e){t("./glue").declareObjects(e),t("./controls").declareObjects(e),t("./waa/dsp").declareObjects(e),t("./waa/portlets").declareObjects(e)}},{"./controls":2,"./glue":11,"./waa/dsp":13,"./waa/portlets":15,underscore:22}],13:[function(t,e,n){var i=t("underscore"),o=t("waaoffsetnode"),s=t("waawhitenoisenode"),r=t("waatablenode"),a=t("../core/utils"),u=t("../core/mixins"),c=t("../core/PdObject"),l=t("./portlets"),h=t("../global");
n.declareObjects=function(t){var e=c.extend({inletDefs:[l.DspInlet.extend({message:function(t){var e=t[0];if(!this.hasDspSource()){if(!i.isNumber(e))return console.error("invalid ["+this.obj.type+"] frequency "+e);e===1/0&&(e=0),this.obj.frequency=e,this.obj._updateFrequency(a.getTimeTag(t))}}}),l.Inlet.extend({message:function(t){var e=t[0];return i.isNumber(e)?void this.obj._updatePhase(e,a.getTimeTag(t)):console.error("invalid ["+this.obj.type+"] phase "+e)}})],outletDefs:[l.DspOutlet],init:function(t){this.frequency=t[0]||0},start:function(){this._createOscillator(0,0)},stop:function(){this._destroyOscillator()},_updateFrequency:function(t){this._oscNode&&this._oscNode.frequency.setValueAtTime(this.frequency,t/1e3)},_updatePhase:function(t,e){h.isStarted&&this._createOscillator(t,e)}});t["osc~"]=e.extend({type:"osc~",_createOscillator:function(t,e){t=2*t*Math.PI,this._oscNode=h.audio.context.createOscillator(),this._oscNode.setPeriodicWave(h.audio.context.createPeriodicWave(new Float32Array([0,Math.cos(t)]),new Float32Array([0,Math.sin(-t)]))),this._oscNode.start(e/1e3),this.o(0).setWaa(this._oscNode,0),this.i(0).setWaa(this._oscNode.frequency,0),this.i(0).message([this.frequency])},_destroyOscillator:function(){this._oscNode.stop(0),this._oscNode=null}}),t["phasor~"]=e.extend({type:"phasor~",_createOscillator:function(t,e){this._gainNode=h.audio.context.createGain(),this._gainNode.gain.value=.5,this._oscNode=h.audio.context.createOscillator(),this._oscNode.type="sawtooth",this._oscNode.start(e/1e3),this._oscNode.connect(this._gainNode),this._offsetNode=new o(h.audio.context),this._offsetNode.offset.value=1,this._offsetNode.connect(this._gainNode),this.o(0).setWaa(this._gainNode,0),this.i(0).setWaa(this._oscNode.frequency,0),this.i(0).message([this.frequency])},_destroyOscillator:function(){this._oscNode.stop(0),this._oscNode=null,this._gainNode=null,this._offsetNode=null}}),t["triangle~"]=e.extend({type:"triangle~",_createOscillator:function(t,e){this._oscNode=h.audio.context.createOscillator(),this._oscNode.type="triangle",this._oscNode.start(e/1e3),this.o(0).setWaa(this._oscNode,0),this.i(0).setWaa(this._oscNode.frequency,0),this.i(0).message([this.frequency])},_destroyOscillator:function(){this._oscNode.stop(0),this._oscNode=null}}),t["square~"]=e.extend({type:"square~",_createOscillator:function(t,e){this._oscNode=h.audio.context.createOscillator(),this._oscNode.type="square",this._oscNode.start(e/1e3),this.o(0).setWaa(this._oscNode,0),this.i(0).setWaa(this._oscNode.frequency,0),this.i(0).message([this.frequency])},_destroyOscillator:function(){this._oscNode.stop(0),this._oscNode=null}}),t["noise~"]=c.extend({type:"noise~",outletDefs:[l.DspOutlet],start:function(){this._noiseNode=new s(h.audio.context),this._noiseNode.start(0),this.o(0).setWaa(this._noiseNode,0)},stop:function(){this._noiseNode.stop(0),this._noiseNode.disconnect(),this._noiseNode=null}}),t["line~"]=c.extend({type:"line~",inletDefs:[l.Inlet.extend({init:function(){this._queue=[],this._lastValue=0},message:function(t){var e=this;if(this.obj._offsetNode){var n=t[0],o=a.getTimeTag(t),s=t[1]||0;if(!i.isNumber(n))return console.error("invalid [line~] value "+n);if(s&&!i.isNumber(s))return console.error("invalid [line~] duration "+s);this._refreshQueue(h.audio.time);var r=this._pushToQueue(o,n,s);this.obj._offsetNode.offset.cancelScheduledValues(r[0].t1/1e3+1e-6),r.forEach(function(t){t.t1!==t.t2?e.obj._offsetNode.offset.linearRampToValueAtTime(t.v2,t.t2/1e3):e.obj._offsetNode.offset.setValueAtTime(t.v2,t.t2/1e3)})}},_interpolate:function(t,e){return(e-t.t1)*(t.v2-t.v1)/(t.t2-t.t1)+t.v1},_refreshQueue:function(t){if(0!==this._queue.length){for(var e,n,i=0;(e=this._queue[i++])&&t>=e.t2;);n=this._queue.slice(0,i-1),this._queue=this._queue.slice(i-1),0===this._queue.length&&(this._lastValue=n[n.length-1].v2)}},_pushToQueue:function(t,e,n){for(var i,o=0,s=[];(i=this._queue[o++])&&t>=i.t2;);if(this._queue=this._queue.slice(0),this._queue.length){var r=this._queue[this._queue.length-1];t<r.t2?(this._queue=this._queue.slice(0,-1),i={t1:r.t1,v1:r.v1,t2:t,v2:this._interpolate(r,t)},s.push(i),this._queue.push(i)):t>r.t2&&(i={t1:r.t2,v1:r.v2,t2:t,v2:r.v2},s.push(i),this._queue.push(i))}else i={t1:0,v1:this._lastValue,t2:t,v2:this._lastValue},s.push(i),this._queue.push(i);return i={t1:t,v1:this._queue[this._queue.length-1].v2,t2:t+n,v2:e},s.push(i),this._queue.push(i),s}})],outletDefs:[l.DspOutlet],start:function(){this._offsetNode=new o(h.audio.context),this._offsetNode.offset.setValueAtTime(0,0),this.o(0).setWaa(this._offsetNode,0)},stop:function(){this._offsetNode=null}}),t["sig~"]=c.extend({type:"sig~",inletDefs:[l.Inlet.extend({message:function(t){var e=t[0];return i.isNumber(e)?(this.obj.value=e,void(this.obj._offsetNode&&this.obj._offsetNode.offset.setValueAtTime(e,a.getTimeTag(t)/1e3))):console.error("invalid [sig~] value "+e)}})],outletDefs:[l.DspOutlet],init:function(t){this.value=t[0]||0},start:function(){this._offsetNode=new o(h.audio.context),this._offsetNode.offset.setValueAtTime(0,0),this.o(0).setWaa(this._offsetNode,0),this.i(0).message([this.value])},stop:function(){this._offsetNode=null}});var n={message:function(t){var e=t[0];return i.isNumber(e)?(this.obj.frequency=e,void(this.obj._filterNode&&this.obj._filterNode.frequency.setValueAtTime(e,a.getTimeTag(t)/1e3))):console.error("invalid ["+this.obj.type+"] frequency "+e)}},f={message:function(t){var e=t[0];return i.isNumber(e)?(this.obj.Q=e,void(this.obj._filterNode&&this.obj._filterNode.Q.setValueAtTime(e,a.getTimeTag(t)/1e3))):console.error("invalid ["+this.obj.type+"] Q "+e)}},d=c.extend({inletDefs:[l.DspInlet,l.Inlet.extend(n)],outletDefs:[l.DspOutlet],init:function(t){this.frequency=t[0]||0},start:function(){this._filterNode=h.audio.context.createBiquadFilter(),this._filterNode.frequency.setValueAtTime(this.frequency,0),this._filterNode.type=this.waaFilterType,this.i(0).setWaa(this._filterNode,0),this.o(0).setWaa(this._filterNode,0),this.i(1).message([this.frequency])},stop:function(){this._filterNode=null}}),p=d.extend({waaFilterType:"bandpass",init:function(t){d.prototype.init.call(this,t),this.Q=t[1]||1},start:function(t){d.prototype.start.call(this,t),this._filterNode.Q.setValueAtTime(this.Q,0),this.i(2).message([this.Q])}});t["lop~"]=d.extend({type:"lop~",waaFilterType:"lowpass"}),t["hip~"]=d.extend({type:"hip~",waaFilterType:"highpass"}),t["bp~"]=p.extend({type:"bp~",inletDefs:[l.DspInlet,l.Inlet.extend(n),l.Inlet.extend(f)]}),t["vcf~"]=p.extend({type:"vcf~",inletDefs:[l.DspInlet,l.DspInlet.extend(n),l.Inlet.extend(f)],start:function(t){p.prototype.start.call(this,t),this.i(1).setWaa(this._filterNode.frequency,0)}});var v=c.extend({outletDefs:[l.DspOutlet],init:function(t){var e=t[0];this.setVal(e||0)},setVal:function(t){return i.isNumber(t)?void(this.val=t):console.error("invalid ["+this.obj.type+"] value "+t)}}),g={message:function(t){var e=t[0];this.obj.setVal(e),this.hasDspSource()||this._setValNoDsp(e,a.getTimeTag(t))},disconnection:function(t){l.DspInlet.prototype.disconnection.apply(this,arguments),t instanceof l.DspOutlet&&!this.hasDspSource()&&this._setValNoDsp(this.obj.val,0)}};t["*~"]=v.extend({type:"*~",inletDefs:[l.DspInlet,l.DspInlet.extend(g,{_setValNoDsp:function(t,e){this.obj._gainNode&&this.obj._gainNode.gain.setValueAtTime(t,e/1e3)}})],start:function(){this._gainNode=h.audio.context.createGain(),this.i(0).setWaa(this._gainNode,0),this.i(1).setWaa(this._gainNode.gain,0),this.o(0).setWaa(this._gainNode,0),this.i(1).hasDspSource()||this.i(1)._setValNoDsp(this.val,0)},stop:function(){this._gainNode=null}}),t["+~"]=v.extend({type:"+~",inletDefs:[l.DspInlet,l.DspInlet.extend(g,{_setValNoDsp:function(t,e){this.obj._offsetNode&&this.obj._offsetNode.offset.setValueAtTime(t,e/1e3)}})],start:function(){this._offsetNode=new o(h.audio.context),this._gainNode=h.audio.context.createGain(),this._gainNode.gain.value=1,this._offsetNode.offset.value=0,this._offsetNode.connect(this._gainNode,0,0),this.i(0).setWaa(this._gainNode,0),this.i(1).setWaa(this._offsetNode.offset,0),this.o(0).setWaa(this._gainNode,0),this.i(1).hasDspSource()||this.i(1)._setValNoDsp(this.val,0)},stop:function(){this._offsetNode.disconnect(),this._gainNode=null,this._offsetNode=null}}),t["-~"]=v.extend({type:"-~",inletDefs:[l.DspInlet,l.DspInlet.extend(g,{_setValNoDsp:function(t,e){this.obj._offsetNode&&this.obj._offsetNode.offset.setValueAtTime(t,e/1e3)}})],start:function(){this._offsetNode=new o(h.audio.context),this._gainNode=h.audio.context.createGain(),this._negateGainNode=h.audio.context.createGain(),this._gainNode.gain.value=1,this._negateGainNode.gain.value=-1,this._offsetNode.offset.value=0,this._offsetNode.connect(this._negateGainNode,0,0),this._negateGainNode.connect(this._gainNode,0,0),this.i(0).setWaa(this._gainNode,0),this.i(1).setWaa(this._offsetNode.offset,0),this.o(0).setWaa(this._gainNode,0),this.i(1).hasDspSource()||this.i(1)._setValNoDsp(this.val,0)},stop:function(){this._negateGainNode.disconnect(),this._offsetNode.disconnect(),this._gainNode=null,this._negateGainNode=null,this._offsetNode=null}});var m=c.extend({init:function(t){var e=this;this.array=new u.Reference("array"),this._onDataChangedHandler=null,this._eventReceiver=new u.EventReceiver,this._eventReceiver.on(this.array,"changed",function(t,n){n&&n.removeListener("changed:data",e._onDataChangedHandler),t&&(e._onDataChangedHandler=function(){e.dataChanged()},e._eventReceiver.on(t,"changed:data",e._onDataChangedHandler))})},dataChanged:function(){},destroy:function(){this._eventReceiver.destroy(),this.array.destroy()}});t["tabread~"]=t["tabread4~"]=m.extend({type:"tabread~",inletDefs:[l.DspInlet.extend({message:function(t){var e=t[0];"set"===e?this.obj.array.set(t[1]):console.error("unknown method "+e)},connection:function(){l.DspInlet.prototype.connection.apply(this,arguments),this.obj._updateDsp()},disconnection:function(){l.DspInlet.prototype.disconnection.apply(this,arguments),this.obj._updateDsp()}})],outletDefs:[l.DspOutlet],init:function(t){var e=this,n=t[0];m.prototype.init.apply(this,arguments),this._eventReceiver.on(this.array,"changed",function(){e._updateDsp()}),n&&this.array.set(n)},start:function(){this._tableNode=new r(h.audio.context),this._gainNode=h.audio.context.createGain(),this.i(0).setWaa(this._tableNode.position,0),this.o(0).setWaa(this._gainNode,0),this._updateDsp()},stop:function(){this._tableNode=null,this._gainNode=null},dataChanged:function(){this._tableNode&&(this._tableNode.table=this.array.resolved.data)},_updateDsp:function(){this._tableNode&&this.array.resolved&&this.i(0).hasDspSource()?(this._tableNode.table=this.array.resolved.data,this._tableNode.connect(this._gainNode)):this._tableNode&&this._tableNode.disconnect()}}),t["delwrite~"]=c.extend(u.NamedMixin,u.EventEmitterMixin,{type:"delwrite~",inletDefs:[l.DspInlet],init:function(t){var e=t[0],n=t[1];this.maxDelayTime=n||1e3,e&&this.setName(e)},start:function(){this._pipeNode=h.audio.context.createGain(),this.i(0).setWaa(this._pipeNode,0),this.emit("started")},stop:function(){this._pipeNode.disconnect(),this._pipeNode=null},destroy:function(){u.NamedMixin.destroy.apply(this,arguments),u.EventEmitterMixin.destroy.apply(this,arguments)}}),t["delread~"]=t["vd~"]=c.extend({type:"delread~",inletDefs:[l.DspInlet.extend({message:function(t){var e=t[0];this.obj.setDelayTime(e,a.getTimeTag(t))}})],outletDefs:[l.DspOutlet],init:function(t){var e=t[0],n=t[1];this._eventReceiver=new u.EventReceiver,this._delayTime=n||0,this._delWrite=new u.Reference("delwrite~"),this._onDelWriteStarted=null,e&&this._delWrite.set(e)},start:function(){this._createDelay(),this._onDelWriteChanged=function(t,e){h.isStarted&&t&&self._createDelay()},this._eventReceiver.on(this._delWrite,"changed",this._onDelWriteChanged)},stop:function(){this._toSecondsGain=null,this._delayNode.disconnect(),this._delayNode=null,this._delWrite.removeListener("changed",this._onDelWriteChanged),this._onDelWriteChanged=null},destroy:function(){this._delWrite.destroy(),this._eventReceiver.destroy()},setDelayTime:function(t,e){return i.isNumber(t)?(this._delayTime=t,void(this._delayNode&&!this.i(0).hasDspSource()&&this._delayNode.delayTime.setValueAtTime(this._delayTime/1e3,e/1e3||0))):console.error("invalid [delread~] length "+t)},_createDelay:function(){this._delayNode&&this._delayNode.disconnect();var t=this._delWrite.resolved?this._delWrite.resolved.maxDelayTime/1e3:1,e=this;if(this._delayNode=h.audio.context.createDelay(t),this._toSecondsGain||(this._toSecondsGain=h.audio.context.createGain(),this._toSecondsGain.gain.value=.001,this.i(0).setWaa(this._toSecondsGain,0)),this._toSecondsGain.connect(this._delayNode.delayTime),this.o(0).setWaa(this._delayNode,0),this.setDelayTime(this._delayTime),this._delWrite.resolved){var n=function(){e._delWrite.resolved._pipeNode.connect(e._delayNode)};this._delWrite.resolved._pipeNode?n():(this._onDelWriteStarted=n,this._eventReceiver.once(this._delWrite.resolved,"started",this._onDelWriteStarted))}}}),t["clip~"]=c.extend({type:"clip~",inletDefs:[l.DspInlet,l.Inlet.extend({message:function(t){var e=t[0];return i.isNumber(e)?(this.obj.minValue=e,void this.obj._updateGains()):console.error("invalid [clip~] min "+e)}}),l.Inlet.extend({message:function(t){var e=t[0];return i.isNumber(e)?(this.obj.maxValue=e,void this.obj._updateGains()):console.error("invalid [clip~] max "+e)}})],outletDefs:[l.DspOutlet],init:function(t){this.minValue=t[0]||0,this.maxValue=t[1]||0},start:function(){this._gainInNode=h.audio.context.createGain(),this._gainOutNode=h.audio.context.createGain(),this._waveShaperNode=h.audio.context.createWaveShaper(),this._gainInNode.connect(this._waveShaperNode),this.i(0).setWaa(this._gainInNode,0),this.o(0).setWaa(this._waveShaperNode,0),this._updateGains()},stop:function(){this._gainInNode=null,this._waveShaperNode=null,this._gainOutNode.disconnect(),this._gainOutNode=null},_updateGains:function(){if(this._waveShaperNode){var t,e=Math.max(Math.abs(this.minValue),Math.abs(this.maxValue)),n=h.audio.sampleRate,i=new Float32Array(n),o=-e,s=2*e/n;for(t=0;n>t;t++)i[t]=o>=this.minValue&&o<=this.maxValue?o:o>this.maxValue?this.maxValue:this.minValue,o+=s;this._waveShaperNode.curve=i,this._gainInNode.gain.setValueAtTime(0!==e?1/e:0,0)}}}),t["dac~"]=c.extend({type:"dac~",endPoint:!0,inletDefs:[l.DspInlet,l.DspInlet],start:function(){this.i(0).setWaa(h.audio.channels[0],0),this.i(1).setWaa(h.audio.channels[1],0)}})}},{"../core/PdObject":5,"../core/mixins":7,"../core/utils":9,"../global":10,"./portlets":15,underscore:22,waaoffsetnode:25,waatablenode:27,waawhitenoisenode:31}],14:[function(t,e,n){var i=t("underscore"),o=t("waaclock"),s=(t("../global"),n.Audio=function(t){return"undefined"==typeof AudioContext?console.error("this environment doesn't support Web Audio API"):(this.channelCount=t.channelCount,this.setContext(t.audioContext||new AudioContext),this.sampleRate=this.context.sampleRate,void Object.defineProperty(this,"time",{get:function(){return 1e3*this.context.currentTime}}))});s.prototype.start=function(){},s.prototype.stop=function(){},s.prototype.decode=function(t,e){this.context.decodeAudioData(t,function(t){var n,i=[];for(n=0;n<t.numberOfChannels;n++)i.push(t.getChannelData(n));e(null,i)},function(t){e(new Error("error decoding "+t))})},s.prototype.setContext=function(t){var e;for(this.context=t,this._channelMerger=this.context.createChannelMerger(this.channelCount),this._channelMerger.connect(this.context.destination),this.channels=[],e=0;e<this.channelCount;e++)this.channels.push(this.context.createGain()),this.channels[e].connect(this._channelMerger,0,e)};var r=n.Clock=function(t){var e=this;this._audioContext=t.audioContext,this._waaClock=t.waaClock||new o(t.audioContext),this._waaClock.start(),Object.defineProperty(this,"time",{get:function(){return 1e3*e._audioContext.currentTime}})};r.prototype.schedule=function(t,e,n){var o=function(e){void 0==e.timeTag&&(e.timeTag=1e3*e.deadline),t(e)},s=this._waaClock.callbackAtTime(o,e/1e3);return Object.defineProperty(s,"timeTag",{get:function(){return 1e3*this.deadline}}),i.isNumber(n)&&s.repeat(n/1e3),s},r.prototype.unschedule=function(t){t.clear()};var a=n.Storage=function(){};a.prototype.get=function(t,e){var n=new XMLHttpRequest;n.onload=function(t){200===this.status?e(null,this.response):e(new Error("HTTP "+this.status+": "+this.statusText))},n.onerror=function(t){e(t)},n.open("GET",t,!0),n.responseType="arraybuffer",n.send()}},{"../global":10,underscore:22,waaclock:23}],15:[function(t,e,n){var i=t("underscore"),o=t("waawire"),s=t("../core/utils"),r=t("../core/PdObject"),a=t("../core/portlets").Inlet,u=t("../core/portlets").Outlet,c=t("../global"),l="undefined"!=typeof window?window.AudioParam:function(){},h={future:function(t,e){this.message(s.timeTag(e,t))}},f=n.Inlet=a.extend(h),d=n.Outlet=u.extend({message:function(t){this.connections.forEach(function(e){e.message(t)})}}),p=n.DspInlet=a.extend(h,{hasDspSource:function(){return i.filter(this.connections,function(t){return t instanceof v}).length>0},init:function(){this._started=!1},start:function(){this._started=!0},stop:function(){this._waa=null,this._started=!1},setWaa:function(t,e){var n=this;this._waa={node:t,input:e},t instanceof l&&t.setValueAtTime(0,0),this._started&&i.chain(this.connections).filter(function(t){return t instanceof v}).forEach(function(t){t._waaUpdate(n)}).value()}}),v=n.DspOutlet=u.extend({init:function(){this._waaConnections={},this._started=!1},start:function(){this._started=!0,this.connections.forEach(this._waaConnect.bind(this))},stop:function(){this._started=!1,this.connections.forEach(this._waaDisconnect.bind(this)),this._waaConnections={}},connection:function(t){if(!(t instanceof p))throw new Error("can only connect to DSP inlet");this._started&&this._waaConnect(t)},disconnection:function(t){this._started&&this._waaDisconnect(t)},message:function(){throw new Error("dsp outlet received a message")},setWaa:function(t,e){this._waa={node:t,output:e},t i