Partition.hxx 4.89 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2014 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
#include "PlayerControl.hxx"
27
#include "PlayerListener.hxx"
28

29
struct Instance;
30
class MultipleOutputs;
31
class SongLoader;
32

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

40 41
	struct playlist playlist;

42 43
	MultipleOutputs outputs;

44
	PlayerControl pc;
45

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

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

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

64
	PlaylistResult DeletePosition(unsigned position) {
65 66 67
		return playlist.DeletePosition(pc, position);
	}

68
	PlaylistResult DeleteId(unsigned id) {
69 70 71 72 73 74 75 76 77
		return playlist.DeleteId(pc, id);
	}

	/**
	 * 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
	 */
78
	PlaylistResult DeleteRange(unsigned start, unsigned end) {
79 80 81
		return playlist.DeleteRange(pc, start, end);
	}

82 83
#ifdef ENABLE_DATABASE

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

88 89
#endif

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

94
	PlaylistResult MoveRange(unsigned start, unsigned end, int to) {
95 96 97
		return playlist.MoveRange(pc, start, end, to);
	}

98
	PlaylistResult MoveId(unsigned id, int to) {
99 100 101
		return playlist.MoveId(pc, id, to);
	}

102
	PlaylistResult SwapPositions(unsigned song1, unsigned song2) {
103 104 105
		return playlist.SwapPositions(pc, song1, song2);
	}

106
	PlaylistResult SwapIds(unsigned id1, unsigned id2) {
107 108 109
		return playlist.SwapIds(pc, id1, id2);
	}

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

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

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

127
	PlaylistResult PlayPosition(int position) {
128 129 130
		return playlist.PlayPosition(pc, position);
	}

131
	PlaylistResult PlayId(int id) {
132 133 134 135 136 137 138 139 140 141 142
		return playlist.PlayId(pc, id);
	}

	void PlayNext() {
		return playlist.PlayNext(pc);
	}

	void PlayPrevious() {
		return playlist.PlayPrevious(pc);
	}

143 144
	PlaylistResult SeekSongPosition(unsigned song_position,
					float seek_time) {
145 146 147
		return playlist.SeekSongPosition(pc, song_position, seek_time);
	}

148
	PlaylistResult SeekSongId(unsigned song_id, float seek_time) {
149 150 151
		return playlist.SeekSongId(pc, song_id, seek_time);
	}

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

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

176
#ifdef ENABLE_DATABASE
177 178 179 180
	/**
	 * The database has been modified.  Propagate the change to
	 * all subsystems.
	 */
181
	void DatabaseModified(const Database &db);
182
#endif
183

184
	/**
185 186
	 * A tag in the play queue has been modified by the player
	 * thread.  Propagate the change to all subsystems.
187 188 189 190 191 192 193
	 */
	void TagModified();

	/**
	 * Synchronize the player with the play queue.
	 */
	void SyncWithPlayer();
194 195

private:
196 197 198 199
	/* virtual methods from class PlayerListener */
	virtual void OnPlayerSync() override;
	virtual void OnPlayerTagModified() override;

200 201
	/* virtual methods from class MixerListener */
	virtual void OnMixerVolumeChanged(Mixer &mixer, int volume) override;
202 203 204
};

#endif