aboutsummaryrefslogtreecommitdiffstats
path: root/src/PlaylistSong.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/PlaylistSong.cxx99
1 files changed, 52 insertions, 47 deletions
diff --git a/src/PlaylistSong.cxx b/src/PlaylistSong.cxx
index 60774dc36..2da644bc2 100644
--- a/src/PlaylistSong.cxx
+++ b/src/PlaylistSong.cxx
@@ -24,43 +24,42 @@
#include "DatabaseGlue.hxx"
#include "ls.hxx"
#include "tag/Tag.hxx"
+#include "tag/TagBuilder.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/Traits.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
+#include "DetachedSong.hxx"
#include "Song.hxx"
-#include <glib.h>
-
#include <assert.h>
#include <string.h>
static void
-merge_song_metadata(Song *dest, const Song *base,
- const Song *add)
+merge_song_metadata(DetachedSong *dest, const DetachedSong *base,
+ const DetachedSong *add)
{
- dest->tag = base->tag != nullptr
- ? (add->tag != nullptr
- ? Tag::Merge(*base->tag, *add->tag)
- : new Tag(*base->tag))
- : (add->tag != nullptr
- ? new Tag(*add->tag)
- : nullptr);
-
- dest->mtime = base->mtime;
- dest->start_ms = add->start_ms;
- dest->end_ms = add->end_ms;
+ {
+ TagBuilder builder(add->GetTag());
+ builder.Complement(base->GetTag());
+ dest->SetTag(builder.Commit());
+ }
+
+ dest->SetLastModified(base->GetLastModified());
+ dest->SetStartMS(add->GetStartMS());
+ dest->SetEndMS(add->GetEndMS());
}
-static Song *
-apply_song_metadata(Song *dest, const Song *src)
+static DetachedSong *
+apply_song_metadata(DetachedSong *dest, const DetachedSong *src)
{
- Song *tmp;
+ DetachedSong *tmp;
assert(dest != nullptr);
assert(src != nullptr);
- if (src->tag == nullptr && src->start_ms == 0 && src->end_ms == 0)
+ if (!src->GetTag().IsDefined() &&
+ src->GetStartMS() == 0 && src->GetEndMS() == 0)
return dest;
if (dest->IsInDatabase()) {
@@ -72,37 +71,41 @@ apply_song_metadata(Song *dest, const Song *src)
if (path_utf8.empty())
path_utf8 = path_fs.c_str();
- tmp = Song::NewFile(path_utf8.c_str(), nullptr);
+ tmp = new DetachedSong(std::move(path_utf8));
merge_song_metadata(tmp, dest, src);
} else {
- tmp = Song::NewFile(dest->uri, nullptr);
+ tmp = new DetachedSong(dest->GetURI());
merge_song_metadata(tmp, dest, src);
}
- if (dest->tag != nullptr && dest->tag->time > 0 &&
- src->start_ms > 0 && src->end_ms == 0 &&
- src->start_ms / 1000 < (unsigned)dest->tag->time)
+ if (dest->GetTag().IsDefined() && dest->GetTag().time > 0 &&
+ src->GetStartMS() > 0 && src->GetEndMS() == 0 &&
+ src->GetStartMS() / 1000 < (unsigned)dest->GetTag().time)
/* the range is open-ended, and the playlist plugin
did not know the total length of the song file
(e.g. last track on a CUE file); fix it up here */
- tmp->tag->time = dest->tag->time - src->start_ms / 1000;
+ tmp->WritableTag().time =
+ dest->GetTag().time - src->GetStartMS() / 1000;
- dest->Free();
+ delete dest;
return tmp;
}
-static Song *
-playlist_check_load_song(const Song *song, const char *uri, bool secure)
+static DetachedSong *
+playlist_check_load_song(const DetachedSong *song, const char *uri, bool secure)
{
- Song *dest;
+ DetachedSong *dest;
if (uri_has_scheme(uri)) {
- dest = Song::NewRemote(uri);
- } else if (PathTraits::IsAbsoluteUTF8(uri) && secure) {
- dest = Song::LoadFile(uri, nullptr);
- if (dest == nullptr)
+ dest = new DetachedSong(uri);
+ } else if (PathTraitsUTF8::IsAbsolute(uri) && secure) {
+ Song *tmp = Song::LoadFile(uri, nullptr);
+ if (tmp == nullptr)
return nullptr;
+
+ dest = new DetachedSong(*tmp);
+ delete tmp;
} else {
const Database *db = GetDatabase();
if (db == nullptr)
@@ -113,22 +116,22 @@ playlist_check_load_song(const Song *song, const char *uri, bool secure)
/* not found in database */
return nullptr;
- dest = tmp->DupDetached();
+ dest = new DetachedSong(*tmp);
db->ReturnSong(tmp);
}
return apply_song_metadata(dest, song);
}
-Song *
-playlist_check_translate_song(Song *song, const char *base_uri,
+DetachedSong *
+playlist_check_translate_song(DetachedSong *song, const char *base_uri,
bool secure)
{
if (song->IsInDatabase())
/* already ok */
return song;
- const char *uri = song->uri;
+ const char *uri = song->GetURI();
if (uri_has_scheme(uri)) {
if (uri_supported_scheme(uri))
@@ -136,19 +139,19 @@ playlist_check_translate_song(Song *song, const char *base_uri,
return song;
else {
/* unsupported remote song */
- song->Free();
+ delete song;
return nullptr;
}
}
if (base_uri != nullptr && strcmp(base_uri, ".") == 0)
- /* PathTraits::GetParentUTF8() returns "." when there
+ /* PathTraitsUTF8::GetParent() returns "." when there
is no directory name in the given path; clear that
now, because it would break the database lookup
functions */
base_uri = nullptr;
- if (PathTraits::IsAbsoluteUTF8(uri)) {
+ if (PathTraitsUTF8::IsAbsolute(uri)) {
/* XXX fs_charset vs utf8? */
const char *suffix = map_to_relative_path(uri);
assert(suffix != nullptr);
@@ -158,19 +161,21 @@ playlist_check_translate_song(Song *song, const char *base_uri,
else if (!secure) {
/* local files must be relative to the music
directory when "secure" is enabled */
- song->Free();
+ delete song;
return nullptr;
}
base_uri = nullptr;
}
- char *allocated = nullptr;
- if (base_uri != nullptr)
- uri = allocated = g_build_filename(base_uri, uri, nullptr);
+ std::string full_uri;
+ if (base_uri != nullptr) {
+ full_uri = PathTraitsUTF8::Build(base_uri, uri);
+ uri = full_uri.c_str();
+ }
+
+ DetachedSong *dest = playlist_check_load_song(song, uri, secure);
+ delete song;
- Song *dest = playlist_check_load_song(song, uri, secure);
- song->Free();
- g_free(allocated);
return dest;
}