Skip to content

Commit

Permalink
added support for setting enhanced sound mode from the PhET menu, see #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Jul 10, 2018
1 parent 3c5a4c5 commit d19da38
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
12 changes: 6 additions & 6 deletions js/TamboQueryParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ define( function( require ) {
// use the stubbed audio context regardless of whether support exists for Web Audio
forceStubbedAudioContext: { type: 'flag' },

// control the initial sonification level (user can change later)
initialSonificationLevel: {
type: 'string',
defaultValue: 'basic'
},

// turn sound on or off at startup (user can change later)
soundInitiallyEnabled: {
type: 'boolean',
defaultValue: true
},

// control whether enhanced sound mode is initially enabled (user can change later)
enhancedSoundEnabled: {
type: 'boolean',
defaultValue: false
}

} );
Expand Down
6 changes: 3 additions & 3 deletions js/demo/controls/view/SonificationControlsScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ define( function( require ) {

// add an AB switch that will select between 'basic' and 'enhanced' sonification
var abSwitch = new ABSwitch(
soundManager.sonificationLevelProperty,
'basic',
soundManager.enhancedSoundEnabledProperty,
false,
new Text( 'basic' ),
'enhanced',
true,
new Text( 'enhanced' ),
{ switchSize: new Dimension2( 40, 20 ), left: 100, top: 200 }
);
Expand Down
33 changes: 20 additions & 13 deletions js/soundManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ define( function( require ) {
var DEFAULT_REVERB_LEVEL = 0.2;
var TC_FOR_PARAM_CHANGES = 0.015; // time constant for param changes, empirically determined to avoid clicks
var SOUND_INITIALLY_ENABLED = TamboQueryParameters.soundInitiallyEnabled;
var INITIAL_SONIFICATION_LEVEL = TamboQueryParameters.initialSonificationLevel;
var ENHANCED_SOUND_INITIALLY_ENABLED = TamboQueryParameters.enhancedSoundEnabled;

// flag that tracks whether sound generation of any kind is enabled
var enabledProperty = new BooleanProperty( SOUND_INITIALLY_ENABLED );

// the level setting, either 'basic' or 'enhanced'
var sonificationLevelProperty = new StringProperty( INITIAL_SONIFICATION_LEVEL );
// flag that tracks whether just basic or basic+enhanced sounds are enabled
var enhancedSoundEnabledProperty = new BooleanProperty( ENHANCED_SOUND_INITIALLY_ENABLED );

// next ID number value, used to assign a unique ID to each sound generator that is registered
var nextIdNumber = 1;
Expand Down Expand Up @@ -95,12 +95,6 @@ define( function( require ) {
// false when a reset is in progress
var noResetInProgressProperty = new BooleanProperty( true );

// @private {BooleanProperty} - a Property whose value is true when in enhance sonification mode, false when in basic
var enhancedLevelEnabled = new BooleanProperty( false );
sonificationLevelProperty.link( function( sonificationLevel ) {
enhancedLevelEnabled.set( sonificationLevel === 'enhanced' );
} );

// create the gain nodes for each of the defined "classes" and hook them up, will be defined during init
var gainNodesForClasses = {};

Expand Down Expand Up @@ -159,6 +153,8 @@ define( function( require ) {
*/
initialize: function( simVisibleProperty, options ) {

assert && assert( !initialized, 'can\'t initialize the sound manager more than once' );

options = _.extend( {

// Classes that can be used to group sound generators together and control their volume as a group - the names
Expand Down Expand Up @@ -195,6 +191,17 @@ define( function( require ) {
initialized = true;
},

/**
* get a value that indicates whether the sound manager has been initialized
* TODO: This was added when the global controls in joist were not yet on master, and was necessary to allow the
* demo sim to run, and may not be needed in the long term. Added 7/10/2018, if not in use a month or two after
* that, remove it.
* @return {boolean}
*/
isInitialized: function() {
return initialized;
},

/**
* register a sound generator, which connects it to the output, puts it on the list of sound generators, and
* creates and returns a unique ID
Expand Down Expand Up @@ -261,7 +268,7 @@ define( function( require ) {

// if this sound generator is only enabled in enhanced mode, add the enhanced mode property as an enable control
if ( options.sonificationLevel === 'enhanced' ) {
soundGenerator.addEnableControlProperty( enhancedLevelEnabled );
soundGenerator.addEnableControlProperty( enhancedSoundEnabledProperty );
}

// if a view node was specified, create and pass in a boolean property that is true only when the node is displayed
Expand Down Expand Up @@ -404,22 +411,22 @@ define( function( require ) {
*/
set sonificationLevel( sonificationLevel ) {
assert && assert( sonificationLevel === 'basic' || sonificationLevel === 'enhanced' );
sonificationLevelProperty.set( sonificationLevel );
enhancedSoundEnabledProperty.set( sonificationLevel === 'enhanced' );
},

/**
* ES5 getter for sonification level
* @returns {string}
*/
get sonificationLevel() {
return sonificationLevelProperty.get();
return enhancedSoundEnabledProperty.get() ? 'enhanced' : 'basic';
},

/**
* property that corresponds to the sonification level setting
* @public (read-only)
*/
sonificationLevelProperty: sonificationLevelProperty,
enhancedSoundEnabledProperty: enhancedSoundEnabledProperty,

/**
* add a property that indicates that a reset is in progress for a screen, should be called 1x per screen
Expand Down
6 changes: 3 additions & 3 deletions js/tambo-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ define( function( require ) {
], simOptions ).start();

// TODO: The following is temporarily here until init of soundManager is permanently moved into Sim.js.
soundManager.initialize(
phet.joist.sim.browserTabVisibleProperty
);
if ( !soundManager.isInitialized() ) {
soundManager.initialize( phet.joist.sim.browserTabVisibleProperty );
}
} );
} );

0 comments on commit d19da38

Please sign in to comment.