player/Listener: add virtual method OnPlayerState(), wrapping IDLE_PLAYER

This eliminates most of the remaining global "player" idle events.
This commit is contained in:
Max Kellermann 2022-07-13 13:34:45 +02:00
parent 047561dc22
commit 64f84d5468
5 changed files with 18 additions and 6 deletions

1
NEWS
View File

@ -2,6 +2,7 @@ ver 0.24 (not yet released)
* protocol
- "playlistfind"/"playlistsearch" have "sort" and "window" parameters
- filter "prio" (for "playlistfind"/"playlistsearch")
- limit "player" idle events to the current partition
* archive
- add option to disable archive plugins in mpd.conf
* decoder

View File

@ -189,6 +189,12 @@ Partition::OnPlayerError() noexcept
EmitIdle(IDLE_PLAYER);
}
void
Partition::OnPlayerStateChanged() noexcept
{
EmitIdle(IDLE_PLAYER);
}
void
Partition::OnPlayerSync() noexcept
{

View File

@ -278,6 +278,7 @@ private:
/* virtual methods from class PlayerListener */
void OnPlayerError() noexcept override;
void OnPlayerStateChanged() noexcept override;
void OnPlayerSync() noexcept override;
void OnPlayerTagModified() noexcept override;
void OnBorderPause() noexcept override;

View File

@ -28,6 +28,12 @@ public:
*/
virtual void OnPlayerError() noexcept = 0;
/**
* Some state of the player has changed. This maps to
* #IDLE_PLAYER.
*/
virtual void OnPlayerStateChanged() noexcept = 0;
/**
* Must call playlist_sync().
*/

View File

@ -46,7 +46,6 @@
#include "CrossFade.hxx"
#include "pcm/MixRampGlue.hxx"
#include "tag/Tag.hxx"
#include "Idle.hxx"
#include "util/Compiler.h"
#include "util/Domain.hxx"
#include "thread/Name.hxx"
@ -582,8 +581,7 @@ Player::OpenOutput() noexcept
paused = false;
pc.state = PlayerState::PLAY;
idle_add(IDLE_PLAYER);
pc.listener.OnPlayerStateChanged();
return true;
}
@ -617,7 +615,7 @@ Player::CheckDecoderStartup(std::unique_lock<Mutex> &lock) noexcept
(buffer_before_play_size + sizeof(MusicChunk::data) - 1)
/ sizeof(MusicChunk::data);
idle_add(IDLE_PLAYER);
pc.listener.OnPlayerStateChanged();
if (pending_seek > SongTime::zero()) {
assert(pc.seeking);
@ -707,7 +705,7 @@ Player::SeekDecoder(std::unique_lock<Mutex> &lock) noexcept
pc.outputs.Cancel();
}
idle_add(IDLE_PLAYER);
pc.listener.OnPlayerStateChanged();
if (!dc.IsSeekableCurrentSong(*pc.next_song)) {
/* the decoder is already decoding the "next" song -
@ -1108,7 +1106,7 @@ Player::SongBorder() noexcept
pc.outputs.Drain();
pc.outputs.Pause();
idle_add(IDLE_PLAYER);
pc.listener.OnPlayerStateChanged();
}
}