diff options
Diffstat (limited to 'src/ui/include')
| -rw-r--r-- | src/ui/include/screen.hpp | 10 | ||||
| -rw-r--r-- | src/ui/include/screen_playing.hpp | 36 | ||||
| -rw-r--r-- | src/ui/include/ui_fsm.hpp | 31 |
3 files changed, 69 insertions, 8 deletions
diff --git a/src/ui/include/screen.hpp b/src/ui/include/screen.hpp index 7ff06fbd..13b92a09 100644 --- a/src/ui/include/screen.hpp +++ b/src/ui/include/screen.hpp @@ -15,14 +15,24 @@ namespace ui { +/* + * Base class for ever discrete screen in the app. Provides a consistent + * interface that can be used for transitioning between screens, adding them to + * back stacks, etc. + */ class Screen { public: Screen() : root_(lv_obj_create(NULL)), group_(lv_group_create()) {} + virtual ~Screen() { lv_obj_del(root_); lv_group_del(group_); } + /* + * Called periodically to allow the screen to update itself, e.g. to handle + * std::futures that are still loading in. + */ virtual auto Tick() -> void {} auto root() -> lv_obj_t* { return root_; } diff --git a/src/ui/include/screen_playing.hpp b/src/ui/include/screen_playing.hpp index 3eae32a7..148f2774 100644 --- a/src/ui/include/screen_playing.hpp +++ b/src/ui/include/screen_playing.hpp @@ -6,25 +6,55 @@ #pragma once +#include <stdint.h> +#include <sys/_stdint.h> #include <memory> +#include <vector> #include "lvgl.h" #include "database.hpp" +#include "future_fetcher.hpp" #include "screen.hpp" +#include "track.hpp" +#include "track_queue.hpp" namespace ui { namespace screens { +/* + * The 'Now Playing' / 'Currently Playing' screen that contains information + * about the current track, as well as playback controls. + */ class Playing : public Screen { public: - explicit Playing(database::Track t); + explicit Playing(std::weak_ptr<database::Database> db, + audio::TrackQueue* queue); ~Playing(); - auto BindTrack(database::Track t) -> void; + auto Tick() -> void override; + + // Callbacks invoked by the UI state machine in response to audio events. + + auto OnTrackUpdate() -> void; + auto OnPlaybackUpdate(uint32_t, uint32_t) -> void; + auto OnQueueUpdate() -> void; private: - database::Track track_; + auto BindTrack(const database::Track& track) -> void; + auto ApplyNextUp(const std::vector<database::Track>& tracks) -> void; + + std::weak_ptr<database::Database> db_; + audio::TrackQueue* queue_; + + std::optional<database::Track> track_; + std::vector<database::Track> next_tracks_; + + std::unique_ptr<database::FutureFetcher<std::optional<database::Track>>> + new_track_; + std::unique_ptr< + database::FutureFetcher<std::vector<std::optional<database::Track>>>> + new_next_tracks_; lv_obj_t* artist_label_; lv_obj_t* album_label_; diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 32275fab..2fc6db4e 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -9,7 +9,9 @@ #include <memory> #include <stack> +#include "audio_events.hpp" #include "relative_wheel.hpp" +#include "screen_playing.hpp" #include "tinyfsm.hpp" #include "display.hpp" @@ -17,13 +19,14 @@ #include "storage.hpp" #include "system_events.hpp" #include "touchwheel.hpp" +#include "track_queue.hpp" #include "ui_events.hpp" namespace ui { class UiState : public tinyfsm::Fsm<UiState> { public: - static auto Init(drivers::IGpios* gpio_expander) -> bool; + static auto Init(drivers::IGpios*, audio::TrackQueue*) -> bool; virtual ~UiState() {} @@ -37,10 +40,14 @@ class UiState : public tinyfsm::Fsm<UiState> { /* Fallback event handler. Does nothing. */ void react(const tinyfsm::Event& ev) {} - virtual void react(const system_fsm::KeyLockChanged&){}; + virtual void react(const audio::PlaybackStarted&) {} + virtual void react(const audio::PlaybackUpdate&) {} + virtual void react(const audio::QueueUpdate&) {} - virtual void react(const internal::RecordSelected&){}; - virtual void react(const internal::IndexSelected&){}; + virtual void react(const system_fsm::KeyLockChanged&) {} + + virtual void react(const internal::RecordSelected&) {} + virtual void react(const internal::IndexSelected&) {} virtual void react(const system_fsm::DisplayReady&) {} virtual void react(const system_fsm::BootComplete&) {} @@ -48,8 +55,11 @@ class UiState : public tinyfsm::Fsm<UiState> { protected: void PushScreen(std::shared_ptr<Screen>); + void PopScreen(); static drivers::IGpios* sIGpios; + static audio::TrackQueue* sQueue; + static std::shared_ptr<drivers::TouchWheel> sTouchWheel; static std::shared_ptr<drivers::RelativeWheel> sRelativeWheel; static std::shared_ptr<drivers::Display> sDisplay; @@ -68,7 +78,7 @@ class Splash : public UiState { using UiState::react; }; -class Interactive : public UiState { +class Browse : public UiState { void entry() override; void react(const internal::RecordSelected&) override; @@ -76,6 +86,17 @@ class Interactive : public UiState { void react(const system_fsm::KeyLockChanged&) override; void react(const system_fsm::StorageMounted&) override; + using UiState::react; +}; + +class Playing : public UiState { + void entry() override; + void exit() override; + + void react(const audio::PlaybackStarted&) override; + void react(const audio::PlaybackUpdate&) override; + void react(const audio::QueueUpdate&) override; + using UiState::react; }; class FatalError : public UiState {}; |
