Partition.hxx 4.99 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2015 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 "queue/Playlist.hxx"
24
#include "output/MultipleOutputs.hxx"
25
#include "mixer/Listener.hxx"
26 27
#include "player/Control.hxx"
#include "player/Listener.hxx"
28
#include "Chrono.hxx"
29
#include "Compiler.h"
30

31
struct Instance;
32
class MultipleOutputs;
33
class SongLoader;
34

35 36 37 38
/**
 * A partition of the Music Player Daemon.  It is a separate unit with
 * a playlist, a player, outputs etc.
 */
39
struct Partition final : private PlayerListener, private MixerListener {
40 41
	Instance &instance;

42 43
	struct playlist playlist;

44 45
	MultipleOutputs outputs;

46
	PlayerControl pc;
47

48 49
	Partition(Instance &_instance,
		  unsigned max_length,
50 51
		  unsigned buffer_chunks,
		  unsigned buffered_before_play)
52
		:instance(_instance), playlist(max_length),
53
		 outputs(*this),
54
		 pc(*this, outputs, buffer_chunks, buffered_before_play) {}
55 56 57 58 59

	void ClearQueue() {
		playlist.Clear(pc);
	}

60 61 62 63
	unsigned AppendURI(const SongLoader &loader,
			   const char *uri_utf8,
			   Error &error) {
		return playlist.AppendURI(pc, loader, uri_utf8, error);
64 65
	}

66 67
	void DeletePosition(unsigned position) {
		playlist.DeletePosition(pc, position);
68 69
	}

70 71
	void DeleteId(unsigned id) {
		playlist.DeleteId(pc, id);
72 73 74 75 76 77 78 79
	}

	/**
	 * 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
	 */
80 81
	void DeleteRange(unsigned start, unsigned end) {
		playlist.DeleteRange(pc, start, end);
82 83
	}

84 85
#ifdef ENABLE_DATABASE

86 87
	void DeleteSong(const char *uri) {
		playlist.DeleteSong(pc, uri);
88 89
	}

90 91
#endif

92 93 94 95
	void Shuffle(unsigned start, unsigned end) {
		playlist.Shuffle(pc, start, end);
	}

96 97
	void MoveRange(unsigned start, unsigned end, int to) {
		playlist.MoveRange(pc, start, end, to);
98 99
	}

100 101
	void MoveId(unsigned id, int to) {
		playlist.MoveId(pc, id, to);
102 103
	}

104 105
	void SwapPositions(unsigned song1, unsigned song2) {
		playlist.SwapPositions(pc, song1, song2);
106 107
	}

108 109
	void SwapIds(unsigned id1, unsigned id2) {
		playlist.SwapIds(pc, id1, id2);
110 111
	}

112 113 114 115
	void SetPriorityRange(unsigned start_position, unsigned end_position,
			      uint8_t priority) {
		playlist.SetPriorityRange(pc, start_position, end_position,
					  priority);
116 117
	}

118 119
	void SetPriorityId(unsigned song_id, uint8_t priority) {
		playlist.SetPriorityId(pc, song_id, priority);
120 121 122 123 124 125
	}

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

126 127
	void PlayPosition(int position) {
		playlist.PlayPosition(pc, position);
128 129
	}

130 131
	void PlayId(int id) {
		playlist.PlayId(pc, id);
132 133 134
	}

	void PlayNext() {
135
		playlist.PlayNext(pc);
136 137 138
	}

	void PlayPrevious() {
139
		playlist.PlayPrevious(pc);
140 141
	}

142 143 144 145
	bool SeekSongPosition(unsigned song_position,
			      SongTime seek_time, Error &error) {
		return playlist.SeekSongPosition(pc, song_position, seek_time,
						 error);
146 147
	}

148 149
	bool SeekSongId(unsigned song_id, SongTime seek_time, Error &error) {
		return playlist.SeekSongId(pc, song_id, seek_time, error);
150 151
	}

152 153 154
	bool SeekCurrent(SignedSongTime seek_time, bool relative,
			 Error &error) {
		return playlist.SeekCurrent(pc, seek_time, relative, error);
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
	}

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

177
#ifdef ENABLE_DATABASE
178 179 180 181 182 183 184
	/**
	 * 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;

185 186 187 188
	/**
	 * The database has been modified.  Propagate the change to
	 * all subsystems.
	 */
189
	void DatabaseModified(const Database &db);
190
#endif
191

192
	/**
193 194
	 * A tag in the play queue has been modified by the player
	 * thread.  Propagate the change to all subsystems.
195 196 197 198 199 200 201
	 */
	void TagModified();

	/**
	 * Synchronize the player with the play queue.
	 */
	void SyncWithPlayer();
202 203

private:
204 205 206 207
	/* virtual methods from class PlayerListener */
	virtual void OnPlayerSync() override;
	virtual void OnPlayerTagModified() override;

208 209
	/* virtual methods from class MixerListener */
	virtual void OnMixerVolumeChanged(Mixer &mixer, int volume) override;
210 211 212
};

#endif