diff --git a/README.md b/README.md
index 181afce..ab934e8 100644
--- a/README.md
+++ b/README.md
@@ -106,7 +106,7 @@ VALUES (gen_random_uuid(), 'jellywx', 3, 50);
| `months` | 3 | Months of listening history to cluster |
| `cluster_count` | automatic | Number of mixes |
| `playlist_size` | 50 | Songs per mix |
-| `familiar_ratio` | 0.3 | Share of each mix taken from recently played tracks |
+| `familiar_ratio` | 0.3 | Share of each mix made of songs you've played recently (also used by the discover UI's "Play mix") |
| `name_template` | `Mix: {label}` | Playlist name; `{label}` becomes the mix's top genres |
| `refresh_hours` | 24 | How often to rebuild the mixes |
| `discovery_count`| 15 | New songs (not in your library) to suggest per mix |
@@ -131,6 +131,10 @@ In the UI, songs from your library stream from Subsonic. New songs are found on
installed on the server (keep it up to date: YouTube changes often break older versions). You can
like a new song to keep it in "Liked new songs", or hide it so it isn't suggested again.
+"Play mix" plays a mix's new songs in random order with songs you already know (the songs in the
+mix you've played recently) mixed in evenly, so that `familiar_ratio` of what you hear is familiar.
+If a mix has too few known songs to keep that ratio, all of them are used.
+
Build it with:
```sh
diff --git a/discover/src/App.tsx b/discover/src/App.tsx
index 5a4e8d7..735b9b0 100644
--- a/discover/src/App.tsx
+++ b/discover/src/App.tsx
@@ -211,7 +211,7 @@ export function App() {
{route.view === "liked" ? (
) : detail ? (
-
+
) : (
mixId &&
Loading…
)}
diff --git a/discover/src/MixView.tsx b/discover/src/MixView.tsx
index 0c50787..f5ae245 100644
--- a/discover/src/MixView.tsx
+++ b/discover/src/MixView.tsx
@@ -1,6 +1,6 @@
import { useMemo } from "react";
import { MixDetail, mixTitle, Suggestion, SuggestionStatus } from "./api";
-import { fromSong, fromSuggestion, interleave, QueueItem } from "./queue";
+import { fromSong, fromSuggestion, mixAtRatio, QueueItem, shuffled } from "./queue";
import { Player } from "./usePlayer";
import { TrackRow } from "./TrackRow";
import * as Icon from "./icons";
@@ -37,15 +37,24 @@ export function SuggestionActions({ s, onStatus }: { s: Suggestion; onStatus: (s
type Props = {
mix: MixDetail;
+ /** Share of "Play mix" made of songs the user already knows */
+ knownRatio: number;
player: Player;
onStatus: (s: Suggestion, status: SuggestionStatus) => void;
};
-export function MixView({ mix, player, onStatus }: Props) {
+export function MixView({ mix, knownRatio, player, onStatus }: Props) {
const fresh = useMemo(() => mix.suggestions.map(fromSuggestion), [mix.suggestions]);
const library = useMemo(() => mix.songs.map(fromSong), [mix.songs]);
- // clicking a row plays through everything shown, new songs first
- const all = useMemo(() => [...fresh, ...library], [fresh, library]);
+ const knownIds = useMemo(() => new Set(mix.known_song_ids), [mix.known_song_ids]);
+ // mixes built before songs were marked as known fall back to the whole library
+ const known = useMemo(
+ () => (knownIds.size ? library.filter((_, i) => knownIds.has(mix.songs[i].id)) : library),
+ [library, knownIds, mix.songs],
+ );
+ // clicking a new song plays the new songs in order, with known songs mixed in
+ const mixed = useMemo(() => mixAtRatio(fresh, known, knownRatio), [fresh, known, knownRatio]);
+ const percent = Math.round(Math.min(Math.max(knownRatio, 0), 1) * 100);
const title = mixTitle(mix);
const h = hue(mix.tags.join());
@@ -65,10 +74,13 @@ export function MixView({ mix, player, onStatus }: Props) {
{mix.tags.map((t) =>
{t}
)}
- {mix.songs.length} from your library · {mix.suggestions.length} new
+ {mix.suggestions.length} new · {mix.songs.length} from your library
+ {knownIds.size > 0 && <>, {knownIds.size} you've played>}