diff --git a/app/src/main/kotlin/com/subtracks/ui/settings/ReplayGainControls.kt b/app/src/main/kotlin/com/subtracks/ui/settings/ReplayGainControls.kt index fe43209d..393caa0f 100644 --- a/app/src/main/kotlin/com/subtracks/ui/settings/ReplayGainControls.kt +++ b/app/src/main/kotlin/com/subtracks/ui/settings/ReplayGainControls.kt @@ -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, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be037408..469a461e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,11 +79,11 @@ Track gain Lower preamp Raise preamp - Adjust level on top of the ReplayGain + Extra level on top of ReplayGain Reset Preamp %1$s dB - Normalise loudness with the server\'s ReplayGain + Normalise loudness using the ReplayGain tags from the server ReplayGain Network Stream quality: Mobile diff --git a/app/src/test/kotlin/com/subtracks/ui/AppScreenshotTest.kt b/app/src/test/kotlin/com/subtracks/ui/AppScreenshotTest.kt index a6c6961e..3f0fce0e 100644 --- a/app/src/test/kotlin/com/subtracks/ui/AppScreenshotTest.kt +++ b/app/src/test/kotlin/com/subtracks/ui/AppScreenshotTest.kt @@ -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") } diff --git a/app/src/test/kotlin/com/subtracks/ui/settings/ReplayGainControlsTest.kt b/app/src/test/kotlin/com/subtracks/ui/settings/ReplayGainControlsTest.kt index 5b08e816..b58e2250 100644 --- a/app/src/test/kotlin/com/subtracks/ui/settings/ReplayGainControlsTest.kt +++ b/app/src/test/kotlin/com/subtracks/ui/settings/ReplayGainControlsTest.kt @@ -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) + } }