diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-08-28 12:45:10 +1000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-08-28 04:07:21 +0000 |
| commit | 9ec8d6dafcee6c9722672eefad28ee3aeba4feb9 (patch) | |
| tree | 7fc8068ff4cd70bee413d29b0dd9e52b7d6c2cf2 /src/tangara/audio/track_queue.cpp | |
| parent | d3c15bf070ff6214cd48fa04027ee5d105bc38b7 (diff) | |
| download | tangara-fw-9ec8d6dafcee6c9722672eefad28ee3aeba4feb9.tar.gz | |
Handle the loading state whilst appending many tracks better
1) Update the queue length periodically so that the user can see we're
working
2) Clear any previous track and display "loading..." instead
Diffstat (limited to 'src/tangara/audio/track_queue.cpp')
| -rw-r--r-- | src/tangara/audio/track_queue.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/tangara/audio/track_queue.cpp b/src/tangara/audio/track_queue.cpp index 761ea09a..4f90e2ea 100644 --- a/src/tangara/audio/track_queue.cpp +++ b/src/tangara/audio/track_queue.cpp @@ -26,6 +26,7 @@ #include "database/track.hpp" #include "events/event_queue.hpp" #include "memory_resource.hpp" +#include "random.hpp" #include "tasks.hpp" #include "track_queue.hpp" #include "ui/ui_fsm.hpp" @@ -190,6 +191,8 @@ auto TrackQueue::append(Item i) -> void { // doesn't block. bg_worker_.Dispatch<void>([=, this]() { database::TrackIterator it = std::get<database::TrackIterator>(i); + + size_t next_update_at = 10; while (true) { auto next = *it; if (!next) { @@ -205,7 +208,16 @@ auto TrackQueue::append(Item i) -> void { } } it++; + + // Appending very large iterators can take a while. Send out periodic + // queue updates during them so that the user has an idea what's going + // on. + if (!--next_update_at) { + next_update_at = util::sRandom->RangeInclusive(10, 20); + notifyChanged(false, Reason::kBulkLoadingUpdate); + } } + { const std::unique_lock<std::shared_mutex> lock(mutex_); updateShuffler(was_queue_empty); |
