Partition.hxx 5.44 KB
Newer Older
1
/*
2
 * Copyright 2003-2016 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 "Chrono.hxx"
31
#include "Compiler.h"
32

33
struct Instance;
34
class MultipleOutputs;
35
class SongLoader;
36

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

45 46
	Instance &instance;

47
	CallbackMaskMonitor<Partition> global_events;
48

49 50
	struct playlist playlist;

51 52
	MultipleOutputs outputs;

53
	PlayerControl pc;
54

55 56
	Partition(Instance &_instance,
		  unsigned max_length,
57
		  unsigned buffer_chunks,
58
		  unsigned buffered_before_play);
59

60 61 62
	void EmitGlobalEvent(unsigned mask) {
		global_events.OrMask(mask);
	}
63

64 65
	void EmitIdle(unsigned mask);

66 67 68 69
	void ClearQueue() {
		playlist.Clear(pc);
	}

70 71 72 73
	unsigned AppendURI(const SongLoader &loader,
			   const char *uri_utf8,
			   Error &error) {
		return playlist.AppendURI(pc, loader, uri_utf8, error);
74 75
	}

76 77
	void DeletePosition(unsigned position) {
		playlist.DeletePosition(pc, position);
78 79
	}

80 81
	void DeleteId(unsigned id) {
		playlist.DeleteId(pc, id);
82 83 84 85 86 87 88 89
	}

	/**
	 * 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
	 */
90 91
	void DeleteRange(unsigned start, unsigned end) {
		playlist.DeleteRange(pc, start, end);
92 93
	}

94 95
	void StaleSong(const char *uri) {
		playlist.StaleSong(pc, uri);
96 97 98 99 100 101
	}

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

102 103
	void MoveRange(unsigned start, unsigned end, int to) {
		playlist.MoveRange(pc, start, end, to);
104 105
	}

106 107
	void MoveId(unsigned id, int to) {
		playlist.MoveId(pc, id, to);
108 109
	}

110 111
	void SwapPositions(unsigned song1, unsigned song2) {
		playlist.SwapPositions(pc, song1, song2);
112 113
	}

114 115
	void SwapIds(unsigned id1, unsigned id2) {
		playlist.SwapIds(pc, id1, id2);
116 117
	}

118 119 120 121
	void SetPriorityRange(unsigned start_position, unsigned end_position,
			      uint8_t priority) {
		playlist.SetPriorityRange(pc, start_position, end_position,
					  priority);
122 123
	}

124 125
	void SetPriorityId(unsigned song_id, uint8_t priority) {
		playlist.SetPriorityId(pc, song_id, priority);
126 127 128 129 130 131
	}

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

132 133
	bool PlayPosition(int position, Error &error) {
		return playlist.PlayPosition(pc, position, error);
134 135
	}

136 137
	bool PlayId(int id, Error &error) {
		return playlist.PlayId(pc, id, error);
138 139
	}

140 141
	bool PlayNext(Error &error) {
		return playlist.PlayNext(pc, error);
142 143
	}

144 145
	bool PlayPrevious(Error &error) {
		return playlist.PlayPrevious(pc, error);
146 147
	}

148 149 150 151
	bool SeekSongPosition(unsigned song_position,
			      SongTime seek_time, Error &error) {
		return playlist.SeekSongPosition(pc, song_position, seek_time,
						 error);
152 153
	}

154 155
	bool SeekSongId(unsigned song_id, SongTime seek_time, Error &error) {
		return playlist.SeekSongId(pc, song_id, seek_time, error);
156 157
	}

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

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

183
#ifdef ENABLE_DATABASE
184 185 186 187 188 189 190
	/**
	 * Returns the global #Database instance.  May return nullptr
	 * if this MPD configuration has no database (no
	 * music_directory was configured).
	 */
	const Database *GetDatabase(Error &error) const;

191 192 193 194
	/**
	 * The database has been modified.  Propagate the change to
	 * all subsystems.
	 */
195
	void DatabaseModified(const Database &db);
196
#endif
197

198
	/**
199 200
	 * A tag in the play queue has been modified by the player
	 * thread.  Propagate the change to all subsystems.
201 202 203 204 205 206 207
	 */
	void TagModified();

	/**
	 * Synchronize the player with the play queue.
	 */
	void SyncWithPlayer();
208 209

private:
210 211 212 213 214
	/* virtual methods from class QueueListener */
	void OnQueueModified() override;
	void OnQueueOptionsChanged() override;
	void OnQueueSongStarted() override;

215
	/* virtual methods from class PlayerListener */
216 217
	void OnPlayerSync() override;
	void OnPlayerTagModified() override;
218

219
	/* virtual methods from class MixerListener */
220
	void OnMixerVolumeChanged(Mixer &mixer, int volume) override;
221 222 223

	/* callback for #global_events */
	void OnGlobalEvent(unsigned mask);
224 225 226
};

#endif