settings: clamp the preamp and make the dialog test assert

Review follow-ups.

- The snap clamped nothing, so an out-of-range stored value would show a
  decibel label the slider cannot reach: clamps now live in the snap
  rather than duplicated in the step.
- The screenshot test only rendered the dialog without asserting it
  opened, so deleting the row's click would have left it passing while
  the capture showed the plain list. It now requires the dialog's Reset.
- "Adjust level on top of the ReplayGain" was not grammatical, and the
  mode prompt claimed the server normalises when it only supplies the
  tags.
- Drop a test assertion that restated the production formula.
This commit is contained in:
austinried
2026-10-16 13:07:12 +00:00
parent 5b6c0ef45c
commit 8bcca2767d
4 changed files with 13 additions and 7 deletions
@@ -15,14 +15,14 @@ internal val REPLAY_GAIN_PREAMP_STEPS =
// Compose Material 3's Slider snaps in pixel space and converts back, so the value it reports is
// near, but not on, the grid it was configured with (for example -0.99999905 for -1.0). Snap before
// showing or storing it.
internal fun snapReplayGainPreampDb(value: Float): Float = (value / REPLAY_GAIN_PREAMP_STEP_DB).roundToInt() * REPLAY_GAIN_PREAMP_STEP_DB
internal fun snapReplayGainPreampDb(value: Float): Float =
((value / REPLAY_GAIN_PREAMP_STEP_DB).roundToInt() * REPLAY_GAIN_PREAMP_STEP_DB)
.coerceIn(MIN_REPLAY_GAIN_PREAMP_DB, MAX_REPLAY_GAIN_PREAMP_DB)
internal fun stepReplayGainPreampDb(
value: Float,
steps: Int,
): Float =
snapReplayGainPreampDb(value + steps * REPLAY_GAIN_PREAMP_STEP_DB)
.coerceIn(MIN_REPLAY_GAIN_PREAMP_DB, MAX_REPLAY_GAIN_PREAMP_DB)
): Float = snapReplayGainPreampDb(value + steps * REPLAY_GAIN_PREAMP_STEP_DB)
internal fun replayGainModeLabel(
resources: Resources,
+2 -2
View File
@@ -79,11 +79,11 @@
<string name="settings_replay_gain_mode_track">Track gain</string>
<string name="settings_replay_gain_preamp_decrease">Lower preamp</string>
<string name="settings_replay_gain_preamp_increase">Raise preamp</string>
<string name="settings_replay_gain_preamp_prompt">Adjust level on top of the ReplayGain</string>
<string name="settings_replay_gain_preamp_prompt">Extra level on top of ReplayGain</string>
<string name="settings_replay_gain_preamp_reset">Reset</string>
<string name="settings_replay_gain_preamp_title">Preamp</string>
<string name="settings_replay_gain_preamp_value">%1$s dB</string>
<string name="settings_replay_gain_prompt">Normalise loudness with the server\'s ReplayGain</string>
<string name="settings_replay_gain_prompt">Normalise loudness using the ReplayGain tags from the server</string>
<string name="settings_replay_gain_title">ReplayGain</string>
<string name="settings_network_name">Network</string>
<string name="settings_network_options_max_bitrate_mobile_title">Stream quality: Mobile</string>
@@ -355,6 +355,7 @@ class AppScreenshotTest {
composeRule.onNode(hasScrollAction()).performScrollToNode(hasText("Preamp"))
composeRule.onAllNodesWithText("Preamp")[0].performClick()
composeRule.waitForIdle()
composeRule.onAllNodesWithText("Reset").assertCountEquals(1)
composeRule.onRoot().captureRoboImage("src/test/screenshots/replay_gain_preamp.png")
}
@@ -30,7 +30,6 @@ class ReplayGainControlsTest {
@Test
fun theSliderHasOneStepPerHalfDecibel() {
assertEquals(60, ((MAX_REPLAY_GAIN_PREAMP_DB - MIN_REPLAY_GAIN_PREAMP_DB) / REPLAY_GAIN_PREAMP_STEP_DB).toInt())
assertEquals(59, REPLAY_GAIN_PREAMP_STEPS)
}
@@ -51,4 +50,10 @@ class ReplayGainControlsTest {
assertEquals(MAX_REPLAY_GAIN_PREAMP_DB, snapReplayGainPreampDb(14.9f), 0f)
assertEquals(MIN_REPLAY_GAIN_PREAMP_DB, snapReplayGainPreampDb(-14.9f), 0f)
}
@Test
fun thePreampIsClampedToItsRange() {
assertEquals(MAX_REPLAY_GAIN_PREAMP_DB, snapReplayGainPreampDb(20f), 0f)
assertEquals(MIN_REPLAY_GAIN_PREAMP_DB, snapReplayGainPreampDb(-20f), 0f)
}
}