Skip to content

Commit

Permalink
Print positions in the list playlist functions.
Browse files Browse the repository at this point in the history
For simple listing this can be done by the client, but for the search case the client can not determine the correct position.

I hope this does not break existing client implementations.
  • Loading branch information
jcorporation committed Sep 1, 2024
1 parent a3a0728 commit f8b5861
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ver 0.24 (not yet released)
- "sticker find" supports sort and window parameter and new sticker compare operators "eq", "lt" and "gt"
- consume only idle flags that were subscribed to
- volume command is no longer deprecated
- listing stored playlists respond now with song position
* database
- attribute "added" shows when each song was added to the database
- fix integer overflows with 64-bit inode numbers
Expand Down
24 changes: 19 additions & 5 deletions src/playlist/Print.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "Partition.hxx"
#include "Instance.hxx"
#include "PlaylistError.hxx"
#include <fmt/format.h>
#include "client/Response.hxx"

static void
playlist_provider_print(Response &r,
Expand All @@ -43,12 +45,16 @@ playlist_provider_print(Response &r,

if (playlist_check_translate_song(*song, base_uri,
loader) &&
detail)
detail) {
song_print_info(r, *song);
else
r.Fmt(FMT_STRING("Pos: {}\n"), i);
}
else {
/* fallback if no detail was requested or no
detail was available */
song_print_uri(r, *song);
r.Fmt(FMT_STRING("Pos: {}\n"), i);
}
}
}

Expand All @@ -69,27 +75,35 @@ playlist_provider_search_print(Response &r,

unsigned skip = start_index;
unsigned n = end_index - start_index;
unsigned position = 0;

while ((song = e.NextSong()) != nullptr) {
const bool detail = playlist_check_translate_song(*song, base_uri,
loader);
if (!filter->Match(static_cast<LightSong>(*song)))
if (!filter->Match(static_cast<LightSong>(*song))) {
++position;
continue;
}

if (skip > 0) {
--skip;
++position;
continue;
}

if (detail)
if (detail) {
song_print_info(r, *song);
else
r.Fmt(FMT_STRING("Pos: {}\n"), position);
} else {
/* fallback if no detail was requested or no
detail was available */
song_print_uri(r, *song);
}

if (--n == 0)
break;

++position;
}
}

Expand Down

0 comments on commit f8b5861

Please sign in to comment.