Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 5, 2019
2 parents 74f4db6 + 98a6ee5 commit 076aa5c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
64 changes: 64 additions & 0 deletions js/gravity-force-lab/view/BoundarySoundGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2019, University of Colorado Boulder

/**
* BoundarySoundGenerator generates the sounds that indicate when the masses have reached their inner and outer motion
* limits.
*
* @author John Blanco (PhET Interactive Simulations)
*/
define( require => {
'use strict';

// modules
const gravityForceLab = require( 'GRAVITY_FORCE_LAB/gravityForceLab' );
const SoundClip = require( 'TAMBO/sound-generators/SoundClip' );
const SoundGenerator = require( 'TAMBO/sound-generators/SoundGenerator' );

// sounds
const innerBoundarySoundInfo = require( 'sound!GRAVITY_FORCE_LAB/scrunched-mass-collision-sonic-womp.mp3' );
const outerBoundarySoundInfo = require( 'sound!TAMBO/boundary-reached.mp3' );

class BoundarySoundGenerator extends SoundGenerator {

/**
* @param {ISLCObject} movableObject
* @param {ISLCModel} model
* @param {Object} [options]
*/
constructor( movableObject, model, options ) {

super( options );

const innerBoundarySoundClip = new SoundClip( innerBoundarySoundInfo );
innerBoundarySoundClip.connect( this.masterGainNode );
const outerBoundarySoundClip = new SoundClip( outerBoundarySoundInfo );
outerBoundarySoundClip.connect( this.masterGainNode );

// function for starting the force sound or adjusting the volume
const positionListener = position => {
if ( position === model.getObjectMinPosition( movableObject ) ) {
innerBoundarySoundClip.play();
}
else if ( position === model.getObjectMaxPosition( movableObject ) ) {
outerBoundarySoundClip.play();
}
};
movableObject.positionProperty.link( positionListener );

// @private {function}
this.disposeBoundarySoundGenerator = () => { movableObject.positionProperty.unlink( positionListener ); };
}

/**
* @public
*/
dispose() {
this.disposeBoundarySoundGenerator();
super.dispose();
}
}

gravityForceLab.register( 'BoundarySoundGenerator', BoundarySoundGenerator );

return BoundarySoundGenerator;
} );
10 changes: 10 additions & 0 deletions js/gravity-force-lab/view/GravityForceLabScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define( require => {

// modules
const AccessiblePeer = require( 'SCENERY/accessibility/AccessiblePeer' );
const BoundarySoundGenerator = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/view/BoundarySoundGenerator' );
const Bounds2 = require( 'DOT/Bounds2' );
const DefaultDirection = require( 'INVERSE_SQUARE_LAW_COMMON/view/DefaultDirection' );
const ForceSoundGenerator = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/view/ForceSoundGenerator' );
Expand Down Expand Up @@ -70,6 +71,7 @@ define( require => {
const OBJECT_ONE = ISLCObjectEnum.OBJECT_ONE;
const OBJECT_TWO = ISLCObjectEnum.OBJECT_TWO;
const CHECKBOX_TEXT_SIZE = 15;
const BOUNDARY_SOUNDS_LEVEL = 1;

function GravityForceLabScreenView( model, tandem ) {

Expand Down Expand Up @@ -356,6 +358,14 @@ define( require => {
resetAllButton.buttonModel.isFiringProperty,
{ initialOutputLevel: 0.7, lockoutTime: 0.2 }
) );

// sound generation for masses reaching the inner or outer motion boundaries
soundManager.addSoundGenerator( new BoundarySoundGenerator( model.object1, model, {
initialOutputLevel: BOUNDARY_SOUNDS_LEVEL
} ) );
soundManager.addSoundGenerator( new BoundarySoundGenerator( model.object2, model, {
initialOutputLevel: BOUNDARY_SOUNDS_LEVEL
} ) );
}

gravityForceLab.register( 'GravityForceLabScreenView', GravityForceLabScreenView );
Expand Down

0 comments on commit 076aa5c

Please sign in to comment.