web-audio-api
Version:
Node.js implementation of Web audio API
64 lines (54 loc) • 2.59 kB
JavaScript
var PRS$0 = (function(o,t){o["__proto__"]={"a":t};return o["a"]===t})({},{});var DP$0 = Object.defineProperty;var GOPD$0 = Object.getOwnPropertyDescriptor;var MIXIN$0 = function(t,s){for(var p in s){if(s.hasOwnProperty(p)){DP$0(t,p,GOPD$0(s,p));}}return t};var SP$0 = Object.setPrototypeOf||function(o,p){if(PRS$0){o["__proto__"]=p;}else {DP$0(o,"__proto__",{"value":p,"configurable":true,"enumerable":false,"writable":true});}return o};var OC$0 = Object.create;var _ = require('underscore')
, events = require('events')
var DspObject = (function(super$0){"use strict";super$0=events.EventEmitter;if(!PRS$0)MIXIN$0(DspObject, super$0);var proto$0={};
function DspObject(context) {
super$0.call(this)
this.context = context
this._scheduled = []
}if(super$0!==null)SP$0(DspObject,super$0);DspObject.prototype = OC$0(super$0!==null?super$0.prototype:null,{"constructor":{"value":DspObject,"configurable":true,"writable":true}});DP$0(DspObject,"prototype",{"configurable":false,"enumerable":false,"writable":false});
proto$0._tick = function() {
this._frame++
var event = this._scheduled.shift()
, eventsSameTime, eventsToExecute = []
, previousTime
// Gather all events that need to be executed at this tick
while (event && event.time <= this.context.currentTime) {
previousTime = event.time
eventsSameTime = []
// Gather all the events with same time
while (event && event.time === previousTime) {
// Add the event only if there isn't already events with same type
if (eventsSameTime.every(function(other) {
return event.type !== other.type
})) eventsSameTime.push(event)
event = this._scheduled.shift()
}
eventsSameTime.forEach(function(event) {
eventsToExecute.push(event)
})
}
if (event) this._scheduled.unshift(event)
// And execute
eventsToExecute.reverse().forEach(function(event) {
event.func && event.func()
})
};
proto$0._schedule = function(type, time, func, args) {
var event = {
time: time,
func: func,
type: type
},
ind = _.sortedIndex(this._scheduled, event, function(e) {
return e.time
})
if (args) event.args = args
this._scheduled.splice(ind, 0, event)
};
proto$0._unscheduleTypes = function(types) {
this._scheduled = _.reject(this._scheduled, function(event) {
return _.contains(types, event.type)
})
};
MIXIN$0(DspObject.prototype,proto$0);proto$0=void 0;return DspObject;})();
module.exports = DspObject