DetachedSong: fork of struct Song
From now on, struct Song will be used by the database only, and DetachedSong will be used by everybody else. DetachedSong is easier to use, but Song has lower overhead.
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
#include "util/Alloc.hxx"
|
||||
#include "util/StringUtil.hxx"
|
||||
#include "util/CharUtil.hxx"
|
||||
#include "Song.hxx"
|
||||
#include "DetachedSong.hxx"
|
||||
#include "tag/Tag.hxx"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -38,14 +38,9 @@ CueParser::CueParser()
|
||||
|
||||
CueParser::~CueParser()
|
||||
{
|
||||
if (current != nullptr)
|
||||
current->Free();
|
||||
|
||||
if (previous != nullptr)
|
||||
previous->Free();
|
||||
|
||||
if (finished != nullptr)
|
||||
finished->Free();
|
||||
delete current;
|
||||
delete previous;
|
||||
delete finished;
|
||||
}
|
||||
|
||||
static const char *
|
||||
@@ -169,8 +164,8 @@ CueParser::Commit()
|
||||
if (current == nullptr)
|
||||
return;
|
||||
|
||||
assert(current->tag == nullptr);
|
||||
current->tag = song_tag.CommitNew();
|
||||
assert(!current->GetTag().IsDefined());
|
||||
current->SetTag(song_tag.Commit());
|
||||
|
||||
finished = previous;
|
||||
previous = current;
|
||||
@@ -249,8 +244,8 @@ CueParser::Feed2(char *p)
|
||||
}
|
||||
|
||||
state = TRACK;
|
||||
current = Song::NewRemote(filename.c_str());
|
||||
assert(current->tag == nullptr);
|
||||
current = new DetachedSong(std::move(filename));
|
||||
assert(!current->GetTag().IsDefined());
|
||||
|
||||
song_tag = header_tag;
|
||||
song_tag.AddItem(TAG_TRACK, nr);
|
||||
@@ -272,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +300,7 @@ CueParser::Finish()
|
||||
end = true;
|
||||
}
|
||||
|
||||
Song *
|
||||
DetachedSong *
|
||||
CueParser::Get()
|
||||
{
|
||||
if (finished == nullptr && end) {
|
||||
@@ -317,7 +312,7 @@ CueParser::Get()
|
||||
previous = nullptr;
|
||||
}
|
||||
|
||||
Song *song = finished;
|
||||
DetachedSong *song = finished;
|
||||
finished = nullptr;
|
||||
return song;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
struct Song;
|
||||
class DetachedSong;
|
||||
struct Tag;
|
||||
|
||||
class CueParser {
|
||||
@@ -74,19 +74,19 @@ class CueParser {
|
||||
/**
|
||||
* 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
|
||||
@@ -125,7 +125,7 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user