diff options
| author | Gubolin <gubolin@fantasymail.de> | 2014-08-03 12:41:23 +0200 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2014-08-03 12:41:23 +0200 |
| commit | b700eaa3f35b931445df06ba1ff952a709f82cc5 (patch) | |
| tree | 585c65e055fd1513af005a39df45a6f272746b68 | |
| parent | 51387ddfbc536c5ecc88658682f1894411f60631 (diff) | |
| download | snap-b700eaa3f35b931445df06ba1ff952a709f82cc5.tar.gz snap-b700eaa3f35b931445df06ba1ff952a709f82cc5.zip | |
add mute functions
| -rw-r--r-- | gui.js | 19 | ||||
| -rw-r--r-- | objects.js | 23 |
2 files changed, 38 insertions, 4 deletions
@@ -3407,10 +3407,21 @@ IDE_Morph.prototype.toggleMuteSounds = function (isMuted) { this.isMuted = isNil(isMuted) ? !this.isMuted : isMuted; this.controlBar.muteSoundsButton.refresh(); - this.sprites.asArray().forEach(function (sprt) { - sprt.refreshVolumeOfAllActiveSounds(); - }); - this.stage.refreshVolumeOfAllActiveSounds(); + /* stage.activeSounds holds all active sounds + * a sprite's .activeSounds holds just its own + * so you have to use the stage to mute + * and the sprite to unmute, because the stage's volume + * overrides the sprite's one. + */ + + if (this.isMuted === false) { + this.stage.unmuteAllSounds(); + this.sprites.asArray().forEach(function (sprt) { + sprt.unmuteAllSounds(); + }); + } else { + this.stage.muteAllSounds(); + } }; IDE_Morph.prototype.createNewProject = function () { @@ -2619,6 +2619,10 @@ SpriteMorph.prototype.playSound = function (name) { sound.volume = this.volume; active = sound.play(); + if (stage.muted === true) { + active.volume = 0; + } + this.activeSounds.push(active); this.activeSounds = this.activeSounds.filter(function (aud) { return !aud.ended && !aud.terminated; @@ -2651,6 +2655,13 @@ SpriteMorph.prototype.reportVolume = function () { return this.volume; } +SpriteMorph.prototype.unmuteAllSounds = function () { + var stage = this.parentThatIsA(StageMorph); + stage.muted = false; + + this.doSetVolume(this.volume); +}; + SpriteMorph.prototype.reportSounds = function () { return this.sounds; }; @@ -4293,6 +4304,7 @@ StageMorph.prototype.init = function (globals) { this.isFastTracked = false; this.cloneCount = 0; this.volume = 100; + this.muted = false; this.timerStart = Date.now(); this.tempo = 60; // bpm @@ -5507,6 +5519,17 @@ StageMorph.prototype.resumeAllActiveSounds = function () { }); }; +StageMorph.prototype.muteAllSounds = function () { + this.muted = true; + + this.activeSounds.forEach(function (audio) { + audio.volume = 0; + }); +}; + +StageMorph.prototype.unmuteAllSounds + = SpriteMorph.prototype.unmuteAllSounds; + StageMorph.prototype.reportSounds = SpriteMorph.prototype.reportSounds; |
