mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 14:02:29 -05:00
add stopall function for instruments and drums
This commit is contained in:
parent
193a9f181b
commit
703502cfbb
3 changed files with 19 additions and 10 deletions
|
@ -11,6 +11,10 @@ function DrumPlayer (outputNode) {
|
|||
|
||||
DrumPlayer.prototype.start = function () {
|
||||
this.snare.start();
|
||||
DrumPlayer.prototype.stopAll = function () {
|
||||
for (var i=0; i<this.drumSounds.length; i++) {
|
||||
this.drumSounds[i].stop();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = DrumPlayer;
|
||||
|
|
|
@ -36,4 +36,12 @@ InstrumentPlayer.prototype.loadInstrument = function (instrumentNum) {
|
|||
}
|
||||
};
|
||||
|
||||
InstrumentPlayer.prototype.stopAll = function () {
|
||||
for (var i=0; i<this.instruments.length; i++) {
|
||||
if (this.instruments[i]) {
|
||||
this.instruments[i].stop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = InstrumentPlayer;
|
||||
|
|
17
src/index.js
17
src/index.js
|
@ -141,20 +141,17 @@ AudioPlayer.prototype.beatsToSec = function (beats) {
|
|||
};
|
||||
|
||||
AudioPlayer.prototype.stopAllSounds = function () {
|
||||
// stop drum notes
|
||||
// for (var i = 0; i<this.drumSamplers.length; i++) {
|
||||
// this.drumSamplers[i].triggerRelease();
|
||||
// }
|
||||
|
||||
// stop sounds triggered with playSound
|
||||
// stop all sound players
|
||||
for (var i=0; i<this.soundPlayers.length; i++) {
|
||||
this.soundPlayers[i].stop();
|
||||
}
|
||||
|
||||
// stop soundfont notes
|
||||
// if (this.instrument) {
|
||||
// this.instrument.stop();
|
||||
// }
|
||||
// stop all instruments
|
||||
this.audioEngine.instrumentPlayer.stopAll();
|
||||
|
||||
// stop drum notes
|
||||
this.audioEngine.drumPlayer.stopAll();
|
||||
|
||||
};
|
||||
|
||||
AudioPlayer.prototype.setEffect = function (effect, value) {
|
||||
|
|
Loading…
Reference in a new issue