2009-01-23 16:23:59 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 The Music Player Daemon Project
|
2009-01-23 16:23:59 +01:00
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2009-01-23 16:23:59 +01:00
|
|
|
*/
|
|
|
|
|
2012-08-29 19:27:03 +02:00
|
|
|
#include "QueuePrint.hxx"
|
2013-01-04 20:50:00 +01:00
|
|
|
#include "Queue.hxx"
|
2018-08-02 13:45:43 +02:00
|
|
|
#include "song/Filter.hxx"
|
2013-01-02 20:29:24 +01:00
|
|
|
#include "SongPrint.hxx"
|
2018-08-02 13:45:43 +02:00
|
|
|
#include "song/DetachedSong.hxx"
|
|
|
|
#include "song/LightSong.hxx"
|
2015-08-06 22:10:25 +02:00
|
|
|
#include "client/Response.hxx"
|
2012-08-29 19:07:30 +02:00
|
|
|
|
2009-03-29 19:58:26 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2017-02-24 13:56:13 +01:00
|
|
|
queue_print_song_info(Response &r, const Queue &queue,
|
2009-01-23 16:23:59 +01:00
|
|
|
unsigned position)
|
|
|
|
{
|
2017-02-24 13:56:13 +01:00
|
|
|
song_print_info(r, queue.Get(position));
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Format("Pos: %u\nId: %u\n",
|
|
|
|
position, queue.PositionToId(position));
|
2011-07-19 00:34:33 +02:00
|
|
|
|
2013-10-19 18:48:38 +02:00
|
|
|
uint8_t priority = queue.GetPriorityAtPosition(position);
|
2011-07-19 00:34:33 +02:00
|
|
|
if (priority != 0)
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Format("Prio: %u\n", priority);
|
2009-01-23 16:23:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-24 13:56:13 +01:00
|
|
|
queue_print_info(Response &r, const Queue &queue,
|
2009-01-23 16:23:59 +01:00
|
|
|
unsigned start, unsigned end)
|
|
|
|
{
|
|
|
|
assert(start <= end);
|
2013-10-19 18:48:38 +02:00
|
|
|
assert(end <= queue.GetLength());
|
2009-01-23 16:23:59 +01:00
|
|
|
|
|
|
|
for (unsigned i = start; i < end; ++i)
|
2017-02-24 13:56:13 +01:00
|
|
|
queue_print_song_info(r, queue, i);
|
2009-01-23 16:23:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-24 13:56:13 +01:00
|
|
|
queue_print_uris(Response &r, const Queue &queue,
|
2009-01-23 16:23:59 +01:00
|
|
|
unsigned start, unsigned end)
|
|
|
|
{
|
|
|
|
assert(start <= end);
|
2013-10-19 18:48:38 +02:00
|
|
|
assert(end <= queue.GetLength());
|
2009-01-23 16:23:59 +01:00
|
|
|
|
|
|
|
for (unsigned i = start; i < end; ++i) {
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Format("%i:", i);
|
2017-02-24 13:56:13 +01:00
|
|
|
song_print_uri(r, queue.Get(i));
|
2009-01-23 16:23:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-24 13:56:13 +01:00
|
|
|
queue_print_changes_info(Response &r, const Queue &queue,
|
2015-10-27 20:35:40 +01:00
|
|
|
uint32_t version,
|
|
|
|
unsigned start, unsigned end)
|
2009-01-23 16:23:59 +01:00
|
|
|
{
|
2015-10-27 20:35:40 +01:00
|
|
|
assert(start <= end);
|
|
|
|
|
|
|
|
if (start >= queue.GetLength())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (end > queue.GetLength())
|
|
|
|
end = queue.GetLength();
|
|
|
|
|
|
|
|
for (unsigned i = start; i < end; i++)
|
2013-10-19 18:48:38 +02:00
|
|
|
if (queue.IsNewerAtPosition(i, version))
|
2017-02-24 13:56:13 +01:00
|
|
|
queue_print_song_info(r, queue, i);
|
2009-01-23 16:23:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-06 22:10:25 +02:00
|
|
|
queue_print_changes_position(Response &r, const Queue &queue,
|
2015-10-27 20:35:40 +01:00
|
|
|
uint32_t version,
|
|
|
|
unsigned start, unsigned end)
|
2009-01-23 16:23:59 +01:00
|
|
|
{
|
2015-10-27 20:35:40 +01:00
|
|
|
assert(start <= end);
|
|
|
|
|
|
|
|
if (start >= queue.GetLength())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (end > queue.GetLength())
|
|
|
|
end = queue.GetLength();
|
|
|
|
|
|
|
|
for (unsigned i = start; i < end; i++)
|
2013-10-19 18:48:38 +02:00
|
|
|
if (queue.IsNewerAtPosition(i, version))
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Format("cpos: %i\nId: %i\n",
|
|
|
|
i, queue.PositionToId(i));
|
2009-01-23 16:23:59 +01:00
|
|
|
}
|
2009-01-24 14:55:28 +01:00
|
|
|
|
|
|
|
void
|
2017-02-24 13:56:13 +01:00
|
|
|
queue_find(Response &r, const Queue &queue,
|
2012-08-29 19:27:03 +02:00
|
|
|
const SongFilter &filter)
|
2009-01-24 14:55:28 +01:00
|
|
|
{
|
2013-10-19 18:48:38 +02:00
|
|
|
for (unsigned i = 0; i < queue.GetLength(); i++) {
|
2018-07-25 07:43:05 +02:00
|
|
|
const LightSong song{queue.Get(i)};
|
2009-01-24 14:55:28 +01:00
|
|
|
|
2013-10-19 18:48:38 +02:00
|
|
|
if (filter.Match(song))
|
2017-02-24 13:56:13 +01:00
|
|
|
queue_print_song_info(r, queue, i);
|
2009-01-24 14:55:28 +01:00
|
|
|
}
|
|
|
|
}
|