player bar: wavy seek bar, fixed-width time, narrow layout; play video sound
The seek bar is a wavy progress line: the played part waves (travelling only while playing, flat when paused, still under reduced motion), then a gap, a pill handle at the playhead and the flat rest with a stop dot. Drag shows the position live and seeks on release. The time label keeps the width of its widest text; narrow, the volume slider, half the title, the cover and artist and the mute button go in turn, so the bar fits down to the 720 px window. Play is offered for audio and video files (by MIME type), Edit tags for every format lofty writes; a tag write on the playing file closes it and resumes playback where it was. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
efb4acc35a
commit
92d9e29f42
7 changed files with 307 additions and 162 deletions
|
|
@ -93,7 +93,7 @@ Never modify: `PROMPT.md` (the user's brief), the user's other projects under `~
|
|||
| `TUNAL_DRAG=x1,y1,x2,y2[,hold] TUNAL_REDUCED_MOTION=1 cargo run -p tunal -- <dir> --screenshot <png> --size 1200x760` (`XDG_CONFIG_HOME=<scratch>`) | drags between window points and drops (drop menu) or holds (glow + drag image) before the frame | S014 |
|
||||
| `Xvfb :97 &` then `env -u WAYLAND_DISPLAY DISPLAY=:97 target/debug/tunal <dir> &` and `DISPLAY=:97 target/debug/examples/xdnd_probe x1 y1 x2 y2` (or `in x y <uri>`) | X11 native DnD: fake XTEST drag out of the window onto a probe target, or a probe source dropping into the app; Xvfb only | S031 |
|
||||
| `TUNAL_APPEARANCE=1 XDG_CONFIG_HOME=<scratch> cargo run -p tunal -- <dir> --screenshot <png> --size 1000x760` | folder appearance dialog for `<dir>` (theme icons looked up at once); `cargo run -p tunal-dirmeta --example roundtrip -- <dir>` sets `Icon` in `<dir>/.directory` and prints the old values | S015 |
|
||||
| `TUNAL_PLAY=<audio file> XDG_CONFIG_HOME=<scratch> cargo run -p tunal -- <dir> --screenshot <png> [--dark] --size 1200x760` | player bar open on that file, a third in (tags, cover, waveform read at once; no audio output) | S023 |
|
||||
| `TUNAL_PLAY=<audio file> XDG_CONFIG_HOME=<scratch> cargo run -p tunal -- <dir> --screenshot <png> [--dark] --size 1200x760` (`TUNAL_PLAY_STATE=playing` draws it playing: the wave) | player bar open on that file, a third in (tags, cover, length read at once; no audio output), paused unless asked | S023 |
|
||||
| `TUNAL_TAGS=editor\|lookup\|mapping\|apply:<file>:<file> TUNAL_TAGS_SYNC=1 TUNAL_MUSICBRAINZ=<mock url> XDG_CONFIG_HOME=<scratch> cargo run -p tunal -- <dir> --screenshot <png> --size 1000x760` | tag editor / lookup / mapping over a folder; `apply` also writes the tags (scratch copies only); mock = a local server for both services | S021 |
|
||||
| `cargo run -p tunal -- --gallery --page connection\|host-key\|secret --screenshot <png> [--dark] --size 960x640` | the connection editor, the unknown-host-key prompt, the password prompt over a stand-in folder; with a scratch `HOME` (own `.ssh/config`, key) and `XDG_CONFIG_HOME` holding `tunal/connections.toml`, `session.toml` (pane `sftp://…`) and a trusted `known_hosts`, a normal `--screenshot` shows the Network section and an SFTP folder (local sshd on a spare port only) | S029 |
|
||||
| `cargo build -p tunal && target/debug/tunal --matrix <dir>` (about 1.5 min) | screenshot matrix: shell full/grid/empty/split, row hover/pressed/selected, context menu, drag, rename, properties, open-with, delete, appearance, player, tag editor, settings pages 0–5, gallery pages, light + dark, 720x480 minimum; stand-in folder in `<dir>/fixture`, config in `<dir>/config`. Hooks: `TUNAL_POINTER=x,y[,press\|click\|menu]` (hover/press/select/right-click before the frame), `TUNAL_ACTION=<action id>` (runs a menu action on the selection) | S034 |
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use crate::folder::appearance::Appearance;
|
|||
use crate::jobs_bridge::Bridge;
|
||||
use crate::menus::{Context as MenuContext, Menus};
|
||||
use crate::open::Opener;
|
||||
use crate::player_bridge::PlayerUi;
|
||||
use crate::player_bridge::{self, PlayerUi};
|
||||
use crate::properties::Properties;
|
||||
use crate::shell::Shell;
|
||||
use crate::shell::pane::Pane;
|
||||
|
|
@ -215,7 +215,8 @@ impl Action {
|
|||
Self::Open | Self::OpenWith => files && ctx.selected > 0,
|
||||
Self::Properties => true,
|
||||
Self::Appearance => files && ctx.selected <= 1,
|
||||
Self::EditTags | Self::Play => files && ctx.audio,
|
||||
Self::EditTags => files && ctx.taggable,
|
||||
Self::Play => files && ctx.playable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -229,8 +230,10 @@ pub struct Context {
|
|||
pub can_trash: bool,
|
||||
/// The clipboard holds something to paste.
|
||||
pub paste: bool,
|
||||
/// Every selected entry is a local audio file.
|
||||
pub audio: bool,
|
||||
/// Every selected entry is a local audio file whose tags can be written.
|
||||
pub taggable: bool,
|
||||
/// Every selected entry is a local audio or video file (video plays its sound).
|
||||
pub playable: bool,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -346,10 +349,10 @@ impl Actions {
|
|||
.map(|l| l.capabilities())
|
||||
.unwrap_or_default();
|
||||
let selected = pane.model.selected_uris();
|
||||
let files = !selected.is_empty() && !pane.model.selection_is_dir();
|
||||
Context {
|
||||
audio: !selected.is_empty()
|
||||
&& !pane.model.selection_is_dir()
|
||||
&& selected.iter().all(tags_bridge::is_audio),
|
||||
taggable: files && selected.iter().all(tags_bridge::can_tag),
|
||||
playable: files && selected.iter().all(player_bridge::can_play),
|
||||
selected: selected.len(),
|
||||
in_trash: pane.dir().is_some_and(|d| d.scheme() == tunal_core::TRASH),
|
||||
writable: caps.write,
|
||||
|
|
@ -571,12 +574,12 @@ impl Actions {
|
|||
return;
|
||||
}
|
||||
Action::Play => {
|
||||
// The folder's audio files queue up after the first one chosen.
|
||||
// The folder's playable files queue up after the first one chosen.
|
||||
let queue: Vec<_> = pane
|
||||
.model
|
||||
.shown_files()
|
||||
.iter()
|
||||
.filter(|u| tags_bridge::is_audio(u))
|
||||
.filter(|u| player_bridge::can_play(u))
|
||||
.filter_map(|u| u.to_path())
|
||||
.collect();
|
||||
if let Some(first) = uris.first().and_then(|u| u.to_path()) {
|
||||
|
|
|
|||
|
|
@ -1,27 +1,43 @@
|
|||
//! The quick player: the bar under the panes plays one audio file at a time, with its tags,
|
||||
//! cover and waveform, and goes on through the folder's audio files when the setting says so.
|
||||
//! Playback, tags and the waveform run off the UI thread; their results come back to the UI
|
||||
//! The quick player: the bar under the panes plays one audio file (or a video's sound) at a
|
||||
//! time, with its tags and cover, and goes on through the folder's playable files when the
|
||||
//! setting says so. Playback and tags run off the UI thread; their results come back to the UI
|
||||
//! thread, where the bar's state lives (a thread-local, so only plain data crosses threads).
|
||||
|
||||
use std::cell::{Cell, OnceCell, RefCell};
|
||||
use std::ffi::OsStr;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::rc::{Rc, Weak};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use slint::{ComponentHandle, Image, ModelRc, Rgba8Pixel, SharedPixelBuffer, VecModel};
|
||||
use tunal_player::{Event, Player, State, WaveTicket, Waveform, Waveforms};
|
||||
use slint::{ComponentHandle, Image, Rgba8Pixel, SharedPixelBuffer};
|
||||
use tunal_core::{Kind, Uri, mime};
|
||||
use tunal_player::{Event, Handle, Player, State, WaveTicket, Waveform, Waveforms};
|
||||
|
||||
use crate::config;
|
||||
use crate::jobs_bridge::Bridge;
|
||||
use crate::tags_bridge::TAGGABLE;
|
||||
use crate::{MainWindow, PlayerData};
|
||||
|
||||
/// Peaks read per track; the bar draws fewer, one per bar.
|
||||
const BUCKETS: usize = 600;
|
||||
/// Peaks read when a waveform is only wanted for the track's length.
|
||||
const BUCKETS: usize = 1;
|
||||
/// What ←/→ on the seek bar skip.
|
||||
const STEP: Duration = Duration::from_secs(5);
|
||||
/// The cover is scaled down to this (the bar shows it at 48 px, twice that for HiDPI).
|
||||
const COVER: u32 = 96;
|
||||
/// Audio or video by MIME type, yet nothing to play: playlists and MIDI (no synthesizer).
|
||||
const NOT_MEDIA: [&str; 8] = [
|
||||
"audio/x-mpegurl",
|
||||
"audio/mpegurl",
|
||||
"audio/scpls",
|
||||
"audio/x-scpls",
|
||||
"audio/x-pn-realaudio",
|
||||
"video/x-ms-asf",
|
||||
"audio/mid",
|
||||
"audio/midi",
|
||||
];
|
||||
/// Extensions the MIME table calls video that are mostly source files (TypeScript, Go modules).
|
||||
const NOT_MEDIA_EXT: [&str; 2] = ["ts", "mod"];
|
||||
|
||||
thread_local! {
|
||||
static PLAYER: RefCell<Weak<PlayerUi>> = const { RefCell::new(Weak::new()) };
|
||||
|
|
@ -34,11 +50,45 @@ fn with(f: impl FnOnce(&PlayerUi)) {
|
|||
}
|
||||
}
|
||||
|
||||
/// A local audio or video file (a video plays its sound). Formats neither decoder knows get
|
||||
/// an error toast when played.
|
||||
pub fn can_play(uri: &Uri) -> bool {
|
||||
let (Some(path), Some(name)) = (uri.to_path(), uri.file_name()) else {
|
||||
return false;
|
||||
};
|
||||
let ext = path.extension().and_then(OsStr::to_str).unwrap_or_default();
|
||||
let is = |list: &[&str]| list.iter().any(|e| ext.eq_ignore_ascii_case(e));
|
||||
if is(&TAGGABLE) {
|
||||
return true;
|
||||
}
|
||||
let mime = mime::mime_type(name, &Kind::File);
|
||||
(mime.starts_with("audio/") || mime.starts_with("video/"))
|
||||
&& !NOT_MEDIA.contains(&mime)
|
||||
&& !is(&NOT_MEDIA_EXT)
|
||||
}
|
||||
|
||||
/// The engine's handle once something was played, so another thread can close the playing
|
||||
/// file while it rewrites it (`Handle::without`).
|
||||
pub fn handle() -> Option<Handle> {
|
||||
let player = PLAYER.with(|w| w.borrow().upgrade())?;
|
||||
player.player.get().map(Player::handle)
|
||||
}
|
||||
|
||||
/// Tags of `paths` were written: the bar reads the title, artist and cover again when it
|
||||
/// shows one of them.
|
||||
pub fn tags_changed(paths: &[PathBuf]) {
|
||||
with(|p| {
|
||||
let current = p.track.borrow().as_ref().map(|t| t.path.clone());
|
||||
if let Some(path) = current.filter(|c| paths.contains(c)) {
|
||||
p.read_info_later(path);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
struct Track {
|
||||
path: PathBuf,
|
||||
duration: Duration,
|
||||
position: Duration,
|
||||
waveform: Option<Arc<Waveform>>,
|
||||
ticket: Option<WaveTicket>,
|
||||
}
|
||||
|
||||
|
|
@ -55,8 +105,9 @@ pub struct PlayerUi {
|
|||
bridge: Rc<Bridge>,
|
||||
/// Started at the first play: it owns a thread and the audio device.
|
||||
player: OnceCell<Player>,
|
||||
/// Decodes a whole track for its length when the file doesn't tell it.
|
||||
waves: Waveforms,
|
||||
/// The folder's audio files when playing started, for "next track".
|
||||
/// The folder's playable files when playing started, for "next track".
|
||||
queue: RefCell<Vec<PathBuf>>,
|
||||
track: RefCell<Option<Track>>,
|
||||
playing: Cell<bool>,
|
||||
|
|
@ -83,14 +134,15 @@ impl PlayerUi {
|
|||
me
|
||||
}
|
||||
|
||||
/// Plays `first`; `queue` is the folder's audio files in the order shown.
|
||||
/// Plays `first`; `queue` is the folder's playable files in the order shown.
|
||||
pub fn play(&self, first: PathBuf, queue: Vec<PathBuf>) {
|
||||
*self.queue.borrow_mut() = queue;
|
||||
self.open(first, true);
|
||||
}
|
||||
|
||||
/// Screenshots (`TUNAL_PLAY` in main.rs): shows `path` a third of the way through, with
|
||||
/// its tags and waveform read in place and no audio output.
|
||||
/// its tags and length read in place and no audio output. `TUNAL_PLAY_STATE=playing`
|
||||
/// draws it playing (the wave), otherwise paused (flat).
|
||||
pub fn debug_open(&self, path: PathBuf) {
|
||||
self.show_track(&path);
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
|
|
@ -106,8 +158,10 @@ impl PlayerUi {
|
|||
track.position = waveform.duration / 3;
|
||||
}
|
||||
self.waveform_ready(&path, Ok(waveform));
|
||||
self.show_position();
|
||||
}
|
||||
let playing = std::env::var("TUNAL_PLAY_STATE").is_ok_and(|s| s == "playing");
|
||||
self.playing.set(playing);
|
||||
self.show_position();
|
||||
}
|
||||
|
||||
fn player(&self) -> &Player {
|
||||
|
|
@ -129,7 +183,7 @@ impl PlayerUi {
|
|||
}
|
||||
}
|
||||
|
||||
/// The bar with the file name until the tags come, an empty waveform until it comes.
|
||||
/// The bar with the file name until the tags come.
|
||||
fn show_track(&self, path: &Path) {
|
||||
if let Some(old) = self.track.borrow_mut().take()
|
||||
&& let Some(ticket) = old.ticket
|
||||
|
|
@ -140,7 +194,6 @@ impl PlayerUi {
|
|||
path: path.to_path_buf(),
|
||||
duration: Duration::ZERO,
|
||||
position: Duration::ZERO,
|
||||
waveform: None,
|
||||
ticket: None,
|
||||
});
|
||||
self.playing.set(false);
|
||||
|
|
@ -153,10 +206,10 @@ impl PlayerUi {
|
|||
cover: Image::default(),
|
||||
has_cover: false,
|
||||
time: time_text(Duration::ZERO, Duration::ZERO).into(),
|
||||
time_template: time_template(Duration::ZERO).into(),
|
||||
volume: self.volume.get(),
|
||||
muted: self.muted.get(),
|
||||
});
|
||||
ui.set_player_peaks(ModelRc::default());
|
||||
ui.set_player_position(0.0);
|
||||
}
|
||||
}
|
||||
|
|
@ -168,14 +221,21 @@ impl PlayerUi {
|
|||
if play {
|
||||
player.play();
|
||||
}
|
||||
// Tags and cover.
|
||||
self.read_info_later(path);
|
||||
}
|
||||
|
||||
/// Tags and cover, read on a thread.
|
||||
fn read_info_later(&self, path: PathBuf) {
|
||||
let ui = self.ui.clone();
|
||||
let p = path.clone();
|
||||
std::thread::spawn(move || {
|
||||
let info = read_info(&p);
|
||||
let _ = ui.upgrade_in_event_loop(move |ui| with(|me| me.show_info(&ui, &p, info)));
|
||||
let info = read_info(&path);
|
||||
let _ = ui.upgrade_in_event_loop(move |ui| with(|me| me.show_info(&ui, &path, info)));
|
||||
});
|
||||
// The waveform (at once from the cache when this track was shown before).
|
||||
}
|
||||
|
||||
/// The file has no length in its header: decode it all for one (at once from the cache
|
||||
/// when this track was shown before).
|
||||
fn measure(&self, path: PathBuf) {
|
||||
let ui = self.ui.clone();
|
||||
let p = path.clone();
|
||||
let ticket = self.waves.request(path, BUCKETS, move |result| {
|
||||
|
|
@ -195,9 +255,7 @@ impl PlayerUi {
|
|||
return;
|
||||
}
|
||||
let mut data = ui.get_player();
|
||||
if let Some(title) = info.title {
|
||||
data.title = title.into();
|
||||
}
|
||||
data.title = info.title.unwrap_or_else(|| name_of(path)).into();
|
||||
data.artist = info.artist.unwrap_or_default().into();
|
||||
data.has_cover = info.cover.is_some();
|
||||
data.cover = info.cover.map(Image::from_rgba8).unwrap_or_default();
|
||||
|
|
@ -208,29 +266,14 @@ impl PlayerUi {
|
|||
if !self.is_current(path) {
|
||||
return;
|
||||
}
|
||||
// No waveform (an odd file): the bar keeps its plain track.
|
||||
if let Ok(waveform) = result {
|
||||
if let Some(track) = self.track.borrow_mut().as_mut() {
|
||||
if track.duration.is_zero() {
|
||||
track.duration = waveform.duration;
|
||||
}
|
||||
track.waveform = Some(waveform);
|
||||
}
|
||||
self.show_bars();
|
||||
// No waveform (an odd file): the length stays unknown.
|
||||
if let Ok(waveform) = result
|
||||
&& let Some(track) = self.track.borrow_mut().as_mut()
|
||||
&& track.duration.is_zero()
|
||||
{
|
||||
track.duration = waveform.duration;
|
||||
}
|
||||
}
|
||||
|
||||
/// Downsamples the waveform to the bars the seek bar has room for.
|
||||
fn show_bars(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else {
|
||||
return;
|
||||
};
|
||||
let track = self.track.borrow();
|
||||
let Some(waveform) = track.as_ref().and_then(|t| t.waveform.as_ref()) else {
|
||||
return;
|
||||
};
|
||||
let n = usize::try_from(ui.get_player_bar_count()).unwrap_or(0);
|
||||
ui.set_player_peaks(ModelRc::new(VecModel::from(bars(waveform, n))));
|
||||
self.show_position();
|
||||
}
|
||||
|
||||
fn show_position(&self) {
|
||||
|
|
@ -249,6 +292,7 @@ impl PlayerUi {
|
|||
ui.set_player_position(fraction as f32);
|
||||
let mut data = ui.get_player();
|
||||
data.time = time_text(track.position, track.duration).into();
|
||||
data.time_template = time_template(track.duration).into();
|
||||
data.playing = self.playing.get();
|
||||
ui.set_player(data);
|
||||
}
|
||||
|
|
@ -256,11 +300,20 @@ impl PlayerUi {
|
|||
fn event(&self, event: Event) {
|
||||
match event {
|
||||
Event::Opened { path, duration } => {
|
||||
if let Some(track) = self.track.borrow_mut().as_mut()
|
||||
&& track.path == path
|
||||
&& let Some(duration) = duration
|
||||
{
|
||||
track.duration = duration;
|
||||
let unknown = {
|
||||
let mut track = self.track.borrow_mut();
|
||||
match track.as_mut().filter(|t| t.path == path) {
|
||||
Some(track) => {
|
||||
if let Some(duration) = duration {
|
||||
track.duration = duration;
|
||||
}
|
||||
track.duration.is_zero() && track.ticket.is_none()
|
||||
}
|
||||
None => false,
|
||||
}
|
||||
};
|
||||
if unknown {
|
||||
self.measure(path);
|
||||
}
|
||||
}
|
||||
Event::State(state) => self.playing.set(state == State::Playing),
|
||||
|
|
@ -289,7 +342,7 @@ impl PlayerUi {
|
|||
self.show_position();
|
||||
}
|
||||
|
||||
/// The audio file after the current one, when the setting asks for it.
|
||||
/// The playable file after the current one, when the setting asks for it.
|
||||
fn next(&self) -> Option<PathBuf> {
|
||||
if !config::load::<config::Settings>("settings").player_next {
|
||||
return None;
|
||||
|
|
@ -405,12 +458,6 @@ impl PlayerUi {
|
|||
me.set_volume(me.volume.get(), !me.muted.get());
|
||||
}
|
||||
});
|
||||
let me = self.me.clone();
|
||||
ui.on_player_bars_changed(move || {
|
||||
if let Some(me) = me.upgrade() {
|
||||
me.show_bars();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -435,45 +482,40 @@ fn cover(data: &[u8]) -> Option<SharedPixelBuffer<Rgba8Pixel>> {
|
|||
))
|
||||
}
|
||||
|
||||
/// `n` bar heights 0..1: the loudest peak under each bar, the loudest bar at full height.
|
||||
fn bars(waveform: &Waveform, n: usize) -> Vec<f32> {
|
||||
let peaks = &waveform.peaks;
|
||||
if peaks.is_empty() || n == 0 {
|
||||
return Vec::new();
|
||||
}
|
||||
let amplitude: Vec<f32> = (0..n)
|
||||
.map(|i| {
|
||||
let a = i * peaks.len() / n;
|
||||
let b = ((i + 1) * peaks.len() / n).clamp(a + 1, peaks.len());
|
||||
peaks[a..b]
|
||||
.iter()
|
||||
.map(|(lo, hi)| (hi - lo) / 2.0)
|
||||
.fold(0.0, f32::max)
|
||||
})
|
||||
.collect();
|
||||
let top = amplitude.iter().copied().fold(0.0, f32::max);
|
||||
if top <= 0.0 {
|
||||
return vec![0.0; n];
|
||||
}
|
||||
amplitude.into_iter().map(|a| a / top).collect()
|
||||
}
|
||||
|
||||
fn name_of(path: &Path) -> String {
|
||||
path.file_name()
|
||||
.map(|n| n.to_string_lossy().into_owned())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn clock(d: Duration, hours: bool) -> String {
|
||||
let s = d.as_secs();
|
||||
if hours {
|
||||
format!("{}:{:02}:{:02}", s / 3600, s / 60 % 60, s % 60)
|
||||
} else {
|
||||
format!("{}:{:02}", s / 60, s % 60)
|
||||
}
|
||||
}
|
||||
|
||||
/// "1:23 / 4:56"; hours when the track has them.
|
||||
fn time_text(position: Duration, duration: Duration) -> String {
|
||||
let long = duration.as_secs() >= 3600;
|
||||
let fmt = |d: Duration| {
|
||||
let s = d.as_secs();
|
||||
if long {
|
||||
format!("{}:{:02}:{:02}", s / 3600, s / 60 % 60, s % 60)
|
||||
} else {
|
||||
format!("{}:{:02}", s / 60, s % 60)
|
||||
}
|
||||
let hours = duration.as_secs() >= 3600;
|
||||
format!("{} / {}", clock(position, hours), clock(duration, hours))
|
||||
}
|
||||
|
||||
/// The widest `time_text` of a track this long, at least "00:00 / 00:00": its digits as 0s
|
||||
/// (the widest digit in most fonts) and the position as long as the length.
|
||||
fn time_template(duration: Duration) -> String {
|
||||
let widest = |s: String| -> String {
|
||||
s.chars()
|
||||
.map(|c| if c.is_ascii_digit() { '0' } else { c })
|
||||
.collect()
|
||||
};
|
||||
format!("{} / {}", fmt(position), fmt(duration))
|
||||
let one = widest(clock(duration, duration.as_secs() >= 3600));
|
||||
let one = if one.len() < 5 {
|
||||
"00:00".to_owned()
|
||||
} else {
|
||||
one
|
||||
};
|
||||
format!("{one} / {one}")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,12 @@ use crate::dnd::parse_uri_list;
|
|||
use crate::jobs_bridge::Bridge;
|
||||
use crate::{MainWindow, MapRow, ReleaseRow, TagEditorData, TagField, TagLookupData};
|
||||
|
||||
/// Extensions lofty reads and writes.
|
||||
const AUDIO: [&str; 14] = [
|
||||
"mp3", "flac", "ogg", "oga", "opus", "m4a", "m4b", "mp4", "aac", "wav", "wv", "ape", "mpc",
|
||||
"aif",
|
||||
/// Extensions of the formats lofty reads and writes: MPEG audio (ID3v2/APE), FLAC, Ogg
|
||||
/// Vorbis/Opus/Speex (Vorbis comments), MP4/M4A (atoms), WAV, AIFF, APE, WavPack, Musepack,
|
||||
/// AAC. Opened, a file goes by its content, so a misnamed one still works.
|
||||
pub const TAGGABLE: [&str; 25] = [
|
||||
"mp3", "mp2", "mp1", "flac", "ogg", "oga", "opus", "spx", "m4a", "m4b", "m4p", "m4r", "mp4",
|
||||
"aac", "wav", "wave", "aif", "aiff", "aifc", "ape", "wv", "mpc", "mp+", "mpp", "3gp",
|
||||
];
|
||||
|
||||
/// Releases the search lists, and how many get a cover (each costs a request).
|
||||
|
|
@ -35,12 +37,12 @@ const COVERED_RELEASES: usize = 6;
|
|||
const SHOWN_COVER: u32 = 256;
|
||||
const MAX_COVER_BYTES: u64 = 16 * 1024 * 1024;
|
||||
|
||||
/// An audio file we can edit: local, with a known extension.
|
||||
pub fn is_audio(uri: &Uri) -> bool {
|
||||
/// An audio file we can edit: local, in a format lofty writes.
|
||||
pub fn can_tag(uri: &Uri) -> bool {
|
||||
uri.to_path().is_some_and(|p| {
|
||||
p.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.is_some_and(|e| AUDIO.iter().any(|a| e.eq_ignore_ascii_case(a)))
|
||||
.is_some_and(|e| TAGGABLE.iter().any(|a| e.eq_ignore_ascii_case(a)))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -992,10 +994,21 @@ fn write_all(
|
|||
) {
|
||||
let sync = std::env::var_os("TUNAL_TAGS_SYNC").is_some();
|
||||
let weak = ui.clone();
|
||||
// The playing track is closed while its file is rewritten, then plays on.
|
||||
let player = crate::player_bridge::handle();
|
||||
let paths: Vec<PathBuf> = jobs.iter().map(|(p, _)| p.clone()).collect();
|
||||
let done = move |ui: &MainWindow, failures: Vec<String>| {
|
||||
crate::player_bridge::tags_changed(&paths);
|
||||
done(ui, failures);
|
||||
};
|
||||
let run = move || {
|
||||
let mut failures = Vec::new();
|
||||
for (i, (path, edit)) in jobs.iter().enumerate() {
|
||||
if let Err(e) = tunal_tags::write(path, edit) {
|
||||
let written = match &player {
|
||||
Some(player) => player.without(path, || tunal_tags::write(path, edit)),
|
||||
None => tunal_tags::write(path, edit),
|
||||
};
|
||||
if let Err(e) = written {
|
||||
failures.push(format!("{}: {e}", name_of(path)));
|
||||
}
|
||||
if !sync {
|
||||
|
|
|
|||
|
|
@ -167,11 +167,9 @@ export component MainWindow inherits Window {
|
|||
// Tags were written to the files; the argument is the message for a toast.
|
||||
callback tags-written(string);
|
||||
|
||||
// The quick player (player_bridge.rs): `player-peaks` has `player-bar-count` bars.
|
||||
// The quick player (player_bridge.rs).
|
||||
in property <PlayerData> player;
|
||||
in property <[float]> player-peaks;
|
||||
in property <float> player-position;
|
||||
out property <int> player-bar-count: player-bar.bar-count;
|
||||
callback player-toggle();
|
||||
callback player-close();
|
||||
// Fraction of the track.
|
||||
|
|
@ -180,7 +178,6 @@ export component MainWindow inherits Window {
|
|||
callback player-step(int);
|
||||
callback player-volume(float);
|
||||
callback player-mute();
|
||||
callback player-bars-changed();
|
||||
|
||||
// Properties (properties.rs) and Open with (open.rs).
|
||||
in property <PropertiesInfo> properties;
|
||||
|
|
@ -637,9 +634,8 @@ export component MainWindow inherits Window {
|
|||
}
|
||||
}
|
||||
|
||||
player-bar := PlayerBar {
|
||||
PlayerBar {
|
||||
data: root.player;
|
||||
peaks: root.player-peaks;
|
||||
position: root.player-position;
|
||||
toggle => {
|
||||
root.player-toggle();
|
||||
|
|
@ -659,9 +655,6 @@ export component MainWindow inherits Window {
|
|||
mute => {
|
||||
root.player-mute();
|
||||
}
|
||||
changed bar-count => {
|
||||
root.player-bars-changed();
|
||||
}
|
||||
}
|
||||
|
||||
StatusBar {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { Theme } from "../theme.slint";
|
||||
import { Motion } from "../motion.slint";
|
||||
import { Shapes } from "../shapes.slint";
|
||||
import { Icons } from "../components/icon.slint";
|
||||
import { IconButton } from "../components/icon-button.slint";
|
||||
import { StateLayer } from "../components/state-layer.slint";
|
||||
|
|
@ -15,6 +16,8 @@ export struct PlayerData {
|
|||
has-cover: bool,
|
||||
// "1:23 / 4:56"
|
||||
time: string,
|
||||
// The widest `time` of this track ("00:00 / 00:00"): the label keeps its width.
|
||||
time-template: string,
|
||||
// 0..1
|
||||
volume: float,
|
||||
muted: bool,
|
||||
|
|
@ -46,27 +49,47 @@ component PlayButton inherits StateLayer {
|
|||
}
|
||||
}
|
||||
|
||||
// The waveform seek bar: one bar per peak, the played part tinted. A line follows the
|
||||
// pointer; press and drag scrub, release seeks; ←/→ step. Nothing here animates: the tint
|
||||
// moves only when the position does (while playing or scrubbing).
|
||||
// The wavy seek bar: the played part is a sine line that travels while the track plays and
|
||||
// flattens when it pauses; a gap, the handle at the playhead, another gap, then the flat rest
|
||||
// of the track with a stop dot at its end. Press or drag anywhere: the handle follows the
|
||||
// pointer and release seeks; ←/→ step. Paused (or under reduced motion) nothing moves, so
|
||||
// nothing repaints.
|
||||
component SeekBar {
|
||||
// Bar heights 0..1, `bar-count` of them (none while the waveform is being read).
|
||||
in property <[float]> peaks;
|
||||
// 0..1
|
||||
in property <float> position;
|
||||
in property <bool> playing;
|
||||
callback seek(float);
|
||||
callback step(int);
|
||||
|
||||
property <length> bar-width: 3px;
|
||||
property <length> pitch: 5px;
|
||||
out property <int> bar-count: max(1, floor(root.width / root.pitch));
|
||||
property <float> shown: touch.pressed ? clamp(touch.mouse-x / root.width, 0, 1) : root.position;
|
||||
property <length> stroke: Theme.seek-stroke;
|
||||
property <length> gap: Theme.space-1;
|
||||
// The wave swells when playback starts and flattens when it stops.
|
||||
property <length> amplitude: root.playing ? Theme.seek-amplitude : 0;
|
||||
animate amplitude {
|
||||
duration: Motion.time(Motion.medium2);
|
||||
easing: Motion.standard;
|
||||
}
|
||||
// One wavelength per period while there is a wave to move.
|
||||
property <float> phase: root.amplitude > 0 && !Motion.reduced ? Math.mod(animation-tick() / Motion.wave-period, 1) : 0;
|
||||
// The handle's centre runs from half a handle in to half a handle before the end.
|
||||
property <length> travel: max(1px, root.width - Theme.seek-handle-width);
|
||||
property <float> shown: touch.pressed ? clamp((touch.mouse-x - Theme.seek-handle-width / 2) / root.travel, 0, 1) : root.position;
|
||||
property <length> head: Theme.seek-handle-width / 2 + root.shown * root.travel;
|
||||
property <length> wave-end: max(0, root.head - Theme.seek-handle-width / 2 - root.gap);
|
||||
property <length> rest-start: root.head + Theme.seek-handle-width / 2 + root.gap;
|
||||
property <length> band: 2 * root.amplitude + root.stroke;
|
||||
property <length> band-top: (root.height - root.band) / 2;
|
||||
|
||||
min-width: 120px;
|
||||
min-width: 64px;
|
||||
accessible-role: slider;
|
||||
accessible-label: "Position";
|
||||
accessible-value: round(root.position * 100) + "%";
|
||||
|
||||
// The band's centre line `x` along the wave (`Shapes.wave`'s curve), from the bar's top.
|
||||
pure function centre(x: length) -> length {
|
||||
root.band-top + root.amplitude * (1 - Math.sin((x / Theme.seek-wave-length - root.phase) * 360deg)) + root.stroke / 2
|
||||
}
|
||||
|
||||
keys := FocusScope {
|
||||
key-pressed(event) => {
|
||||
if event.text == Key.LeftArrow {
|
||||
|
|
@ -81,35 +104,67 @@ component SeekBar {
|
|||
}
|
||||
}
|
||||
|
||||
// Before the waveform comes: a plain track.
|
||||
if root.peaks.length == 0: Rectangle {
|
||||
// The played part, inset by half a stroke at each end for the round caps.
|
||||
if root.wave-end > root.stroke: Path {
|
||||
x: root.stroke / 2;
|
||||
y: root.band-top;
|
||||
width: root.wave-end - root.stroke;
|
||||
height: root.band;
|
||||
viewbox-width: max(1, self.width / 1px);
|
||||
viewbox-height: root.band / 1px;
|
||||
commands: Shapes.wave(self.width / 1px, Theme.seek-wave-length / 1px, root.amplitude / 1px, root.stroke / 1px, root.phase);
|
||||
fill: Theme.primary;
|
||||
}
|
||||
|
||||
if root.wave-end > 0: Rectangle {
|
||||
x: 0;
|
||||
y: root.centre(0) - root.stroke / 2;
|
||||
width: min(root.stroke, root.wave-end);
|
||||
height: root.stroke;
|
||||
border-radius: Theme.corner-full(self.height);
|
||||
background: Theme.primary;
|
||||
}
|
||||
|
||||
if root.wave-end > root.stroke: Rectangle {
|
||||
x: root.wave-end - root.stroke;
|
||||
y: root.centre(root.wave-end - root.stroke) - root.stroke / 2;
|
||||
width: root.stroke;
|
||||
height: root.stroke;
|
||||
border-radius: Theme.corner-full(self.height);
|
||||
background: Theme.primary;
|
||||
}
|
||||
|
||||
// The rest of the track, and the stop dot at its end.
|
||||
if root.rest-start < root.width: Rectangle {
|
||||
x: root.rest-start;
|
||||
y: (root.height - self.height) / 2;
|
||||
height: Theme.wave-stroke;
|
||||
border-radius: self.height / 2;
|
||||
width: root.width - self.x;
|
||||
height: root.stroke;
|
||||
border-radius: Theme.corner-full(self.height);
|
||||
background: Theme.outline-variant;
|
||||
|
||||
Rectangle {
|
||||
x: 0;
|
||||
width: parent.width * root.shown;
|
||||
border-radius: parent.border-radius;
|
||||
background: Theme.primary;
|
||||
}
|
||||
}
|
||||
|
||||
for peak[i] in root.peaks: Rectangle {
|
||||
x: i * root.pitch;
|
||||
width: root.bar-width;
|
||||
height: max(root.bar-width, peak * root.height);
|
||||
if root.rest-start < root.width - 2 * root.stroke: Rectangle {
|
||||
x: root.width - self.width;
|
||||
y: (root.height - self.height) / 2;
|
||||
border-radius: self.width / 2;
|
||||
background: (i + 0.5) / root.peaks.length < root.shown ? Theme.primary : Theme.outline-variant;
|
||||
width: root.stroke;
|
||||
height: root.stroke;
|
||||
border-radius: Theme.corner-full(self.height);
|
||||
background: Theme.primary;
|
||||
}
|
||||
|
||||
if touch.has-hover || touch.pressed: Rectangle {
|
||||
x: clamp(touch.mouse-x, 0, root.width) - self.width / 2;
|
||||
width: Theme.focus-ring-width;
|
||||
border-radius: self.width / 2;
|
||||
background: Theme.on-surface;
|
||||
// The handle: taller on hover and focus, thinner while held.
|
||||
Rectangle {
|
||||
x: root.head - self.width / 2;
|
||||
y: (root.height - self.height) / 2;
|
||||
width: touch.pressed ? Theme.seek-handle-width / 2 : Theme.seek-handle-width;
|
||||
height: touch.has-hover || touch.pressed || keys.has-focus ? Theme.seek-handle-height + Theme.space-1 : Theme.seek-handle-height;
|
||||
border-radius: Theme.corner-full(self.width);
|
||||
background: Theme.primary;
|
||||
animate width, height {
|
||||
duration: Motion.time(Motion.short3);
|
||||
easing: Motion.standard;
|
||||
}
|
||||
}
|
||||
|
||||
// Keyboard focus: a ring round the bar.
|
||||
|
|
@ -128,7 +183,7 @@ component SeekBar {
|
|||
keys.focus();
|
||||
}
|
||||
if event.kind == PointerEventKind.up && event.button == PointerEventButton.left {
|
||||
root.seek(clamp(self.mouse-x / root.width, 0, 1));
|
||||
root.seek(root.shown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -191,11 +246,11 @@ component VolumeBar {
|
|||
|
||||
// The quick player under the panes. It slides up from the status bar when a track opens
|
||||
// and back down when closed: occasional, so it moves (height, emphasized decelerate).
|
||||
// Narrow, the seek bar shrinks first; then the parts go in order: the volume slider (the
|
||||
// mute button stays), half the title width, the cover and artist line, the mute button.
|
||||
export component PlayerBar inherits Rectangle {
|
||||
in property <PlayerData> data;
|
||||
in property <[float]> peaks;
|
||||
in property <float> position;
|
||||
out property <int> bar-count: seek.bar-count;
|
||||
callback toggle();
|
||||
callback close();
|
||||
callback seek(float);
|
||||
|
|
@ -205,6 +260,27 @@ export component PlayerBar inherits Rectangle {
|
|||
|
||||
property <length> card-height: 64px;
|
||||
property <length> full: root.card-height + Theme.space-2;
|
||||
property <length> card-width: root.width - 2 * Theme.space-3;
|
||||
property <length> gap: Theme.space-3;
|
||||
property <length> cover-size: 48px;
|
||||
property <length> button: 40px;
|
||||
property <length> play-size: 48px;
|
||||
property <length> volume-width: 72px;
|
||||
property <length> info-wide: 180px;
|
||||
property <length> info-narrow: 120px;
|
||||
property <length> info-title: 96px;
|
||||
// The time label's width: its widest text, so the digits never push the row.
|
||||
property <length> time-width: time-probe.preferred-width;
|
||||
// Padding, play button, time, close button and their gaps: always there.
|
||||
property <length> base: Theme.space-2 + Theme.space-3 + root.play-size + root.time-width + root.button + 3 * root.gap;
|
||||
property <length> with-mute: root.base + root.button + root.gap;
|
||||
property <length> with-cover: root.with-mute + root.cover-size + root.gap;
|
||||
// 0 everything, 1 no volume slider, 2 narrower title, 3 no cover or artist, 4 no mute.
|
||||
property <int> tier: root.card-width >= root.with-cover + root.info-wide + root.volume-width + 2 * root.gap + 160px ? 0
|
||||
: root.card-width >= root.with-cover + root.info-wide + root.gap + 160px ? 1
|
||||
: root.card-width >= root.with-cover + root.info-narrow + root.gap + 120px ? 2
|
||||
: root.card-width >= root.with-mute + root.info-title + root.gap + 80px ? 3
|
||||
: 4;
|
||||
|
||||
height: root.data.open ? root.full : 0;
|
||||
clip: true;
|
||||
|
|
@ -216,22 +292,29 @@ export component PlayerBar inherits Rectangle {
|
|||
// Anchored to the bottom: it rises out from behind the status bar.
|
||||
Rectangle {
|
||||
x: Theme.space-3;
|
||||
width: root.width - 2 * Theme.space-3;
|
||||
width: root.card-width;
|
||||
height: root.card-height;
|
||||
y: root.height - root.full + Theme.space-2;
|
||||
border-radius: Theme.corner-full(self.height);
|
||||
background: Theme.surface-container-high;
|
||||
|
||||
time-probe := Text {
|
||||
visible: false;
|
||||
text: root.data.time-template;
|
||||
font-size: Theme.label-medium.size;
|
||||
font-weight: Theme.label-medium.weight;
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-2;
|
||||
padding-right: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
spacing: root.gap;
|
||||
alignment: stretch;
|
||||
|
||||
VerticalLayout {
|
||||
if root.tier < 3: VerticalLayout {
|
||||
alignment: center;
|
||||
Shape {
|
||||
size: 48px;
|
||||
size: root.cover-size;
|
||||
shape: ShapeKind.cookie9;
|
||||
fill: Theme.tertiary-container;
|
||||
glyph: Icons.music-note;
|
||||
|
|
@ -241,9 +324,11 @@ export component PlayerBar inherits Rectangle {
|
|||
}
|
||||
}
|
||||
|
||||
// The tier-3 title-only column gets the cover's padding back on its left.
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
width: 180px;
|
||||
padding-left: root.tier < 3 ? 0 : Theme.space-2;
|
||||
width: root.tier < 2 ? root.info-wide : root.tier == 2 ? root.info-narrow : root.info-title;
|
||||
Text {
|
||||
text: root.data.title;
|
||||
color: Theme.on-surface;
|
||||
|
|
@ -251,7 +336,7 @@ export component PlayerBar inherits Rectangle {
|
|||
font-weight: Theme.label-large.weight;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
if root.tier < 3: Text {
|
||||
text: root.data.artist;
|
||||
color: Theme.on-surface-variant;
|
||||
font-size: Theme.body-small.size;
|
||||
|
|
@ -271,10 +356,10 @@ export component PlayerBar inherits Rectangle {
|
|||
}
|
||||
}
|
||||
|
||||
seek := SeekBar {
|
||||
SeekBar {
|
||||
horizontal-stretch: 1;
|
||||
peaks: root.peaks;
|
||||
position: root.position;
|
||||
playing: root.data.playing;
|
||||
seek(f) => {
|
||||
root.seek(f);
|
||||
}
|
||||
|
|
@ -284,14 +369,16 @@ export component PlayerBar inherits Rectangle {
|
|||
}
|
||||
|
||||
Text {
|
||||
width: root.time-width;
|
||||
text: root.data.time;
|
||||
color: Theme.on-surface-variant;
|
||||
font-size: Theme.label-medium.size;
|
||||
font-weight: Theme.label-medium.weight;
|
||||
horizontal-alignment: right;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
VerticalLayout {
|
||||
if root.tier < 4: VerticalLayout {
|
||||
alignment: center;
|
||||
IconButton {
|
||||
icon: root.data.muted ? Icons.volume-off : Icons.volume-up;
|
||||
|
|
@ -302,7 +389,7 @@ export component PlayerBar inherits Rectangle {
|
|||
}
|
||||
}
|
||||
|
||||
VolumeBar {
|
||||
if root.tier == 0: VolumeBar {
|
||||
value: root.data.volume;
|
||||
muted: root.data.muted;
|
||||
changed-value(v) => {
|
||||
|
|
|
|||
|
|
@ -66,6 +66,13 @@ export global Theme {
|
|||
out property <length> wave-stroke: 3px;
|
||||
out property <length> wave-amplitude: 2px;
|
||||
out property <length> wave-length: 20px;
|
||||
// The player's wavy seek bar: stroke, wave height above its centre, one wavelength, and
|
||||
// the handle at the playhead (a pill).
|
||||
out property <length> seek-stroke: 4px;
|
||||
out property <length> seek-amplitude: 3px;
|
||||
out property <length> seek-wave-length: 32px;
|
||||
out property <length> seek-handle-width: 4px;
|
||||
out property <length> seek-handle-height: 20px;
|
||||
// Fully rounded ends for a shape of the given height.
|
||||
public pure function corner-full(height: length) -> length {
|
||||
height / 2
|
||||
|
|
|
|||
Loading…
Reference in a new issue