mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2025-01-03 11:35:49 -05:00
set, change, and report volume
This commit is contained in:
parent
a6bb22b90a
commit
4cefe6d2ad
1 changed files with 5 additions and 6 deletions
11
src/index.js
11
src/index.js
|
@ -71,6 +71,8 @@ function AudioPlayer (audioEngine) {
|
|||
// default is 60bpm
|
||||
|
||||
this.currentTempo = 60;
|
||||
|
||||
this.currentVolume = 100;
|
||||
}
|
||||
|
||||
AudioPlayer.prototype.loadSounds = function (sounds) {
|
||||
|
@ -222,15 +224,12 @@ AudioPlayer.prototype.setInstrument = function (instrumentNum) {
|
|||
};
|
||||
|
||||
AudioPlayer.prototype.setVolume = function (value) {
|
||||
var vol = this._clamp(value, 0, 100);
|
||||
vol /= 100;
|
||||
this.effectsNode.gain.value = vol;
|
||||
this.currentVolume = this._clamp(value, 0, 100);
|
||||
this.effectsNode.gain.value = this.currentVolume / 100;
|
||||
};
|
||||
|
||||
AudioPlayer.prototype.changeVolume = function (value) {
|
||||
value /= 100;
|
||||
var newVol = this.effectsNode.gain.value + value;
|
||||
this.effectsNode.gain.value = this._clamp(newVol, 0, 1);
|
||||
this.setVolume(this.currentVolume + value);
|
||||
};
|
||||
|
||||
AudioPlayer.prototype.setTempo = function (value) {
|
||||
|
|
Loading…
Reference in a new issue