Merge pull request 'Makes the ⏮ and ⏭ on the Now Playing screen work' (#14) from rh/next-prev into main

Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/14
Reviewed-by: cooljqln <cooljqln@noreply.codeberg.org>
custom
Robin Howard 1 year ago
commit 6b9a513214
  1. 6
      ldoc-stubs/queue.lua
  2. 39
      lua/playing.lua
  3. 3
      luals-stubs/queue.lua
  4. 7
      src/audio/track_queue.cpp
  5. 3
      src/ui/include/ui_fsm.hpp
  6. 16
      src/ui/ui_fsm.cpp

@ -19,4 +19,10 @@ queue.replay = types.Property
-- @see types.Property -- @see types.Property
queue.random = 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 return queue

@ -5,6 +5,15 @@ local font = require("font")
local playback = require("playback") local playback = require("playback")
local queue = require("queue") local queue = require("queue")
local img = {
play = "//lua/img/play.png",
pause = "//lua/img/pause.png",
next = "//lua/img/next.png",
next_disabled = "//lua/img/next_disabled.png",
prev = "//lua/img/prev.png",
prev_disabled = "//lua/img/prev_disabled.png",
}
return function(opts) return function(opts)
local screen = {} local screen = {}
screen.root = lvgl.Object(nil, { screen.root = lvgl.Object(nil, {
@ -106,19 +115,20 @@ return function(opts)
controls:Object({ flex_grow = 1, h = 1 }) -- spacer controls:Object({ flex_grow = 1, h = 1 }) -- spacer
controls:Image { local prev_btn = controls:Button {}
src = "//lua/img/prev.png", prev_btn:onClicked(queue.previous)
} local prev_img = prev_btn:Image { src = img.prev_disabled }
local play_pause_btn = controls:Button {} local play_pause_btn = controls:Button {}
play_pause_btn:onClicked(function() play_pause_btn:onClicked(function()
playback.playing:set(not playback.playing:get()) playback.playing:set(not playback.playing:get())
end) end)
local play_pause_img = play_pause_btn:Image { local play_pause_img = play_pause_btn:Image { src = img.pause }
src = "//lua/img/pause.png",
} local next_btn = controls:Button {}
controls:Image { next_btn:onClicked(queue.next)
src = "//lua/img/next.png", local next_img = next_btn:Image { src = img.next_disabled }
}
controls:Object({ flex_grow = 1, h = 1 }) -- spacer controls:Object({ flex_grow = 1, h = 1 }) -- spacer
local end_time = controls:Label { local end_time = controls:Label {
@ -136,9 +146,9 @@ return function(opts)
screen.bindings = { screen.bindings = {
playback.playing:bind(function(playing) playback.playing:bind(function(playing)
if playing then if playing then
play_pause_img:set_src("//lua/img/pause.png") play_pause_img:set_src(img.pause)
else else
play_pause_img:set_src("//lua/img/play.png") play_pause_img:set_src(img.play)
end end
end), end),
playback.position:bind(function(pos) playback.position:bind(function(pos)
@ -162,6 +172,13 @@ return function(opts)
queue.position:bind(function(pos) queue.position:bind(function(pos)
if not pos then return end if not pos then return end
playlist_pos:set { text = tostring(pos) } playlist_pos:set { text = tostring(pos) }
next_img:set_src(
pos < queue.size:get() and img.next or img.next_disabled
)
prev_img:set_src(
pos > 1 and img.prev or img.prev_disabled
)
end), end),
queue.size:bind(function(num) queue.size:bind(function(num)
if not num then return end if not num then return end

@ -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. --- @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 = {} local queue = {}
function queue.next() end
function queue.previous() end
return queue return queue

@ -200,10 +200,13 @@ auto TrackQueue::next() -> void {
shuffle_->next(); shuffle_->next();
pos_ = shuffle_->current(); pos_ = shuffle_->current();
} else { } else {
pos_++; if (pos_ + 1 >= tracks_.size()) {
if (pos_ >= tracks_.size() && repeat_) { if (repeat_) {
pos_ = 0; pos_ = 0;
} }
} else {
pos_++;
}
} }
notifyChanged(true); notifyChanged(true);

@ -164,6 +164,9 @@ class Lua : public UiState {
auto SetPlaying(const lua::LuaValue&) -> bool; auto SetPlaying(const lua::LuaValue&) -> bool;
auto SetRandom(const lua::LuaValue&) -> bool; auto SetRandom(const lua::LuaValue&) -> bool;
auto SetRepeat(const lua::LuaValue&) -> bool; auto SetRepeat(const lua::LuaValue&) -> bool;
auto QueueNext(lua_State*) -> int;
auto QueuePrevious(lua_State*) -> int;
}; };
} // namespace states } // namespace states

@ -396,7 +396,11 @@ void Lua::entry() {
{"track", &sPlaybackTrack}, {"track", &sPlaybackTrack},
{"position", &sPlaybackPosition}, {"position", &sPlaybackPosition},
}); });
sLua->bridge().AddPropertyModule("queue", { sLua->bridge().AddPropertyModule(
"queue",
{
{"next", [&](lua_State* s) { return QueueNext(s); }},
{"previous", [&](lua_State* s) { return QueuePrevious(s); }},
{"position", &sQueuePosition}, {"position", &sQueuePosition},
{"size", &sQueueSize}, {"size", &sQueueSize},
{"replay", &sQueueRepeat}, {"replay", &sQueueRepeat},
@ -476,6 +480,16 @@ auto Lua::PushLuaScreen(lua_State* s) -> int {
return 0; 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 { auto Lua::PopLuaScreen(lua_State* s) -> int {
PopScreen(); PopScreen();
luavgl_set_root(s, sCurrentScreen->content()); luavgl_set_root(s, sCurrentScreen->content());

Loading…
Cancel
Save