command/queue: add range parameter to plchanges and plchangesposid

This commit is contained in:
Max Kellermann 2015-10-27 20:35:40 +01:00
parent 15e432204e
commit 8acf996d90
8 changed files with 58 additions and 18 deletions

1
NEWS
View File

@ -5,6 +5,7 @@ ver 0.20 (not yet released)
- report song duration with milliseconds precision
- "sticker find" can match sticker values
- drop the "file:///" prefix for absolute file paths
- add range parameter to command "plchanges" and "plchangesposid"
* tags
- ape, ogg: drop support for non-standard tag "album artist"
affected filetypes: vorbis, flac, opus & all files with ape2 tags

View File

@ -1161,12 +1161,15 @@ OK
<cmdsynopsis>
<command>plchanges</command>
<arg choice="req"><replaceable>VERSION</replaceable></arg>
<arg><replaceable>START:END</replaceable></arg>
</cmdsynopsis>
</term>
<listitem>
<para>
Displays changed songs currently in the playlist since
<varname>VERSION</varname>.
<varname>VERSION</varname>. Start and end positions may
be given to limit the output to changes in the given
range.
</para>
<para>
To detect songs that were deleted at the end of the
@ -1179,6 +1182,7 @@ OK
<cmdsynopsis>
<command>plchangesposid</command>
<arg choice="req"><replaceable>VERSION</replaceable></arg>
<arg><replaceable>START:END</replaceable></arg>
</cmdsynopsis>
</term>
<listitem>

View File

@ -104,17 +104,21 @@ playlist_print_find(Response &r, Partition &partition,
void
playlist_print_changes_info(Response &r, Partition &partition,
const playlist &playlist,
uint32_t version)
uint32_t version,
unsigned start, unsigned end)
{
queue_print_changes_info(r, partition, playlist.queue, version);
queue_print_changes_info(r, partition, playlist.queue, version,
start, end);
}
void
playlist_print_changes_position(Response &r,
const playlist &playlist,
uint32_t version)
uint32_t version,
unsigned start, unsigned end)
{
queue_print_changes_position(r, playlist.queue, version);
queue_print_changes_position(r, playlist.queue, version,
start, end);
}
#ifdef ENABLE_DATABASE

View File

@ -79,7 +79,8 @@ playlist_print_find(Response &r, Partition &partition,
void
playlist_print_changes_info(Response &r, Partition &partition,
const playlist &playlist,
uint32_t version);
uint32_t version,
unsigned start, unsigned end);
/**
* Print changes since the specified playlist version, position only.
@ -87,7 +88,8 @@ playlist_print_changes_info(Response &r, Partition &partition,
void
playlist_print_changes_position(Response &r,
const playlist &playlist,
uint32_t version);
uint32_t version,
unsigned start, unsigned end);
/**
* Send the stored playlist to the client.

View File

@ -148,8 +148,8 @@ static constexpr struct command commands[] = {
{ "playlistinfo", PERMISSION_READ, 0, 1, handle_playlistinfo },
{ "playlistmove", PERMISSION_CONTROL, 3, 3, handle_playlistmove },
{ "playlistsearch", PERMISSION_READ, 2, -1, handle_playlistsearch },
{ "plchanges", PERMISSION_READ, 1, 1, handle_plchanges },
{ "plchangesposid", PERMISSION_READ, 1, 1, handle_plchangesposid },
{ "plchanges", PERMISSION_READ, 1, 2, handle_plchanges },
{ "plchangesposid", PERMISSION_READ, 1, 2, handle_plchangesposid },
{ "previous", PERMISSION_CONTROL, 0, 0, handle_previous },
{ "prio", PERMISSION_CONTROL, 2, -1, handle_prio },
{ "prioid", PERMISSION_CONTROL, 2, -1, handle_prioid },

View File

@ -251,8 +251,13 @@ handle_plchanges(Client &client, Request args, Response &r)
if (!ParseCommandArg32(r, version, args.front()))
return CommandResult::ERROR;
RangeArg range = RangeArg::All();
if (!args.ParseOptional(1, range, r))
return CommandResult::ERROR;
playlist_print_changes_info(r, client.partition,
client.playlist, version);
client.playlist, version,
range.start, range.end);
return CommandResult::OK;
}
@ -263,7 +268,12 @@ handle_plchangesposid(Client &client, Request args, Response &r)
if (!ParseCommandArg32(r, version, args.front()))
return CommandResult::ERROR;
playlist_print_changes_position(r, client.playlist, version);
RangeArg range = RangeArg::All();
if (!args.ParseOptional(1, range, r))
return CommandResult::ERROR;
playlist_print_changes_position(r, client.playlist, version,
range.start, range.end);
return CommandResult::OK;
}

View File

@ -71,19 +71,36 @@ queue_print_uris(Response &r, Partition &partition, const Queue &queue,
void
queue_print_changes_info(Response &r, Partition &partition, const Queue &queue,
uint32_t version)
uint32_t version,
unsigned start, unsigned end)
{
for (unsigned i = 0; i < queue.GetLength(); i++) {
assert(start <= end);
if (start >= queue.GetLength())
return;
if (end > queue.GetLength())
end = queue.GetLength();
for (unsigned i = start; i < end; i++)
if (queue.IsNewerAtPosition(i, version))
queue_print_song_info(r, partition, queue, i);
}
}
void
queue_print_changes_position(Response &r, const Queue &queue,
uint32_t version)
uint32_t version,
unsigned start, unsigned end)
{
for (unsigned i = 0; i < queue.GetLength(); i++)
assert(start <= end);
if (start >= queue.GetLength())
return;
if (end > queue.GetLength())
end = queue.GetLength();
for (unsigned i = start; i < end; i++)
if (queue.IsNewerAtPosition(i, version))
r.Format("cpos: %i\nId: %i\n",
i, queue.PositionToId(i));

View File

@ -42,11 +42,13 @@ queue_print_uris(Response &r, Partition &partition, const Queue &queue,
void
queue_print_changes_info(Response &r, Partition &partition, const Queue &queue,
uint32_t version);
uint32_t version,
unsigned start, unsigned end);
void
queue_print_changes_position(Response &r, const Queue &queue,
uint32_t version);
uint32_t version,
unsigned start, unsigned end);
void
queue_find(Response &response, Partition &partition, const Queue &queue,