Skip to content

Commit

Permalink
added mass sound, see #166
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Jul 9, 2019
1 parent 311a217 commit 35b61fc
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
20 changes: 20 additions & 0 deletions js/gravity-force-lab-basics/view/GFLBScreenView.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 Bounds2 = require( 'DOT/Bounds2' );
const CheckboxSoundGenerator = require( 'TAMBO/sound-generators/CheckboxSoundGenerator' );
const Color = require( 'SCENERY/util/Color' );
const ControlAreaNode = require( 'SCENERY_PHET/accessibility/nodes/ControlAreaNode' );
const DefaultDirection = require( 'INVERSE_SQUARE_LAW_COMMON/view/DefaultDirection' );
Expand All @@ -35,6 +36,7 @@ define( require => {
const ISLCGridNode = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCGridNode' );
const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' );
const ISLCQueryParameters = require( 'INVERSE_SQUARE_LAW_COMMON/ISLCQueryParameters' );
const MassSoundGenerator = require( 'GRAVITY_FORCE_LAB_BASICS/gravity-force-lab-basics/view/MassSoundGenerator' );
const ModelViewTransform2 = require( 'PHETCOMMON/view/ModelViewTransform2' );
const Node = require( 'SCENERY/nodes/Node' );
const PlayAreaNode = require( 'SCENERY_PHET/accessibility/nodes/PlayAreaNode' );
Expand Down Expand Up @@ -209,6 +211,16 @@ define( require => {
massControlsHelpTextBillionsString;
} );

// sound generation for the mass values
soundManager.addSoundGenerator( new MassSoundGenerator(
model.object1.valueProperty,
model.resetInProgressProperty )
);
soundManager.addSoundGenerator( new MassSoundGenerator(
model.object2.valueProperty,
model.resetInProgressProperty )
);

const checkboxItems = [
{
label: forceValuesString, property: model.showForceValuesProperty,
Expand Down Expand Up @@ -240,6 +252,14 @@ define( require => {
fill: '#f1f1f2'
} );

// sound generation for check box items
checkboxItems.forEach( checkboxItem => {
soundManager.addSoundGenerator( new CheckboxSoundGenerator(
checkboxItem.property,
model.resetInProgressProperty
) );
} );

// arrow that shows distance between the two masses
const distanceArrowNode = new DistanceArrowNode( model, modelViewTransform, {
tandem: tandem.createTandem( 'distanceArrowNode' ),
Expand Down
66 changes: 66 additions & 0 deletions js/gravity-force-lab-basics/view/MassSoundGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2019, University of Colorado Boulder

/**
* sound generator for mass changes
*
* @author John Blanco (PhET Interactive Simulations)
*/
define( require => {
'use strict';

// modules
const SoundClip = require( 'TAMBO/sound-generators/SoundClip' );
const gravityForceLabBasics = require( 'GRAVITY_FORCE_LAB_BASICS/gravityForceLabBasics' );
const GFLBConstants = require( 'GRAVITY_FORCE_LAB_BASICS/gravity-force-lab-basics/GFLBConstants' );

// sounds
const massSound = require( 'sound!GRAVITY_FORCE_LAB_BASICS/rubber-band-v2-middle-c.mp3' );

// constants
const PITCH_RANGE_IN_SEMI_TONES = 30;

class MassSoundGenerator extends SoundClip {

/**
* @param {NumberProperty} massProperty
* @param {BooleanProperty} resetInProgressProperty
* @param {Object} [options]
* @constructor
*/
constructor( massProperty, resetInProgressProperty, options ) {

super( massSound, options );

// function for playing the mass sound
const massListener = mass => {
if ( !resetInProgressProperty.value ) {

// convert the mass to a playback rate, see the design document for an explanation
const massRange = GFLBConstants.MASS_RANGE;
const normalizedMass = ( mass - massRange.min ) / ( massRange.max - massRange.min );
const centerAndFlippedNormMass = ( ( 1 - normalizedMass ) - 0.5 );
const midiNote = PITCH_RANGE_IN_SEMI_TONES / 2 * centerAndFlippedNormMass;
const playbackSpeed = Math.pow( 2, midiNote / 12 );
this.setPlaybackRate( playbackSpeed );
this.play();
}
};
massProperty.link( massListener );

// @private {function}
this.disposeMassSoundGenerator = () => { massProperty.unlink( massListener ); };
}

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

gravityForceLabBasics.register( 'MassSoundGenerator', MassSoundGenerator );

return MassSoundGenerator;
} );
10 changes: 10 additions & 0 deletions sounds/license.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"rubber-band-v2-middle-c.mp3": {
"text": [
"Copyright 2002-2019 University of Colorado Boulder"
],
"projectURL": "http://phet.colorado.edu",
"license": "contact [email protected]",
"notes": "created by Ashton Morris (PhET Interactive Simulations)"
}
}
Binary file added sounds/rubber-band-v2-middle-c.mp3
Binary file not shown.

0 comments on commit 35b61fc

Please sign in to comment.