aboutsummaryrefslogtreecommitdiffstats
path: root/src/tag
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tag/Tag.cxx4
-rw-r--r--src/tag/Tag.hxx21
-rw-r--r--src/tag/TagBuilder.cxx18
-rw-r--r--src/tag/TagBuilder.hxx21
-rw-r--r--src/tag/TagHandler.cxx2
5 files changed, 32 insertions, 34 deletions
diff --git a/src/tag/Tag.cxx b/src/tag/Tag.cxx
index 1b338ae8d..92ac4214c 100644
--- a/src/tag/Tag.cxx
+++ b/src/tag/Tag.cxx
@@ -61,7 +61,7 @@ tag_name_parse_i(const char *name)
void
Tag::Clear()
{
- time = -1;
+ duration = SignedSongTime::Negative();
has_playlist = false;
tag_pool_lock.lock();
@@ -75,7 +75,7 @@ Tag::Clear()
}
Tag::Tag(const Tag &other)
- :time(other.time), has_playlist(other.has_playlist),
+ :duration(other.duration), has_playlist(other.has_playlist),
num_items(other.num_items),
items(nullptr)
{
diff --git a/src/tag/Tag.hxx b/src/tag/Tag.hxx
index 74221417f..f1d3d5767 100644
--- a/src/tag/Tag.hxx
+++ b/src/tag/Tag.hxx
@@ -22,6 +22,7 @@
#include "TagType.h" // IWYU pragma: export
#include "TagItem.hxx" // IWYU pragma: export
+#include "Chrono.hxx"
#include "Compiler.h"
#include <algorithm>
@@ -35,12 +36,10 @@
*/
struct Tag {
/**
- * The duration of the song (in seconds). A value of zero
- * means that the length is unknown. If the duration is
- * really between zero and one second, you should round up to
- * 1.
+ * The duration of the song. A negative value means that the
+ * length is unknown.
*/
- int time;
+ SignedSongTime duration;
/**
* Does this file have an embedded playlist (e.g. embedded CUE
@@ -57,13 +56,13 @@ struct Tag {
/**
* Create an empty tag.
*/
- Tag():time(-1), has_playlist(false),
+ Tag():duration(SignedSongTime::Negative()), has_playlist(false),
num_items(0), items(nullptr) {}
Tag(const Tag &other);
Tag(Tag &&other)
- :time(other.time), has_playlist(other.has_playlist),
+ :duration(other.duration), has_playlist(other.has_playlist),
num_items(other.num_items), items(other.items) {
other.items = nullptr;
other.num_items = 0;
@@ -79,7 +78,7 @@ struct Tag {
Tag &operator=(const Tag &other) = delete;
Tag &operator=(Tag &&other) {
- time = other.time;
+ duration = other.duration;
has_playlist = other.has_playlist;
std::swap(items, other.items);
std::swap(num_items, other.num_items);
@@ -87,8 +86,8 @@ struct Tag {
}
/**
- * Returns true if the tag contains no items. This ignores the "time"
- * attribute.
+ * Returns true if the tag contains no items. This ignores
+ * the "duration" attribute.
*/
bool IsEmpty() const {
return num_items == 0;
@@ -98,7 +97,7 @@ struct Tag {
* Returns true if the tag contains any information.
*/
bool IsDefined() const {
- return !IsEmpty() || time >= 0;
+ return !IsEmpty() || !duration.IsNegative();
}
/**
diff --git a/src/tag/TagBuilder.cxx b/src/tag/TagBuilder.cxx
index bc8ea2ae7..85060e9ee 100644
--- a/src/tag/TagBuilder.cxx
+++ b/src/tag/TagBuilder.cxx
@@ -29,7 +29,7 @@
#include <stdlib.h>
TagBuilder::TagBuilder(const Tag &other)
- :time(other.time), has_playlist(other.has_playlist)
+ :duration(other.duration), has_playlist(other.has_playlist)
{
items.reserve(other.num_items);
@@ -40,7 +40,7 @@ TagBuilder::TagBuilder(const Tag &other)
}
TagBuilder::TagBuilder(Tag &&other)
- :time(other.time), has_playlist(other.has_playlist)
+ :duration(other.duration), has_playlist(other.has_playlist)
{
/* move all TagItem pointers from the Tag object; we don't
need to contact the tag pool, because all we do is move
@@ -58,7 +58,7 @@ TagBuilder &
TagBuilder::operator=(const TagBuilder &other)
{
/* copy all attributes */
- time = other.time;
+ duration = other.duration;
has_playlist = other.has_playlist;
items = other.items;
@@ -74,7 +74,7 @@ TagBuilder::operator=(const TagBuilder &other)
TagBuilder &
TagBuilder::operator=(TagBuilder &&other)
{
- time = other.time;
+ duration = other.duration;
has_playlist = other.has_playlist;
items = std::move(other.items);
@@ -84,7 +84,7 @@ TagBuilder::operator=(TagBuilder &&other)
TagBuilder &
TagBuilder::operator=(Tag &&other)
{
- time = other.time;
+ duration = other.duration;
has_playlist = other.has_playlist;
/* move all TagItem pointers from the Tag object; we don't
@@ -105,7 +105,7 @@ TagBuilder::operator=(Tag &&other)
void
TagBuilder::Clear()
{
- time = -1;
+ duration = SignedSongTime::Negative();
has_playlist = false;
RemoveAll();
}
@@ -115,7 +115,7 @@ TagBuilder::Commit(Tag &tag)
{
tag.Clear();
- tag.time = time;
+ tag.duration = duration;
tag.has_playlist = has_playlist;
/* move all TagItem pointers to the new Tag object without
@@ -162,8 +162,8 @@ TagBuilder::HasType(TagType type) const
void
TagBuilder::Complement(const Tag &other)
{
- if (time <= 0)
- time = other.time;
+ if (duration.IsNegative())
+ duration = other.duration;
has_playlist |= other.has_playlist;
diff --git a/src/tag/TagBuilder.hxx b/src/tag/TagBuilder.hxx
index 6de52b775..aff581313 100644
--- a/src/tag/TagBuilder.hxx
+++ b/src/tag/TagBuilder.hxx
@@ -21,6 +21,7 @@
#define MPD_TAG_BUILDER_HXX
#include "TagType.h"
+#include "Chrono.hxx"
#include "Compiler.h"
#include <vector>
@@ -35,12 +36,10 @@ struct Tag;
*/
class TagBuilder {
/**
- * The duration of the song (in seconds). A value of zero
- * means that the length is unknown. If the duration is
- * really between zero and one second, you should round up to
- * 1.
+ * The duration of the song. A negative value means that the
+ * length is unknown.
*/
- int time;
+ SignedSongTime duration;
/**
* Does this file have an embedded playlist (e.g. embedded CUE
@@ -56,7 +55,7 @@ public:
* Create an empty tag.
*/
TagBuilder()
- :time(-1), has_playlist(false) {}
+ :duration(SignedSongTime::Negative()), has_playlist(false) {}
~TagBuilder() {
Clear();
@@ -73,8 +72,8 @@ public:
TagBuilder &operator=(Tag &&other);
/**
- * Returns true if the tag contains no items. This ignores the "time"
- * attribute.
+ * Returns true if the tag contains no items. This ignores
+ * the "duration" attribute.
*/
bool IsEmpty() const {
return items.empty();
@@ -85,7 +84,7 @@ public:
*/
gcc_pure
bool IsDefined() const {
- return time >= 0 || has_playlist || !IsEmpty();
+ return !duration.IsNegative() || has_playlist || !IsEmpty();
}
void Clear();
@@ -109,8 +108,8 @@ public:
*/
Tag *CommitNew();
- void SetTime(int _time) {
- time = _time;
+ void SetDuration(SignedSongTime _duration) {
+ duration = _duration;
}
void SetHasPlaylist(bool _has_playlist) {
diff --git a/src/tag/TagHandler.cxx b/src/tag/TagHandler.cxx
index 014834b88..20a51f064 100644
--- a/src/tag/TagHandler.cxx
+++ b/src/tag/TagHandler.cxx
@@ -27,7 +27,7 @@ add_tag_duration(unsigned seconds, void *ctx)
{
TagBuilder &tag = *(TagBuilder *)ctx;
- tag.SetTime(seconds);
+ tag.SetDuration(SignedSongTime::FromS(seconds));
}
static void