/*
* 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 .
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "core/IConfig.hpp"
#include "core/Random.hpp"
#include "core/Service.hpp"
#include "core/StreamLogger.hpp"
#include "database/Artist.hpp"
#include "database/Cluster.hpp"
#include "database/Db.hpp"
#include "database/MediaLibrary.hpp"
#include "database/Release.hpp"
#include "database/Session.hpp"
#include "database/Track.hpp"
#include "database/TrackArtistLink.hpp"
namespace lms
{
struct GeneratorParameters
{
std::size_t mediaLibraryCount{ 1 };
std::size_t releaseCountPerBatch{ 1000 };
std::size_t releaseCount{ 100 };
std::size_t trackCountPerRelease{ 10 };
float compilationRatio{ 0.1 };
std::size_t genreCountPerTrack{ 3 };
std::size_t moodCountPerTrack{ 3 };
std::size_t genreCount{ 50 };
std::size_t moodCount{ 25 };
std::filesystem::path trackPath;
};
struct GenerationContext
{
db::Session& session;
std::vector mediaLibraries;
std::vector genres;
std::vector moods;
GenerationContext(db::Session& _session)
: session{ _session } {}
};
db::Cluster::pointer generateCluster(db::Session& session, db::ClusterType::pointer clusterType)
{
const std::string clusterName{ std::string{ clusterType->getName() } + "-" + std::string{ core::UUID::generate().getAsString() } };
return session.create(clusterType, clusterName);
}
db::Artist::pointer generateArtist(db::Session& session)
{
const core::UUID artistMBID{ core::UUID::generate() };
const std::string artistName{ "Artist-" + std::string{ core::UUID::generate().getAsString() } };
return session.create(artistName, artistMBID);
}
void generateRelease(const GeneratorParameters& params, GenerationContext& context)
{
using namespace db;
const core::UUID releaseMBID{ core::UUID::generate() };
const std::string releaseName{ "Release-" + std::string{ core::UUID::generate().getAsString() } };
Release::pointer release{ context.session.create(releaseName, releaseMBID) };
Artist::pointer artist{ generateArtist(context.session) };
MediaLibrary::pointer mediaLibrary;
if (!context.mediaLibraries.empty())
mediaLibrary = *core::random::pickRandom(context.mediaLibraries);
for (std::size_t i{}; i < params.trackCountPerRelease; ++i)
{
Track::pointer track{ context.session.create