diff --git a/js/common/view/BothHandsPDOMNode.js b/js/common/view/BothHandsPDOMNode.js index 8f9ad6c5..d2087802 100644 --- a/js/common/view/BothHandsPDOMNode.js +++ b/js/common/view/BothHandsPDOMNode.js @@ -18,6 +18,7 @@ import Utterance from '../../../../utterance-queue/js/Utterance.js'; import ratioAndProportion from '../../ratioAndProportion.js'; import ratioAndProportionStrings from '../../ratioAndProportionStrings.js'; import BothHandsInteractionListener from './BothHandsInteractionListener.js'; +import ViewSounds from './sound/ViewSounds.js'; class BothHandsPDOMNode extends Node { @@ -31,7 +32,7 @@ class BothHandsPDOMNode extends Node { * @param {Property.} unclampedFitnessProperty * @param {RatioDescriber} ratioDescriber * @param {BothHandsDescriber} bothHandsDescriber - * @param {ViewSounds} viewSounds + * @param {BooleanProperty} playTickMarkBumpSoundProperty * @param {BooleanProperty} ratioLockedProperty * @param {Property.} targetRatioProperty * @param {function(RatioTerm):number} getIdealTerm @@ -46,7 +47,7 @@ class BothHandsPDOMNode extends Node { unclampedFitnessProperty, ratioDescriber, bothHandsDescriber, - viewSounds, + playTickMarkBumpSoundProperty, ratioLockedProperty, targetRatioProperty, getIdealTerm, @@ -81,6 +82,8 @@ class BothHandsPDOMNode extends Node { this.consequentInteractedWithProperty = new BooleanProperty( false ); this.bothHandsFocusedProperty = new BooleanProperty( false ); + this.viewSounds = new ViewSounds( tickMarkRangeProperty, tickMarkViewProperty, playTickMarkBumpSoundProperty ); + Property.multilink( [ this.antecedentInteractedWithProperty, this.consequentInteractedWithProperty @@ -115,7 +118,7 @@ class BothHandsPDOMNode extends Node { // @private this.bothHandsInteractionListener = new BothHandsInteractionListener( interactiveNode, ratioTupleProperty, this.antecedentInteractedWithProperty, this.consequentInteractedWithProperty, enabledRatioTermsRangeProperty, tickMarkRangeProperty, keyboardStep, - viewSounds.boundarySoundClip, viewSounds.tickMarkBumpSoundClip, ratioLockedProperty, targetRatioProperty, getIdealTerm, { + this.viewSounds.boundarySoundClip, this.viewSounds.tickMarkBumpSoundClip, ratioLockedProperty, targetRatioProperty, getIdealTerm, { onInput: () => { this.alertBothHandsContextResponse(); } @@ -125,11 +128,11 @@ class BothHandsPDOMNode extends Node { interactiveNode.addInputListener( { focus: () => { this.alertBothHandsObjectResponse( tickMarkViewProperty.value ); - viewSounds.grabSoundClip.play(); + this.viewSounds.grabSoundClip.play(); this.bothHandsFocusedProperty.value = true; }, blur: () => { - viewSounds.releaseSoundClip.play(); + this.viewSounds.releaseSoundClip.play(); this.bothHandsFocusedProperty.value = false; // This only works because the bothHandsInteractionListener needs alt-input control resetting @@ -187,6 +190,7 @@ class BothHandsPDOMNode extends Node { this.bothHandsInteractionListener.reset(); this.objectResponseUtterance.reset(); this.contextResponseUtterance.reset(); + this.viewSounds.reset(); } /** diff --git a/js/common/view/RAPScreenView.js b/js/common/view/RAPScreenView.js index f7c26beb..bb484d6b 100644 --- a/js/common/view/RAPScreenView.js +++ b/js/common/view/RAPScreenView.js @@ -37,7 +37,6 @@ import RatioHalf from './RatioHalf.js'; import InProportionSoundGenerator from './sound/InProportionSoundGenerator.js'; import MovingInProportionSoundGenerator from './sound/MovingInProportionSoundGenerator.js'; import StaccatoFrequencySoundGenerator from './sound/StaccatoFrequencySoundGenerator.js'; -import ViewSounds from './sound/ViewSounds.js'; import TickMarkView from './TickMarkView.js'; import TickMarkViewRadioButtonGroup from './TickMarkViewRadioButtonGroup.js'; @@ -124,10 +123,6 @@ class RAPScreenView extends ScreenView { const playTickMarkBumpSoundProperty = new DerivedProperty( [ model.ratioFitnessProperty ], fitness => !model.ratio.lockedProperty.value && fitness === model.fitnessRange.min ); - // @private - this.viewSounds = new ViewSounds( this.tickMarkRangeProperty, - this.tickMarkViewProperty, playTickMarkBumpSoundProperty ); - // by default, the keyboard step size should be half of one default tick mark width. See https://github.com/phetsims/ratio-and-proportion/issues/85 const keyboardStep = 1 / 2 / this.tickMarkRangeProperty.value; @@ -152,7 +147,7 @@ class RAPScreenView extends ScreenView { keyboardStep, model.ratio.lockedProperty, model.ratio.lockedProperty, // not a bug - this.viewSounds, + playTickMarkBumpSoundProperty, this.inProportionSoundGenerator, () => model.getIdealValueForTerm( RatioTerm.ANTECEDENT ), { handColorProperty: options.leftHandColorProperty, @@ -183,7 +178,7 @@ class RAPScreenView extends ScreenView { keyboardStep, model.ratio.lockedProperty, model.ratio.lockedProperty, // not a bug - this.viewSounds, + playTickMarkBumpSoundProperty, this.inProportionSoundGenerator, () => model.getIdealValueForTerm( RatioTerm.CONSEQUENT ), { handColorProperty: options.rightHandColorProperty, @@ -201,7 +196,7 @@ class RAPScreenView extends ScreenView { model.unclampedFitnessProperty, this.ratioDescriber, bothHandsDescriber, - this.viewSounds, + playTickMarkBumpSoundProperty, model.ratio.lockedProperty, model.targetRatioProperty, model.getIdealValueForTerm.bind( model ), merge( { @@ -395,7 +390,6 @@ class RAPScreenView extends ScreenView { this.staccatoFrequencySoundGenerator.reset(); this.inProportionSoundGenerator.reset(); this.movingInProportionSoundGenerator.reset(); - this.viewSounds.reset(); } /** diff --git a/js/common/view/RatioHalf.js b/js/common/view/RatioHalf.js index 0c6614f3..51a0531d 100644 --- a/js/common/view/RatioHalf.js +++ b/js/common/view/RatioHalf.js @@ -29,6 +29,7 @@ import RAPConstants from '../RAPConstants.js'; import CueDisplay from './CueDisplay.js'; import RatioHalfTickMarksNode from './RatioHalfTickMarksNode.js'; import RatioHandNode from './RatioHandNode.js'; +import ViewSounds from './sound/ViewSounds.js'; import TickMarkView from './TickMarkView.js'; // constants @@ -72,7 +73,7 @@ class RatioHalf extends Rectangle { * @param {number} keyboardStep * @param {BooleanProperty} horizontalMovementAllowedProperty * @param {BooleanProperty} ratioLockedProperty - * @param {ViewSounds} viewSounds + * @param {BooleanProperty} playTickMarkBumpSoundProperty * @param {InProportionSoundGenerator} inProportionSoundGenerator * @param {function():number} getIdealValue - a function that gets the value of this RatioHalf term that would achieve the targetRatio * @param {Object} [options] @@ -91,7 +92,7 @@ class RatioHalf extends Rectangle { keyboardStep, horizontalMovementAllowedProperty, ratioLockedProperty, - viewSounds, + playTickMarkBumpSoundProperty, inProportionSoundGenerator, getIdealValue, options ) { @@ -131,6 +132,8 @@ class RatioHalf extends Rectangle { this.tickMarkViewProperty = tickMarkViewProperty; this.valueProperty = valueProperty; + const viewSounds = new ViewSounds( tickMarkRangeProperty, tickMarkViewProperty, playTickMarkBumpSoundProperty ); + // This follows the spec outlined in https://github.com/phetsims/ratio-and-proportion/issues/81 const cueDisplayStateProperty = new DerivedProperty( [ cueArrowsState.interactedWithKeyboardProperty, @@ -352,6 +355,7 @@ class RatioHalf extends Rectangle { // @private this.resetRatioHalf = () => { this.ratioHandNode.reset(); + viewSounds.reset(); positionProperty.value.setX( INITIAL_X_VALUE ); positionProperty.notifyListenersStatic(); };