From bbc1552f478438ab6e11a1539a0881352ef3eaf7 Mon Sep 17 00:00:00 2001 From: Lajos Meszaros Date: Thu, 19 Sep 2019 10:45:54 +0200 Subject: [PATCH] feat(api): replaced hasScheduledChanges() with hasScheduledChangesAtTime() --- dist/audioparam-getvalueattime.min.js | 4 ++-- src/helpers.js | 9 +++++++-- src/index.js | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/dist/audioparam-getvalueattime.min.js b/dist/audioparam-getvalueattime.min.js index e49ef97..17c34f9 100644 --- a/dist/audioparam-getvalueattime.min.js +++ b/dist/audioparam-getvalueattime.min.js @@ -1,2 +1,2 @@ -// audioparam-getvalueattime - created by Lajos Meszaros - GPL-3.0-or-later licence - last built on 2019-09-18 -!function(){"use strict";var _isPlaceholder_1=function(a){return null!=a&&"object"==typeof a&&!0===a["@@functional/placeholder"]};var _curry1_1=function(fn){return function f1(a){return 0===arguments.length||_isPlaceholder_1(a)?f1:fn.apply(this,arguments)}},isNil_1=_curry1_1((function(x){return null==x}));function _slicedToArray(arr,i){return function(arr){if(Array.isArray(arr))return arr}(arr)||function(arr,i){if(!(Symbol.iterator in Object(arr)||"[object Arguments]"===Object.prototype.toString.call(arr)))return;var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i.return||_i.return()}finally{if(_d)throw _e}}return _arr}(arr,i)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var _has_1=function(prop,obj){return Object.prototype.hasOwnProperty.call(obj,prop)},toString=Object.prototype.toString,_isArguments_1=function(){return"[object Arguments]"===toString.call(arguments)?function(x){return"[object Arguments]"===toString.call(x)}:function(x){return _has_1("callee",x)}}(),_isArray=Array.isArray||function(val){return null!=val&&val.length>=0&&"[object Array]"===Object.prototype.toString.call(val)};var _isObject_1=function(x){return"[object Object]"===Object.prototype.toString.call(x)};var _isString_1=function(x){return"[object String]"===Object.prototype.toString.call(x)},empty_1=_curry1_1((function(x){return null!=x&&"function"==typeof x["fantasy-land/empty"]?x["fantasy-land/empty"]():null!=x&&null!=x.constructor&&"function"==typeof x.constructor["fantasy-land/empty"]?x.constructor["fantasy-land/empty"]():null!=x&&"function"==typeof x.empty?x.empty():null!=x&&null!=x.constructor&&"function"==typeof x.constructor.empty?x.constructor.empty():_isArray(x)?[]:_isString_1(x)?"":_isObject_1(x)?{}:_isArguments_1(x)?function(){return arguments}():void 0}));var _curry2_1=function(fn){return function f2(a,b){switch(arguments.length){case 0:return f2;case 1:return _isPlaceholder_1(a)?f2:_curry1_1((function(_b){return fn(a,_b)}));default:return _isPlaceholder_1(a)&&_isPlaceholder_1(b)?f2:_isPlaceholder_1(a)?_curry1_1((function(_a){return fn(_a,b)})):_isPlaceholder_1(b)?_curry1_1((function(_b){return fn(a,_b)})):fn(a,b)}}};var _arrayFromIterator_1=function(iter){for(var next,list=[];!(next=iter.next()).done;)list.push(next.value);return list};var _includesWith_1=function(pred,x,list){for(var idx=0,len=list.length;idx=0;)_has_1(prop=nonEnumerableProps[nIdx],obj)&&!contains(ks,prop)&&(ks[ks.length]=prop),nIdx-=1;return ks})):_curry1_1((function(obj){return Object(obj)!==obj?[]:Object.keys(obj)})),type_1=_curry1_1((function(val){return null===val?"Null":void 0===val?"Undefined":Object.prototype.toString.call(val).slice(8,-1)}));function _uniqContentEquals(aIterator,bIterator,stackA,stackB){var a=_arrayFromIterator_1(aIterator),b=_arrayFromIterator_1(bIterator);function eq(_a,_b){return _equals(_a,_b,stackA.slice(),stackB.slice())}return!_includesWith_1((function(b,aItem){return!_includesWith_1(eq,aItem,b)}),b,a)}function _equals(a,b,stackA,stackB){if(_objectIs_1(a,b))return!0;var typeA=type_1(a);if(typeA!==type_1(b))return!1;if(null==a||null==b)return!1;if("function"==typeof a["fantasy-land/equals"]||"function"==typeof b["fantasy-land/equals"])return"function"==typeof a["fantasy-land/equals"]&&a["fantasy-land/equals"](b)&&"function"==typeof b["fantasy-land/equals"]&&b["fantasy-land/equals"](a);if("function"==typeof a.equals||"function"==typeof b.equals)return"function"==typeof a.equals&&a.equals(b)&&"function"==typeof b.equals&&b.equals(a);switch(typeA){case"Arguments":case"Array":case"Object":if("function"==typeof a.constructor&&"Promise"===_functionName_1(a.constructor))return a===b;break;case"Boolean":case"Number":case"String":if(typeof a!=typeof b||!_objectIs_1(a.valueOf(),b.valueOf()))return!1;break;case"Date":if(!_objectIs_1(a.valueOf(),b.valueOf()))return!1;break;case"Error":return a.name===b.name&&a.message===b.message;case"RegExp":if(a.source!==b.source||a.global!==b.global||a.ignoreCase!==b.ignoreCase||a.multiline!==b.multiline||a.sticky!==b.sticky||a.unicode!==b.unicode)return!1}for(var idx=stackA.length-1;idx>=0;){if(stackA[idx]===a)return stackB[idx]===b;idx-=1}switch(typeA){case"Map":return a.size===b.size&&_uniqContentEquals(a.entries(),b.entries(),stackA.concat([a]),stackB.concat([b]));case"Set":return a.size===b.size&&_uniqContentEquals(a.values(),b.values(),stackA.concat([a]),stackB.concat([b]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var keysA=keys_1(a);if(keysA.length!==keys_1(b).length)return!1;var extendedStackA=stackA.concat([a]),extendedStackB=stackB.concat([b]);for(idx=keysA.length-1;idx>=0;){var key=keysA[idx];if(!_has_1(key,b)||!_equals(b[key],a[key],extendedStackA,extendedStackB))return!1;idx-=1}return!0}var _equals_1=_equals,equals_1=_curry2_1((function(a,b){return _equals_1(a,b,[],[])})),isEmpty_1=_curry1_1((function(x){return null!=x&&equals_1(x,empty_1(x))})),path_1=_curry2_1((function(paths,obj){for(var val=obj,idx=0;idx0&&(x.hasOwnProperty(0)&&x.hasOwnProperty(x.length-1)))))})),XWrap=function(){function XWrap(fn){this.f=fn}return XWrap.prototype["@@transducer/init"]=function(){throw new Error("init not implemented on XWrap")},XWrap.prototype["@@transducer/result"]=function(acc){return acc},XWrap.prototype["@@transducer/step"]=function(acc,x){return this.f(acc,x)},XWrap}();var _xwrap_1=function(fn){return new XWrap(fn)},bind_1=_curry2_1((function(fn,thisObj){return _arity_1(fn.length,(function(){return fn.apply(thisObj,arguments)}))}));function _iterableReduce(xf,acc,iter){for(var step=iter.next();!step.done;){if((acc=xf["@@transducer/step"](acc,step.value))&&acc["@@transducer/reduced"]){acc=acc["@@transducer/value"];break}step=iter.next()}return xf["@@transducer/result"](acc)}function _methodReduce(xf,acc,obj,methodName){return xf["@@transducer/result"](obj[methodName](bind_1(xf["@@transducer/step"],xf),acc))}var symIterator="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator";var _reduce_1=function(fn,acc,list){if("function"==typeof fn&&(fn=_xwrap_1(fn)),_isArrayLike_1(list))return function(xf,acc,list){for(var idx=0,len=list.length;idx=arguments.length)?result=received[combinedIdx]:(result=arguments[argsIdx],argsIdx+=1),combined[combinedIdx]=result,_isPlaceholder_1(result)||(left-=1),combinedIdx+=1}return left<=0?fn.apply(this,combined):_arity_1(left,_curryN(length,combined,fn))}},curryN_1=_curry2_1((function(length,fn){return 1===length?_curry1_1(fn):_arity_1(length,_curryN_1(length,[],fn))})),map_1=_curry2_1(_dispatchable_1(["fantasy-land/map","map"],_xmap_1,(function(fn,functor){switch(Object.prototype.toString.call(functor)){case"[object Function]":return curryN_1(functor.length,(function(){return fn.call(this,functor.apply(this,arguments))}));case"[object Object]":return _reduce_1((function(acc,key){return acc[key]=fn(functor[key]),acc}),{},keys_1(functor));default:return _map_1(fn,functor)}}))),ap_1=_curry2_1((function(applyF,applyX){return"function"==typeof applyX["fantasy-land/ap"]?applyX["fantasy-land/ap"](applyF):"function"==typeof applyF.ap?applyF.ap(applyX):"function"==typeof applyF?function(x){return applyF(x)(applyX(x))}:_reduce_1((function(acc,f){return _concat_1(acc,map_1(f,applyX))}),[],applyF)})),liftN_1=_curry2_1((function(arity,fn){var lifted=curryN_1(arity,fn);return curryN_1(arity,(function(){return _reduce_1(ap_1,map_1(lifted,arguments[0]),Array.prototype.slice.call(arguments,1))}))})),lift_1=_curry1_1((function(fn){return liftN_1(fn.length,fn)})),complement_1=lift_1(_curry1_1((function(a){return!a}))),clamp_1=_curry3_1((function(min,max,value){if(min>max)throw new Error("min must not be greater than max in clamp(min, max, value)");return valuemax?max:value}));var _complement_1=function(f){return function(){return!f.apply(this,arguments)}};var _filter_1=function(fn,list){for(var idx=0,len=list.length,result=[];idx=b}));var _isFunction_1=function(x){return"[object Function]"===Object.prototype.toString.call(x)},or_1=_curry2_1((function(a,b){return a||b})),either_1=_curry2_1((function(f,g){return _isFunction_1(f)?function(){return f.apply(this,arguments)||g.apply(this,arguments)}:lift_1(or_1)(f,g)})),and_1=_curry2_1((function(a,b){return a&&b})),both_1=_curry2_1((function(f,g){return _isFunction_1(f)?function(){return f.apply(this,arguments)&&g.apply(this,arguments)}:lift_1(and_1)(f,g)})),max_1=_curry2_1((function(a,b){return b>a?b:a})),pluck_1=_curry2_1((function(p,list){return map_1(prop_1(p),list)})),unless_1=_curry3_1((function(pred,whenFalseFn,x){return pred(x)?x:whenFalseFn(x)}));var _reduced_1=function(x){return x&&x["@@transducer/reduced"]?x:{"@@transducer/value":x,"@@transducer/reduced":!0}},XFind=function(){function XFind(f,xf){this.xf=xf,this.f=f,this.found=!1}return XFind.prototype["@@transducer/init"]=_xfBase_init,XFind.prototype["@@transducer/result"]=function(result){return this.found||(result=this.xf["@@transducer/step"](result,void 0)),this.xf["@@transducer/result"](result)},XFind.prototype["@@transducer/step"]=function(result,input){return this.f(input)&&(this.found=!0,result=_reduced_1(this.xf["@@transducer/step"](result,input))),result},XFind}(),find_1=_curry2_1(_dispatchable_1(["find"],_curry2_1((function(f,xf){return new XFind(f,xf)})),(function(fn,list){for(var idx=0,len=list.length;idxb})),nth_1=_curry2_1((function(offset,list){var idx=offset<0?list.length+offset:offset;return _isString_1(list)?list.charAt(idx):list[idx]})),last_1=nth_1(-1),hasPath_1=_curry2_1((function(_path,obj){if(0===_path.length)return!1;for(var val=obj,idx=0;idx<_path.length;){if(!_has_1(_path[idx],val))return!1;val=val[_path[idx]],idx+=1}return!0})),has_1=_curry2_1((function(prop,obj){return hasPath_1([prop],obj)})),XAll=function(){function XAll(f,xf){this.xf=xf,this.f=f,this.all=!0}return XAll.prototype["@@transducer/init"]=_xfBase_init,XAll.prototype["@@transducer/result"]=function(result){return this.all&&(result=this.xf["@@transducer/step"](result,!0)),this.xf["@@transducer/result"](result)},XAll.prototype["@@transducer/step"]=function(result,input){return this.f(input)||(this.all=!1,result=_reduced_1(this.xf["@@transducer/step"](result,!1))),result},XAll}(),all_1=_curry2_1(_dispatchable_1(["all"],_curry2_1((function(f,xf){return new XAll(f,xf)})),(function(fn,list){for(var idx=0;idx=0},flip_1=_curry1_1((function(fn){return curryN_1(fn.length,(function(a,b){var args=Array.prototype.slice.call(arguments,0);return args[0]=b,args[1]=a,fn.apply(this,args)}))})),without_1=_curry2_1((function(xs,list){return reject_1(flip_1(_includes_1)(xs),list)})),sortBy_1=_curry2_1((function(fn,list){return Array.prototype.slice.call(list,0).sort((function(a,b){var aa=fn(a),bb=fn(b);return aabb?1:0}))}));var descriptor,originalSetter,expr_1=function(t,v0,v1,t0,t1){return t<=t0?v0:t1<=t?v1:v0+(t-t0)/(t1-t0)*(v1-v0)},expr_2=function(t,v0,v1,t0,t1){var a;return t<=t0?v0:t1<=t?v1:v0===v1?v0:(a=(t-t0)/(t1-t0),03&&void 0!==arguments[3]?arguments[3]:1/0,lastChangeBeforeTime=findLastChangeBeforeTime(scheduledChanges,endTime),firstChangeAfterTime=findFirstChangeAfterTime(scheduledChanges,endTime),value=isNil_1(lastChangeBeforeTime)?initialValue:getTargetValueOfChange(lastChangeBeforeTime);if(!isNil_1(firstChangeAfterTime)){var endTimeOfLastChange=isNil_1(lastChangeBeforeTime)?initialTime:lastChangeBeforeTime.targetTime;switch(firstChangeAfterTime.method){case"linearRampToValueAtTime":value=expr_1(endTime,value,getTargetValueOfChange(firstChangeAfterTime),endTimeOfLastChange,firstChangeAfterTime.targetTime);break;case"exponentialRampToValueAtTime":value=expr_2(endTime,value,getTargetValueOfChange(firstChangeAfterTime),endTimeOfLastChange,firstChangeAfterTime.targetTime);break;case"setTargetAtTime":value=expr_3(endTime,value,firstChangeAfterTime.params[0],firstChangeAfterTime.params[1],firstChangeAfterTime.params[2]);break;case"setValueCurveAtTime":value=expr_4(endTime,firstChangeAfterTime.params[0],firstChangeAfterTime.params[1],firstChangeAfterTime.params[2])}}return value},scheduleChange=function(audioParam,method,params,targetTime){var now=audioParam._ctx.currentTime,outdatedSchedulements=filter_1(compose_1(both_1(gte_1(__,audioParam._valueWasLastSetAt),lt_1(__,now)),prop_1("targetTime")))(audioParam._scheduledChanges);if(isEmpty_1(outdatedSchedulements)||(audioParam._valueWasLastSetAt=compose_1(maxAll,pluck_1("targetTime"))(outdatedSchedulements),audioParam._value=evaluateSchedulement(outdatedSchedulements,audioParam._value,audioParam._valueWasLastSetAt)),audioParam._scheduledChanges=compose_1(unless_1((function(){return"cancelScheduledValues"===method||"cancelAndHoldAtTime"===method}),append_1({method:method,params:params,targetTime:clamp_1(now,1/0,targetTime)})),reject_1(compose_1(either_1("cancelScheduledValues"===method?gte_1(__,targetTime):equals_1(__,targetTime),lt_1(__,now)),prop_1("targetTime"))))(audioParam._scheduledChanges),"cancelAndHoldAtTime"===method){var events=filter_1(compose_1(gte_1(__,targetTime),prop_1("targetTime")),audioParam._scheduledChanges);if(!isEmpty_1(events)){var event;if("setValueAtTime"!==(event=1===length_1(events)?head_1(events):compose_1(head_1,sortBy_1(prop_1("targetTime")))(events)).method&&"setTargetAtTime"!==event.method)switch(event.targetTime=targetTime,event.method){case"linearRampToValueAtTime":event.params=[expr_1(targetTime,audioParam._value,event.params[0],audioParam._valueWasLastSetAt,event.params[1]),targetTime];break;case"exponentialRampToValueAtTime":event.params=[expr_2(targetTime,audioParam._value,event.params[0],audioParam._valueWasLastSetAt,event.params[1]),targetTime];break;case"setValueCurveAtTime":var _event$params=_slicedToArray(event.params,2),values=_event$params[0],startTime=_event$params[1],newDuration=targetTime-startTime,newValues=values;event.params=[newValues,startTime,newDuration]}audioParam._scheduledChanges=compose_1(append_1(event),without_1(events))(audioParam._scheduledChanges)}}},hasScheduledChanges=compose_1(isNotEmpty,prop_1("_scheduledChanges")),bindContextToParams=function(creatorName,params){var originalFn=AudioContextClass.prototype[creatorName];isNil_1(originalFn)||(AudioContextClass.prototype[creatorName]=function(){for(var ctx=this,_len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++)args[_key]=arguments[_key];var node=originalFn.apply(ctx,args);return params.forEach((function(param){var audioParam=node[param];audioParam._ctx=ctx,audioParam._value=audioParam.value,audioParam._valueWasLastSetAt=0,audioParam._scheduledChanges=[]})),node})},bindSchedulerToParamMethod=function(methodName){var timeArgIndexes=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],originalFn=AudioParam.prototype[methodName];isNil_1(originalFn)||(AudioParam.prototype[methodName]=function(){for(var audioParam=this,targetTime=1/0,_len2=arguments.length,args=new Array(_len2),_key2=0;_key2<_len2;_key2++)args[_key2]=arguments[_key2];return!isEmpty_1(timeArgIndexes)&&all_1(has_1(__,args),timeArgIndexes)&&(targetTime=reduce_1(add_1,0,props_1(timeArgIndexes,args))),scheduleChange(audioParam,methodName,args,targetTime),originalFn.apply(audioParam,args),audioParam})};!isNil_1(window.AudioParam)&&isNil_1(AudioParam.prototype.getValueAtTime)&&(bindContextToParams("createBiquadFilter",["frequency","detune","Q","gain"]),bindContextToParams("createBufferSource",["detune","playbackRate"]),bindContextToParams("createConstantSource",["offset"]),bindContextToParams("createDelay",["delayTime"]),bindContextToParams("createDynamicsCompressor",["threshold","knee","ratio","attack","release"]),bindContextToParams("createGain",["gain"]),bindContextToParams("createOscillator",["frequency","detune"]),bindContextToParams("createPanner",["orientationX","orientationY","orientationZ","positionX","positionY","positionZ"]),bindContextToParams("createStereoPanner",["pan"]),bindSchedulerToParamMethod("cancelScheduledValues",[0]),bindSchedulerToParamMethod("setValueAtTime",[1]),bindSchedulerToParamMethod("linearRampToValueAtTime",[1]),bindSchedulerToParamMethod("exponentialRampToValueAtTime",[1]),bindSchedulerToParamMethod("setTargetAtTime",[]),bindSchedulerToParamMethod("setValueCurveAtTime",[1,2]),isNil_1(AudioParam.prototype.cancelAndHoldAtTime)||bindSchedulerToParamMethod("cancelAndHoldAtTime",[0]),descriptor=Object.getOwnPropertyDescriptor(AudioParam.prototype,"value"),originalSetter=descriptor.set,descriptor.set=function(newValue){hasScheduledChanges(this)||(this._value=clamp_1(this.minValue,this.maxValue,newValue),this._valueWasLastSetAt=this._ctx.currentTime,originalSetter.call(this,newValue))},Object.defineProperty(AudioParam.prototype,"value",descriptor),AudioParam.prototype.getValueAtTime=function(time){return function(audioParam,time){return hasScheduledChanges(audioParam)?evaluateSchedulement(audioParam._scheduledChanges,audioParam._value,audioParam._valueWasLastSetAt,time):audioParam._value}(this,time)},AudioParam.prototype.hasScheduledChanges=function(){return hasScheduledChanges(this)})}(); +// audioparam-getvalueattime - created by Lajos Meszaros - GPL-3.0-or-later licence - last built on 2019-09-19 +!function(){"use strict";var _isPlaceholder_1=function(a){return null!=a&&"object"==typeof a&&!0===a["@@functional/placeholder"]};var _curry1_1=function(fn){return function f1(a){return 0===arguments.length||_isPlaceholder_1(a)?f1:fn.apply(this,arguments)}},isNil_1=_curry1_1((function(x){return null==x}));function _slicedToArray(arr,i){return function(arr){if(Array.isArray(arr))return arr}(arr)||function(arr,i){if(!(Symbol.iterator in Object(arr)||"[object Arguments]"===Object.prototype.toString.call(arr)))return;var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i.return||_i.return()}finally{if(_d)throw _e}}return _arr}(arr,i)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var _has_1=function(prop,obj){return Object.prototype.hasOwnProperty.call(obj,prop)},toString=Object.prototype.toString,_isArguments_1=function(){return"[object Arguments]"===toString.call(arguments)?function(x){return"[object Arguments]"===toString.call(x)}:function(x){return _has_1("callee",x)}}(),_isArray=Array.isArray||function(val){return null!=val&&val.length>=0&&"[object Array]"===Object.prototype.toString.call(val)};var _isObject_1=function(x){return"[object Object]"===Object.prototype.toString.call(x)};var _isString_1=function(x){return"[object String]"===Object.prototype.toString.call(x)},empty_1=_curry1_1((function(x){return null!=x&&"function"==typeof x["fantasy-land/empty"]?x["fantasy-land/empty"]():null!=x&&null!=x.constructor&&"function"==typeof x.constructor["fantasy-land/empty"]?x.constructor["fantasy-land/empty"]():null!=x&&"function"==typeof x.empty?x.empty():null!=x&&null!=x.constructor&&"function"==typeof x.constructor.empty?x.constructor.empty():_isArray(x)?[]:_isString_1(x)?"":_isObject_1(x)?{}:_isArguments_1(x)?function(){return arguments}():void 0}));var _curry2_1=function(fn){return function f2(a,b){switch(arguments.length){case 0:return f2;case 1:return _isPlaceholder_1(a)?f2:_curry1_1((function(_b){return fn(a,_b)}));default:return _isPlaceholder_1(a)&&_isPlaceholder_1(b)?f2:_isPlaceholder_1(a)?_curry1_1((function(_a){return fn(_a,b)})):_isPlaceholder_1(b)?_curry1_1((function(_b){return fn(a,_b)})):fn(a,b)}}};var _arrayFromIterator_1=function(iter){for(var next,list=[];!(next=iter.next()).done;)list.push(next.value);return list};var _includesWith_1=function(pred,x,list){for(var idx=0,len=list.length;idx=0;)_has_1(prop=nonEnumerableProps[nIdx],obj)&&!contains(ks,prop)&&(ks[ks.length]=prop),nIdx-=1;return ks})):_curry1_1((function(obj){return Object(obj)!==obj?[]:Object.keys(obj)})),type_1=_curry1_1((function(val){return null===val?"Null":void 0===val?"Undefined":Object.prototype.toString.call(val).slice(8,-1)}));function _uniqContentEquals(aIterator,bIterator,stackA,stackB){var a=_arrayFromIterator_1(aIterator),b=_arrayFromIterator_1(bIterator);function eq(_a,_b){return _equals(_a,_b,stackA.slice(),stackB.slice())}return!_includesWith_1((function(b,aItem){return!_includesWith_1(eq,aItem,b)}),b,a)}function _equals(a,b,stackA,stackB){if(_objectIs_1(a,b))return!0;var typeA=type_1(a);if(typeA!==type_1(b))return!1;if(null==a||null==b)return!1;if("function"==typeof a["fantasy-land/equals"]||"function"==typeof b["fantasy-land/equals"])return"function"==typeof a["fantasy-land/equals"]&&a["fantasy-land/equals"](b)&&"function"==typeof b["fantasy-land/equals"]&&b["fantasy-land/equals"](a);if("function"==typeof a.equals||"function"==typeof b.equals)return"function"==typeof a.equals&&a.equals(b)&&"function"==typeof b.equals&&b.equals(a);switch(typeA){case"Arguments":case"Array":case"Object":if("function"==typeof a.constructor&&"Promise"===_functionName_1(a.constructor))return a===b;break;case"Boolean":case"Number":case"String":if(typeof a!=typeof b||!_objectIs_1(a.valueOf(),b.valueOf()))return!1;break;case"Date":if(!_objectIs_1(a.valueOf(),b.valueOf()))return!1;break;case"Error":return a.name===b.name&&a.message===b.message;case"RegExp":if(a.source!==b.source||a.global!==b.global||a.ignoreCase!==b.ignoreCase||a.multiline!==b.multiline||a.sticky!==b.sticky||a.unicode!==b.unicode)return!1}for(var idx=stackA.length-1;idx>=0;){if(stackA[idx]===a)return stackB[idx]===b;idx-=1}switch(typeA){case"Map":return a.size===b.size&&_uniqContentEquals(a.entries(),b.entries(),stackA.concat([a]),stackB.concat([b]));case"Set":return a.size===b.size&&_uniqContentEquals(a.values(),b.values(),stackA.concat([a]),stackB.concat([b]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var keysA=keys_1(a);if(keysA.length!==keys_1(b).length)return!1;var extendedStackA=stackA.concat([a]),extendedStackB=stackB.concat([b]);for(idx=keysA.length-1;idx>=0;){var key=keysA[idx];if(!_has_1(key,b)||!_equals(b[key],a[key],extendedStackA,extendedStackB))return!1;idx-=1}return!0}var _equals_1=_equals,equals_1=_curry2_1((function(a,b){return _equals_1(a,b,[],[])})),isEmpty_1=_curry1_1((function(x){return null!=x&&equals_1(x,empty_1(x))})),path_1=_curry2_1((function(paths,obj){for(var val=obj,idx=0;idx0&&(x.hasOwnProperty(0)&&x.hasOwnProperty(x.length-1)))))})),XWrap=function(){function XWrap(fn){this.f=fn}return XWrap.prototype["@@transducer/init"]=function(){throw new Error("init not implemented on XWrap")},XWrap.prototype["@@transducer/result"]=function(acc){return acc},XWrap.prototype["@@transducer/step"]=function(acc,x){return this.f(acc,x)},XWrap}();var _xwrap_1=function(fn){return new XWrap(fn)},bind_1=_curry2_1((function(fn,thisObj){return _arity_1(fn.length,(function(){return fn.apply(thisObj,arguments)}))}));function _iterableReduce(xf,acc,iter){for(var step=iter.next();!step.done;){if((acc=xf["@@transducer/step"](acc,step.value))&&acc["@@transducer/reduced"]){acc=acc["@@transducer/value"];break}step=iter.next()}return xf["@@transducer/result"](acc)}function _methodReduce(xf,acc,obj,methodName){return xf["@@transducer/result"](obj[methodName](bind_1(xf["@@transducer/step"],xf),acc))}var symIterator="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator";var _reduce_1=function(fn,acc,list){if("function"==typeof fn&&(fn=_xwrap_1(fn)),_isArrayLike_1(list))return function(xf,acc,list){for(var idx=0,len=list.length;idx=arguments.length)?result=received[combinedIdx]:(result=arguments[argsIdx],argsIdx+=1),combined[combinedIdx]=result,_isPlaceholder_1(result)||(left-=1),combinedIdx+=1}return left<=0?fn.apply(this,combined):_arity_1(left,_curryN(length,combined,fn))}},curryN_1=_curry2_1((function(length,fn){return 1===length?_curry1_1(fn):_arity_1(length,_curryN_1(length,[],fn))})),map_1=_curry2_1(_dispatchable_1(["fantasy-land/map","map"],_xmap_1,(function(fn,functor){switch(Object.prototype.toString.call(functor)){case"[object Function]":return curryN_1(functor.length,(function(){return fn.call(this,functor.apply(this,arguments))}));case"[object Object]":return _reduce_1((function(acc,key){return acc[key]=fn(functor[key]),acc}),{},keys_1(functor));default:return _map_1(fn,functor)}}))),ap_1=_curry2_1((function(applyF,applyX){return"function"==typeof applyX["fantasy-land/ap"]?applyX["fantasy-land/ap"](applyF):"function"==typeof applyF.ap?applyF.ap(applyX):"function"==typeof applyF?function(x){return applyF(x)(applyX(x))}:_reduce_1((function(acc,f){return _concat_1(acc,map_1(f,applyX))}),[],applyF)})),liftN_1=_curry2_1((function(arity,fn){var lifted=curryN_1(arity,fn);return curryN_1(arity,(function(){return _reduce_1(ap_1,map_1(lifted,arguments[0]),Array.prototype.slice.call(arguments,1))}))})),lift_1=_curry1_1((function(fn){return liftN_1(fn.length,fn)})),complement_1=lift_1(_curry1_1((function(a){return!a}))),clamp_1=_curry3_1((function(min,max,value){if(min>max)throw new Error("min must not be greater than max in clamp(min, max, value)");return valuemax?max:value}));var _complement_1=function(f){return function(){return!f.apply(this,arguments)}};var _filter_1=function(fn,list){for(var idx=0,len=list.length,result=[];idx=b}));var _isFunction_1=function(x){return"[object Function]"===Object.prototype.toString.call(x)},or_1=_curry2_1((function(a,b){return a||b})),either_1=_curry2_1((function(f,g){return _isFunction_1(f)?function(){return f.apply(this,arguments)||g.apply(this,arguments)}:lift_1(or_1)(f,g)})),and_1=_curry2_1((function(a,b){return a&&b})),both_1=_curry2_1((function(f,g){return _isFunction_1(f)?function(){return f.apply(this,arguments)&&g.apply(this,arguments)}:lift_1(and_1)(f,g)})),max_1=_curry2_1((function(a,b){return b>a?b:a})),pluck_1=_curry2_1((function(p,list){return map_1(prop_1(p),list)})),unless_1=_curry3_1((function(pred,whenFalseFn,x){return pred(x)?x:whenFalseFn(x)}));var _reduced_1=function(x){return x&&x["@@transducer/reduced"]?x:{"@@transducer/value":x,"@@transducer/reduced":!0}},XFind=function(){function XFind(f,xf){this.xf=xf,this.f=f,this.found=!1}return XFind.prototype["@@transducer/init"]=_xfBase_init,XFind.prototype["@@transducer/result"]=function(result){return this.found||(result=this.xf["@@transducer/step"](result,void 0)),this.xf["@@transducer/result"](result)},XFind.prototype["@@transducer/step"]=function(result,input){return this.f(input)&&(this.found=!0,result=_reduced_1(this.xf["@@transducer/step"](result,input))),result},XFind}(),find_1=_curry2_1(_dispatchable_1(["find"],_curry2_1((function(f,xf){return new XFind(f,xf)})),(function(fn,list){for(var idx=0,len=list.length;idxb})),nth_1=_curry2_1((function(offset,list){var idx=offset<0?list.length+offset:offset;return _isString_1(list)?list.charAt(idx):list[idx]})),last_1=nth_1(-1),hasPath_1=_curry2_1((function(_path,obj){if(0===_path.length)return!1;for(var val=obj,idx=0;idx<_path.length;){if(!_has_1(_path[idx],val))return!1;val=val[_path[idx]],idx+=1}return!0})),has_1=_curry2_1((function(prop,obj){return hasPath_1([prop],obj)})),XAll=function(){function XAll(f,xf){this.xf=xf,this.f=f,this.all=!0}return XAll.prototype["@@transducer/init"]=_xfBase_init,XAll.prototype["@@transducer/result"]=function(result){return this.all&&(result=this.xf["@@transducer/step"](result,!0)),this.xf["@@transducer/result"](result)},XAll.prototype["@@transducer/step"]=function(result,input){return this.f(input)||(this.all=!1,result=_reduced_1(this.xf["@@transducer/step"](result,!1))),result},XAll}(),all_1=_curry2_1(_dispatchable_1(["all"],_curry2_1((function(f,xf){return new XAll(f,xf)})),(function(fn,list){for(var idx=0;idx=0},flip_1=_curry1_1((function(fn){return curryN_1(fn.length,(function(a,b){var args=Array.prototype.slice.call(arguments,0);return args[0]=b,args[1]=a,fn.apply(this,args)}))})),without_1=_curry2_1((function(xs,list){return reject_1(flip_1(_includes_1)(xs),list)})),sortBy_1=_curry2_1((function(fn,list){return Array.prototype.slice.call(list,0).sort((function(a,b){var aa=fn(a),bb=fn(b);return aabb?1:0}))})),XAny=function(){function XAny(f,xf){this.xf=xf,this.f=f,this.any=!1}return XAny.prototype["@@transducer/init"]=_xfBase_init,XAny.prototype["@@transducer/result"]=function(result){return this.any||(result=this.xf["@@transducer/step"](result,!1)),this.xf["@@transducer/result"](result)},XAny.prototype["@@transducer/step"]=function(result,input){return this.f(input)&&(this.any=!0,result=_reduced_1(this.xf["@@transducer/step"](result,!0))),result},XAny}(),any_1=_curry2_1(_dispatchable_1(["any"],_curry2_1((function(f,xf){return new XAny(f,xf)})),(function(fn,list){for(var idx=0;idx3&&void 0!==arguments[3]?arguments[3]:1/0,lastChangeBeforeTime=findLastChangeBeforeTime(scheduledChanges,endTime),firstChangeAfterTime=findFirstChangeAfterTime(scheduledChanges,endTime),value=isNil_1(lastChangeBeforeTime)?initialValue:getTargetValueOfChange(lastChangeBeforeTime);if(!isNil_1(firstChangeAfterTime)){var endTimeOfLastChange=isNil_1(lastChangeBeforeTime)?initialTime:lastChangeBeforeTime.targetTime;switch(firstChangeAfterTime.method){case"linearRampToValueAtTime":value=expr_1(endTime,value,getTargetValueOfChange(firstChangeAfterTime),endTimeOfLastChange,firstChangeAfterTime.targetTime);break;case"exponentialRampToValueAtTime":value=expr_2(endTime,value,getTargetValueOfChange(firstChangeAfterTime),endTimeOfLastChange,firstChangeAfterTime.targetTime);break;case"setTargetAtTime":value=expr_3(endTime,value,firstChangeAfterTime.params[0],firstChangeAfterTime.params[1],firstChangeAfterTime.params[2]);break;case"setValueCurveAtTime":value=expr_4(endTime,firstChangeAfterTime.params[0],firstChangeAfterTime.params[1],firstChangeAfterTime.params[2])}}return value},scheduleChange=function(audioParam,method,params,targetTime){var now=audioParam._ctx.currentTime,outdatedSchedulements=filter_1(compose_1(both_1(gte_1(__,audioParam._valueWasLastSetAt),lt_1(__,now)),prop_1("targetTime")))(audioParam._scheduledChanges);if(isEmpty_1(outdatedSchedulements)||(audioParam._valueWasLastSetAt=compose_1(maxAll,pluck_1("targetTime"))(outdatedSchedulements),audioParam._value=evaluateSchedulement(outdatedSchedulements,audioParam._value,audioParam._valueWasLastSetAt)),audioParam._scheduledChanges=compose_1(unless_1((function(){return"cancelScheduledValues"===method||"cancelAndHoldAtTime"===method}),append_1({method:method,params:params,targetTime:clamp_1(now,1/0,targetTime)})),reject_1(compose_1(either_1("cancelScheduledValues"===method?gte_1(__,targetTime):equals_1(__,targetTime),lt_1(__,now)),prop_1("targetTime"))))(audioParam._scheduledChanges),"cancelAndHoldAtTime"===method){var events=filter_1(compose_1(gte_1(__,targetTime),prop_1("targetTime")),audioParam._scheduledChanges);if(!isEmpty_1(events)){var event;if("setValueAtTime"!==(event=1===length_1(events)?head_1(events):compose_1(head_1,sortBy_1(prop_1("targetTime")))(events)).method&&"setTargetAtTime"!==event.method)switch(event.targetTime=targetTime,event.method){case"linearRampToValueAtTime":event.params=[expr_1(targetTime,audioParam._value,event.params[0],audioParam._valueWasLastSetAt,event.params[1]),targetTime];break;case"exponentialRampToValueAtTime":event.params=[expr_2(targetTime,audioParam._value,event.params[0],audioParam._valueWasLastSetAt,event.params[1]),targetTime];break;case"setValueCurveAtTime":var _event$params=_slicedToArray(event.params,2),values=_event$params[0],startTime=_event$params[1],newDuration=targetTime-startTime,newValues=values;event.params=[newValues,startTime,newDuration]}audioParam._scheduledChanges=compose_1(append_1(event),without_1(events))(audioParam._scheduledChanges)}}},hasScheduledChanges=compose_1(isNotEmpty,prop_1("_scheduledChanges")),bindContextToParams=function(creatorName,params){var originalFn=AudioContextClass.prototype[creatorName];isNil_1(originalFn)||(AudioContextClass.prototype[creatorName]=function(){for(var ctx=this,_len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++)args[_key]=arguments[_key];var node=originalFn.apply(ctx,args);return params.forEach((function(param){var audioParam=node[param];audioParam._ctx=ctx,audioParam._value=audioParam.value,audioParam._valueWasLastSetAt=0,audioParam._scheduledChanges=[]})),node})},bindSchedulerToParamMethod=function(methodName){var timeArgIndexes=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],originalFn=AudioParam.prototype[methodName];isNil_1(originalFn)||(AudioParam.prototype[methodName]=function(){for(var audioParam=this,targetTime=1/0,_len2=arguments.length,args=new Array(_len2),_key2=0;_key2<_len2;_key2++)args[_key2]=arguments[_key2];return!isEmpty_1(timeArgIndexes)&&all_1(has_1(__,args),timeArgIndexes)&&(targetTime=reduce_1(add_1,0,props_1(timeArgIndexes,args))),scheduleChange(audioParam,methodName,args,targetTime),originalFn.apply(audioParam,args),audioParam})};!isNil_1(window.AudioParam)&&isNil_1(AudioParam.prototype.getValueAtTime)&&(bindContextToParams("createBiquadFilter",["frequency","detune","Q","gain"]),bindContextToParams("createBufferSource",["detune","playbackRate"]),bindContextToParams("createConstantSource",["offset"]),bindContextToParams("createDelay",["delayTime"]),bindContextToParams("createDynamicsCompressor",["threshold","knee","ratio","attack","release"]),bindContextToParams("createGain",["gain"]),bindContextToParams("createOscillator",["frequency","detune"]),bindContextToParams("createPanner",["orientationX","orientationY","orientationZ","positionX","positionY","positionZ"]),bindContextToParams("createStereoPanner",["pan"]),bindSchedulerToParamMethod("cancelScheduledValues",[0]),bindSchedulerToParamMethod("setValueAtTime",[1]),bindSchedulerToParamMethod("linearRampToValueAtTime",[1]),bindSchedulerToParamMethod("exponentialRampToValueAtTime",[1]),bindSchedulerToParamMethod("setTargetAtTime",[]),bindSchedulerToParamMethod("setValueCurveAtTime",[1,2]),isNil_1(AudioParam.prototype.cancelAndHoldAtTime)||bindSchedulerToParamMethod("cancelAndHoldAtTime",[0]),descriptor=Object.getOwnPropertyDescriptor(AudioParam.prototype,"value"),originalSetter=descriptor.set,descriptor.set=function(newValue){hasScheduledChanges(this)||(this._value=clamp_1(this.minValue,this.maxValue,newValue),this._valueWasLastSetAt=this._ctx.currentTime,originalSetter.call(this,newValue))},Object.defineProperty(AudioParam.prototype,"value",descriptor),AudioParam.prototype.getValueAtTime=function(time){return function(audioParam,time){return hasScheduledChanges(audioParam)?evaluateSchedulement(audioParam._scheduledChanges,audioParam._value,audioParam._valueWasLastSetAt,time):audioParam._value}(this,time)},AudioParam.prototype.hasScheduledChangesAtTime=function(time){return function(audioParam,time){return any_1(compose_1(gt_1(__,time),prop_1("targetTime")),audioParam._scheduledChanges)}(this,time)})}(); diff --git a/src/helpers.js b/src/helpers.js index c4e0234..89b2913 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,6 +1,6 @@ /* global BaseAudioContext, AudioContext, webkitAudioContext, AudioParam */ -import { isEmpty, prop, compose, complement, clamp, isNil, reject, append, equals, lt, __, gte, either, filter, both, reduce, max, pluck, unless, find, propEq, min, gt, last, has, all, props, add, length, head, without, sortBy } from 'ramda' +import { isEmpty, prop, compose, complement, clamp, isNil, reject, append, equals, lt, __, gte, either, filter, both, reduce, max, pluck, unless, find, propEq, min, gt, last, has, all, props, add, length, head, without, sortBy, any } from 'ramda' import { getLinearRampToValueAtTime, getExponentialRampToValueAtTime, getTargetValueAtTime, getValueCurveAtTime } from 'pseudo-audio-param/lib/expr.js' const AudioContextClass = isNil(window.BaseAudioContext) ? (isNil(window.AudioContext) ? webkitAudioContext : AudioContext) : BaseAudioContext @@ -148,6 +148,10 @@ const hasScheduledChanges = compose( prop('_scheduledChanges') ) +const hasScheduledChangesAtTime = (audioParam, time) => { + return any(compose(gt(__, time), prop('targetTime')), audioParam._scheduledChanges) +} + const getValueAtTime = (audioParam, time) => { if (hasScheduledChanges(audioParam)) { return evaluateSchedulement(audioParam._scheduledChanges, audioParam._value, audioParam._valueWasLastSetAt, time) @@ -222,5 +226,6 @@ export { getValueAtTime, bindContextToParams, bindSchedulerToParamMethod, - hijackParamValueSetter + hijackParamValueSetter, + hasScheduledChangesAtTime } diff --git a/src/index.js b/src/index.js index 95c49e7..8feebcb 100644 --- a/src/index.js +++ b/src/index.js @@ -6,7 +6,7 @@ import { bindContextToParams, bindSchedulerToParamMethod, hijackParamValueSetter, - hasScheduledChanges + hasScheduledChangesAtTime } from './helpers' if (!isNil(window.AudioParam) && isNil(AudioParam.prototype.getValueAtTime)) { @@ -40,8 +40,8 @@ if (!isNil(window.AudioParam) && isNil(AudioParam.prototype.getValueAtTime)) { return getValueAtTime(audioParam, time) } - AudioParam.prototype.hasScheduledChanges = function () { + AudioParam.prototype.hasScheduledChangesAtTime = function (time) { const audioParam = this - return hasScheduledChanges(audioParam) + return hasScheduledChangesAtTime(audioParam, time) } }