QueuePrint.cxx 3.03 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13
 * 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.
14 15 16 17
 *
 * 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.
18 19
 */

20
#include "QueuePrint.hxx"
21
#include "Queue.hxx"
22
#include "song/Filter.hxx"
Max Kellermann's avatar
Max Kellermann committed
23
#include "SongPrint.hxx"
24 25
#include "song/DetachedSong.hxx"
#include "song/LightSong.hxx"
26
#include "client/Response.hxx"
27

28 29 30 31 32 33 34 35 36
/**
 * Send detailed information about a range of songs in the queue to a
 * client.
 *
 * @param client the client which has requested information
 * @param start the index of the first song (including)
 * @param end the index of the last song (excluding)
 */
static void
37
queue_print_song_info(Response &r, const Queue &queue,
38 39
		      unsigned position)
{
40
	song_print_info(r, queue.Get(position));
41 42
	r.Format("Pos: %u\nId: %u\n",
		 position, queue.PositionToId(position));
43

44
	uint8_t priority = queue.GetPriorityAtPosition(position);
45
	if (priority != 0)
46
		r.Format("Prio: %u\n", priority);
47 48 49
}

void
50
queue_print_info(Response &r, const Queue &queue,
51 52 53
		 unsigned start, unsigned end)
{
	assert(start <= end);
54
	assert(end <= queue.GetLength());
55 56

	for (unsigned i = start; i < end; ++i)
57
		queue_print_song_info(r, queue, i);
58 59 60
}

void
61
queue_print_uris(Response &r, const Queue &queue,
62 63 64
		 unsigned start, unsigned end)
{
	assert(start <= end);
65
	assert(end <= queue.GetLength());
66 67

	for (unsigned i = start; i < end; ++i) {
68
		r.Format("%i:", i);
69
		song_print_uri(r, queue.Get(i));
70 71 72 73
	}
}

void
74
queue_print_changes_info(Response &r, const Queue &queue,
75 76
			 uint32_t version,
			 unsigned start, unsigned end)
77
{
78 79 80 81 82 83 84 85 86
	assert(start <= end);

	if (start >= queue.GetLength())
		return;

	if (end > queue.GetLength())
		end = queue.GetLength();

	for (unsigned i = start; i < end; i++)
87
		if (queue.IsNewerAtPosition(i, version))
88
			queue_print_song_info(r, queue, i);
89 90 91
}

void
92
queue_print_changes_position(Response &r, const Queue &queue,
93 94
			     uint32_t version,
			     unsigned start, unsigned end)
95
{
96 97 98 99 100 101 102 103 104
	assert(start <= end);

	if (start >= queue.GetLength())
		return;

	if (end > queue.GetLength())
		end = queue.GetLength();

	for (unsigned i = start; i < end; i++)
105
		if (queue.IsNewerAtPosition(i, version))
106 107
			r.Format("cpos: %i\nId: %i\n",
				 i, queue.PositionToId(i));
108
}
109 110

void
111
queue_find(Response &r, const Queue &queue,
112
	   const SongFilter &filter)
113
{
114
	for (unsigned i = 0; i < queue.GetLength(); i++) {
115
		const LightSong song{queue.Get(i)};
116

117
		if (filter.Match(song))
118
			queue_print_song_info(r, queue, i);
119 120
	}
}