diff --git a/README.md b/README.md index d9c518b..869b34f 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,8 @@ picoAudio.play(); ### 停止 ```javascript -// 停止 -picoAudio.stop(); +// 一時停止 +picoAudio.pause(); ``` @@ -93,10 +93,10 @@ PicoAudio.setData(parsedSMF: ParsedSMF): void PicoAudio.play(isLoop: boolean): void ``` -#### PicoAudio.stop +#### PicoAudio.pause ```typescript -// 楽曲の停止 -PicoAudio.stop(): void +// 楽曲の一時停止 +PicoAudio.pause(): void ``` #### PicoAudio.initStatus @@ -154,7 +154,7 @@ PicoAudio.setCC111(enable: boolean): void ```typeScript // イベントリスナを登録 PicoAudio.addEventListener( - type: <'play' | 'stop' | 'noteOn' | 'noteOff' | 'songEnd'>, + type: <'play' | 'pause' | 'noteOn' | 'noteOff' | 'songEnd'>, listener: Function ): void ``` @@ -209,7 +209,7 @@ PicoAudio.addEventListener( ```typescript // 指定のイベントリスナを解除 PicoAudio.removeEventListener( - type: <'play' | 'stop' | 'noteOn' | 'noteOff' | 'songEnd'>, + type: <'play' | 'pause' | 'noteOn' | 'noteOff' | 'songEnd'>, listener: Function ): void ``` @@ -218,7 +218,7 @@ PicoAudio.removeEventListener( ```typescript // 指定typeのイベントリスナをすべて解除 PicoAudio.removeAllEventListener( - type: <'play' | 'stop' | 'noteOn' | 'noteOff' | 'songEnd'> + type: <'play' | 'pause' | 'noteOn' | 'noteOff' | 'songEnd'> ): void ``` diff --git a/dist/browser/PicoAudio.js b/dist/browser/PicoAudio.js index 38255fb..523bfea 100644 --- a/dist/browser/PicoAudio.js +++ b/dist/browser/PicoAudio.js @@ -1220,6 +1220,7 @@ var PicoAudio = (function () { this.trigger.stop(); + this.fireEvent('pause'); this.fireEvent('stop'); } @@ -3836,7 +3837,7 @@ var PicoAudio = (function () { var PicoAudio = /*#__PURE__*/function () { /** * PicoAudioクラスのコンストラクタ - * @param {Object} argsObj + * @param {Object} argsObj */ function PicoAudio(argsObj) { _classCallCheck(this, PicoAudio); @@ -3845,7 +3846,7 @@ var PicoAudio = (function () { } /** * 初期化・準備 - * @param {Object} argsObj + * @param {Object} argsObj */ @@ -3885,6 +3886,16 @@ var PicoAudio = (function () { value: function play$1(_isSongLooping) { return play.call(this, _isSongLooping); } + /** + * 一時停止 + * @param {boolean} _isSongLooping PicoAudio内部で使う引数 + */ + + }, { + key: "pause", + value: function pause(_isSongLooping) { + return stop.call(this, _isSongLooping); + } /** * 停止 * @param {boolean} _isSongLooping PicoAudio内部で使う引数 @@ -3937,11 +3948,11 @@ var PicoAudio = (function () { /** * 再生処理(Web Audio API の oscillator等で音を鳴らす) - * @param {Object} option - * @param {boolean} isDrum - * @param {boolean} isExpression - * @param {boolean} nonChannel - * @param {boolean} nonStop + * @param {Object} option + * @param {boolean} isDrum + * @param {boolean} isExpression + * @param {boolean} nonChannel + * @param {boolean} nonStop * @returns {Object} AudioNodeやパラメータを返す */ @@ -3952,7 +3963,7 @@ var PicoAudio = (function () { } /** * 音源(パーカッション以外) - * @param {Object} option + * @param {Object} option * @returns {Object} 音をストップさせる関数を返す */ @@ -3963,7 +3974,7 @@ var PicoAudio = (function () { } /** * パーカッション音源 - * @param {Object} option + * @param {Object} option * @returns {Object} 音をストップさせる関数を返す */ diff --git a/dist/browser/PicoAudio.min.js b/dist/browser/PicoAudio.min.js index 68272c7..8395e27 100644 --- a/dist/browser/PicoAudio.min.js +++ b/dist/browser/PicoAudio.min.js @@ -1 +1 @@ -var PicoAudio=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var a=0;a>>19^e^e>>>8;return t=Math.abs(t)/2147483648%2}}]),e}(),p=function(){function e(){t(this,e)}return i(e,null,[{key:"lerpWave",value:function(e,t){var a=e.getChannelData(0).length,i=t[0].length;if(a==i)for(var n=0;n<2;n++)for(var s=e.getChannelData(n),r=t[n],o=0;o=48e3?48e3:n;if(a&&a.whitenoise)this.whitenoise=a.whitenoise;else{h.resetSeed();for(var r=1*n,o=1*s,u=[],c=0;c<2;c++){u.push(new Float32Array(o));for(var l=u[c],m=0;m=.03&&V<.031?2*A:A)*(V>=.04&&V<.042?1.5*A:A)*(V>=.05&&V<.054?1.25*A:A)*h.random()*.2*Math.pow(A-.03,4);y[b]=k}}this.impulseResponse=this.context.createBuffer(2,f,this.context.sampleRate),p.lerpWave(this.impulseResponse,v)}this.convolver=this.context.createConvolver(),this.convolver.buffer=this.impulseResponse,this.convolver.normalize=!0,this.convolverGainNode=this.context.createGain(),this.convolverGainNode.gain.value=this.settings.reverbVolume,this.convolver.connect(this.convolverGainNode),this.convolverGainNode.connect(this.masterGainNode),this.masterGainNode.connect(this.context.destination),this.chorusDelayNode=this.context.createDelay(),this.chorusGainNode=this.context.createGain(),this.chorusOscillator=this.context.createOscillator(),this.chorusLfoGainNode=this.context.createGain(),this.chorusDelayNode.delayTime.value=.025,this.chorusLfoGainNode.gain.value=.01,this.chorusOscillator.frequency.value=.05,this.chorusGainNode.gain.value=this.settings.chorusVolume,this.chorusOscillator.connect(this.chorusLfoGainNode),this.chorusLfoGainNode.connect(this.chorusDelayNode.delayTime),this.chorusDelayNode.connect(this.chorusGainNode),this.chorusGainNode.connect(this.masterGainNode),this.masterGainNode.connect(this.context.destination),this.chorusOscillator.start(0),this.baseLatency=this.context.baseLatency||this.baseLatency,-1!=this.settings.baseLatency&&(this.baseLatency=this.settings.baseLatency)}}var f=function(){function e(){t(this,e)}return i(e,null,[{key:"now",value:function(){return null==this._now&&(void 0===window.performance?this._now=function(){return window.Date.now()}:this._now=function(){return window.performance.now()}),this._now()}}]),e}();function g(e){if(this.debug)var t=f.now();if(this.states.isPlaying&&this.stop(),this.playData=e,this.settings.resolution=e.header.resolution,this.settings.tempo=e.tempo||120,this.tempoTrack=e.tempoTrack,this.cc111Time=e.cc111Time,this.firstNoteOnTiming=e.firstNoteOnTiming,this.lastNoteOffTiming=e.lastNoteOffTiming,this.firstNoteOnTime=e.firstNoteOnTime,this.lastNoteOffTime=e.lastNoteOffTime,this.initStatus(),this.debug){var a=f.now();console.log("setData time",a-t)}return this}function v(e,t){if((!this.settings.isWebMIDI||null==this.states.webMIDIWaitState)&&(this.stop(e),this.states={isPlaying:!1,startTime:0,stopTime:0,stopFuncs:[],webMIDIWaitState:null,webMIDIStopTime:this.states.webMIDIStopTime,playIndices:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],updateBufTime:this.states.updateBufTime,updateBufMaxTime:this.states.updateBufMaxTime,updateIntervalTime:this.states.updateIntervalTime,latencyLimitTime:this.states.latencyLimitTime,noteOnAry:[],noteOffAry:[]},this.settings.isWebMIDI&&!t)){if(e)return;if(null==this.settings.WebMIDIPortOutput)return void this.startWebMIDI();if(this.settings.WebMIDIPortSysEx)this.settings.WebMIDIPortOutput.send([240,126,127,9,1,247]);else for(var a=0;a<16;a++)this.settings.WebMIDIPortOutput.send([192+a,0]),this.settings.WebMIDIPortOutput.send([224+a,0,64]),this.settings.WebMIDIPortOutput.send([176+a,100,0]),this.settings.WebMIDIPortOutput.send([176+a,101,0]),this.settings.WebMIDIPortOutput.send([176+a,6,2]),this.settings.WebMIDIPortOutput.send([176+a,100,1]),this.settings.WebMIDIPortOutput.send([176+a,96,0]),this.settings.WebMIDIPortOutput.send([176+a,97,64]),this.settings.WebMIDIPortOutput.send([176+a,7,100]),this.settings.WebMIDIPortOutput.send([176+a,10,64]),this.settings.WebMIDIPortOutput.send([176+a,11,127]),this.settings.WebMIDIPortOutput.send([176+a,98,0]),this.settings.WebMIDIPortOutput.send([176+a,99,0]),this.settings.WebMIDIPortOutput.send([176+a,122,0])}}var d=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}(l,e);var a,o,u=(a=l,o=r(),function(){var e,t=n(a);if(o){var i=n(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return c(this,e)});function l(){return t(this,l),u.apply(this,arguments)}return i(l,null,[{key:"delete",value:function(e,t){t==e.length-1?e.pop():0==t?e.shift():e.splice(t,1)}}]),l}(u(Array)),y=function(){function e(){t(this,e)}return i(e,null,[{key:"getInt",value:function(e,t,a){for(var i=0,n=t;n=128;)i=4&&a=4?s[t.indicesFoot+3]=t.indicesLength:t.indicesHead=0,t.indicesFoot=t.indicesLength,s[t.indicesLength]=a,s[t.indicesLength+1]=n,s[t.indicesLength+2]=i,s[t.indicesLength+3]=-1,t.indicesLength+=4}}]),e}(),b=function(){function e(){t(this,e)}return i(e,null,[{key:"init",value:function(e,t){this.updatePreTime=f.now(),this.pPreTime=f.now(),this.cPreTime=1e3*e.context.currentTime,this.pTimeSum=0,this.cTimeSum=0,this.cnt=0,this.initCurrentTime=t}},{key:"update",value:function(e){var t=this,a=e.context,i=e.settings,n=e.states,s=e.baseLatency,r=f.now(),o=this.updatePreTime,u=this.pPreTime,c=this.cPreTime,l=this.pTimeSum,m=this.cTimeSum,h=this.cnt,p=r-o,T=r,g=1e3*a.currentTime;l+=T-u,m+=g-c,u=T,c=g;var v=l-m;if(n.latencyTime=v,v>=100?(n.latencyLimitTime+=v,m+=100):v<=-100?m=l:n.latencyLimitTime>0&&(n.latencyLimitTime-=.003*p,n.latencyLimitTime<0&&(n.latencyLimitTime=0)),n.updateIntervalTime=p,n.updateBufTime350&&(n.updateBufMaxTime-=.002*n.updateBufMaxTime),n.updateBufTime<20&&(n.updateBufTime+=5e-4*n.updateBufTime),n.updateBufMaxTime>=10&&n.updateBufMaxTime<340&&(n.updateBufMaxTime+=.002*n.updateBufMaxTime)),n.updateBufTime>n.updateBufMaxTime){if(p>=900&&n.latencyLimitTime<=150)n.updateBufMaxTime+=p;else{var d=p-n.updateBufMaxTime;n.updateBufTime=n.updateBufMaxTime,n.updateBufMaxTime<10?(n.updateBufTime=n.updateBufMaxTime,n.updateBufMaxTime*=1.25):n.updateBufMaxTime+=d/2}n.updateBufMaxTime>1100&&(n.updateBufMaxTime=1100)}n.latencyLimitTime>150&&(m=l,n.latencyLimitTime-=5,n.latencyLimitTime>1e3&&(n.latencyLimitTime=1e3),n.updateBufMaxTime=1,n.updateBufTime=1,p=1);for(var b=0;b<16;b++){for(var A=e.playData.channels[b].notes,V=n.playIndices[b],k=function(){var r=A[V],o=0==h?t.initCurrentTime-n.startTime:a.currentTime-n.startTime;if(o>=r.stopTime)return"continue";if(0==h&&o>r.startTime+s)return"continue";if(o=350&&n.updateBufTime<1e3&&(n.updateBufTime=12,n.updateBufMaxTime=n.updateBufTime),-1!=i.maxPoly||-1!=i.maxPercPoly){var u=0,c=0;if(n.stopFuncs.forEach((function(e){e.note&&(9!=e.note.channel?r.start>=e.note.start&&r.start=i.maxPoly||9==r.channel&&c>=i.maxPercPoly)return"continue"}var l=9!=r.channel?e.createNote(r):e.createPercussionNote(r);if(!l)return"continue";e.pushFunc({note:r,stopFunc:l})}n.noteOnAry.push(r)};Vw.time+1)){if(O0&&(h=!1);var a=e.time+u+c;a<0&&(a=0),T.gain.setValueAtTime(t,a)})):p>0&&(h=!1),h)return{isGainValueZero:!0};var f=e.startTime+u+c,g=e.stopTime+u+c,v=r.basePitch*Math.pow(Math.pow(2,1/12),(e.pitch||69)-69),d=t?o.createBufferSource():o.createOscillator(),y=o.createStereoPanner?o.createStereoPanner():o.createPanner?o.createPanner():{pan:{setValueAtTime:function(){}}},b=o.createGain(),A=o.createGain();t?(d.loop=!0,d.buffer=this.whitenoise):(d.type=e.type||"sine",d.detune.value=0,d.frequency.value=v,e.pitchBend&&e.pitchBend.forEach((function(t){var a=t.time+u+c;a<0&&(a=0),d.frequency.setValueAtTime(r.basePitch*Math.pow(Math.pow(2,1/12),e.pitch-69+t.value),a)})));var V,k,R=e.pan&&64!=e.pan[0].value?e.pan[0].value/127*2-1:0;if(function(e,t,a){if(e.createStereoPanner)a>1&&(a=1),t.pan.value=a;else if(e.createPanner){var i=I(a);t.panningModel="equalpower",t.setPosition(i.x,i.y,i.z)}}(o,y,R),o.createStereoPanner||o.createPanner){var M=!0;if(o.createStereoPanner)e.pan&&e.pan.forEach((function(e){if(M)M=!1;else{var t=64==e.value?0:e.value/127*2-1;t>1&&(t=1);var a=e.time+u+c;a<0&&(a=0),y.pan.setValueAtTime(t,a)}}));else if(o.createPanner)if(y.positionX){var N=!0;e.pan&&e.pan.forEach((function(e){if(N)N=!1;else{var t=I(64==e.value?0:e.value/127*2-1),a=e.time+u+c;a<0&&(a=0),y.positionX.setValueAtTime(t.x,a),y.positionY.setValueAtTime(t.y,a),y.positionZ.setValueAtTime(t.z,a)}}))}else e.pan&&e.pan.forEach((function(e){if(M)M=!1;else{var t=setTimeout((function(){s.clearFunc("pan",t);var a=64==e.value?0:e.value/127*2-1;a>1&&(a=1);var i=I(a);y.setPosition(i.x,i.y,i.z)}),1e3*(e.time+u+c-o.currentTime));s.pushFunc({pan:t,stopFunc:function(){clearTimeout(t)}})}}));d.connect(y),y.connect(T)}else d.connect(T);if(T.connect(b),b.connect(A),A.connect(this.masterGainNode),this.masterGainNode.connect(o.destination),!t&&e.modulation&&(e.modulation.length>=2||e.modulation[0].value>0)){V=o.createOscillator(),k=o.createGain();var w=!0;e.modulation&&e.modulation.forEach((function(e){if(w)w=!1;else{var t=e.value/127;t>1&&(t=1);var a=e.time+u+c;a<0&&(a=0),k.gain.setValueAtTime(10*v/440*t,a)}}));var O=e.modulation?e.modulation[0].value/127:0;O>1&&(O=1),k.gain.value=10*v/440*O,V.frequency.value=6,V.connect(k),k.connect(d.frequency)}if(this.settings.isReverb&&e.reverb&&(e.reverb.length>=2||e.reverb[0].value>0)){var P=this.convolver,D=o.createGain(),x=!0;e.reverb&&e.reverb.forEach((function(e){if(x)x=!1;else{var t=e.value/127;t>1&&(t=1);var a=e.time+u+c;a<0&&(a=0),D.gain.setValueAtTime(t,a)}}));var S=e.reverb?e.reverb[0].value/127:0;S>1&&(S=1),D.gain.value=S,b.connect(A),A.connect(D),D.connect(P)}if(this.settings.isChorus&&e.chorus&&(e.chorus.length>=2||e.chorus[0].value>0)){var L=this.chorusDelayNode,W=o.createGain(),q=!0;e.chorus&&e.chorus.forEach((function(e){if(q)q=!1;else{var t=e.value/127;t>1&&(t=1);var a=e.time+u+c;a<0&&(a=0),W.gain.setValueAtTime(t,a)}}));var B=e.chorus?e.chorus[0].value/127:0;B>1&&(B=1),W.gain.value=B,b.connect(A),A.connect(W),W.connect(L)}return V&&(V.start(f),this.stopAudioNode(V,g,k)),d.start(f),t||i||n||this.stopAudioNode(d,g,A),{start:f,stop:g,pitch:v,channel:l,velocity:m,oscillator:d,panNode:y,gainNode:b,stopGainNode:A,isGainValueZero:!1}}function I(e){e>1&&(e=1);var t={},a=90*e;return t.x=Math.sin(a*(Math.PI/180)),t.y=0,t.z=-Math.cos(a*(Math.PI/180)),t}function R(e){var t=this,a=this.createBaseNote(e,!1,!0,!1,!0);if(a.isGainValueZero)return null;var i,n=a.oscillator,s=a.gainNode,r=a.stopGainNode,o=!1,u=!1;switch(1e3*this.channels[a.channel][0]||e.instrument){case 1e3:case 6:case 15:case 24:case 26:case 46:case 50:case 51:case 52:case 53:case 54:case 82:case 85:case 86:n.type="sine",s.gain.value*=1.5;break;case 2e3:case 4:case 12:case 13:case 16:case 19:case 20:case 32:case 34:case 45:case 48:case 49:case 55:case 56:case 57:case 61:case 62:case 63:case 71:case 72:case 73:case 74:case 75:case 76:case 77:case 78:case 79:case 80:case 84:n.type="square",s.gain.value*=.8;break;case 3e3:case 0:case 1:case 2:case 3:case 7:case 17:case 18:case 21:case 22:case 23:case 27:case 28:case 29:case 30:case 36:case 37:case 38:case 39:case 40:case 41:case 42:case 43:case 44:case 47:case 59:case 64:case 65:case 66:case 67:case 68:case 69:case 70:case 87:n.type="sawtooth";break;case 4e3:case 8:case 9:case 10:case 11:case 14:case 25:case 31:case 33:case 35:case 58:case 60:case 83:case 88:case 89:case 90:case 91:case 92:case 93:case 94:case 95:n.type="triangle",s.gain.value*=1.5;break;default:n.type="square"}switch(("sine"==n.type||"triangle"==n.type)&&!o&&a.stop-a.start>.01&&(u=!0),this.channels[a.channel][1]/10||e.instrument){case.2:case 12:case 13:case 45:case 55:o=!0,s.gain.value*=1.1,s.gain.setValueAtTime(s.gain.value,a.start),s.gain.linearRampToValueAtTime(0,a.start+.2),this.stopAudioNode(n,a.start+.2,r);break;case.3:case 0:case 1:case 2:case 3:case 6:case 9:case 11:case 14:case 15:case 32:case 36:case 37:case 46:case 47:s.gain.value*=1.1;var c=(128-e.pitch)/128;s.gain.setValueAtTime(s.gain.value,a.start),s.gain.linearRampToValueAtTime(.85*s.gain.value,a.start+c*c/8),s.gain.linearRampToValueAtTime(.8*s.gain.value,a.start+c*c/4),s.gain.setTargetAtTime(0,a.start+c*c/4,5*c*c),this.stopAudioNode(n,a.stop,r,u);break;case.4:case 24:case 25:case 26:case 27:case 28:case 29:case 30:case 31:case 34:s.gain.value*=1.1,s.gain.setValueAtTime(s.gain.value,a.start),s.gain.linearRampToValueAtTime(0,a.start+1+4*a.velocity),this.stopAudioNode(n,a.stop,r,u);break;case.5:case 4:case 5:case 7:case 8:case 10:case 33:case 35:s.gain.value*=1,s.gain.setValueAtTime(s.gain.value,a.start),s.gain.linearRampToValueAtTime(.95*s.gain.value,a.start+.1),s.gain.setValueAtTime(.95*s.gain.value,a.start+.1),s.gain.linearRampToValueAtTime(0,a.start+2+10*a.velocity),this.stopAudioNode(n,a.stop,r,u);break;case 119:if(s.gain.value=0,this.stopAudioNode(n,a.stop,r,u),(i=this.createBaseNote(e,!0,!0)).isGainValueZero)break;i.oscillator.playbackRate.setValueAtTime((e.pitch+1)/128,a.start),i.gainNode.gain.setValueAtTime(0,a.start),i.gainNode.gain.linearRampToValueAtTime(1.3,a.start+2),this.stopAudioNode(i.oscillator,a.stop,i.stopGainNode);break;default:s.gain.value*=1.1,s.gain.setValueAtTime(s.gain.value,a.start),this.stopAudioNode(n,a.stop,r,u)}return function(){t.stopAudioNode(n,0,r,!0),i&&i.oscillator&&t.stopAudioNode(i.oscillator,0,i.stopGainNode,!0)}}function M(e){var t=this,a=this.createBaseNote(e,!0,!1);if(a.isGainValueZero)return null;var i=a.oscillator,n=a.gainNode,s=a.stopGainNode,r=a.start,o=this.createBaseNote(e,!1,!1,!0),u=o.oscillator,c=o.gainNode,l=o.stopGainNode,m=e.nextSameNoteOnInterval;rm&&(h=m),p>m&&(p=m)),this.stopAudioNode(i,r+h,s),this.stopAudioNode(u,r+p,l),e.drumStopTime=e.startTime+(h>=p?h:p),function(){t.stopAudioNode(i,0,s,!0),t.stopAudioNode(u,0,l,!0)}}function N(e,t,a,i){var n=t-.005,s=t;t<=this.context.currentTime&&(i?(n=this.context.currentTime,s=this.context.currentTime+.005):s=this.context.currentTime);try{i?(e.stop(s),a.gain.cancelScheduledValues(0),a.gain.setValueAtTime(1,n),a.gain.linearRampToValueAtTime(0,s)):e.stop(s)}catch(e){a.gain.cancelScheduledValues(0),i?(a.gain.setValueAtTime(1,n),a.gain.linearRampToValueAtTime(0,s)):a.gain.setValueAtTime(0,s)}}function w(e){(e.note||e.rootTimeout||e.pan||this.trigger.isNoteTrigger)&&this.states.stopFuncs.push(e)}function O(e,t){("note"==e||"rootTimeout"==e||"pan"==e||this.trigger.isNoteTrigger)&&this.states.stopFuncs.some((function(a,i,n){if(a[e]==t)return d.delete(n,i),!0}))}function P(e){var t=-1;if(this.tempoTrack&&this.tempoTrack.length>=1){if(e>=this.tempoTrack[this.tempoTrack.length-1].timing)return this.tempoTrack[this.tempoTrack.length-1].time;for(var a=0,i=this.tempoTrack.length-1;;){t=Math.floor(a+(i-a)/2);var n=this.tempoTrack[t].timing;if(en))break;a=t+1}if(a>i){e=0){var u=this.tempoTrack[t];s=u.time,r=u.timing,o=u.value}return s+=60/o/this.settings.resolution*(e-r)}function D(e){var t=-1;if(this.tempoTrack&&this.tempoTrack.length>=1){if(e>=this.tempoTrack[this.tempoTrack.length-1].time)return this.tempoTrack[this.tempoTrack.length-1].timing;for(var a=0,i=this.tempoTrack.length-1;;){t=Math.floor(a+(i-a)/2);var n=this.tempoTrack[t].time;if(en))break;a=t+1}if(a>i){e=0){var u=this.tempoTrack[t];s=u.time,r=u.timing,o=u.value}return r+=(e-s)/(60/o/this.settings.resolution)}function x(e){var t=e.smf,a=4,i={};i.size=y.getInt(t,4,8),i.format=t[9],i.trackcount=y.getInt(t,10,12),i.timemanage=t[12],i.resolution=y.getInt(t,12,14),a+=4+i.size;for(var n=[],s=this.settings.isWebMIDI?17:16,r=0;r>4){case 8:case 9:case 10:case 11:case 14:var d=n[15&(T=t[a])];y.chIndicesInsert(this,d,l,a,3),a+=3;break;case 12:case 13:var b=n[15&(T=t[a])];y.chIndicesInsert(this,b,l,a,2),a+=2;break;case 15:switch(t[a]){case 240:case 247:var A=y.variableLengthToInt(t,a+1,a+1+4);if(A[0]>=7&&127==t[a+2]&&127==t[a+3]&&4==t[a+4]&&1==t[a+5])for(var V=0;V<16;V++){var k=n[V];y.chIndicesInsert(this,k,l,a,A[0])}a+=1+A[1]+A[0];break;case 241:a+=2;break;case 242:a+=3;break;case 243:a+=2;break;case 246:case 248:case 250:case 251:case 252:case 254:a+=1;break;case 255:switch(t[a+1]){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 32:break;case 47:l+=(this.settings.isSkipEnding?0:i.resolution)-f;break;case 81:for(var I=0;I<16;I++){var R=n[I];y.chIndicesInsert(this,R,l,a,6)}p+=60/m/i.resolution*(l-h),h=l,m=6e7/(65536*t[a+3]+256*t[a+4]+t[a+5]),s.push({timing:l,time:p,value:m});break;case 84:break;case 88:r.push({timing:l,value:[t[a+3],Math.pow(2,t[a+4])]})}var M=y.variableLengthToInt(t,a+2,a+2+4);a+=2+M[1]+M[0]}break;default:if(null==T)return"Irregular SMF. ("+a+" byte addr)";t[--a]=T,T=null}this.settings.isWebMIDI&&null!=T&&y.chIndicesInsert(this,n[16],l,v,a-v)}!this.settings.isSkipEnding&&o>4;switch(q){case 8:case 9:if(9==q&&0!=r[u+2]){var B={start:e,stop:null,startTime:W,stopTime:null,pitch:r[u+1],pitchBend:[{timing:e,time:W,value:v}],pan:[{timing:e,time:W,value:y}],expression:[{timing:e,time:W,value:b*(O/127)}],velocity:r[u+2]/127*(A/127),modulation:[{timing:e,time:W,value:V}],holdBeforeStop:null,reverb:[{timing:e,time:W,value:I}],chorus:[{timing:e,time:W,value:R}],instrument:w,channel:t,nextSameNoteOnInterval:-1,drumStopTime:2},E=S[r[u+1]];E&&(E.nextSameNoteOnInterval=W-E.startTime),S[r[u+1]]=B,P.some((function(t,a){var i=c.notes[t];i.pitch==r[u+1]&&null==i.stop&&(i.stop=e,i.stopTime=W,d.delete(P,a))})),P.push(c.notes.length),c.notes.push(B),e=s.settings.holdOnValue?null==i.holdBeforeStop&&(i.holdBeforeStop=[{timing:e,time:W,value:k}]):(i.stop=e,i.stopTime=W,d.delete(P,a)),e>f&&(f=e,g=W),!0}));break;case 10:break;case 11:switch(r[u+1]){case 1:V=r[u+2],P.forEach((function(t){c.notes[t].modulation.push({timing:e,time:W,value:V})}));break;case 6:0==M&&0==N&&(l=r[u+2])>24&&(l=24);break;case 7:A=r[u+2];break;case 10:y=r[u+2],P.forEach((function(t){c.notes[t].pan.push({timing:e,time:W,value:y})}));break;case 11:b=r[u+2],P.forEach((function(t){c.notes[t].expression.push({timing:e,time:W,value:b*(O/127)})}));break;case 64:if((k=r[u+2])=0;C--){var G=P[C],F=c.notes[G];null==F.stop&&null!=F.holdBeforeStop&&(F.stop=e,F.stopTime=W,d.delete(P,C))}break;case 91:I=r[u+2],P.forEach((function(t){c.notes[t].reverb.push({timing:e,time:W,value:I})}));break;case 93:R=r[u+2],P.forEach((function(t){c.notes[t].chorus.push({timing:e,time:W,value:R})}));break;case 98:r[u+2];break;case 99:r[u+2];break;case 100:M=r[u+2];break;case 101:N=r[u+2];break;case 111:-1==m&&(m=e,h=W)}break;case 12:w=r[u+1];break;case 13:break;case 14:v=(128*r[u+2]+r[u+1]-8192)/8192*l,P.forEach((function(t){c.notes[t].pitchBend.push({timing:e,time:W,value:v})}));break;case 15:switch(r[u]){case 240:case 247:if(127==r[u+1]&&127==r[u+2]&&4==r[u+3]&&1==r[u+4]){var _=r[u+6];_>127&&(_=127),O=_,P.forEach((function(t){c.notes[t].expression.push({timing:e,time:W,value:b*(O/127)})}))}break;case 255:switch(r[u+1]){case 81:n+=60/a/o.resolution*(e-i),i=e,a=6e7/(65536*r[u+3]+256*r[u+4]+r[u+5])}}break;default:return{v:{v:"Error parseSMF. "}}}D=L};-1!=D;){var W=L();if("object"===e(W))return W.v}c.nowNoteOnIdxAry=P,s.debug||delete c.indices},y=0;y<16;y++){var b=v(y);if("object"===e(b))return b.v}for(var A=0;A<16;A++){for(var V=u[A],k=V.nowNoteOnIdxAry,I=function(e){var t=V.notes[k[e]];if(null==t.stop){t.stop=f,t.stopTime=g;["pitchBend","pan","expression","modulation","reverb","chorus"].forEach((function(e){for(var a=t[e],i=a.length-1;i>=1;i--){a[i].timing>f&&d.delete(a,i)}})),d.delete(k,e)}},R=k.length-1;R>=0;R--)I(R);delete V.nowNoteOnIdxAry}this.settings.isSkipEnding&&(l=f),c.push({timing:l,time:60/a/o.resolution*(l-i)+n,value:120});var M=[];if(this.settings.isWebMIDI)for(var N=u[16],w=120,O=0,P=0,D=N.indicesHead,x=N.indices;-1!=D;){var S=x[D],L=x[D+1],W=x[D+2],q=x[D+3],B=60/w/o.resolution*(S-O)+P;switch(r[W]){case 255:switch(r[W+1]){case 81:P+=60/w/o.resolution*(S-O),O=S,w=6e7/(65536*r[W+3]+256*r[W+4]+r[W+5])}}M.push({time:B,tick:S,smfPtr:W,smfPtrLen:L}),D=q}return t.songLength=l,t.cc111Tick=m,t.cc111Time=h,t.firstNoteOnTiming=p,t.firstNoteOnTime=T,t.lastNoteOffTiming=f,t.lastNoteOffTime=g,this.settings.isWebMIDI&&(t.messages=M,t.smfData=new Uint8Array(r)),t}function W(e){if(this.debug){console.log(e);var t=f.now()}var a=new Uint8Array(e);if(77!=a[0]||84!=a[1]||104!=a[2]||100!=a[3])return"Not Sandard MIDI File.";var i={};if(i.smf=a,x.call(this,i),this.debug)var n=f.now();if(S.call(this,i),this.debug)var s=f.now();L.call(this,i);var r={};if(r.header=i.header,r.tempoTrack=i.tempoTrack,r.beatTrack=i.beatTrack,r.channels=i.channels,r.songLength=i.songLength,r.cc111Tick=i.cc111Tick,r.cc111Time=i.cc111Time,r.firstNoteOnTiming=i.firstNoteOnTiming,r.firstNoteOnTime=i.firstNoteOnTime,r.lastNoteOffTiming=i.lastNoteOffTiming,r.lastNoteOffTime=i.lastNoteOffTime,this.settings.isWebMIDI&&(r.messages=i.messages,r.smfData=new Uint8Array(a)),this.debug){var o=f.now();console.log("parseSMF time",o-t),console.log("parseSMF(0/2) time",n-t),console.log("parseSMF(1/2) time",s-n),console.log("parseSMF(2/2) time",o-s),console.log(r)}return r}function q(){var e=this;if(navigator.requestMIDIAccess){var t=this.settings.WebMIDIPortSysEx,a=function(a){var i,n=a.outputs;return e.settings.WebMIDIPortOutputs=n,-1==e.settings.WebMIDIPort?e.settings.WebMIDIPortOutputs.forEach((function(e){i||(i=e)})):i=e.settings.WebMIDIPortOutputs.get(e.settings.WebMIDIPort),e.settings.WebMIDIPortOutput=i,e.settings.WebMIDIPortSysEx=t,i&&(i.open(),e.initStatus()),n};navigator.requestMIDIAccess({sysex:t}).then(a).catch((function e(i){console.log(i),t&&(t=!1,navigator.requestMIDIAccess({sysex:t}).then(a).catch(e))})),window.addEventListener("unload",(function(){for(var t=0;t<16;t++){e.settings.WebMIDIPortOutput.send([176+t,120,0]);for(var a=0;a<128;a++)e.settings.WebMIDIPortOutput.send([128+t,a,0])}}))}}return function(){function e(a){t(this,e),l.call(this,a)}return i(e,[{key:"init",value:function(e){return T.call(this,e)}},{key:"parseSMF",value:function(e){return W.call(this,e)}},{key:"setData",value:function(e){return g.call(this,e)}},{key:"play",value:function(e){return A.call(this,e)}},{key:"stop",value:function(e){return V.call(this,e)}},{key:"initStatus",value:function(e,t){return v.call(this,e,t)}},{key:"setStartTime",value:function(e){this.states.startTime-=e}},{key:"getTime",value:function(e){return P.call(this,e)}},{key:"getTiming",value:function(e){return D.call(this,e)}},{key:"createBaseNote",value:function(e,t,a,i,n){return k.call(this,e,t,a,i,n)}},{key:"createNote",value:function(e){return R.call(this,e)}},{key:"createPercussionNote",value:function(e){return M.call(this,e)}},{key:"stopAudioNode",value:function(e,t,a,i){return N.call(this,e,t,a,i)}},{key:"pushFunc",value:function(e){return w.call(this,e)}},{key:"clearFunc",value:function(e,t){return O.call(this,e,t)}},{key:"startWebMIDI",value:function(){return q.call(this)}},{key:"addEventListener",value:function(e,t){this.events.push({type:e,func:t})}},{key:"removeEventListener",value:function(e,t){for(var a=this.events.length;a>=0;a--)event.type==e&&event.func===t&&this.events.splice(a,1)}},{key:"removeAllEventListener",value:function(e){for(var t=this.events.length;t>=0;t--)event.type==e&&this.events.splice(t,1)}},{key:"fireEvent",value:function(e,t){this.events.forEach((function(a){if(a.type==e)try{a.func(t)}catch(e){console.log(e)}}))}},{key:"setOnSongEndListener",value:function(e){this.onSongEndListener=e}},{key:"onSongEnd",value:function(){if(this.onSongEndListener&&this.onSongEndListener())return;this.settings.loop&&(this.initStatus(!0),this.settings.isCC111&&-1!=this.cc111Time&&this.setStartTime(this.cc111Time),this.play(!0))}},{key:"gethannels",value:function(){return this.channels}},{key:"setChannels",value:function(e){var t=this;e.forEach((function(e,a){t.channels[a]=e}))}},{key:"initChannels",value:function(){for(var e=0;e<16;e++)this.channels[e]=[0,0,1]}},{key:"getMasterVolume",value:function(){return this.settings.masterVolume}},{key:"setMasterVolume",value:function(e){this.settings.masterVolume=e,this.isStarted&&(this.masterGainNode.gain.value=this.settings.masterVolume)}},{key:"isLoop",value:function(){return this.settings.loop}},{key:"setLoop",value:function(e){this.settings.loop=e}},{key:"isWebMIDI",value:function(){return this.settings.isWebMIDI}},{key:"setWebMIDI",value:function(e){this.settings.isWebMIDI=e}},{key:"isCC111",value:function(){return this.settings.isCC111}},{key:"setCC111",value:function(e){this.settings.isCC111=e}},{key:"isReverb",value:function(){return this.settings.isReverb}},{key:"setReverb",value:function(e){this.settings.isReverb=e}},{key:"getReverbVolume",value:function(){return this.settings.reverbVolume}},{key:"setReverbVolume",value:function(e){this.settings.reverbVolume=e}},{key:"isChorus",value:function(){return this.settings.isChorus}},{key:"setChorus",value:function(e){this.settings.isChorus=e}},{key:"getChorusVolume",value:function(){return this.settings.chorusVolume}},{key:"setChorusVolume",value:function(e){this.settings.chorusVolume=e}}]),e}()}(); +var PicoAudio=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var a=0;a>>19^e^e>>>8;return t=Math.abs(t)/2147483648%2}}]),e}(),p=function(){function e(){t(this,e)}return i(e,null,[{key:"lerpWave",value:function(e,t){var a=e.getChannelData(0).length,i=t[0].length;if(a==i)for(var n=0;n<2;n++)for(var s=e.getChannelData(n),r=t[n],o=0;o=48e3?48e3:n;if(a&&a.whitenoise)this.whitenoise=a.whitenoise;else{h.resetSeed();for(var r=1*n,o=1*s,u=[],c=0;c<2;c++){u.push(new Float32Array(o));for(var l=u[c],m=0;m=.03&&V<.031?2*A:A)*(V>=.04&&V<.042?1.5*A:A)*(V>=.05&&V<.054?1.25*A:A)*h.random()*.2*Math.pow(A-.03,4);y[b]=k}}this.impulseResponse=this.context.createBuffer(2,f,this.context.sampleRate),p.lerpWave(this.impulseResponse,v)}this.convolver=this.context.createConvolver(),this.convolver.buffer=this.impulseResponse,this.convolver.normalize=!0,this.convolverGainNode=this.context.createGain(),this.convolverGainNode.gain.value=this.settings.reverbVolume,this.convolver.connect(this.convolverGainNode),this.convolverGainNode.connect(this.masterGainNode),this.masterGainNode.connect(this.context.destination),this.chorusDelayNode=this.context.createDelay(),this.chorusGainNode=this.context.createGain(),this.chorusOscillator=this.context.createOscillator(),this.chorusLfoGainNode=this.context.createGain(),this.chorusDelayNode.delayTime.value=.025,this.chorusLfoGainNode.gain.value=.01,this.chorusOscillator.frequency.value=.05,this.chorusGainNode.gain.value=this.settings.chorusVolume,this.chorusOscillator.connect(this.chorusLfoGainNode),this.chorusLfoGainNode.connect(this.chorusDelayNode.delayTime),this.chorusDelayNode.connect(this.chorusGainNode),this.chorusGainNode.connect(this.masterGainNode),this.masterGainNode.connect(this.context.destination),this.chorusOscillator.start(0),this.baseLatency=this.context.baseLatency||this.baseLatency,-1!=this.settings.baseLatency&&(this.baseLatency=this.settings.baseLatency)}}var f=function(){function e(){t(this,e)}return i(e,null,[{key:"now",value:function(){return null==this._now&&(void 0===window.performance?this._now=function(){return window.Date.now()}:this._now=function(){return window.performance.now()}),this._now()}}]),e}();function g(e){if(this.debug)var t=f.now();if(this.states.isPlaying&&this.stop(),this.playData=e,this.settings.resolution=e.header.resolution,this.settings.tempo=e.tempo||120,this.tempoTrack=e.tempoTrack,this.cc111Time=e.cc111Time,this.firstNoteOnTiming=e.firstNoteOnTiming,this.lastNoteOffTiming=e.lastNoteOffTiming,this.firstNoteOnTime=e.firstNoteOnTime,this.lastNoteOffTime=e.lastNoteOffTime,this.initStatus(),this.debug){var a=f.now();console.log("setData time",a-t)}return this}function v(e,t){if((!this.settings.isWebMIDI||null==this.states.webMIDIWaitState)&&(this.stop(e),this.states={isPlaying:!1,startTime:0,stopTime:0,stopFuncs:[],webMIDIWaitState:null,webMIDIStopTime:this.states.webMIDIStopTime,playIndices:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],updateBufTime:this.states.updateBufTime,updateBufMaxTime:this.states.updateBufMaxTime,updateIntervalTime:this.states.updateIntervalTime,latencyLimitTime:this.states.latencyLimitTime,noteOnAry:[],noteOffAry:[]},this.settings.isWebMIDI&&!t)){if(e)return;if(null==this.settings.WebMIDIPortOutput)return void this.startWebMIDI();if(this.settings.WebMIDIPortSysEx)this.settings.WebMIDIPortOutput.send([240,126,127,9,1,247]);else for(var a=0;a<16;a++)this.settings.WebMIDIPortOutput.send([192+a,0]),this.settings.WebMIDIPortOutput.send([224+a,0,64]),this.settings.WebMIDIPortOutput.send([176+a,100,0]),this.settings.WebMIDIPortOutput.send([176+a,101,0]),this.settings.WebMIDIPortOutput.send([176+a,6,2]),this.settings.WebMIDIPortOutput.send([176+a,100,1]),this.settings.WebMIDIPortOutput.send([176+a,96,0]),this.settings.WebMIDIPortOutput.send([176+a,97,64]),this.settings.WebMIDIPortOutput.send([176+a,7,100]),this.settings.WebMIDIPortOutput.send([176+a,10,64]),this.settings.WebMIDIPortOutput.send([176+a,11,127]),this.settings.WebMIDIPortOutput.send([176+a,98,0]),this.settings.WebMIDIPortOutput.send([176+a,99,0]),this.settings.WebMIDIPortOutput.send([176+a,122,0])}}var d=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}(l,e);var a,o,u=(a=l,o=r(),function(){var e,t=n(a);if(o){var i=n(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return c(this,e)});function l(){return t(this,l),u.apply(this,arguments)}return i(l,null,[{key:"delete",value:function(e,t){t==e.length-1?e.pop():0==t?e.shift():e.splice(t,1)}}]),l}(u(Array)),y=function(){function e(){t(this,e)}return i(e,null,[{key:"getInt",value:function(e,t,a){for(var i=0,n=t;n=128;)i=4&&a=4?s[t.indicesFoot+3]=t.indicesLength:t.indicesHead=0,t.indicesFoot=t.indicesLength,s[t.indicesLength]=a,s[t.indicesLength+1]=n,s[t.indicesLength+2]=i,s[t.indicesLength+3]=-1,t.indicesLength+=4}}]),e}(),b=function(){function e(){t(this,e)}return i(e,null,[{key:"init",value:function(e,t){this.updatePreTime=f.now(),this.pPreTime=f.now(),this.cPreTime=1e3*e.context.currentTime,this.pTimeSum=0,this.cTimeSum=0,this.cnt=0,this.initCurrentTime=t}},{key:"update",value:function(e){var t=this,a=e.context,i=e.settings,n=e.states,s=e.baseLatency,r=f.now(),o=this.updatePreTime,u=this.pPreTime,c=this.cPreTime,l=this.pTimeSum,m=this.cTimeSum,h=this.cnt,p=r-o,T=r,g=1e3*a.currentTime;l+=T-u,m+=g-c,u=T,c=g;var v=l-m;if(n.latencyTime=v,v>=100?(n.latencyLimitTime+=v,m+=100):v<=-100?m=l:n.latencyLimitTime>0&&(n.latencyLimitTime-=.003*p,n.latencyLimitTime<0&&(n.latencyLimitTime=0)),n.updateIntervalTime=p,n.updateBufTime350&&(n.updateBufMaxTime-=.002*n.updateBufMaxTime),n.updateBufTime<20&&(n.updateBufTime+=5e-4*n.updateBufTime),n.updateBufMaxTime>=10&&n.updateBufMaxTime<340&&(n.updateBufMaxTime+=.002*n.updateBufMaxTime)),n.updateBufTime>n.updateBufMaxTime){if(p>=900&&n.latencyLimitTime<=150)n.updateBufMaxTime+=p;else{var d=p-n.updateBufMaxTime;n.updateBufTime=n.updateBufMaxTime,n.updateBufMaxTime<10?(n.updateBufTime=n.updateBufMaxTime,n.updateBufMaxTime*=1.25):n.updateBufMaxTime+=d/2}n.updateBufMaxTime>1100&&(n.updateBufMaxTime=1100)}n.latencyLimitTime>150&&(m=l,n.latencyLimitTime-=5,n.latencyLimitTime>1e3&&(n.latencyLimitTime=1e3),n.updateBufMaxTime=1,n.updateBufTime=1,p=1);for(var b=0;b<16;b++){for(var A=e.playData.channels[b].notes,V=n.playIndices[b],k=function(){var r=A[V],o=0==h?t.initCurrentTime-n.startTime:a.currentTime-n.startTime;if(o>=r.stopTime)return"continue";if(0==h&&o>r.startTime+s)return"continue";if(o=350&&n.updateBufTime<1e3&&(n.updateBufTime=12,n.updateBufMaxTime=n.updateBufTime),-1!=i.maxPoly||-1!=i.maxPercPoly){var u=0,c=0;if(n.stopFuncs.forEach((function(e){e.note&&(9!=e.note.channel?r.start>=e.note.start&&r.start=i.maxPoly||9==r.channel&&c>=i.maxPercPoly)return"continue"}var l=9!=r.channel?e.createNote(r):e.createPercussionNote(r);if(!l)return"continue";e.pushFunc({note:r,stopFunc:l})}n.noteOnAry.push(r)};Vw.time+1)){if(O0&&(h=!1);var a=e.time+u+c;a<0&&(a=0),T.gain.setValueAtTime(t,a)})):p>0&&(h=!1),h)return{isGainValueZero:!0};var f=e.startTime+u+c,g=e.stopTime+u+c,v=r.basePitch*Math.pow(Math.pow(2,1/12),(e.pitch||69)-69),d=t?o.createBufferSource():o.createOscillator(),y=o.createStereoPanner?o.createStereoPanner():o.createPanner?o.createPanner():{pan:{setValueAtTime:function(){}}},b=o.createGain(),A=o.createGain();t?(d.loop=!0,d.buffer=this.whitenoise):(d.type=e.type||"sine",d.detune.value=0,d.frequency.value=v,e.pitchBend&&e.pitchBend.forEach((function(t){var a=t.time+u+c;a<0&&(a=0),d.frequency.setValueAtTime(r.basePitch*Math.pow(Math.pow(2,1/12),e.pitch-69+t.value),a)})));var V,k,R=e.pan&&64!=e.pan[0].value?e.pan[0].value/127*2-1:0;if(function(e,t,a){if(e.createStereoPanner)a>1&&(a=1),t.pan.value=a;else if(e.createPanner){var i=I(a);t.panningModel="equalpower",t.setPosition(i.x,i.y,i.z)}}(o,y,R),o.createStereoPanner||o.createPanner){var M=!0;if(o.createStereoPanner)e.pan&&e.pan.forEach((function(e){if(M)M=!1;else{var t=64==e.value?0:e.value/127*2-1;t>1&&(t=1);var a=e.time+u+c;a<0&&(a=0),y.pan.setValueAtTime(t,a)}}));else if(o.createPanner)if(y.positionX){var N=!0;e.pan&&e.pan.forEach((function(e){if(N)N=!1;else{var t=I(64==e.value?0:e.value/127*2-1),a=e.time+u+c;a<0&&(a=0),y.positionX.setValueAtTime(t.x,a),y.positionY.setValueAtTime(t.y,a),y.positionZ.setValueAtTime(t.z,a)}}))}else e.pan&&e.pan.forEach((function(e){if(M)M=!1;else{var t=setTimeout((function(){s.clearFunc("pan",t);var a=64==e.value?0:e.value/127*2-1;a>1&&(a=1);var i=I(a);y.setPosition(i.x,i.y,i.z)}),1e3*(e.time+u+c-o.currentTime));s.pushFunc({pan:t,stopFunc:function(){clearTimeout(t)}})}}));d.connect(y),y.connect(T)}else d.connect(T);if(T.connect(b),b.connect(A),A.connect(this.masterGainNode),this.masterGainNode.connect(o.destination),!t&&e.modulation&&(e.modulation.length>=2||e.modulation[0].value>0)){V=o.createOscillator(),k=o.createGain();var w=!0;e.modulation&&e.modulation.forEach((function(e){if(w)w=!1;else{var t=e.value/127;t>1&&(t=1);var a=e.time+u+c;a<0&&(a=0),k.gain.setValueAtTime(10*v/440*t,a)}}));var O=e.modulation?e.modulation[0].value/127:0;O>1&&(O=1),k.gain.value=10*v/440*O,V.frequency.value=6,V.connect(k),k.connect(d.frequency)}if(this.settings.isReverb&&e.reverb&&(e.reverb.length>=2||e.reverb[0].value>0)){var P=this.convolver,D=o.createGain(),x=!0;e.reverb&&e.reverb.forEach((function(e){if(x)x=!1;else{var t=e.value/127;t>1&&(t=1);var a=e.time+u+c;a<0&&(a=0),D.gain.setValueAtTime(t,a)}}));var S=e.reverb?e.reverb[0].value/127:0;S>1&&(S=1),D.gain.value=S,b.connect(A),A.connect(D),D.connect(P)}if(this.settings.isChorus&&e.chorus&&(e.chorus.length>=2||e.chorus[0].value>0)){var L=this.chorusDelayNode,W=o.createGain(),q=!0;e.chorus&&e.chorus.forEach((function(e){if(q)q=!1;else{var t=e.value/127;t>1&&(t=1);var a=e.time+u+c;a<0&&(a=0),W.gain.setValueAtTime(t,a)}}));var B=e.chorus?e.chorus[0].value/127:0;B>1&&(B=1),W.gain.value=B,b.connect(A),A.connect(W),W.connect(L)}return V&&(V.start(f),this.stopAudioNode(V,g,k)),d.start(f),t||i||n||this.stopAudioNode(d,g,A),{start:f,stop:g,pitch:v,channel:l,velocity:m,oscillator:d,panNode:y,gainNode:b,stopGainNode:A,isGainValueZero:!1}}function I(e){e>1&&(e=1);var t={},a=90*e;return t.x=Math.sin(a*(Math.PI/180)),t.y=0,t.z=-Math.cos(a*(Math.PI/180)),t}function R(e){var t=this,a=this.createBaseNote(e,!1,!0,!1,!0);if(a.isGainValueZero)return null;var i,n=a.oscillator,s=a.gainNode,r=a.stopGainNode,o=!1,u=!1;switch(1e3*this.channels[a.channel][0]||e.instrument){case 1e3:case 6:case 15:case 24:case 26:case 46:case 50:case 51:case 52:case 53:case 54:case 82:case 85:case 86:n.type="sine",s.gain.value*=1.5;break;case 2e3:case 4:case 12:case 13:case 16:case 19:case 20:case 32:case 34:case 45:case 48:case 49:case 55:case 56:case 57:case 61:case 62:case 63:case 71:case 72:case 73:case 74:case 75:case 76:case 77:case 78:case 79:case 80:case 84:n.type="square",s.gain.value*=.8;break;case 3e3:case 0:case 1:case 2:case 3:case 7:case 17:case 18:case 21:case 22:case 23:case 27:case 28:case 29:case 30:case 36:case 37:case 38:case 39:case 40:case 41:case 42:case 43:case 44:case 47:case 59:case 64:case 65:case 66:case 67:case 68:case 69:case 70:case 87:n.type="sawtooth";break;case 4e3:case 8:case 9:case 10:case 11:case 14:case 25:case 31:case 33:case 35:case 58:case 60:case 83:case 88:case 89:case 90:case 91:case 92:case 93:case 94:case 95:n.type="triangle",s.gain.value*=1.5;break;default:n.type="square"}switch(("sine"==n.type||"triangle"==n.type)&&!o&&a.stop-a.start>.01&&(u=!0),this.channels[a.channel][1]/10||e.instrument){case.2:case 12:case 13:case 45:case 55:o=!0,s.gain.value*=1.1,s.gain.setValueAtTime(s.gain.value,a.start),s.gain.linearRampToValueAtTime(0,a.start+.2),this.stopAudioNode(n,a.start+.2,r);break;case.3:case 0:case 1:case 2:case 3:case 6:case 9:case 11:case 14:case 15:case 32:case 36:case 37:case 46:case 47:s.gain.value*=1.1;var c=(128-e.pitch)/128;s.gain.setValueAtTime(s.gain.value,a.start),s.gain.linearRampToValueAtTime(.85*s.gain.value,a.start+c*c/8),s.gain.linearRampToValueAtTime(.8*s.gain.value,a.start+c*c/4),s.gain.setTargetAtTime(0,a.start+c*c/4,5*c*c),this.stopAudioNode(n,a.stop,r,u);break;case.4:case 24:case 25:case 26:case 27:case 28:case 29:case 30:case 31:case 34:s.gain.value*=1.1,s.gain.setValueAtTime(s.gain.value,a.start),s.gain.linearRampToValueAtTime(0,a.start+1+4*a.velocity),this.stopAudioNode(n,a.stop,r,u);break;case.5:case 4:case 5:case 7:case 8:case 10:case 33:case 35:s.gain.value*=1,s.gain.setValueAtTime(s.gain.value,a.start),s.gain.linearRampToValueAtTime(.95*s.gain.value,a.start+.1),s.gain.setValueAtTime(.95*s.gain.value,a.start+.1),s.gain.linearRampToValueAtTime(0,a.start+2+10*a.velocity),this.stopAudioNode(n,a.stop,r,u);break;case 119:if(s.gain.value=0,this.stopAudioNode(n,a.stop,r,u),(i=this.createBaseNote(e,!0,!0)).isGainValueZero)break;i.oscillator.playbackRate.setValueAtTime((e.pitch+1)/128,a.start),i.gainNode.gain.setValueAtTime(0,a.start),i.gainNode.gain.linearRampToValueAtTime(1.3,a.start+2),this.stopAudioNode(i.oscillator,a.stop,i.stopGainNode);break;default:s.gain.value*=1.1,s.gain.setValueAtTime(s.gain.value,a.start),this.stopAudioNode(n,a.stop,r,u)}return function(){t.stopAudioNode(n,0,r,!0),i&&i.oscillator&&t.stopAudioNode(i.oscillator,0,i.stopGainNode,!0)}}function M(e){var t=this,a=this.createBaseNote(e,!0,!1);if(a.isGainValueZero)return null;var i=a.oscillator,n=a.gainNode,s=a.stopGainNode,r=a.start,o=this.createBaseNote(e,!1,!1,!0),u=o.oscillator,c=o.gainNode,l=o.stopGainNode,m=e.nextSameNoteOnInterval;rm&&(h=m),p>m&&(p=m)),this.stopAudioNode(i,r+h,s),this.stopAudioNode(u,r+p,l),e.drumStopTime=e.startTime+(h>=p?h:p),function(){t.stopAudioNode(i,0,s,!0),t.stopAudioNode(u,0,l,!0)}}function N(e,t,a,i){var n=t-.005,s=t;t<=this.context.currentTime&&(i?(n=this.context.currentTime,s=this.context.currentTime+.005):s=this.context.currentTime);try{i?(e.stop(s),a.gain.cancelScheduledValues(0),a.gain.setValueAtTime(1,n),a.gain.linearRampToValueAtTime(0,s)):e.stop(s)}catch(e){a.gain.cancelScheduledValues(0),i?(a.gain.setValueAtTime(1,n),a.gain.linearRampToValueAtTime(0,s)):a.gain.setValueAtTime(0,s)}}function w(e){(e.note||e.rootTimeout||e.pan||this.trigger.isNoteTrigger)&&this.states.stopFuncs.push(e)}function O(e,t){("note"==e||"rootTimeout"==e||"pan"==e||this.trigger.isNoteTrigger)&&this.states.stopFuncs.some((function(a,i,n){if(a[e]==t)return d.delete(n,i),!0}))}function P(e){var t=-1;if(this.tempoTrack&&this.tempoTrack.length>=1){if(e>=this.tempoTrack[this.tempoTrack.length-1].timing)return this.tempoTrack[this.tempoTrack.length-1].time;for(var a=0,i=this.tempoTrack.length-1;;){t=Math.floor(a+(i-a)/2);var n=this.tempoTrack[t].timing;if(en))break;a=t+1}if(a>i){e=0){var u=this.tempoTrack[t];s=u.time,r=u.timing,o=u.value}return s+=60/o/this.settings.resolution*(e-r)}function D(e){var t=-1;if(this.tempoTrack&&this.tempoTrack.length>=1){if(e>=this.tempoTrack[this.tempoTrack.length-1].time)return this.tempoTrack[this.tempoTrack.length-1].timing;for(var a=0,i=this.tempoTrack.length-1;;){t=Math.floor(a+(i-a)/2);var n=this.tempoTrack[t].time;if(en))break;a=t+1}if(a>i){e=0){var u=this.tempoTrack[t];s=u.time,r=u.timing,o=u.value}return r+=(e-s)/(60/o/this.settings.resolution)}function x(e){var t=e.smf,a=4,i={};i.size=y.getInt(t,4,8),i.format=t[9],i.trackcount=y.getInt(t,10,12),i.timemanage=t[12],i.resolution=y.getInt(t,12,14),a+=4+i.size;for(var n=[],s=this.settings.isWebMIDI?17:16,r=0;r>4){case 8:case 9:case 10:case 11:case 14:var d=n[15&(T=t[a])];y.chIndicesInsert(this,d,l,a,3),a+=3;break;case 12:case 13:var b=n[15&(T=t[a])];y.chIndicesInsert(this,b,l,a,2),a+=2;break;case 15:switch(t[a]){case 240:case 247:var A=y.variableLengthToInt(t,a+1,a+1+4);if(A[0]>=7&&127==t[a+2]&&127==t[a+3]&&4==t[a+4]&&1==t[a+5])for(var V=0;V<16;V++){var k=n[V];y.chIndicesInsert(this,k,l,a,A[0])}a+=1+A[1]+A[0];break;case 241:a+=2;break;case 242:a+=3;break;case 243:a+=2;break;case 246:case 248:case 250:case 251:case 252:case 254:a+=1;break;case 255:switch(t[a+1]){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 32:break;case 47:l+=(this.settings.isSkipEnding?0:i.resolution)-f;break;case 81:for(var I=0;I<16;I++){var R=n[I];y.chIndicesInsert(this,R,l,a,6)}p+=60/m/i.resolution*(l-h),h=l,m=6e7/(65536*t[a+3]+256*t[a+4]+t[a+5]),s.push({timing:l,time:p,value:m});break;case 84:break;case 88:r.push({timing:l,value:[t[a+3],Math.pow(2,t[a+4])]})}var M=y.variableLengthToInt(t,a+2,a+2+4);a+=2+M[1]+M[0]}break;default:if(null==T)return"Irregular SMF. ("+a+" byte addr)";t[--a]=T,T=null}this.settings.isWebMIDI&&null!=T&&y.chIndicesInsert(this,n[16],l,v,a-v)}!this.settings.isSkipEnding&&o>4;switch(q){case 8:case 9:if(9==q&&0!=r[u+2]){var B={start:e,stop:null,startTime:W,stopTime:null,pitch:r[u+1],pitchBend:[{timing:e,time:W,value:v}],pan:[{timing:e,time:W,value:y}],expression:[{timing:e,time:W,value:b*(O/127)}],velocity:r[u+2]/127*(A/127),modulation:[{timing:e,time:W,value:V}],holdBeforeStop:null,reverb:[{timing:e,time:W,value:I}],chorus:[{timing:e,time:W,value:R}],instrument:w,channel:t,nextSameNoteOnInterval:-1,drumStopTime:2},E=S[r[u+1]];E&&(E.nextSameNoteOnInterval=W-E.startTime),S[r[u+1]]=B,P.some((function(t,a){var i=c.notes[t];i.pitch==r[u+1]&&null==i.stop&&(i.stop=e,i.stopTime=W,d.delete(P,a))})),P.push(c.notes.length),c.notes.push(B),e=s.settings.holdOnValue?null==i.holdBeforeStop&&(i.holdBeforeStop=[{timing:e,time:W,value:k}]):(i.stop=e,i.stopTime=W,d.delete(P,a)),e>f&&(f=e,g=W),!0}));break;case 10:break;case 11:switch(r[u+1]){case 1:V=r[u+2],P.forEach((function(t){c.notes[t].modulation.push({timing:e,time:W,value:V})}));break;case 6:0==M&&0==N&&(l=r[u+2])>24&&(l=24);break;case 7:A=r[u+2];break;case 10:y=r[u+2],P.forEach((function(t){c.notes[t].pan.push({timing:e,time:W,value:y})}));break;case 11:b=r[u+2],P.forEach((function(t){c.notes[t].expression.push({timing:e,time:W,value:b*(O/127)})}));break;case 64:if((k=r[u+2])=0;C--){var G=P[C],F=c.notes[G];null==F.stop&&null!=F.holdBeforeStop&&(F.stop=e,F.stopTime=W,d.delete(P,C))}break;case 91:I=r[u+2],P.forEach((function(t){c.notes[t].reverb.push({timing:e,time:W,value:I})}));break;case 93:R=r[u+2],P.forEach((function(t){c.notes[t].chorus.push({timing:e,time:W,value:R})}));break;case 98:r[u+2];break;case 99:r[u+2];break;case 100:M=r[u+2];break;case 101:N=r[u+2];break;case 111:-1==m&&(m=e,h=W)}break;case 12:w=r[u+1];break;case 13:break;case 14:v=(128*r[u+2]+r[u+1]-8192)/8192*l,P.forEach((function(t){c.notes[t].pitchBend.push({timing:e,time:W,value:v})}));break;case 15:switch(r[u]){case 240:case 247:if(127==r[u+1]&&127==r[u+2]&&4==r[u+3]&&1==r[u+4]){var _=r[u+6];_>127&&(_=127),O=_,P.forEach((function(t){c.notes[t].expression.push({timing:e,time:W,value:b*(O/127)})}))}break;case 255:switch(r[u+1]){case 81:n+=60/a/o.resolution*(e-i),i=e,a=6e7/(65536*r[u+3]+256*r[u+4]+r[u+5])}}break;default:return{v:{v:"Error parseSMF. "}}}D=L};-1!=D;){var W=L();if("object"===e(W))return W.v}c.nowNoteOnIdxAry=P,s.debug||delete c.indices},y=0;y<16;y++){var b=v(y);if("object"===e(b))return b.v}for(var A=0;A<16;A++){for(var V=u[A],k=V.nowNoteOnIdxAry,I=function(e){var t=V.notes[k[e]];if(null==t.stop){t.stop=f,t.stopTime=g;["pitchBend","pan","expression","modulation","reverb","chorus"].forEach((function(e){for(var a=t[e],i=a.length-1;i>=1;i--){a[i].timing>f&&d.delete(a,i)}})),d.delete(k,e)}},R=k.length-1;R>=0;R--)I(R);delete V.nowNoteOnIdxAry}this.settings.isSkipEnding&&(l=f),c.push({timing:l,time:60/a/o.resolution*(l-i)+n,value:120});var M=[];if(this.settings.isWebMIDI)for(var N=u[16],w=120,O=0,P=0,D=N.indicesHead,x=N.indices;-1!=D;){var S=x[D],L=x[D+1],W=x[D+2],q=x[D+3],B=60/w/o.resolution*(S-O)+P;switch(r[W]){case 255:switch(r[W+1]){case 81:P+=60/w/o.resolution*(S-O),O=S,w=6e7/(65536*r[W+3]+256*r[W+4]+r[W+5])}}M.push({time:B,tick:S,smfPtr:W,smfPtrLen:L}),D=q}return t.songLength=l,t.cc111Tick=m,t.cc111Time=h,t.firstNoteOnTiming=p,t.firstNoteOnTime=T,t.lastNoteOffTiming=f,t.lastNoteOffTime=g,this.settings.isWebMIDI&&(t.messages=M,t.smfData=new Uint8Array(r)),t}function W(e){if(this.debug){console.log(e);var t=f.now()}var a=new Uint8Array(e);if(77!=a[0]||84!=a[1]||104!=a[2]||100!=a[3])return"Not Sandard MIDI File.";var i={};if(i.smf=a,x.call(this,i),this.debug)var n=f.now();if(S.call(this,i),this.debug)var s=f.now();L.call(this,i);var r={};if(r.header=i.header,r.tempoTrack=i.tempoTrack,r.beatTrack=i.beatTrack,r.channels=i.channels,r.songLength=i.songLength,r.cc111Tick=i.cc111Tick,r.cc111Time=i.cc111Time,r.firstNoteOnTiming=i.firstNoteOnTiming,r.firstNoteOnTime=i.firstNoteOnTime,r.lastNoteOffTiming=i.lastNoteOffTiming,r.lastNoteOffTime=i.lastNoteOffTime,this.settings.isWebMIDI&&(r.messages=i.messages,r.smfData=new Uint8Array(a)),this.debug){var o=f.now();console.log("parseSMF time",o-t),console.log("parseSMF(0/2) time",n-t),console.log("parseSMF(1/2) time",s-n),console.log("parseSMF(2/2) time",o-s),console.log(r)}return r}function q(){var e=this;if(navigator.requestMIDIAccess){var t=this.settings.WebMIDIPortSysEx,a=function(a){var i,n=a.outputs;return e.settings.WebMIDIPortOutputs=n,-1==e.settings.WebMIDIPort?e.settings.WebMIDIPortOutputs.forEach((function(e){i||(i=e)})):i=e.settings.WebMIDIPortOutputs.get(e.settings.WebMIDIPort),e.settings.WebMIDIPortOutput=i,e.settings.WebMIDIPortSysEx=t,i&&(i.open(),e.initStatus()),n};navigator.requestMIDIAccess({sysex:t}).then(a).catch((function e(i){console.log(i),t&&(t=!1,navigator.requestMIDIAccess({sysex:t}).then(a).catch(e))})),window.addEventListener("unload",(function(){for(var t=0;t<16;t++){e.settings.WebMIDIPortOutput.send([176+t,120,0]);for(var a=0;a<128;a++)e.settings.WebMIDIPortOutput.send([128+t,a,0])}}))}}return function(){function e(a){t(this,e),l.call(this,a)}return i(e,[{key:"init",value:function(e){return T.call(this,e)}},{key:"parseSMF",value:function(e){return W.call(this,e)}},{key:"setData",value:function(e){return g.call(this,e)}},{key:"play",value:function(e){return A.call(this,e)}},{key:"pause",value:function(e){return V.call(this,e)}},{key:"stop",value:function(e){return V.call(this,e)}},{key:"initStatus",value:function(e,t){return v.call(this,e,t)}},{key:"setStartTime",value:function(e){this.states.startTime-=e}},{key:"getTime",value:function(e){return P.call(this,e)}},{key:"getTiming",value:function(e){return D.call(this,e)}},{key:"createBaseNote",value:function(e,t,a,i,n){return k.call(this,e,t,a,i,n)}},{key:"createNote",value:function(e){return R.call(this,e)}},{key:"createPercussionNote",value:function(e){return M.call(this,e)}},{key:"stopAudioNode",value:function(e,t,a,i){return N.call(this,e,t,a,i)}},{key:"pushFunc",value:function(e){return w.call(this,e)}},{key:"clearFunc",value:function(e,t){return O.call(this,e,t)}},{key:"startWebMIDI",value:function(){return q.call(this)}},{key:"addEventListener",value:function(e,t){this.events.push({type:e,func:t})}},{key:"removeEventListener",value:function(e,t){for(var a=this.events.length;a>=0;a--)event.type==e&&event.func===t&&this.events.splice(a,1)}},{key:"removeAllEventListener",value:function(e){for(var t=this.events.length;t>=0;t--)event.type==e&&this.events.splice(t,1)}},{key:"fireEvent",value:function(e,t){this.events.forEach((function(a){if(a.type==e)try{a.func(t)}catch(e){console.log(e)}}))}},{key:"setOnSongEndListener",value:function(e){this.onSongEndListener=e}},{key:"onSongEnd",value:function(){if(this.onSongEndListener&&this.onSongEndListener())return;this.settings.loop&&(this.initStatus(!0),this.settings.isCC111&&-1!=this.cc111Time&&this.setStartTime(this.cc111Time),this.play(!0))}},{key:"gethannels",value:function(){return this.channels}},{key:"setChannels",value:function(e){var t=this;e.forEach((function(e,a){t.channels[a]=e}))}},{key:"initChannels",value:function(){for(var e=0;e<16;e++)this.channels[e]=[0,0,1]}},{key:"getMasterVolume",value:function(){return this.settings.masterVolume}},{key:"setMasterVolume",value:function(e){this.settings.masterVolume=e,this.isStarted&&(this.masterGainNode.gain.value=this.settings.masterVolume)}},{key:"isLoop",value:function(){return this.settings.loop}},{key:"setLoop",value:function(e){this.settings.loop=e}},{key:"isWebMIDI",value:function(){return this.settings.isWebMIDI}},{key:"setWebMIDI",value:function(e){this.settings.isWebMIDI=e}},{key:"isCC111",value:function(){return this.settings.isCC111}},{key:"setCC111",value:function(e){this.settings.isCC111=e}},{key:"isReverb",value:function(){return this.settings.isReverb}},{key:"setReverb",value:function(e){this.settings.isReverb=e}},{key:"getReverbVolume",value:function(){return this.settings.reverbVolume}},{key:"setReverbVolume",value:function(e){this.settings.reverbVolume=e}},{key:"isChorus",value:function(){return this.settings.isChorus}},{key:"setChorus",value:function(e){this.settings.isChorus=e}},{key:"getChorusVolume",value:function(){return this.settings.chorusVolume}},{key:"setChorusVolume",value:function(e){this.settings.chorusVolume=e}}]),e}()}(); diff --git a/dist/nodejs/pico-audio.js b/dist/nodejs/pico-audio.js index 1981d61..fa20e02 100644 --- a/dist/nodejs/pico-audio.js +++ b/dist/nodejs/pico-audio.js @@ -903,6 +903,7 @@ function stop(isSongLooping) { // 停止をコールバックに通知 // this.trigger.stop(); + this.fireEvent('pause'); this.fireEvent('stop'); } @@ -3123,7 +3124,7 @@ function startWebMIDI() { class PicoAudio { /** * PicoAudioクラスのコンストラクタ - * @param {Object} argsObj + * @param {Object} argsObj */ constructor(argsObj) { picoAudioConstructor.call(this, argsObj); @@ -3131,12 +3132,12 @@ class PicoAudio { /** * 初期化・準備 - * @param {Object} argsObj + * @param {Object} argsObj */ init(argsObj) { return init.call(this, argsObj); } - + /** * MIDIファイル(SMF)を解析する * @param {Uint8Array} smf MIDIファイルの内容が入ったUint8Arrayオブジェクト @@ -3162,6 +3163,14 @@ class PicoAudio { return play.call(this, _isSongLooping); } + /** + * 一時停止 + * @param {boolean} _isSongLooping PicoAudio内部で使う引数 + */ + pause(_isSongLooping) { + return stop.call(this, _isSongLooping); + } + /** * 停止 * @param {boolean} _isSongLooping PicoAudio内部で使う引数 @@ -3204,11 +3213,11 @@ class PicoAudio { // 再生・音源関係 // /** * 再生処理(Web Audio API の oscillator等で音を鳴らす) - * @param {Object} option - * @param {boolean} isDrum - * @param {boolean} isExpression - * @param {boolean} nonChannel - * @param {boolean} nonStop + * @param {Object} option + * @param {boolean} isDrum + * @param {boolean} isExpression + * @param {boolean} nonChannel + * @param {boolean} nonStop * @returns {Object} AudioNodeやパラメータを返す */ createBaseNote(option, isDrum, isExpression, nonChannel, nonStop) { @@ -3216,7 +3225,7 @@ class PicoAudio { } /** * 音源(パーカッション以外) - * @param {Object} option + * @param {Object} option * @returns {Object} 音をストップさせる関数を返す */ createNote(option) { @@ -3224,7 +3233,7 @@ class PicoAudio { } /** * パーカッション音源 - * @param {Object} option + * @param {Object} option * @returns {Object} 音をストップさせる関数を返す */ createPercussionNote(option) { @@ -3311,13 +3320,13 @@ class PicoAudio { if (this.isStarted) { this.masterGainNode.gain.value = this.settings.masterVolume; } - } + } isLoop() { return this.settings.loop; } setLoop(loop) { this.settings.loop = loop; } isWebMIDI() { return this.settings.isWebMIDI; } setWebMIDI(enable) { this.settings.isWebMIDI = enable; } isCC111() { return this.settings.isCC111; } - setCC111(enable) { this.settings.isCC111 = enable; } + setCC111(enable) { this.settings.isCC111 = enable; } isReverb() { return this.settings.isReverb; } setReverb(enable) { this.settings.isReverb = enable; } getReverbVolume() { return this.settings.reverbVolume; } diff --git a/dist/nodejs/pico-audio.mjs b/dist/nodejs/pico-audio.mjs index a06e266..09b2d55 100644 --- a/dist/nodejs/pico-audio.mjs +++ b/dist/nodejs/pico-audio.mjs @@ -901,6 +901,7 @@ function stop(isSongLooping) { // 停止をコールバックに通知 // this.trigger.stop(); + this.fireEvent('pause'); this.fireEvent('stop'); } @@ -3121,7 +3122,7 @@ function startWebMIDI() { class PicoAudio { /** * PicoAudioクラスのコンストラクタ - * @param {Object} argsObj + * @param {Object} argsObj */ constructor(argsObj) { picoAudioConstructor.call(this, argsObj); @@ -3129,12 +3130,12 @@ class PicoAudio { /** * 初期化・準備 - * @param {Object} argsObj + * @param {Object} argsObj */ init(argsObj) { return init.call(this, argsObj); } - + /** * MIDIファイル(SMF)を解析する * @param {Uint8Array} smf MIDIファイルの内容が入ったUint8Arrayオブジェクト @@ -3160,6 +3161,14 @@ class PicoAudio { return play.call(this, _isSongLooping); } + /** + * 一時停止 + * @param {boolean} _isSongLooping PicoAudio内部で使う引数 + */ + pause(_isSongLooping) { + return stop.call(this, _isSongLooping); + } + /** * 停止 * @param {boolean} _isSongLooping PicoAudio内部で使う引数 @@ -3202,11 +3211,11 @@ class PicoAudio { // 再生・音源関係 // /** * 再生処理(Web Audio API の oscillator等で音を鳴らす) - * @param {Object} option - * @param {boolean} isDrum - * @param {boolean} isExpression - * @param {boolean} nonChannel - * @param {boolean} nonStop + * @param {Object} option + * @param {boolean} isDrum + * @param {boolean} isExpression + * @param {boolean} nonChannel + * @param {boolean} nonStop * @returns {Object} AudioNodeやパラメータを返す */ createBaseNote(option, isDrum, isExpression, nonChannel, nonStop) { @@ -3214,7 +3223,7 @@ class PicoAudio { } /** * 音源(パーカッション以外) - * @param {Object} option + * @param {Object} option * @returns {Object} 音をストップさせる関数を返す */ createNote(option) { @@ -3222,7 +3231,7 @@ class PicoAudio { } /** * パーカッション音源 - * @param {Object} option + * @param {Object} option * @returns {Object} 音をストップさせる関数を返す */ createPercussionNote(option) { @@ -3309,13 +3318,13 @@ class PicoAudio { if (this.isStarted) { this.masterGainNode.gain.value = this.settings.masterVolume; } - } + } isLoop() { return this.settings.loop; } setLoop(loop) { this.settings.loop = loop; } isWebMIDI() { return this.settings.isWebMIDI; } setWebMIDI(enable) { this.settings.isWebMIDI = enable; } isCC111() { return this.settings.isCC111; } - setCC111(enable) { this.settings.isCC111 = enable; } + setCC111(enable) { this.settings.isCC111 = enable; } isReverb() { return this.settings.isReverb; } setReverb(enable) { this.settings.isReverb = enable; } getReverbVolume() { return this.settings.reverbVolume; } diff --git a/sample/sample1.html b/sample/sample1.html index bbf9282..fc449bf 100644 --- a/sample/sample1.html +++ b/sample/sample1.html @@ -32,7 +32,7 @@

操作

楽曲再生
楽曲停止
-
+
音量調整
@@ -68,10 +68,10 @@

ログ

}); // 停止 - const stopButtonElem = document.getElementById('stop-button'); - stopButtonElem.addEventListener('click', () => { + const pauseButtonElem = document.getElementById('pause-button'); + pauseButtonElem.addEventListener('click', () => { picoAudio.init(); - picoAudio.stop(); + picoAudio.pause(); }); const volumeRangeElem = document.getElementById('volume-range'); @@ -86,8 +86,8 @@

ログ

}); // イベント - 再生停止 - picoAudio.addEventListener('stop', () => { - pushLog('stop', '#008'); + picoAudio.addEventListener('pause', () => { + pushLog('pause', '#008'); }); // イベント - 楽曲終了 diff --git a/sample/sample2.html b/sample/sample2.html index b982f52..d75e452 100644 --- a/sample/sample2.html +++ b/sample/sample2.html @@ -32,7 +32,7 @@ }); document.getElementById('pause').addEventListener("click", function() { - pAudio.stop(); + pAudio.pause(); }); document.getElementById('stop').addEventListener("click", function() { diff --git a/src/main.js b/src/main.js index 06e211d..d4818ae 100644 --- a/src/main.js +++ b/src/main.js @@ -24,7 +24,7 @@ import startWebMIDI from './web-midi/start-web-midi.js'; class PicoAudio { /** * PicoAudioクラスのコンストラクタ - * @param {Object} argsObj + * @param {Object} argsObj */ constructor(argsObj) { picoAudioConstructor.call(this, argsObj); @@ -32,12 +32,12 @@ class PicoAudio { /** * 初期化・準備 - * @param {Object} argsObj + * @param {Object} argsObj */ init(argsObj) { return init.call(this, argsObj); } - + /** * MIDIファイル(SMF)を解析する * @param {Uint8Array} smf MIDIファイルの内容が入ったUint8Arrayオブジェクト @@ -63,6 +63,14 @@ class PicoAudio { return play.call(this, _isSongLooping); } + /** + * 一時停止 + * @param {boolean} _isSongLooping PicoAudio内部で使う引数 + */ + pause(_isSongLooping) { + return stop.call(this, _isSongLooping); + } + /** * 停止 * @param {boolean} _isSongLooping PicoAudio内部で使う引数 @@ -105,11 +113,11 @@ class PicoAudio { // 再生・音源関係 // /** * 再生処理(Web Audio API の oscillator等で音を鳴らす) - * @param {Object} option - * @param {boolean} isDrum - * @param {boolean} isExpression - * @param {boolean} nonChannel - * @param {boolean} nonStop + * @param {Object} option + * @param {boolean} isDrum + * @param {boolean} isExpression + * @param {boolean} nonChannel + * @param {boolean} nonStop * @returns {Object} AudioNodeやパラメータを返す */ createBaseNote(option, isDrum, isExpression, nonChannel, nonStop) { @@ -117,7 +125,7 @@ class PicoAudio { } /** * 音源(パーカッション以外) - * @param {Object} option + * @param {Object} option * @returns {Object} 音をストップさせる関数を返す */ createNote(option) { @@ -125,7 +133,7 @@ class PicoAudio { } /** * パーカッション音源 - * @param {Object} option + * @param {Object} option * @returns {Object} 音をストップさせる関数を返す */ createPercussionNote(option) { @@ -212,13 +220,13 @@ class PicoAudio { if (this.isStarted) { this.masterGainNode.gain.value = this.settings.masterVolume; } - } + } isLoop() { return this.settings.loop; } setLoop(loop) { this.settings.loop = loop; } isWebMIDI() { return this.settings.isWebMIDI; } setWebMIDI(enable) { this.settings.isWebMIDI = enable; } isCC111() { return this.settings.isCC111; } - setCC111(enable) { this.settings.isCC111 = enable; } + setCC111(enable) { this.settings.isCC111 = enable; } isReverb() { return this.settings.isReverb; } setReverb(enable) { this.settings.isReverb = enable; } getReverbVolume() { return this.settings.reverbVolume; } diff --git a/src/player/stop.js b/src/player/stop.js index 96d0722..4811dfa 100644 --- a/src/player/stop.js +++ b/src/player/stop.js @@ -33,5 +33,6 @@ export default function stop(isSongLooping) { // 停止をコールバックに通知 // this.trigger.stop(); + this.fireEvent('pause'); this.fireEvent('stop'); } \ No newline at end of file