queue/Playlist: add interface QueueListener, replacing calls to idle_add()
This commit is contained in:
parent
ba43ec5759
commit
9a9b6fa326
@ -166,6 +166,7 @@ libmpd_a_SOURCES = \
|
|||||||
src/queue/PlaylistEdit.cxx \
|
src/queue/PlaylistEdit.cxx \
|
||||||
src/queue/PlaylistTag.cxx \
|
src/queue/PlaylistTag.cxx \
|
||||||
src/queue/PlaylistState.cxx src/queue/PlaylistState.hxx \
|
src/queue/PlaylistState.cxx src/queue/PlaylistState.hxx \
|
||||||
|
src/queue/Listener.hxx \
|
||||||
src/ReplayGainConfig.cxx src/ReplayGainConfig.hxx \
|
src/ReplayGainConfig.cxx src/ReplayGainConfig.hxx \
|
||||||
src/ReplayGainInfo.cxx src/ReplayGainInfo.hxx \
|
src/ReplayGainInfo.cxx src/ReplayGainInfo.hxx \
|
||||||
src/DetachedSong.cxx src/DetachedSong.hxx \
|
src/DetachedSong.cxx src/DetachedSong.hxx \
|
||||||
|
@ -29,7 +29,7 @@ Partition::Partition(Instance &_instance,
|
|||||||
unsigned max_length,
|
unsigned max_length,
|
||||||
unsigned buffer_chunks,
|
unsigned buffer_chunks,
|
||||||
unsigned buffered_before_play)
|
unsigned buffered_before_play)
|
||||||
:instance(_instance), playlist(max_length),
|
:instance(_instance), playlist(max_length, *this),
|
||||||
outputs(*this),
|
outputs(*this),
|
||||||
pc(*this, outputs, buffer_chunks, buffered_before_play)
|
pc(*this, outputs, buffer_chunks, buffered_before_play)
|
||||||
{
|
{
|
||||||
@ -74,6 +74,24 @@ Partition::SyncWithPlayer()
|
|||||||
playlist.SyncWithPlayer(pc);
|
playlist.SyncWithPlayer(pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Partition::OnQueueModified()
|
||||||
|
{
|
||||||
|
EmitIdle(IDLE_PLAYLIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Partition::OnQueueOptionsChanged()
|
||||||
|
{
|
||||||
|
EmitIdle(IDLE_OPTIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Partition::OnQueueSongStarted()
|
||||||
|
{
|
||||||
|
EmitIdle(IDLE_PLAYER);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Partition::OnPlayerSync()
|
Partition::OnPlayerSync()
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define MPD_PARTITION_HXX
|
#define MPD_PARTITION_HXX
|
||||||
|
|
||||||
#include "queue/Playlist.hxx"
|
#include "queue/Playlist.hxx"
|
||||||
|
#include "queue/Listener.hxx"
|
||||||
#include "output/MultipleOutputs.hxx"
|
#include "output/MultipleOutputs.hxx"
|
||||||
#include "mixer/Listener.hxx"
|
#include "mixer/Listener.hxx"
|
||||||
#include "player/Control.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 partition of the Music Player Daemon. It is a separate unit with
|
||||||
* a playlist, a player, outputs etc.
|
* a playlist, a player, outputs etc.
|
||||||
*/
|
*/
|
||||||
struct Partition final : private PlayerListener, private MixerListener {
|
struct Partition final : QueueListener, PlayerListener, MixerListener {
|
||||||
Instance &instance;
|
Instance &instance;
|
||||||
|
|
||||||
struct playlist playlist;
|
struct playlist playlist;
|
||||||
@ -200,6 +201,11 @@ struct Partition final : private PlayerListener, private MixerListener {
|
|||||||
void SyncWithPlayer();
|
void SyncWithPlayer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/* virtual methods from class QueueListener */
|
||||||
|
void OnQueueModified() override;
|
||||||
|
void OnQueueOptionsChanged() override;
|
||||||
|
void OnQueueSongStarted() override;
|
||||||
|
|
||||||
/* virtual methods from class PlayerListener */
|
/* virtual methods from class PlayerListener */
|
||||||
virtual void OnPlayerSync() override;
|
virtual void OnPlayerSync() override;
|
||||||
virtual void OnPlayerTagModified() override;
|
virtual void OnPlayerTagModified() override;
|
||||||
|
43
src/queue/Listener.hxx
Normal file
43
src/queue/Listener.hxx
Normal file
@ -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
|
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Playlist.hxx"
|
#include "Playlist.hxx"
|
||||||
|
#include "Listener.hxx"
|
||||||
#include "PlaylistError.hxx"
|
#include "PlaylistError.hxx"
|
||||||
#include "player/Control.hxx"
|
#include "player/Control.hxx"
|
||||||
#include "DetachedSong.hxx"
|
#include "DetachedSong.hxx"
|
||||||
#include "Idle.hxx"
|
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -86,7 +86,7 @@ playlist::QueuedSongStarted(PlayerControl &pc)
|
|||||||
if (queue.consume)
|
if (queue.consume)
|
||||||
DeleteOrder(pc, old_current);
|
DeleteOrder(pc, old_current);
|
||||||
|
|
||||||
idle_add(IDLE_PLAYER);
|
listener.OnQueueSongStarted();
|
||||||
|
|
||||||
SongStarted();
|
SongStarted();
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ playlist::SetRepeat(PlayerControl &pc, bool status)
|
|||||||
might change when repeat mode is toggled */
|
might change when repeat mode is toggled */
|
||||||
UpdateQueuedSong(pc, GetQueuedSong());
|
UpdateQueuedSong(pc, GetQueuedSong());
|
||||||
|
|
||||||
idle_add(IDLE_OPTIONS);
|
listener.OnQueueOptionsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -272,7 +272,7 @@ playlist::SetSingle(PlayerControl &pc, bool status)
|
|||||||
might change when single mode is toggled */
|
might change when single mode is toggled */
|
||||||
UpdateQueuedSong(pc, GetQueuedSong());
|
UpdateQueuedSong(pc, GetQueuedSong());
|
||||||
|
|
||||||
idle_add(IDLE_OPTIONS);
|
listener.OnQueueOptionsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -282,7 +282,7 @@ playlist::SetConsume(bool status)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
queue.consume = status;
|
queue.consume = status;
|
||||||
idle_add(IDLE_OPTIONS);
|
listener.OnQueueOptionsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -319,7 +319,7 @@ playlist::SetRandom(PlayerControl &pc, bool status)
|
|||||||
|
|
||||||
UpdateQueuedSong(pc, queued_song);
|
UpdateQueuedSong(pc, queued_song);
|
||||||
|
|
||||||
idle_add(IDLE_OPTIONS);
|
listener.OnQueueOptionsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -30,6 +30,7 @@ class Error;
|
|||||||
class SongLoader;
|
class SongLoader;
|
||||||
class SongTime;
|
class SongTime;
|
||||||
class SignedSongTime;
|
class SignedSongTime;
|
||||||
|
class QueueListener;
|
||||||
|
|
||||||
struct playlist {
|
struct playlist {
|
||||||
/**
|
/**
|
||||||
@ -37,6 +38,8 @@ struct playlist {
|
|||||||
*/
|
*/
|
||||||
Queue queue;
|
Queue queue;
|
||||||
|
|
||||||
|
QueueListener &listener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This value is true if the player is currently playing (or
|
* This value is true if the player is currently playing (or
|
||||||
* should be playing).
|
* should be playing).
|
||||||
@ -85,8 +88,11 @@ struct playlist {
|
|||||||
*/
|
*/
|
||||||
int queued;
|
int queued;
|
||||||
|
|
||||||
playlist(unsigned max_length)
|
playlist(unsigned max_length,
|
||||||
:queue(max_length), playing(false),
|
QueueListener &_listener)
|
||||||
|
:queue(max_length),
|
||||||
|
listener(_listener),
|
||||||
|
playing(false),
|
||||||
bulk_edit(false),
|
bulk_edit(false),
|
||||||
current(-1), queued(-1) {
|
current(-1), queued(-1) {
|
||||||
}
|
}
|
||||||
@ -129,7 +135,8 @@ struct playlist {
|
|||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Called by all editing methods after a modification.
|
* 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();
|
void OnModified();
|
||||||
|
|
||||||
|
@ -25,12 +25,12 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Playlist.hxx"
|
#include "Playlist.hxx"
|
||||||
|
#include "Listener.hxx"
|
||||||
#include "PlaylistError.hxx"
|
#include "PlaylistError.hxx"
|
||||||
#include "player/Control.hxx"
|
#include "player/Control.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "DetachedSong.hxx"
|
#include "DetachedSong.hxx"
|
||||||
#include "SongLoader.hxx"
|
#include "SongLoader.hxx"
|
||||||
#include "Idle.hxx"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ playlist::OnModified()
|
|||||||
|
|
||||||
queue.IncrementVersion();
|
queue.IncrementVersion();
|
||||||
|
|
||||||
idle_add(IDLE_PLAYLIST);
|
listener.OnQueueModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "db/Interface.hxx"
|
#include "db/Interface.hxx"
|
||||||
#include "db/LightSong.hxx"
|
#include "db/LightSong.hxx"
|
||||||
#include "DetachedSong.hxx"
|
#include "DetachedSong.hxx"
|
||||||
#include "Idle.hxx"
|
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
Loading…
Reference in New Issue
Block a user