From ca5d7b867c381b7886a660ce744df0b74f38b2e6 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 8 Dec 2023 11:11:57 +1100 Subject: Add shuffle and repeat options for the playback queue --- src/ui/include/ui_fsm.hpp | 4 ++++ src/ui/ui_fsm.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 7ad6be93..ba3f5e3f 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -137,6 +137,8 @@ class Lua : public UiState { auto PushLuaScreen(lua_State*) -> int; auto PopLuaScreen(lua_State*) -> int; auto SetPlaying(const lua::LuaValue&) -> bool; + auto SetRandom(const lua::LuaValue&) -> bool; + auto SetRepeat(const lua::LuaValue&) -> bool; std::shared_ptr battery_pct_; std::shared_ptr battery_mv_; @@ -150,6 +152,8 @@ class Lua : public UiState { std::shared_ptr queue_position_; std::shared_ptr queue_size_; + std::shared_ptr queue_repeat_; + std::shared_ptr queue_random_; }; class Browse : public UiState { diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index 783494dd..f4b56a27 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -176,6 +176,8 @@ void Lua::entry() { queue_position_ = std::make_shared(0); queue_size_ = std::make_shared(0); + queue_repeat_ = std::make_shared(false); + queue_random_ = std::make_shared(false); playback_playing_ = std::make_shared( false, [&](const lua::LuaValue& val) { return SetPlaying(val); }); @@ -203,6 +205,8 @@ void Lua::entry() { sLua->bridge().AddPropertyModule("queue", { {"position", queue_position_}, {"size", queue_size_}, + {"replay", queue_repeat_}, + {"random", queue_random_}, }); sLua->bridge().AddPropertyModule( "backstack", @@ -242,7 +246,7 @@ auto Lua::PushLuaScreen(lua_State* s) -> int { return 0; } -auto Lua::PopLuaScreen(lua_State *s) -> int { +auto Lua::PopLuaScreen(lua_State* s) -> int { PopScreen(); luavgl_set_root(s, sCurrentScreen->content()); lv_group_set_default(sCurrentScreen->group()); @@ -261,6 +265,24 @@ auto Lua::SetPlaying(const lua::LuaValue& val) -> bool { return true; } +auto Lua::SetRandom(const lua::LuaValue& val) -> bool { + if (!std::holds_alternative(val)) { + return false; + } + bool b = std::get(val); + sServices->track_queue().random(b); + return true; +} + +auto Lua::SetRepeat(const lua::LuaValue& val) -> bool { + if (!std::holds_alternative(val)) { + return false; + } + bool b = std::get(val); + sServices->track_queue().repeat(b); + return true; +} + void Lua::exit() { lv_group_set_default(NULL); } @@ -288,6 +310,8 @@ void Lua::react(const audio::QueueUpdate&) { current_pos++; } queue_position_->Update(current_pos); + queue_random_->Update(queue.random()); + queue_repeat_->Update(queue.repeat()); } void Lua::react(const audio::PlaybackStarted& ev) { -- cgit v1.2.3