Merge branch 'release-type' into develop

This commit is contained in:
emeric
2023-04-20 16:15:06 +02:00
37 changed files with 826 additions and 121 deletions
+9 -8
View File
@@ -20,14 +20,8 @@
</ul>
</div>
</div>
${<if-has-releases>}
${<if-release-title>}<h3>${tr:Lms.Explore.releases}</h3>${</if-release-title>}
${releases class="mb-3"}
${</if-has-releases>}
${<if-has-appears-on-releases>}
<h3>${tr:Lms.Explore.Artist.appears-on}</h3>
${appears-on-releases class="mb-3"}
${</if-has-appears-on-releases>}
${release-containers}
${appears-on-releases}
${<if-has-non-release-tracks>}
<h3>${tr:Lms.Explore.tracks}</h3>
${tracks class="mb-3"}
@@ -38,4 +32,11 @@
${</if-has-similar-artists>}
</message>
<message id="Lms.Explore.Artist.template.release-container">
<div class="mb-3">
<h3>${release-type}</h3>
${releases}
</div>
</message>
</messages>
+17
View File
@@ -197,6 +197,23 @@
<message id="Lms.Explore.Release.similar-releases">Similar albums</message>
<message id="Lms.Explore.Release.copyright">Copyright</message>
<message id="Lms.Explore.Release.disc">Disc {1}</message>
<message id="Lms.Explore.Release.type">Type</message>
<message id="Lms.Explore.Release.type-primary-album">Album</message>
<message id="Lms.Explore.Release.type-primary-broadcast">Broadcast</message>
<message id="Lms.Explore.Release.type-primary-ep">EP</message>
<message id="Lms.Explore.Release.type-primary-other">Other</message>
<message id="Lms.Explore.Release.type-primary-single">Single</message>
<message id="Lms.Explore.Release.type-secondary-audiobook">Audiobook</message>
<message id="Lms.Explore.Release.type-secondary-audiodrama">Audio drama</message>
<message id="Lms.Explore.Release.type-secondary-compilation">Compilation</message>
<message id="Lms.Explore.Release.type-secondary-demo">Demo</message>
<message id="Lms.Explore.Release.type-secondary-djmix">DJ-mix</message>
<message id="Lms.Explore.Release.type-secondary-interview">Interview</message>
<message id="Lms.Explore.Release.type-secondary-live">Live</message>
<message id="Lms.Explore.Release.type-secondary-mixtape-street">Mixtape/Street</message>
<message id="Lms.Explore.Release.type-secondary-remix">Remix</message>
<message id="Lms.Explore.Release.type-secondary-soundtrack">Soundtrack</message>
<message id="Lms.Explore.Release.type-secondary-spokenword">Spokenword</message>
<!--Explore:TrackLists-->
<message id="Lms.Explore.TrackLists.del-tracklist-confirm">Delete playlist?</message>
+17
View File
@@ -197,6 +197,23 @@
<message id="Lms.Explore.Release.similar-releases">Albums similaires</message>
<message id="Lms.Explore.Release.copyright">Copyright</message>
<message id="Lms.Explore.Release.disc">Disque {1}</message>
<message id="Lms.Explore.Release.type">Type</message>
<message id="Lms.Explore.Release.type-primary-album">Album</message>
<message id="Lms.Explore.Release.type-primary-broadcast">Broadcast</message>
<message id="Lms.Explore.Release.type-primary-ep">EP</message>
<message id="Lms.Explore.Release.type-primary-other">Other</message>
<message id="Lms.Explore.Release.type-primary-single">Single</message>
<message id="Lms.Explore.Release.type-secondary-audiobook">Audiobook</message>
<message id="Lms.Explore.Release.type-secondary-audiodrama">Audio drama</message>
<message id="Lms.Explore.Release.type-secondary-compilation">Compilation</message>
<message id="Lms.Explore.Release.type-secondary-demo">Demo</message>
<message id="Lms.Explore.Release.type-secondary-djmix">DJ-mix</message>
<message id="Lms.Explore.Release.type-secondary-interview">Interview</message>
<message id="Lms.Explore.Release.type-secondary-live">Live</message>
<message id="Lms.Explore.Release.type-secondary-mixtape-street">Mixtape/Street</message>
<message id="Lms.Explore.Release.type-secondary-remix">Remix</message>
<message id="Lms.Explore.Release.type-secondary-soundtrack">Soundtrack</message>
<message id="Lms.Explore.Release.type-secondary-spokenword">Spokenword</message>
<!--Explore:TrackLists-->
<message id="Lms.Explore.TrackLists.del-tracklist-confirm">Supprimer la liste de lecture ?</message>
+17
View File
@@ -198,6 +198,23 @@
<message id="Lms.Explore.Release.copyright">Copyright</message>
<message id="Lms.Explore.Release.disc">Disco {1}</message>
<!--Explore:TrackLists-->
+17 -4
View File
@@ -198,6 +198,23 @@
<message id="Lms.Explore.Release.copyright">版权所有</message>
<message id="Lms.Explore.Release.disc">唱片 {1}</message>
<!--Explore:TrackLists-->
<message id="Lms.Explore.TrackLists.del-tracklist-confirm">删除播放列表?</message>
@@ -210,10 +227,6 @@
<!--Playqueue-->
<message id="Lms.PlayQueue.clear">清除</message>
<message id="Lms.PlayQueue.create-tracklist">创建新播放列表</message>
<message id="Lms.PlayQueue.playqueue">播放队列</message>
<message id="Lms.PlayQueue.radio-mode">广播模式</message>
<message id="Lms.PlayQueue.repeat">循环播放</message>
+12
View File
@@ -103,7 +103,19 @@
</div>
<div class="modal-body">
<div class="container-fluid d-grid gap-2">
${<if-has-release-type>}
<div class="row align-items-center">
<div class="col-4">
${tr:Lms.Explore.Release.type}
</div>
<div class="col">
${release-type}
</div>
</div>
${</if-has-release-type>}
${<if-has-artist>}
${artist-table class="d-grid gap-2"}
${</if-has-artist>}
${<if-has-codec>}
<div class="row align-items-center">
<div class="col-4">
+2
View File
@@ -100,7 +100,9 @@
</div>
</div>
${</if-has-clusters>}
${<if-has-artist>}
${artist-table class="d-grid gap-2"}
${</if-has-artist>}
<div class="row align-items-center">
<div class="col-4">
${tr:Lms.Explore.duration}
+23 -16
View File
@@ -50,7 +50,7 @@ using TagMap = std::map<std::string, std::vector<std::string>>;
template<typename T>
std::vector<T>
getPropertyValuesFirstMatchAs(const TagMap& tags, const std::vector<std::string_view>& keys)
getPropertyValuesFirstMatchAs(const TagMap& tags, std::initializer_list<std::string_view> keys)
{
std::vector<T> res;
@@ -83,7 +83,7 @@ getPropertyValuesFirstMatchAs(const TagMap& tags, const std::vector<std::string_
template <typename T>
std::optional<T>
getPropertyValueFirstMatchAs(const TagMap& tags, const std::vector<std::string_view>& keys)
getPropertyValueFirstMatchAs(const TagMap& tags, std::initializer_list<std::string_view> keys)
{
std::optional<T> res;
std::vector<T> values {getPropertyValuesFirstMatchAs<T>(tags, keys)};
@@ -95,14 +95,14 @@ getPropertyValueFirstMatchAs(const TagMap& tags, const std::vector<std::string_v
template <typename T>
std::vector<T>
getPropertyValuesAs(const TagMap& tags, const std::string& key)
getPropertyValuesAs(const TagMap& tags, std::string_view key)
{
return getPropertyValuesFirstMatchAs<T>(tags, {key});
}
template <typename T>
std::optional<T>
getPropertyValueAs(const TagMap& tags, const std::string& key)
getPropertyValueAs(const TagMap& tags, std::string_view key)
{
return getPropertyValueFirstMatchAs<T>(tags, {key});
}
@@ -121,22 +121,22 @@ splitAndTrimString(std::string_view str, std::string_view delimiters)
static
std::vector<Artist>
getArtists(const TagMap& tags,
const std::vector<std::string_view>& artistTagNames,
const std::vector<std::string_view>& artistSortTagNames,
const std::vector<std::string_view>& artistMBIDTagNames
std::initializer_list<std::string_view> artistTagNames,
std::initializer_list<std::string_view> artistSortTagNames,
std::initializer_list<std::string_view> artistMBIDTagNames
)
{
const std::vector<std::string> artistNames {getPropertyValuesFirstMatchAs<std::string>(tags, artistTagNames)};
const std::vector<std::string_view> artistNames {getPropertyValuesFirstMatchAs<std::string_view>(tags, artistTagNames)};
if (artistNames.empty())
return {};
std::vector<Artist> artists;
artists.reserve(artistNames.size());
std::transform(std::cbegin(artistNames), std::cend(artistNames), std::back_inserter(artists),
[&](const std::string& name) { return Artist {name}; });
[&](std::string_view name) { return Artist {name}; });
{
const std::vector<std::string> artistSortNames {getPropertyValuesFirstMatchAs<std::string>(tags, artistSortTagNames)};
const std::vector<std::string_view> artistSortNames {getPropertyValuesFirstMatchAs<std::string_view>(tags, artistSortTagNames)};
if (artistSortNames.size() == artists.size())
{
for (std::size_t i {}; i < artistSortNames.size(); ++i)
@@ -161,14 +161,14 @@ getArtists(const TagMap& tags,
static
PerformerContainer
getPerformerArtists(const TagMap& tags,
const std::vector<std::string_view>& artistTagNames)
std::initializer_list<std::string_view> artistTagNames)
{
PerformerContainer performers;
// picard stores like this: (see https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#performer)
// We may hit both styles for the same track
// PERFORMER: artist (role)
if (const std::vector<std::string> artistNames {getPropertyValuesFirstMatchAs<std::string>(tags, artistTagNames)}; !artistNames.empty())
if (const std::vector<std::string_view> artistNames {getPropertyValuesFirstMatchAs<std::string_view>(tags, artistTagNames)}; !artistNames.empty())
{
for (std::string_view entry : artistNames)
{
@@ -216,7 +216,7 @@ getRelease(const TagMap& tags)
if (!release->mediumCount)
{
// mediumCount may be encoded as "position/count"
if (const auto value {getPropertyValueAs<std::string>(tags, "DISCNUMBER")})
if (const auto value {getPropertyValueAs<std::string_view>(tags, "DISCNUMBER")})
{
// Expecting 'Number/Total'
const std::vector<std::string_view> strings {StringUtils::splitString(*value, "/") };
@@ -225,6 +225,13 @@ getRelease(const TagMap& tags)
}
}
release->primaryType = getPropertyValueFirstMatchAs<MetaData::Release::PrimaryType>(tags, {"MUSICBRAINZ_ALBUMTYPE", "RELEASETYPE", "MUSICBRAINZ ALBUM TYPE", "MUSICBRAINZ/ALBUM TYPE"});
if (release->primaryType)
{
const auto secondaryTypes {getPropertyValuesFirstMatchAs<MetaData::Release::SecondaryType>(tags, {"MUSICBRAINZ_ALBUMTYPE", "RELEASETYPE", "MUSICBRAINZ ALBUM TYPE", "MUSICBRAINZ/ALBUM TYPE"})};
release->secondaryTypes.assign(std::cbegin(secondaryTypes), std::cend(secondaryTypes));
}
return release;
}
@@ -241,7 +248,7 @@ getMedium(const TagMap& tags)
if (!medium->trackCount)
{
// totalTracks may be encoded as "position/count"
if (const auto value {getPropertyValueAs<std::string>(tags, "TRACKNUMBER")})
if (const auto value {getPropertyValueAs<std::string_view>(tags, "TRACKNUMBER")})
{
// Expecting 'Number/Total'
const std::vector<std::string_view> strings {StringUtils::splitString(*value, "/") };
@@ -445,7 +452,7 @@ TagLibParser::parse(const std::filesystem::path& p, bool debug)
for (const auto& [name, attributeList] : tag->attributeListMap())
{
std::string strName {name.to8Bit(true)};
std::string strName {StringUtils::stringToUpper(name.to8Bit(true))};
if (strName.find("WM/") == 0 || tags.find(strName) != std::cend(tags))
continue;
@@ -461,7 +468,7 @@ TagLibParser::parse(const std::filesystem::path& p, bool debug)
if (debug)
std::cout << "ASF property: '" << name << "'" << std::endl;
tags[strName] = std::move(attributes);
tags.emplace(strName, std::move(attributes));
}
}
}
+47
View File
@@ -119,3 +119,50 @@ namespace MetaData::Utils
}
}
namespace StringUtils
{
static bool iequals(std::string_view a, std::string_view b)
{
return std::equal(std::cbegin(a), std::cend(a),
std::cbegin(b), std::cend(b),
[](char a, char b) { return tolower(a) == tolower(b);}
);
}
template<>
std::optional<MetaData::Release::PrimaryType> readAs(std::string_view str)
{
str = stringTrim(str);
if (iequals(str, "album"))
return MetaData::Release::PrimaryType::Album;
else if (iequals(str, "single"))
return MetaData::Release::PrimaryType::Single;
else if (iequals(str, "EP"))
return MetaData::Release::PrimaryType::EP;
else if (iequals(str, "broadcast"))
return MetaData::Release::PrimaryType::Broadcast;
else if (iequals(str, "other"))
return MetaData::Release::PrimaryType::Other;
return std::nullopt;
}
template<>
std::optional<MetaData::Release::SecondaryType> readAs(std::string_view str)
{
str = stringTrim(str);
if (iequals(str, "compilation"))
return MetaData::Release::SecondaryType::Compilation;
else if (iequals(str, "soundtrack"))
return MetaData::Release::SecondaryType::Soundtrack;
else if (iequals(str, "live"))
return MetaData::Release::SecondaryType::Live;
else if (iequals(str, "demo"))
return MetaData::Release::SecondaryType::Demo;
return std::nullopt;
}
}
+9 -1
View File
@@ -38,6 +38,14 @@ namespace MetaData::Utils
// format is "artist name (role)"
PerformerArtist extractPerformerAndRole(std::string_view entry);
}
namespace StringUtils
{
template<>
std::optional<MetaData::Release::PrimaryType> readAs(std::string_view str);
template<>
std::optional<MetaData::Release::SecondaryType> readAs(std::string_view str);
}
@@ -29,6 +29,7 @@
#include <vector>
#include <Wt/WDate.h>
#include "utils/EnumSet.hpp"
#include "utils/UUID.hpp"
namespace MetaData
@@ -51,10 +52,37 @@ namespace MetaData
struct Release
{
// see https://musicbrainz.org/doc/Release_Group/Type
enum class PrimaryType
{
Album,
Single,
EP,
Broadcast,
Other
};
enum class SecondaryType
{
Compilation,
Soundtrack,
Spokenword,
Interview,
Audiobook,
AudioDrama,
Live,
Remix,
DJMix,
Mixtape_Street,
Demo,
};
std::optional<UUID> mbid;
std::string name;
std::vector<Artist> artists;
std::optional<std::size_t> mediumCount;
std::optional<PrimaryType> primaryType;
EnumSet<SecondaryType> secondaryTypes;
};
struct Medium
+57
View File
@@ -115,3 +115,60 @@ TEST(MetaData, extractPerformerAndRole)
EXPECT_EQ(performer.role, testCase.expectedRole) << " str was '" << testCase.str << "'";
}
}
TEST(MetaData, primaryReleaseTypes)
{
using namespace MetaData;
struct TestCase
{
std::string str;
std::optional<Release::PrimaryType> result;
} testCases []
{
{ "", std::nullopt },
{ "album", Release::PrimaryType::Album },
{ "Album", Release::PrimaryType::Album },
{ " Album", Release::PrimaryType::Album },
{ "Album ", Release::PrimaryType::Album },
{ "ep", Release::PrimaryType::EP },
{ " ep ", Release::PrimaryType::EP },
{ "broadcast", Release::PrimaryType::Broadcast },
{ "single", Release::PrimaryType::Single },
{ "other", Release::PrimaryType::Other },
};
for (const TestCase& testCase : testCases)
{
std::optional<Release::PrimaryType> parsed {StringUtils::readAs<Release::PrimaryType>(testCase.str)};
EXPECT_EQ(parsed, testCase.result) << " str was '" << testCase.str << "'";
}
}
TEST(MetaData, secondaryReleaseTypes)
{
using namespace MetaData;
struct TestCase
{
std::string str;
std::optional<Release::SecondaryType> result;
} testCases []
{
{ "", std::nullopt },
{ "compilation", Release::SecondaryType::Compilation },
{ " compilation ", Release::SecondaryType::Compilation },
{ "soundtrack", Release::SecondaryType::Soundtrack },
{ "live", Release::SecondaryType::Live },
{ "demo", Release::SecondaryType::Demo },
};
for (const TestCase& testCase : testCases)
{
std::optional<Release::SecondaryType> parsed {StringUtils::readAs<Release::SecondaryType>(testCase.str)};
EXPECT_EQ(parsed, testCase.result) << " str was '" << testCase.str << "'";
}
}
@@ -28,6 +28,7 @@
#include "utils/Logger.hpp"
#include "SqlQuery.hpp"
#include "Utils.hpp"
#include "EnumSetTraits.hpp"
#include "IdTypeTraits.hpp"
namespace Database
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2023 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <type_traits>
#include <Wt/Dbo/StdSqlTraits.h>
#include "utils/EnumSet.hpp"
namespace Wt::Dbo
{
template<typename T>
struct sql_value_traits<EnumSet<T>, void> : public sql_value_traits<long long>
{
using ValueType = typename EnumSet<T>::ValueType;
static_assert(sizeof(long long) > sizeof(ValueType));
static void bind(EnumSet<T> v, SqlStatement *statement, int column, int size)
{
sql_value_traits<long long>::bind(static_cast<long long>(v.getBitfield()), statement, column, size);
}
static bool read(EnumSet<T>& v, SqlStatement *statement, int column, int size)
{
long long val;
if (sql_value_traits<long long>::read(val, statement, column, size))
{
v.setBitfield(val);
return true;
}
v.clear();
return false;
}
};
}
@@ -653,6 +653,18 @@ CREATE TABLE IF NOT EXISTS "track_backup" (
ScanSettings::get(session).modify()->incScanVersion();
}
static
void
migrateFromV39(Session& session)
{
// add release type
session.getDboSession().execute("ALTER TABLE release ADD primary_type INTEGER");
session.getDboSession().execute("ALTER TABLE release ADD secondary_types INTEGER");
// Just increment the scan version of the settings to make the next scheduled scan rescan everything
ScanSettings::get(session).modify()->incScanVersion();
}
void
doDbMigration(Session& session)
{
@@ -698,6 +710,7 @@ CREATE TABLE IF NOT EXISTS "track_backup" (
{36, migrateFromV36},
{37, migrateFromV37},
{38, migrateFromV38},
{39, migrateFromV39},
};
while (1)
@@ -26,7 +26,7 @@ namespace Database
class Session;
using Version = std::size_t;
static constexpr Version LMS_DATABASE_VERSION {39};
static constexpr Version LMS_DATABASE_VERSION {40};
class VersionInfo
{
public:
@@ -28,6 +28,7 @@
#include "services/database/User.hpp"
#include "utils/Logger.hpp"
#include "SqlQuery.hpp"
#include "EnumSetTraits.hpp"
#include "IdTypeTraits.hpp"
#include "Utils.hpp"
@@ -138,6 +139,11 @@ createQuery(Session& session, const Release::FindParameters& params)
query.where(oss.str());
}
if (params.primaryType)
query.where("primary_type = ?").bind(*params.primaryType);
if (!params.secondaryTypes.empty())
query.where("secondary_type = ?").bind(params.secondaryTypes);
switch (params.sortMethod)
{
case ReleaseSortMethod::None:
@@ -40,6 +40,7 @@
#include "services/database/TrackList.hpp"
#include "services/database/TrackFeatures.hpp"
#include "services/database/User.hpp"
#include "EnumSetTraits.hpp"
#include "Migration.hpp"
namespace Database
@@ -61,6 +61,8 @@ class Release : public Object<Release, ReleaseId>
ArtistId artist; // only releases that involved this user
EnumSet<TrackArtistLinkType> trackArtistLinkTypes; // and for these link types
EnumSet<TrackArtistLinkType> excludedTrackArtistLinkTypes; // but not for these link types
std::optional<ReleaseTypePrimary> primaryType; // if, set, matching this primary type
EnumSet<ReleaseTypeSecondary> secondaryTypes; // Matching all this (if any)
FindParameters& setClusters(const std::vector<ClusterId>& _clusters) { clusters = _clusters; return *this; }
FindParameters& setKeywords(const std::vector<std::string_view>& _keywords) { keywords = _keywords; return *this; }
@@ -109,11 +111,15 @@ class Release : public Object<Release, ReleaseId>
std::size_t getDiscCount() const; // may not be total disc (if incomplete for example)
std::chrono::milliseconds getDuration() const;
Wt::WDateTime getLastWritten() const;
std::optional<ReleaseTypePrimary> getPrimaryType() const { return _primaryType; }
EnumSet<ReleaseTypeSecondary> getSecondaryTypes() const { return _secondaryTypes; }
// Setters
void setName(std::string_view name) { _name = name; }
void setMBID(const std::optional<UUID>& mbid) { _MBID = mbid ? mbid->getAsString() : ""; }
void setTotalDisc(std::optional<int> totalDisc) { _totalDisc = totalDisc; }
void setPrimaryType(std::optional<ReleaseTypePrimary> type) { _primaryType = type; }
void setSecondaryTypes(EnumSet<ReleaseTypeSecondary> types) { _secondaryTypes = types; }
// Get the artists of this release
std::vector<ObjectPtr<Artist>> getArtists(TrackArtistLinkType type = TrackArtistLinkType::Artist) const;
@@ -128,6 +134,8 @@ class Release : public Object<Release, ReleaseId>
Wt::Dbo::field(a, _name, "name");
Wt::Dbo::field(a, _MBID, "mbid");
Wt::Dbo::field(a, _totalDisc, "total_disc");
Wt::Dbo::field(a, _primaryType, "primary_type");
Wt::Dbo::field(a, _secondaryTypes, "secondary_types");
Wt::Dbo::hasMany(a, _tracks, Wt::Dbo::ManyToOne, "release");
}
@@ -139,9 +147,11 @@ class Release : public Object<Release, ReleaseId>
static constexpr std::size_t _maxNameLength {128};
std::string _name;
std::string _MBID;
std::optional<int> _totalDisc {};
std::string _name;
std::string _MBID;
std::optional<int> _totalDisc {};
std::optional<ReleaseTypePrimary> _primaryType;
EnumSet<ReleaseTypeSecondary> _secondaryTypes;
Wt::Dbo::collection<Wt::Dbo::ptr<Track>> _tracks; // Tracks in the release
};
@@ -191,5 +191,30 @@ namespace Database
Playlist, // user controlled playlists
Internal, // internal usage (current playqueue, history, ...)
};
// as defined in https://musicbrainz.org/doc/Release_Group/Type
enum class ReleaseTypePrimary
{
Album,
Single,
EP,
Broadcast,
Other,
};
enum class ReleaseTypeSecondary
{
Compilation,
Soundtrack,
Spokenword,
Interview,
Audiobook,
AudioDrama,
Live,
Remix,
DJMix,
Mixtape_Street,
Demo,
};
}
@@ -507,3 +507,26 @@ TEST_F(DatabaseFixture, Release_getDiscCount)
EXPECT_EQ(release.get()->getDiscCount(), 2);
}
}
TEST_F(DatabaseFixture, Release_releaseType)
{
ScopedRelease release {session, "MyRelease"};
{
auto transaction {session.createSharedTransaction()};
EXPECT_EQ(release.get()->getPrimaryType(), std::nullopt);
EXPECT_EQ(release.get()->getSecondaryTypes(), EnumSet<ReleaseTypeSecondary> {});
}
{
auto transaction {session.createUniqueTransaction()};
release.get().modify()->setPrimaryType({ ReleaseTypePrimary::Album });
release.get().modify()->setSecondaryTypes({ ReleaseTypeSecondary::Compilation });
}
{
auto transaction {session.createSharedTransaction()};
EXPECT_EQ(release.get()->getPrimaryType(), ReleaseTypePrimary::Album);
EXPECT_TRUE(release.get()->getSecondaryTypes().contains(ReleaseTypeSecondary::Compilation));
}
}
@@ -115,6 +115,67 @@ namespace
return artists;
}
ReleaseTypePrimary convertReleaseTypePrimary(MetaData::Release::PrimaryType type)
{
switch (type)
{
case MetaData::Release::PrimaryType::Album: return ReleaseTypePrimary::Album;
case MetaData::Release::PrimaryType::Single: return ReleaseTypePrimary::Single;
case MetaData::Release::PrimaryType::EP: return ReleaseTypePrimary::EP;
case MetaData::Release::PrimaryType::Broadcast: return ReleaseTypePrimary::Broadcast;
case MetaData::Release::PrimaryType::Other: return ReleaseTypePrimary::Other;
}
return ReleaseTypePrimary::Other;
}
EnumSet<ReleaseTypeSecondary> convertReleaseTypesSecondary(EnumSet<MetaData::Release::SecondaryType> types)
{
EnumSet<ReleaseTypeSecondary> res;
for (MetaData::Release::SecondaryType type : types)
{
switch (type)
{
case MetaData::Release::SecondaryType::Compilation:
res.insert(ReleaseTypeSecondary::Compilation);
break;
case MetaData::Release::SecondaryType::Soundtrack:
res.insert(ReleaseTypeSecondary::Soundtrack);
break;
case MetaData::Release::SecondaryType::Spokenword:
res.insert(ReleaseTypeSecondary::Spokenword);
break;
case MetaData::Release::SecondaryType::Interview:
res.insert(ReleaseTypeSecondary::Interview);
break;
case MetaData::Release::SecondaryType::Audiobook:
res.insert(ReleaseTypeSecondary::Audiobook);
break;
case MetaData::Release::SecondaryType::AudioDrama:
res.insert(ReleaseTypeSecondary::AudioDrama);
break;
case MetaData::Release::SecondaryType::Live:
res.insert(ReleaseTypeSecondary::Live);
break;
case MetaData::Release::SecondaryType::Remix:
res.insert(ReleaseTypeSecondary::Remix);
break;
case MetaData::Release::SecondaryType::DJMix:
res.insert(ReleaseTypeSecondary::DJMix);
break;
case MetaData::Release::SecondaryType::Mixtape_Street:
res.insert(ReleaseTypeSecondary::Mixtape_Street);
break;
case MetaData::Release::SecondaryType::Demo:
res.insert(ReleaseTypeSecondary::Demo);
break;
}
}
return res;
}
void
updateReleaseIfNeeded(Release::pointer release, const MetaData::Release& releaseInfo)
{
@@ -122,6 +183,15 @@ namespace
release.modify()->setName(releaseInfo.name);
if (release->getTotalDisc() != releaseInfo.mediumCount)
release.modify()->setTotalDisc(releaseInfo.mediumCount);
if (releaseInfo.primaryType)
{
const ReleaseTypePrimary primaryType {convertReleaseTypePrimary(*releaseInfo.primaryType)};
if (release->getPrimaryType() != primaryType)
release.modify()->setPrimaryType(primaryType);
}
const EnumSet<ReleaseTypeSecondary> secondaryTypes {convertReleaseTypesSecondary(releaseInfo.secondaryTypes)};
if (release->getSecondaryTypes() != secondaryTypes)
release.modify()->setSecondaryTypes(secondaryTypes);
}
Release::pointer
+7
View File
@@ -63,6 +63,13 @@ readAs(std::string_view str)
return std::string {str};
}
template<>
std::optional<std::string_view>
readAs(std::string_view str)
{
return str;
}
template<>
std::optional<bool>
readAs(std::string_view str)
+44 -12
View File
@@ -31,9 +31,11 @@ class EnumSet
static_assert(std::is_enum<T>::value);
static_assert(std::is_same<underlying_type, std::uint64_t>::value || std::is_same<underlying_type, std::uint32_t>::value);
using index_type = std::uint_fast8_t;
using IndexType = std::uint_fast8_t;
public:
using ValueType = underlying_type;
EnumSet() = default;
constexpr EnumSet(std::initializer_list<T> values)
{
@@ -44,6 +46,13 @@ class EnumSet
template <typename It>
constexpr EnumSet(It begin, It end)
{
assign(begin, end);
}
template <typename It>
constexpr void assign(It begin, It end)
{
clear();
for (It it {begin}; it != end; ++it)
insert(*it);
}
@@ -71,6 +80,11 @@ class EnumSet
return _bitfield & (underlying_type{ 1 } << static_cast<underlying_type>(value));
}
constexpr void clear()
{
_bitfield = 0;
}
class iterator
{
public:
@@ -100,14 +114,14 @@ class EnumSet
private:
friend class EnumSet;
constexpr iterator(const EnumSet& _container, index_type _index)
constexpr iterator(const EnumSet& _container, IndexType _index)
: _container {_container}
, _index {_index}
{
}
const EnumSet& _container;
index_type _index;
IndexType _index;
};
constexpr iterator begin() const
@@ -120,25 +134,45 @@ class EnumSet
return iterator {*this, npos};
}
private:
static_assert(std::numeric_limits<index_type>::max() >= sizeof(underlying_type) * 8);
enum : index_type { npos = sizeof(underlying_type) * 8 };
constexpr underlying_type getBitfield() const
{
return _bitfield;
}
constexpr index_type getFirstBitSetIndex(index_type start = {}) const
constexpr void setBitfield(underlying_type bitfield)
{
_bitfield = bitfield;
}
constexpr bool operator==(const EnumSet other) const
{
return _bitfield == other._bitfield;
}
constexpr bool operator!=(const EnumSet other) const
{
return _bitfield != other._bitfield;
}
private:
static_assert(std::numeric_limits<IndexType>::max() >= sizeof(underlying_type) * 8);
enum : IndexType { npos = sizeof(underlying_type) * 8 };
constexpr IndexType getFirstBitSetIndex(IndexType start = {}) const
{
assert(start < npos);
// return npos if no bit found
index_type res {countTrailingZero(_bitfield >> start)};
IndexType res {countTrailingZero(_bitfield >> start)};
if (res == npos)
return res;
return res + start;
}
static constexpr index_type countTrailingZero(underlying_type bitField)
static constexpr IndexType countTrailingZero(underlying_type bitField)
{
index_type res {};
IndexType res {};
while (res < (sizeof(underlying_type) * 8) && (bitField & 1) == 0)
{
@@ -154,5 +188,3 @@ class EnumSet
underlying_type _bitfield{};
};
+5
View File
@@ -88,6 +88,11 @@ template<>
std::optional<std::string>
readAs(std::string_view str);
template<>
[[nodiscard]]
std::optional<std::string_view>
readAs(std::string_view str);
template<>
[[nodiscard]]
std::optional<bool>
+2 -1
View File
@@ -1,8 +1,9 @@
include(GoogleTest)
add_executable(test-utils
String.cpp
EnumSet.cpp
RecursiveSharedMutex.cpp
String.cpp
Utils.cpp
)
+60
View File
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2019 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include "utils/EnumSet.hpp"
TEST(EnumSet, ctr)
{
enum class Foo
{
One,
Two,
};
{
constexpr EnumSet<Foo> test {Foo::One};
static_assert(!test.empty());
static_assert(test.contains(Foo::One));
static_assert(!test.contains(Foo::Two));
EXPECT_TRUE(!test.empty());
EXPECT_TRUE(test.contains(Foo::One));
EXPECT_FALSE(test.contains(Foo::Two));
static_assert(test.getBitfield() != 0);
}
{
constexpr EnumSet<Foo> test {Foo::One, Foo::Two};
constexpr auto bitfield {test.getBitfield()};
EnumSet<Foo> test2;
EXPECT_FALSE(test2.contains(Foo::One));
EXPECT_FALSE(test2.contains(Foo::Two));
test2.setBitfield(bitfield);
EXPECT_TRUE(test2.contains(Foo::One));
EXPECT_TRUE(test2.contains(Foo::Two));
EXPECT_EQ(test, test2);
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ add_executable(lms
ui/explore/Filters.cpp
ui/explore/PlayQueueController.cpp
ui/explore/ReleaseCollector.cpp
ui/explore/ReleaseListHelpers.cpp
ui/explore/ReleaseHelpers.cpp
ui/explore/ReleasesView.cpp
ui/explore/ReleaseView.cpp
ui/explore/SearchView.cpp
+95 -50
View File
@@ -40,7 +40,7 @@
#include "LmsApplication.hpp"
#include "LmsApplicationException.hpp"
#include "PlayQueueController.hpp"
#include "ReleaseListHelpers.hpp"
#include "ReleaseHelpers.hpp"
#include "TrackListHelpers.hpp"
#include "Utils.hpp"
@@ -48,6 +48,19 @@ using namespace Database;
namespace UserInterface {
bool
Artist::ReleaseType::operator<(const ReleaseType& other) const
{
if (!primaryType && other.primaryType)
return false;
else if (primaryType && !other.primaryType)
return true;
else if (*primaryType == *other.primaryType)
return secondaryTypes.getBitfield() < other.secondaryTypes.getBitfield();
else
return static_cast<int>(*primaryType) < static_cast<int>(*other.primaryType);
}
Artist::Artist(Filters& filters, PlayQueueController& controller)
: Template {Wt::WString::tr("Lms.Explore.Artist.template")}
, _filters {filters}
@@ -114,15 +127,12 @@ Artist::refreshView()
LmsApp->setTitle(artist->getName());
_artistId = *artistId;
bool setReleaseTitle {};
refreshReleases();
setReleaseTitle |= refreshAppearsOnReleases();
setReleaseTitle |= refreshNonReleaseTracks();
refreshAppearsOnReleases();
refreshNonReleaseTracks();
refreshLinks(artist);
refreshSimilarArtists(similarArtistIds);
setCondition("if-release-title", setReleaseTitle);
Wt::WContainerWidget* clusterContainers {bindNew<Wt::WContainerWidget>("clusters")};
{
@@ -184,25 +194,57 @@ Artist::refreshView()
}
}
bool
void
Artist::refreshReleases()
{
_releaseContainer = bindNew<InfiniteScrollingContainer>("releases", Wt::WString::tr("Lms.Explore.Releases.template.container"));
_releaseContainer->onRequestElements.connect(this, [this]
_releaseContainers.clear();
Release::FindParameters params;
params.setClusters(_filters.getClusterIds());
params.setArtist(_artistId, {TrackArtistLinkType::ReleaseArtist}, {});
params.setSortMethod(ReleaseSortMethod::DateDesc);
const auto releases {Release::find(LmsApp->getDbSession(), params)};
if (!releases.results.empty())
{
addSomeReleases(*_releaseContainer, {TrackArtistLinkType::ReleaseArtist}, {});
});
// first pass: gather all ids and sort by type
for (const ReleaseId releaseId : releases.results)
{
const Database::Release::pointer release {Database::Release::find(LmsApp->getDbSession(), releaseId)};
const bool added {addSomeReleases(*_releaseContainer, {TrackArtistLinkType::ReleaseArtist}, {})};
setCondition("if-has-releases", added);
ReleaseType releaseType {release->getPrimaryType(), release->getSecondaryTypes()};
_releaseContainers[releaseType].releases.push_back(releaseId);
}
return added;
// second pass: construct widgets
Wt::WContainerWidget* releaseContainers {bindNew<Wt::WContainerWidget>("release-containers")};
for (auto& [releaseType, releases] : _releaseContainers)
{
Wt::WTemplate* releaseContainer {releaseContainers->addNew<Wt::WTemplate>(Wt::WString::tr("Lms.Explore.Artist.template.release-container"))};
if (releaseType.primaryType)
releaseContainer->bindString("release-type", ReleaseHelpers::buildReleaseTypeString(*releaseType.primaryType, releaseType.secondaryTypes));
else
releaseContainer->bindString("release-type", Wt::WString::tr("Lms.Explore.releases")); // fallback when not tagged with MB
releases.container = releaseContainer->bindNew<InfiniteScrollingContainer>("releases", Wt::WString::tr("Lms.Explore.Releases.template.container"));
releases.container->onRequestElements.connect(this, [this, &releases = releases]
{
addSomeReleases(releases);
});
releases.container->setHasMore(true);
}
}
else
{
bindEmpty("release-containers");
}
}
bool
void
Artist::refreshAppearsOnReleases()
{
const EnumSet<TrackArtistLinkType> types
constexpr EnumSet<TrackArtistLinkType> types
{
TrackArtistLinkType::Artist,
TrackArtistLinkType::Arranger,
@@ -216,18 +258,33 @@ Artist::refreshAppearsOnReleases()
TrackArtistLinkType::Writer,
};
_appearsOnReleaseContainer = bindNew<InfiniteScrollingContainer>("appears-on-releases", Wt::WString::tr("Lms.Explore.Releases.template.container"));
_appearsOnReleaseContainer->onRequestElements.connect(this, [=]
{
addSomeReleases(*_appearsOnReleaseContainer, types, {TrackArtistLinkType::ReleaseArtist});
});
_appearsOnReleaseContainer = {};
const bool added {addSomeReleases(*_appearsOnReleaseContainer, types, {TrackArtistLinkType::ReleaseArtist})};
setCondition("if-has-appears-on-releases", added);
return added;
Release::FindParameters params;
params.setClusters(_filters.getClusterIds());
params.setArtist(_artistId, types, {TrackArtistLinkType::ReleaseArtist});
params.setSortMethod(ReleaseSortMethod::DateDesc);
const auto releases {Release::find(LmsApp->getDbSession(), params)};
if (!releases.results.empty())
{
Wt::WTemplate* releaseContainer {bindNew<Wt::WTemplate>("appears-on-releases", Wt::WString::tr("Lms.Explore.Artist.template.release-container"))};
releaseContainer->bindString("release-type", Wt::WString::tr("Lms.Explore.Artist.appears-on"));
_appearsOnReleaseContainer.releases = releases.results;
_appearsOnReleaseContainer.container = releaseContainer->bindNew<InfiniteScrollingContainer>("releases", Wt::WString::tr("Lms.Explore.Releases.template.container"));
_appearsOnReleaseContainer.container->onRequestElements.connect(this, [this, &releases]
{
addSomeReleases(_appearsOnReleaseContainer);
});
_appearsOnReleaseContainer.container->setHasMore(true);
}
else
{
bindEmpty("appears-on-releases");
}
}
bool
void
Artist::refreshNonReleaseTracks()
{
setCondition("if-has-non-release-tracks", true);
@@ -239,7 +296,6 @@ Artist::refreshNonReleaseTracks()
const bool added {addSomeNonReleaseTracks()};
setCondition("if-has-non-release-tracks", added);
return added;
}
void
@@ -272,35 +328,24 @@ Artist::refreshLinks(const Database::Artist::pointer& artist)
}
}
bool
Artist::addSomeReleases(InfiniteScrollingContainer& releaseContainer, EnumSet<Database::TrackArtistLinkType> linkTypes, EnumSet<Database::TrackArtistLinkType> excludedLinkTypes)
void
Artist::addSomeReleases(ReleaseContainer& releaseContainer)
{
bool areArtistsAdded{};
auto transaction {LmsApp->getDbSession().createSharedTransaction()};
const Database::Artist::pointer artist {Database::Artist::find(LmsApp->getDbSession(), _artistId)};
if (!artist)
return areArtistsAdded;
const Range range {static_cast<std::size_t>(releaseContainer.getCount()), _releasesBatchSize};
Release::FindParameters params;
params.setClusters(_filters.getClusterIds());
params.setArtist(_artistId, linkTypes, excludedLinkTypes);
params.setRange(range);
params.setSortMethod(ReleaseSortMethod::DateDesc);
const auto releases {Release::find(LmsApp->getDbSession(), params)};
for (const ReleaseId releaseId : releases.results)
if (const Database::Artist::pointer artist {Database::Artist::find(LmsApp->getDbSession(), _artistId)})
{
const Database::Release::pointer release {Database::Release::find(LmsApp->getDbSession(), releaseId)};
releaseContainer.add(ReleaseListHelpers::createEntryForArtist(release, artist));
areArtistsAdded = true;
for (std::size_t i {static_cast<std::size_t>(releaseContainer.container->getCount())}; i < releaseContainer.releases.size(); ++i)
{
const Database::Release::pointer release {Database::Release::find(LmsApp->getDbSession(), releaseContainer.releases[i])};
releaseContainer.container->add(ReleaseListHelpers::createEntryForArtist(release, artist));
}
releaseContainer.container->setHasMore(releaseContainer.container->getCount() < releaseContainer.releases.size());
}
else
{
releaseContainer.container->setHasMore(false);
}
releaseContainer.setHasMore(releases.moreResults);
return areArtistsAdded;
}
bool
+24 -6
View File
@@ -19,8 +19,11 @@
#pragma once
#include <map>
#include <optional>
#include "services/database/ArtistId.hpp"
#include "services/database/Object.hpp"
#include "services/database/ReleaseId.hpp"
#include "services/database/Types.hpp"
#include "utils/EnumSet.hpp"
#include "common/Template.hpp"
@@ -44,13 +47,14 @@ namespace UserInterface
private:
void refreshView();
bool refreshReleases();
bool refreshAppearsOnReleases();
bool refreshNonReleaseTracks();
void refreshReleases();
void refreshAppearsOnReleases();
void refreshNonReleaseTracks();
void refreshSimilarArtists(const std::vector<Database::ArtistId>& similarArtistsId);
void refreshLinks(const Database::ObjectPtr<Database::Artist>& artist);
bool addSomeReleases(InfiniteScrollingContainer& container, EnumSet<Database::TrackArtistLinkType> linkTypes, EnumSet<Database::TrackArtistLinkType> excludedLinkTypes);
struct ReleaseContainer;
void addSomeReleases(ReleaseContainer& releaseContainer);
bool addSomeNonReleaseTracks();
static constexpr std::size_t _releasesBatchSize {6};
static constexpr std::size_t _tracksBatchSize {6};
@@ -58,8 +62,22 @@ namespace UserInterface
Filters& _filters;
PlayQueueController& _playQueueController;
InfiniteScrollingContainer* _releaseContainer {};
InfiniteScrollingContainer* _appearsOnReleaseContainer {};
struct ReleaseType
{
std::optional<Database::ReleaseTypePrimary> primaryType;
EnumSet<Database::ReleaseTypeSecondary> secondaryTypes;
bool operator<(const ReleaseType& other) const;
};
struct ReleaseContainer
{
InfiniteScrollingContainer* container {};
std::vector<Database::ReleaseId> releases;
};
std::map<ReleaseType, ReleaseContainer> _releaseContainers;
ReleaseContainer _appearsOnReleaseContainer {};
InfiniteScrollingContainer* _trackContainer {};
Database::ArtistId _artistId {};
};
@@ -17,7 +17,7 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ReleaseListHelpers.hpp"
#include "ReleaseHelpers.hpp"
#include <Wt/WAnchor.h>
#include <Wt/WImage.h>
@@ -104,3 +104,42 @@ namespace UserInterface::ReleaseListHelpers
}
} // namespace UserInterface
namespace UserInterface::ReleaseHelpers
{
Wt::WString
buildReleaseTypeString(ReleaseTypePrimary primaryType, EnumSet<ReleaseTypeSecondary> secondaryTypes)
{
Wt::WString res;
switch (primaryType)
{
case ReleaseTypePrimary::Album: res = Wt::WString::tr("Lms.Explore.Release.type-primary-album"); break;
case ReleaseTypePrimary::Broadcast: res = Wt::WString::tr("Lms.Explore.Release.type-primary-broadcast"); break;
case ReleaseTypePrimary::EP: res = Wt::WString::tr("Lms.Explore.Release.type-primary-ep"); break;
case ReleaseTypePrimary::Single: res = Wt::WString::tr("Lms.Explore.Release.type-primary-single"); break;
case ReleaseTypePrimary::Other: res = Wt::WString::tr("Lms.Explore.Release.type-primary-other"); break;
}
for (ReleaseTypeSecondary secondaryType : secondaryTypes)
{
res += Wt::WString {" · "};
switch (secondaryType)
{
case ReleaseTypeSecondary::Compilation: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-compilation"); break;
case ReleaseTypeSecondary::Spokenword: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-spokenword"); break;
case ReleaseTypeSecondary::Soundtrack: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-soundtrack"); break;
case ReleaseTypeSecondary::Interview: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-interview"); break;
case ReleaseTypeSecondary::Audiobook: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-audiobook"); break;
case ReleaseTypeSecondary::AudioDrama: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-audiodrama"); break;
case ReleaseTypeSecondary::Live: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-live"); break;
case ReleaseTypeSecondary::Remix: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-remix"); break;
case ReleaseTypeSecondary::DJMix: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-djmix"); break;
case ReleaseTypeSecondary::Mixtape_Street: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-mixtape-street"); break;
case ReleaseTypeSecondary::Demo: res += Wt::WString::tr("Lms.Explore.Release.type-secondary-demo"); break;
}
}
return res;
}
} // namespace UserInterface::ReleaseHelpers}
@@ -23,6 +23,8 @@
#include <Wt/WTemplate.h>
#include "services/database/Object.hpp"
#include "services/database/Types.hpp"
#include "utils/EnumSet.hpp"
namespace Database
{
@@ -36,3 +38,7 @@ namespace UserInterface::ReleaseListHelpers
std::unique_ptr<Wt::WTemplate> createEntryForArtist(const Database::ObjectPtr<Database::Release>& release, const Database::ObjectPtr<Database::Artist>& artist);
} // namespace UserInterface
namespace UserInterface::ReleaseHelpers
{
Wt::WString buildReleaseTypeString(Database::ReleaseTypePrimary primaryType, EnumSet<Database::ReleaseTypeSecondary> secondaryTypes);
}
+19 -8
View File
@@ -40,7 +40,7 @@
#include "resource/DownloadResource.hpp"
#include "explore/Filters.hpp"
#include "explore/PlayQueueController.hpp"
#include "explore/ReleaseListHelpers.hpp"
#include "explore/ReleaseHelpers.hpp"
#include "explore/TrackListHelpers.hpp"
#include "LmsApplication.hpp"
#include "LmsApplicationException.hpp"
@@ -65,7 +65,12 @@ showReleaseInfoModal(Database::ReleaseId releaseId)
Wt::WWidget* releaseInfoPtr {releaseInfo.get()};
releaseInfo->addFunction("tr", &Wt::WTemplate::Functions::tr);
Wt::WContainerWidget* artistTable {releaseInfo->bindNew<Wt::WContainerWidget>("artist-table")};
if (auto primaryReleaseType {release->getPrimaryType()})
{
releaseInfo->setCondition("if-has-release-type", true);
releaseInfo->bindString("release-type", ReleaseHelpers::buildReleaseTypeString(*primaryReleaseType, release->getSecondaryTypes()));
}
std::map<Wt::WString, std::set<ArtistId>> artistMap;
auto addArtists = [&](TrackArtistLinkType linkType, const char* type)
@@ -116,13 +121,19 @@ showReleaseInfoModal(Database::ReleaseId releaseId)
artistMap.erase(itRolelessPerformers);
}
for (const auto& [role, artistIds] : artistMap)
if (!artistMap.empty())
{
std::unique_ptr<Wt::WContainerWidget> artistContainer {Utils::createArtistContainer(std::vector (std::cbegin(artistIds), std::cend(artistIds)))};
auto artistsEntry {std::make_unique<Template>(Wt::WString::tr("Lms.Explore.template.info.artists"))};
artistsEntry->bindString("type", role);
artistsEntry->bindWidget("artist-container", std::move(artistContainer));
artistTable->addWidget(std::move(artistsEntry));
releaseInfo->setCondition("if-has-artist", true);
Wt::WContainerWidget* artistTable {releaseInfo->bindNew<Wt::WContainerWidget>("artist-table")};
for (const auto& [role, artistIds] : artistMap)
{
std::unique_ptr<Wt::WContainerWidget> artistContainer {Utils::createArtistContainer(std::vector (std::cbegin(artistIds), std::cend(artistIds)))};
auto artistsEntry {std::make_unique<Template>(Wt::WString::tr("Lms.Explore.template.info.artists"))};
artistsEntry->bindString("type", role);
artistsEntry->bindWidget("artist-container", std::move(artistContainer));
artistTable->addWidget(std::move(artistsEntry));
}
}
// TODO: save in DB and mean all this
+1 -1
View File
@@ -28,7 +28,7 @@
#include "common/Template.hpp"
#include "explore/Filters.hpp"
#include "explore/PlayQueueController.hpp"
#include "explore/ReleaseListHelpers.hpp"
#include "explore/ReleaseHelpers.hpp"
#include "LmsApplication.hpp"
using namespace Database;
+1 -1
View File
@@ -28,7 +28,7 @@
#include "ArtistListHelpers.hpp"
#include "Filters.hpp"
#include "LmsApplication.hpp"
#include "ReleaseListHelpers.hpp"
#include "ReleaseHelpers.hpp"
#include "TrackListHelpers.hpp"
using namespace Database;
+12 -7
View File
@@ -60,7 +60,6 @@ namespace UserInterface::TrackListHelpers
Wt::WWidget* trackInfoPtr {trackInfo.get()};
trackInfo->addFunction("tr", &Wt::WTemplate::Functions::tr);
Wt::WContainerWidget* artistTable {trackInfo->bindNew<Wt::WContainerWidget>("artist-table")};
std::map<Wt::WString, std::set<ArtistId>> artistMap;
auto addArtists = [&](TrackArtistLinkType linkType, const char* type)
@@ -111,13 +110,19 @@ namespace UserInterface::TrackListHelpers
artistMap.erase(itRolelessPerformers);
}
for (const auto& [role, artistIds] : artistMap)
if (!artistMap.empty())
{
std::unique_ptr<Wt::WContainerWidget> artistContainer {Utils::createArtistContainer(std::vector (std::cbegin(artistIds), std::cend(artistIds)))};
auto artistsEntry {std::make_unique<Template>(Wt::WString::tr("Lms.Explore.template.info.artists"))};
artistsEntry->bindString("type", role);
artistsEntry->bindWidget("artist-container", std::move(artistContainer));
artistTable->addWidget(std::move(artistsEntry));
trackInfo->setCondition("if-has-artist", true);
Wt::WContainerWidget* artistTable {trackInfo->bindNew<Wt::WContainerWidget>("artist-table")};
for (const auto& [role, artistIds] : artistMap)
{
std::unique_ptr<Wt::WContainerWidget> artistContainer {Utils::createArtistContainer(std::vector (std::cbegin(artistIds), std::cend(artistIds)))};
auto artistsEntry {std::make_unique<Template>(Wt::WString::tr("Lms.Explore.template.info.artists"))};
artistsEntry->bindString("type", role);
artistsEntry->bindWidget("artist-container", std::move(artistContainer));
artistTable->addWidget(std::move(artistsEntry));
}
}
if (const auto audioFile {Av::parseAudioFile(track->getPath())})
+47
View File
@@ -44,6 +44,46 @@ operator<<(std::ostream& os, const MetaData::Artist& artist)
return os;
}
static
std::ostream&
operator<<(std::ostream& os, MetaData::Release::PrimaryType type)
{
switch (type)
{
case MetaData::Release::PrimaryType::Album: os << "Album"; break;
case MetaData::Release::PrimaryType::Single: os << "Single"; break;
case MetaData::Release::PrimaryType::EP: os << "EP"; break;
case MetaData::Release::PrimaryType::Broadcast: os << "Broadcast"; break;
case MetaData::Release::PrimaryType::Other: os << "Other"; break;
default:
os << "??";
}
return os;
}
static
std::ostream&
operator<<(std::ostream& os, MetaData::Release::SecondaryType type)
{
switch (type)
{
case MetaData::Release::SecondaryType::Compilation: os << "Compilation"; break;
case MetaData::Release::SecondaryType::Soundtrack: os << "Soundtrack"; break;
case MetaData::Release::SecondaryType::Spokenword: os << "Spokenword"; break;
case MetaData::Release::SecondaryType::Interview: os << "Interview"; break;
case MetaData::Release::SecondaryType::Audiobook: os << "Audiobook"; break;
case MetaData::Release::SecondaryType::AudioDrama: os << "Audio drama"; break;
case MetaData::Release::SecondaryType::Live: os << "Live"; break;
case MetaData::Release::SecondaryType::Remix: os << "Remix"; break;
case MetaData::Release::SecondaryType::DJMix: os << "DJ-mix"; break;
case MetaData::Release::SecondaryType::Mixtape_Street: os << "Mixtape/Street"; break;
case MetaData::Release::SecondaryType::Demo: os << "Mixtape/Demo"; break;
default:
os << "??";
}
return os;
}
static
std::ostream&
operator<<(std::ostream& os, const MetaData::Release& release)
@@ -59,6 +99,13 @@ operator<<(std::ostream& os, const MetaData::Release& release)
for (const MetaData::Artist& artist : release.artists)
std::cout << "\tRelease artist: " << artist << std::endl;
if (release.primaryType)
{
std::cout << "\tPrimary type: " << *release.primaryType << std::endl;
for (MetaData::Release::SecondaryType type : release.secondaryTypes)
std::cout << "\tSecondary type:" << type << std::endl;
}
return os;
}