Skip to content

Commit

Permalink
Mute the sources while the separation is being changed, see #316
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jan 16, 2019
1 parent 1264d56 commit 95e7708
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
18 changes: 18 additions & 0 deletions js/common/model/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ define( require => {
// @public the frequency in the appropriate units for the scene
this.frequencyProperty = new NumberProperty( frequencyRange.getCenter(), { range: frequencyRange } );

// @private - point source wave generation is suppressed when changing the source separation
this.muted = false;

// @public distance between the sources in the units of the scene, or 0 if there is only one
// source initialized to match the initial slit separation,
// see https://github.com/phetsims/wave-interference/issues/87
Expand Down Expand Up @@ -401,6 +404,11 @@ define( require => {
* @private
*/
setPointSourceValues( amplitude, time ) {

if ( this.muted ) {
return;
}

const frequency = this.frequencyProperty.get();
const period = 1 / frequency;
const timeSincePulseStarted = time - this.pulseStartTime;
Expand Down Expand Up @@ -660,6 +668,7 @@ define( require => {
this.lattice.clear();
this.temporalMask1.clear();
this.temporalMask2.clear();
this.muted = false;
}

/**
Expand Down Expand Up @@ -692,6 +701,15 @@ define( require => {
return new Bounds2( 0, 0, this.waveAreaWidth, this.waveAreaWidth );
}

/**
* Mute or unmute the model.
* @param {boolean} muted
* @public
*/
setMuted( muted ) {
this.muted = muted;
}

/**
* The user has initiated a single pulse.
* @public
Expand Down
19 changes: 15 additions & 4 deletions js/interference/view/SeparationControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ define( require => {
const lightSceneRange = lightSeparationProperty.range;
const allRanges = [ waterSceneRange, soundSceneRange, lightSceneRange ];

const createMuteOptions = scene => {
return {
sliderStartCallback: () => scene.setMuted( true ),
sliderEndCallback: () => scene.setMuted( false ),
leftArrowStartCallback: () => scene.setMuted( true ),
leftArrowEndCallback: () => scene.setMuted( false ),
rightArrowStartCallback: () => scene.setMuted( true ),
rightArrowEndCallback: () => scene.setMuted( false )
};
};

// Switch between controls for each scene. No advantage in using SceneToggleNode in this case
// because the control constructor calls are substantially different.
super( model.sceneProperty, [ {
Expand All @@ -48,24 +59,24 @@ define( require => {
valuePattern: cmValueString,
decimalPlaces: 1,
constrainValue: value => Util.roundToInterval( value, 0.5 ),
majorTicks: createTicks( waterSceneRange, allRanges )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) )
majorTicks: createTicks( waterSceneRange, allRanges ),
}, createMuteOptions( model.waterScene ), WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) )
}, {
value: model.soundScene,
node: new NumberControl( separationString, soundSeparationProperty, soundSceneRange, _.extend( {
delta: 1,
valuePattern: cmValueString,
constrainValue: value => Util.roundToInterval( value, 10 ),
majorTicks: createTicks( soundSceneRange, allRanges )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) )
}, createMuteOptions( model.soundScene ), WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) )
}, {
value: model.lightScene,
node: new NumberControl( separationString, lightSeparationProperty, lightSceneRange, _.extend( {
delta: 10,
valuePattern: nmValueString,
constrainValue: value => Util.roundToInterval( value, 100 ),
majorTicks: createTicks( lightSceneRange, allRanges )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) )
}, createMuteOptions( model.lightScene ), WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) )
} ] );
}
}
Expand Down

0 comments on commit 95e7708

Please sign in to comment.