diff --git a/src/tangara/audio/track_queue.cpp b/src/tangara/audio/track_queue.cpp index fb4ff696..51f17a8f 100644 --- a/src/tangara/audio/track_queue.cpp +++ b/src/tangara/audio/track_queue.cpp @@ -121,9 +121,12 @@ auto TrackQueue::totalSize() const -> size_t { return sum; } -auto TrackQueue::updateShuffler() -> void { +auto TrackQueue::updateShuffler(bool andUpdatePosition) -> void { if (shuffle_) { shuffle_->resize(totalSize()); + if (andUpdatePosition) { + goTo(shuffle_->current()); + } } } @@ -140,7 +143,7 @@ auto TrackQueue::openPlaylist(const std::string& playlist_file) -> bool { if (!res) { return false; } - updateShuffler(); + updateShuffler(true); notifyChanged(true, Reason::kExplicitUpdate); return true; } @@ -169,16 +172,6 @@ auto TrackQueue::append(Item i) -> void { current_changed = was_queue_empty; // Dont support inserts yet } - // If there wasn't anything already playing, then we should make sure we - // begin playback at a random point, instead of always starting with - // whatever was inserted first and *then* shuffling. - // We don't base this purely off of current_changed because we would like - // 'play this track now' (by inserting at the current pos) to work even - // when shuffling is enabled. - if (was_queue_empty && shuffle_) { - playlist_.skipTo(shuffle_->current()); - } - if (std::holds_alternative(i)) { { const std::unique_lock lock(mutex_); @@ -186,7 +179,7 @@ auto TrackQueue::append(Item i) -> void { if (!filename.empty()) { playlist_.append(filename); } - updateShuffler(); + updateShuffler(was_queue_empty); } notifyChanged(current_changed, Reason::kExplicitUpdate); } else if (std::holds_alternative(i)) { @@ -213,7 +206,7 @@ auto TrackQueue::append(Item i) -> void { } { const std::unique_lock lock(mutex_); - updateShuffler(); + updateShuffler(was_queue_empty); } notifyChanged(current_changed, Reason::kExplicitUpdate); }); @@ -224,7 +217,7 @@ auto TrackQueue::next() -> void { next(Reason::kExplicitUpdate); } -auto TrackQueue::goTo(size_t position) { +auto TrackQueue::goTo(size_t position) -> void { position_ = position; if (opened_playlist_) { if (position_ < opened_playlist_->size()) { diff --git a/src/tangara/audio/track_queue.hpp b/src/tangara/audio/track_queue.hpp index 72713242..b66d18d1 100644 --- a/src/tangara/audio/track_queue.hpp +++ b/src/tangara/audio/track_queue.hpp @@ -80,7 +80,7 @@ class TrackQueue { auto insert(Item, size_t index = 0) -> void; auto append(Item i) -> void; - auto updateShuffler() -> void; + auto updateShuffler(bool andUpdatePosition) -> void; /* * Advances to the next track in the queue, placing the current track at the @@ -117,7 +117,7 @@ class TrackQueue { private: auto next(QueueUpdate::Reason r) -> void; - auto goTo(size_t position); + auto goTo(size_t position) -> void; auto getFilepath(database::TrackId id) -> std::optional; mutable std::shared_mutex mutex_;