Skip to content

Commit

Permalink
customized default sound generation to match quantized slider behavio…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Mar 4, 2022
1 parent b444f65 commit eb0e488
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
7 changes: 6 additions & 1 deletion js/common/view/DiameterControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ class DiameterControl extends NumberControl {
constrainValue: ( value: number ) => Utils.roundToInterval( value, GOConstants.DIAMETER_SLIDER_STEP ),
keyboardStep: GOConstants.DIAMETER_KEYBOARD_STEP, // used by all alternative-input devices
shiftKeyboardStep: GOConstants.DIAMETER_SHIFT_KEYBOARD_STEP, // finer grain, used by keyboard only
pageKeyboardStep: GOConstants.DIAMETER_PAGE_KEYBOARD_STEP // coarser grain, used by keyboard only
pageKeyboardStep: GOConstants.DIAMETER_PAGE_KEYBOARD_STEP, // coarser grain, used by keyboard only

// generate a sound for each slider step
soundGeneratorOptions: {
numberOfMiddleThresholds: diameterProperty.range!.getLength() / GOConstants.DIAMETER_SLIDER_STEP - 1
}
},
numberDisplayOptions: {
decimalPlaces: GOConstants.DIAMETER_DECIMAL_PLACES,
Expand Down
21 changes: 15 additions & 6 deletions js/common/view/IndexOfRefractionControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,27 @@ class IndexOfRefractionControl extends NumberControl {
*/
constructor( indexOfRefractionProperty: NumberProperty, providedOptions: IndexOfRefractionControlOptions ) {

assert && assert( indexOfRefractionProperty.range ); // {Range|null}
const indexOfRefractionRange: Range = indexOfRefractionProperty.range!;

// function to constrain the allowed values
const constrainValues = ( value: number ) =>
Utils.roundToInterval( value, GOConstants.INDEX_OF_REFRACTION_SLIDER_STEP );

// Assemble the defaults for NumberControl, because optionize doesn't currently support defaults in multiple objects.
const numberControlDefaults: OptionizeDefaults<{}, NumberControlOptions> = merge( {}, GOConstants.NUMBER_CONTROL_OPTIONS, {
delta: GOConstants.INDEX_OF_REFRACTION_SPINNER_STEP,
sliderOptions: {
constrainValue: ( value: number ) =>
Utils.roundToInterval( value, GOConstants.INDEX_OF_REFRACTION_SLIDER_STEP ),
constrainValue: constrainValues,
keyboardStep: GOConstants.INDEX_OF_REFRACTION_KEYBOARD_STEP, // used by all alternative-input devices
shiftKeyboardStep: GOConstants.INDEX_OF_REFRACTION_SHIFT_KEYBOARD_STEP, // finer grain, used by keyboard only
pageKeyboardStep: GOConstants.INDEX_OF_REFRACTION_PAGE_KEYBOARD_STEP // coarser grain, used by keyboard only
pageKeyboardStep: GOConstants.INDEX_OF_REFRACTION_PAGE_KEYBOARD_STEP, // coarser grain, used by keyboard only

// generate a sound for each slider step
soundGeneratorOptions: {
numberOfMiddleThresholds: Utils.roundSymmetric( indexOfRefractionRange.getLength() / GOConstants.INDEX_OF_REFRACTION_SLIDER_STEP ) - 1,
constrainThresholds: constrainValues
}
},
numberDisplayOptions: {
decimalPlaces: GOConstants.INDEX_OF_REFRACTION_DECIMAL_PLACES
Expand All @@ -45,9 +57,6 @@ class IndexOfRefractionControl extends NumberControl {

const options = optionize<IndexOfRefractionControlOptions, {}, NumberControlOptions>( numberControlDefaults, providedOptions );

assert && assert( indexOfRefractionProperty.range ); // {Range|null}
const indexOfRefractionRange: Range = indexOfRefractionProperty.range!;

super( geometricOpticsStrings.indexOfRefraction, indexOfRefractionProperty, indexOfRefractionRange, options );

this.addLinkedElement( indexOfRefractionProperty, {
Expand Down
13 changes: 9 additions & 4 deletions js/common/view/RadiusOfCurvatureControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class RadiusOfCurvatureControl extends NumberControl {
: geometricOpticsStrings.radiusOfCurvatureNegative;
} );

assert && assert( radiusOfCurvatureMagnitudeProperty.range ); // {Range|null}
const radiusOfCurvatureRange: Range = radiusOfCurvatureMagnitudeProperty.range!;

// Assemble the defaults for NumberControl, because optionize doesn't currently support defaults in multiple objects.
const numberControlDefaults: OptionizeDefaults<{}, NumberControlOptions> = merge( {}, GOConstants.NUMBER_CONTROL_OPTIONS, {
delta: GOConstants.RADIUS_OF_CURVATURE_SPINNER_STEP,
Expand All @@ -58,15 +61,17 @@ class RadiusOfCurvatureControl extends NumberControl {
constrainValue: ( value: number ) => Utils.roundToInterval( value, GOConstants.RADIUS_OF_CURVATURE_SLIDER_STEP ),
keyboardStep: GOConstants.RADIUS_OF_CURVATURE_KEYBOARD_STEP, // used by all alternative-input devices
shiftKeyboardStep: GOConstants.RADIUS_OF_CURVATURE_SHIFT_KEYBOARD_STEP, // finer grain, used by keyboard only
pageKeyboardStep: GOConstants.RADIUS_OF_CURVATURE_PAGE_KEYBOARD_STEP // coarser grain, used by keyboard only
pageKeyboardStep: GOConstants.RADIUS_OF_CURVATURE_PAGE_KEYBOARD_STEP, // coarser grain, used by keyboard only

// generate a sound for each slider step
soundGeneratorOptions: {
numberOfMiddleThresholds: radiusOfCurvatureRange.getLength() / GOConstants.RADIUS_OF_CURVATURE_SLIDER_STEP - 1
}
}
} );

const options = optionize<RadiusOfCurvatureControlOptions, {}, NumberControlOptions>( numberControlDefaults, providedOptions );

assert && assert( radiusOfCurvatureMagnitudeProperty.range ); // {Range|null}
const radiusOfCurvatureRange: Range = radiusOfCurvatureMagnitudeProperty.range!;

super( textProperty.value, radiusOfCurvatureMagnitudeProperty, radiusOfCurvatureRange, options );

this.addLinkedElement( radiusOfCurvatureMagnitudeProperty, {
Expand Down

0 comments on commit eb0e488

Please sign in to comment.