PlayerListener: new interface to replace GlobalEvents access
This commit is contained in:
parent
860339c132
commit
30a82076ba
|
@ -137,6 +137,7 @@ libmpd_a_SOURCES = \
|
|||
src/Permission.cxx src/Permission.hxx \
|
||||
src/PlayerThread.cxx src/PlayerThread.hxx \
|
||||
src/PlayerControl.cxx src/PlayerControl.hxx \
|
||||
src/PlayerListener.hxx \
|
||||
src/Playlist.cxx src/Playlist.hxx \
|
||||
src/PlaylistError.cxx src/PlaylistError.hxx \
|
||||
src/PlaylistGlobal.cxx src/PlaylistGlobal.hxx \
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "output/MultipleOutputs.hxx"
|
||||
#include "mixer/Volume.hxx"
|
||||
#include "Idle.hxx"
|
||||
#include "GlobalEvents.hxx"
|
||||
|
||||
#ifdef ENABLE_DATABASE
|
||||
|
||||
|
@ -50,6 +51,18 @@ Partition::SyncWithPlayer()
|
|||
playlist.SyncWithPlayer(pc);
|
||||
}
|
||||
|
||||
void
|
||||
Partition::OnPlayerSync()
|
||||
{
|
||||
GlobalEvents::Emit(GlobalEvents::PLAYLIST);
|
||||
}
|
||||
|
||||
void
|
||||
Partition::OnPlayerTagModified()
|
||||
{
|
||||
GlobalEvents::Emit(GlobalEvents::TAG);
|
||||
}
|
||||
|
||||
void
|
||||
Partition::OnMixerVolumeChanged(gcc_unused Mixer &mixer, gcc_unused int volume)
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "output/MultipleOutputs.hxx"
|
||||
#include "mixer/Listener.hxx"
|
||||
#include "PlayerControl.hxx"
|
||||
#include "PlayerListener.hxx"
|
||||
|
||||
struct Instance;
|
||||
class MultipleOutputs;
|
||||
|
@ -33,7 +34,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 MixerListener {
|
||||
struct Partition final : private PlayerListener, private MixerListener {
|
||||
Instance &instance;
|
||||
|
||||
struct playlist playlist;
|
||||
|
@ -48,7 +49,7 @@ struct Partition final : private MixerListener {
|
|||
unsigned buffered_before_play)
|
||||
:instance(_instance), playlist(max_length),
|
||||
outputs(*this),
|
||||
pc(outputs, buffer_chunks, buffered_before_play) {}
|
||||
pc(*this, outputs, buffer_chunks, buffered_before_play) {}
|
||||
|
||||
void ClearQueue() {
|
||||
playlist.Clear(pc);
|
||||
|
@ -192,6 +193,10 @@ struct Partition final : private MixerListener {
|
|||
void SyncWithPlayer();
|
||||
|
||||
private:
|
||||
/* virtual methods from class PlayerListener */
|
||||
virtual void OnPlayerSync() override;
|
||||
virtual void OnPlayerTagModified() override;
|
||||
|
||||
/* virtual methods from class MixerListener */
|
||||
virtual void OnMixerVolumeChanged(Mixer &mixer, int volume) override;
|
||||
};
|
||||
|
|
|
@ -26,10 +26,11 @@
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
PlayerControl::PlayerControl(MultipleOutputs &_outputs,
|
||||
PlayerControl::PlayerControl(PlayerListener &_listener,
|
||||
MultipleOutputs &_outputs,
|
||||
unsigned _buffer_chunks,
|
||||
unsigned _buffered_before_play)
|
||||
:outputs(_outputs),
|
||||
:listener(_listener), outputs(_outputs),
|
||||
buffer_chunks(_buffer_chunks),
|
||||
buffered_before_play(_buffered_before_play),
|
||||
command(PlayerCommand::NONE),
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
class PlayerListener;
|
||||
class MultipleOutputs;
|
||||
class DetachedSong;
|
||||
|
||||
|
@ -92,6 +93,8 @@ struct player_status {
|
|||
};
|
||||
|
||||
struct PlayerControl {
|
||||
PlayerListener &listener;
|
||||
|
||||
MultipleOutputs &outputs;
|
||||
|
||||
unsigned buffer_chunks;
|
||||
|
@ -137,8 +140,8 @@ struct PlayerControl {
|
|||
* A copy of the current #DetachedSong after its tags have
|
||||
* been updated by the decoder (for example, a radio stream
|
||||
* that has sent a new tag after switching to the next song).
|
||||
* This shall be used by the GlobalEvents::TAG handler to
|
||||
* update the current #DetachedSong in the queue.
|
||||
* This shall be used by PlayerListener::OnPlayerTagModified()
|
||||
* to update the current #DetachedSong in the queue.
|
||||
*
|
||||
* Protected by #mutex. Set by the PlayerThread and consumed
|
||||
* by the main thread.
|
||||
|
@ -173,7 +176,8 @@ struct PlayerControl {
|
|||
*/
|
||||
bool border_pause;
|
||||
|
||||
PlayerControl(MultipleOutputs &_outputs,
|
||||
PlayerControl(PlayerListener &_listener,
|
||||
MultipleOutputs &_outputs,
|
||||
unsigned buffer_chunks,
|
||||
unsigned buffered_before_play);
|
||||
~PlayerControl();
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2014 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_PLAYER_LISTENER_HXX
|
||||
#define MPD_PLAYER_LISTENER_HXX
|
||||
|
||||
class PlayerListener {
|
||||
public:
|
||||
/**
|
||||
* Must call playlist_sync().
|
||||
*/
|
||||
virtual void OnPlayerSync() = 0;
|
||||
|
||||
/**
|
||||
* The current song's tag has changed.
|
||||
*/
|
||||
virtual void OnPlayerTagModified() = 0;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "PlayerThread.hxx"
|
||||
#include "PlayerListener.hxx"
|
||||
#include "decoder/DecoderThread.hxx"
|
||||
#include "decoder/DecoderControl.hxx"
|
||||
#include "MusicPipe.hxx"
|
||||
|
@ -31,7 +32,6 @@
|
|||
#include "output/MultipleOutputs.hxx"
|
||||
#include "tag/Tag.hxx"
|
||||
#include "Idle.hxx"
|
||||
#include "GlobalEvents.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "thread/Name.hxx"
|
||||
#include "Log.hxx"
|
||||
|
@ -359,7 +359,7 @@ Player::WaitForDecoder()
|
|||
pc.Unlock();
|
||||
|
||||
/* call syncPlaylistWithQueue() in the main thread */
|
||||
GlobalEvents::Emit(GlobalEvents::PLAYLIST);
|
||||
pc.listener.OnPlayerSync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -696,7 +696,7 @@ update_song_tag(PlayerControl &pc, DetachedSong &song, const Tag &new_tag)
|
|||
|
||||
/* the main thread will update the playlist version when he
|
||||
receives this event */
|
||||
GlobalEvents::Emit(GlobalEvents::TAG);
|
||||
pc.listener.OnPlayerTagModified();
|
||||
|
||||
/* notify all clients that the tag of the current song has
|
||||
changed */
|
||||
|
@ -1124,7 +1124,7 @@ player_task(void *arg)
|
|||
|
||||
pc.Unlock();
|
||||
do_play(pc, dc, buffer);
|
||||
GlobalEvents::Emit(GlobalEvents::PLAYLIST);
|
||||
pc.listener.OnPlayerSync();
|
||||
pc.Lock();
|
||||
break;
|
||||
|
||||
|
|
|
@ -53,10 +53,11 @@ filter_plugin_by_name(gcc_unused const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
PlayerControl::PlayerControl(gcc_unused MultipleOutputs &_outputs,
|
||||
PlayerControl::PlayerControl(PlayerListener &_listener,
|
||||
MultipleOutputs &_outputs,
|
||||
gcc_unused unsigned _buffer_chunks,
|
||||
gcc_unused unsigned _buffered_before_play)
|
||||
:outputs(_outputs) {}
|
||||
:listener(_listener), outputs(_outputs) {}
|
||||
PlayerControl::~PlayerControl() {}
|
||||
|
||||
static AudioOutput *
|
||||
|
@ -69,7 +70,8 @@ load_audio_output(EventLoop &event_loop, const char *name)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static struct PlayerControl dummy_player_control(*(MultipleOutputs *)nullptr,
|
||||
static struct PlayerControl dummy_player_control(*(PlayerListener *)nullptr,
|
||||
*(MultipleOutputs *)nullptr,
|
||||
32, 4);
|
||||
|
||||
Error error;
|
||||
|
|
Loading…
Reference in New Issue