Partition.hxx 6.3 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * 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

23
#include "event/MaskMonitor.hxx"
24
#include "queue/Playlist.hxx"
25
#include "queue/Listener.hxx"
26
#include "output/MultipleOutputs.hxx"
27
#include "mixer/Listener.hxx"
28 29
#include "player/Control.hxx"
#include "player/Listener.hxx"
30
#include "ReplayGainMode.hxx"
31
#include "SingleMode.hxx"
32
#include "Chrono.hxx"
33
#include "Compiler.h"
34

35
#include <string>
36
#include <memory>
37

38
struct Instance;
39
class MultipleOutputs;
40
class SongLoader;
41
class ClientListener;
42

43 44 45 46
/**
 * A partition of the Music Player Daemon.  It is a separate unit with
 * a playlist, a player, outputs etc.
 */
47
struct Partition final : QueueListener, PlayerListener, MixerListener {
48 49
	static constexpr unsigned TAG_MODIFIED = 0x1;
	static constexpr unsigned SYNC_WITH_PLAYER = 0x2;
50
	static constexpr unsigned BORDER_PAUSE = 0x4;
51

52 53
	Instance &instance;

54 55
	const std::string name;

56 57
	std::unique_ptr<ClientListener> listener;

58
	MaskMonitor global_events;
59

60 61
	struct playlist playlist;

62 63
	MultipleOutputs outputs;

64
	PlayerControl pc;
65

66 67
	ReplayGainMode replay_gain_mode = ReplayGainMode::OFF;

68
	Partition(Instance &_instance,
69
		  const char *_name,
70
		  unsigned max_length,
71
		  unsigned buffer_chunks,
72
		  unsigned buffered_before_play,
73
		  AudioFormat configured_audio_format,
74
		  const ReplayGainConfig &replay_gain_config);
75

76 77
	~Partition() noexcept;

78 79 80
	void EmitGlobalEvent(unsigned mask) {
		global_events.OrMask(mask);
	}
81

82 83
	void EmitIdle(unsigned mask);

84 85 86 87
	void ClearQueue() {
		playlist.Clear(pc);
	}

88
	unsigned AppendURI(const SongLoader &loader,
89 90
			   const char *uri_utf8) {
		return playlist.AppendURI(pc, loader, uri_utf8);
91 92
	}

93 94
	void DeletePosition(unsigned position) {
		playlist.DeletePosition(pc, position);
95 96
	}

97 98
	void DeleteId(unsigned id) {
		playlist.DeleteId(pc, id);
99 100 101 102 103 104 105 106
	}

	/**
	 * 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
	 */
107 108
	void DeleteRange(unsigned start, unsigned end) {
		playlist.DeleteRange(pc, start, end);
109 110
	}

111 112
	void StaleSong(const char *uri) {
		playlist.StaleSong(pc, uri);
113 114 115 116 117 118
	}

	void Shuffle(unsigned start, unsigned end) {
		playlist.Shuffle(pc, start, end);
	}

119 120
	void MoveRange(unsigned start, unsigned end, int to) {
		playlist.MoveRange(pc, start, end, to);
121 122
	}

123 124
	void MoveId(unsigned id, int to) {
		playlist.MoveId(pc, id, to);
125 126
	}

127 128
	void SwapPositions(unsigned song1, unsigned song2) {
		playlist.SwapPositions(pc, song1, song2);
129 130
	}

131 132
	void SwapIds(unsigned id1, unsigned id2) {
		playlist.SwapIds(pc, id1, id2);
133 134
	}

135 136 137 138
	void SetPriorityRange(unsigned start_position, unsigned end_position,
			      uint8_t priority) {
		playlist.SetPriorityRange(pc, start_position, end_position,
					  priority);
139 140
	}

141 142
	void SetPriorityId(unsigned song_id, uint8_t priority) {
		playlist.SetPriorityId(pc, song_id, priority);
143 144 145 146 147 148
	}

	void Stop() {
		playlist.Stop(pc);
	}

149 150
	void PlayPosition(int position) {
		return playlist.PlayPosition(pc, position);
151 152
	}

153 154
	void PlayId(int id) {
		return playlist.PlayId(pc, id);
155 156
	}

157 158
	void PlayNext() {
		return playlist.PlayNext(pc);
159 160
	}

161 162
	void PlayPrevious() {
		return playlist.PlayPrevious(pc);
163 164
	}

165 166
	void SeekSongPosition(unsigned song_position, SongTime seek_time) {
		playlist.SeekSongPosition(pc, song_position, seek_time);
167 168
	}

169 170
	void SeekSongId(unsigned song_id, SongTime seek_time) {
		playlist.SeekSongId(pc, song_id, seek_time);
171 172
	}

173 174
	void SeekCurrent(SignedSongTime seek_time, bool relative) {
		playlist.SeekCurrent(pc, seek_time, relative);
175 176 177 178 179 180 181 182 183 184 185 186 187 188
	}

	void SetRepeat(bool new_value) {
		playlist.SetRepeat(pc, new_value);
	}

	bool GetRandom() const {
		return playlist.GetRandom();
	}

	void SetRandom(bool new_value) {
		playlist.SetRandom(pc, new_value);
	}

189
	void SetSingle(SingleMode new_value) {
190 191 192 193 194 195
		playlist.SetSingle(pc, new_value);
	}

	void SetConsume(bool new_value) {
		playlist.SetConsume(new_value);
	}
196

197 198 199 200 201
	void SetReplayGainMode(ReplayGainMode mode) {
		replay_gain_mode = mode;
		UpdateEffectiveReplayGainMode();
	}

202 203
	/**
	 * Publishes the effective #ReplayGainMode to all subsystems.
204
	 * #ReplayGainMode::AUTO is substituted.
205
	 */
206
	void UpdateEffectiveReplayGainMode();
207

208
#ifdef ENABLE_DATABASE
209 210 211 212 213
	/**
	 * Returns the global #Database instance.  May return nullptr
	 * if this MPD configuration has no database (no
	 * music_directory was configured).
	 */
214
	const Database *GetDatabase() const;
215

216 217
	const Database &GetDatabaseOrThrow() const;

218 219 220 221
	/**
	 * The database has been modified.  Propagate the change to
	 * all subsystems.
	 */
222
	void DatabaseModified(const Database &db);
223
#endif
224

225
	/**
226 227
	 * A tag in the play queue has been modified by the player
	 * thread.  Propagate the change to all subsystems.
228 229 230
	 */
	void TagModified();

231 232 233 234 235 236
	/**
	 * 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;

237 238 239 240
	/**
	 * Synchronize the player with the play queue.
	 */
	void SyncWithPlayer();
241

242 243 244 245 246 247
	/**
	 * Border pause has just been enabled. Change single mode to off
	 * if it was one-shot.
	 */
	void BorderPause();

248
private:
249 250 251 252 253
	/* virtual methods from class QueueListener */
	void OnQueueModified() override;
	void OnQueueOptionsChanged() override;
	void OnQueueSongStarted() override;

254
	/* virtual methods from class PlayerListener */
255 256
	void OnPlayerSync() noexcept override;
	void OnPlayerTagModified() noexcept override;
257
	void OnBorderPause() noexcept override;
258

259
	/* virtual methods from class MixerListener */
260
	void OnMixerVolumeChanged(Mixer &mixer, int volume) override;
261 262 263

	/* callback for #global_events */
	void OnGlobalEvent(unsigned mask);
264 265 266
};

#endif