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/ui_fsm.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/ui/ui_fsm.cpp') 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