Merge branch 'main' of git.sr.ht:~jacqueline/tangara-fw

custom
jacqueline 1 year ago
commit 3f6256f9e6
  1. 7
      src/database/database.cpp
  2. 10
      src/database/file_gatherer.cpp
  3. 4
      src/database/include/file_gatherer.hpp
  4. 6
      src/database/include/tag_parser.hpp
  5. 8
      src/database/tag_parser.cpp

@ -383,8 +383,7 @@ auto Database::updateIndexes() -> void {
ESP_LOGI(kTag, "scanning for new tracks");
uint64_t num_processed = 0;
std::pair<uint16_t, uint16_t> newest_track = last_update;
file_gatherer_.FindFiles("", [&](const std::string& path,
const FILINFO& info) {
file_gatherer_.FindFiles("", [&](std::string_view path, const FILINFO& info) {
num_processed++;
events::Ui().Dispatch(event::UpdateProgress{
.stage = event::UpdateProgress::Stage::kScanningForNewTracks,
@ -456,9 +455,7 @@ auto Database::updateIndexes() -> void {
dbCreateIndexesForTrack(*t);
} else if (existing_data->filepath !=
std::pmr::string{path.data(), path.size()}) {
ESP_LOGW(kTag, "tag hash collision for %s and %s",
existing_data->filepath.c_str(), path.c_str());
ESP_LOGI(kTag, "hash components: %s, %s, %s",
ESP_LOGW(kTag, "hash collision: %s, %s, %s",
tags->title().value_or("no title").c_str(),
tags->artist().value_or("no artist").c_str(),
tags->album().value_or("no album").c_str());

@ -22,12 +22,12 @@ static_assert(sizeof(TCHAR) == sizeof(char), "TCHAR must be CHAR");
auto FileGathererImpl::FindFiles(
const std::string& root,
std::function<void(const std::string&, const FILINFO&)> cb) -> void {
std::deque<std::string> to_explore;
to_explore.push_back(root);
std::function<void(std::string_view, const FILINFO&)> cb) -> void {
std::pmr::deque<std::pmr::string> to_explore{&memory::kSpiRamResource};
to_explore.push_back({root.data(), root.size()});
while (!to_explore.empty()) {
std::string next_path_str = to_explore.front();
auto next_path_str = to_explore.front();
to_explore.pop_front();
const TCHAR* next_path = static_cast<const TCHAR*>(next_path_str.c_str());
@ -56,7 +56,7 @@ auto FileGathererImpl::FindFiles(
// System or hidden file. Ignore it and move on.
continue;
} else {
std::string full_path;
std::pmr::string full_path{&memory::kSpiRamResource};
full_path += next_path_str;
full_path += "/";
full_path += info.fname;

@ -21,7 +21,7 @@ class IFileGatherer {
virtual auto FindFiles(
const std::string& root,
std::function<void(const std::string&, const FILINFO&)> cb)
std::function<void(std::string_view, const FILINFO&)> cb)
-> void = 0;
};
@ -29,7 +29,7 @@ class FileGathererImpl : public IFileGatherer {
public:
virtual auto FindFiles(
const std::string& root,
std::function<void(const std::string&, const FILINFO&)> cb)
std::function<void(std::string_view, const FILINFO&)> cb)
-> void override;
};

@ -16,18 +16,18 @@ namespace database {
class ITagParser {
public:
virtual ~ITagParser() {}
virtual auto ReadAndParseTags(const std::string& path)
virtual auto ReadAndParseTags(std::string_view path)
-> std::shared_ptr<TrackTags> = 0;
};
class TagParserImpl : public ITagParser {
public:
TagParserImpl();
auto ReadAndParseTags(const std::string& path)
auto ReadAndParseTags(std::string_view path)
-> std::shared_ptr<TrackTags> override;
private:
auto parseNew(const std::string& path) -> std::shared_ptr<TrackTags>;
auto parseNew(std::string_view path) -> std::shared_ptr<TrackTags>;
/*
* Cache of tags that have already been extracted from files. Ideally this

@ -108,7 +108,7 @@ static const std::size_t kBufSize = 1024;
TagParserImpl::TagParserImpl() {}
auto TagParserImpl::ReadAndParseTags(const std::string& path)
auto TagParserImpl::ReadAndParseTags(std::string_view path)
-> std::shared_ptr<TrackTags> {
{
std::lock_guard<std::mutex> lock{cache_mutex_};
@ -130,7 +130,7 @@ auto TagParserImpl::ReadAndParseTags(const std::string& path)
if (!tags->track()) {
auto slash_pos = path.find_last_of("/");
if (slash_pos != std::string::npos && path.size() - slash_pos > 1) {
std::string trunc = path.substr(slash_pos + 1);
auto trunc = path.substr(slash_pos + 1);
tags->track({trunc.data(), trunc.size()});
}
}
@ -143,8 +143,8 @@ auto TagParserImpl::ReadAndParseTags(const std::string& path)
return tags;
}
auto TagParserImpl::parseNew(const std::string& path)
-> std::shared_ptr<TrackTags> {
auto TagParserImpl::parseNew(std::string_view p) -> std::shared_ptr<TrackTags> {
std::string path{p};
libtags::Aux aux;
auto out = TrackTags::create();
aux.tags = out.get();

Loading…
Cancel
Save