Deleted all playlist-related code from libprojectM.

Note: SDL test UI won't compile after this commit. Will be fixed in a later commit, when the playlist library is done.
This commit is contained in:
Kai Blaschke
2022-11-06 14:35:45 +01:00
parent 7363afecc2
commit b23b5ce25c
17 changed files with 341 additions and 2109 deletions

View File

@ -26,7 +26,6 @@
#include "PCM.hpp" //Sound data handler (buffering, FFT, etc.)
#include "PipelineMerger.hpp"
#include "Preset.hpp"
#include "PresetChooser.hpp"
#include "Renderer.hpp"
#include "TimeKeeper.hpp"
@ -55,16 +54,14 @@ void ProjectM::ResetTextures()
}
ProjectM::ProjectM(const std::string& configurationFilename, Flags flags)
: m_flags(flags)
ProjectM::ProjectM(const std::string& configurationFilename)
{
ReadConfig(configurationFilename);
Reset();
ResetOpenGL(m_settings.windowWidth, m_settings.windowHeight);
}
ProjectM::ProjectM(const class Settings& settings, Flags flags)
: m_flags(flags)
ProjectM::ProjectM(const class Settings& settings)
{
ReadSettings(settings);
Reset();
@ -85,12 +82,9 @@ auto ProjectM::WriteConfig(const std::string& configurationFilename, const class
config.add("Window Height", settings.windowHeight);
config.add("Smooth Preset Duration", settings.softCutDuration);
config.add("Preset Duration", settings.presetDuration);
config.add("Preset Path", settings.presetPath);
config.add("Hard Cut Sensitivity", settings.beatSensitivity);
config.add("Aspect Correction", settings.aspectCorrection);
config.add("Easter Egg Parameter", settings.easterEgg);
config.add("Shuffle Enabled", settings.shuffleEnabled);
config.add("Soft Cut Ratings Enabled", settings.softCutRatingsEnabled);
std::fstream file(configurationFilename.c_str(), std::ios_base::trunc | std::ios_base::out);
if (file)
{
@ -117,25 +111,7 @@ void ProjectM::ReadConfig(const std::string& configurationFilename)
m_settings.windowHeight = config.read<int>("Window Height", 512);
m_settings.softCutDuration = config.read<double>("Smooth Preset Duration", config.read<int>("Smooth Transition Duration", 10));
m_settings.presetDuration = config.read<double>("Preset Duration", 15);
#ifdef __unix__
m_settings.presetPath = config.read<string>("Preset Path", "/usr/local/share/projectM/presets");
#endif
#ifdef __APPLE__
/// @bug awful hardcoded hack- need to add intelligence to cmake wrt bundling - carm
m_settings.presetPath = config.read<string>("Preset Path", "../Resources/presets");
#endif
#ifdef _WIN32
m_settings.presetPath = config.read<string>("Preset Path", "/usr/local/share/projectM/presets");
#endif
m_settings.shuffleEnabled = config.read<bool>("Shuffle Enabled", true);
m_settings.easterEgg = config.read<float>("Easter Egg Parameter", 0.0);
m_settings.softCutRatingsEnabled =
config.read<bool>("Soft Cut Ratings Enabled", false);
// Hard Cuts are preset transitions that occur when your music becomes louder. They only occur after a hard cut duration threshold has passed.
m_settings.hardCutEnabled = config.read<bool>("Hard Cuts Enabled", false);
@ -164,11 +140,8 @@ void ProjectM::ReadSettings(const class Settings& settings)
m_settings.windowHeight = settings.windowHeight;
m_settings.softCutDuration = settings.softCutDuration;
m_settings.presetDuration = settings.presetDuration;
m_settings.softCutRatingsEnabled = settings.softCutRatingsEnabled;
m_settings.presetPath = settings.presetPath;
m_settings.texturePath = settings.texturePath;
m_settings.shuffleEnabled = settings.shuffleEnabled;
m_settings.dataPath = settings.dataPath;
m_settings.easterEgg = settings.easterEgg;
@ -248,41 +221,24 @@ auto ProjectM::RenderFrameOnlyPass1(Pipeline* pipeline) -> Pipeline*
m_beatDetect->CalculateBeatStatistics();
//if the preset isn't locked and there are more presets
if (!m_renderer->noSwitch && !m_presetChooser->empty())
if (!m_renderer->noSwitch)
{
//if preset is done and we're not already switching
if (m_timeKeeper->PresetProgressA() >= 1.0 && !m_timeKeeper->IsSmoothing())
{
if (Settings().shuffleEnabled)
{
SelectRandom(false);
}
else
{
SelectNext(false);
}
// Call preset change callback
}
else if (Settings().hardCutEnabled &&
(m_beatDetect->vol - m_beatDetect->volOld > Settings().hardCutSensitivity) &&
m_timeKeeper->CanHardCut())
{
// Hard Cuts must be enabled, must have passed the hardcut duration, and the volume must be a greater difference than the hardcut sensitivity.
if (Settings().shuffleEnabled)
{
SelectRandom(true);
}
else
{
SelectNext(true);
}
// Call preset change callback
}
}
if (m_timeKeeper->IsSmoothing() && m_timeKeeper->SmoothRatio() <= 1.0 && !m_presetChooser->empty())
if (m_timeKeeper->IsSmoothing() && m_timeKeeper->SmoothRatio() <= 1.0 && m_activePreset2 != nullptr)
{
assert(m_activePreset2.get());
#if USE_THREADS
m_workerSync.WakeUpBackgroundTask();
#endif
@ -384,10 +340,6 @@ void ProjectM::Initialize()
m_beatDetect = std::make_unique<BeatDetect>(m_pcm);
// Create texture search path list
if (!m_settings.presetPath.empty())
{
m_textureSearchPaths.emplace_back(m_settings.presetPath);
}
if (!m_settings.texturePath.empty())
{
m_textureSearchPaths.emplace_back(m_settings.texturePath);
@ -412,8 +364,6 @@ void ProjectM::Initialize()
m_workerThread = std::thread(&ProjectM::ThreadWorker, this);
#endif
/// @bug order of operatoins here is busted
//renderer->setPresetName ( m_activePreset->name() );
m_timeKeeper->StartPreset();
// ToDo: Calculate the real FPS instead
@ -446,96 +396,18 @@ auto ProjectM::InitializePresetTools() -> void
/* Set the seed to the current time in seconds */
srand(time(nullptr));
std::string url;
if ((m_flags & Flags::DisablePlaylistLoad) != Flags::DisablePlaylistLoad)
{
url = Settings().presetPath;
}
m_presetLoader = std::make_unique<PresetLoader>(m_settings.meshX, m_settings.meshY, url);
m_presetChooser = std::make_unique<PresetChooser>(*m_presetLoader, Settings().softCutRatingsEnabled);
m_presetPos = std::make_unique<PresetIterator>();
// Start at end ptr- this allows next/previous to easily be done from this position.
*m_presetPos = m_presetChooser->end();
// Load idle preset
m_activePreset = m_presetLoader->loadPreset("idle://Geiss & Sperl - Feedback (projectM idle HDR mix).milk");
m_renderer->setPresetName("Geiss & Sperl - Feedback (projectM idle HDR mix)");
m_renderer->SetPipeline(m_activePreset->pipeline());
ResetEngine();
}
/// @bug queuePreset case isn't handled
void ProjectM::RemovePreset(unsigned int index)
{
size_t chooserIndex = **m_presetPos;
m_presetLoader->removePreset(index);
// Case: no more presets, set iterator to end
if (m_presetChooser->empty())
{
*m_presetPos = m_presetChooser->end();
// Case: chooser index has become one less due to removal of an index below it
}
else if (chooserIndex > index)
{
chooserIndex--;
*m_presetPos = m_presetChooser->begin(chooserIndex);
}
// Case: we have deleted the active preset position
// Set iterator to end of chooser
else if (chooserIndex == index)
{
*m_presetPos = m_presetChooser->end();
}
}
auto ProjectM::AddPresetURL(const std::string& presetFilename, const std::string& presetName, const RatingList& ratingList) -> unsigned int
{
bool restorePosition = false;
if (*m_presetPos == m_presetChooser->end())
{
restorePosition = true;
}
int index = m_presetLoader->addPresetURL(presetFilename, presetName, ratingList);
if (restorePosition)
{
*m_presetPos = m_presetChooser->end();
}
return index;
}
void ProjectM::SelectPreset(unsigned int index, bool hardCut)
{
if (m_presetChooser->empty())
{
return;
}
*m_presetPos = m_presetChooser->begin(index);
if (!StartPresetTransition(hardCut))
{
SelectRandom(hardCut);
}
}
bool ProjectM::StartPresetTransition(bool hardCut)
{
std::unique_ptr<Preset> new_preset = SwitchToCurrentPreset();
if (new_preset == nullptr)
{
PresetSwitchFailedEvent(hardCut, **m_presetPos, "fake error");
PresetSwitchFailedEvent(hardCut, "", "No preset available to switch to");
m_errorLoadingCurrentPreset = true;
return false;
@ -553,36 +425,11 @@ bool ProjectM::StartPresetTransition(bool hardCut)
m_timeKeeper->StartSmoothing();
}
PresetSwitchedEvent(hardCut, **m_presetPos);
m_errorLoadingCurrentPreset = false;
return true;
}
void ProjectM::SelectRandom(const bool hardCut)
{
if (m_presetChooser->empty())
{
return;
}
m_presetHistory.push_back(m_presetPos->lastIndex());
for (int i = 0; i < kMaxSwitchRetries; ++i)
{
*m_presetPos = m_presetChooser->weightedRandom(hardCut);
if (StartPresetTransition(hardCut))
{
break;
}
}
// If presetHistory is tracking more than 10, then delete the oldest entry so we cap to a history of 10.
if (m_presetHistory.size() >= 10)
{
m_presetHistory.erase(m_presetHistory.begin());
}
m_presetFuture.clear();
}
auto ProjectM::WindowWidth() -> int
{
return m_settings.windowWidth;
@ -598,60 +445,6 @@ auto ProjectM::ErrorLoadingCurrentPreset() const -> bool
return m_errorLoadingCurrentPreset;
}
void ProjectM::SelectPrevious(const bool hardCut)
{
if (m_presetChooser->empty())
{
return;
}
if (Settings().shuffleEnabled && m_presetHistory.size() >= 1 &&
static_cast<std::size_t>(m_presetHistory.back()) != m_presetLoader->size())
{ // if randomly browsing presets, "previous" should return to last random preset not the index--. Avoid returning to size() because that's the idle:// preset.
m_presetFuture.push_back(m_presetPos->lastIndex());
SelectPreset(m_presetHistory.back());
m_presetHistory.pop_back();
}
else
{
// if we are not shuffling or there is no random future history, then let's not track a random vector and move backwards in the preset index.
m_presetHistory.clear();
m_presetFuture.clear();
m_presetChooser->previousPreset(*m_presetPos);
if (!StartPresetTransition(hardCut))
{
SelectRandom(hardCut);
}
}
}
void ProjectM::SelectNext(const bool hardCut)
{
if (m_presetChooser->empty())
{
return;
}
if (Settings().shuffleEnabled && m_presetFuture.size() >= 1 &&
static_cast<std::size_t>(m_presetFuture.front()) != m_presetLoader->size())
{ // if shuffling and we have future presets already stashed then let's go forward rather than truely move randomly.
m_presetHistory.push_back(m_presetPos->lastIndex());
SelectPreset(m_presetFuture.back());
m_presetFuture.pop_back();
}
else
{
// if we are not shuffling or there is no random history, then let's not track a random vector and move forwards in the preset index.
m_presetFuture.clear();
m_presetHistory.clear();
m_presetChooser->nextPreset(*m_presetPos);
if (!StartPresetTransition(hardCut))
{
SelectRandom(hardCut);
}
}
}
/**
* Switches the pipeline and renderer to the current preset.
* @return the resulting Preset object, or nullptr on failure.
@ -663,23 +456,14 @@ auto ProjectM::SwitchToCurrentPreset() -> std::unique_ptr<Preset>
std::lock_guard<std::recursive_mutex> guard(m_presetSwitchMutex);
#endif
try
{
new_preset = m_presetPos->allocate();
}
catch (const PresetFactoryException& e)
{
std::cerr << "problem allocating target preset: " << e.message()
<< std::endl;
}
// ToDo: Load preset by filename here
if (new_preset == nullptr)
{
std::cerr << "Could not switch to current preset" << std::endl;
return nullptr;
}
// Set preset name here- event is not done because at the moment this function
// Set preset name here - event is not done because at the moment this function
// is oblivious to smooth/hard switches
m_renderer->setPresetName(new_preset->name());
std::string result = m_renderer->SetPipeline(new_preset->pipeline());
@ -693,6 +477,8 @@ auto ProjectM::SwitchToCurrentPreset() -> std::unique_ptr<Preset>
void ProjectM::SetPresetLocked(bool locked)
{
// ToDo: Add a preset switch timer separate from the display timer and reset to 0 when
// disabling the preset switch lock.
m_renderer->noSwitch = locked;
}
@ -701,123 +487,7 @@ auto ProjectM::PresetLocked() const -> bool
return m_renderer->noSwitch;
}
auto ProjectM::PresetURL(unsigned int index) const -> std::string
{
return m_presetLoader->getPresetURL(index);
}
auto ProjectM::PresetRating(unsigned int index, const PresetRatingType ratingType) const -> int
{
return m_presetLoader->getPresetRating(index, ratingType);
}
auto ProjectM::PresetName(unsigned int index) const -> std::string
{
return m_presetLoader->getPresetName(index);
}
void ProjectM::ClearPlaylist()
{
m_presetLoader->clear();
*m_presetPos = m_presetChooser->end();
}
void ProjectM::SelectPresetPosition(unsigned int index)
{
*m_presetPos = m_presetChooser->begin(index);
}
auto ProjectM::SelectedPresetIndex(unsigned int& index) const -> bool
{
if (*m_presetPos == m_presetChooser->end())
{
return false;
}
index = **m_presetPos;
return true;
}
auto ProjectM::PresetPositionValid() const -> bool
{
return (*m_presetPos != m_presetChooser->end());
}
auto ProjectM::PlaylistSize() const -> unsigned int
{
return m_presetLoader->size();
}
void ProjectM::SetShuffleEnabled(bool value)
{
m_settings.shuffleEnabled = value;
}
auto ProjectM::ShuffleEnabled() const -> bool
{
return m_settings.shuffleEnabled;
}
void ProjectM::PresetSwitchedEvent(bool, size_t) const {}
void ProjectM::ShuffleEnabledValueChanged(bool) const {}
void ProjectM::PresetSwitchFailedEvent(bool, unsigned int, const std::string&) const {}
void ProjectM::PresetRatingChanged(unsigned int, int, PresetRatingType) const {}
void ProjectM::ChangePresetRating(unsigned int index, int rating, const PresetRatingType ratingType)
{
m_presetLoader->setRating(index, rating, ratingType);
PresetRatingChanged(index, rating, ratingType);
}
void ProjectM::InsertPresetURL(unsigned int index, const std::string& presetFilename, const std::string& presetName,
const RatingList& ratingList)
{
bool atEndPosition = false;
int newSelectedIndex = 0;
if (*m_presetPos == m_presetChooser->end()) // Case: preset not selected
{
atEndPosition = true;
}
else if (**m_presetPos < index) // Case: inserting before selected preset
{
newSelectedIndex = **m_presetPos;
}
else if (**m_presetPos > index) // Case: inserting after selected preset
{
newSelectedIndex++;
}
else // Case: inserting at selected preset
{
newSelectedIndex++;
}
m_presetLoader->insertPresetURL(index, presetFilename, presetName, ratingList);
if (atEndPosition)
{
*m_presetPos = m_presetChooser->end();
}
else
{
*m_presetPos = m_presetChooser->begin(newSelectedIndex);
}
}
void ProjectM::ChangePresetName(unsigned int index, std::string presetName)
{
m_presetLoader->setPresetName(index, presetName);
}
void ProjectM::PresetSwitchFailedEvent(bool, const std::string&, const std::string&) const {}
void ProjectM::SetTextureSize(size_t size)
{
@ -846,12 +516,6 @@ auto ProjectM::SoftCutDuration() const -> double
return m_settings.softCutDuration;
}
void ProjectM::SetSoftCutDuration(int seconds)
{
m_settings.softCutDuration = static_cast<double>(seconds);
m_timeKeeper->ChangeSoftCutDuration(seconds);
}
void ProjectM::SetSoftCutDuration(double seconds)
{
m_settings.softCutDuration = seconds;
@ -863,12 +527,6 @@ auto ProjectM::HardCutDuration() const -> double
return m_settings.hardCutDuration;
}
void ProjectM::SetHardCutDuration(int seconds)
{
m_settings.hardCutDuration = seconds;
m_timeKeeper->ChangeHardCutDuration(seconds);
}
void ProjectM::SetHardCutDuration(double seconds)
{
m_settings.hardCutDuration = static_cast<int>(seconds);
@ -895,7 +553,7 @@ void ProjectM::SetHardCutSensitivity(float sensitivity)
m_settings.hardCutSensitivity = sensitivity;
}
void ProjectM::SetPresetDuration(int seconds)
void ProjectM::SetPresetDuration(double seconds)
{
m_timeKeeper->ChangePresetDuration(seconds);
}
@ -905,11 +563,6 @@ auto ProjectM::PresetDuration() const -> double
return m_timeKeeper->PresetDuration();
}
void ProjectM::SetPresetDuration(double seconds)
{
m_timeKeeper->ChangePresetDuration(seconds);
}
auto ProjectM::FramesPerSecond() const -> int32_t
{
return m_settings.fps;
@ -964,40 +617,6 @@ auto ProjectM::Pcm() -> class Pcm&
return m_pcm;
}
// get index from search results based on preset name
auto ProjectM::SearchIndex(const std::string& presetName) const -> unsigned int
{
for (auto& it : m_renderer->m_presetList)
{
if (it.name == presetName)
{
return it.id;
}
}
return 0;
}
// get preset index based on preset name
auto ProjectM::PresetIndex(const std::string& presetFilename) const -> unsigned int
{
return m_presetLoader->getPresetIndex(presetFilename);
}
// load preset based on name
void ProjectM::SelectPresetByName(std::string presetName, bool hardCut)
{
if (presetName == "")
{
return;
}
unsigned int index = PresetIndex(presetName);
if (m_presetChooser->empty())
{
return;
}
SelectPreset(index);
}
auto ProjectM::Settings() const -> const class ProjectM::Settings&
{
return m_settings;