Skip to content

Commit

Permalink
Merge pull request #31 from cagpie/fix/stop-to-pause
Browse files Browse the repository at this point in the history
pauseを採用してstopをなるべく使わないようにする
  • Loading branch information
cagpie authored Aug 24, 2020
2 parents d0bd84b + 2fbe407 commit e002de1
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 61 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ picoAudio.play();

### 停止
```javascript
// 停止
picoAudio.stop();
// 一時停止
picoAudio.pause();
```


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -209,7 +209,7 @@ PicoAudio.addEventListener(
```typescript
// 指定のイベントリスナを解除
PicoAudio.removeEventListener(
type: <'play' | 'stop' | 'noteOn' | 'noteOff' | 'songEnd'>,
type: <'play' | 'pause' | 'noteOn' | 'noteOff' | 'songEnd'>,
listener: Function
): void
```
Expand All @@ -218,7 +218,7 @@ PicoAudio.removeEventListener(
```typescript
// 指定typeのイベントリスナをすべて解除
PicoAudio.removeAllEventListener(
type: <'play' | 'stop' | 'noteOn' | 'noteOff' | 'songEnd'>
type: <'play' | 'pause' | 'noteOn' | 'noteOff' | 'songEnd'>
): void
```
Expand Down
29 changes: 20 additions & 9 deletions dist/browser/PicoAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ var PicoAudio = (function () {


this.trigger.stop();
this.fireEvent('pause');
this.fireEvent('stop');
}

Expand Down Expand Up @@ -3836,7 +3837,7 @@ var PicoAudio = (function () {
var PicoAudio = /*#__PURE__*/function () {
/**
* PicoAudioクラスのコンストラクタ
* @param {Object} argsObj
* @param {Object} argsObj
*/
function PicoAudio(argsObj) {
_classCallCheck(this, PicoAudio);
Expand All @@ -3845,7 +3846,7 @@ var PicoAudio = (function () {
}
/**
* 初期化・準備
* @param {Object} argsObj
* @param {Object} argsObj
*/


Expand Down Expand Up @@ -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内部で使う引数
Expand Down Expand Up @@ -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やパラメータを返す
*/

Expand All @@ -3952,7 +3963,7 @@ var PicoAudio = (function () {
}
/**
* 音源(パーカッション以外)
* @param {Object} option
* @param {Object} option
* @returns {Object} 音をストップさせる関数を返す
*/

Expand All @@ -3963,7 +3974,7 @@ var PicoAudio = (function () {
}
/**
* パーカッション音源
* @param {Object} option
* @param {Object} option
* @returns {Object} 音をストップさせる関数を返す
*/

Expand Down
2 changes: 1 addition & 1 deletion dist/browser/PicoAudio.min.js

Large diffs are not rendered by default.

33 changes: 21 additions & 12 deletions dist/nodejs/pico-audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ function stop(isSongLooping) {

// 停止をコールバックに通知 //
this.trigger.stop();
this.fireEvent('pause');
this.fireEvent('stop');
}

Expand Down Expand Up @@ -3123,20 +3124,20 @@ function startWebMIDI() {
class PicoAudio {
/**
* PicoAudioクラスのコンストラクタ
* @param {Object} argsObj
* @param {Object} argsObj
*/
constructor(argsObj) {
picoAudioConstructor.call(this, argsObj);
}

/**
* 初期化・準備
* @param {Object} argsObj
* @param {Object} argsObj
*/
init(argsObj) {
return init.call(this, argsObj);
}

/**
* MIDIファイル(SMF)を解析する
* @param {Uint8Array} smf MIDIファイルの内容が入ったUint8Arrayオブジェクト
Expand All @@ -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内部で使う引数
Expand Down Expand Up @@ -3204,27 +3213,27 @@ 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) {
return createBaseNote.call(this, option, isDrum, isExpression, nonChannel, nonStop);
}
/**
* 音源(パーカッション以外)
* @param {Object} option
* @param {Object} option
* @returns {Object} 音をストップさせる関数を返す
*/
createNote(option) {
return createNote.call(this, option);
}
/**
* パーカッション音源
* @param {Object} option
* @param {Object} option
* @returns {Object} 音をストップさせる関数を返す
*/
createPercussionNote(option) {
Expand Down Expand Up @@ -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; }
Expand Down
33 changes: 21 additions & 12 deletions dist/nodejs/pico-audio.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ function stop(isSongLooping) {

// 停止をコールバックに通知 //
this.trigger.stop();
this.fireEvent('pause');
this.fireEvent('stop');
}

Expand Down Expand Up @@ -3121,20 +3122,20 @@ function startWebMIDI() {
class PicoAudio {
/**
* PicoAudioクラスのコンストラクタ
* @param {Object} argsObj
* @param {Object} argsObj
*/
constructor(argsObj) {
picoAudioConstructor.call(this, argsObj);
}

/**
* 初期化・準備
* @param {Object} argsObj
* @param {Object} argsObj
*/
init(argsObj) {
return init.call(this, argsObj);
}

/**
* MIDIファイル(SMF)を解析する
* @param {Uint8Array} smf MIDIファイルの内容が入ったUint8Arrayオブジェクト
Expand All @@ -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内部で使う引数
Expand Down Expand Up @@ -3202,27 +3211,27 @@ 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) {
return createBaseNote.call(this, option, isDrum, isExpression, nonChannel, nonStop);
}
/**
* 音源(パーカッション以外)
* @param {Object} option
* @param {Object} option
* @returns {Object} 音をストップさせる関数を返す
*/
createNote(option) {
return createNote.call(this, option);
}
/**
* パーカッション音源
* @param {Object} option
* @param {Object} option
* @returns {Object} 音をストップさせる関数を返す
*/
createPercussionNote(option) {
Expand Down Expand Up @@ -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; }
Expand Down
12 changes: 6 additions & 6 deletions sample/sample1.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h2>操作</h2>
<dt>楽曲再生</dt>
<dd><button id="play-button">Play</button></dd>
<dt>楽曲停止</dt>
<dd><button id="stop-button">Stop</button></dd>
<dd><button id="pause-button">Pause</button></dd>
<dt>音量調整</dt>
<dd><input type="range" id="volume-range" min="0" max="1" step="0.1"></dd>
</dl>
Expand Down Expand Up @@ -68,10 +68,10 @@ <h2>ログ</h2>
});

// 停止
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');
Expand All @@ -86,8 +86,8 @@ <h2>ログ</h2>
});

// イベント - 再生停止
picoAudio.addEventListener('stop', () => {
pushLog('stop', '#008');
picoAudio.addEventListener('pause', () => {
pushLog('pause', '#008');
});

// イベント - 楽曲終了
Expand Down
2 changes: 1 addition & 1 deletion sample/sample2.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
});

document.getElementById('pause').addEventListener("click", function() {
pAudio.stop();
pAudio.pause();
});

document.getElementById('stop').addEventListener("click", function() {
Expand Down
Loading

0 comments on commit e002de1

Please sign in to comment.