mpd/src/Partition.hxx

299 lines
7.3 KiB
C++
Raw Normal View History

/*
2020-01-18 19:22:19 +01:00
* Copyright 2003-2020 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_PARTITION_HXX
#define MPD_PARTITION_HXX
#include "event/MaskMonitor.hxx"
2014-02-27 17:12:42 +01:00
#include "queue/Playlist.hxx"
#include "queue/Listener.hxx"
#include "output/MultipleOutputs.hxx"
#include "mixer/Listener.hxx"
2015-08-15 15:55:46 +02:00
#include "player/Control.hxx"
#include "player/Listener.hxx"
#include "ReplayGainMode.hxx"
#include "SingleMode.hxx"
#include "Chrono.hxx"
#include "config.h"
#include <boost/intrusive/list.hpp>
2017-02-17 23:18:51 +01:00
#include <string>
#include <memory>
2017-02-17 23:18:51 +01:00
struct Instance;
class MultipleOutputs;
class SongLoader;
class ClientListener;
class Client;
/**
* A partition of the Music Player Daemon. It is a separate unit with
* a playlist, a player, outputs etc.
*/
struct Partition final : QueueListener, PlayerListener, MixerListener {
static constexpr unsigned TAG_MODIFIED = 0x1;
static constexpr unsigned SYNC_WITH_PLAYER = 0x2;
static constexpr unsigned BORDER_PAUSE = 0x4;
Instance &instance;
2017-02-17 23:18:51 +01:00
const std::string name;
std::unique_ptr<ClientListener> listener;
boost::intrusive::list<Client,
boost::intrusive::base_hook<boost::intrusive::list_base_hook<boost::intrusive::tag<Partition>,
boost::intrusive::link_mode<boost::intrusive::normal_link>>>,
boost::intrusive::constant_time_size<false>> clients;
/**
* Monitor for idle events local to this partition.
*/
MaskMonitor idle_monitor;
MaskMonitor global_events;
struct playlist playlist;
MultipleOutputs outputs;
PlayerControl pc;
ReplayGainMode replay_gain_mode = ReplayGainMode::OFF;
Partition(Instance &_instance,
2017-02-17 23:18:51 +01:00
const char *_name,
unsigned max_length,
unsigned buffer_chunks,
AudioFormat configured_audio_format,
2019-05-31 13:54:52 +02:00
const ReplayGainConfig &replay_gain_config) noexcept;
2013-01-07 10:55:05 +01:00
~Partition() noexcept;
void BeginShutdown() noexcept;
2019-05-31 13:54:52 +02:00
void EmitGlobalEvent(unsigned mask) noexcept {
global_events.OrMask(mask);
}
/**
* Emit an "idle" event to all clients of this partition.
*
* This method can be called from any thread.
*/
void EmitIdle(unsigned mask) noexcept {
idle_monitor.OrMask(mask);
}
/**
* Populate the #InputCacheManager with soon-to-be-played song
* files.
*
* Errors will be logged.
*/
void PrefetchQueue() noexcept;
2019-05-31 13:54:52 +02:00
void ClearQueue() noexcept {
2013-01-07 10:55:05 +01:00
playlist.Clear(pc);
}
unsigned AppendURI(const SongLoader &loader,
const char *uri_utf8) {
return playlist.AppendURI(pc, loader, uri_utf8);
2013-01-07 10:55:05 +01:00
}
void DeletePosition(unsigned position) {
playlist.DeletePosition(pc, position);
2013-01-07 10:55:05 +01:00
}
void DeleteId(unsigned id) {
playlist.DeleteId(pc, id);
2013-01-07 10:55:05 +01:00
}
/**
* Deletes a range of songs from the playlist.
*
* @param start the position of the first song to delete
* @param end the position after the last song to delete
*/
void DeleteRange(unsigned start, unsigned end) {
playlist.DeleteRange(pc, start, end);
2013-01-07 10:55:05 +01:00
}
2019-05-31 13:54:52 +02:00
void StaleSong(const char *uri) noexcept {
playlist.StaleSong(pc, uri);
2013-01-07 10:55:05 +01:00
}
2019-05-31 13:54:52 +02:00
void Shuffle(unsigned start, unsigned end) noexcept {
2013-01-07 10:55:05 +01:00
playlist.Shuffle(pc, start, end);
}
void MoveRange(unsigned start, unsigned end, int to) {
playlist.MoveRange(pc, start, end, to);
2013-01-07 10:55:05 +01:00
}
void MoveId(unsigned id, int to) {
playlist.MoveId(pc, id, to);
2013-01-07 10:55:05 +01:00
}
void SwapPositions(unsigned song1, unsigned song2) {
playlist.SwapPositions(pc, song1, song2);
2013-01-07 10:55:05 +01:00
}
void SwapIds(unsigned id1, unsigned id2) {
playlist.SwapIds(pc, id1, id2);
2013-01-07 10:55:05 +01:00
}
void SetPriorityRange(unsigned start_position, unsigned end_position,
uint8_t priority) {
playlist.SetPriorityRange(pc, start_position, end_position,
priority);
2013-01-07 10:55:05 +01:00
}
void SetPriorityId(unsigned song_id, uint8_t priority) {
playlist.SetPriorityId(pc, song_id, priority);
2013-01-07 10:55:05 +01:00
}
2019-05-31 13:54:52 +02:00
void Stop() noexcept {
2013-01-07 10:55:05 +01:00
playlist.Stop(pc);
}
void PlayPosition(int position) {
return playlist.PlayPosition(pc, position);
2013-01-07 10:55:05 +01:00
}
void PlayId(int id) {
return playlist.PlayId(pc, id);
2013-01-07 10:55:05 +01:00
}
void PlayNext() {
return playlist.PlayNext(pc);
2013-01-07 10:55:05 +01:00
}
void PlayPrevious() {
return playlist.PlayPrevious(pc);
2013-01-07 10:55:05 +01:00
}
void SeekSongPosition(unsigned song_position, SongTime seek_time) {
playlist.SeekSongPosition(pc, song_position, seek_time);
2013-01-07 10:55:05 +01:00
}
void SeekSongId(unsigned song_id, SongTime seek_time) {
playlist.SeekSongId(pc, song_id, seek_time);
2013-01-07 10:55:05 +01:00
}
void SeekCurrent(SignedSongTime seek_time, bool relative) {
playlist.SeekCurrent(pc, seek_time, relative);
2013-01-07 10:55:05 +01:00
}
2019-05-31 13:54:52 +02:00
void SetRepeat(bool new_value) noexcept {
2013-01-07 10:55:05 +01:00
playlist.SetRepeat(pc, new_value);
}
2019-05-31 13:54:52 +02:00
bool GetRandom() const noexcept {
2013-01-07 10:55:05 +01:00
return playlist.GetRandom();
}
2019-05-31 13:54:52 +02:00
void SetRandom(bool new_value) noexcept {
2013-01-07 10:55:05 +01:00
playlist.SetRandom(pc, new_value);
}
2019-05-31 13:54:52 +02:00
void SetSingle(SingleMode new_value) noexcept {
2013-01-07 10:55:05 +01:00
playlist.SetSingle(pc, new_value);
}
2019-05-31 13:54:52 +02:00
void SetConsume(bool new_value) noexcept {
2013-01-07 10:55:05 +01:00
playlist.SetConsume(new_value);
}
2019-05-31 13:54:52 +02:00
void SetReplayGainMode(ReplayGainMode mode) noexcept {
replay_gain_mode = mode;
UpdateEffectiveReplayGainMode();
}
/**
* Publishes the effective #ReplayGainMode to all subsystems.
* #ReplayGainMode::AUTO is substituted.
*/
2019-05-31 13:54:52 +02:00
void UpdateEffectiveReplayGainMode() noexcept;
#ifdef ENABLE_DATABASE
2015-08-06 12:45:22 +02:00
/**
* Returns the global #Database instance. May return nullptr
* if this MPD configuration has no database (no
* music_directory was configured).
*/
2019-05-31 13:54:52 +02:00
const Database *GetDatabase() const noexcept;
2015-08-06 12:45:22 +02:00
2016-10-26 18:47:19 +02:00
const Database &GetDatabaseOrThrow() const;
/**
* The database has been modified. Propagate the change to
* all subsystems.
*/
2019-05-31 13:54:52 +02:00
void DatabaseModified(const Database &db) noexcept;
#endif
/**
* A tag in the play queue has been modified by the player
* thread. Propagate the change to all subsystems.
*/
2019-05-31 13:54:52 +02:00
void TagModified() noexcept;
/**
* The tag of the given song has been modified. Propagate the
* change to all instances of this song in the queue.
*/
void TagModified(const char *uri, const Tag &tag) noexcept;
/**
* Synchronize the player with the play queue.
*/
2019-05-31 13:54:52 +02:00
void SyncWithPlayer() noexcept;
/**
* Border pause has just been enabled. Change single mode to off
* if it was one-shot.
*/
2019-05-31 13:54:52 +02:00
void BorderPause() noexcept;
private:
/* virtual methods from class QueueListener */
2019-05-31 13:57:46 +02:00
void OnQueueModified() noexcept override;
void OnQueueOptionsChanged() noexcept override;
void OnQueueSongStarted() noexcept override;
/* virtual methods from class PlayerListener */
2017-11-26 12:39:09 +01:00
void OnPlayerSync() noexcept override;
void OnPlayerTagModified() noexcept override;
void OnBorderPause() noexcept override;
/* virtual methods from class MixerListener */
2019-05-31 14:09:47 +02:00
void OnMixerVolumeChanged(Mixer &mixer, int volume) noexcept override;
/* callback for #idle_monitor */
void OnIdleMonitor(unsigned mask) noexcept;
/* callback for #global_events */
void OnGlobalEvent(unsigned mask) noexcept;
};
#endif