diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-12-19 04:29:23 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-12-19 04:29:23 +0000 |
| commit | 5cdc1141ee5f5c7b19809940457b4c4c21db9ae6 (patch) | |
| tree | 3d4484992bb819a4809ae828ee6cd7f571b00ad7 /src/tangara/ui/ui_fsm.cpp | |
| parent | ceb66b46eac7811a9e1ad4d8141b09947f7ee4b2 (diff) | |
| download | tangara-fw-5cdc1141ee5f5c7b19809940457b4c4c21db9ae6.tar.gz | |
Queue repeat modes (#126)
This replaces the previous system of a separate track and queue repeat, with a RepeatMode type with the following options and behaviours:
- OFF: No repeat, queue or track. When the current queue finishes, shuffled or otherwise, playback will stop.
- REPEAT_TRACK: The current track will loop indefinitely, unless next is explicitly called through some user action (ie using the next button in the now playing screen)
- REPEAT_QUEUE: The entire queue will repeat indefinitely. When shuffled is enabled this will repeat the queue with new combinations each cycle.
The repeat mode is persisted in non-volatile storage, so the behaviour will be consistent throughout restarts and queue replacements, and so the "queue repeat by default" use case can be met in this way.
In addition, I've made it work a little nicer when the queue runs out in the now playing screen, keeping the previously played track shown and playback can be continued by using the play button or by going to a previous song in the queue.
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/126
Co-authored-by: ailurux <ailuruxx@gmail.com>
Co-committed-by: ailurux <ailuruxx@gmail.com>
Diffstat (limited to 'src/tangara/ui/ui_fsm.cpp')
| -rw-r--r-- | src/tangara/ui/ui_fsm.cpp | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/src/tangara/ui/ui_fsm.cpp b/src/tangara/ui/ui_fsm.cpp index 3f59d4ad..5ea4617e 100644 --- a/src/tangara/ui/ui_fsm.cpp +++ b/src/tangara/ui/ui_fsm.cpp @@ -210,20 +210,15 @@ lua::Property UiState::sQueuePosition{0, [](const lua::LuaValue& val){ return sServices->track_queue().currentPosition(new_val-1); }}; lua::Property UiState::sQueueSize{0}; -lua::Property UiState::sQueueRepeat{false, [](const lua::LuaValue& val) { - if (!std::holds_alternative<bool>(val)) { +lua::Property UiState::sQueueRepeatMode{0, [](const lua::LuaValue& val) { + if (!std::holds_alternative<int>(val)) { return false; } - bool new_val = std::get<bool>(val); - sServices->track_queue().repeat(new_val); - return true; - }}; -lua::Property UiState::sQueueReplay{false, [](const lua::LuaValue& val) { - if (!std::holds_alternative<bool>(val)) { + int new_val = std::get<int>(val); + if (new_val < 0 || new_val >= 3) { return false; } - bool new_val = std::get<bool>(val); - sServices->track_queue().replay(new_val); + sServices->track_queue().repeatMode(static_cast<audio::TrackQueue::RepeatMode>(new_val)); return true; }}; lua::Property UiState::sQueueRandom{false, [](const lua::LuaValue& val) { @@ -450,8 +445,7 @@ void UiState::react(const audio::QueueUpdate& update) { } sQueuePosition.setDirect(current_pos); sQueueRandom.setDirect(queue.random()); - sQueueRepeat.setDirect(queue.repeat()); - sQueueReplay.setDirect(queue.replay()); + sQueueRepeatMode.setDirect(queue.repeatMode()); if (update.reason == audio::QueueUpdate::Reason::kBulkLoadingUpdate) { sQueueLoading.setDirect(true); @@ -654,8 +648,7 @@ void Lua::entry() { {"previous", [&](lua_State* s) { return QueuePrevious(s); }}, {"position", &sQueuePosition}, {"size", &sQueueSize}, - {"replay", &sQueueReplay}, - {"repeat_track", &sQueueRepeat}, + {"repeat_mode", &sQueueRepeatMode}, {"random", &sQueueRandom}, {"loading", &sQueueLoading}, }); @@ -850,23 +843,15 @@ auto Lua::SetRandom(const lua::LuaValue& val) -> bool { return true; } -auto Lua::SetRepeat(const lua::LuaValue& val) -> bool { - if (!std::holds_alternative<bool>(val)) { +auto Lua::SetRepeatMode(const lua::LuaValue& val) -> bool { + if (!std::holds_alternative<int>(val)) { return false; } - bool b = std::get<bool>(val); - sServices->track_queue().repeat(b); + int mode = std::get<int>(val); + sServices->track_queue().repeatMode(static_cast<audio::TrackQueue::RepeatMode>(mode)); return true; } -auto Lua::SetReplay(const lua::LuaValue& val) -> bool { - if (!std::holds_alternative<bool>(val)) { - return false; - } - bool b = std::get<bool>(val); - sServices->track_queue().replay(b); - return true; -} void Lua::exit() { lv_group_set_default(NULL); |
