Partition.hxx 4.94 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
#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
	PlaylistResult DeletePosition(unsigned position) {
67 68 69
		return playlist.DeletePosition(pc, position);
	}

70
	PlaylistResult DeleteId(unsigned id) {
71 72 73 74 75 76 77 78 79
		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
	 */
80
	PlaylistResult DeleteRange(unsigned start, unsigned end) {
81 82 83
		return playlist.DeleteRange(pc, start, end);
	}

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
	PlaylistResult MoveRange(unsigned start, unsigned end, int to) {
97 98 99
		return playlist.MoveRange(pc, start, end, to);
	}

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

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

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

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

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

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

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

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

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

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

145
	PlaylistResult SeekSongPosition(unsigned song_position,
146
					SongTime seek_time) {
147 148 149
		return playlist.SeekSongPosition(pc, song_position, seek_time);
	}

150
	PlaylistResult SeekSongId(unsigned song_id, SongTime seek_time) {
151 152 153
		return playlist.SeekSongId(pc, song_id, seek_time);
	}

154
	PlaylistResult SeekCurrent(SignedSongTime seek_time, bool relative) {
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
		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);
	}
177

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

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

	/**
	 * Synchronize the player with the play queue.
	 */
	void SyncWithPlayer();
196 197

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

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

#endif