aboutsummaryrefslogtreecommitdiffstats
path: root/src/cue
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cue/CueParser.cxx77
-rw-r--r--src/cue/CueParser.hxx25
2 files changed, 55 insertions, 47 deletions
diff --git a/src/cue/CueParser.cxx b/src/cue/CueParser.cxx
index 60b33b6b4..f05a69ae3 100644
--- a/src/cue/CueParser.cxx
+++ b/src/cue/CueParser.cxx
@@ -19,19 +19,18 @@
#include "config.h"
#include "CueParser.hxx"
+#include "util/Alloc.hxx"
#include "util/StringUtil.hxx"
#include "util/CharUtil.hxx"
-#include "Song.hxx"
+#include "DetachedSong.hxx"
#include "tag/Tag.hxx"
-#include <glib.h>
-
#include <assert.h>
#include <string.h>
#include <stdlib.h>
CueParser::CueParser()
- :state(HEADER), tag(new Tag()),
+ :state(HEADER),
current(nullptr),
previous(nullptr),
finished(nullptr),
@@ -39,16 +38,9 @@ CueParser::CueParser()
CueParser::~CueParser()
{
- delete tag;
-
- if (current != nullptr)
- current->Free();
-
- if (previous != nullptr)
- previous->Free();
-
- if (finished != nullptr)
- finished->Free();
+ delete current;
+ delete previous;
+ delete finished;
}
static const char *
@@ -109,7 +101,7 @@ cue_next_value(char **pp)
}
static void
-cue_add_tag(Tag &tag, TagType type, char *p)
+cue_add_tag(TagBuilder &tag, TagType type, char *p)
{
const char *value = cue_next_value(&p);
if (value != nullptr)
@@ -118,7 +110,7 @@ cue_add_tag(Tag &tag, TagType type, char *p)
}
static void
-cue_parse_rem(char *p, Tag &tag)
+cue_parse_rem(char *p, TagBuilder &tag)
{
const char *type = cue_next_token(&p);
if (type == nullptr)
@@ -129,13 +121,13 @@ cue_parse_rem(char *p, Tag &tag)
cue_add_tag(tag, type2, p);
}
-Tag *
+TagBuilder *
CueParser::GetCurrentTag()
{
if (state == HEADER)
- return tag;
+ return &header_tag;
else if (state == TRACK)
- return current->tag;
+ return &song_tag;
else
return nullptr;
}
@@ -172,6 +164,9 @@ CueParser::Commit()
if (current == nullptr)
return;
+ assert(!current->GetTag().IsDefined());
+ current->SetTag(song_tag.Commit());
+
finished = previous;
previous = current;
current = nullptr;
@@ -188,9 +183,9 @@ CueParser::Feed2(char *p)
return;
if (strcmp(command, "REM") == 0) {
- Tag *current_tag = GetCurrentTag();
- if (current_tag != nullptr)
- cue_parse_rem(p, *current_tag);
+ TagBuilder *tag = GetCurrentTag();
+ if (tag != nullptr)
+ cue_parse_rem(p, *tag);
} else if (strcmp(command, "PERFORMER") == 0) {
/* MPD knows a "performer" tag, but it is not a good
match for this CUE tag; from the Hydrogenaudio
@@ -202,14 +197,14 @@ CueParser::Feed2(char *p)
? TAG_ARTIST
: TAG_ALBUM_ARTIST;
- Tag *current_tag = GetCurrentTag();
- if (current_tag != nullptr)
- cue_add_tag(*current_tag, type, p);
+ TagBuilder *tag = GetCurrentTag();
+ if (tag != nullptr)
+ cue_add_tag(*tag, type, p);
} else if (strcmp(command, "TITLE") == 0) {
if (state == HEADER)
- cue_add_tag(*tag, TAG_ALBUM, p);
+ cue_add_tag(header_tag, TAG_ALBUM, p);
else if (state == TRACK)
- cue_add_tag(*current->tag, TAG_TITLE, p);
+ cue_add_tag(song_tag, TAG_TITLE, p);
} else if (strcmp(command, "FILE") == 0) {
Commit();
@@ -249,10 +244,12 @@ CueParser::Feed2(char *p)
}
state = TRACK;
- current = Song::NewRemote(filename.c_str());
- assert(current->tag == nullptr);
- current->tag = new Tag(*tag);
- current->tag->AddItem(TAG_TRACK, nr);
+ current = new DetachedSong(std::move(filename));
+ assert(!current->GetTag().IsDefined());
+
+ song_tag = header_tag;
+ song_tag.AddItem(TAG_TRACK, nr);
+
last_updated = false;
} else if (state == IGNORE_TRACK) {
return;
@@ -270,14 +267,14 @@ CueParser::Feed2(char *p)
return;
if (!last_updated && previous != nullptr &&
- previous->start_ms < (unsigned)position_ms) {
+ previous->GetStartMS() < (unsigned)position_ms) {
last_updated = true;
- previous->end_ms = position_ms;
- previous->tag->time =
- (previous->end_ms - previous->start_ms + 500) / 1000;
+ previous->SetEndMS(position_ms);
+ previous->WritableTag().time =
+ (previous->GetEndMS() - previous->GetStartMS() + 500) / 1000;
}
- current->start_ms = position_ms;
+ current->SetStartMS(position_ms);
}
}
@@ -287,9 +284,9 @@ CueParser::Feed(const char *line)
assert(!end);
assert(line != nullptr);
- char *allocated = g_strdup(line);
+ char *allocated = xstrdup(line);
Feed2(allocated);
- g_free(allocated);
+ free(allocated);
}
void
@@ -303,7 +300,7 @@ CueParser::Finish()
end = true;
}
-Song *
+DetachedSong *
CueParser::Get()
{
if (finished == nullptr && end) {
@@ -315,7 +312,7 @@ CueParser::Get()
previous = nullptr;
}
- Song *song = finished;
+ DetachedSong *song = finished;
finished = nullptr;
return song;
}
diff --git a/src/cue/CueParser.hxx b/src/cue/CueParser.hxx
index abcceaa2e..9a32a33c4 100644
--- a/src/cue/CueParser.hxx
+++ b/src/cue/CueParser.hxx
@@ -21,11 +21,12 @@
#define MPD_CUE_PARSER_HXX
#include "check.h"
+#include "tag/TagBuilder.hxx"
#include "Compiler.h"
#include <string>
-struct Song;
+class DetachedSong;
struct Tag;
class CueParser {
@@ -56,26 +57,36 @@ class CueParser {
IGNORE_TRACK,
} state;
- Tag *tag;
+ /**
+ * Tags read from the CUE header.
+ */
+ TagBuilder header_tag;
+
+ /**
+ * Tags read for the current song (attribute #current). When
+ * #current gets moved to #previous, TagBuilder::Commit() will
+ * be called.
+ */
+ TagBuilder song_tag;
std::string filename;
/**
* The song currently being edited.
*/
- Song *current;
+ DetachedSong *current;
/**
* The previous song. It is remembered because its end_time
* will be set to the current song's start time.
*/
- Song *previous;
+ DetachedSong *previous;
/**
* A song that is completely finished and can be returned to
* the caller via cue_parser_get().
*/
- Song *finished;
+ DetachedSong *finished;
/**
* Set to true after previous.end_time has been updated to the
@@ -114,11 +125,11 @@ public:
* @return a song object that must be freed by the caller, or NULL if
* no song was finished at this time
*/
- Song *Get();
+ DetachedSong *Get();
private:
gcc_pure
- Tag *GetCurrentTag();
+ TagBuilder *GetCurrentTag();
/**
* Commit the current song. It will be moved to "previous",