Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
AutoMix: filtered fade instead of a one-second cut between distant tempos, stretch up to 12/16 %, long mixes refused only on a real overlap of two voices, Session DJ keeps A's last loud section, seek bar no longer pulses during a mix
kota-zo1b07076aa1f2
diff --git a/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt b/base/app/src/main/java/com/music/spotui/automix/AutoMix.ktindex 1c7cc2c3..c18acb87 100644--- a/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt+++ b/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt@@ -113,7 +113,7 @@ object AutoMix {* when no longer one fits the songs), the upper one a limit. A plain fade lasts 4, 8 or 14 s.*/fun settings() = MixPlanner.Settings(- maxStretch = doubleArrayOf(0.04, 0.08, 0.12)[tempoRange],+ maxStretch = doubleArrayOf(0.04, 0.12, 0.16)[tempoRange],maxSec = if (mixLength == 2) 90.0 else 48.0,lengthBias = mixLength - 1,style = arrayOf(MixPlan.Style.BLEND, MixPlan.Style.CUT, MixPlan.Style.FADE)[style],@@ -121,6 +121,7 @@ object AutoMix {maxBars = intArrayOf(8, 16, 32)[mixLength],keyWeight = if (harmonic) 2.0 else 0.0,smoothSec = doubleArrayOf(4.0, 8.0, 14.0)[mixLength],+ filterSec = doubleArrayOf(6.0, 10.0, 14.0)[mixLength],djMode = sessionDj,)diff --git a/base/app/src/main/java/com/music/spotui/ui/components/AutoMixVisuals.kt b/base/app/src/main/java/com/music/spotui/ui/components/AutoMixVisuals.ktindex 0ea2d221..6522e0bd 100644--- a/base/app/src/main/java/com/music/spotui/ui/components/AutoMixVisuals.kt+++ b/base/app/src/main/java/com/music/spotui/ui/components/AutoMixVisuals.kt@@ -208,16 +208,13 @@ fun Modifier.mixBeat(pulse: MixPulse?, amount: Float = 0.035f): Modifier =/*** Draws the mix's stretch on a seek bar's track (the canvas holding the bar, [y] its middle): the- * part still ahead in [color] at half strength, the part played in full, thicker on the beat.+ * part still ahead in [color] at half strength, the part played in full. Still: the bar does not+ * beat with the music (the cover and the player's animation do).*/-fun DrawScope.drawMixZone(zone: ClosedFloatingPointRange<Float>, played: Float, y: Float, thickness: Float, color: Color, pulse: Float) {+fun DrawScope.drawMixZone(zone: ClosedFloatingPointRange<Float>, played: Float, y: Float, thickness: Float, color: Color) {val x0 = size.width * zone.start; val x1 = size.width * zone.endInclusive- val h = thickness * (1f + 0.8f * pulse)+ val h = thicknessval radius = CornerRadius(h / 2)- if (pulse > 0f) {- val g = h * 2.6f- drawRoundRect(color.copy(alpha = 0.22f * pulse), Offset(x0 - g / 4, y - g / 2), Size(x1 - x0 + g / 2, g), CornerRadius(g / 2))- }drawRoundRect(color.copy(alpha = 0.45f), Offset(x0, y - h / 2), Size(x1 - x0, h), radius)val px = (size.width * played).coerceIn(x0, x1)if (px > x0) drawRoundRect(color, Offset(x0, y - h / 2), Size(px - x0, h), radius)diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.ktindex 00a8d341..db2882e5 100644--- a/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt@@ -141,7 +141,6 @@ internal fun PlayerScrubber(// AutoMix: the mix's stretch in the accent from the moment it is planned, beating while it plays.mixZone = { state.mixCue?.zoneOn(state.durationMs, incomingShown = state.blend?.outgoingWords == false) },mixColor = com.music.spotui.ui.immersive.Immersive.Accent,- mixPulse = { state.mixPulse?.level() ?: 0f },)ScrubTimes(frame, scrub, state)com.music.spotui.ui.components.PlaybackSpeedNote(LocalPlayerTint.current.copy(alpha = 0.8f), com.music.spotui.ui.immersive.Immersive.Accent,diff --git a/base/app/src/main/java/com/music/spotui/ui/look/ThinSlider.kt b/base/app/src/main/java/com/music/spotui/ui/look/ThinSlider.ktindex ddc278de..08ab16d0 100644--- a/base/app/src/main/java/com/music/spotui/ui/look/ThinSlider.kt+++ b/base/app/src/main/java/com/music/spotui/ui/look/ThinSlider.kt@@ -108,7 +108,6 @@ fun ThinSlider(mixZone: () -> ClosedFloatingPointRange<Float>? = { null },mixColor: Color = Color.White,/** The mix's beat, 0..1, read in the draw: the stretch thickens and glows with it. */- mixPulse: () -> Float = { 0f },) {var dragging by remember { mutableStateOf(false) }val height by animateDpAsState(@@ -201,7 +200,7 @@ fun ThinSlider()}mixZone()?.let { z ->- drawMixZone(z, value().coerceIn(0f, 1f) * fillFactor, size.height / 2f, size.height, mixColor, mixPulse())+ drawMixZone(z, value().coerceIn(0f, 1f) * fillFactor, size.height / 2f, size.height, mixColor)}}// Composed only while loading. The infinite animation therefore costs nodiff --git a/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.ktindex 2fbac9ca..89c6abad 100644--- a/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt+++ b/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt@@ -633,7 +633,6 @@ fun PlayerScreen(navController: NavController) {.padding(horizontal = 24.dp).padding(top = 11.dp),mixZone = { mixCue?.zoneOn(duration, incomingShown = blend != null && outgoing == null) },- mixPulse = { mixPulse?.level() ?: 0f },)Row(modifier = Modifier@@ -1166,7 +1165,6 @@ fun SpotifySeekBar(/** An AutoMix mix's stretch of the bar (fractions), read in the draw; null with none. */mixZone: () -> ClosedFloatingPointRange<Float>? = { null },/** The mix's beat, 0..1, read in the draw. */- mixPulse: () -> Float = { 0f },) {var widthPx by remember { mutableStateOf(1f) }val seekDescription = stringResource(R.string.playback_seek_description)@@ -1216,7 +1214,7 @@ fun SpotifySeekBar(val f = fraction().coerceIn(0f, 1f)drawLine(Color.White.copy(alpha = 0.3f), androidx.compose.ui.geometry.Offset(0f, y), androidx.compose.ui.geometry.Offset(size.width, y), track, androidx.compose.ui.graphics.StrokeCap.Round)drawLine(Color.White, androidx.compose.ui.geometry.Offset(0f, y), androidx.compose.ui.geometry.Offset(size.width * f, y), track, androidx.compose.ui.graphics.StrokeCap.Round)- mixZone()?.let { drawMixZone(it, f, y, track * 1.5f, com.music.spotui.ui.theme.AppAccent, mixPulse()) }+ mixZone()?.let { drawMixZone(it, f, y, track * 1.5f, com.music.spotui.ui.theme.AppAccent) }drawCircle(Color.White, radius = 5.dp.toPx(), center = androidx.compose.ui.geometry.Offset(size.width * f, y))}}diff --git a/base/app/src/main/res/values-de/myspoti_strings.xml b/base/app/src/main/res/values-de/myspoti_strings.xmlindex 6214e60b..88dc3cf8 100644--- a/base/app/src/main/res/values-de/myspoti_strings.xml+++ b/base/app/src/main/res/values-de/myspoti_strings.xml@@ -712,10 +712,10 @@<string name="settings_automix_length_auto">Ausgewogen</string><string name="settings_automix_length_long">Lang</string><string name="settings_automix_tempo">Tempoangleichung</string>- <string name="settings_automix_tempo_detail">Wie stark das Tempo des nächsten Songs angepasst werden darf, um im Takt zu landen. Darüber hinaus wechseln die Songs mit einem Schnitt im Takt.</string>+ <string name="settings_automix_tempo_detail">Wie stark das Tempo des nächsten Songs angepasst werden darf, um im Takt zu landen. Darüber hinaus wechseln die Songs mit einer gefilterten Überblendung: Der nächste kommt ohne Bass, der auf seiner Eins übernimmt.</string><string name="settings_automix_tempo_strict">Streng (4 %)</string>- <string name="settings_automix_tempo_normal">Normal (8 %)</string>- <string name="settings_automix_tempo_wide">Weit (12 %)</string>+ <string name="settings_automix_tempo_normal">Normal (12 %)</string>+ <string name="settings_automix_tempo_wide">Weit (16 %)</string><string name="settings_automix_eq">DJ-EQ</string><string name="settings_automix_eq_detail">Bass-Tausch und Filter während des Mixes. Aus, bewegen sich nur die Lautstärken.</string><string name="settings_automix_pulse">Player-Animation</string>diff --git a/base/app/src/main/res/values-el/myspoti_strings.xml b/base/app/src/main/res/values-el/myspoti_strings.xmlindex 982950bf..30289135 100644--- a/base/app/src/main/res/values-el/myspoti_strings.xml+++ b/base/app/src/main/res/values-el/myspoti_strings.xml@@ -712,10 +712,10 @@<string name="settings_automix_length_auto">Ισορροπημένη</string><string name="settings_automix_length_long">Μεγάλη</string><string name="settings_automix_tempo">Ταίριασμα τέμπο</string>- <string name="settings_automix_tempo_detail">Πόσο μπορεί να αλλάξει το τέμπο του επόμενου τραγουδιού για να πέσει στον ρυθμό. Πέρα από αυτό, τα τραγούδια αλλάζουν με κόψιμο στον ρυθμό.</string>+ <string name="settings_automix_tempo_detail">Πόσο μπορεί να αλλάξει το τέμπο του επόμενου τραγουδιού για να πέσει στον ρυθμό. Πέρα από αυτό, τα τραγούδια αλλάζουν με φιλτραρισμένο σβήσιμο: το επόμενο μπαίνει χωρίς μπάσα, που αναλαμβάνουν στον πρώτο του χρόνο.</string><string name="settings_automix_tempo_strict">Αυστηρό (4 %)</string>- <string name="settings_automix_tempo_normal">Κανονικό (8 %)</string>- <string name="settings_automix_tempo_wide">Ευρύ (12 %)</string>+ <string name="settings_automix_tempo_normal">Κανονικό (12 %)</string>+ <string name="settings_automix_tempo_wide">Ευρύ (16 %)</string><string name="settings_automix_eq">DJ EQ</string><string name="settings_automix_eq_detail">Εναλλαγή μπάσων και φίλτρα κατά τη μίξη. Απενεργοποιημένο, κινούνται μόνο οι εντάσεις.</string><string name="settings_automix_pulse">Κίνηση προγράμματος αναπαραγωγής</string>diff --git a/base/app/src/main/res/values-es/myspoti_strings.xml b/base/app/src/main/res/values-es/myspoti_strings.xmlindex 5b55b194..367181ec 100644--- a/base/app/src/main/res/values-es/myspoti_strings.xml+++ b/base/app/src/main/res/values-es/myspoti_strings.xml@@ -712,10 +712,10 @@<string name="settings_automix_length_auto">Equilibrada</string><string name="settings_automix_length_long">Larga</string><string name="settings_automix_tempo">Ajuste de tempo</string>- <string name="settings_automix_tempo_detail">Cuánto puede cambiar el tempo de la siguiente canción para caer a tiempo. Más allá, las canciones cambian con un corte a tiempo.</string>+ <string name="settings_automix_tempo_detail">Cuánto puede cambiar el tempo de la siguiente canción para caer a tiempo. Más allá, las canciones cambian con un fundido filtrado: la siguiente entra sin graves, que toman el relevo en su primer tiempo.</string><string name="settings_automix_tempo_strict">Estricto (4 %)</string>- <string name="settings_automix_tempo_normal">Normal (8 %)</string>- <string name="settings_automix_tempo_wide">Amplio (12 %)</string>+ <string name="settings_automix_tempo_normal">Normal (12 %)</string>+ <string name="settings_automix_tempo_wide">Amplio (16 %)</string><string name="settings_automix_eq">EQ de DJ</string><string name="settings_automix_eq_detail">Intercambio de graves y filtros durante la mezcla. Desactivado, solo se mueven los volúmenes.</string><string name="settings_automix_pulse">Animación del reproductor</string>diff --git a/base/app/src/main/res/values-fr/myspoti_strings.xml b/base/app/src/main/res/values-fr/myspoti_strings.xmlindex 69de704b..95b7a47d 100644--- a/base/app/src/main/res/values-fr/myspoti_strings.xml+++ b/base/app/src/main/res/values-fr/myspoti_strings.xml@@ -717,10 +717,10 @@<string name="settings_automix_length_auto">Équilibrée</string><string name="settings_automix_length_long">Longue</string><string name="settings_automix_tempo">Calage du tempo</string>- <string name="settings_automix_tempo_detail">Jusqu\'où le tempo du morceau suivant peut être modifié pour tomber sur le temps. Au-delà, les morceaux changent par une coupe sur le temps.</string>+ <string name="settings_automix_tempo_detail">Jusqu\'où le tempo du morceau suivant peut être modifié pour tomber sur le temps. Au-delà, les morceaux changent par un fondu filtré : le suivant arrive sans ses basses, qui prennent le relais sur son premier temps.</string><string name="settings_automix_tempo_strict">Strict (4 %)</string>- <string name="settings_automix_tempo_normal">Normal (8 %)</string>- <string name="settings_automix_tempo_wide">Large (12 %)</string>+ <string name="settings_automix_tempo_normal">Normal (12 %)</string>+ <string name="settings_automix_tempo_wide">Large (16 %)</string><string name="settings_automix_eq">EQ DJ</string><string name="settings_automix_eq_detail">Échange des basses et filtres pendant le mix. Désactivé, seuls les volumes bougent.</string><string name="settings_automix_pulse">Animation du lecteur</string>diff --git a/base/app/src/main/res/values-it/myspoti_strings.xml b/base/app/src/main/res/values-it/myspoti_strings.xmlindex 44e425ea..2743d5df 100644--- a/base/app/src/main/res/values-it/myspoti_strings.xml+++ b/base/app/src/main/res/values-it/myspoti_strings.xml@@ -712,10 +712,10 @@<string name="settings_automix_length_auto">Bilanciata</string><string name="settings_automix_length_long">Lunga</string><string name="settings_automix_tempo">Allineamento del tempo</string>- <string name="settings_automix_tempo_detail">Quanto può cambiare il tempo del brano successivo per cadere a tempo. Oltre, i brani cambiano con un taglio a tempo.</string>+ <string name="settings_automix_tempo_detail">Quanto può cambiare il tempo del brano successivo per cadere a tempo. Oltre, i brani cambiano con una dissolvenza filtrata: il successivo entra senza bassi, che subentrano sul suo primo tempo.</string><string name="settings_automix_tempo_strict">Rigido (4 %)</string>- <string name="settings_automix_tempo_normal">Normale (8 %)</string>- <string name="settings_automix_tempo_wide">Ampio (12 %)</string>+ <string name="settings_automix_tempo_normal">Normale (12 %)</string>+ <string name="settings_automix_tempo_wide">Ampio (16 %)</string><string name="settings_automix_eq">EQ da DJ</string><string name="settings_automix_eq_detail">Scambio dei bassi e filtri durante il mix. Disattivato, si muovono solo i volumi.</string><string name="settings_automix_pulse">Animazione del player</string>diff --git a/base/app/src/main/res/values-pl/myspoti_strings.xml b/base/app/src/main/res/values-pl/myspoti_strings.xmlindex 10896f10..f289574d 100644--- a/base/app/src/main/res/values-pl/myspoti_strings.xml+++ b/base/app/src/main/res/values-pl/myspoti_strings.xml@@ -727,10 +727,10 @@<string name="settings_automix_length_auto">Zrównoważona</string><string name="settings_automix_length_long">Długa</string><string name="settings_automix_tempo">Dopasowanie tempa</string>- <string name="settings_automix_tempo_detail">Jak bardzo można zmienić tempo następnego utworu, żeby trafić w rytm. Powyżej utwory zmieniają się cięciem w rytm.</string>+ <string name="settings_automix_tempo_detail">Jak bardzo można zmienić tempo następnego utworu, żeby trafić w rytm. Powyżej utwory zmieniają się filtrowanym przejściem: następny wchodzi bez basu, który przejmuje na jego pierwszą miarę.</string><string name="settings_automix_tempo_strict">Ścisłe (4 %)</string>- <string name="settings_automix_tempo_normal">Normalne (8 %)</string>- <string name="settings_automix_tempo_wide">Szerokie (12 %)</string>+ <string name="settings_automix_tempo_normal">Normalne (12 %)</string>+ <string name="settings_automix_tempo_wide">Szerokie (16 %)</string><string name="settings_automix_eq">EQ DJ</string><string name="settings_automix_eq_detail">Zamiana basu i filtry podczas miksu. Wyłączone: zmieniają się tylko głośności.</string><string name="settings_automix_pulse">Animacja odtwarzacza</string>diff --git a/base/app/src/main/res/values-pt-rBR/myspoti_strings.xml b/base/app/src/main/res/values-pt-rBR/myspoti_strings.xmlindex 1422e82b..8505692d 100644--- a/base/app/src/main/res/values-pt-rBR/myspoti_strings.xml+++ b/base/app/src/main/res/values-pt-rBR/myspoti_strings.xml@@ -691,10 +691,10 @@<string name="settings_automix_length_auto">Equilibrada</string><string name="settings_automix_length_long">Longa</string><string name="settings_automix_tempo">Ajuste do andamento</string>- <string name="settings_automix_tempo_detail">Quanto o andamento da próxima música pode mudar para cair no tempo. Além disso, as músicas trocam com um corte no tempo.</string>+ <string name="settings_automix_tempo_detail">Quanto o andamento da próxima música pode mudar para cair no tempo. Além disso, as músicas trocam com um fade filtrado: a próxima entra sem graves, que assumem no seu primeiro tempo.</string><string name="settings_automix_tempo_strict">Estrito (4 %)</string>- <string name="settings_automix_tempo_normal">Normal (8 %)</string>- <string name="settings_automix_tempo_wide">Amplo (12 %)</string>+ <string name="settings_automix_tempo_normal">Normal (12 %)</string>+ <string name="settings_automix_tempo_wide">Amplo (16 %)</string><string name="settings_automix_eq">EQ de DJ</string><string name="settings_automix_eq_detail">Troca de graves e filtros durante a mixagem. Desligado, só os volumes mudam.</string><string name="settings_automix_pulse">Animação do player</string>diff --git a/base/app/src/main/res/values-pt-rPT/myspoti_strings.xml b/base/app/src/main/res/values-pt-rPT/myspoti_strings.xmlindex 071e78c5..8c680e4e 100644--- a/base/app/src/main/res/values-pt-rPT/myspoti_strings.xml+++ b/base/app/src/main/res/values-pt-rPT/myspoti_strings.xml@@ -658,10 +658,10 @@<string name="settings_automix_length_auto">Equilibrada</string><string name="settings_automix_length_long">Longa</string><string name="settings_automix_tempo">Ajuste do andamento</string>- <string name="settings_automix_tempo_detail">Quanto o andamento da música seguinte pode mudar para cair no tempo. Além disso, as músicas mudam com um corte no tempo.</string>+ <string name="settings_automix_tempo_detail">Quanto o andamento da música seguinte pode mudar para cair no tempo. Além disso, as músicas mudam com um fade filtrado: a seguinte entra sem graves, que assumem no seu primeiro tempo.</string><string name="settings_automix_tempo_strict">Estrito (4 %)</string>- <string name="settings_automix_tempo_normal">Normal (8 %)</string>- <string name="settings_automix_tempo_wide">Amplo (12 %)</string>+ <string name="settings_automix_tempo_normal">Normal (12 %)</string>+ <string name="settings_automix_tempo_wide">Amplo (16 %)</string><string name="settings_automix_eq">EQ de DJ</string><string name="settings_automix_eq_detail">Troca de graves e filtros durante a mistura. Desligado, só os volumes mudam.</string><string name="settings_automix_pulse">Animação do leitor</string>diff --git a/base/app/src/main/res/values-pt/myspoti_strings.xml b/base/app/src/main/res/values-pt/myspoti_strings.xmlindex 9ef243c7..bf717492 100644--- a/base/app/src/main/res/values-pt/myspoti_strings.xml+++ b/base/app/src/main/res/values-pt/myspoti_strings.xml@@ -712,10 +712,10 @@<string name="settings_automix_length_auto">Equilibrada</string><string name="settings_automix_length_long">Longa</string><string name="settings_automix_tempo">Ajuste do andamento</string>- <string name="settings_automix_tempo_detail">Quanto o andamento da música seguinte pode mudar para cair no tempo. Além disso, as músicas mudam com um corte no tempo.</string>+ <string name="settings_automix_tempo_detail">Quanto o andamento da música seguinte pode mudar para cair no tempo. Além disso, as músicas mudam com um fade filtrado: a seguinte entra sem graves, que assumem no seu primeiro tempo.</string><string name="settings_automix_tempo_strict">Estrito (4 %)</string>- <string name="settings_automix_tempo_normal">Normal (8 %)</string>- <string name="settings_automix_tempo_wide">Amplo (12 %)</string>+ <string name="settings_automix_tempo_normal">Normal (12 %)</string>+ <string name="settings_automix_tempo_wide">Amplo (16 %)</string><string name="settings_automix_eq">EQ de DJ</string><string name="settings_automix_eq_detail">Troca de graves e filtros durante a mistura. Desligado, só os volumes mudam.</string><string name="settings_automix_pulse">Animação do leitor</string>diff --git a/base/app/src/main/res/values-ru/myspoti_strings.xml b/base/app/src/main/res/values-ru/myspoti_strings.xmlindex 78463e25..b4214b87 100644--- a/base/app/src/main/res/values-ru/myspoti_strings.xml+++ b/base/app/src/main/res/values-ru/myspoti_strings.xml@@ -727,10 +727,10 @@<string name="settings_automix_length_auto">Сбалансированная</string><string name="settings_automix_length_long">Длинная</string><string name="settings_automix_tempo">Подгонка темпа</string>- <string name="settings_automix_tempo_detail">Насколько можно изменить темп следующего трека, чтобы попасть в такт. Сверх этого треки сменяются склейкой в такт.</string>+ <string name="settings_automix_tempo_detail">Насколько можно изменить темп следующего трека, чтобы попасть в такт. Сверх этого треки сменяются фильтрованным переходом: следующий входит без баса, который вступает на его сильную долю.</string><string name="settings_automix_tempo_strict">Строгая (4 %)</string>- <string name="settings_automix_tempo_normal">Обычная (8 %)</string>- <string name="settings_automix_tempo_wide">Широкая (12 %)</string>+ <string name="settings_automix_tempo_normal">Обычная (12 %)</string>+ <string name="settings_automix_tempo_wide">Широкая (16 %)</string><string name="settings_automix_eq">DJ-эквалайзер</string><string name="settings_automix_eq_detail">Смена баса и фильтры во время сведения. Если выключено, меняется только громкость.</string><string name="settings_automix_pulse">Анимация плеера</string>diff --git a/base/app/src/main/res/values-zh/myspoti_strings.xml b/base/app/src/main/res/values-zh/myspoti_strings.xmlindex 0c7bb179..85279012 100644--- a/base/app/src/main/res/values-zh/myspoti_strings.xml+++ b/base/app/src/main/res/values-zh/myspoti_strings.xml@@ -712,10 +712,10 @@<string name="settings_automix_length_auto">均衡</string><string name="settings_automix_length_long">长</string><string name="settings_automix_tempo">速度对齐</string>- <string name="settings_automix_tempo_detail">下一首的速度最多可调整多少以对上节拍。超出时,歌曲会在节拍上直接切换。</string>+ <string name="settings_automix_tempo_detail">下一首的速度最多可调整多少以对上节拍。超出时,歌曲以滤波淡入淡出切换:下一首先去掉低音进入,低音在它的强拍上接替。</string><string name="settings_automix_tempo_strict">严格 (4%)</string>- <string name="settings_automix_tempo_normal">正常 (8%)</string>- <string name="settings_automix_tempo_wide">宽松 (12%)</string>+ <string name="settings_automix_tempo_normal">正常 (12%)</string>+ <string name="settings_automix_tempo_wide">宽松 (16%)</string><string name="settings_automix_eq">DJ 均衡器</string><string name="settings_automix_eq_detail">混音时交换低音并使用滤波。关闭后只调整音量。</string><string name="settings_automix_pulse">播放器动画</string>diff --git a/base/app/src/main/res/values/myspoti_strings.xml b/base/app/src/main/res/values/myspoti_strings.xmlindex 66e3f3e8..f42913fe 100644--- a/base/app/src/main/res/values/myspoti_strings.xml+++ b/base/app/src/main/res/values/myspoti_strings.xml@@ -719,10 +719,10 @@<string name="settings_automix_length_auto">Balanced</string><string name="settings_automix_length_long">Long</string><string name="settings_automix_tempo">Tempo matching</string>- <string name="settings_automix_tempo_detail">How far the next song\'s tempo may be bent to land on the beat. Beyond it, the songs change with a cut on the beat.</string>+ <string name="settings_automix_tempo_detail">How far the next song\'s tempo may be bent to land on the beat. Beyond it, the songs change with a filtered fade: the next one comes in without its bass, which takes over on its downbeat.</string><string name="settings_automix_tempo_strict">Strict (4 %)</string>- <string name="settings_automix_tempo_normal">Normal (8 %)</string>- <string name="settings_automix_tempo_wide">Wide (12 %)</string>+ <string name="settings_automix_tempo_normal">Normal (12 %)</string>+ <string name="settings_automix_tempo_wide">Wide (16 %)</string><string name="settings_automix_eq">DJ EQ</string><string name="settings_automix_eq_detail">Bass swap and filters during the mix. Off, only the volumes move.</string><string name="settings_automix_pulse">Player animation</string>diff --git a/base/automix/build.gradle.kts b/base/automix/build.gradle.ktsindex 60bbf090..ac2a39dd 100644--- a/base/automix/build.gradle.kts+++ b/base/automix/build.gradle.kts@@ -23,5 +23,6 @@ tasks.register<JavaExec>("bench") {args = (findProperty("args") as String?)?.split(" ")?.filter { it.isNotBlank() } ?: emptyList()jvmArgs("-Xmx4g")environment("AUTOMIX_THREADS", (findProperty("threads") as String?) ?: "2")+ environment("AUTOMIX_STRETCH", (findProperty("stretch") as String?) ?: "0.12")environment("AUTOMIX_MODEL", rootProject.file("app/src/main/assets/automix/beat-this-small0-int8.onnx").path)}diff --git a/base/automix/src/main/kotlin/app/myspoti/automix/MixPlan.kt b/base/automix/src/main/kotlin/app/myspoti/automix/MixPlan.ktindex d2b910a0..81fde57e 100644--- a/base/automix/src/main/kotlin/app/myspoti/automix/MixPlan.kt+++ b/base/automix/src/main/kotlin/app/myspoti/automix/MixPlan.kt@@ -33,6 +33,8 @@ class MixPlan(val note: String,/** A's gain at the middle of the mix and on: A louder than B comes down towards B's level (1: untouched). */val matchA: Double = 1.0,+ /** A FADE between tempos too far apart: B without its bass until a hand-over at [swapAt], A's top end closing. */+ val filtered: Boolean = false,) {enum class Style {/** Beat-matched blend over several bars with a bass swap. */@@ -93,7 +95,16 @@ class MixPlan(// A few tens of ms of ramp on B: no click if the downbeat lands between two steps.Levels(gA, matchB * (x / 0.04).coerceAtMost(1.0), KILL, 0.0, -10.0 * x, 0.0)}- Style.FADE -> {+ Style.FADE -> if (filtered) {+ val s = swapAt+ val ramp = beatShare.coerceAtLeast(0.0001)+ // B rises under A without its bass (its drums' kick would fight A's), A holds until the swap.+ val gB = if (x < s) 0.6 * sin(PI / 2 * (x / s)) else 0.6 + 0.4 * ((x - s) / (1 - s)).coerceIn(0.0, 1.0)+ val gA = if (x < s) 1.0 else cos(PI / 2 * ((x - s) / (1 - s)).coerceIn(0.0, 1.0))+ val swap = smooth(((x - s) / ramp).coerceIn(0.0, 1.0))+ Levels(gA, gB * matchB, KILL * swap, KILL * (1 - swap), if (x > s) -18.0 * ((x - s) / (1 - s)) else 0.0,+ if (x < s) -9.0 * (1 - x / s) else 0.0)+ } else {val gA = cos(PI / 2 * x); val gB = sin(PI / 2 * x)Levels(gA, gB * matchB, KILL * smooth(((x - 0.4) / 0.3).coerceIn(0.0, 1.0)), KILL * (1 - smooth((x / 0.6).coerceIn(0.0, 1.0))), -12.0 * x, 0.0)}@@ -111,8 +122,8 @@ class MixPlan(/** B's gain after the mix: [matchB] back to 1 over 8 s of B. */fun gainAfter(tB: Double): Double = matchB + (1 - matchB) * smooth(((tB - resumeB) / 8.0).coerceIn(0.0, 1.0))- override fun toString() = String.format("%s A %.2f→%.2f (%.1f s, %d beats) B from %.2f ×%.4f swap %.2f gainB %.2f | %s",- style, exitA, endA, length, beats, entryB, speedB, swapAt, matchB, note)+ override fun toString() = String.format("%s%s A %.2f→%.2f (%.1f s, %d beats) B from %.2f ×%.4f swap %.2f gainB %.2f | %s",+ style, if (filtered) "(filtered)" else "", exitA, endA, length, beats, entryB, speedB, swapAt, matchB, note)companion object {/** A band "off", in dB. */diff --git a/base/automix/src/main/kotlin/app/myspoti/automix/MixPlanner.kt b/base/automix/src/main/kotlin/app/myspoti/automix/MixPlanner.ktindex 4d0f2609..ab6fc28e 100644--- a/base/automix/src/main/kotlin/app/myspoti/automix/MixPlanner.kt+++ b/base/automix/src/main/kotlin/app/myspoti/automix/MixPlanner.kt@@ -30,8 +30,10 @@ object MixPlanner {/** 0 ignores keys, 2 strongly discourages known harmonic clashes. Unknown is not a clash. */val keyWeight: Double = 1.0,val smoothSec: Double = 8.0,- /** Allow a structural exit earlier in the second half, rather than preserving every late bar. */+ /** Allow a structural exit earlier in the second half, never before A's last loud section. */val djMode: Boolean = false,+ /** Filtered fade between tempos too far apart to match, seconds. */+ val filterSec: Double = 10.0,)fun plan(a: TrackAnalysis, b: TrackAnalysis, s: Settings = Settings()): MixPlan =@@ -59,6 +61,12 @@ object MixPlanner {if (soft != null && sa.softTexture(a, soft.exitA, soft.endA) &&sb.softTexture(b, soft.entryB, soft.entryB + soft.length)) return soft}+ // Tempos too far apart to match: a filtered fade (B in without its bass, the bass handed over on+ // one of B's downbeats, A's top end closing) rather than a one-second cut at the very end.+ val inRange = match != null && abs(match.speed - 1) <= s.maxStretch+ if (s.style == MixPlan.Style.BLEND && !inRange && ga != null && !a.tailDown.isNaN()) {+ filterFade(a, b, sa, sb, ga, gb?.takeIf { !b.headDown.isNaN() }, s, earliestExit)?.let { return it }+ }if (ga != null && !a.tailDown.isNaN()) cut(a, b, sa, sb, ga, gb, match, s, earliestExit)?.let { return it }return fade(a, b, sa, if (match == null) "no checked beat pair" else "no safe blend ahead", s.fadeSec, earliestExit)}@@ -106,6 +114,10 @@ object MixPlanner {private class Entry(val cue: Cue, val end: Double, val score: Double, val relativeLevel: Double)private class Choice(val exit: Cue, val entry: Cue, val bars: Int, val score: Double)private const val MIN_BLEND_SCORE = 0.5+ /** Beyond this stretch a blend is kept to 16 bars, and B's tempo comes back a little faster. */+ private const val WIDE_STRETCH = 0.08+ /** Per-bar voice-like risk from which a bar counts as sung or rapped (see [VocalRisk]). */+ private const val VOICE = 0.6fprivate val BARS = intArrayOf(32, 24, 16, 12, 8, 6, 4, 2)private fun blend(a: TrackAnalysis, b: TrackAnalysis, sa: Summary, sb: Summary, ga: Grid, gb: Grid,@@ -120,6 +132,8 @@ object MixPlanner {var preferred: Choice? = nullfor (bars in BARS) {if (bars > max(2, s.maxBars)) continue+ // A large stretch is heard on B for the second half and its way back: kept to 16 bars.+ if (abs(m.speed - 1) > WIDE_STRETCH && bars > 16) continueval len = bars * barAif (len > s.maxSec + 0.01 && bars > 2) continueval spanB = len * m.speed@@ -139,6 +153,7 @@ object MixPlanner {for (e in exits) {val endA = e.time + lenif (endA > sa.musicEnd + barA || endA > a.contentEnd + 0.01 || endA > ga.last + ga.period + 0.01) continue+ if (!keepsLastLoud(sa, s, e.time, len, 0.75, barA)) continueval lost = sa.loudCut(a, endA) * if (s.djMode) 0.08 else 0.6val endBar = a.barAt(endA + 0.05)val structure = if (s.djMode) a.sectionStrength(endBar) * 2.0 else 0.0@@ -146,16 +161,18 @@ object MixPlanner {max(0.0, endA - sa.musicEnd) / barA * 0.5val relativeA = sa.levelAt(a, e.time, endA)for (n in prepared) {- val voices = if (sa.maxVoice == 0f || sb.maxVoice == 0f) 0.0 else vocalOverlap(a, e.time, endA, b, n.cue.time, n.end)- // Disallow a long overlap dominated by two voices, even when Long was requested.- if (bars >= 8 && voices > 0.65) continue- val score = scoreA + n.score - voices * bars / 4.0 -+ val co = if (sa.maxVoice == 0f || sb.maxVoice == 0f) CoVocal.NONE else coVocal(a, e.time, endA, b, n.cue.time, n.end)+ val runBars = co.run / barA+ // Two voices really on top of each other for more than 4 bars: not a long mix.+ // Voices in different parts of the overlap (B's beat under A's verse) are fine.+ if (bars >= 8 && runBars > 4.0) continue+ val score = scoreA + n.score - co.total / barA * 0.35 -max(0.0, relativeA + n.relativeLevel) * 0.08 * bars / 8.0if (score < MIN_BLEND_SCORE) continueif (best == null || score > best.score) best = Choice(e, n.cue, bars, score)// Length is a real preference among safe candidates, not a penalty that a drop// can accidentally outweigh. Known clashes/high vocal risk may still shorten it.- val safeLong = (s.keyWeight == 0.0 || keyPenalty < 1.5) && voices < 0.4 &&+ val safeLong = (s.keyWeight == 0.0 || keyPenalty < 1.5) && runBars <= 2.0 &&abs(m.speed - 1) <= max(0.01, s.maxStretch * 0.85)if (bars >= s.minBars && safeLong && (preferred == null || score > preferred.score)) {preferred = Choice(e, n.cue, bars, score)@@ -192,6 +209,7 @@ object MixPlanner {private fun cut(a: TrackAnalysis, b: TrackAnalysis, sa: Summary, sb: Summary, ga: Grid, gb: Grid?, m: TempoMatch?,s: Settings, earliest: Double): MixPlan? {val exits = exitCues(a, sa, ga, s, earliest).filter { it.time + 2 * ga.period <= a.contentEnd + 0.01 }+ .let { all -> all.filter { keepsLastLoud(sa, s, it.time, 0.0, 0.0, 4 * ga.period, 2) }.ifEmpty { all } }if (exits.isEmpty()) return nullval entry = if (gb != null && !b.headDown.isNaN()) entryCues(b, sb, gb).maxBy { it.score }.time else b.contentStartval e = exits.maxBy { it.score - sa.loudCut(a, it.time + 2 * ga.period) * if (s.djMode) 0.08 else 0.6 }@@ -201,6 +219,47 @@ object MixPlanner {if (synced) restore(speed, gb!!.period) else 0.0, "cut on ${e.why}" + if (synced) "" else ", no common tempo")}+ /**+ * Between tempos too far apart to match: B comes in without its bass and with its top end held+ * back, unsynced, the bass changes hands on a downbeat of B about 60 % of the way, A's top end+ * closes as it goes. Exits and entries are the blend's (A's phrases, sections and outro; B's first+ * downbeat or an intro phrase), chosen so that two voices do not run together.+ */+ private fun filterFade(a: TrackAnalysis, b: TrackAnalysis, sa: Summary, sb: Summary, ga: Grid, gb: Grid?,+ s: Settings, earliest: Double): MixPlan? {+ val barA = 4 * ga.period+ val exits = exitCues(a, sa, ga, s, earliest)+ val entries = if (gb != null) entryCues(b, sb, gb) else listOf(Cue(b.contentStart, 1.0, "B start"))+ if (exits.isEmpty()) return null+ val wanted = s.filterSec.coerceAtLeast(2.0)+ var best: Pair<Double, MixPlan>? = null+ for (len in doubleArrayOf(wanted, max(4.0, wanted * 0.6))) {+ for (e in exits) {+ val endA = e.time + len+ if (endA > a.contentEnd + 0.01 || endA > sa.musicEnd + barA) continue+ if (!keepsLastLoud(sa, s, e.time, len, 0.8, barA)) continue+ val scoreA = e.score - sa.loudCut(a, endA) * (if (s.djMode) 0.08 else 0.6) -+ (if (len < wanted) 0.6 else 0.0)+ for (n in entries) {+ val endB = n.time + len+ if (endB > b.contentEnd - 10) continue+ val co = if (sa.maxVoice == 0f || sb.maxVoice == 0f) CoVocal.NONE else coVocal(a, e.time, endA, b, n.time, endB)+ if (co.run > len * 0.5) continue+ val score = scoreA + n.score - co.total / len * 3.0+ if (best != null && score <= best.first) continue+ // B's bass on its own downbeat near 60 %, as a share of the fade.+ val swapT = if (gb != null) firstDown(gb, b.headDown, n.time + len * 0.6 - 2 * gb.period) else n.time + len * 0.6+ val swap = ((swapT - n.time) / len).coerceIn(0.4, 0.8)+ best = score to MixPlan(MixPlan.Style.FADE, e.time, n.time, len, 1.0, 0, swap, (0.4 / len).coerceAtMost(0.1),+ matchGain(a, b), 0.0, String.format("filtered fade: %s, %s, %.1f→%.1f BPM, score %.1f", e.why, n.why,+ ga.bpm, gb?.bpm ?: b.bpm, score), matchA = matchGainA(a, b), filtered = true)+ }+ }+ if (best != null) break+ }+ return best?.second+ }+private fun fade(a: TrackAnalysis, b: TrackAnalysis, sa: Summary, why: String, seconds: Double, earliest: Double): MixPlan? {val minExit = max(a.contentStart, earliest)val wanted = min(seconds, (a.contentEnd - a.contentStart) / 4).coerceAtLeast(0.05)@@ -216,7 +275,10 @@ object MixPlanner {private fun exitCues(a: TrackAnalysis, sa: Summary, g: Grid, s: Settings, earliest: Double): List<Cue> {val end = sa.musicEnd- val from = maxOf(a.contentStart + (end - a.contentStart) * 0.5, end - if (s.djMode) 180 else 90, g.first, earliest)+ // Session DJ: B may come in under A's last loud section, but A is not let go before its end.+ val longest = min(s.maxSec, max(2, s.maxBars) * 4 * g.period)+ val from = maxOf(a.contentStart + (end - a.contentStart) * 0.5, end - if (s.djMode) 180 else 90, g.first, earliest,+ if (s.djMode) sa.lastLoudEnd - longest * 0.75 - 8 * 4 * g.period else 0.0)val to = min(end, g.last) - 2 * g.periodval out = ArrayList<Cue>()var t = firstDown(g, a.tailDown, from)@@ -276,6 +338,14 @@ object MixPlanner {}fun musicEnd(a: TrackAnalysis): Double = summary(a).musicEnd+ /** Where Session DJ may start leaving A at the earliest: its last loud section kept. */+ fun lastLoudEnd(a: TrackAnalysis): Double = summary(a).lastLoudEnd+ /**+ * Session DJ leaves A early only after its last loud section: A is still clearly heard ([release],+ * share of the mix where its fade is well under way) until at most [bars] bars before that section ends.+ */+ private fun keepsLastLoud(sa: Summary, s: Settings, exit: Double, len: Double, release: Double, bar: Double, bars: Int = 8) =+ !s.djMode || exit + len * release >= sa.lastLoudEnd - bars * barfun firstDown(g: Grid, down: Double, from: Double): Double {val bar = 4 * g.period@@ -296,6 +366,8 @@ object MixPlanner {val maxVoice = a.barVocalRisk.maxOrNull() ?: 0fval noveltyMean = a.barNovelty.average().takeIf { it > 0 } ?: 0.0val musicEnd: Double+ /** End of A's final loud section (at least 4 loud bars: its last chorus, or its last verse). */+ val lastLoudEnd: Doubleinit {var last = -1for (i in a.bars - 1 downTo 0) {@@ -303,6 +375,11 @@ object MixPlanner {if (last < 0 && a.barDb[i] > loud - 15) last = i}musicEnd = if (last < 0) a.contentEnd else min(a.contentEnd, a.barEnd(last))+ val hot = BooleanArray(a.bars) { a.barDb[it] >= loud - 3 }+ fun hot(i: Int) = i in 0 until a.bars && (hot[i] || (i > 0 && i + 1 < a.bars && hot[i - 1] && hot[i + 1]))+ var keep = a.contentStart+ for (i in a.bars - 1 downTo 3) if ((i - 3..i).all(::hot)) { keep = a.barEnd(i); break }+ lastLoudEnd = keepfor (i in 2 until a.bars) {val db = levelBars(i, i + 4) - levelBars(i - 4, i)val bass = mean(low, i, i + 4) - mean(low, i - 4, i)@@ -382,6 +459,31 @@ object MixPlanner {return if (weight > 0) overlap / weight else 0.0}+ internal class CoVocal(val run: Double, val total: Double) { companion object { val NONE = CoVocal(0.0, 0.0) } }++ /**+ * Where two voices are really heard together: bars of A and of B (after B's entry and stretch)+ * both over [VOICE], in the audible middle of the mix (15–85 %). [CoVocal.run] is the longest+ * such stretch and [CoVocal.total] their sum, in A's seconds.+ */+ internal fun coVocal(a: TrackAnalysis, a0: Double, a1: Double, b: TrackAnalysis, b0: Double, b1: Double): CoVocal {+ if (a1 <= a0 || b1 <= b0 || a.bars == 0 || b.bars == 0) return CoVocal.NONE+ val speed = (b1 - b0) / (a1 - a0)+ val lo = a0 + (a1 - a0) * 0.15; val hi = a0 + (a1 - a0) * 0.85+ var t = lo; var run = 0.0; var top = 0.0; var total = 0.0+ while (t < hi - 1e-6) {+ val ia = a.barAt(t + 1e-6); val ib = b.barAt(b0 + (t - a0) * speed + 1e-6)+ if (ia < 0 || ib < 0) break+ val to = minOf(hi, a.barEnd(ia), a0 + (b.barEnd(ib) - b0) / speed)+ if (to <= t + 1e-7) break+ if (a.barVocalRisk.getOrElse(ia) { 0f } >= VOICE && b.barVocalRisk.getOrElse(ib) { 0f } >= VOICE) {+ run += to - t; total += to - t; top = max(top, run)+ } else run = 0.0+ t = to+ }+ return CoVocal(top, total)+ }+private fun knownKey(a: TrackAnalysis): Boolean = a.key >= 0 && a.keyStrength >= 0.5/** Same/neighbouring Camelot keys: 0; two steps: 1; further: 2. Unknown carries no clash evidence. */@@ -411,7 +513,7 @@ object MixPlanner {}private fun restore(speed: Double, period: Double): Double {- val beats = max(8.0, abs(speed - 1) / 0.003)+ val beats = max(8.0, abs(speed - 1) / if (abs(speed - 1) > WIDE_STRETCH) 0.004 else 0.003)return if (abs(speed - 1) < 1e-4) 0.0 else (beats * period).let { (it * 10).roundToInt() / 10.0 }}}diff --git a/base/automix/src/test/kotlin/app/myspoti/automix/Bench.kt b/base/automix/src/test/kotlin/app/myspoti/automix/Bench.ktindex def2a642..1b28e179 100644--- a/base/automix/src/test/kotlin/app/myspoti/automix/Bench.kt+++ b/base/automix/src/test/kotlin/app/myspoti/automix/Bench.kt@@ -36,6 +36,14 @@ fun main(args: Array<String>) {"model" -> dir.listFiles { f -> f.name.endsWith(".f32") }!!.map { it.nameWithoutExtension }.sorted().forEach { modelDebug(dir, it) }"profile" -> args.drop(2).forEach { profile(dir, it) }"grids" -> args.drop(2).forEach { gridDebug(dir, it) }+ "vocal" -> dir.listFiles { f -> f.name.endsWith(".f32") }!!.map { it.nameWithoutExtension }.sorted().forEach { n ->+ // Per-bar voice-like risk, as a strip (0–9) and its quartiles, to calibrate the planner's thresholds.+ val a = analysisOf(dir, n)+ val r = a.barVocalRisk.sortedArray()+ fun q(p: Double) = if (r.isEmpty()) 0f else r[((r.size - 1) * p).toInt()]+ println(String.format(java.util.Locale.ROOT, "%s\t%.0f BPM\tq25 %.2f q50 %.2f q75 %.2f\t%s", n, a.bpm, q(0.25), q(0.5), q(0.75),+ a.barVocalRisk.joinToString("") { (it * 9.99f).toInt().coerceIn(0, 9).toString() }))+ }"tempo" -> dir.listFiles { f -> f.name.endsWith(".f32") }!!.map { it.nameWithoutExtension }.sorted().forEach { tempoDebug(dir, it) }else -> println("unknown $cmd")}@@ -69,17 +77,20 @@ private fun matrix(dir: File, long: Boolean, fresh: Boolean, dj: Boolean) {require(names.size >= 2) { "matrix needs at least two .f32 songs" }val analyses = names.associateWith { name ->val result = BenchCache.analysis(dir, name, fresh)- println(String.format(java.util.Locale.ROOT, "track\t%s\t%s\t%.1f ms\t%.2f BPM\t%d sections", name,- if (result.cached) "cached" else "analysed", result.elapsedMs, result.analysis.bpm, result.analysis.sectionStarts.size))+ println(String.format(java.util.Locale.ROOT, "track\t%s\t%s\t%.1f ms\t%.2f BPM\t%d sections\tmusicEnd %.1f\tlastLoud %.1f", name,+ if (result.cached) "cached" else "analysed", result.elapsedMs, result.analysis.bpm, result.analysis.sectionStarts.size,+ MixPlanner.musicEnd(result.analysis), MixPlanner.lastLoudEnd(result.analysis)))result.analysis}// Same balanced/long policy as AutoMix.settings(), with harmonic mixing and Session DJ on.- val settings = MixPlanner.Settings(maxSec = if (long) 90.0 else 48.0, lengthBias = if (long) 1 else 0,- minBars = if (long) 12 else 8, maxBars = if (long) 32 else 16, keyWeight = 2.0, djMode = dj)+ val stretch = System.getenv("AUTOMIX_STRETCH")?.toDouble() ?: 0.12+ val settings = MixPlanner.Settings(maxStretch = stretch, maxSec = if (long) 90.0 else 48.0, lengthBias = if (long) 1 else 0,+ minBars = if (long) 12 else 8, maxBars = if (long) 32 else 16, keyWeight = 2.0, djMode = dj, filterSec = if (long) 14.0 else 10.0)val counts = MixPlan.Style.values().associateWith { 0 }.toMutableMap()val costs = ArrayList<Double>(); val lengths = ArrayList<Double>()- var longBlends = 0- println("pair\tstyle\tseconds\tbars\texitA\tentryB\tspeedB\tplan_ms\treason")+ var longBlends = 0; var filtered = 0+ val left = ArrayList<Double>()+ println("pair\tstyle\tseconds\tbars\texitA\tentryB\tspeedB\tplan_ms\tleftA\treason")for (a in names) for (b in names) if (a != b) {val t0 = System.nanoTime()val plan = MixPlanner.plan(analyses.getValue(a), analyses.getValue(b), settings)@@ -87,14 +98,17 @@ private fun matrix(dir: File, long: Boolean, fresh: Boolean, dj: Boolean) {costs.add(ms); lengths.add(plan.length)counts[plan.style] = counts.getValue(plan.style) + 1if (plan.style == MixPlan.Style.BLEND && plan.beats >= 48) longBlends++- println(String.format(java.util.Locale.ROOT, "%s,%s\t%s\t%.3f\t%.1f\t%.3f\t%.3f\t%.5f\t%.3f\t%s",- a, b, plan.style, plan.length, plan.beats / 4.0, plan.exitA, plan.entryB, plan.speedB, ms, plan.note))+ if (plan.filtered) filtered+++ // A's music left out after the mix (its silent tail not counted).+ val leftA = (MixPlanner.musicEnd(analyses.getValue(a)) - plan.endA).coerceAtLeast(0.0); left.add(leftA)+ println(String.format(java.util.Locale.ROOT, "%s,%s\t%s\t%.3f\t%.1f\t%.3f\t%.3f\t%.5f\t%.3f\t%.1f\t%s",+ a, b, if (plan.filtered) "FILTER" else plan.style, plan.length, plan.beats / 4.0, plan.exitA, plan.entryB, plan.speedB, ms, leftA, plan.note))}- costs.sort(); lengths.sort()+ costs.sort(); lengths.sort(); left.sort()fun percentile(x: List<Double>, q: Double) = x[((x.size - 1) * q).toInt()]- println(String.format(java.util.Locale.ROOT, "summary\tpairs=%d\tBLEND=%d\tCUT=%d\tFADE=%d\tblend_12plus_bars=%d\tmedian_seconds=%.2f\tplan_median_ms=%.3f\tplan_p95_ms=%.3f",- costs.size, counts.getValue(MixPlan.Style.BLEND), counts.getValue(MixPlan.Style.CUT), counts.getValue(MixPlan.Style.FADE), longBlends,- percentile(lengths, 0.5), percentile(costs, 0.5), percentile(costs, 0.95)))+ println(String.format(java.util.Locale.ROOT, "summary\tpairs=%d\tBLEND=%d\tFILTER=%d\tCUT=%d\tFADE=%d\tblend_12plus_bars=%d\tmedian_seconds=%.2f\tmedian_leftA=%.1f\tplan_median_ms=%.3f\tplan_p95_ms=%.3f",+ costs.size, counts.getValue(MixPlan.Style.BLEND), filtered, counts.getValue(MixPlan.Style.CUT), counts.getValue(MixPlan.Style.FADE) - filtered, longBlends,+ percentile(lengths, 0.5), percentile(left, 0.5), percentile(costs, 0.5), percentile(costs, 0.95)))}private fun analyzeOne(dir: File, name: String) {diff --git a/base/automix/src/test/kotlin/app/myspoti/automix/MixPlannerPolicyTest.kt b/base/automix/src/test/kotlin/app/myspoti/automix/MixPlannerPolicyTest.ktindex f50ced92..c9158134 100644--- a/base/automix/src/test/kotlin/app/myspoti/automix/MixPlannerPolicyTest.kt+++ b/base/automix/src/test/kotlin/app/myspoti/automix/MixPlannerPolicyTest.kt@@ -95,18 +95,27 @@ class MixPlannerPolicyTest {assertTrue("$plan", plan.endA <= tail.last + tail.period + 0.01)}- @Test fun djModeCanUseAnEarlierStructuralBreakWithoutChangingTempo() {+ @Test fun djModeLeavesALongQuietOutroEarlyWithoutChangingTempo() {fun outgoing(): TrackAnalysis = track().also { a ->- for (i in 80 until 88) a.barDb[i] = -22f- a.barNovelty[80] = 3f+ // Loud until bar 88 (176 s), then 32 bars of quiet outro.+ for (i in 88 until 120) a.barDb[i] = -24f+ a.barNovelty[88] = 3f}- val preserve = MixPlanner.plan(outgoing(), track())val dj = MixPlanner.plan(outgoing(), track(), MixPlanner.Settings(djMode = true))assertEquals(MixPlan.Style.BLEND, dj.style)- assertTrue("preserve=$preserve, DJ=$dj", dj.exitA < preserve.exitA - 10)+ // Out well before the end of the outro, but not before the loud part is (nearly) over.+ assertTrue("$dj", dj.endA < 215 && dj.exitA + dj.length * 0.75 >= 176.0 - 16)+ assertEquals(176.0, MixPlanner.lastLoudEnd(outgoing()), 1e-9)assertEquals(1.0, dj.speedB, 1e-9)}+ @Test fun djModeDoesNotSkipTheLastLoudSectionForAnEarlierBreak() {+ val a = track().also { for (i in 80 until 88) it.barDb[i] = -22f; it.barNovelty[80] = 3f }+ val dj = MixPlanner.plan(a, track(), MixPlanner.Settings(djMode = true, maxSec = 64.0, lengthBias = 1, minBars = 12, maxBars = 32))+ // The break at 160 s is followed by 32 loud bars: A is still clearly heard until at most 8 bars before 240 s.+ assertTrue("$dj", dj.exitA + dj.length * 0.75 >= 240.0 - 8 * 2.0 - 1e-9)+ }+@Test fun bassHandoverFollowsAStrongArrivalWithinTheMix() {val b = track()// A bass-only arrival keeps B's earlier melody worth playing: the entry stays at 0.@@ -140,8 +149,60 @@ class MixPlannerPolicyTest {val slower = TrackAnalysis(b.duration, b.contentStart, b.contentEnd, b.loudnessDb, b.key, b.keyStrength,100.0, true, g, g, b.beats, b.barStarts, b.barDb, b.barLowDb, b.barHighDb, b.barCentre, b.barNovelty,0, false, 0.0, 0.0)- val plan = MixPlanner.plan(track(), slower, MixPlanner.Settings(lengthBias = 1, smoothSec = 14.0))- assertEquals(MixPlan.Style.CUT, plan.style)- assertEquals(1.0, plan.length, 1e-9)+ val plan = MixPlanner.plan(track(), slower, MixPlanner.Settings(lengthBias = 1, smoothSec = 14.0, filterSec = 12.0))+ // 120 → 100 BPM (20 %): no stretch, no one-second cut, but a filtered fade with the bass handed over.+ assertEquals(MixPlan.Style.FADE, plan.style)+ assertTrue("$plan", plan.filtered)+ assertEquals(12.0, plan.length, 1e-9)+ assertEquals(1.0, plan.speedB, 1e-9)+ // B's bass comes in on one of its own downbeats (every 2.4 s from its entry).+ val swapB = plan.entryB + plan.swapAt * plan.length+ assertEquals(0.0, Math.floorMod(Math.round((swapB - plan.entryB) * 1000), 2400L).toDouble(), 1.0)+ val before = plan.levels(plan.swapAt - 0.05); val after = plan.levels(plan.swapAt + 0.2)+ assertEquals(MixPlan.KILL, before.lowB, 1e-9); assertEquals(0.0, before.lowA, 1e-9)+ assertEquals(0.0, after.lowB, 1e-9); assertEquals(MixPlan.KILL, after.lowA, 1e-9)+ for (i in 0..100) plan.levels(i / 100.0).let { assertTrue(it.gainA * it.gainA + it.gainB * it.gainB <= 1.0 + 1e-9) }+ }++ @Test fun filteredFadeAvoidsTwoVoicesAndCutOnlyWhenAskedFor() {+ val g = Grid(0.0, 0.6, 400, 1.0, 0.0, 1.0)+ val base = track(risk = { if (it < 6) 0f else 1f })+ val slower = TrackAnalysis(base.duration, base.contentStart, base.contentEnd, base.loudnessDb, base.key, base.keyStrength,+ 100.0, true, g, g, base.beats, base.barStarts, base.barDb, base.barLowDb, base.barHighDb, base.barCentre, base.barNovelty,+ 0, false, 0.0, 0.0, barVocalRisk = base.barVocalRisk)+ val fade = MixPlanner.plan(track(risk = { 1f }), slower, MixPlanner.Settings(filterSec = 10.0))+ assertTrue("$fade", fade.filtered)+ val co = MixPlanner.coVocal(track(risk = { 1f }), fade.exitA, fade.endA, slower, fade.entryB, fade.entryB + fade.length)+ assertTrue("$fade co=${co.run}", co.run <= fade.length * 0.5)+ assertEquals(MixPlan.Style.CUT, MixPlanner.plan(track(), slower, MixPlanner.Settings(style = MixPlan.Style.CUT)).style)+ }++ @Test fun coVocalMeasuresOnlyVoicesHeardTogether() {+ val a = track(risk = { if (it < 4) 1f else 0f })+ val b = track(risk = { if (it in 4..7) 1f else 0f })+ assertEquals(0.0, MixPlanner.coVocal(a, 0.0, 16.0, b, 0.0, 16.0).total, 1e-9)+ val both = track(risk = { 1f })+ // Over 16 s, the audible middle (15–85 %) is 11.2 s, all of it two voices.+ assertEquals(11.2, MixPlanner.coVocal(both, 0.0, 16.0, both, 0.0, 16.0).run, 1e-6)+ }++ @Test fun twoVoicesForAFewBarsDoNotRuleOutALongMix() {+ // B raps from its bar 12 on: a 32-bar mix from B's start has its voice under A's for the last part only.+ val a = track(risk = { if (it >= 104) 0f else 1f })+ val b = track(risk = { if (it < 12) 0f else 1f })+ val plan = MixPlanner.plan(a, b, long())+ assertEquals(MixPlan.Style.BLEND, plan.style)+ assertTrue("$plan", plan.beats >= 48)+ }++ @Test fun wideStretchKeepsBlendsTo16Bars() {+ val b = track()+ val g = Grid(0.0, 60.0 / 109.0, 430, 1.0, 0.0, 1.0)+ val slower = TrackAnalysis(b.duration, b.contentStart, b.contentEnd, b.loudnessDb, b.key, b.keyStrength,+ 109.0, true, g, g, b.beats, b.barStarts, b.barDb, b.barLowDb, b.barHighDb, b.barCentre, b.barNovelty,+ 0, false, 0.0, 0.0)+ val plan = MixPlanner.plan(track(), slower, MixPlanner.Settings(maxStretch = 0.12, maxSec = 90.0, lengthBias = 1, minBars = 12, maxBars = 32))+ assertEquals(MixPlan.Style.BLEND, plan.style)+ assertTrue("$plan", plan.beats <= 64 && plan.speedB > 1.08)}}