Skip to content

Commit

Permalink
sound player instead of sound generator for slider sounds, see #697
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed May 27, 2022
1 parent 09af024 commit b98e7dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 7 additions & 8 deletions js/Slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Tandem from '../../tandem/js/Tandem.js';
import BooleanIO from '../../tandem/js/types/BooleanIO.js';
import IOType from '../../tandem/js/types/IOType.js';
import VoidIO from '../../tandem/js/types/VoidIO.js';
import ValueChangeSoundGenerator, { ValueChangeSoundGeneratorOptions } from '../../tambo/js/sound-generators/ValueChangeSoundGenerator.js';
import ValueChangeSoundPlayer, { ValueChangeSoundPlayerOptions } from '../../tambo/js/sound-generators/ValueChangeSoundPlayer.js';
import AccessibleSlider, { AccessibleSliderOptions } from './accessibility/AccessibleSlider.js';
import DefaultSliderTrack from './DefaultSliderTrack.js';
import SliderThumb from './SliderThumb.js';
Expand Down Expand Up @@ -118,11 +118,10 @@ type SelfOptions = {

// This is used to generate sounds as the slider is moved by the user. If not provided, the default sound generator
// will be created. If set to null, the slider will generate no sound.
soundGenerator?: ValueChangeSoundGenerator | null;
soundGenerator?: ValueChangeSoundPlayer | null;

// Options for the default sound generator. These should only be provided when using the default.
valueChangeSoundGeneratorOptions?: ValueChangeSoundGeneratorOptions;

valueChangeSoundGeneratorOptions?: ValueChangeSoundPlayerOptions;
};

// We provide these options to the super
Expand Down Expand Up @@ -153,7 +152,7 @@ export default class Slider extends AccessibleSlider( Node, 0 ) {
private readonly disposeSlider: () => void;

// This is a marker to indicate that we should create the actual default slider sound.
public static DEFAULT_SOUND = new ValueChangeSoundGenerator( new Range( 0, 1 ) );
public static DEFAULT_SOUND = new ValueChangeSoundPlayer( new Range( 0, 1 ) );

constructor( valueProperty: IProperty<number>, range: Range, providedOptions?: SliderOptions ) {

Expand Down Expand Up @@ -232,14 +231,14 @@ export default class Slider extends AccessibleSlider( Node, 0 ) {

// If no sound generator was provided, create the default.
if ( options.soundGenerator === Slider.DEFAULT_SOUND ) {
options.soundGenerator = new ValueChangeSoundGenerator( range, options.valueChangeSoundGeneratorOptions || {} );
options.soundGenerator = new ValueChangeSoundPlayer( range, options.valueChangeSoundGeneratorOptions || {} );
}
else if ( options.soundGenerator === null ) {
options.soundGenerator = ValueChangeSoundGenerator.NO_SOUND;
options.soundGenerator = ValueChangeSoundPlayer.NO_SOUND;
}

// Set up the drag handler to generate sound when drag events cause changes.
if ( options.soundGenerator !== ValueChangeSoundGenerator.NO_SOUND ) {
if ( options.soundGenerator !== ValueChangeSoundPlayer.NO_SOUND ) {

// variable to keep track of the value at the start of user drag interactions
let previousValue = valueProperty.value;
Expand Down
10 changes: 5 additions & 5 deletions js/SliderTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Property from '../../axon/js/Property.js';
import Dimension2 from '../../dot/js/Dimension2.js';
import LinearFunction from '../../dot/js/LinearFunction.js';
import Range from '../../dot/js/Range.js';
import ValueChangeSoundGenerator, { ValueChangeSoundGeneratorOptions } from '../../tambo/js/sound-generators/ValueChangeSoundGenerator.js';
import ValueChangeSoundPlayer, { ValueChangeSoundPlayerOptions } from '../../tambo/js/sound-generators/ValueChangeSoundPlayer.js';
import optionize from '../../phet-core/js/optionize.js';
import { DragListener, Node, NodeOptions, SceneryEvent, Trail } from '../../scenery/js/imports.js';
import Tandem from '../../tandem/js/Tandem.js';
Expand All @@ -41,10 +41,10 @@ type SelfOptions = {

// This is used to generate sounds when clicking in the track. If not provided, the default sound generator
// will be created. If set to null, the slider will generate no sound.
soundGenerator?: ValueChangeSoundGenerator | null;
soundGenerator?: ValueChangeSoundPlayer | null;

// Options for the default sound generator. These should only be provided when using the default.
valueChangeSoundGeneratorOptions?: ValueChangeSoundGeneratorOptions;
valueChangeSoundGeneratorOptions?: ValueChangeSoundPlayerOptions;
};

export type SliderTrackOptions = SelfOptions & NodeOptions;
Expand Down Expand Up @@ -81,10 +81,10 @@ export default class SliderTrack extends Node {

// If no sound generator was provided, create the default.
if ( options.soundGenerator === Slider.DEFAULT_SOUND ) {
options.soundGenerator = new ValueChangeSoundGenerator( range, options.valueChangeSoundGeneratorOptions || {} );
options.soundGenerator = new ValueChangeSoundPlayer( range, options.valueChangeSoundGeneratorOptions || {} );
}
else if ( options.soundGenerator === null ) {
options.soundGenerator = ValueChangeSoundGenerator.NO_SOUND;
options.soundGenerator = ValueChangeSoundPlayer.NO_SOUND;
}

this.size = options.size;
Expand Down

0 comments on commit b98e7dd

Please sign in to comment.