2013-01-04 22:42:05 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 The Music Player Daemon Project
|
2013-01-04 22:42:05 +01:00
|
|
|
* 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
|
|
|
|
|
2016-03-10 22:44:34 +01:00
|
|
|
#include "event/MaskMonitor.hxx"
|
2014-02-27 17:12:42 +01:00
|
|
|
#include "queue/Playlist.hxx"
|
2016-03-10 20:10:14 +01:00
|
|
|
#include "queue/Listener.hxx"
|
2014-01-27 08:20:25 +01:00
|
|
|
#include "output/MultipleOutputs.hxx"
|
2014-02-05 23:20:33 +01:00
|
|
|
#include "mixer/Listener.hxx"
|
2015-08-15 15:55:46 +02:00
|
|
|
#include "player/Control.hxx"
|
|
|
|
#include "player/Listener.hxx"
|
2016-12-03 13:56:25 +01:00
|
|
|
#include "ReplayGainMode.hxx"
|
2018-02-05 17:13:00 +01:00
|
|
|
#include "SingleMode.hxx"
|
2014-08-27 19:11:55 +02:00
|
|
|
#include "Chrono.hxx"
|
2018-11-19 12:49:45 +01:00
|
|
|
#include "config.h"
|
2013-01-04 22:42:05 +01:00
|
|
|
|
2020-01-20 13:16:13 +01:00
|
|
|
#include <boost/intrusive/list.hpp>
|
|
|
|
|
2017-02-17 23:18:51 +01:00
|
|
|
#include <string>
|
2018-01-29 23:53:52 +01:00
|
|
|
#include <memory>
|
2017-02-17 23:18:51 +01:00
|
|
|
|
2013-04-17 22:58:33 +02:00
|
|
|
struct Instance;
|
2014-01-27 08:20:25 +01:00
|
|
|
class MultipleOutputs;
|
2014-02-02 14:37:52 +01:00
|
|
|
class SongLoader;
|
2018-01-29 23:53:52 +01:00
|
|
|
class ClientListener;
|
2020-01-20 13:16:13 +01:00
|
|
|
class Client;
|
2013-04-17 22:58:33 +02:00
|
|
|
|
2013-01-04 22:42:05 +01:00
|
|
|
/**
|
|
|
|
* A partition of the Music Player Daemon. It is a separate unit with
|
|
|
|
* a playlist, a player, outputs etc.
|
|
|
|
*/
|
2016-03-10 20:10:14 +01:00
|
|
|
struct Partition final : QueueListener, PlayerListener, MixerListener {
|
2016-03-10 23:10:14 +01:00
|
|
|
static constexpr unsigned TAG_MODIFIED = 0x1;
|
|
|
|
static constexpr unsigned SYNC_WITH_PLAYER = 0x2;
|
2018-02-05 17:13:00 +01:00
|
|
|
static constexpr unsigned BORDER_PAUSE = 0x4;
|
2016-03-10 23:10:14 +01:00
|
|
|
|
2013-04-17 22:58:33 +02:00
|
|
|
Instance &instance;
|
|
|
|
|
2017-02-17 23:18:51 +01:00
|
|
|
const std::string name;
|
|
|
|
|
2018-01-29 23:53:52 +01:00
|
|
|
std::unique_ptr<ClientListener> listener;
|
|
|
|
|
2020-01-20 13:16:13 +01:00
|
|
|
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;
|
|
|
|
|
2020-01-20 13:28:58 +01:00
|
|
|
/**
|
|
|
|
* Monitor for idle events local to this partition.
|
|
|
|
*/
|
|
|
|
MaskMonitor idle_monitor;
|
|
|
|
|
2016-06-17 17:00:05 +02:00
|
|
|
MaskMonitor global_events;
|
2016-03-10 22:47:47 +01:00
|
|
|
|
2013-01-04 22:42:05 +01:00
|
|
|
struct playlist playlist;
|
|
|
|
|
2014-01-27 08:20:25 +01:00
|
|
|
MultipleOutputs outputs;
|
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl pc;
|
2013-01-04 22:42:05 +01:00
|
|
|
|
2016-12-03 13:56:25 +01:00
|
|
|
ReplayGainMode replay_gain_mode = ReplayGainMode::OFF;
|
|
|
|
|
2013-04-17 22:58:33 +02:00
|
|
|
Partition(Instance &_instance,
|
2017-02-17 23:18:51 +01:00
|
|
|
const char *_name,
|
2013-04-17 22:58:33 +02:00
|
|
|
unsigned max_length,
|
2013-01-04 22:42:05 +01:00
|
|
|
unsigned buffer_chunks,
|
2016-12-03 14:12:08 +01:00
|
|
|
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
|
|
|
|
2018-01-29 23:53:52 +01:00
|
|
|
~Partition() noexcept;
|
|
|
|
|
2020-01-20 09:21:56 +01:00
|
|
|
void BeginShutdown() noexcept;
|
|
|
|
|
2019-05-31 13:54:52 +02:00
|
|
|
void EmitGlobalEvent(unsigned mask) noexcept {
|
2016-03-10 23:10:14 +01:00
|
|
|
global_events.OrMask(mask);
|
|
|
|
}
|
2016-03-10 22:44:34 +01:00
|
|
|
|
2020-01-20 12:50:48 +01:00
|
|
|
/**
|
|
|
|
* Emit an "idle" event to all clients of this partition.
|
|
|
|
*
|
2020-01-20 13:28:58 +01:00
|
|
|
* This method can be called from any thread.
|
2020-01-20 12:50:48 +01:00
|
|
|
*/
|
2020-01-20 13:28:58 +01:00
|
|
|
void EmitIdle(unsigned mask) noexcept {
|
|
|
|
idle_monitor.OrMask(mask);
|
|
|
|
}
|
2016-03-05 19:16:39 +01:00
|
|
|
|
2019-05-08 18:39:00 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2014-02-27 17:27:23 +01:00
|
|
|
unsigned AppendURI(const SongLoader &loader,
|
2016-10-27 21:59:17 +02:00
|
|
|
const char *uri_utf8) {
|
|
|
|
return playlist.AppendURI(pc, loader, uri_utf8);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void DeletePosition(unsigned position) {
|
|
|
|
playlist.DeletePosition(pc, position);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2015-12-18 09:21:11 +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
|
|
|
|
*/
|
2015-12-18 09:21:11 +01:00
|
|
|
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 {
|
2016-03-18 18:01:01 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void MoveRange(unsigned start, unsigned end, int to) {
|
|
|
|
playlist.MoveRange(pc, start, end, to);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void MoveId(unsigned id, int to) {
|
|
|
|
playlist.MoveId(pc, id, to);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void SwapPositions(unsigned song1, unsigned song2) {
|
|
|
|
playlist.SwapPositions(pc, song1, song2);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void SwapIds(unsigned id1, unsigned id2) {
|
|
|
|
playlist.SwapIds(pc, id1, id2);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2015-12-18 09:21:11 +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
|
|
|
}
|
|
|
|
|
2015-12-18 09:21:11 +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);
|
|
|
|
}
|
|
|
|
|
2016-09-08 10:29:49 +02:00
|
|
|
void PlayPosition(int position) {
|
|
|
|
return playlist.PlayPosition(pc, position);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 10:29:49 +02:00
|
|
|
void PlayId(int id) {
|
|
|
|
return playlist.PlayId(pc, id);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 10:29:49 +02:00
|
|
|
void PlayNext() {
|
|
|
|
return playlist.PlayNext(pc);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 10:29:49 +02:00
|
|
|
void PlayPrevious() {
|
|
|
|
return playlist.PlayPrevious(pc);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 10:29:49 +02:00
|
|
|
void SeekSongPosition(unsigned song_position, SongTime seek_time) {
|
|
|
|
playlist.SeekSongPosition(pc, song_position, seek_time);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 10:29:49 +02:00
|
|
|
void SeekSongId(unsigned song_id, SongTime seek_time) {
|
|
|
|
playlist.SeekSongId(pc, song_id, seek_time);
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 10:29:49 +02: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);
|
|
|
|
}
|
2013-10-21 23:40:52 +02:00
|
|
|
|
2019-05-31 13:54:52 +02:00
|
|
|
void SetReplayGainMode(ReplayGainMode mode) noexcept {
|
2016-12-03 13:56:25 +01:00
|
|
|
replay_gain_mode = mode;
|
|
|
|
UpdateEffectiveReplayGainMode();
|
|
|
|
}
|
|
|
|
|
2016-11-24 15:18:57 +01:00
|
|
|
/**
|
|
|
|
* Publishes the effective #ReplayGainMode to all subsystems.
|
2016-11-24 17:21:23 +01:00
|
|
|
* #ReplayGainMode::AUTO is substituted.
|
2016-11-24 15:18:57 +01:00
|
|
|
*/
|
2019-05-31 13:54:52 +02:00
|
|
|
void UpdateEffectiveReplayGainMode() noexcept;
|
2016-11-24 15:18:57 +01:00
|
|
|
|
2014-02-01 00:44:41 +01:00
|
|
|
#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;
|
|
|
|
|
2013-10-22 00:26:20 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
2014-02-01 00:44:41 +01:00
|
|
|
#endif
|
2013-10-22 00:26:20 +02:00
|
|
|
|
2013-10-21 23:40:52 +02:00
|
|
|
/**
|
2013-10-21 23:22:16 +02:00
|
|
|
* A tag in the play queue has been modified by the player
|
|
|
|
* thread. Propagate the change to all subsystems.
|
2013-10-21 23:40:52 +02:00
|
|
|
*/
|
2019-05-31 13:54:52 +02:00
|
|
|
void TagModified() noexcept;
|
2013-10-21 23:40:52 +02:00
|
|
|
|
2018-01-29 12:02:14 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2013-10-21 23:40:52 +02:00
|
|
|
/**
|
|
|
|
* Synchronize the player with the play queue.
|
|
|
|
*/
|
2019-05-31 13:54:52 +02:00
|
|
|
void SyncWithPlayer() noexcept;
|
2014-02-05 23:20:33 +01:00
|
|
|
|
2018-02-05 17:13:00 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
2018-02-05 17:13:00 +01:00
|
|
|
|
2014-02-05 23:20:33 +01:00
|
|
|
private:
|
2016-03-10 20:10:14 +01:00
|
|
|
/* 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;
|
2016-03-10 20:10:14 +01:00
|
|
|
|
2014-02-21 08:55:52 +01:00
|
|
|
/* virtual methods from class PlayerListener */
|
2017-11-26 12:39:09 +01:00
|
|
|
void OnPlayerSync() noexcept override;
|
|
|
|
void OnPlayerTagModified() noexcept override;
|
2018-02-05 17:13:00 +01:00
|
|
|
void OnBorderPause() noexcept override;
|
2014-02-21 08:55:52 +01:00
|
|
|
|
2014-02-05 23:20:33 +01:00
|
|
|
/* virtual methods from class MixerListener */
|
2019-05-31 14:09:47 +02:00
|
|
|
void OnMixerVolumeChanged(Mixer &mixer, int volume) noexcept override;
|
2016-03-10 22:44:34 +01:00
|
|
|
|
2020-01-20 13:28:58 +01:00
|
|
|
/* callback for #idle_monitor */
|
|
|
|
void OnIdleMonitor(unsigned mask) noexcept;
|
|
|
|
|
2016-03-10 22:44:34 +01:00
|
|
|
/* callback for #global_events */
|
2019-08-02 14:44:00 +02:00
|
|
|
void OnGlobalEvent(unsigned mask) noexcept;
|
2013-01-04 22:42:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|