mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 06:25:41 +00:00
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:
@@ -126,44 +126,125 @@ pub fn analysis_backfill_shared(app: &tauri::AppHandle) -> Arc<AnalysisBackfillS
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// Decode `bytes` for `track_id` via the cpu-seed queue. Returns `Ok(true)` when
|
||||
/// a loudness row exists in the cache after the seed (cache-hit short-circuits as
|
||||
/// well as fresh decode hits).
|
||||
use crate::track_analysis_plan::plan_track_analysis;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum EnqueueTrackAnalysisOutcome {
|
||||
/// Waveform, LUFS, and enrichment facts are all current.
|
||||
Complete,
|
||||
/// Symphonia full-file decode queued (enrichment runs after seed when needed).
|
||||
QueuedFullSeed,
|
||||
/// Oximedia pass ran inline (waveform + LUFS already cached).
|
||||
RanEnrichmentOnly,
|
||||
}
|
||||
|
||||
/// **Single entry point** for byte-backed track analysis.
|
||||
///
|
||||
/// 1. Plan: waveform / LUFS gaps in analysis cache + enrichment facts in library.
|
||||
/// 2. If nothing missing → no-op.
|
||||
/// 3. If waveform or LUFS missing → CPU seed queue (Symphonia + EBU R128).
|
||||
/// 4. Else if enrichment missing → oximedia 60 s window only.
|
||||
pub async fn enqueue_track_analysis(
|
||||
app: &tauri::AppHandle,
|
||||
server_id: &str,
|
||||
track_id: &str,
|
||||
bytes: &[u8],
|
||||
high_priority: bool,
|
||||
) -> Result<EnqueueTrackAnalysisOutcome, String> {
|
||||
if bytes.is_empty() {
|
||||
return Ok(EnqueueTrackAnalysisOutcome::Complete);
|
||||
}
|
||||
let content_hash = analysis_cache::md5_first_16kb(bytes);
|
||||
let plan = plan_track_analysis(app, server_id, track_id, &content_hash);
|
||||
if !plan.any() {
|
||||
crate::app_deprintln!(
|
||||
"[analysis] track complete track_id={} hash={}",
|
||||
track_id,
|
||||
content_hash
|
||||
);
|
||||
return Ok(EnqueueTrackAnalysisOutcome::Complete);
|
||||
}
|
||||
if plan.needs_full_cpu_seed() {
|
||||
crate::app_deprintln!(
|
||||
"[analysis] queue full seed track_id={} hash={} need_waveform={} need_loudness={} need_enrichment={}",
|
||||
track_id,
|
||||
content_hash,
|
||||
plan.need_waveform,
|
||||
plan.need_loudness,
|
||||
plan.enrichment.any()
|
||||
);
|
||||
submit_analysis_cpu_seed(
|
||||
app.clone(),
|
||||
server_id.to_string(),
|
||||
track_id.to_string(),
|
||||
bytes.to_vec(),
|
||||
high_priority,
|
||||
)
|
||||
.await?;
|
||||
return Ok(EnqueueTrackAnalysisOutcome::QueuedFullSeed);
|
||||
}
|
||||
if plan.needs_enrichment_only() {
|
||||
crate::app_deprintln!(
|
||||
"[analysis] enrichment-only track_id={} hash={}",
|
||||
track_id,
|
||||
content_hash
|
||||
);
|
||||
run_track_enrichment_from_bytes(app, server_id, track_id, bytes).await;
|
||||
return Ok(EnqueueTrackAnalysisOutcome::RanEnrichmentOnly);
|
||||
}
|
||||
Ok(EnqueueTrackAnalysisOutcome::Complete)
|
||||
}
|
||||
|
||||
/// Re-export for HTTP backfill gate (no bytes yet).
|
||||
pub use crate::track_analysis_plan::track_analysis_needs_work;
|
||||
|
||||
/// Oximedia BPM/mood pass only — prefer [`enqueue_track_analysis`].
|
||||
pub async fn run_track_enrichment_from_bytes(
|
||||
app: &tauri::AppHandle,
|
||||
server_id: &str,
|
||||
track_id: &str,
|
||||
bytes: &[u8],
|
||||
) {
|
||||
if server_id.is_empty() {
|
||||
return;
|
||||
}
|
||||
let app = app.clone();
|
||||
let sid = server_id.to_string();
|
||||
let tid = track_id.to_string();
|
||||
let data = bytes.to_vec();
|
||||
let _ = tokio::task::spawn_blocking(move || {
|
||||
crate::track_enrichment::run_track_enrichment_if_needed(&app, &sid, &tid, &data);
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Read a local file and run [`enqueue_track_analysis`] (hot cache, offline, spill promote).
|
||||
pub async fn enqueue_track_analysis_from_file(
|
||||
app: &tauri::AppHandle,
|
||||
server_id: &str,
|
||||
track_id: &str,
|
||||
file_path: &std::path::Path,
|
||||
high_priority: bool,
|
||||
) -> Result<EnqueueTrackAnalysisOutcome, String> {
|
||||
let bytes = tokio::fs::read(file_path)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
if bytes.is_empty() {
|
||||
return Ok(EnqueueTrackAnalysisOutcome::Complete);
|
||||
}
|
||||
enqueue_track_analysis(app, server_id, track_id, &bytes, high_priority).await
|
||||
}
|
||||
|
||||
/// Decode `bytes` for `track_id` via the cpu-seed queue. Prefer [`enqueue_track_analysis`].
|
||||
pub async fn enqueue_analysis_seed(
|
||||
app: &tauri::AppHandle,
|
||||
server_id: &str,
|
||||
track_id: &str,
|
||||
bytes: &[u8],
|
||||
) -> Result<bool, String> {
|
||||
if let Some(cache) = app.try_state::<analysis_cache::AnalysisCache>() {
|
||||
if cache.cpu_seed_redundant_for_track(server_id, track_id).unwrap_or(false) {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
let high = analysis_backfill_is_current_track(app, track_id);
|
||||
let outcome = submit_analysis_cpu_seed(
|
||||
app.clone(),
|
||||
server_id.to_string(),
|
||||
track_id.to_string(),
|
||||
bytes.to_vec(),
|
||||
high,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
crate::app_eprintln!("[analysis] failed to seed {}: {}", track_id, e);
|
||||
e
|
||||
})?;
|
||||
let has_loudness = app
|
||||
.try_state::<analysis_cache::AnalysisCache>()
|
||||
.and_then(|cache| cache.get_latest_loudness_for_track(server_id, track_id).ok().flatten())
|
||||
.is_some();
|
||||
crate::app_deprintln!(
|
||||
"[analysis] seed result track_id={} bytes={} has_loudness={} outcome={outcome:?}",
|
||||
track_id,
|
||||
bytes.len(),
|
||||
has_loudness
|
||||
);
|
||||
Ok(has_loudness)
|
||||
let outcome = enqueue_track_analysis(app, server_id, track_id, bytes, high).await?;
|
||||
Ok(!matches!(outcome, EnqueueTrackAnalysisOutcome::Complete))
|
||||
}
|
||||
|
||||
async fn analysis_backfill_download_and_seed(
|
||||
|
||||
Reference in New Issue
Block a user