From b1067333dcb48682cef019064421ca7401dbc9df Mon Sep 17 00:00:00 2001 From: jcorporation Date: Sun, 1 Sep 2024 16:21:01 +0200 Subject: [PATCH] Print positions in the search playlist functions. --- NEWS | 1 + src/playlist/Print.cxx | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index bf3fba46d..61b928b97 100644 --- a/NEWS +++ b/NEWS @@ -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 + - searching 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 diff --git a/src/playlist/Print.cxx b/src/playlist/Print.cxx index 10fecfa9d..a86f2cd4c 100644 --- a/src/playlist/Print.cxx +++ b/src/playlist/Print.cxx @@ -17,6 +17,8 @@ #include "Partition.hxx" #include "Instance.hxx" #include "PlaylistError.hxx" +#include +#include "client/Response.hxx" static void playlist_provider_print(Response &r, @@ -69,27 +71,34 @@ 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(*song))) - continue; - - if (skip > 0) { - --skip; + if (!filter->Match(static_cast(*song))) { + ++position; continue; } - if (detail) + if (skip > 0) { + --skip; + ++position; + continue; + } + + 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; } }