Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
Merge automix/segue-plan: plan-based mixes (test build only), late entries, EQ, faster cold start
kota-zoee1e827b61ca
diff --cc base/app/build.gradle.ktsindex 6ee1b9e1,83589d2b..eaaa0904--- a/base/app/build.gradle.kts+++ b/base/app/build.gradle.kts@@@ -13,18 -13,11 +13,21 @@@ val keystoreProperties = Properties().a}}+ // -PautomixLab: a test app with its own data, installed alongside every regular/dev build.+ val automixLab = findProperty("automixLab") != null++/** The ABIs a release has an APK for, and how they are named in it (UpdateChecker reads the same names). */+val RELEASE_ABIS = listOf("arm64-v8a", "armeabi-v7a")+val ABI_NAMES = mapOf("arm64-v8a" to "ARMv8", "armeabi-v7a" to "ARMv7")+android {+ testOptions {+ unitTests {+ isIncludeAndroidResources = true+ all { it.systemProperty("roborazzi.test.record", "true") }+ }+ }namespace = "app.myspoti.engine"compileSdk = 37@@@ -47,9 -40,12 +50,10 @@@versionName = version// GitHub "owner/repo" whose releases the app checks for updates; empty = off// (local builds). CI sets it to the repository it builds.+ buildConfigField("boolean", "AUTOMIX_LAB", automixLab.toString())buildConfigField("String", "UPDATE_REPO", "\"${(findProperty("updateRepo") as String?) ?: System.getenv("MYSPOTI_UPDATE_REPO") ?: ""}\"")- ndk {- // -Pabis=arm64-v8a: a smaller test APK for one phone.- abiFilters += (findProperty("abis") as String?)?.split(",") ?: listOf("arm64-v8a", "armeabi-v7a")- }+ // -Pabis=arm64-v8a: one APK for one phone (the test builds). Without it, the ABI splits below.+ (findProperty("abis") as String?)?.let { ndk { abiFilters += it.split(",") } }// On-device tests (codecs): ./gradlew connectedDebugAndroidTesttestInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"}diff --cc base/app/src/main/java/com/music/spotui/automix/AutoMix.ktindex 9a809ba2,929d88d6..729a4a8c--- a/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt+++ b/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt@@@ -216,40 -257,55 +266,59 @@@ object AutoMix}}- private fun analyse(uri: Uri, key: String): TrackAnalysis? {- // A stream is read a second time for the analysis: on unmetered networks only, unless the- // listener allows mobile data (never under the data saver, which refuses every connection).- if (uri.scheme == ExtensionAudio.SCHEME) {- val saver = com.music.spotui.data.DataSaver.active- if (com.music.spotui.data.DataSaver.metered && (saver || !analyzeOnMobileData)) {- synchronized(memory) { refused[key] = Reason.MobileData }- journal("not analysed (${if (saver) "data saver" else "metered network"}): ${uri.lastPathSegment}"); return null+ @Volatile private var pageWaited = false++ /**+ * A cold start: the player's page loads first. A mix is planned long before it is needed, and two+ * songs decoded at once with it took the page from about 3 s to about 20 s on the test phone.+ */+ private fun waitForThePage() {+ if (pageWaited) return+ val end = android.os.SystemClock.elapsedRealtime() + PAGE_WAIT_MS+ while (android.os.SystemClock.elapsedRealtime() < end && !runCatching { app.myspoti.host.android.MyspotiRuntime.api.ready.value }.getOrDefault(false)) Thread.sleep(250)+ pageWaited = true+ }++ private const val PAGE_WAIT_MS = 25_000L++ private fun analyse(uri: Uri, epoch: Long): Pair<String, TrackAnalysis>? {+ val id = requestId(uri)+ val cancelled = { epoch != cacheEpoch || id !in wanted }+ var cacheKey = key(uri)+ try {+ if (uri.scheme == ExtensionAudio.SCHEME) {+ val saver = com.music.spotui.data.DataSaver.active+ if (com.music.spotui.data.DataSaver.metered && (saver || !analyzeOnMobileData)) {+ synchronized(memory) { refused[id] = Reason.MobileData }+ return null+ }+ if (ExtensionAudio.resolve(uri, ahead = true) == null) throw java.io.IOException("no stream")+ prepareStreamKey(uri)+ cacheKey = key(uri)+ // A source had not answered at the cache pass: its old analysis may now be usable.+ load(cacheKey)?.let { return cacheKey to it }}- // DASH answers too: the data source reads them as one file, as the player does.- val s = runCatching { ExtensionAudio.resolve(uri, ahead = true) }.getOrNull()- if (s == null) { synchronized(memory) { failed += key; refused[key] = Reason.NotAnalyzed }; journal("not analysed (no stream): ${uri.lastPathSegment}"); return null }- }- val t0 = System.currentTimeMillis()- return try {- val cancelled = { key !in wanted }+ if (cancelled()) return null+ val t0 = System.currentTimeMillis()val pcm = TrackDecoder.decode(uri, cancelled)val t1 = System.currentTimeMillis()- val a = Analyzer.analyze(pcm.mid, pcm.side, model(), cancelled, if (frugal()) 2 else if (charging()) THREADS else minOf(THREADS, 3))+ // On battery 3: measured on the S24, 5 made the same song's analysis slower (7.6 s against 5.5 s),+ // the extra cores being small ones and the next song's decode running meanwhile.+ val threads = if (frugal()) 2 else if (charging()) THREADS else minOf(THREADS, 3)+ val a = Analyzer.analyze(pcm.mid, pcm.side, model(), cancelled, threads)- save(key, a)+ if (cancelled() || cacheKey != key(uri)) return null+ save(cacheKey, a)- journal(String.format("analysed %s: %.1f BPM%s, %d bars, key %d, decode %d ms, analysis %d ms", label(uri), a.bpm,- if (a.steady) " steady" else (if (a.tail != null) " (tail grid)" else " (no grid)"), a.bars, a.key, t1 - t0, System.currentTimeMillis() - t1) ++ journal(String.format("analysed %s: %.1f BPM%s, %d bars, key %d, decode %d ms (bytes %d ms, %.1f MB, convert %d ms, %d restarts), analysis %d ms on %d threads", label(uri), a.bpm,+ if (a.steady) " steady" else (if (a.tail != null) " (tail grid)" else " (no grid)"), a.bars, a.key, t1 - t0, pcm.readMs, pcm.bytes / 1e6, pcm.convertMs, pcm.restarts,+ System.currentTimeMillis() - t1, threads) +(if (a.note.isNotEmpty()) " | grids refused: ${a.note}" else ""))- a- } catch (e: InterruptedException) {- null- } catch (e: Throwable) {- synchronized(memory) { failed += key; refused[key] = Reason.NotAnalyzed }- journal("analysis failed for ${label(uri)}: ${e.javaClass.simpleName} ${e.message?.take(120)}")- null+ return cacheKey to a+ } catch (e: Exception) {+ // MediaExtractor can wrap the data source's cancellation IOException.+ if (cancelled() || e is InterruptedException) return null+ synchronized(memory) { retry.failed(cacheKey, android.os.SystemClock.elapsedRealtime()); refused[id] = Reason.NotAnalyzed }+ journal("analysis deferred for ${label(uri)}: ${e.javaClass.simpleName} ${e.message?.take(120)}")+ return null}}diff --cc base/app/src/main/java/com/music/spotui/automix/TrackDecoder.ktindex ab42905f,f30e33b6..66e4c718--- a/base/app/src/main/java/com/music/spotui/automix/TrackDecoder.kt+++ b/base/app/src/main/java/com/music/spotui/automix/TrackDecoder.kt@@@ -169,76 -158,28 +169,76 @@@ object TrackDecoder}}- /** Random-access adapter over the player's data source: each seek reopens it at the new position. */+ /**+ * Random-access adapter over the player's data source, reading ahead: a thread of its own fetches+ * the bytes after the ones asked (up to [AHEAD_BYTES]) while the codec decodes. Read in turns, the+ * network and the decoder added up (on the phone, 24 MB of a Tidal FLAC: 8.2 s waiting for bytes+ * plus 7.8 s decoding). A read elsewhere (a seek) starts again from there.+ */private class ByteSource(private val uri: Uri, private val cancelled: () -> Boolean) : MediaDataSource() {- private val data = OfflineCrypto.Factory(Graph.app).createDataSource()- private var open = false- private var cursor = 0L+ // Through the media cache for an extension's song: the bytes read for the analysis are the+ // ones the song then plays from, not asked a second time (see ExtStreamCache).+ private val data = com.music.spotui.data.offline.ExtStreamCache.Factory(Graph.app).createDataSource()private var size = -1Lprivate var sizeKnown = false+ /** [data] is open at 0 from [getSize], not read yet: the first read from 0 goes on from it. */+ private var openAtStart = false+ private var ahead: Ahead? = null++ /** Time the decoder waited for bytes (ns), the bytes read, and the reads elsewhere (each starts again). */+ var readNs = 0L; var readBytes = 0L; var restarts = 0+ /**+ * The last bytes handed to the decoder, by their offset: an MP4's extractor goes back a few+ * hundred KB at each fragment (to its samples after the box saying where they are), and each+ * of those went to the network again (39 to 75 times a song, ~0.2 s each).+ */+ private val history = ArrayDeque<Pair<Long, ByteArray>>()+ private var historyBytes = 0L++ private fun remember(start: Long, c: ByteArray) {+ history.addLast(start to c); historyBytes += c.size+ while (historyBytes > HISTORY_BYTES && history.size > 1) historyBytes -= history.removeFirst().second.size+ }++ /** Bytes at [position] (before [until]) from [history], or -1 when they are not there. */+ private fun fromHistory(position: Long, until: Long, buffer: ByteArray, offset: Int, length: Int): Int {+ for (i in history.indices.reversed()) {+ val (start, c) = history[i]+ if (position < start || position >= start + c.size) continue+ val from = (position - start).toInt()+ val n = minOf(length.toLong(), c.size - from.toLong(), until - position).toInt()+ if (n <= 0) return -1+ System.arraycopy(c, from, buffer, offset, n)+ return n+ }+ return -1+ }@Synchronized override fun readAt(position: Long, buffer: ByteArray, offset: Int, length: Int): Int {- if (cancelled()) throw IOException("cancelled")+ if (cancelled()) throw InterruptedException("cancelled")if (length == 0) return 0if (position < 0) return -1- if (!open || cursor != position) {- if (open) runCatching { data.close() }- val remaining = data.open(DataSpec.Builder().setUri(uri).setPosition(position).build())- if (!sizeKnown) { size = if (remaining >= 0) position + remaining else -1; sizeKnown = true }- open = true; cursor = position- }- val n = data.read(buffer, offset, length)- if (n == C.RESULT_END_OF_INPUT) return -1- if (n > 0) cursor += n- return n+ if (sizeKnown && size >= 0 && position >= size) return -1+ val t0 = System.nanoTime()+ try {+ var a = ahead+ // A little back (the extractor going back to a fragment's samples): from memory.+ if (a != null && position < a.pos) {+ val n = fromHistory(position, a.pos, buffer, offset, length)+ if (n > 0) { readBytes += n; return n }+ }+ // A little further on (the extractor skipping a box): taken from the bytes read ahead.+ if (a != null && position > a.pos && position - a.pos <= SKIP_BYTES) a.skip(position - a.pos)+ if (a == null || a.pos != position) {+ if (a != null) restarts+++ a?.close()+ a = Ahead(position, openAtStart && position == 0L).also { ahead = it }+ openAtStart = false+ }+ val n = a.read(buffer, offset, length)+ if (n > 0) readBytes += n+ return n+ } finally { readNs += System.nanoTime() - t0 }}@Synchronized override fun getSize(): Long {diff --cc base/app/src/main/java/com/music/spotui/ui/immersive/pages/ImmersiveSettingsScreen.ktindex 9b8a5539,ef53834b..6396e0ab--- a/base/app/src/main/java/com/music/spotui/ui/immersive/pages/ImmersiveSettingsScreen.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/pages/ImmersiveSettingsScreen.kt@@@ -567,6 -463,16 +567,12 @@@ private fun CrossfadePage(back: () -> U}}if (mode == TransitionMode.AUTOMIX) immersiveGroup("automix", headerRes = R.string.settings_automix_title, footerRes = R.string.settings_automix_detail) {+ row {+ if (app.myspoti.engine.BuildConfig.AUTOMIX_LAB) ImmersiveSwitchRow(stringResource(R.string.settings_automix_segue), checked = automix.segue,+ onChecked = automix::changeSegue, detail = stringResource(R.string.settings_automix_segue_detail))+ ImmersiveSwitchRow(stringResource(R.string.settings_automix_session), checked = automix.sessionDj,+ onChecked = automix::changeSessionDj, detail = stringResource(R.string.settings_automix_session_detail))+ }- row {- ImmersiveSwitchRow(stringResource(R.string.settings_automix_on_next), checked = automix.mixOnNext,- onChecked = automix::changeMixOnNext, detail = stringResource(R.string.settings_automix_on_next_detail))- }row {ImmersiveSwitchRow(stringResource(R.string.settings_automix_album_order), checked = automix.albumOrder,onChecked = automix::changeAlbumOrder, detail = stringResource(R.string.settings_automix_album_order_detail))diff --cc base/app/src/main/java/com/music/spotui/ui/screens/SettingsScreen.ktindex 5ccf9a7f,1d20c9f5..b58e455e--- a/base/app/src/main/java/com/music/spotui/ui/screens/SettingsScreen.kt+++ b/base/app/src/main/java/com/music/spotui/ui/screens/SettingsScreen.kt@@@ -707,6 -598,12 +707,10 @@@ private fun TransitionsRow()com.music.spotui.ui.theme.AppAccent, AppText, AppMuted, Modifier.padding(top = 12.dp))}if (mode == TransitionMode.AUTOMIX) {+ OptionRow(stringResource(R.string.settings_automix_session), stringResource(R.string.settings_automix_session_detail),+ checked = automix.sessionDj, onChecked = automix::changeSessionDj)+ if (app.myspoti.engine.BuildConfig.AUTOMIX_LAB) OptionRow(stringResource(R.string.settings_automix_segue), stringResource(R.string.settings_automix_segue_detail),+ checked = automix.segue, onChecked = automix::changeSegue)- OptionRow(stringResource(R.string.settings_automix_on_next), stringResource(R.string.settings_automix_on_next_detail),- checked = automix.mixOnNext, onChecked = automix::changeMixOnNext)OptionRow(stringResource(R.string.settings_automix_album_order), stringResource(R.string.settings_automix_album_order_detail),checked = automix.albumOrder, onChecked = automix::changeAlbumOrder)OptionRow(stringResource(R.string.settings_automix_podcasts), stringResource(R.string.settings_automix_podcasts_detail),diff --cc base/app/src/main/java/com/music/spotui/ui/screens/SettingsSearch.ktindex 370004cb,00000000..17cb397amode 100644,000000..100644--- a/base/app/src/main/java/com/music/spotui/ui/screens/SettingsSearch.kt+++ b/base/app/src/main/java/com/music/spotui/ui/screens/SettingsSearch.kt@@@ -1,153 -1,0 +1,155 @@@+package com.music.spotui.ui.screens++import app.myspoti.engine.R++/** One row Settings' search finds: its title, its description (0: none) and where it is ([place]). */+internal class SettingsEntry(val title: Int, val detail: Int, val place: String)++/**+ * What the search button of Settings looks through, in both looks: the rows of every page, by+ * their title and description in the app's language. A hit opens the page (Immersive: a+ * `SettingsPage` name) or the tab (Classic: its index, or `transitions` for that page) it is on.+ * Kept by hand with the pages: a row added to a page is added here too.+ */+internal object SettingsSearch {+ val immersive: List<SettingsEntry> = listOf(+ SettingsEntry(R.string.settings_sources_tab, 0, "Sources"),+ SettingsEntry(R.string.settings_transitions_title, R.string.settings_transitions_detail, "Crossfade"),+ SettingsEntry(R.string.accounts_title, 0, "Accounts"),+ SettingsEntry(R.string.extensions_title, R.string.extensions_row_detail, "Sources"),+ SettingsEntry(R.string.settings_autoplay_title, R.string.settings_autoplay_detail, "Playback"),+ SettingsEntry(R.string.settings_release_notify, R.string.settings_release_notify_detail, "Playback"),+ SettingsEntry(R.string.myspoti_shuffle_title, R.string.myspoti_shuffle_detail, "Playback"),+ SettingsEntry(R.string.equalizer_title, R.string.equalizer_settings_detail, "Playback"),+ SettingsEntry(R.string.settings_keep_playing_title, R.string.settings_keep_playing_detail, "Playback"),+ SettingsEntry(R.string.settings_headset_skip_title, R.string.settings_headset_skip_detail, "Playback"),+ SettingsEntry(R.string.settings_connect_mirror_title, R.string.settings_connect_mirror_detail, "Playback"),+ SettingsEntry(R.string.settings_download_sync_title, R.string.settings_download_sync_detail, "Playback"),+ SettingsEntry(R.string.live_radio_settings_title, R.string.live_radio_settings_detail, "Playback"),+ SettingsEntry(R.string.hidden_songs_title, R.string.hidden_songs_detail, "Playback"),+ SettingsEntry(R.string.lyrics_word_sync_title, 0, "Lyrics"),+ SettingsEntry(R.string.lyrics_extra_title, 0, "Lyrics"),+ SettingsEntry(R.string.settings_lyrics_keep_awake_title, R.string.settings_lyrics_keep_awake_detail, "Lyrics"),+ SettingsEntry(R.string.lyrics_romanization, R.string.settings_lyrics_romanization_detail, "Lyrics"),+ SettingsEntry(R.string.lyrics_translation_title, R.string.lyrics_translation_detail, "Lyrics"),++ SettingsEntry(R.string.settings_automix_session, R.string.settings_automix_session_detail, "Crossfade"),+ SettingsEntry(R.string.settings_automix_album_order, R.string.settings_automix_album_order_detail, "Crossfade"),+ SettingsEntry(R.string.settings_automix_podcasts, R.string.settings_automix_podcasts_detail, "Crossfade"),+ SettingsEntry(R.string.settings_automix_harmonic, R.string.settings_automix_harmonic_detail, "Crossfade"),+ SettingsEntry(R.string.settings_automix_eq, R.string.settings_automix_eq_detail, "Crossfade"),+ SettingsEntry(R.string.settings_automix_show, R.string.settings_automix_show_detail, "Crossfade"),+ SettingsEntry(R.string.settings_automix_mobile_data, R.string.settings_automix_mobile_data_detail, "Crossfade"),+ SettingsEntry(R.string.settings_automix_cache, 0, "Crossfade"),+ SettingsEntry(R.string.downloads_source_row_title, 0, "Downloads"),+ SettingsEntry(R.string.settings_download_lyrics_title, R.string.settings_download_lyrics_detail, "Downloads"),+ SettingsEntry(R.string.settings_storage_clear_cache, 0, "Storage"),+ SettingsEntry(R.string.settings_item_remove_downloads_title, 0, "Storage"),+ SettingsEntry(R.string.energy_saver_title, R.string.energy_saver_summary, "Data"),+ SettingsEntry(R.string.data_saver_title, R.string.data_saver_summary, "Data"),+ SettingsEntry(R.string.background_playback_title, 0, "Data"),+ SettingsEntry(R.string.settings_look_title, 0, "Display"),+ SettingsEntry(R.string.settings_dynamic_color_title, R.string.settings_dynamic_color_detail, "Display"),+ SettingsEntry(R.string.settings_system_font_title, R.string.settings_system_font_detail, "Display"),+ SettingsEntry(R.string.settings_liquid_glass_title, R.string.settings_liquid_glass_detail, "Display"),+ SettingsEntry(R.string.settings_amoled_theme, R.string.settings_amoled_theme_subtitle, "Display"),+ SettingsEntry(R.string.settings_item_canvas_title, 0, "Display"),+ SettingsEntry(R.string.canvas_wifi_only, R.string.canvas_wifi_only_detail, "Display"),+ SettingsEntry(R.string.settings_music_video_title, R.string.settings_music_video_detail, "Display"),+ SettingsEntry(R.string.settings_song_pip_title, R.string.settings_song_pip_detail, "Display"),+ SettingsEntry(R.string.settings_hide_dj_title, R.string.settings_hide_dj_detail, "Display"),+ SettingsEntry(R.string.settings_player_lyrics_card_title, R.string.settings_player_lyrics_card_detail, "Display"),+ SettingsEntry(R.string.settings_player_source_title, R.string.settings_player_source_detail, "Display"),+ SettingsEntry(R.string.settings_player_capsule_title, R.string.settings_player_capsule_detail, "Display"),+ SettingsEntry(R.string.settings_player_modes_title, R.string.settings_player_modes_detail, "Display"),+ SettingsEntry(R.string.settings_player_volume_title, R.string.settings_player_volume_detail, "Display"),+ SettingsEntry(R.string.settings_rotation_title, 0, "Display"),+ SettingsEntry(R.string.settings_item_app_language_title, 0, "Display"),+ SettingsEntry(R.string.settings_auto_update_title, R.string.settings_auto_update_detail, "App"),+ SettingsEntry(R.string.restart_player_title, R.string.restart_player_detail, "App"),+ SettingsEntry(R.string.diagnostic_export_title, R.string.diagnostic_export_detail, "App"),+ SettingsEntry(R.string.settings_section_playback, 0, "Playback"),+ SettingsEntry(R.string.settings_section_downloads, 0, "Downloads"),+ SettingsEntry(R.string.settings_section_lyrics, 0, "Lyrics"),+ SettingsEntry(R.string.settings_section_display, 0, "Display"),+ SettingsEntry(R.string.settings_section_data, 0, "Data"),+ SettingsEntry(R.string.settings_section_storage, 0, "Storage"),+ SettingsEntry(R.string.settings_section_app, 0, "App"),+ SettingsEntry(R.string.supporter_accent, 0, "Display"),+ )++ val classic: List<SettingsEntry> = listOf(+ SettingsEntry(R.string.settings_autoplay_title, R.string.settings_autoplay_detail, "0"),+ SettingsEntry(R.string.settings_release_notify, R.string.settings_release_notify_detail, "0"),+ SettingsEntry(R.string.myspoti_shuffle_title, R.string.myspoti_shuffle_detail, "0"),+ SettingsEntry(R.string.settings_keep_playing_title, R.string.settings_keep_playing_detail, "0"),+ SettingsEntry(R.string.settings_headset_skip_title, R.string.settings_headset_skip_detail, "0"),+ SettingsEntry(R.string.settings_connect_mirror_title, R.string.settings_connect_mirror_detail, "0"),+ SettingsEntry(R.string.settings_download_sync_title, R.string.settings_download_sync_detail, "0"),+ SettingsEntry(R.string.live_radio_settings_title, R.string.live_radio_settings_detail, "0"),+ SettingsEntry(R.string.energy_saver_title, R.string.energy_saver_summary, "0"),+ SettingsEntry(R.string.data_saver_title, R.string.data_saver_summary, "0"),+ SettingsEntry(R.string.background_playback_title, 0, "0"),+ SettingsEntry(R.string.lyrics_word_sync_title, 0, "2"),+ SettingsEntry(R.string.lyrics_extra_title, R.string.lyrics_extra_summary, "2"),+ SettingsEntry(R.string.settings_lyrics_keep_awake_title, R.string.settings_lyrics_keep_awake_detail, "2"),+ SettingsEntry(R.string.lyrics_romanization, R.string.settings_lyrics_romanization_detail, "2"),+ SettingsEntry(R.string.settings_download_lyrics_title, R.string.settings_download_lyrics_detail, "3"),+ SettingsEntry(R.string.settings_amoled_theme, R.string.settings_amoled_theme_subtitle, "4"),+ SettingsEntry(R.string.settings_item_canvas_title, 0, "4"),+ SettingsEntry(R.string.canvas_wifi_only, R.string.canvas_wifi_only_detail, "4"),+ SettingsEntry(R.string.settings_music_video_title, R.string.settings_music_video_detail, "4"),+ SettingsEntry(R.string.settings_player_lyrics_card_title, R.string.settings_player_lyrics_card_detail, "4"),+ SettingsEntry(R.string.settings_player_source_title, R.string.settings_player_source_detail, "4"),+ SettingsEntry(R.string.settings_solid_nav_title, R.string.settings_solid_nav_detail, "4"),+ SettingsEntry(R.string.settings_song_pip_title, R.string.settings_song_pip_detail, "4"),+ SettingsEntry(R.string.settings_hide_dj_title, R.string.settings_hide_dj_detail, "4"),+ SettingsEntry(R.string.settings_dynamic_color_title, R.string.settings_dynamic_color_detail, "4"),+ SettingsEntry(R.string.settings_system_font_title, R.string.settings_system_font_detail, "4"),+ SettingsEntry(R.string.settings_auto_update_title, R.string.settings_auto_update_detail, "5"),+ SettingsEntry(R.string.settings_section_playback, 0, "0"),+ SettingsEntry(R.string.settings_sources_tab, 0, "1"),+ SettingsEntry(R.string.extensions_title, 0, "1"),+ SettingsEntry(R.string.settings_section_lyrics, 0, "2"),+ SettingsEntry(R.string.settings_section_downloads, 0, "3"),+ SettingsEntry(R.string.settings_section_storage, 0, "3"),+ SettingsEntry(R.string.settings_tab_appearance, 0, "4"),+ SettingsEntry(R.string.settings_section_display, 0, "4"),+ SettingsEntry(R.string.supporter_accent, 0, "4"),+ SettingsEntry(R.string.settings_look_title, 0, "4"),+ SettingsEntry(R.string.settings_rotation_title, 0, "4"),+ SettingsEntry(R.string.settings_item_app_language_title, 0, "4"),+ SettingsEntry(R.string.settings_tab_about, 0, "5"),+ SettingsEntry(R.string.settings_section_app, 0, "5"),+ SettingsEntry(R.string.accounts_title, 0, "6"),+ SettingsEntry(R.string.settings_transitions_title, 0, "transitions"),+ SettingsEntry(R.string.equalizer_title, 0, "0"),+ SettingsEntry(R.string.settings_section_data, 0, "0"),++ SettingsEntry(R.string.settings_automix_session, R.string.settings_automix_session_detail, "transitions"),+ SettingsEntry(R.string.settings_automix_album_order, R.string.settings_automix_album_order_detail, "transitions"),+ SettingsEntry(R.string.settings_automix_podcasts, R.string.settings_automix_podcasts_detail, "transitions"),+ SettingsEntry(R.string.settings_automix_harmonic, R.string.settings_automix_harmonic_detail, "transitions"),+ SettingsEntry(R.string.settings_automix_eq, R.string.settings_automix_eq_detail, "transitions"),+ SettingsEntry(R.string.settings_automix_show, R.string.settings_automix_show_detail, "transitions"),+ SettingsEntry(R.string.settings_automix_mobile_data, R.string.settings_automix_mobile_data_detail, "transitions"),+ SettingsEntry(R.string.settings_automix_cache, 0, "transitions"),+ )++ /** Lower case, without accents, so "lecture" finds "Lecture" and "ecran" finds "écran". */+ fun normalize(text: String): String =+ java.text.Normalizer.normalize(text.lowercase(), java.text.Normalizer.Form.NFD).replace(Regex("\\p{Mn}+"), "")++ /** Every word of [query] is in the title or the description. */+ fun matches(query: String, title: String, detail: String): Boolean {+ val words = normalize(query).split(Regex("\\s+")).filter { it.isNotEmpty() }+ if (words.isEmpty()) return false+ val text = normalize("$title $detail")+ return words.all { it in text }+ }++ /** The entries [query] finds, titles first, each title once; [text] reads a string resource. */+ fun search(entries: List<SettingsEntry>, query: String, text: (Int) -> String): List<SettingsEntry> {+ val hits = entries.filter { matches(query, text(it.title), if (it.detail != 0) text(it.detail) else "") }+ val q = normalize(query.trim())+ return hits.sortedBy { if (normalize(text(it.title)).contains(q)) 0 else 1 }.distinctBy { text(it.title) }+ }+}diff --cc base/automix/src/main/kotlin/app/myspoti/automix/MixPlanner.ktindex 6a266134,f0d06197..67d86710--- a/base/automix/src/main/kotlin/app/myspoti/automix/MixPlanner.kt+++ b/base/automix/src/main/kotlin/app/myspoti/automix/MixPlanner.kt@@@ -90,53 -94,6 +94,53 @@@ object MixPlannerif (s.style == MixPlan.Style.FADE) "skip: fade" else "skip: fade (no beat grid here)")}+ /**+ * Next with the real mix: A leaves on one of its downbeats within [window] s of [now] + [lead] (a+ * phrase start preferred), B comes in at its best entry (its first downbeat or a phrase of its+ * intro, two voices avoided), beat-matched over 4 bars (2 when a bar is long) with the bass handed+ * over halfway; tempos too far apart: a cut on A's downbeat onto that entry. Null without both+ * analyses and grids there: [planSkip] then.+ */+ /** The longest a skip's cut waits for A's phrase. */+ private const val CUT_WAIT_SEC = 2.0++ fun planSkipFull(a: TrackAnalysis?, b: TrackAnalysis?, now: Double, lead: Double, s: Settings = Settings(), window: Double = 4.0): MixPlan? {+ if (a == null || b == null || s.style == MixPlan.Style.FADE) return null+ val from = now + lead+ val (ga, downA) = gridAt(a, from) ?: return null+ val gb = b.head?.takeIf { !b.headDown.isNaN() } ?: return null+ val barA = 4 * ga.period+ var exit = firstDown(ga, downA, from)+ var why = "A's next downbeat"+ var t = exit+ while (t <= from + window && t < ga.last - 2 * ga.period) {+ val bar = a.barAt(t + 0.05)+ if (bar >= 0 && a.phrasePos(bar) == 0) { exit = t; why = "A's phrase"; break }+ t += barA+ }- val entries = entryCues(b, gb)++ val entries = entryCues(b, summary(b), gb)+ val m = tempoMatch(ga.bpm, gb.bpm)+ val synced = abs(m.speed - 1) <= s.maxStretch+ if (s.style == MixPlan.Style.BLEND && synced) {+ val bars = if (4 * barA <= 9.0) 4 else 2+ val len = bars * barA+ if (exit + len <= a.contentEnd) {+ val n = entries.filter { it.time + len * m.speed < b.contentEnd - 10 }- .maxByOrNull { it.score - voiceClash(a, exit, exit + len, b, it.time, it.time + len * m.speed) * bars / 8.0 }++ .maxByOrNull { it.score - vocalOverlap(a, exit, exit + len, b, it.time, it.time + len * m.speed) * bars / 8.0 }+ if (n != null) return MixPlan(MixPlan.Style.BLEND, exit, n.time, len, m.speed, bars * 4, 0.5, 1.0 / (bars * 4), matchGain(a, b),+ restore(m.speed, gb.period), matchA = matchGainA(a, b),+ note = String.format("skip (real mix): %d bars from %s at %.1f, %s, %.1f→%.1f BPM", bars, why, exit, n.why, ga.bpm, gb.bpm))+ }+ }+ val entry = entries.maxBy { it.score }+ val speed = if (synced) m.speed else 1.0+ // A cut is over at once: a phrase is worth a short wait only, after that A's next downbeat.+ if (exit > from + CUT_WAIT_SEC) { exit = firstDown(ga, downA, from); why = "A's next downbeat" }+ return MixPlan(MixPlan.Style.CUT, exit, entry.time, 2 * ga.period, speed, 2, 0.0, 0.5, matchGain(a, b),+ if (synced) restore(speed, gb.period) else 0.0, String.format("skip (real mix): cut on %s at %.1f onto %s", why, exit, entry.why))+ }++ /** The grid (and one of its downbeats) holding at A's time [t]: the tail's near the end, the head's near the start, the one grid of a steady song. */private fun gridAt(a: TrackAnalysis, t: Double): Pair<Grid, Double>? {val tail = a.tail?.takeIf { !a.tailDown.isNaN() && t >= max(it.first, a.contentEnd - Analyzer.TAIL_SEC) && t < it.last }if (tail != null) return tail to a.tailDown