1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
/*
* Copyright 2003-2020 The Music Player Daemon Project
* 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
#include "event/MaskMonitor.hxx"
#include "queue/Playlist.hxx"
#include "queue/Listener.hxx"
#include "output/MultipleOutputs.hxx"
#include "mixer/Listener.hxx"
#include "player/Control.hxx"
#include "player/Listener.hxx"
#include "ReplayGainMode.hxx"
#include "SingleMode.hxx"
#include "Chrono.hxx"
#include "config.h"
#include <boost/intrusive/list.hpp>
#include <string>
#include <memory>
struct Instance;
class MultipleOutputs;
class SongLoader;
class ClientListener;
class Client;
/**
* A partition of the Music Player Daemon. It is a separate unit with
* a playlist, a player, outputs etc.
*/
struct Partition final : QueueListener, PlayerListener, MixerListener {
static constexpr unsigned TAG_MODIFIED = 0x1;
static constexpr unsigned SYNC_WITH_PLAYER = 0x2;
static constexpr unsigned BORDER_PAUSE = 0x4;
Instance &instance;
const std::string name;
std::unique_ptr<ClientListener> listener;
boost::intrusive::list<Client,
boost::intrusive::base_hook<boost::intrusive::list_base_hook<boost::intrusive::tag<Partition>,
boost::intrusive::link_mode<boost::intrusive::normal_link>>>,
boost::intrusive::constant_time_size<false>> clients;
/**
* Monitor for idle events local to this partition.
*/
MaskMonitor idle_monitor;
MaskMonitor global_events;
struct playlist playlist;
MultipleOutputs outputs;
PlayerControl pc;
ReplayGainMode replay_gain_mode = ReplayGainMode::OFF;
Partition(Instance &_instance,
const char *_name,
unsigned max_length,
unsigned buffer_chunks,
AudioFormat configured_audio_format,
const ReplayGainConfig &replay_gain_config) noexcept;
~Partition() noexcept;
void BeginShutdown() noexcept;
void EmitGlobalEvent(unsigned mask) noexcept {
global_events.OrMask(mask);
}
/**
* Emit an "idle" event to all clients of this partition.
*
* This method can be called from any thread.
*/
void EmitIdle(unsigned mask) noexcept {
idle_monitor.OrMask(mask);
}
/**
* Populate the #InputCacheManager with soon-to-be-played song
* files.
*
* Errors will be logged.
*/
void PrefetchQueue() noexcept;
void ClearQueue() noexcept {
playlist.Clear(pc);
}
unsigned AppendURI(const SongLoader &loader,
const char *uri_utf8) {
return playlist.AppendURI(pc, loader, uri_utf8);
}
void DeletePosition(unsigned position) {
playlist.DeletePosition(pc, position);
}
void DeleteId(unsigned id) {
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
*/
void DeleteRange(unsigned start, unsigned end) {
playlist.DeleteRange(pc, start, end);
}
void StaleSong(const char *uri) noexcept {
playlist.StaleSong(pc, uri);
}
void Shuffle(unsigned start, unsigned end) noexcept {
playlist.Shuffle(pc, start, end);
}
void MoveRange(unsigned start, unsigned end, int to) {
playlist.MoveRange(pc, start, end, to);
}
void MoveId(unsigned id, int to) {
playlist.MoveId(pc, id, to);
}
void SwapPositions(unsigned song1, unsigned song2) {
playlist.SwapPositions(pc, song1, song2);
}
void SwapIds(unsigned id1, unsigned id2) {
playlist.SwapIds(pc, id1, id2);
}
void SetPriorityRange(unsigned start_position, unsigned end_position,
uint8_t priority) {
playlist.SetPriorityRange(pc, start_position, end_position,
priority);
}
void SetPriorityId(unsigned song_id, uint8_t priority) {
playlist.SetPriorityId(pc, song_id, priority);
}
void Stop() noexcept {
playlist.Stop(pc);
}
void PlayPosition(int position) {
return playlist.PlayPosition(pc, position);
}
void PlayId(int id) {
return playlist.PlayId(pc, id);
}
void PlayNext() {
return playlist.PlayNext(pc);
}
void PlayPrevious() {
return playlist.PlayPrevious(pc);
}
void SeekSongPosition(unsigned song_position, SongTime seek_time) {
playlist.SeekSongPosition(pc, song_position, seek_time);
}
void SeekSongId(unsigned song_id, SongTime seek_time) {
playlist.SeekSongId(pc, song_id, seek_time);
}
void SeekCurrent(SignedSongTime seek_time, bool relative) {
playlist.SeekCurrent(pc, seek_time, relative);
}
void SetRepeat(bool new_value) noexcept {
playlist.SetRepeat(pc, new_value);
}
bool GetRandom() const noexcept {
return playlist.GetRandom();
}
void SetRandom(bool new_value) noexcept {
playlist.SetRandom(pc, new_value);
}
void SetSingle(SingleMode new_value) noexcept {
playlist.SetSingle(pc, new_value);
}
void SetConsume(bool new_value) noexcept {
playlist.SetConsume(new_value);
}
void SetReplayGainMode(ReplayGainMode mode) noexcept {
replay_gain_mode = mode;
UpdateEffectiveReplayGainMode();
}
/**
* Publishes the effective #ReplayGainMode to all subsystems.
* #ReplayGainMode::AUTO is substituted.
*/
void UpdateEffectiveReplayGainMode() noexcept;
#ifdef ENABLE_DATABASE
/**
* Returns the global #Database instance. May return nullptr
* if this MPD configuration has no database (no
* music_directory was configured).
*/
const Database *GetDatabase() const noexcept;
const Database &GetDatabaseOrThrow() const;
/**
* The database has been modified. Propagate the change to
* all subsystems.
*/
void DatabaseModified(const Database &db) noexcept;
#endif
/**
* A tag in the play queue has been modified by the player
* thread. Propagate the change to all subsystems.
*/
void TagModified() noexcept;
/**
* The tag of the given song has been modified. Propagate the
* change to all instances of this song in the queue.
*/
void TagModified(const char *uri, const Tag &tag) noexcept;
/**
* Synchronize the player with the play queue.
*/
void SyncWithPlayer() noexcept;
/**
* Border pause has just been enabled. Change single mode to off
* if it was one-shot.
*/
void BorderPause() noexcept;
private:
/* virtual methods from class QueueListener */
void OnQueueModified() noexcept override;
void OnQueueOptionsChanged() noexcept override;
void OnQueueSongStarted() noexcept override;
/* virtual methods from class PlayerListener */
void OnPlayerSync() noexcept override;
void OnPlayerTagModified() noexcept override;
void OnBorderPause() noexcept override;
/* virtual methods from class MixerListener */
void OnMixerVolumeChanged(Mixer &mixer, int volume) noexcept override;
/* callback for #idle_monitor */
void OnIdleMonitor(unsigned mask) noexcept;
/* callback for #global_events */
void OnGlobalEvent(unsigned mask) noexcept;
};
#endif
|