Revert "Improve representation of track numbers in indexes"

This reverts commit a3da259a37.
custom
jacqueline 1 year ago
parent a3da259a37
commit 81855a78f4
  1. 2
      src/database/database.cpp
  2. 17
      src/database/index.cpp
  3. 8
      src/database/tag_parser.cpp

@ -51,7 +51,7 @@ static SingletonEnv<leveldb::EspEnv> sEnv;
static const char kDbPath[] = "/.tangara-db"; static const char kDbPath[] = "/.tangara-db";
static const char kKeyDbVersion[] = "schema_version"; static const char kKeyDbVersion[] = "schema_version";
static const uint8_t kCurrentDbVersion = 4; static const uint8_t kCurrentDbVersion = 3;
static const char kKeyCollator[] = "collator"; static const char kKeyCollator[] = "collator";
static const char kKeyTrackId[] = "next_track_id"; static const char kKeyTrackId[] = "next_track_id";

@ -8,7 +8,6 @@
#include <cstdint> #include <cstdint>
#include <sstream> #include <sstream>
#include <string>
#include <variant> #include <variant>
#include "collation.hpp" #include "collation.hpp"
@ -56,7 +55,7 @@ static auto missing_component_text(const Track& track, Tag tag)
case Tag::kTitle: case Tag::kTitle:
return track.TitleOrFilename(); return track.TitleOrFilename();
case Tag::kAlbumTrack: case Tag::kAlbumTrack:
return "0"; return "0000";
case Tag::kDuration: case Tag::kDuration:
default: default:
return {}; return {};
@ -77,20 +76,9 @@ auto Index(locale::ICollator& collator, const IndexInfo& info, const Track& t)
}; };
for (std::uint8_t i = 0; i < info.components.size(); i++) { for (std::uint8_t i = 0; i < info.components.size(); i++) {
Tag component = info.components.at(i);
// Fill in the text for this depth. // Fill in the text for this depth.
auto text = t.tags().at(info.components.at(i));
std::pmr::string value; std::pmr::string value;
if (component == Tag::kAlbumTrack) {
// Track numbers are a special case, since they're numbers rather than
// text.
auto pmr_num = t.tags().at(component).value_or("0");
// std::pmr continues to be a true disappointment.
std::string raw_num{pmr_num.data(), pmr_num.size()};
uint32_t num = std::stoi(raw_num);
key.item = std::pmr::string{reinterpret_cast<char*>(&num), 4};
} else {
auto text = t.tags().at(component);
if (text) { if (text) {
std::pmr::string orig = *text; std::pmr::string orig = *text;
auto xfrm = collator.Transform({orig.data(), orig.size()}); auto xfrm = collator.Transform({orig.data(), orig.size()});
@ -100,7 +88,6 @@ auto Index(locale::ICollator& collator, const IndexInfo& info, const Track& t)
key.item = {}; key.item = {};
value = missing_component_text(t, info.components.at(i)).value_or(""); value = missing_component_text(t, info.components.at(i)).value_or("");
} }
}
// If this is the last component, then we should also fill in the track id // If this is the last component, then we should also fill in the track id
// and title. // and title.

@ -30,8 +30,9 @@ const static std::array<std::pair<const char*, Tag>, 5> kVorbisIdToTag = {{
}}; }};
static auto convert_track_number(int number) -> std::pmr::string { static auto convert_track_number(int number) -> std::pmr::string {
std::string s = std::to_string(number); std::ostringstream oss;
return {s.data(), s.size()}; oss << std::setw(4) << std::setfill('0') << number;
return std::pmr::string(oss.str());
} }
static auto convert_track_number(const std::pmr::string& raw) static auto convert_track_number(const std::pmr::string& raw)
@ -166,7 +167,8 @@ auto TagParserImpl::ReadAndParseTags(const std::pmr::string& path)
} }
} }
// Normalise track numbers to ensure that they're actually numbers. // Normalise track numbers; they're usually treated as strings, but we would
// like to sort them lexicographically.
tags->set(Tag::kAlbumTrack, tags->set(Tag::kAlbumTrack,
convert_track_number(tags->at(Tag::kAlbumTrack).value_or("0"))); convert_track_number(tags->at(Tag::kAlbumTrack).value_or("0")));

Loading…
Cancel
Save