QueuePrint.cxx 2.99 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 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 "config.h"
21
#include "QueuePrint.hxx"
22
#include "Queue.hxx"
23
#include "SongFilter.hxx"
Max Kellermann's avatar
Max Kellermann committed
24
#include "SongPrint.hxx"
25
#include "client/Response.hxx"
26

27 28 29 30 31 32 33 34 35
/**
 * 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
36
queue_print_song_info(Response &r, const Queue &queue,
37 38
		      unsigned position)
{
39
	song_print_info(r, queue.Get(position));
40 41
	r.Format("Pos: %u\nId: %u\n",
		 position, queue.PositionToId(position));
42

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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