diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-06-23 15:32:11 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-06-23 15:32:11 +1000 |
| commit | 245d9ff4b9cde1f487beed76085a52f3f2d6d26c (patch) | |
| tree | 0730e6cda4c03a92c0d5e6b2e31fe27bfa021f69 /src/database/include/track.hpp | |
| parent | aee0474191aa6b4e4505e3f5a74b4ac8cc48063b (diff) | |
| download | tangara-fw-245d9ff4b9cde1f487beed76085a52f3f2d6d26c.tar.gz | |
add indexing to the database
idk man i wrote most of this in a fugue state whilst high on the couch
with my cat
Diffstat (limited to 'src/database/include/track.hpp')
| -rw-r--r-- | src/database/include/track.hpp | 37 |
1 files changed, 28 insertions, 9 deletions
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 <stdint.h> +#include <map> +#include <memory> #include <optional> #include <string> #include <utility> #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<std::string> 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<std::string> artist; - std::optional<std::string> album; + TrackTags() : encoding_(Encoding::kUnsupported) {} std::optional<int> channels; std::optional<int> sample_rate; std::optional<int> bits_per_sample; + auto set(const Tag& key, const std::string& val) -> void; + auto at(const Tag& key) const -> std::optional<shared_string>; + auto operator[](const Tag& key) const -> std::optional<shared_string>; + /* * 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<Tag, shared_string> 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); } |
