S023: quick player bar with waveform seek bar

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-19 00:11:52 -06:00
commit 26073c4e7b
17 changed files with 960 additions and 11 deletions

View file

@ -92,6 +92,7 @@ Never modify: `PROMPT.md` (the user's brief), the user's other projects under `~
| `TUNAL_SETTINGS=<0-4> cargo run -p tunal -- <dir> --screenshot <png> --size 1000x700` (`XDG_CONFIG_HOME=<scratch>`) | settings dialog page over a folder | S013 |
| `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 |
| `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_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 |
Don't assume a tool exists: check first. When your plan creates a tool, add its row here.

View file

@ -10,10 +10,10 @@ A quick player bar: Space or 'Play' on an audio file, waveform seek bar with scr
crates/tunal-player API; crates/tunal/src/actions.rs; `animate` skill.
## Steps
- [ ] Play action (Space on selected audio, context menu) and a player bar that slides in at the bottom: play/pause, title/artist (tags crate), time, volume, close.
- [ ] Waveform seek bar: bars from peaks (downsampled to width), played part tinted, hover line, click/drag seek, ←/→ keys.
- [ ] Repaint only while playing or scrubbing.
- [ ] PROGRESS entry, INDEX line, commit `S023: …`
- [x] Play action (Space on selected audio, context menu) and a player bar that slides in at the bottom: play/pause, title/artist (tags crate), time, volume, close.
- [x] Waveform seek bar: bars from peaks (downsampled to width), played part tinted, hover line, click/drag seek, ←/→ keys.
- [x] Repaint only while playing or scrubbing.
- [x] PROGRESS entry, INDEX line, commit `S023: …`
## End criteria
- `cargo build --workspace`, `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --check` pass.

View file

@ -51,7 +51,7 @@ Tracker: https://claude.ai/artifact/4X8YCk3cQjUGyuyCqGuU7v
## 08 Audio player
- [x] [S022 — Audio player backend](08%20Audio%20player/S022-player-backend.md) · Opus medium
- [ ] [S023 — Quick player with waveform seek bar](08%20Audio%20player/S023-player-ui.md) · Opus medium
- [x] [S023 — Quick player with waveform seek bar](08%20Audio%20player/S023-player-ui.md) · Opus medium
## 09 Devices

View file

@ -15,6 +15,7 @@ tunal-devices = { path = "../tunal-devices" }
tunal-dirmeta = { path = "../tunal-dirmeta" }
tunal-thumbs = { path = "../tunal-thumbs" }
tunal-tags = { path = "../tunal-tags" }
tunal-player = { path = "../tunal-player" }
image.workspace = true
jiff.workspace = true
serde.workspace = true

View file

@ -14,6 +14,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::properties::Properties;
use crate::shell::Shell;
use crate::shell::pane::Pane;
@ -39,6 +40,7 @@ pub enum Action {
Properties,
Appearance,
EditTags,
Play,
}
enum Shortcut {
@ -47,7 +49,7 @@ enum Shortcut {
}
impl Action {
pub const ALL: [Action; 16] = [
pub const ALL: [Action; 17] = [
Self::Cut,
Self::Copy,
Self::Paste,
@ -64,6 +66,7 @@ impl Action {
Self::Properties,
Self::Appearance,
Self::EditTags,
Self::Play,
];
pub fn id(self) -> &'static str {
@ -84,6 +87,7 @@ impl Action {
Self::Properties => "properties",
Self::Appearance => "appearance",
Self::EditTags => "edit-tags",
Self::Play => "play",
}
}
@ -109,6 +113,7 @@ impl Action {
Self::Properties => "Properties",
Self::Appearance => "Folder appearance…",
Self::EditTags => "Edit tags…",
Self::Play => "Play",
}
}
@ -131,10 +136,11 @@ impl Action {
Self::Properties => "\u{e88e}",
Self::Appearance => "\u{e40a}",
Self::EditTags => "\u{e892}",
Self::Play => "\u{e037}",
}
}
/// `(key, shift)`; every shortcut but F2 and Delete holds Ctrl.
/// `(key, shift)`; every shortcut but F2, Delete and Space holds Ctrl.
fn shortcut(self) -> Option<(Shortcut, bool)> {
Some(match self {
Self::Cut => (Shortcut::Char('x'), false),
@ -146,6 +152,7 @@ impl Action {
Self::Trash => (Shortcut::Key(Key::Delete), false),
Self::Delete => (Shortcut::Key(Key::Delete), true),
Self::Settings => (Shortcut::Char(','), false),
Self::Play => (Shortcut::Key(Key::Space), false),
Self::Restore
| Self::EmptyTrash
| Self::Open
@ -169,7 +176,11 @@ impl Action {
)
}
Some((Shortcut::Key(key), shift)) => {
let name = if key == Key::F2 { "F2" } else { "Del" };
let name = match key {
Key::F2 => "F2",
Key::Space => "Space",
_ => "Del",
};
format!("{}{name}", if shift { "Shift+" } else { "" })
}
}
@ -203,7 +214,7 @@ impl Action {
Self::Open | Self::OpenWith => files && ctx.selected > 0,
Self::Properties => true,
Self::Appearance => files && ctx.selected <= 1,
Self::EditTags => files && ctx.audio,
Self::EditTags | Self::Play => files && ctx.audio,
}
}
}
@ -242,6 +253,7 @@ pub struct Actions {
properties: Rc<Properties>,
appearance: Rc<Appearance>,
tags: Rc<Tags>,
player: Rc<PlayerUi>,
}
impl Actions {
@ -251,6 +263,7 @@ impl Actions {
let properties = Properties::attach(ui, locations.clone());
let appearance = Appearance::attach(ui, bridge.elevation());
let tags = Tags::attach(ui, bridge.clone());
let player = PlayerUi::attach(ui, bridge.clone());
let actions = Rc::new_cyclic(|me| Self {
me: me.clone(),
ui: ui.as_weak(),
@ -264,6 +277,7 @@ impl Actions {
properties,
appearance,
tags,
player,
});
let me = actions.me.clone();
let shell_weak = Rc::downgrade(shell);
@ -295,6 +309,11 @@ impl Actions {
self.tags.debug_open(spec);
}
/// Screenshots: shows a file in the player bar (see `TUNAL_PLAY` in main.rs).
pub fn debug_play(&self, path: std::path::PathBuf) {
self.player.debug_open(path);
}
/// Runs a file job (drag and drop).
pub fn submit(&self, kind: JobKind) {
self.bridge.submit(kind);
@ -433,7 +452,7 @@ impl Actions {
}
/// A key the window saw: true when it was an enabled action's shortcut.
fn key(&self, text: &str, ctrl: bool, shift: bool, alt: bool) -> bool {
pub fn key(&self, text: &str, ctrl: bool, shift: bool, alt: bool) -> bool {
if alt || self.bridge.modal() {
return false;
}
@ -545,6 +564,19 @@ impl Actions {
}
return;
}
Action::Play => {
// The folder's audio files queue up after the first one chosen.
let queue: Vec<_> = pane
.model
.shown_files()
.iter()
.filter(|u| tags_bridge::is_audio(u))
.filter_map(|u| u.to_path())
.collect();
if let Some(first) = uris.first().and_then(|u| u.to_path()) {
self.player.play(first, queue);
}
}
Action::Settings => {
if let Some(ui) = self.ui.upgrade() {
ui.invoke_show_settings(0);

View file

@ -153,6 +153,8 @@ pub struct Settings {
pub preview_max_mib: u32,
/// Previews on network file systems (off: browsing them stays fast).
pub preview_remote: bool,
/// The player goes on to the next audio file of the folder when a track ends.
pub player_next: bool,
}
impl Default for Settings {
@ -174,6 +176,7 @@ impl Default for Settings {
preview_frame: 10,
preview_max_mib: 64,
preview_remote: false,
player_next: true,
}
}
}

View file

@ -1088,6 +1088,21 @@ impl FolderModel {
names.into_iter().map(|n| dir.join(n)).collect()
}
/// The files shown (no folders), in the order shown.
pub fn shown_files(&self) -> Vec<Uri> {
let s = self.state.borrow();
let Some(dir) = &s.dir else {
return Vec::new();
};
s.rows
.iter()
.filter_map(|r| match r {
Row::Item(i) if !s.items[*i].is_dir => Some(dir.join(&s.items[*i].entry.name)),
_ => None,
})
.collect()
}
/// What a drag from `row` carries: the selection when the row is in it, else the row.
pub fn drag_uris(&self, row: usize) -> Vec<Uri> {
let Some(name) = self.name_at(row) else {

View file

@ -8,6 +8,7 @@ mod icons;
mod jobs_bridge;
mod menus;
mod open;
mod player_bridge;
mod properties;
mod screenshot;
mod settings;
@ -105,6 +106,10 @@ fn window(
if let Ok(spec) = std::env::var("TUNAL_TAGS") {
shell.debug_tags(&spec);
}
// `TUNAL_PLAY=<audio file>` shows it in the player bar, a third of the way through.
if let Some(path) = std::env::var_os("TUNAL_PLAY") {
shell.debug_play(PathBuf::from(path));
}
Ok((ui, shell))
}

View file

@ -44,6 +44,7 @@ impl Context {
let ids: &[&str] = match self {
Self::File => &[
"open",
"play",
"open-with",
"edit-tags",
"-",
@ -77,6 +78,7 @@ impl Context {
"properties",
],
Self::Multiple => &[
"play",
"edit-tags",
"cut",
"copy",

View file

@ -0,0 +1,479 @@
//! 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
//! thread, where the bar's state lives (a thread-local, so only plain data crosses threads).
use std::cell::{Cell, OnceCell, RefCell};
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 crate::config;
use crate::jobs_bridge::Bridge;
use crate::{MainWindow, PlayerData};
/// Peaks read per track; the bar draws fewer, one per bar.
const BUCKETS: usize = 600;
/// 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;
thread_local! {
static PLAYER: RefCell<Weak<PlayerUi>> = const { RefCell::new(Weak::new()) };
}
/// Runs `f` on the UI thread's player, if it is still there.
fn with(f: impl FnOnce(&PlayerUi)) {
if let Some(p) = PLAYER.with(|w| w.borrow().upgrade()) {
f(&p);
}
}
struct Track {
path: PathBuf,
duration: Duration,
position: Duration,
waveform: Option<Arc<Waveform>>,
ticket: Option<WaveTicket>,
}
/// Title, artist and cover, read off the UI thread.
struct Info {
title: Option<String>,
artist: Option<String>,
cover: Option<SharedPixelBuffer<Rgba8Pixel>>,
}
pub struct PlayerUi {
me: Weak<PlayerUi>,
ui: slint::Weak<MainWindow>,
bridge: Rc<Bridge>,
/// Started at the first play: it owns a thread and the audio device.
player: OnceCell<Player>,
waves: Waveforms,
/// The folder's audio files when playing started, for "next track".
queue: RefCell<Vec<PathBuf>>,
track: RefCell<Option<Track>>,
playing: Cell<bool>,
volume: Cell<f32>,
muted: Cell<bool>,
}
impl PlayerUi {
pub fn attach(ui: &MainWindow, bridge: Rc<Bridge>) -> Rc<Self> {
let me = Rc::new_cyclic(|me| Self {
me: me.clone(),
ui: ui.as_weak(),
bridge,
player: OnceCell::new(),
waves: Waveforms::new(),
queue: RefCell::new(Vec::new()),
track: RefCell::new(None),
playing: Cell::new(false),
volume: Cell::new(1.0),
muted: Cell::new(false),
});
PLAYER.with(|w| *w.borrow_mut() = me.me.clone());
me.bind(ui);
me
}
/// Plays `first`; `queue` is the folder's audio 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.
pub fn debug_open(&self, path: PathBuf) {
self.show_track(&path);
if let Some(ui) = self.ui.upgrade() {
self.show_info(&ui, &path, read_info(&path));
}
let (tx, rx) = std::sync::mpsc::channel();
self.waves.request(path.clone(), BUCKETS, move |r| {
let _ = tx.send(r);
});
if let Ok(Ok(waveform)) = rx.recv() {
if let Some(track) = self.track.borrow_mut().as_mut() {
track.duration = waveform.duration;
track.position = waveform.duration / 3;
}
self.waveform_ready(&path, Ok(waveform));
self.show_position();
}
}
fn player(&self) -> &Player {
self.player.get_or_init(|| {
let ui = self.ui.clone();
let player = Player::new(move |event| {
let _ = ui.upgrade_in_event_loop(move |_| with(|p| p.event(event)));
});
player.set_volume(self.effective_volume());
player
})
}
fn effective_volume(&self) -> f32 {
if self.muted.get() {
0.0
} else {
self.volume.get()
}
}
/// The bar with the file name until the tags come, an empty waveform until it comes.
fn show_track(&self, path: &Path) {
if let Some(old) = self.track.borrow_mut().take()
&& let Some(ticket) = old.ticket
{
ticket.cancel();
}
*self.track.borrow_mut() = Some(Track {
path: path.to_path_buf(),
duration: Duration::ZERO,
position: Duration::ZERO,
waveform: None,
ticket: None,
});
self.playing.set(false);
if let Some(ui) = self.ui.upgrade() {
ui.set_player(PlayerData {
open: true,
playing: false,
title: name_of(path).into(),
artist: Default::default(),
cover: Image::default(),
has_cover: false,
time: time_text(Duration::ZERO, Duration::ZERO).into(),
volume: self.volume.get(),
muted: self.muted.get(),
});
ui.set_player_peaks(ModelRc::default());
ui.set_player_position(0.0);
}
}
fn open(&self, path: PathBuf, play: bool) {
self.show_track(&path);
let player = self.player();
player.open(path.clone());
if play {
player.play();
}
// Tags and cover.
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)));
});
// The waveform (at once from the cache when this track was shown before).
let ui = self.ui.clone();
let p = path.clone();
let ticket = self.waves.request(path, BUCKETS, move |result| {
let _ = ui.upgrade_in_event_loop(move |_| with(|me| me.waveform_ready(&p, result)));
});
if let Some(track) = self.track.borrow_mut().as_mut() {
track.ticket = Some(ticket);
}
}
fn is_current(&self, path: &Path) -> bool {
self.track.borrow().as_ref().is_some_and(|t| t.path == path)
}
fn show_info(&self, ui: &MainWindow, path: &Path, info: Info) {
if !self.is_current(path) {
return;
}
let mut data = ui.get_player();
if let Some(title) = info.title {
data.title = title.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();
ui.set_player(data);
}
fn waveform_ready(&self, path: &Path, result: Result<Arc<Waveform>, tunal_player::Error>) {
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();
}
}
/// 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))));
}
fn show_position(&self) {
let Some(ui) = self.ui.upgrade() else {
return;
};
let track = self.track.borrow();
let Some(track) = track.as_ref() else {
return;
};
let fraction = if track.duration.is_zero() {
0.0
} else {
(track.position.as_secs_f64() / track.duration.as_secs_f64()).clamp(0.0, 1.0)
};
ui.set_player_position(fraction as f32);
let mut data = ui.get_player();
data.time = time_text(track.position, track.duration).into();
data.playing = self.playing.get();
ui.set_player(data);
}
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;
}
}
Event::State(state) => self.playing.set(state == State::Playing),
Event::Position(position) => {
if let Some(track) = self.track.borrow_mut().as_mut() {
track.position = position;
}
}
Event::Ended => {
self.playing.set(false);
if let Some(next) = self.next() {
self.open(next, true);
return;
}
}
Event::Error(tunal_player::Error::Cancelled) => {}
Event::Error(e) => {
self.playing.set(false);
let name = self.track.borrow().as_ref().map(|t| name_of(&t.path));
self.bridge.notify(match name {
Some(name) => format!("Can't play {name}: {e}"),
None => format!("Can't play: {e}"),
});
}
}
self.show_position();
}
/// The audio 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;
}
let track = self.track.borrow();
let current = &track.as_ref()?.path;
let queue = self.queue.borrow();
let i = queue.iter().position(|p| p == current)?;
queue.get(i + 1).cloned()
}
fn toggle(&self) {
if self.track.borrow().is_none() {
return;
}
if self.playing.get() {
self.player().pause();
} else {
self.player().play();
}
}
fn close(&self) {
if let Some(player) = self.player.get() {
player.stop();
}
if let Some(track) = self.track.borrow_mut().take()
&& let Some(ticket) = track.ticket
{
ticket.cancel();
}
self.playing.set(false);
if let Some(ui) = self.ui.upgrade() {
let mut data = ui.get_player();
data.open = false;
data.playing = false;
ui.set_player(data);
}
}
fn seek_to(&self, to: Duration) {
let to = {
let mut track = self.track.borrow_mut();
let Some(track) = track.as_mut() else {
return;
};
let to = to.min(track.duration);
track.position = to;
to
};
self.player().seek(to);
self.show_position();
}
fn set_volume(&self, volume: f32, muted: bool) {
self.volume.set(volume.clamp(0.0, 1.0));
self.muted.set(muted);
if let Some(player) = self.player.get() {
player.set_volume(self.effective_volume());
}
if let Some(ui) = self.ui.upgrade() {
let mut data = ui.get_player();
data.volume = self.volume.get();
data.muted = muted;
ui.set_player(data);
}
}
fn bind(&self, ui: &MainWindow) {
let me = self.me.clone();
ui.on_player_toggle(move || {
if let Some(me) = me.upgrade() {
me.toggle();
}
});
let me = self.me.clone();
ui.on_player_close(move || {
if let Some(me) = me.upgrade() {
me.close();
}
});
let me = self.me.clone();
ui.on_player_seek(move |fraction| {
if let Some(me) = me.upgrade() {
let duration = me.track.borrow().as_ref().map(|t| t.duration);
if let Some(duration) = duration {
me.seek_to(duration.mul_f32(fraction.clamp(0.0, 1.0)));
}
}
});
let me = self.me.clone();
ui.on_player_step(move |direction| {
if let Some(me) = me.upgrade() {
let position = me.track.borrow().as_ref().map(|t| t.position);
if let Some(position) = position {
me.seek_to(if direction < 0 {
position.saturating_sub(STEP)
} else {
position + STEP
});
}
}
});
let me = self.me.clone();
ui.on_player_volume(move |volume| {
if let Some(me) = me.upgrade() {
me.set_volume(volume, false);
}
});
let me = self.me.clone();
ui.on_player_mute(move || {
if let Some(me) = me.upgrade() {
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();
}
});
}
}
fn read_info(path: &Path) -> Info {
let tags = tunal_tags::read(path).unwrap_or_default();
Info {
title: tags.title,
artist: tags.artist,
cover: tags.cover.and_then(|c| cover(&c.data)),
}
}
fn cover(data: &[u8]) -> Option<SharedPixelBuffer<Rgba8Pixel>> {
let image = image::load_from_memory(data)
.ok()?
.thumbnail(COVER, COVER)
.to_rgba8();
Some(SharedPixelBuffer::clone_from_slice(
image.as_raw(),
image.width(),
image.height(),
))
}
/// `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()
}
/// "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)
}
};
format!("{} / {}", fmt(position), fmt(duration))
}

View file

@ -76,6 +76,7 @@ impl SettingsUi {
preview_frame: cfg.preview_frame as i32,
preview_max_mib: cfg.preview_max_mib as i32,
preview_remote: cfg.preview_remote,
player_next: cfg.player_next,
}
}
@ -115,6 +116,7 @@ impl SettingsUi {
cfg.preview_frame = data.preview_frame.clamp(0, 3600) as u32;
cfg.preview_max_mib = data.preview_max_mib.clamp(1, 4096) as u32;
cfg.preview_remote = data.preview_remote;
cfg.player_next = data.player_next;
// The window's own sidebar state is saved with the session, not by this dialog.
if let Some(ui) = self.ui.upgrade() {
cfg.show_sidebar = ui.get_show_sidebar();

View file

@ -457,6 +457,12 @@ impl Shell {
}
}
pub(crate) fn debug_play(&self, path: std::path::PathBuf) {
if let Some(actions) = self.actions.get() {
actions.debug_play(path);
}
}
pub(crate) fn run_action(&self, action: crate::actions::Action) {
if let Some(actions) = self.actions.get() {
actions.run(action);
@ -824,7 +830,15 @@ impl Shell {
});
on_pane!(on_sort_by, |_s, p, column| p.model.sort_column(column));
on_pane!(on_filter_typed, |_s, p, text| p.model.type_filter(&text));
// Space with no filter typed plays the selected audio file (the Play action).
on_pane!(on_filter_typed, |s, p, text| if !(text == " "
&& p.model.state().filter.is_empty()
&& s.actions
.get()
.is_some_and(|a| a.key(&text, false, false, false)))
{
p.model.type_filter(&text)
});
on_pane!(on_filter_edited, |_s, p, text| p.model.set_filter(&text));
on_pane!(on_toggle_hidden, |_s, p| p.model.toggle_hidden());
on_pane!(on_toggle_previews, |_s, p| p.model.toggle_previews());

View file

@ -15,6 +15,7 @@ import { Crumb, Completion, CompletionList } from "shell/breadcrumb.slint";
import { Pane, PaneData } from "shell/pane.slint";
import { Sidebar, SidebarSection, PlaceItem } from "shell/sidebar.slint";
import { StatusBar } from "shell/status-bar.slint";
import { PlayerBar, PlayerData } from "shell/player-bar.slint";
import { ToastStack, ToastData, ToastProgress } from "components/toast.slint";
import { DialogAction } from "components/dialog.slint";
import { ConflictDialog, ConflictInfo } from "dialogs/conflict.slint";
@ -30,6 +31,7 @@ import { Dnd, DropAction, DropMenu, DropTarget } from "components/drop-menu.slin
export { Theme, Shapes, ShapeKind, MotionPrefs, MenuItem, MenuEntry, DetailRow, FolderState, FolderStatus, Grouping, NavKey, SortColumn, Travel, ViewMode, GridRow }
export { ButtonKind, TabData, PaneData, Crumb, Completion, SidebarSection, PlaceItem, ToastData, ToastProgress, DialogAction, ConflictInfo, SettingsData, EditRow }
export { PlayerData }
export { PropertiesInfo, PropRow, AppRow, IconChoice, Dnd, DropAction, DropTarget, TagEditorData, TagField, TagLookupData, ReleaseRow, MapRow }
export { Gallery, GalleryPage } from "gallery.slint";
@ -162,6 +164,21 @@ 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.
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.
callback player-seek(float);
// -1 back, 1 forward.
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;
callback properties-closed();
@ -569,6 +586,33 @@ export component MainWindow inherits Window {
}
}
player-bar := PlayerBar {
data: root.player;
peaks: root.player-peaks;
position: root.player-position;
toggle => {
root.player-toggle();
}
close => {
root.player-close();
}
seek(f) => {
root.player-seek(f);
}
step(d) => {
root.player-step(d);
}
volume(v) => {
root.player-volume(v);
}
mute => {
root.player-mute();
}
changed bar-count => {
root.player-bars-changed();
}
}
StatusBar {
text: root.status;
}

View file

@ -33,6 +33,10 @@ export global Icons {
out property <string> grid-view: "\u{e9b0}";
out property <string> view-list: "\u{e8ef}";
out property <string> music-note: "\u{e405}";
out property <string> play: "\u{e037}";
out property <string> pause: "\u{e034}";
out property <string> volume-up: "\u{e050}";
out property <string> volume-off: "\u{e04f}";
out property <string> description: "\u{e873}";
out property <string> chevron-right: "\u{e5cc}";
out property <string> content-copy: "\u{e14d}";

View file

@ -32,6 +32,7 @@ export struct SettingsData {
preview-frame: int,
preview-max-mib: int,
preview-remote: bool,
player-next: bool,
}
// One choice out of a few, as a row of chips.
@ -286,6 +287,18 @@ export component SettingsDialog inherits Dialog {
}
}
}
Setting {
title: "Play the next track";
hint: "When a track ends, the player goes on with the next audio file in the folder.";
Switch {
checked: root.data.player-next;
changed checked => {
root.data.player-next = self.checked;
root.changed(root.data);
}
}
}
}
if root.page == 1: VerticalLayout {

View file

@ -0,0 +1,325 @@
import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
import { Icons } from "../components/icon.slint";
import { IconButton } from "../components/icon-button.slint";
import { StateLayer } from "../components/state-layer.slint";
import { Shape, ShapeKind } from "../components/shape.slint";
// What the player bar shows besides the position; Rust (player_bridge.rs) fills it.
export struct PlayerData {
open: bool,
playing: bool,
title: string,
artist: string,
cover: image,
has-cover: bool,
// "1:23 / 4:56"
time: string,
// 0..1
volume: float,
muted: bool,
}
// Play/pause: a primary cookie at rest that rounds into a circle while playing.
component PlayButton inherits StateLayer {
in property <bool> playing;
width: 48px;
height: 48px;
border-radius: Theme.corner-full(self.height);
tint: Theme.on-primary;
squeeze: Motion.squeeze-small;
accessible-role: button;
accessible-label: root.tooltip;
accessible-action-default => {
self.activate();
}
Shape {
size: root.width;
shape: ShapeKind.cookie9;
active-shape: ShapeKind.circle;
active: root.playing;
fill: Theme.primary;
glyph: root.playing ? Icons.pause : Icons.play;
glyph-color: Theme.on-primary;
}
}
// 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).
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;
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;
min-width: 120px;
accessible-role: slider;
accessible-label: "Position";
accessible-value: round(root.position * 100) + "%";
keys := FocusScope {
key-pressed(event) => {
if event.text == Key.LeftArrow {
root.step(-1);
return accept;
}
if event.text == Key.RightArrow {
root.step(1);
return accept;
}
reject
}
}
// Before the waveform comes: a plain track.
if root.peaks.length == 0: Rectangle {
y: (root.height - self.height) / 2;
height: Theme.wave-stroke;
border-radius: self.height / 2;
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);
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;
}
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;
}
// Keyboard focus: a ring round the bar.
if keys.has-focus: Rectangle {
x: -Theme.space-1;
width: root.width + 2 * Theme.space-1;
border-radius: Theme.corner-sm;
border-width: Theme.focus-ring-width;
border-color: Theme.secondary;
}
touch := TouchArea {
mouse-cursor: pointer;
pointer-event(event) => {
if event.kind == PointerEventKind.down {
keys.focus();
}
if event.kind == PointerEventKind.up && event.button == PointerEventButton.left {
root.seek(clamp(self.mouse-x / root.width, 0, 1));
}
}
}
}
// Volume: a short track with a thumb; press or drag sets it.
component VolumeBar {
in property <float> value;
in property <bool> muted;
callback changed-value(float);
property <float> shown: root.muted ? 0 : root.value;
width: 72px;
accessible-role: slider;
accessible-label: "Volume";
accessible-value: round(root.shown * 100) + "%";
Rectangle {
y: (root.height - self.height) / 2;
height: Theme.wave-stroke;
border-radius: self.height / 2;
background: Theme.outline-variant;
Rectangle {
x: 0;
width: parent.width * root.shown;
border-radius: parent.border-radius;
background: Theme.primary;
}
}
Rectangle {
width: touch.has-hover || touch.pressed ? 16px : 12px;
height: self.width;
x: root.width * root.shown - self.width / 2;
y: (root.height - self.height) / 2;
border-radius: self.width / 2;
background: Theme.primary;
animate width {
duration: Motion.time(Motion.short3);
easing: Motion.standard;
}
}
touch := TouchArea {
mouse-cursor: pointer;
pointer-event(event) => {
if event.kind == PointerEventKind.down {
root.changed-value(clamp(self.mouse-x / root.width, 0, 1));
}
}
moved => {
if self.pressed {
root.changed-value(clamp(self.mouse-x / root.width, 0, 1));
}
}
}
}
// 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).
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);
callback step(int);
callback volume(float);
callback mute();
property <length> card-height: 64px;
property <length> full: root.card-height + Theme.space-2;
height: root.data.open ? root.full : 0;
clip: true;
animate height {
duration: Motion.time(Motion.medium1);
easing: Motion.emphasized-decelerate;
}
// Anchored to the bottom: it rises out from behind the status bar.
Rectangle {
x: Theme.space-3;
width: root.width - 2 * Theme.space-3;
height: root.card-height;
y: root.height - root.full + Theme.space-2;
border-radius: Theme.corner-full(self.height);
background: Theme.surface-container-high;
HorizontalLayout {
padding-left: Theme.space-2;
padding-right: Theme.space-3;
spacing: Theme.space-3;
alignment: stretch;
VerticalLayout {
alignment: center;
Shape {
size: 48px;
shape: ShapeKind.cookie9;
fill: Theme.tertiary-container;
glyph: Icons.music-note;
glyph-color: Theme.on-tertiary-container;
picture: root.data.cover;
has-picture: root.data.has-cover;
}
}
VerticalLayout {
alignment: center;
width: 180px;
Text {
text: root.data.title;
color: Theme.on-surface;
font-size: Theme.label-large.size;
font-weight: Theme.label-large.weight;
overflow: elide;
}
Text {
text: root.data.artist;
color: Theme.on-surface-variant;
font-size: Theme.body-small.size;
font-weight: Theme.body-small.weight;
overflow: elide;
}
}
VerticalLayout {
alignment: center;
PlayButton {
playing: root.data.playing;
tooltip: root.data.playing ? "Pause" : "Play";
clicked => {
root.toggle();
}
}
}
seek := SeekBar {
horizontal-stretch: 1;
peaks: root.peaks;
position: root.position;
seek(f) => {
root.seek(f);
}
step(d) => {
root.step(d);
}
}
Text {
text: root.data.time;
color: Theme.on-surface-variant;
font-size: Theme.label-medium.size;
font-weight: Theme.label-medium.weight;
vertical-alignment: center;
}
VerticalLayout {
alignment: center;
IconButton {
icon: root.data.muted ? Icons.volume-off : Icons.volume-up;
tooltip: root.data.muted ? "Unmute" : "Mute";
clicked => {
root.mute();
}
}
}
VolumeBar {
value: root.data.volume;
muted: root.data.muted;
changed-value(v) => {
root.volume(v);
}
}
VerticalLayout {
alignment: center;
IconButton {
icon: Icons.close;
tooltip: "Close player";
clicked => {
root.close();
}
}
}
}
}
}

View file

@ -218,6 +218,15 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
- Not done: password and keyboard-interactive paths (local sshd had keys only), agent auth, passphrase keys, ProxyJump (reported unsupported); `posix-rename` not used (library hides offered extensions; rename pre-checks the target instead, so overwriting needs delete first); non-UTF-8 remote paths give `Unsupported`; `NotEmpty` not reported (server says failure); russh keeps its own copy of the password string, not zeroized. Real host check is S036.
- Later: posix-rename via the raw session; watch by polling.
## S023 — Quick player UI
- Done: `Action::Play` ("play", Space, context menu File + Several items): plays the first selected audio file; the folder's shown audio files are the queue. Space reaches it through the folder view's type-to-filter path (only with an empty filter), so text fields never trigger it. `FolderModel::shown_files()`.
- `player_bridge.rs` `PlayerUi` (owned by Actions): lazy `tunal_player::Player`, events back via a thread-local Weak; tags + cover read off-thread; waveform 600 buckets, downsampled to the bar count the seek bar reports (`player-bar-count`, re-done on resize); errors as toasts; ended → next file when Settings › General "Play the next track" (`player_next`, default on, D-037).
- `ui/shell/player-bar.slint`: card above the status bar, rises on open (height, medium1, emphasized-decelerate, Motion.time); cookie9 cover (picture or music glyph), title/artist, PlayButton (primary cookie9 ↔ circle morph, pause/play glyph), SeekBar (bars, played tint, hover line, press-drag scrub, release seeks, ←/→ ±5 s with focus ring), time, mute + volume track, close. No timers: position arrives only while playing.
- Screenshot hook `TUNAL_PLAY=<file>` (bar a third in, no audio output).
- Verified: tunal build, clippy -D warnings, fmt --check, literal grep empty; screenshots light + dark on a generated FLAC with cover.
- Not done: no live window (sound, slide, morph, scrub, Space, next track unchecked live); cover is drawn square inside the cookie (Shape's picture behaviour), not clipped to it.
- Later: clip pictures to the shape; remember volume; previous/next buttons.
## Later
- (orchestrator) Breadcrumb: a long path is hard-clipped at the bar's left edge with no elision mark, and the root crumb elides at 960 px — for S034.
-