diff --git a/ldoc-stubs/queue.lua b/ldoc-stubs/queue.lua index 83849624..2d6a2a29 100644 --- a/ldoc-stubs/queue.lua +++ b/ldoc-stubs/queue.lua @@ -19,4 +19,10 @@ queue.replay = types.Property -- @see types.Property queue.random = types.Property +--- Moves forward in the play queue, looping back around to the beginning if repeat is on. +function queue.next() end + +--- Moves backward in the play queue, looping back around to the end if repeat is on. +function queue.previous() end + return queue diff --git a/luals-stubs/queue.lua b/luals-stubs/queue.lua index 0c63b8c1..ece99c69 100644 --- a/luals-stubs/queue.lua +++ b/luals-stubs/queue.lua @@ -8,4 +8,7 @@ --- @field random Property Determines whether, when progressing to the next track in the queue, the next track will be chosen randomly. The random selection algorithm used is a Miller Shuffle, which guarantees that no repeat selections will be made until every item in the queue has been played. Writeable. local queue = {} +function queue.next() end +function queue.previous() end + return queue diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 9de1169b..3ddef738 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -164,6 +164,9 @@ class Lua : public UiState { auto SetPlaying(const lua::LuaValue&) -> bool; auto SetRandom(const lua::LuaValue&) -> bool; auto SetRepeat(const lua::LuaValue&) -> bool; + + auto QueueNext(lua_State*) -> int; + auto QueuePrevious(lua_State*) -> int; }; } // namespace states diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index e532e693..fe790816 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -396,12 +396,16 @@ void Lua::entry() { {"track", &sPlaybackTrack}, {"position", &sPlaybackPosition}, }); - sLua->bridge().AddPropertyModule("queue", { - {"position", &sQueuePosition}, - {"size", &sQueueSize}, - {"replay", &sQueueRepeat}, - {"random", &sQueueRandom}, - }); + sLua->bridge().AddPropertyModule( + "queue", + { + {"next", [&](lua_State* s) { return QueueNext(s); }}, + {"previous", [&](lua_State* s) { return QueuePrevious(s); }}, + {"position", &sQueuePosition}, + {"size", &sQueueSize}, + {"replay", &sQueueRepeat}, + {"random", &sQueueRandom}, + }); sLua->bridge().AddPropertyModule("volume", { {"current_pct", &sVolumeCurrentPct}, @@ -476,6 +480,16 @@ auto Lua::PushLuaScreen(lua_State* s) -> int { return 0; } +auto Lua::QueueNext(lua_State*) -> int { + sServices->track_queue().next(); + return 0; +} + +auto Lua::QueuePrevious(lua_State*) -> int { + sServices->track_queue().previous(); + return 0; +} + auto Lua::PopLuaScreen(lua_State* s) -> int { PopScreen(); luavgl_set_root(s, sCurrentScreen->content());