db/LightSong: make Tag a reference
This enforces the "not nullptr" rule.
This commit is contained in:
parent
ebc006ab52
commit
b9ff6383a4
@ -26,18 +26,17 @@
|
|||||||
DetachedSong::DetachedSong(const LightSong &other)
|
DetachedSong::DetachedSong(const LightSong &other)
|
||||||
:uri(other.GetURI()),
|
:uri(other.GetURI()),
|
||||||
real_uri(other.real_uri != nullptr ? other.real_uri : ""),
|
real_uri(other.real_uri != nullptr ? other.real_uri : ""),
|
||||||
tag(*other.tag),
|
tag(other.tag),
|
||||||
mtime(other.mtime),
|
mtime(other.mtime),
|
||||||
start_time(other.start_time),
|
start_time(other.start_time),
|
||||||
end_time(other.end_time) {}
|
end_time(other.end_time) {}
|
||||||
|
|
||||||
DetachedSong::operator LightSong() const noexcept
|
DetachedSong::operator LightSong() const noexcept
|
||||||
{
|
{
|
||||||
LightSong result;
|
LightSong result(tag);
|
||||||
result.directory = nullptr;
|
result.directory = nullptr;
|
||||||
result.uri = uri.c_str();
|
result.uri = uri.c_str();
|
||||||
result.real_uri = real_uri.empty() ? nullptr : real_uri.c_str();
|
result.real_uri = real_uri.empty() ? nullptr : real_uri.c_str();
|
||||||
result.tag = &tag;
|
|
||||||
result.mtime = mtime;
|
result.mtime = mtime;
|
||||||
result.start_time = start_time;
|
result.start_time = start_time;
|
||||||
result.end_time = end_time;
|
result.end_time = end_time;
|
||||||
|
@ -164,7 +164,7 @@ SongFilter::Item::Match(const LightSong &song) const noexcept
|
|||||||
return StringMatch(uri.c_str());
|
return StringMatch(uri.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Match(*song.tag);
|
return Match(song.tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
SongFilter::SongFilter(unsigned tag, const char *value, bool fold_case)
|
SongFilter::SongFilter(unsigned tag, const char *value, bool fold_case)
|
||||||
|
@ -92,7 +92,7 @@ song_print_info(Response &r, const LightSong &song, bool base) noexcept
|
|||||||
if (!IsNegative(song.mtime))
|
if (!IsNegative(song.mtime))
|
||||||
time_print(r, "Last-Modified", song.mtime);
|
time_print(r, "Last-Modified", song.mtime);
|
||||||
|
|
||||||
tag_print(r, *song.tag);
|
tag_print(r, song.tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -97,9 +97,7 @@ static void
|
|||||||
GroupCountVisitor(TagCountMap &map, TagType group,
|
GroupCountVisitor(TagCountMap &map, TagType group,
|
||||||
const LightSong &song) noexcept
|
const LightSong &song) noexcept
|
||||||
{
|
{
|
||||||
assert(song.tag != nullptr);
|
const Tag &tag = song.tag;
|
||||||
|
|
||||||
const Tag &tag = *song.tag;
|
|
||||||
if (!CollectGroupCounts(map, group, tag) && group == TAG_ALBUM_ARTIST)
|
if (!CollectGroupCounts(map, group, tag) && group == TAG_ALBUM_ARTIST)
|
||||||
/* fall back to "Artist" if no "AlbumArtist" was found */
|
/* fall back to "Artist" if no "AlbumArtist" was found */
|
||||||
CollectGroupCounts(map, TAG_ARTIST, tag);
|
CollectGroupCounts(map, TAG_ARTIST, tag);
|
||||||
|
@ -105,7 +105,7 @@ PrintSongBrief(Response &r, bool base, const LightSong &song) noexcept
|
|||||||
{
|
{
|
||||||
song_print_uri(r, song, base);
|
song_print_uri(r, song, base);
|
||||||
|
|
||||||
if (song.tag->has_playlist)
|
if (song.tag.has_playlist)
|
||||||
/* this song file has an embedded CUE sheet */
|
/* this song file has an embedded CUE sheet */
|
||||||
print_playlist_in_directory(r, base,
|
print_playlist_in_directory(r, base,
|
||||||
song.directory, song.uri);
|
song.directory, song.uri);
|
||||||
@ -116,7 +116,7 @@ PrintSongFull(Response &r, bool base, const LightSong &song) noexcept
|
|||||||
{
|
{
|
||||||
song_print_info(r, song, base);
|
song_print_info(r, song, base);
|
||||||
|
|
||||||
if (song.tag->has_playlist)
|
if (song.tag.has_playlist)
|
||||||
/* this song file has an embedded CUE sheet */
|
/* this song file has an embedded CUE sheet */
|
||||||
print_playlist_in_directory(r, base,
|
print_playlist_in_directory(r, base,
|
||||||
song.directory, song.uri);
|
song.directory, song.uri);
|
||||||
|
@ -65,7 +65,7 @@ StatsVisitSong(DatabaseStats &stats, StringSet &artists, StringSet &albums,
|
|||||||
{
|
{
|
||||||
++stats.song_count;
|
++stats.song_count;
|
||||||
|
|
||||||
StatsVisitTag(stats, artists, albums, *song.tag);
|
StatsVisitTag(stats, artists, albums, song.tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseStats
|
DatabaseStats
|
||||||
|
@ -25,10 +25,10 @@ LightSong::GetDuration() const noexcept
|
|||||||
{
|
{
|
||||||
SongTime a = start_time, b = end_time;
|
SongTime a = start_time, b = end_time;
|
||||||
if (!b.IsPositive()) {
|
if (!b.IsPositive()) {
|
||||||
if (tag->duration.IsNegative())
|
if (tag.duration.IsNegative())
|
||||||
return tag->duration;
|
return tag.duration;
|
||||||
|
|
||||||
b = SongTime(tag->duration);
|
b = SongTime(tag.duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SignedSongTime(b - a);
|
return SignedSongTime(b - a);
|
||||||
|
@ -57,9 +57,9 @@ struct LightSong {
|
|||||||
const char *real_uri;
|
const char *real_uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must not be nullptr.
|
* Metadata.
|
||||||
*/
|
*/
|
||||||
const Tag *tag;
|
const Tag &tag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time stamp of the last file modification. A negative
|
* The time stamp of the last file modification. A negative
|
||||||
@ -78,6 +78,9 @@ struct LightSong {
|
|||||||
*/
|
*/
|
||||||
SongTime end_time;
|
SongTime end_time;
|
||||||
|
|
||||||
|
explicit LightSong(const Tag &_tag) noexcept
|
||||||
|
:tag(_tag) {}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
std::string GetURI() const noexcept {
|
std::string GetURI() const noexcept {
|
||||||
if (directory == nullptr)
|
if (directory == nullptr)
|
||||||
|
@ -31,8 +31,7 @@ static void
|
|||||||
CollectTags(TagSet &set, TagType tag_type, TagMask group_mask,
|
CollectTags(TagSet &set, TagType tag_type, TagMask group_mask,
|
||||||
const LightSong &song)
|
const LightSong &song)
|
||||||
{
|
{
|
||||||
assert(song.tag != nullptr);
|
const Tag &tag = song.tag;
|
||||||
const Tag &tag = *song.tag;
|
|
||||||
|
|
||||||
set.InsertUnique(tag, tag_type, group_mask);
|
set.InsertUnique(tag, tag_type, group_mask);
|
||||||
}
|
}
|
||||||
|
@ -203,11 +203,11 @@ Copy(TagBuilder &tag, TagType d_tag,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProxySong::ProxySong(const mpd_song *song)
|
ProxySong::ProxySong(const mpd_song *song)
|
||||||
|
:LightSong(tag2)
|
||||||
{
|
{
|
||||||
directory = nullptr;
|
directory = nullptr;
|
||||||
uri = mpd_song_get_uri(song);
|
uri = mpd_song_get_uri(song);
|
||||||
real_uri = nullptr;
|
real_uri = nullptr;
|
||||||
tag = &tag2;
|
|
||||||
|
|
||||||
const auto _mtime = mpd_song_get_last_modified(song);
|
const auto _mtime = mpd_song_get_last_modified(song);
|
||||||
mtime = _mtime > 0
|
mtime = _mtime > 0
|
||||||
|
@ -98,12 +98,11 @@ Song::GetURI() const noexcept
|
|||||||
LightSong
|
LightSong
|
||||||
Song::Export() const noexcept
|
Song::Export() const noexcept
|
||||||
{
|
{
|
||||||
LightSong dest;
|
LightSong dest(tag);
|
||||||
dest.directory = parent->IsRoot()
|
dest.directory = parent->IsRoot()
|
||||||
? nullptr : parent->GetPath();
|
? nullptr : parent->GetPath();
|
||||||
dest.uri = uri;
|
dest.uri = uri;
|
||||||
dest.real_uri = nullptr;
|
dest.real_uri = nullptr;
|
||||||
dest.tag = &tag;
|
|
||||||
dest.mtime = mtime;
|
dest.mtime = mtime;
|
||||||
dest.start_time = start_time;
|
dest.start_time = start_time;
|
||||||
dest.end_time = end_time;
|
dest.end_time = end_time;
|
||||||
|
@ -55,13 +55,13 @@ class UpnpSong : public LightSong {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
UpnpSong(UPnPDirObject &&object, std::string &&_uri)
|
UpnpSong(UPnPDirObject &&object, std::string &&_uri)
|
||||||
:uri2(std::move(_uri)),
|
:LightSong(tag2),
|
||||||
|
uri2(std::move(_uri)),
|
||||||
real_uri2(std::move(object.url)),
|
real_uri2(std::move(object.url)),
|
||||||
tag2(std::move(object.tag)) {
|
tag2(std::move(object.tag)) {
|
||||||
directory = nullptr;
|
directory = nullptr;
|
||||||
uri = uri2.c_str();
|
uri = uri2.c_str();
|
||||||
real_uri = real_uri2.c_str();
|
real_uri = real_uri2.c_str();
|
||||||
tag = &tag2;
|
|
||||||
mtime = std::chrono::system_clock::time_point::min();
|
mtime = std::chrono::system_clock::time_point::min();
|
||||||
start_time = end_time = SongTime::zero();
|
start_time = end_time = SongTime::zero();
|
||||||
}
|
}
|
||||||
@ -321,11 +321,10 @@ visitSong(const UPnPDirObject &meta, const char *path,
|
|||||||
if (!visit_song)
|
if (!visit_song)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LightSong song;
|
LightSong song(meta.tag);
|
||||||
song.directory = nullptr;
|
song.directory = nullptr;
|
||||||
song.uri = path;
|
song.uri = path;
|
||||||
song.real_uri = meta.url.c_str();
|
song.real_uri = meta.url.c_str();
|
||||||
song.tag = &meta.tag;
|
|
||||||
song.mtime = std::chrono::system_clock::time_point::min();
|
song.mtime = std::chrono::system_clock::time_point::min();
|
||||||
song.start_time = song.end_time = SongTime::zero();
|
song.start_time = song.end_time = SongTime::zero();
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ UpdatePlaylistSong(const Database &db, DetachedSong &song)
|
|||||||
}
|
}
|
||||||
|
|
||||||
song.SetLastModified(original->mtime);
|
song.SetLastModified(original->mtime);
|
||||||
song.SetTag(*original->tag);
|
song.SetTag(original->tag);
|
||||||
|
|
||||||
db.ReturnSong(original);
|
db.ReturnSong(original);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user