From 245d9ff4b9cde1f487beed76085a52f3f2d6d26c Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 23 Jun 2023 15:32:11 +1000 Subject: add indexing to the database idk man i wrote most of this in a fugue state whilst high on the couch with my cat --- src/database/include/track.hpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'src/database/include/track.hpp') diff --git a/src/database/include/track.hpp b/src/database/include/track.hpp index 5a0c0ca8..e3f94db4 100644 --- a/src/database/include/track.hpp +++ b/src/database/include/track.hpp @@ -8,11 +8,14 @@ #include +#include +#include #include #include #include #include "leveldb/db.h" +#include "shared_string.h" #include "span.hpp" namespace database { @@ -41,25 +44,33 @@ enum class Encoding { kFlac = 4, }; +enum class Tag { + kTitle = 0, + kArtist = 1, + kAlbum = 2, + kAlbumTrack = 3, + kGenre = 4, +}; + /* * Owning container for tag-related track metadata that was extracted from a * file. */ -struct TrackTags { - Encoding encoding; - std::optional title; - - // TODO(jacqueline): It would be nice to use shared_ptr's for the artist and - // album, since there's likely a fair number of duplicates for each - // (especially the former). +class TrackTags { + public: + auto encoding() const -> Encoding { return encoding_; }; + auto encoding(Encoding e) -> void { encoding_ = e; }; - std::optional artist; - std::optional album; + TrackTags() : encoding_(Encoding::kUnsupported) {} std::optional channels; std::optional sample_rate; std::optional bits_per_sample; + auto set(const Tag& key, const std::string& val) -> void; + auto at(const Tag& key) const -> std::optional; + auto operator[](const Tag& key) const -> std::optional; + /* * Returns a hash of the 'identifying' tags of this track. That is, a hash * that can be used to determine if one track is likely the same as another, @@ -69,6 +80,12 @@ struct TrackTags { auto Hash() const -> uint64_t; bool operator==(const TrackTags&) const = default; + TrackTags& operator=(const TrackTags&) = default; + TrackTags(const TrackTags&) = default; + + private: + Encoding encoding_; + std::map tags_; }; /* @@ -156,6 +173,8 @@ class Track { auto data() const -> const TrackData& { return data_; } auto tags() const -> const TrackTags& { return tags_; } + auto TitleOrFilename() const -> shared_string; + bool operator==(const Track&) const = default; Track operator=(const Track& other) const { return Track(other); } -- cgit v1.2.3