feat(enrichment): oximedia BPM/mood facts, mood search, and queue display (#863)

* feat(enrichment): oximedia BPM/mood facts, mood search, and queue UI

Run client-side oximedia analysis after CPU seed and persist BPM, mood JSON,
and searchable mood_tag facts. Add product mood groups (joy/sadness/dance/work/
romance) with Advanced Search filter on the local index, queue BPM/mood display,
migration 008 mood_tag index, and refreshed licenses for oximedia crates.

* fix(enrichment): keep mood_groups module comment in English

* feat(search): virtual mood groups, anger filter, and Advanced Search UX

Expand mood search via overlapping virtual groups (tag expansion only),
add anger/Злость group, skip album/artist shortcuts for track-only filters,
and simplify mood search UI (songs-only, hide type tabs). Fix CustomSelect
spurious scrollbar on short option lists.

* feat(analysis): unified track analysis plan and enqueue path

Add TrackAnalysisPlan (waveform, LUFS, enrichment) with a single
enqueue_track_analysis entry for all byte-backed triggers. Run enrichment
when cache is full but library facts are missing; route playback, cache,
and backfill through the planner. Fix browseTextSearch LocalSearchOpts tsc
gap and remove obsolete read_seed_bytes_if_needed helper.

* fix(analysis): wire playback dispatch, preload enrichment, and UI refresh

Route stream, gapless, preload, and local-file playback through analysis_dispatch
so BPM/mood enrichment runs when waveform/LUFS are already cached. Fix audio_preload
cache-hit and hot-cache paths, emit preload-cancelled for retry, and add
analysis:enrichment-updated plus content_cache_coverage key resolution.

* fix(audio): preload local files from disk and stop analysis retry loop

Seed hot/offline next tracks via LocalFilePlayback (512 MiB) instead of copying
into the RAM preload slot. Keep bytePreloadingId set after preload-ready so
progress ticks do not re-invoke audio_preload every second.

* fix(enrichment): clippy, album bpm filter routing, and queue mood display

Clippy-clean analysis_dispatch and engine imports; restrict track-derived album
routing to mood_group/mood_tag only so bpm is skipped on album queries. Log
enrichment plan errors with retry-all plan; filter queue mood labels to oximedia ids.

* fix(enrichment): simplify mood_tag backfill branch in plan_track_enrichment

Remove empty if-block; keep same behaviour when backfill fails and moods row exists.

* docs: CHANGELOG and credits for track enrichment PR #863

* docs(credits): track enrichment PR #863 contributor line

* chore(enrichment): clippy-clean plan branch and trim dead exports

Collapse mood_tag backfill if for clippy; remove unused moodGroupById and
OXIMEDIA_MOOD_LABELS re-exports; stop poll when server BPM is already known.

* fix(enrichment): close R2/S1–S3 limits and Song Info BPM fallback

Return TrackEnrichmentOutcome::Failed on oximedia errors so retries are not
masked as complete; extract mood Advanced Search SQL, unify top-3 mood tag
selection in mood_groups with TS invariant tests, and show measured BPM in
Song Info when tag BPM is missing or zero.

* fix(enrichment): restore offline coverage and show mood in Song Info

Add unit tests for offline download cancel/clear registry after the analysis
seed refactor dropped read_seed_bytes coverage; show localized mood labels in
Song Info when library enrichment facts exist.

* fix(enrichment): soft mood scoring and unblock offline cancel tests

Replace oximedia quadrant happy/excited mapping with valence/arousal
soft scores across all mood tags for display, storage, and backfill;
fix offline cancel unit tests that deadlocked by calling clear while
holding the global offline_cancel_flags mutex.

* fix(enrichment): dedupe joy cluster and cap mood display at two labels

Never show happy and excited together; pick one tag per V/A cluster,
tighten oximedia recalibration, and limit queue/Song Info to two moods
that pass a relative score floor.

* fix(enrichment): disable oximedia mood labels in UI and search tags

Oximedia 0.1.7 mood is a spectral energy heuristic, not independent mood
weights; valence correlates with loud/bright audio and false-labels metal
and lyrical tracks as happy. Hide queue/Song Info mood and stop writing
mood_tag facts until a reliable detector lands; keep V/A/moods JSON stored.

* fix(enrichment): disable oximedia mood analysis and add BPM advanced search

Stop planning, running, and storing oximedia mood facts; purge accumulated
mood rows via migration 009. Hide mood filters in Advanced Search, expose
BPM range filter with dual-storage resolution, and show a BPM column in song
results when that filter is active.

* feat(search): analysis BPM priority, source tooltip, and filter UX

Prefer analysis track_fact over file tags for BPM resolution; show source
in list tooltips. Validate BPM range on blur, add clear button, fix double tooltip.

* fix(enrichment): prefer analysis BPM in Song Info and queue tech row

Show measured track_fact BPM before file tags until analysis completes;
pick the highest-confidence analysis fact when several exist.
This commit is contained in:
cucadmuh
2026-05-23 18:54:04 +03:00
committed by GitHub
parent 67b1dc790b
commit 003b280a77
92 changed files with 4566 additions and 492 deletions
@@ -39,6 +39,20 @@ pub struct TrackKey {
pub md5_16kb: String,
}
/// Waveform / loudness rows present for a specific content fingerprint
/// (`md5_16kb`), after track-id variant + legacy server fallback.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ContentCacheCoverage {
pub has_waveform: bool,
pub has_loudness: bool,
}
impl ContentCacheCoverage {
pub fn complete(self) -> bool {
self.has_waveform && self.has_loudness
}
}
#[derive(Debug, Clone)]
pub struct WaveformEntry {
pub bins: Vec<u8>,
@@ -306,6 +320,59 @@ impl AnalysisCache {
Ok(row.filter(|e| waveform_cache_blob_len_ok(&e.bins, e.bin_count)))
}
/// Lookup waveform + loudness for an exact content fingerprint, trying bare /
/// `stream:` track-id variants and the legacy `''` server pool (with lazy
/// re-tag onto `server_id` when a legacy hit occurs).
pub fn content_cache_coverage(
&self,
server_id: &str,
track_id: &str,
md5_16kb: &str,
) -> Result<ContentCacheCoverage, String> {
let mut has_waveform = false;
let mut has_loudness = false;
let mut relabel = false;
for tid in track_id_cache_variants(track_id) {
if !server_id.is_empty() {
let key = TrackKey {
server_id: server_id.to_string(),
track_id: tid.clone(),
md5_16kb: md5_16kb.to_string(),
};
if self.get_waveform(&key)?.is_some() {
has_waveform = true;
}
if self.loudness_row_exists_for_key(&key)? {
has_loudness = true;
}
}
let legacy = TrackKey {
server_id: String::new(),
track_id: tid,
md5_16kb: md5_16kb.to_string(),
};
if self.get_waveform(&legacy)?.is_some() {
has_waveform = true;
if !server_id.is_empty() {
relabel = true;
}
}
if self.loudness_row_exists_for_key(&legacy)? {
has_loudness = true;
if !server_id.is_empty() {
relabel = true;
}
}
}
if relabel {
let _ = self.relabel_legacy_to_server(server_id, track_id);
}
Ok(ContentCacheCoverage {
has_waveform,
has_loudness,
})
}
/// True when this exact `(track_id, md5_16kb)` has a loudness row for the current algo version.
/// Used after `delete_loudness_for_track_id`: waveform may still be cached, but EBU data was removed.
pub fn loudness_row_exists_for_key(&self, key: &TrackKey) -> Result<bool, String> {
@@ -356,6 +423,25 @@ impl AnalysisCache {
Ok(None)
}
/// Latest `md5_16kb` fingerprint for `(server_id, track_id)` with legacy fallback.
pub fn get_latest_md5_16kb_for_track(
&self,
server_id: &str,
track_id: &str,
) -> Result<Option<String>, String> {
let conn = self.conn.lock().map_err(|_| "analysis_cache lock poisoned".to_string())?;
if let Some(md5) = query_latest_md5_16kb_scoped(&conn, server_id, track_id)? {
return Ok(Some(md5));
}
if !server_id.is_empty() {
if let Some(md5) = query_latest_md5_16kb_scoped(&conn, "", track_id)? {
let _ = relabel_legacy_to_server(&conn, server_id, track_id);
return Ok(Some(md5));
}
}
Ok(None)
}
/// Both waveform and loudness rows exist for this `(server_id, track_id)`
/// (including the legacy `''` fallback) — a CPU seed from bytes/file would
/// only decode the file to immediately skip with `SkippedWaveformCacheHit`.
@@ -445,6 +531,40 @@ fn query_latest_waveform_scoped(
Ok(None)
}
fn query_latest_md5_16kb_scoped(
conn: &Connection,
server_id: &str,
track_id: &str,
) -> Result<Option<String>, String> {
const SQL: &str = r#"
SELECT w.md5_16kb
FROM waveform_cache w
JOIN analysis_track a
ON a.server_id = w.server_id
AND a.track_id = w.track_id
AND a.md5_16kb = w.md5_16kb
WHERE w.server_id = ?1
AND w.track_id = ?2
AND a.waveform_algo_version = ?3
ORDER BY w.updated_at DESC
LIMIT 1
"#;
for tid in track_id_cache_variants(track_id) {
let row: Option<String> = conn
.query_row(SQL, params![server_id, tid, WAVEFORM_ALGO_VERSION], |row| {
row.get(0)
})
.optional()
.map_err(|e| e.to_string())?;
if let Some(md5) = row {
if !md5.is_empty() {
return Ok(Some(md5));
}
}
}
Ok(None)
}
/// Server-scoped variant of the "latest loudness for this track" lookup.
fn query_latest_loudness_scoped(
conn: &Connection,