Tag: use SignedSongTime for the song duration

This commit is contained in:
Max Kellermann
2014-08-29 12:14:27 +02:00
parent 8ce30c6a69
commit 7c25d83f1c
25 changed files with 103 additions and 84 deletions

View File

@@ -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)
{

View File

@@ -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();
}
/**

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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