Partition.hxx 5.77 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 "Chrono.hxx"
32
#include "Compiler.h"
33

34 35
#include <string>

36
struct Instance;
37
class MultipleOutputs;
38
class SongLoader;
39

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

48 49
	Instance &instance;

50 51
	const std::string name;

52
	MaskMonitor global_events;
53

54 55
	struct playlist playlist;

56 57
	MultipleOutputs outputs;

58
	PlayerControl pc;
59

60 61
	ReplayGainMode replay_gain_mode = ReplayGainMode::OFF;

62
	Partition(Instance &_instance,
63
		  const char *_name,
64
		  unsigned max_length,
65
		  unsigned buffer_chunks,
66
		  unsigned buffered_before_play,
67
		  AudioFormat configured_audio_format,
68
		  const ReplayGainConfig &replay_gain_config);
69

70 71 72
	void EmitGlobalEvent(unsigned mask) {
		global_events.OrMask(mask);
	}
73

74 75
	void EmitIdle(unsigned mask);

76 77 78 79
	void ClearQueue() {
		playlist.Clear(pc);
	}

80
	unsigned AppendURI(const SongLoader &loader,
81 82
			   const char *uri_utf8) {
		return playlist.AppendURI(pc, loader, uri_utf8);
83 84
	}

85 86
	void DeletePosition(unsigned position) {
		playlist.DeletePosition(pc, position);
87 88
	}

89 90
	void DeleteId(unsigned id) {
		playlist.DeleteId(pc, id);
91 92 93 94 95 96 97 98
	}

	/**
	 * 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
	 */
99 100
	void DeleteRange(unsigned start, unsigned end) {
		playlist.DeleteRange(pc, start, end);
101 102
	}

103 104
	void StaleSong(const char *uri) {
		playlist.StaleSong(pc, uri);
105 106 107 108 109 110
	}

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

111 112
	void MoveRange(unsigned start, unsigned end, int to) {
		playlist.MoveRange(pc, start, end, to);
113 114
	}

115 116
	void MoveId(unsigned id, int to) {
		playlist.MoveId(pc, id, to);
117 118
	}

119 120
	void SwapPositions(unsigned song1, unsigned song2) {
		playlist.SwapPositions(pc, song1, song2);
121 122
	}

123 124
	void SwapIds(unsigned id1, unsigned id2) {
		playlist.SwapIds(pc, id1, id2);
125 126
	}

127 128 129 130
	void SetPriorityRange(unsigned start_position, unsigned end_position,
			      uint8_t priority) {
		playlist.SetPriorityRange(pc, start_position, end_position,
					  priority);
131 132
	}

133 134
	void SetPriorityId(unsigned song_id, uint8_t priority) {
		playlist.SetPriorityId(pc, song_id, priority);
135 136 137 138 139 140
	}

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

141 142
	void PlayPosition(int position) {
		return playlist.PlayPosition(pc, position);
143 144
	}

145 146
	void PlayId(int id) {
		return playlist.PlayId(pc, id);
147 148
	}

149 150
	void PlayNext() {
		return playlist.PlayNext(pc);
151 152
	}

153 154
	void PlayPrevious() {
		return playlist.PlayPrevious(pc);
155 156
	}

157 158
	void SeekSongPosition(unsigned song_position, SongTime seek_time) {
		playlist.SeekSongPosition(pc, song_position, seek_time);
159 160
	}

161 162
	void SeekSongId(unsigned song_id, SongTime seek_time) {
		playlist.SeekSongId(pc, song_id, seek_time);
163 164
	}

165 166
	void SeekCurrent(SignedSongTime seek_time, bool relative) {
		playlist.SeekCurrent(pc, seek_time, relative);
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
	}

	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);
	}

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

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

189 190 191 192 193
	void SetReplayGainMode(ReplayGainMode mode) {
		replay_gain_mode = mode;
		UpdateEffectiveReplayGainMode();
	}

194 195
	/**
	 * Publishes the effective #ReplayGainMode to all subsystems.
196
	 * #ReplayGainMode::AUTO is substituted.
197
	 */
198
	void UpdateEffectiveReplayGainMode();
199

200
#ifdef ENABLE_DATABASE
201 202 203 204 205
	/**
	 * Returns the global #Database instance.  May return nullptr
	 * if this MPD configuration has no database (no
	 * music_directory was configured).
	 */
206
	const Database *GetDatabase() const;
207

208 209
	const Database &GetDatabaseOrThrow() const;

210 211 212 213
	/**
	 * The database has been modified.  Propagate the change to
	 * all subsystems.
	 */
214
	void DatabaseModified(const Database &db);
215
#endif
216

217
	/**
218 219
	 * A tag in the play queue has been modified by the player
	 * thread.  Propagate the change to all subsystems.
220 221 222 223 224 225 226
	 */
	void TagModified();

	/**
	 * Synchronize the player with the play queue.
	 */
	void SyncWithPlayer();
227 228

private:
229 230 231 232 233
	/* virtual methods from class QueueListener */
	void OnQueueModified() override;
	void OnQueueOptionsChanged() override;
	void OnQueueSongStarted() override;

234
	/* virtual methods from class PlayerListener */
235 236
	void OnPlayerSync() noexcept override;
	void OnPlayerTagModified() noexcept override;
237

238
	/* virtual methods from class MixerListener */
239
	void OnMixerVolumeChanged(Mixer &mixer, int volume) override;
240 241 242

	/* callback for #global_events */
	void OnGlobalEvent(unsigned mask);
243 244 245
};

#endif