From dc5676229d19f317b97df6a3d3582bbb02df33df Mon Sep 17 00:00:00 2001 From: Tab_theFox Date: Sun, 23 Mar 2025 17:45:19 +0100 Subject: add single touch shourtcuts for touch wheel This allows you to use the touch wheel for quick playback control: - bottom quadrant for play/pause - left and right quadrant for track skip back / forward - top quadrant to seek back 25 seconds (handy when listening to a podcast) --- src/tangara/ui/ui_events.hpp | 4 ++++ src/tangara/ui/ui_fsm.cpp | 25 +++++++++++++++++++++++++ src/tangara/ui/ui_fsm.hpp | 2 ++ 3 files changed, 31 insertions(+) (limited to 'src/tangara/ui') diff --git a/src/tangara/ui/ui_events.hpp b/src/tangara/ui/ui_events.hpp index 0f371769..ce9320fc 100644 --- a/src/tangara/ui/ui_events.hpp +++ b/src/tangara/ui/ui_events.hpp @@ -34,6 +34,10 @@ struct Screenshot : tinyfsm::Event { std::string filename; }; +struct SeekBack : tinyfsm::Event { + uint32_t seconds; +}; + namespace internal { struct InitDisplay : tinyfsm::Event { diff --git a/src/tangara/ui/ui_fsm.cpp b/src/tangara/ui/ui_fsm.cpp index aaf35d13..1b8c0984 100644 --- a/src/tangara/ui/ui_fsm.cpp +++ b/src/tangara/ui/ui_fsm.cpp @@ -403,6 +403,31 @@ void UiState::react(const Screenshot& ev) { SaveScreenshot(sCurrentScreen->root(), ev.filename); } +void UiState::react(const SeekBack& ev) { + const auto playback_position = sPlaybackPosition.get(); + if (!std::holds_alternative(playback_position)) { + // I don't think this ever happens, but check anyway. + return; + } + + const auto track = sPlaybackTrack.get(); + if (!std::holds_alternative(track)) { + // Nothing is playing + return; + } + + const auto current_position = std::get(playback_position); + int32_t seek_position = current_position - ev.seconds; + if (seek_position < 1) { + seek_position = 0; + } + + events::Audio().Dispatch(audio::SetTrack{ + .new_track = std::get(track).uri, + .seek_to_second = seek_position, + }); +} + void UiState::react(const system_fsm::KeyLockChanged& ev) { sDisplay->SetDisplayOn(!ev.locking); sInput->lock(ev.locking); diff --git a/src/tangara/ui/ui_fsm.hpp b/src/tangara/ui/ui_fsm.hpp index d4354bec..01f0beb1 100644 --- a/src/tangara/ui/ui_fsm.hpp +++ b/src/tangara/ui/ui_fsm.hpp @@ -56,6 +56,8 @@ class UiState : public tinyfsm::Fsm { void react(const tinyfsm::Event& ev) {} void react(const Screenshot&); + void react(const SeekBack&); + virtual void react(const OnLuaError&) {} virtual void react(const DumpLuaStack&) {} virtual void react(const internal::BackPressed&) {} -- cgit v1.2.3