summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Partition.cxx20
-rw-r--r--src/Partition.hxx8
-rw-r--r--src/queue/Listener.hxx43
-rw-r--r--src/queue/Playlist.cxx12
-rw-r--r--src/queue/Playlist.hxx13
-rw-r--r--src/queue/PlaylistEdit.cxx4
-rw-r--r--src/queue/PlaylistUpdate.cxx1
7 files changed, 87 insertions, 14 deletions
diff --git a/src/Partition.cxx b/src/Partition.cxx
index b08551a2a..2bbad1283 100644
--- a/src/Partition.cxx
+++ b/src/Partition.cxx
@@ -29,7 +29,7 @@ Partition::Partition(Instance &_instance,
unsigned max_length,
unsigned buffer_chunks,
unsigned buffered_before_play)
- :instance(_instance), playlist(max_length),
+ :instance(_instance), playlist(max_length, *this),
outputs(*this),
pc(*this, outputs, buffer_chunks, buffered_before_play)
{
@@ -75,6 +75,24 @@ Partition::SyncWithPlayer()
}
void
+Partition::OnQueueModified()
+{
+ EmitIdle(IDLE_PLAYLIST);
+}
+
+void
+Partition::OnQueueOptionsChanged()
+{
+ EmitIdle(IDLE_OPTIONS);
+}
+
+void
+Partition::OnQueueSongStarted()
+{
+ EmitIdle(IDLE_PLAYER);
+}
+
+void
Partition::OnPlayerSync()
{
instance.global_events.Emit(GlobalEvents::PLAYLIST);
diff --git a/src/Partition.hxx b/src/Partition.hxx
index fe273ac44..6e72bf3ab 100644
--- a/src/Partition.hxx
+++ b/src/Partition.hxx
@@ -21,6 +21,7 @@
#define MPD_PARTITION_HXX
#include "queue/Playlist.hxx"
+#include "queue/Listener.hxx"
#include "output/MultipleOutputs.hxx"
#include "mixer/Listener.hxx"
#include "player/Control.hxx"
@@ -36,7 +37,7 @@ class SongLoader;
* A partition of the Music Player Daemon. It is a separate unit with
* a playlist, a player, outputs etc.
*/
-struct Partition final : private PlayerListener, private MixerListener {
+struct Partition final : QueueListener, PlayerListener, MixerListener {
Instance &instance;
struct playlist playlist;
@@ -200,6 +201,11 @@ struct Partition final : private PlayerListener, private MixerListener {
void SyncWithPlayer();
private:
+ /* virtual methods from class QueueListener */
+ void OnQueueModified() override;
+ void OnQueueOptionsChanged() override;
+ void OnQueueSongStarted() override;
+
/* virtual methods from class PlayerListener */
virtual void OnPlayerSync() override;
virtual void OnPlayerTagModified() override;
diff --git a/src/queue/Listener.hxx b/src/queue/Listener.hxx
new file mode 100644
index 000000000..7407d89f6
--- /dev/null
+++ b/src/queue/Listener.hxx
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2003-2016 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_QUEUE_LISTENER_HXX
+#define MPD_QUEUE_LISTENER_HXX
+
+class QueueListener {
+public:
+ /**
+ * Called after the queue has been modified.
+ */
+ virtual void OnQueueModified() = 0;
+
+ /**
+ * Called after a playback options have been changed.
+ */
+ virtual void OnQueueOptionsChanged() = 0;
+
+ /**
+ * Called after the player has started playing a new song.
+ * This gets called by playlist::SyncWithPlayer() after it has
+ * been notified by the player thread.
+ */
+ virtual void OnQueueSongStarted() = 0;
+};
+
+#endif
diff --git a/src/queue/Playlist.cxx b/src/queue/Playlist.cxx
index 6909d36a4..136682b00 100644
--- a/src/queue/Playlist.cxx
+++ b/src/queue/Playlist.cxx
@@ -19,10 +19,10 @@
#include "config.h"
#include "Playlist.hxx"
+#include "Listener.hxx"
#include "PlaylistError.hxx"
#include "player/Control.hxx"
#include "DetachedSong.hxx"
-#include "Idle.hxx"
#include "Log.hxx"
#include <assert.h>
@@ -86,7 +86,7 @@ playlist::QueuedSongStarted(PlayerControl &pc)
if (queue.consume)
DeleteOrder(pc, old_current);
- idle_add(IDLE_PLAYER);
+ listener.OnQueueSongStarted();
SongStarted();
}
@@ -245,7 +245,7 @@ playlist::SetRepeat(PlayerControl &pc, bool status)
might change when repeat mode is toggled */
UpdateQueuedSong(pc, GetQueuedSong());
- idle_add(IDLE_OPTIONS);
+ listener.OnQueueOptionsChanged();
}
static void
@@ -272,7 +272,7 @@ playlist::SetSingle(PlayerControl &pc, bool status)
might change when single mode is toggled */
UpdateQueuedSong(pc, GetQueuedSong());
- idle_add(IDLE_OPTIONS);
+ listener.OnQueueOptionsChanged();
}
void
@@ -282,7 +282,7 @@ playlist::SetConsume(bool status)
return;
queue.consume = status;
- idle_add(IDLE_OPTIONS);
+ listener.OnQueueOptionsChanged();
}
void
@@ -319,7 +319,7 @@ playlist::SetRandom(PlayerControl &pc, bool status)
UpdateQueuedSong(pc, queued_song);
- idle_add(IDLE_OPTIONS);
+ listener.OnQueueOptionsChanged();
}
int
diff --git a/src/queue/Playlist.hxx b/src/queue/Playlist.hxx
index 0446f3f17..46ed9ae36 100644
--- a/src/queue/Playlist.hxx
+++ b/src/queue/Playlist.hxx
@@ -30,6 +30,7 @@ class Error;
class SongLoader;
class SongTime;
class SignedSongTime;
+class QueueListener;
struct playlist {
/**
@@ -37,6 +38,8 @@ struct playlist {
*/
Queue queue;
+ QueueListener &listener;
+
/**
* This value is true if the player is currently playing (or
* should be playing).
@@ -85,8 +88,11 @@ struct playlist {
*/
int queued;
- playlist(unsigned max_length)
- :queue(max_length), playing(false),
+ playlist(unsigned max_length,
+ QueueListener &_listener)
+ :queue(max_length),
+ listener(_listener),
+ playing(false),
bulk_edit(false),
current(-1), queued(-1) {
}
@@ -129,7 +135,8 @@ struct playlist {
protected:
/**
* Called by all editing methods after a modification.
- * Updates the queue version and emits #IDLE_PLAYLIST.
+ * Updates the queue version and invokes
+ * QueueListener::OnQueueModified().
*/
void OnModified();
diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx
index 7af1e110f..f50eec144 100644
--- a/src/queue/PlaylistEdit.cxx
+++ b/src/queue/PlaylistEdit.cxx
@@ -25,12 +25,12 @@
#include "config.h"
#include "Playlist.hxx"
+#include "Listener.hxx"
#include "PlaylistError.hxx"
#include "player/Control.hxx"
#include "util/Error.hxx"
#include "DetachedSong.hxx"
#include "SongLoader.hxx"
-#include "Idle.hxx"
#include <memory>
@@ -47,7 +47,7 @@ playlist::OnModified()
queue.IncrementVersion();
- idle_add(IDLE_PLAYLIST);
+ listener.OnQueueModified();
}
void
diff --git a/src/queue/PlaylistUpdate.cxx b/src/queue/PlaylistUpdate.cxx
index 264ecaa93..d09d66935 100644
--- a/src/queue/PlaylistUpdate.cxx
+++ b/src/queue/PlaylistUpdate.cxx
@@ -22,7 +22,6 @@
#include "db/Interface.hxx"
#include "db/LightSong.hxx"
#include "DetachedSong.hxx"
-#include "Idle.hxx"
#include "util/Error.hxx"
static bool