aboutsummaryrefslogtreecommitdiffstats
path: root/src/queue
diff options
context:
space:
mode:
Diffstat (limited to 'src/queue')
-rw-r--r--src/queue/Playlist.cxx10
-rw-r--r--src/queue/Playlist.hxx19
-rw-r--r--src/queue/PlaylistControl.cxx2
-rw-r--r--src/queue/PlaylistEdit.cxx35
4 files changed, 63 insertions, 3 deletions
diff --git a/src/queue/Playlist.cxx b/src/queue/Playlist.cxx
index abcb2ceaa..b2fd673b4 100644
--- a/src/queue/Playlist.cxx
+++ b/src/queue/Playlist.cxx
@@ -99,6 +99,12 @@ playlist::UpdateQueuedSong(PlayerControl &pc, const DetachedSong *prev)
if (!playing)
return;
+ if (prev == nullptr && bulk_edit)
+ /* postponed until CommitBulk() to avoid always
+ queueing the first song that is being added (in
+ random mode) */
+ return;
+
assert(!queue.IsEmpty());
assert((queued < 0) == (prev == nullptr));
@@ -286,7 +292,9 @@ playlist::SetRandom(PlayerControl &pc, bool status)
if (queue.random) {
/* shuffle the queue order, but preserve current */
- const int current_position = GetCurrentPosition();
+ const int current_position = playing
+ ? GetCurrentPosition()
+ : -1;
queue.ShuffleOrder();
diff --git a/src/queue/Playlist.hxx b/src/queue/Playlist.hxx
index 4a4c7f30c..f2d778382 100644
--- a/src/queue/Playlist.hxx
+++ b/src/queue/Playlist.hxx
@@ -50,6 +50,18 @@ struct playlist {
bool stop_on_error;
/**
+ * If true, then a bulk edit has been initiated by
+ * BeginBulk(), and UpdateQueuedSong() and OnModified() will
+ * be postponed until CommitBulk()
+ */
+ bool bulk_edit;
+
+ /**
+ * Has the queue been modified during bulk edit mode?
+ */
+ bool bulk_modified;
+
+ /**
* Number of errors since playback was started. If this
* number exceeds the length of the playlist, MPD gives up,
* because all songs have been tried.
@@ -73,7 +85,9 @@ struct playlist {
int queued;
playlist(unsigned max_length)
- :queue(max_length), playing(false), current(-1), queued(-1) {
+ :queue(max_length), playing(false),
+ bulk_edit(false),
+ current(-1), queued(-1) {
}
~playlist() {
@@ -130,6 +144,9 @@ protected:
void UpdateQueuedSong(PlayerControl &pc, const DetachedSong *prev);
public:
+ void BeginBulk();
+ void CommitBulk(PlayerControl &pc);
+
void Clear(PlayerControl &pc);
/**
diff --git a/src/queue/PlaylistControl.cxx b/src/queue/PlaylistControl.cxx
index 9d75cc26d..db0b8a25d 100644
--- a/src/queue/PlaylistControl.cxx
+++ b/src/queue/PlaylistControl.cxx
@@ -153,7 +153,7 @@ playlist::PlayNext(PlayerControl &pc)
queue.ShuffleOrder();
/* note that current and queued are
- now invalid, but playlist_play_order() will
+ now invalid, but PlayOrder() will
discard them anyway */
}
diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx
index e8f1a178f..92865cab7 100644
--- a/src/queue/PlaylistEdit.cxx
+++ b/src/queue/PlaylistEdit.cxx
@@ -38,6 +38,12 @@
void
playlist::OnModified()
{
+ if (bulk_edit) {
+ /* postponed to CommitBulk() */
+ bulk_modified = true;
+ return;
+ }
+
queue.IncrementVersion();
idle_add(IDLE_PLAYLIST);
@@ -54,6 +60,35 @@ playlist::Clear(PlayerControl &pc)
OnModified();
}
+void
+playlist::BeginBulk()
+{
+ assert(!bulk_edit);
+
+ bulk_edit = true;
+ bulk_modified = false;
+}
+
+void
+playlist::CommitBulk(PlayerControl &pc)
+{
+ assert(bulk_edit);
+
+ bulk_edit = false;
+ if (!bulk_modified)
+ return;
+
+ if (queued < 0)
+ /* if no song was queued, UpdateQueuedSong() is being
+ ignored in "bulk" edit mode; now that we have
+ shuffled all new songs, we can pick a random one
+ (instead of always picking the first one that was
+ added) */
+ UpdateQueuedSong(pc, nullptr);
+
+ OnModified();
+}
+
unsigned
playlist::AppendSong(PlayerControl &pc, DetachedSong &&song, Error &error)
{