QueuePrint.cxx 3.05 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 "song/Filter.hxx"
Max Kellermann's avatar
Max Kellermann committed
24
#include "SongPrint.hxx"
25 26
#include "song/DetachedSong.hxx"
#include "song/LightSong.hxx"
27
#include "client/Response.hxx"
28

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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