command/Database: add "sort" parameter to "find" and "search"
Implement the second part of https://bugs.musicpd.org/view.php?id=3990
This commit is contained in:
@@ -96,3 +96,68 @@ Tag::HasType(TagType type) const
|
||||
{
|
||||
return GetValue(type) != nullptr;
|
||||
}
|
||||
|
||||
static TagType
|
||||
DecaySort(TagType type)
|
||||
{
|
||||
switch (type) {
|
||||
case TAG_ARTIST_SORT:
|
||||
return TAG_ARTIST;
|
||||
|
||||
case TAG_ALBUM_SORT:
|
||||
return TAG_ALBUM;
|
||||
|
||||
case TAG_ALBUM_ARTIST_SORT:
|
||||
return TAG_ALBUM_ARTIST;
|
||||
|
||||
default:
|
||||
return TAG_NUM_OF_ITEM_TYPES;
|
||||
}
|
||||
}
|
||||
|
||||
static TagType
|
||||
Fallback(TagType type)
|
||||
{
|
||||
switch (type) {
|
||||
case TAG_ALBUM_ARTIST:
|
||||
return TAG_ARTIST;
|
||||
|
||||
case TAG_MUSICBRAINZ_ALBUMARTISTID:
|
||||
return TAG_MUSICBRAINZ_ARTISTID;
|
||||
|
||||
default:
|
||||
return TAG_NUM_OF_ITEM_TYPES;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
Tag::GetSortValue(TagType type) const
|
||||
{
|
||||
const char *value = GetValue(type);
|
||||
if (value != nullptr)
|
||||
return value;
|
||||
|
||||
/* try without *_SORT */
|
||||
const auto no_sort_type = DecaySort(type);
|
||||
if (no_sort_type != TAG_NUM_OF_ITEM_TYPES) {
|
||||
value = GetValue(no_sort_type);
|
||||
if (value != nullptr)
|
||||
return value;
|
||||
}
|
||||
|
||||
/* fall back from TAG_ALBUM_ARTIST to TAG_ALBUM */
|
||||
|
||||
type = Fallback(type);
|
||||
if (type != TAG_NUM_OF_ITEM_TYPES)
|
||||
return GetSortValue(type);
|
||||
|
||||
if (no_sort_type != TAG_NUM_OF_ITEM_TYPES) {
|
||||
type = Fallback(no_sort_type);
|
||||
if (type != TAG_NUM_OF_ITEM_TYPES)
|
||||
return GetSortValue(type);
|
||||
}
|
||||
|
||||
/* finally fall back to empty string */
|
||||
|
||||
return "";
|
||||
}
|
||||
|
@@ -142,6 +142,15 @@ struct Tag {
|
||||
gcc_pure
|
||||
bool HasType(TagType type) const;
|
||||
|
||||
/**
|
||||
* Returns a value for sorting on the specified type, with
|
||||
* automatic fallbacks to the next best tag type
|
||||
* (e.g. #TAG_ALBUM_ARTIST falls back to #TAG_ARTIST). If
|
||||
* there is no such value, returns an empty string.
|
||||
*/
|
||||
gcc_pure
|
||||
const char *GetSortValue(TagType type) const;
|
||||
|
||||
class const_iterator {
|
||||
friend struct Tag;
|
||||
const TagItem *const*cursor;
|
||||
|
Reference in New Issue
Block a user