From 1a629c4b8804375d7eebf56f027e8a373f7d7de7 Mon Sep 17 00:00:00 2001 From: Jackson Goode Date: Wed, 7 Feb 2024 14:14:56 -0800 Subject: [PATCH 1/4] Add arrow seek --- psst-gui/src/controller/playback.rs | 23 +++++++++++++-- psst-gui/src/ui/playback.rs | 44 ++++++++++++++--------------- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/psst-gui/src/controller/playback.rs b/psst-gui/src/controller/playback.rs index 38fe0846..a7bf4250 100644 --- a/psst-gui/src/controller/playback.rs +++ b/psst-gui/src/controller/playback.rs @@ -412,11 +412,30 @@ where ctx.set_handled(); } Event::KeyDown(key) if key.code == Code::ArrowRight => { - self.next(); + if key.mods.shift() { + self.next(); + } else { + if let Some(now_playing) = &data.playback.now_playing { + let current_position = now_playing.progress; + let max_position = now_playing.item.duration(); + let seek_position = + (current_position + Duration::from_secs(10)).min(max_position); + self.seek(seek_position); + } + } ctx.set_handled(); } Event::KeyDown(key) if key.code == Code::ArrowLeft => { - self.previous(); + if key.mods.shift() { + self.previous(); + } else { + if let Some(now_playing) = &data.playback.now_playing { + let current_position = now_playing.progress; + let seek_position = + current_position.saturating_sub(Duration::from_secs(10)); + self.seek(seek_position); + } + } ctx.set_handled(); } Event::KeyDown(key) if key.key == KbKey::Character("+".to_string()) => { diff --git a/psst-gui/src/ui/playback.rs b/psst-gui/src/ui/playback.rs index 22cadb36..b238e646 100644 --- a/psst-gui/src/ui/playback.rs +++ b/psst-gui/src/ui/playback.rs @@ -90,29 +90,27 @@ fn playing_item_widget() -> impl Widget { Flex::row() .with_child(cover_art) .with_flex_child( - Flex::row() - .with_spacer(theme::grid(2.0)) - .with_flex_child( - Flex::column() - .cross_axis_alignment(CrossAxisAlignment::Start) - .with_child(name) - .with_spacer(2.0) - .with_child(detail) - .with_spacer(2.0) - .with_child(origin) - .on_click(|ctx, now_playing, _| { - ctx.submit_command(cmd::NAVIGATE.with(now_playing.origin.to_nav())); - }) - .context_menu(|now_playing| match &now_playing.item { - Playable::Track(track) => { - track::track_menu(track, &now_playing.library, &now_playing.origin) - } - Playable::Episode(episode) => { - episode::episode_menu(episode, &now_playing.library) - } - }), - 1.0 - ), + Flex::row().with_spacer(theme::grid(2.0)).with_flex_child( + Flex::column() + .cross_axis_alignment(CrossAxisAlignment::Start) + .with_child(name) + .with_spacer(2.0) + .with_child(detail) + .with_spacer(2.0) + .with_child(origin) + .on_click(|ctx, now_playing, _| { + ctx.submit_command(cmd::NAVIGATE.with(now_playing.origin.to_nav())); + }) + .context_menu(|now_playing| match &now_playing.item { + Playable::Track(track) => { + track::track_menu(track, &now_playing.library, &now_playing.origin) + } + Playable::Episode(episode) => { + episode::episode_menu(episode, &now_playing.library) + } + }), + 1.0, + ), 1.0, ) .with_child(ViewSwitcher::new( From ed555346fa785927b8fbe9bb190f9e11689b6ae3 Mon Sep 17 00:00:00 2001 From: Jackson Goode Date: Wed, 7 Feb 2024 14:19:31 -0800 Subject: [PATCH 2/4] Linting --- psst-gui/src/controller/playback.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/psst-gui/src/controller/playback.rs b/psst-gui/src/controller/playback.rs index a7bf4250..d6268a23 100644 --- a/psst-gui/src/controller/playback.rs +++ b/psst-gui/src/controller/playback.rs @@ -414,27 +414,22 @@ where Event::KeyDown(key) if key.code == Code::ArrowRight => { if key.mods.shift() { self.next(); - } else { - if let Some(now_playing) = &data.playback.now_playing { - let current_position = now_playing.progress; - let max_position = now_playing.item.duration(); - let seek_position = - (current_position + Duration::from_secs(10)).min(max_position); - self.seek(seek_position); - } + } else if let Some(now_playing) = &data.playback.now_playing { + let current_position = now_playing.progress; + let max_position = now_playing.item.duration(); + let seek_position = + (current_position + Duration::from_secs(10)).min(max_position); + self.seek(seek_position); } ctx.set_handled(); } Event::KeyDown(key) if key.code == Code::ArrowLeft => { if key.mods.shift() { self.previous(); - } else { - if let Some(now_playing) = &data.playback.now_playing { - let current_position = now_playing.progress; - let seek_position = - current_position.saturating_sub(Duration::from_secs(10)); - self.seek(seek_position); - } + } else if let Some(now_playing) = &data.playback.now_playing { + let current_position = now_playing.progress; + let seek_position = current_position.saturating_sub(Duration::from_secs(10)); + self.seek(seek_position); } ctx.set_handled(); } From 18ae9c1b739c36aeda5b11b34af81ac9c401f2e6 Mon Sep 17 00:00:00 2001 From: Jackson Goode Date: Fri, 9 Feb 2024 20:16:46 -0800 Subject: [PATCH 3/4] Add config for track seeking, standardize logic --- psst-gui/src/controller/playback.rs | 30 +++++++++++++++++++---------- psst-gui/src/data/config.rs | 2 ++ psst-gui/src/ui/preferences.rs | 16 +++++++++++++++ psst-gui/src/widget/mod.rs | 2 +- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/psst-gui/src/controller/playback.rs b/psst-gui/src/controller/playback.rs index d6268a23..8577bf14 100644 --- a/psst-gui/src/controller/playback.rs +++ b/psst-gui/src/controller/playback.rs @@ -274,6 +274,22 @@ impl PlaybackController { self.send(PlayerEvent::Command(PlayerCommand::Seek { position })); } + fn seek_relative(&mut self, data: &AppState, forward: bool) { + if let Some(now_playing) = &data.playback.now_playing { + let seek_duration = Duration::from_secs(data.config.step_duration as u64); + + // Calculate new position, ensuring it does not exceed duration for forward seeks. + let seek_position = if forward { + now_playing.progress + seek_duration + } else { + now_playing.progress.saturating_sub(seek_duration) + } + .min(now_playing.item.duration()); // Safeguard to not exceed the track duration. + + self.seek(seek_position); + } + } + fn set_volume(&mut self, volume: f64) { self.send(PlayerEvent::Command(PlayerCommand::SetVolume { volume })); } @@ -414,22 +430,16 @@ where Event::KeyDown(key) if key.code == Code::ArrowRight => { if key.mods.shift() { self.next(); - } else if let Some(now_playing) = &data.playback.now_playing { - let current_position = now_playing.progress; - let max_position = now_playing.item.duration(); - let seek_position = - (current_position + Duration::from_secs(10)).min(max_position); - self.seek(seek_position); + } else { + self.seek_relative(data, true); } ctx.set_handled(); } Event::KeyDown(key) if key.code == Code::ArrowLeft => { if key.mods.shift() { self.previous(); - } else if let Some(now_playing) = &data.playback.now_playing { - let current_position = now_playing.progress; - let seek_position = current_position.saturating_sub(Duration::from_secs(10)); - self.seek(seek_position); + } else { + self.seek_relative(data, false); } ctx.set_handled(); } diff --git a/psst-gui/src/data/config.rs b/psst-gui/src/data/config.rs index 093cbf32..96adbb67 100644 --- a/psst-gui/src/data/config.rs +++ b/psst-gui/src/data/config.rs @@ -94,6 +94,7 @@ pub struct Config { pub sort_order: SortOrder, pub sort_criteria: SortCriteria, pub paginated_limit: usize, + pub step_duration: usize, } impl Default for Config { @@ -111,6 +112,7 @@ impl Default for Config { sort_order: Default::default(), sort_criteria: Default::default(), paginated_limit: 500, + step_duration: 10, } } } diff --git a/psst-gui/src/ui/preferences.rs b/psst-gui/src/ui/preferences.rs index 73159b35..0866bf06 100644 --- a/psst-gui/src/ui/preferences.rs +++ b/psst-gui/src/ui/preferences.rs @@ -212,6 +212,22 @@ fn general_tab_widget() -> impl Widget { col = col.with_spacer(theme::grid(3.0)); + col = col + .with_child(Label::new("Step Duration").with_font(theme::UI_FONT_MEDIUM)) + .with_spacer(theme::grid(2.0)) + .with_child( + Flex::row() + .with_child( + TextBox::new().with_formatter(ParseFormatter::with_format_fn( + |usize: &usize| usize.to_string(), + )), + ) + .padding((theme::grid(1.5), 0.0)) + .lens(AppState::config.then(Config::step_duration)), + ); + + col = col.with_spacer(theme::grid(3.0)); + col = col .with_child( Label::new("Max Loaded Tracks (requires restart)").with_font(theme::UI_FONT_MEDIUM), diff --git a/psst-gui/src/widget/mod.rs b/psst-gui/src/widget/mod.rs index 5cb3a437..c6407d2f 100644 --- a/psst-gui/src/widget/mod.rs +++ b/psst-gui/src/widget/mod.rs @@ -23,7 +23,7 @@ use druid_shell::Cursor; pub use empty::Empty; pub use link::Link; pub use maybe::Maybe; -pub use overlay::{Overlay}; +pub use overlay::Overlay; pub use promise::Async; pub use remote_image::RemoteImage; pub use theme::ThemeScope; From d871b89ef01c056ca8a465f2d1736c58c979f905 Mon Sep 17 00:00:00 2001 From: Jackson Goode Date: Sun, 11 Feb 2024 12:20:40 -0800 Subject: [PATCH 4/4] Rename --- psst-gui/src/controller/playback.rs | 2 +- psst-gui/src/data/config.rs | 4 ++-- psst-gui/src/ui/preferences.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/psst-gui/src/controller/playback.rs b/psst-gui/src/controller/playback.rs index 8577bf14..cd1db0ae 100644 --- a/psst-gui/src/controller/playback.rs +++ b/psst-gui/src/controller/playback.rs @@ -276,7 +276,7 @@ impl PlaybackController { fn seek_relative(&mut self, data: &AppState, forward: bool) { if let Some(now_playing) = &data.playback.now_playing { - let seek_duration = Duration::from_secs(data.config.step_duration as u64); + let seek_duration = Duration::from_secs(data.config.seek_duration as u64); // Calculate new position, ensuring it does not exceed duration for forward seeks. let seek_position = if forward { diff --git a/psst-gui/src/data/config.rs b/psst-gui/src/data/config.rs index 96adbb67..62fcb526 100644 --- a/psst-gui/src/data/config.rs +++ b/psst-gui/src/data/config.rs @@ -94,7 +94,7 @@ pub struct Config { pub sort_order: SortOrder, pub sort_criteria: SortCriteria, pub paginated_limit: usize, - pub step_duration: usize, + pub seek_duration: usize, } impl Default for Config { @@ -112,7 +112,7 @@ impl Default for Config { sort_order: Default::default(), sort_criteria: Default::default(), paginated_limit: 500, - step_duration: 10, + seek_duration: 10, } } } diff --git a/psst-gui/src/ui/preferences.rs b/psst-gui/src/ui/preferences.rs index 0866bf06..1192db92 100644 --- a/psst-gui/src/ui/preferences.rs +++ b/psst-gui/src/ui/preferences.rs @@ -213,7 +213,7 @@ fn general_tab_widget() -> impl Widget { col = col.with_spacer(theme::grid(3.0)); col = col - .with_child(Label::new("Step Duration").with_font(theme::UI_FONT_MEDIUM)) + .with_child(Label::new("Seek Duration").with_font(theme::UI_FONT_MEDIUM)) .with_spacer(theme::grid(2.0)) .with_child( Flex::row() @@ -223,7 +223,7 @@ fn general_tab_widget() -> impl Widget { )), ) .padding((theme::grid(1.5), 0.0)) - .lens(AppState::config.then(Config::step_duration)), + .lens(AppState::config.then(Config::seek_duration)), ); col = col.with_spacer(theme::grid(3.0));