diff options
author | Max Kellermann <max@duempel.org> | 2014-07-11 21:33:50 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-07-11 21:33:50 +0200 |
commit | 828cd6fd0b8838edb39e6b3f62397a5fe369e1d5 (patch) | |
tree | 62bfa8fdaaf846a5a4c18e6607ef8f1e8f13c8a2 /src/queue | |
parent | 681643ea9e6e196c449f1974cd50e1f400da3450 (diff) | |
parent | ecb67a1ed16e93f5fe552b28631e517060115648 (diff) | |
download | mpd-828cd6fd0b8838edb39e6b3f62397a5fe369e1d5.tar.gz mpd-828cd6fd0b8838edb39e6b3f62397a5fe369e1d5.tar.xz mpd-828cd6fd0b8838edb39e6b3f62397a5fe369e1d5.zip |
Merge branch 'v0.18.x'
Diffstat (limited to 'src/queue')
-rw-r--r-- | src/queue/Playlist.cxx | 10 | ||||
-rw-r--r-- | src/queue/Playlist.hxx | 19 | ||||
-rw-r--r-- | src/queue/PlaylistControl.cxx | 2 | ||||
-rw-r--r-- | src/queue/PlaylistEdit.cxx | 35 |
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) { |