summaryrefslogtreecommitdiff
path: root/src/tangara
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2024-08-15 12:42:57 +1000
committerailurux <ailuruxx@gmail.com>2024-08-15 12:42:57 +1000
commit5ab4c2f0d6eda97b73ac789f3d8fd39bd97eeddb (patch)
tree3c25f015ea8353c76230cff516a0872125c6f124 /src/tangara
parent40c754a72a23a849321b60dbd77fa1303c77953b (diff)
downloadtangara-fw-5ab4c2f0d6eda97b73ac789f3d8fd39bd97eeddb.tar.gz
Update position when updating the shuffler
Diffstat (limited to 'src/tangara')
-rw-r--r--src/tangara/audio/track_queue.cpp23
-rw-r--r--src/tangara/audio/track_queue.hpp4
2 files changed, 10 insertions, 17 deletions
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<database::TrackId>(i)) {
{
const std::unique_lock<std::shared_mutex> 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<database::TrackIterator>(i)) {
@@ -213,7 +206,7 @@ auto TrackQueue::append(Item i) -> void {
}
{
const std::unique_lock<std::shared_mutex> 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<std::string>;
mutable std::shared_mutex mutex_;