Partition.hxx 5.69 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
struct Instance;
35
class MultipleOutputs;
36
class SongLoader;
37

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

46 47
	Instance &instance;

48
	MaskMonitor global_events;
49

50 51
	struct playlist playlist;

52 53
	MultipleOutputs outputs;

54
	PlayerControl pc;
55

56 57
	ReplayGainMode replay_gain_mode = ReplayGainMode::OFF;

58 59
	Partition(Instance &_instance,
		  unsigned max_length,
60
		  unsigned buffer_chunks,
61
		  unsigned buffered_before_play,
62
		  AudioFormat configured_audio_format,
63
		  const ReplayGainConfig &replay_gain_config);
64

65 66 67
	void EmitGlobalEvent(unsigned mask) {
		global_events.OrMask(mask);
	}
68

69 70
	void EmitIdle(unsigned mask);

71 72 73 74
	void ClearQueue() {
		playlist.Clear(pc);
	}

75
	unsigned AppendURI(const SongLoader &loader,
76 77
			   const char *uri_utf8) {
		return playlist.AppendURI(pc, loader, uri_utf8);
78 79
	}

80 81
	void DeletePosition(unsigned position) {
		playlist.DeletePosition(pc, position);
82 83
	}

84 85
	void DeleteId(unsigned id) {
		playlist.DeleteId(pc, id);
86 87 88 89 90 91 92 93
	}

	/**
	 * 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
	 */
94 95
	void DeleteRange(unsigned start, unsigned end) {
		playlist.DeleteRange(pc, start, end);
96 97
	}

98 99
	void StaleSong(const char *uri) {
		playlist.StaleSong(pc, uri);
100 101 102 103 104 105
	}

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

106 107
	void MoveRange(unsigned start, unsigned end, int to) {
		playlist.MoveRange(pc, start, end, to);
108 109
	}

110 111
	void MoveId(unsigned id, int to) {
		playlist.MoveId(pc, id, to);
112 113
	}

114 115
	void SwapPositions(unsigned song1, unsigned song2) {
		playlist.SwapPositions(pc, song1, song2);
116 117
	}

118 119
	void SwapIds(unsigned id1, unsigned id2) {
		playlist.SwapIds(pc, id1, id2);
120 121
	}

122 123 124 125
	void SetPriorityRange(unsigned start_position, unsigned end_position,
			      uint8_t priority) {
		playlist.SetPriorityRange(pc, start_position, end_position,
					  priority);
126 127
	}

128 129
	void SetPriorityId(unsigned song_id, uint8_t priority) {
		playlist.SetPriorityId(pc, song_id, priority);
130 131 132 133 134 135
	}

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

136 137
	void PlayPosition(int position) {
		return playlist.PlayPosition(pc, position);
138 139
	}

140 141
	void PlayId(int id) {
		return playlist.PlayId(pc, id);
142 143
	}

144 145
	void PlayNext() {
		return playlist.PlayNext(pc);
146 147
	}

148 149
	void PlayPrevious() {
		return playlist.PlayPrevious(pc);
150 151
	}

152 153
	void SeekSongPosition(unsigned song_position, SongTime seek_time) {
		playlist.SeekSongPosition(pc, song_position, seek_time);
154 155
	}

156 157
	void SeekSongId(unsigned song_id, SongTime seek_time) {
		playlist.SeekSongId(pc, song_id, seek_time);
158 159
	}

160 161
	void SeekCurrent(SignedSongTime seek_time, bool relative) {
		playlist.SeekCurrent(pc, seek_time, relative);
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
	}

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

184 185 186 187 188
	void SetReplayGainMode(ReplayGainMode mode) {
		replay_gain_mode = mode;
		UpdateEffectiveReplayGainMode();
	}

189 190
	/**
	 * Publishes the effective #ReplayGainMode to all subsystems.
191
	 * #ReplayGainMode::AUTO is substituted.
192
	 */
193
	void UpdateEffectiveReplayGainMode();
194

195
#ifdef ENABLE_DATABASE
196 197 198 199 200
	/**
	 * Returns the global #Database instance.  May return nullptr
	 * if this MPD configuration has no database (no
	 * music_directory was configured).
	 */
201
	const Database *GetDatabase() const;
202

203 204 205
	gcc_pure
	const Database &GetDatabaseOrThrow() const;

206 207 208 209
	/**
	 * The database has been modified.  Propagate the change to
	 * all subsystems.
	 */
210
	void DatabaseModified(const Database &db);
211
#endif
212

213
	/**
214 215
	 * A tag in the play queue has been modified by the player
	 * thread.  Propagate the change to all subsystems.
216 217 218 219 220 221 222
	 */
	void TagModified();

	/**
	 * Synchronize the player with the play queue.
	 */
	void SyncWithPlayer();
223 224

private:
225 226 227 228 229
	/* virtual methods from class QueueListener */
	void OnQueueModified() override;
	void OnQueueOptionsChanged() override;
	void OnQueueSongStarted() override;

230
	/* virtual methods from class PlayerListener */
231 232
	void OnPlayerSync() override;
	void OnPlayerTagModified() override;
233

234
	/* virtual methods from class MixerListener */
235
	void OnMixerVolumeChanged(Mixer &mixer, int volume) override;
236 237 238

	/* callback for #global_events */
	void OnGlobalEvent(unsigned mask);
239 240 241
};

#endif