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 /lua/playing.lua | |
| 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 'lua/playing.lua')
| -rw-r--r-- | lua/playing.lua | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/lua/playing.lua b/lua/playing.lua index 4ca79ed6..35e9c8eb 100644 --- a/lua/playing.lua +++ b/lua/playing.lua @@ -176,9 +176,9 @@ return screen:new { local repeat_btn = controls:Button {} repeat_btn:onClicked(function() - queue.repeat_track:set(not queue.repeat_track:get()) + queue.repeat_mode:set((queue.repeat_mode:get() + 1) % 3) end) - local repeat_img = repeat_btn:Image { src = img.repeat_src } + local repeat_img = repeat_btn:Image { src = img.repeat_off } theme.set_subject(repeat_btn, icon_enabled_class) local repeat_desc = widgets.Description(repeat_btn) @@ -197,6 +197,10 @@ return screen:new { local play_pause_btn = controls:Button {} play_pause_btn:onClicked(function() + if (not playback.track:get()) then + -- Restart the last played track + queue.position:set(queue.position:get()) + end playback.playing:set(not playback.playing:get()) end) play_pause_btn:focus() @@ -238,7 +242,10 @@ return screen:new { text = format_time(pos) } local track = playback.track:get() - if not track then return end + if not track then + scrubber:set{value = 0} + return + end if not track.duration then return end scrubber:set { value = pos / track.duration * 100 } end @@ -247,13 +254,7 @@ return screen:new { if not track then if queue.loading:get() then title:set { text = "Loading..." } - else - title:set { text = "" } end - artist:set { text = "" } - cur_time:set { text = format_time(0) } - end_time:set { text = format_time(0) } - scrubber:set { value = 0 } return end if track.duration then @@ -268,7 +269,7 @@ return screen:new { if not pos then return end playlist_pos:set { text = tostring(pos) } - local can_next = pos < queue.size:get() or queue.random:get() + local can_next = pos < queue.size:get() or queue.random:get() or queue.repeat_mode:get() == queue.RepeatMode.REPEAT_QUEUE theme.set_subject( next_btn, can_next and icon_enabled_class or icon_disabled_class ) @@ -283,14 +284,16 @@ return screen:new { shuffle_desc:set { text = "Enable shuffle" } end end), - queue.repeat_track:bind(function(en) - theme.set_subject(repeat_btn, en and icon_enabled_class or icon_disabled_class) - if en then - repeat_img:set_src(img.repeat_src) - repeat_desc:set { text = "Disable track repeat" } - else + queue.repeat_mode:bind(function(mode) + if mode == queue.RepeatMode.OFF then repeat_img:set_src(img.repeat_off) - repeat_desc:set { text = "Enable track repeat" } + repeat_desc:set { text = "Repeat off" } + elseif mode == queue.RepeatMode.REPEAT_TRACK then + repeat_img:set_src(img.repeat_track) + repeat_desc:set { text = "Repeat track" } + elseif mode == queue.RepeatMode.REPEAT_QUEUE then + repeat_img:set_src(img.repeat_queue) + repeat_desc:set { text = "Repeat queue" } end end), queue.size:bind(function(num) |
