Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.
Kotlin alternativeandroidandroid-applicationclientglassmorphisminnertubelibrespotliquid-glassspotifyspotify-connectspotifyapiyoutube-musicyoutube-playerytdlnis
Keep speed and pitch from undoing each other
Lelonio01c17d99bbd1
diff --git a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt b/app/src/main/java/dev/lelonio/square/ui/SquareApp.ktindex c7d9853..05ec772 100644--- a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt+++ b/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt@@ -519,13 +519,22 @@ fun SquareApp(// letting go, and the slider draws its own value meanwhile.val effectsScope = rememberCoroutineScope()var effectsJob by remember { mutableStateOf<kotlinx.coroutines.Job?>(null) }+ // What was last asked for and not yet sent. Speed and pitch travel as a+ // pair, so the one not being moved is taken from here first: taken from+ // the player, a pitch moved within the wait undid the speed still waiting.+ var pendingParameters by remember { mutableStateOf<PlaybackParameters?>(null) }val setPlaybackParameters: (PlaybackParameters) -> Unit = { params ->+ pendingParameters = paramseffectsJob?.cancel()effectsJob = effectsScope.launch {kotlinx.coroutines.delay(120)player?.playbackParameters = params+ pendingParameters = null}}+ val currentParameters: () -> PlaybackParameters = {+ pendingParameters ?: player?.playbackParameters ?: PlaybackParameters.DEFAULT+ }// What was last taken out of the queue, each with the place it had, kept// for a few seconds so it can be put back where it was.var queueUndo by remember {@@ -3205,17 +3214,21 @@ fun SquareApp(// has to carry the other through unchanged.onSpeed = {setPlaybackParameters(- PlaybackParameters(it, playback.pitch),+ PlaybackParameters(it, currentParameters().pitch),)},onPitch = {setPlaybackParameters(- PlaybackParameters(playback.speed, it),+ PlaybackParameters(currentParameters().speed, it),)},onReverb = AudioEffects::setReverb,presets = presets,onApplyPreset = { preset ->+ // Over any slider write still waiting, or+ // that lands after it and undoes it.+ effectsJob?.cancel()+ pendingParameters = nullplayer?.playbackParameters =PlaybackParameters(preset.speed, preset.pitch)AudioEffects.setReverb(preset.reverbAmount)diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidSlider.kt b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidSlider.ktindex ece8e44..e07f2df 100644--- a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidSlider.kt+++ b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidSlider.kt@@ -26,6 +26,7 @@ import androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.rememberCoroutineScope+import androidx.compose.runtime.rememberUpdatedStateimport androidx.compose.runtime.setValueimport androidx.compose.runtime.snapshotFlowimport androidx.compose.ui.Alignment@@ -82,6 +83,14 @@ fun LiquidSlider(val trackWidth = constraints.maxWidthval isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr+ // LOCAL CHANGE: read through this, never the parameter. The animation+ // and the gesture handler below are made once and outlive the+ // composition that made them, so the callback they closed over was the+ // first one — and that one had closed over whatever the caller knew+ // then. The effects panel builds speed and pitch as a pair, so moving+ // one sent the other as it was when the panel opened, and a pitch set+ // a moment ago sprang back to a value nobody had chosen.+ val latestOnValueChange by rememberUpdatedState(onValueChange)val animationScope = rememberCoroutineScope()var didDrag by remember { mutableStateOf(false) }val dampedDragAnimation = remember(animationScope) {@@ -95,7 +104,8 @@ fun LiquidSlider(onDragStarted = {},onDragStopped = {if (didDrag) {- onValueChange(targetValue)+ didDrag = false+ latestOnValueChange(targetValue)}},onDrag = { _, dragAmount ->@@ -103,7 +113,7 @@ fun LiquidSlider(didDrag = dragAmount.x != 0f}val delta = (valueRange.endInclusive - valueRange.start) * (dragAmount.x / trackWidth)- onValueChange(+ latestOnValueChange(if (isLtr) (targetValue + delta).coerceIn(valueRange)else (targetValue - delta).coerceIn(valueRange))@@ -157,7 +167,7 @@ fun LiquidSlider(else valueRange.endInclusive - delta).coerceIn(valueRange)dampedDragAnimation.updateValue(target)- onValueChange(target)+ latestOnValueChange(target)}awaitEachGesture {val down = awaitFirstDown(requireUnconsumed = false)@@ -202,7 +212,7 @@ fun LiquidSlider(else valueRange.endInclusive - delta).coerceIn(valueRange)dampedDragAnimation.animateToValue(targetValue)- onValueChange(targetValue)+ latestOnValueChange(targetValue)}}.height(6f.dp)diff --git a/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.kt b/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.ktindex faf88db..c92865e 100644--- a/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.kt+++ b/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.kt@@ -673,7 +673,12 @@ private fun EffectSlider(color = GlassInk,modifier = Modifier.clip(RoundedCornerShape(50))- .clickable(onClick = onReset)+ .clickable {+ // Or the thumb stays on the dragged value while the+ // player goes back to normal under it.+ dragged = null+ onReset()+ }.padding(horizontal = 10.dp, vertical = 4.dp),)}