From 296c77c889b864b652cddfea4934c3760c28b478 Mon Sep 17 00:00:00 2001 From: matthew-blackman Date: Tue, 30 Apr 2024 10:34:25 -0400 Subject: [PATCH] Disable histogram sound button, stop sonification when audio disabled - see https://github.com/phetsims/projectile-data-lab/issues/319 --- js/common/model/HistogramSonifier.ts | 16 ++++++++++++++-- js/common/view/HistogramNode.ts | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/js/common/model/HistogramSonifier.ts b/js/common/model/HistogramSonifier.ts index 6bef3836..ff014aed 100644 --- a/js/common/model/HistogramSonifier.ts +++ b/js/common/model/HistogramSonifier.ts @@ -15,6 +15,7 @@ import Utils from '../../../../dot/js/Utils.js'; import histogramTone_mp3 from '../../../sounds/histogramTone_mp3.js'; import Property from '../../../../axon/js/Property.js'; import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js'; +import audioManager from '../../../../joist/js/audioManager.js'; const binSoundClip = new SoundClip( histogramTone_mp3, { initialOutputLevel: 0.7 } ); soundManager.addSoundGenerator( binSoundClip ); @@ -68,6 +69,13 @@ export default class HistogramSonifier { binSoundClip.play(); } } ); + + // If the audio is disabled, stop the histogram sonification + audioManager.audioEnabledProperty.lazyLink( audioEnabled => { + if ( !audioEnabled ) { + this.stopSonification(); + } + } ); } // Set the histogram data, which is used to determine the sonification @@ -97,7 +105,7 @@ export default class HistogramSonifier { // If the data changes, stop playing the sound if ( cancelSonification ) { - this.histogramSonifierPhaseProperty.value = { phaseName: 'idlePhase' }; + this.stopSonification(); } } @@ -106,10 +114,14 @@ export default class HistogramSonifier { this.startHistogramSoundSequence(); } else { - this.histogramSonifierPhaseProperty.value = { phaseName: 'idlePhase' }; + this.stopSonification(); } } + private stopSonification(): void { + this.histogramSonifierPhaseProperty.value = { phaseName: 'idlePhase' }; + } + // Initiate the sequence of sounds for the histogram bins private startHistogramSoundSequence(): void { diff --git a/js/common/view/HistogramNode.ts b/js/common/view/HistogramNode.ts index 2ac28d32..0b93434e 100644 --- a/js/common/view/HistogramNode.ts +++ b/js/common/view/HistogramNode.ts @@ -47,6 +47,7 @@ import stopSolidShape from '../../../../sherpa/js/fontawesome-5/stopSolidShape.j import DerivedProperty from '../../../../axon/js/DerivedProperty.js'; import RectangularPushButton from '../../../../sun/js/buttons/RectangularPushButton.js'; import packageJSON from '../../../../joist/js/packageJSON.js'; +import audioManager from '../../../../joist/js/audioManager.js'; type SelfOptions = EmptySelfOptions; export type HistogramNodeOptions = SelfOptions & WithRequired; @@ -351,7 +352,7 @@ export default class HistogramNode extends Node { const toggleHistogramSoundButton = new RectangularPushButton( { content: histogramSoundIconToggleNode, soundPlayer: nullSoundPlayer, - enabledProperty: histogramSoundEnabledProperty, + enabledProperty: DerivedProperty.and( [ histogramSoundEnabledProperty, audioManager.audioEnabledProperty ] ), size: new Dimension2( 34, 34 ), xMargin: 5, yMargin: 5,