summaryrefslogtreecommitdiff
path: root/src/database/include/song.hpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-05-08 13:38:36 +1000
committerjacqueline <me@jacqueline.id.au>2023-05-08 17:47:29 +1000
commit16e6180ba7946119538d03463ea7d37fccc4dcb3 (patch)
tree968483bfa477b43a72b8b6dfefaac3e771163e9e /src/database/include/song.hpp
parentfe19478e0f286191c3bf1b9946b89ed26d5c4bae (diff)
downloadtangara-fw-16e6180ba7946119538d03463ea7d37fccc4dcb3.tar.gz
Database init is now stable!
Diffstat (limited to 'src/database/include/song.hpp')
-rw-r--r--src/database/include/song.hpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/database/include/song.hpp b/src/database/include/song.hpp
new file mode 100644
index 00000000..79b2160a
--- /dev/null
+++ b/src/database/include/song.hpp
@@ -0,0 +1,76 @@
+#pragma once
+
+#include <stdint.h>
+#include <cstdint>
+#include <optional>
+#include <string>
+
+#include "leveldb/db.h"
+#include "span.hpp"
+
+namespace database {
+
+typedef uint32_t SongId;
+
+enum Encoding { ENC_UNSUPPORTED, ENC_MP3 };
+
+struct SongTags {
+ Encoding encoding;
+ std::optional<std::string> title;
+ std::optional<std::string> artist;
+ std::optional<std::string> album;
+ auto Hash() const -> uint64_t;
+};
+
+auto ReadAndParseTags(const std::string& path, SongTags* out) -> bool;
+
+class SongData {
+ private:
+ const SongId id_;
+ const std::string filepath_;
+ const uint64_t tags_hash_;
+ const uint32_t play_count_;
+ const bool is_tombstoned_;
+
+ public:
+ SongData(SongId id, const std::string& path, uint64_t hash)
+ : id_(id),
+ filepath_(path),
+ tags_hash_(hash),
+ play_count_(0),
+ is_tombstoned_(false) {}
+ SongData(SongId id,
+ const std::string& path,
+ uint64_t hash,
+ uint32_t play_count,
+ bool is_tombstoned)
+ : id_(id),
+ filepath_(path),
+ tags_hash_(hash),
+ play_count_(play_count),
+ is_tombstoned_(is_tombstoned) {}
+
+ auto id() const -> SongId { return id_; }
+ auto filepath() const -> std::string { return filepath_; }
+ auto play_count() const -> uint32_t { return play_count_; }
+ auto tags_hash() const -> uint64_t { return tags_hash_; }
+ auto is_tombstoned() const -> bool { return is_tombstoned_; }
+
+ auto UpdateHash(uint64_t new_hash) const -> SongData;
+ auto Entomb() const -> SongData;
+ auto Exhume(const std::string& new_path) const -> SongData;
+};
+
+class Song {
+ public:
+ Song(SongData data, SongTags tags) : data_(data), tags_(tags) {}
+
+ auto data() -> const SongData& { return data_; }
+ auto tags() -> const SongTags& { return tags_; }
+
+ private:
+ const SongData data_;
+ const SongTags tags_;
+};
+
+} // namespace database