queue/Print: support sorting by priority

This commit is contained in:
Max Kellermann 2022-02-14 14:08:26 +01:00
parent 2172aaf1ce
commit ab5b6f83fd
4 changed files with 19 additions and 1 deletions

View File

@ -787,7 +787,8 @@ Whenever possible, ids should be used.
"ArtistSort", "AlbumSort" or "AlbumArtistSort" instead. These
will automatically fall back to the former if "\*Sort" doesn't
exist. "AlbumArtist" falls back to just "Artist". The type
"Last-Modified" can sort by file modification time.
"Last-Modified" can sort by file modification time, and "prio"
sorts by queue priority.
``window`` can be used to query only a portion of the real
response. The parameter is two zero-based queue positions; a

View File

@ -293,6 +293,9 @@ ParseSortTag(const char *s)
if (StringIsEqualIgnoreCase(s, "Last-Modified"))
return TagType(SORT_TAG_LAST_MODIFIED);
if (StringIsEqualIgnoreCase(s, "prio"))
return TagType(SORT_TAG_PRIO);
TagType tag = tag_name_parse_i(s);
if (tag == TAG_NUM_OF_ITEM_TYPES)
throw ProtocolError(ACK_ERROR_ARG, "Unknown sort tag");

View File

@ -143,6 +143,15 @@ PrintSortedQueue(Response &r, const Queue &queue,
return a.GetLastModified() < b.GetLastModified();
});
else if (sort == TagType(SORT_TAG_PRIO))
std::stable_sort(v.begin(), v.end(),
[&queue, descending](unsigned a_pos, unsigned b_pos){
if (descending)
std::swap(a_pos, b_pos);
return queue.GetPriorityAtPosition(a_pos) <
queue.GetPriorityAtPosition(b_pos);
});
else
std::stable_sort(v.begin(), v.end(),
[&queue, sort, descending](unsigned a_pos,

View File

@ -31,6 +31,11 @@
*/
#define SORT_TAG_LAST_MODIFIED (TAG_NUM_OF_ITEM_TYPES + 3)
/**
* Special value for QueueSelection::sort
*/
#define SORT_TAG_PRIO (TAG_NUM_OF_ITEM_TYPES + 4)
template<typename T> struct ConstBuffer;
enum TagType : uint8_t;
struct LightSong;