Skip to content

Commit

Permalink
addressed issue with excess sound when dragging on track, see #204
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Jan 15, 2019
1 parent 3c5c38c commit d32bfcf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
14 changes: 8 additions & 6 deletions js/resistance-in-a-wire/view/ResistanceSoundGenerator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright 2018, University of Colorado Boulder

/**
* a sound generator used to indicate the resistance level in the RIAW simulation
* A sound generator used to indicate the resistance level in the RIAW simulation. This uses the values for the
* resistivity, length, and area of the wire to decide WHEN to generate a sound, and the value of the resistance to
* determine the nature of the sound to be generated.
*
* @author John Blanco
*/
Expand Down Expand Up @@ -30,8 +32,8 @@ define( function( require ) {

/**
* @constructor
* TODO: document when finalized
* {Object} config
* {Object} config - a configuration object that includes property values for the resistivity, area, and length of
* the wire and the sliders that control each, as well as a property the indicates whether a reset is in progress.
*/
function ResistanceSoundGenerator( config ) {

Expand Down Expand Up @@ -63,7 +65,7 @@ define( function( require ) {

// Play the sound if a change has occurred due to keyboard interaction, if the area value has moved to a new bin,
// or if a min or max has been reached.
if ( !config.resistivitySlider.thumbDragging || bin !== resistivityBin ||
if ( config.resistivitySlider.keyboardDragging || bin !== resistivityBin ||
resistivity === MIN_RESISTIVITY || resistivity === MAX_RESISTIVITY ) {
playResistanceSound();
}
Expand All @@ -78,7 +80,7 @@ define( function( require ) {

// Play the sound if a change has occurred due to keyboard interaction, if the area value has moved to a new bin,
// or if a min or max has been reached.
if ( !config.lengthSlider.thumbDragging || bin !== lengthBin ||
if ( config.lengthSlider.keyboardDragging || bin !== lengthBin ||
length === MIN_LENGTH || length === MAX_LENGTH ) {
playResistanceSound();
}
Expand All @@ -93,7 +95,7 @@ define( function( require ) {

// Play the sound if a change has occurred due to keyboard interaction, if the area value has moved to a new bin,
// or if a min or max has been reached.
if ( !config.areaSlider.thumbDragging || bin !== areaBin ||
if ( config.areaSlider.keyboardDragging || bin !== areaBin ||
area === MIN_AREA || area === MAX_AREA ) {
playResistanceSound();
}
Expand Down
45 changes: 23 additions & 22 deletions js/resistance-in-a-wire/view/SliderUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ define( function( require ) {
*/
function SliderUnit( property, range, symbolString, nameString, unitString, labelContent, tandem, options ) {

var self = this;
Node.call( this );

options = _.extend( {
accessibleDecimalPlaces: 2,
keyboardStep: 1,
shiftKeyboardStep: 0.01,
accessibleValuePattern: '{{value}}', // string pattern used for formatting the value read by the screen reader
endDrag: function() {}, // called at end of drag by HSlider
startDrag: function() {}
startDrag: _.noop,
endDrag: _.noop
}, options );

// text for the symbol, text bounds must be accurate for correct layou
Expand All @@ -59,14 +60,27 @@ define( function( require ) {
tandem: tandem.createTandem( 'nameText' )
} );

// @public (read-only) {boolean} - flag that indicates whether the slider is being dragged by the keyboard
this.keyboardDragging = false;

// @private
this.slider = new VSlider( property, range, {
var slider = new VSlider( property, range, {
trackFillEnabled: 'black',
trackSize: new Dimension2( ResistanceInAWireConstants.SLIDER_HEIGHT - 30, 4 ),
thumbSize: new Dimension2( 22, 45 ),
thumbFillEnabled: '#c3c4c5',
thumbFillHighlighted: '#dedede',
tandem: tandem.createTandem( 'slider' ),
startDrag: function( event ) {
if ( event.type === 'keydown' ) {
self.keyboardDragging = true;
}
options.startDrag && options.startDrag( event );
},
endDrag: function() {
self.keyboardDragging = false;
options.endDrag && options.endDrag( event );
},

// physical values in this sim can have up to 2 decimals
constrainValue: function( value ) {
Expand All @@ -80,8 +94,6 @@ define( function( require ) {
accessibleDecimalPlaces: options.accessibleDecimalPlaces, // demimal places for readout
ariaOrientation: 'vertical',
roundToStepSize: true, // default keyboard step rounds to pedegogically useful values
startDrag: options.startDrag,
endDrag: options.endDrag,

// a11y
containerTagName: 'li',
Expand Down Expand Up @@ -112,12 +124,12 @@ define( function( require ) {
valueText.y = unitText.y - 35;

// sliders along the top of values
this.slider.bottom = valueText.y - 30;
this.slider.centerX = unitText.centerX;
slider.bottom = valueText.y - 30;
slider.centerX = unitText.centerX;

// names along the top of the slider
nameText.y = this.slider.top - 5;
nameText.centerX = this.slider.centerX;
nameText.y = slider.top - 5;
nameText.centerX = slider.centerX;

// symbol texts along the top
symbolText.bottom = nameText.y - 20;
Expand All @@ -126,7 +138,7 @@ define( function( require ) {
// Add children, from top to bottom of the slider unit
this.addChild( symbolText );
this.addChild( nameText );
this.addChild( this.slider );
this.addChild( slider );
this.addChild( valueText );
this.addChild( unitText );

Expand All @@ -141,16 +153,5 @@ define( function( require ) {

resistanceInAWire.register( 'SliderUnit', SliderUnit );

return inherit( Node, SliderUnit, {

/**
* flag indicating whether the slider thumb is being dragged
* @returns {boolean}
*/
get thumbDragging() {

// pass the value through from the actual slider component
return this.slider.isThumbDraggingProperty.value;
}
} );
return inherit( Node, SliderUnit );
} );

0 comments on commit d32bfcf

Please sign in to comment.