Mulberry/src/bus.rs
astar76 eeb0ad5bb9 Rewrite Mulberry in Rust (egui + libmpv)
Port of the Python/PyQt6 app: same library database, playlists, hero panel,
lyrics, tag editor, MusicBrainz/cover tools, CD ripping, MPRIS and tray.

New: right-click 'Set <tag> to "value"' writes the clicked cell's tag into every
selected file (with undo). The seek bar now runs off a monotonic position clock
so it can't jump back and forth.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-24 14:46:05 -05:00

94 lines
2.8 KiB
Rust

//! Messages from worker threads to the UI thread.
use crate::song::Song;
use eframe::egui;
use std::sync::mpsc::Sender;
pub enum Msg {
ScanProgress { done: usize, total: usize },
ScanFinished { added: usize, updated: usize, removed: usize },
/// Cover for the playing song, already scaled for the GPU (None = no art).
Art { ident: String, art: Option<Box<ArtData>>, path: String },
/// Lyrics text and source label ("loading", "error", "none:<label>", … are special sources).
Lyrics { token: u64, text: String, source: String },
ArtistInfo { artist: String, text: String },
Toast(String),
/// Track decoded for the visualizer (mono, TRACK_RATE).
Decoded { token: u64, samples: Vec<f32>, done: bool },
/// Songs gathered from paths/playlist files, ready to be inserted.
Added { job: AddJob, songs: Vec<Song> },
Resolved { token: u64, result: Result<crate::online::Resolved, String> },
/// Tag edit finished on a worker thread.
TagsWritten(Box<TagsDone>),
Engine(u8, crate::player::EngineEvent),
Mpris(MprisCmd),
/// A file/folder dialog finished (it runs on its own thread).
Picked { purpose: String, paths: Vec<String> },
Raise,
OpenArgs(Vec<String>),
CoverCandidates { token: u64, items: Result<Vec<crate::online::CoverCand>, String> },
CoverThumb { token: u64, idx: usize, image: Option<egui::ColorImage> },
CoverFull { token: u64, bytes: Result<Vec<u8>, String> },
MbResults { token: u64, items: Result<Vec<crate::online::MbRelease>, String> },
/// Result of a background job the UI shows as a toast.
Done { toast: String },
ConnectLastFm(Result<(String, String), String>),
}
#[derive(Clone, Debug, Default)]
pub struct AddJob {
pub pl: u64,
pub row: Option<usize>,
pub play: bool,
pub replace: bool,
}
pub struct TagsDone {
/// (song before the edit, song after the edit, old values of the changed fields)
pub ok: Vec<(Song, Song, Vec<(crate::tags::Field, String)>)>,
pub errors: Vec<String>,
pub label: String,
/// True when this was an undo (don't offer another undo).
pub is_undo: bool,
}
pub struct ArtData {
pub cover: egui::ColorImage,
pub blur: egui::ColorImage,
pub accent: Option<egui::Color32>,
}
#[derive(Clone, Debug)]
pub enum MprisCmd {
Play,
Pause,
PlayPause,
Stop,
Next,
Prev,
Seek(f64),
SetPos(f64),
SetVolume(f64),
Raise,
ToggleVisible,
Quit,
SetShuffle(bool),
SetLoop(String),
}
#[derive(Clone)]
pub struct Bus {
pub tx: Sender<Msg>,
pub ctx: egui::Context,
}
impl Bus {
pub fn send(&self, m: Msg) {
let _ = self.tx.send(m);
self.ctx.request_repaint();
}
pub fn toast(&self, s: impl Into<String>) {
self.send(Msg::Toast(s.into()));
}
}