Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Remove tremolo (Android’s decoder is stabler), implement crossfade sl…
Browse files Browse the repository at this point in the history
…ider

Signed-off-by: iTaysonLab <[email protected]>
  • Loading branch information
iTaysonLab committed Apr 22, 2022
1 parent c9e617d commit 9682681
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 242 deletions.
10 changes: 0 additions & 10 deletions app/src/main/java/bruhcollective/itaysonlab/jetispot/SpApp.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package bruhcollective.itaysonlab.jetispot

import android.app.Application
import android.os.Build
import bruhcollective.itaysonlab.jetispot.core.SpConfigurationManager
import bruhcollective.itaysonlab.jetispot.core.SpSessionManager
import bruhcollective.itaysonlab.jetispot.playback.sp.AndroidNativeDecoder
import bruhcollective.itaysonlab.jetispot.playback.sp.TremoloVorbisDecoder
import dagger.hilt.android.HiltAndroidApp
import xyz.gianlu.librespot.audio.decoders.Decoders
import xyz.gianlu.librespot.audio.format.SuperAudioFormat
import javax.inject.Inject

@HiltAndroidApp
class SpApp: Application() {
@Inject lateinit var spConfigurationManager: SpConfigurationManager

init {
Decoders.registerDecoder(SuperAudioFormat.VORBIS, AndroidNativeDecoder::class.java)
Decoders.registerDecoder(SuperAudioFormat.MP3, AndroidNativeDecoder::class.java)
if (isArm()) Decoders.registerDecoder(SuperAudioFormat.VORBIS, 0, TremoloVorbisDecoder::class.java)
}

private fun isArm() = Build.SUPPORTED_ABIS.firstOrNull { it.contains("arm") } != null
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.LibraryMusic
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -59,8 +60,8 @@ sealed class Screen(open val route: String, val screenProvider: @Composable (nav

object Library: BottomNavigationScreen(
route = "library",
name = R.string.tab_library,
iconProvider = { Icons.Default.LibraryMusic },
name = R.string.tab_config,
iconProvider = { Icons.Default.Settings },
screenProvider = { navController ->
ConfigScreen(navController)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bruhcollective.itaysonlab.jetispot.ui.screens.config
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
Expand Down Expand Up @@ -73,15 +74,18 @@ class ConfigScreenViewModel @Inject constructor(
)
}, { it.navigate("config/playbackNormalization") }))

add(ConfigItem.Preference(R.string.config_crossfade, { ctx, cfg ->
when (cfg.playerConfig.crossfade) {
add(ConfigItem.Slider(R.string.config_crossfade, { ctx, value ->
when (value) {
0 -> ctx.getString(R.string.crossfade_disabled)
else -> ctx.getString(
R.string.crossfade_enabled,
cfg.playerConfig.crossfade
) // TODO: move to plurals
else -> ctx.resources.getQuantityString(R.plurals.seconds, value, value)
}
}, { it.navigate("config/playbackCrossfade") }))
}, 0f..12f, 11, { cfg ->
Log.d("SPM", "get ${cfg.playerConfig.crossfade}")
cfg.playerConfig.crossfade
}, { num ->
Log.d("SPM", "set $num")
playerConfig = playerConfig.toBuilder().setCrossfade(num).build()
}))

add(
ConfigItem.Switch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bruhcollective.itaysonlab.jetispot.ui.screens.config

import android.content.Context
import androidx.annotation.FloatRange
import androidx.annotation.StringRes
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -30,6 +31,7 @@ import androidx.navigation.NavController
import bruhcollectie.itaysonlab.jetispot.proto.AppConfig
import bruhcollective.itaysonlab.jetispot.core.SpConfigurationManager
import bruhcollective.itaysonlab.jetispot.ui.ext.compositeSurfaceElevation
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch

interface ConfigViewModel {
Expand Down Expand Up @@ -107,6 +109,12 @@ fun BaseConfigScreen(
scope.launch { viewModel.modifyDatastore { item.modify(this) }}
}
}

is ConfigItem.Slider -> {
ConfigSlider(stringResource(item.title), item.subtitle, item.range, item.stepCount, item.state(dsConfig)) { newValue ->
scope.launch { viewModel.modifyDatastore { item.modify(this, newValue) }}
}
}
}
}
}
Expand Down Expand Up @@ -191,7 +199,8 @@ fun ConfigLargeSwitch(
onClick(!value)
}, modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp).padding(bottom = 8.dp)) {
.padding(horizontal = 16.dp)
.padding(bottom = 8.dp)) {
Row(modifier = Modifier.padding(horizontal = 20.dp, vertical = 8.dp)) {
Text(text = title, color = MaterialTheme.colorScheme.inverseOnSurface, fontSize = 18.sp, modifier = Modifier
.fillMaxWidth(0.85f)
Expand Down Expand Up @@ -260,6 +269,54 @@ fun ConfigPreference(
}
}

@Composable
fun ConfigSlider(
title: String,
subtitleFunc: (Context, Int) -> String,
range: ClosedFloatingPointRange<Float>,
stepCount: Int,
initialValue: Int,
onValueChange: (Int) -> Unit
) {
val sliderValueFirst = remember { initialValue.toFloat() }
val sliderValueWAApplied = remember { mutableStateOf(false) }
var sliderValue by remember { mutableStateOf(sliderValueFirst) }

// a slight workaround for datastore's collectAsState initial
if (!sliderValueWAApplied.value && initialValue.toFloat() != sliderValueFirst) {
sliderValueWAApplied.value = true
sliderValue = initialValue.toFloat()
}

val subtitle = subtitleFunc(LocalContext.current, sliderValue.toInt())

Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
.padding(top = 16.dp, bottom = 6.dp)
) {
Box(Modifier.fillMaxWidth()) {
Text(text = title, color = MaterialTheme.colorScheme.onBackground, fontSize = 18.sp, modifier = Modifier.align(Alignment.CenterStart))
if (subtitle.isNotEmpty()) Text(
text = subtitle,
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontSize = 14.sp,
modifier = Modifier.align(Alignment.CenterEnd)
)
}

Slider(
value = sliderValue,
onValueChange = { sliderValue = it },
onValueChangeFinished = { onValueChange(sliderValue.toInt()) },
modifier = Modifier.padding(top = 4.dp),
valueRange = range,
steps = stepCount
)
}
}

//

sealed class ConfigItem {
Expand Down Expand Up @@ -292,4 +349,13 @@ sealed class ConfigItem {
val enabledState: (AppConfig) -> Boolean,
val modify: AppConfig.Builder.() -> Unit
) : ConfigItem()

class Slider(
@StringRes val title: Int,
val subtitle: (Context, Int) -> String,
val range: ClosedFloatingPointRange<Float>,
val stepCount: Int,
val state: (AppConfig) -> Int,
val modify: AppConfig.Builder.(Int) -> Unit
) : ConfigItem()
}

This file was deleted.

Loading

0 comments on commit 9682681

Please sign in to comment.