Skip to content

Commit

Permalink
Revert "feat: changing reverb (#600)"
Browse files Browse the repository at this point in the history
This reverts commit a1c834d.
  • Loading branch information
zyrouge committed Oct 26, 2024
1 parent a1c834d commit 57497f6
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class Radio(private val symphony: Symphony) : SymphonyHooks {

var persistedSpeed: Float = RadioPlayer.DEFAULT_SPEED
var persistedPitch: Float = RadioPlayer.DEFAULT_PITCH
var persistedReverb: Float = RadioPlayer.DEFAULT_REVERB
var sleepTimer: RadioSleepTimer? = null
var pauseOnCurrentSongEnd = false

Expand Down Expand Up @@ -245,15 +244,7 @@ class Radio(private val symphony: Symphony) : SymphonyHooks {
onUpdate.dispatch(RadioEvents.PitchChanged)
}
}
fun setReverb(reverb: Float, persist: Boolean) {
player?.let {
it.setReverb(reverb)
if (persist) {
persistedReverb = reverb
}
onUpdate.dispatch(RadioEvents.PitchChanged)
}
}

fun setSleepTimer(
duration: Long,
quitOnEnd: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class RadioPlayer(val symphony: Symphony, uri: Uri) {
var volume: Float = MAX_VOLUME
var speed: Float = DEFAULT_SPEED
var pitch: Float = DEFAULT_PITCH
var reverb: Float = DEFAULT_REVERB
val fadePlayback: Boolean
get() = symphony.settings.fadePlayback.value
val audioSessionId: Int?
Expand Down Expand Up @@ -188,26 +187,6 @@ class RadioPlayer(val symphony: Symphony, uri: Uri) {
}
}

@JvmName("setReverbTo")
fun setReverb(to: Float) {
if (!hasPlayedOnce) {
reverb = to
return
}
mediaPlayer?.let {
val isPlaying = it.isPlaying
try {
it.playbackParams = it.playbackParams.setReverb(to)
reverb = to
} catch (err: Exception) {
Logger.error("RadioPlayer", "changing reverb failed", err)
}
if (!isPlaying) {
it.pause()
}
}
}

fun setOnPlaybackPositionListener(listener: RadioPlayerOnPlaybackPositionListener?) {
onPlaybackPosition = listener
}
Expand Down Expand Up @@ -239,6 +218,5 @@ class RadioPlayer(val symphony: Symphony, uri: Uri) {
const val DUCK_VOLUME = 0.2f
const val DEFAULT_SPEED = 1f
const val DEFAULT_PITCH = 1f
const val DEFAULT_REVERB = 1f
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ data class NowPlayingData(
val currentShuffleMode: Boolean,
val currentSpeed: Float,
val currentPitch: Float,
val currentReverb: Float,
val persistedSpeed: Float,
val persistedPitch: Float,
val persistedReverb: Float,
val hasSleepTimer: Boolean,
val pauseOnCurrentSongEnd: Boolean,
val showSongAdditionalInfo: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ fun NowPlayingBodyBottomBar(
var showSleepTimerDialog by remember { mutableStateOf(false) }
var showSpeedDialog by remember { mutableStateOf(false) }
var showPitchDialog by remember { mutableStateOf(false) }
var showReverbDialog by remember { mutableStateOf(false) }
var showExtraOptions by remember { mutableStateOf(false) }

data.run {
Expand Down Expand Up @@ -213,16 +212,7 @@ fun NowPlayingBodyBottomBar(
}
)
}
if (showReverbDialog) {
NowPlayingReverbDialog(
context,
currentReverb= data.currentReverb,
persistedReverb = data.persistedReverb,
onDismissRequest = {
showReverbDialog = false
}
)
}

if (showExtraOptions) {
val sheetState = rememberModalBottomSheetState()
val closeBottomSheet = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.zyrouge.symphony.ui.view.nowPlaying

import android.media.audiofx.PresetReverb
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -223,100 +222,3 @@ fun NowPlayingPitchDialog(
},
)
}

@Composable
fun NowPlayingReverbDialog(
context: ViewContext,
currentReverb: Float,
persistedReverb: Float,
onDismissRequest: () -> Unit,
) {
val allowedReverb = listOf(0.5f, 1f, 1.5f, 2f, 3f)
val allowedReverbRange = allowedReverb.first()..allowedReverb.last()
var persistent by remember {
mutableStateOf(currentReverb == persistedReverb)
}

ScaffoldDialog(
onDismissRequest = onDismissRequest,
title = {
Text(context.symphony.t.Reverb)
},
content = {
Column(modifier = Modifier.padding(0.dp, 8.dp)) {
Row(
horizontalArrangement = Arrangement.spacedBy(
4.dp,
Alignment.CenterHorizontally
),
modifier = Modifier
.fillMaxWidth()
.padding(top = 16.dp),
) {
allowedReverb.forEach { reverb ->
val onClick = {
context.symphony.radio.setReverb(reverb, persistent)
}
val shape = RoundedCornerShape(4.dp)

Text(
"x$reverb",
style = MaterialTheme.typography.labelMedium,
modifier = Modifier
.background(
MaterialTheme.colorScheme.surfaceVariant,
shape,
)
.clip(shape)
. clickable(onClick = onClick)
.padding(8.dp, 4.dp)
)
}
}
Slider(
value = currentReverb,
onChange = { value ->
val reverb = (value * 10).roundToInt().toFloat() / 10
context.symphony.radio.setReverb(reverb, persistent)
},
range = allowedReverbRange,
label = { value ->
Text("x$value")
},
modifier = Modifier
.padding(top = 24.dp, bottom = 8.dp)
)

Row(
modifier = Modifier.padding(12.dp, 0.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Checkbox(
checked = persistent,
onCheckedChange = {
persistent = !persistent
context.symphony.radio.setReverb(currentReverb, persistent)
}
)
Spacer(modifier = Modifier.width(8.dp))
Text(context.symphony.t.PersistUntilQueueEnd)
}
}
},
actions = {
TextButton(
onClick = {
context.symphony.radio.setReverb(1f, persistent)
onDismissRequest()
}
) {
Text(context.symphony.t.Reset)
}
TextButton(
onClick = onDismissRequest
) {
Text(context.symphony.t.Done)
}
},
)
}

0 comments on commit 57497f6

Please sign in to comment.