-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters