Render random transitions.

The TimeKeeper-based "smoothing" code still needs to be cleaned up, same with the threading stuff which never really worked.
This commit is contained in:
Kai Blaschke
2023-11-01 23:16:30 +01:00
parent 1ba6b1a25f
commit c9b0ce0c2c
2 changed files with 51 additions and 12 deletions

View File

@ -23,10 +23,15 @@
#include "Preset.hpp"
#include "PresetFactoryManager.hpp"
#include "TextureManager.hpp"
#include "TimeKeeper.hpp"
#include "libprojectM/Audio/BeatDetect.hpp"
#include "libprojectM/Audio/PCM.hpp" //Sound data handler (buffering, FFT, etc.)
#include "Audio/BeatDetect.hpp"
#include "Audio/PCM.hpp" //Sound data handler (buffering, FFT, etc.)
#include "Renderer/PresetTransition.hpp"
#include "Renderer/TextureManager.hpp"
#include "Renderer/TransitionShaderManager.hpp"
#if PROJECTM_USE_THREADS
@ -175,7 +180,6 @@ void ProjectM::RenderFrame()
m_activePreset->Initialize(GetRenderContext());
}
// ToDo: Encapsulate preset loading check and transition in Renderer?
if (m_timeKeeper->IsSmoothing() && m_transitioningPreset != nullptr)
{
#if PROJECTM_USE_THREADS
@ -192,8 +196,32 @@ void ProjectM::RenderFrame()
}
}
auto renderContext = GetRenderContext();
auto audioData = m_beatDetect->GetFrameAudioData();
if (m_transition != nullptr && m_transitioningPreset != nullptr)
{
if (m_transition->IsDone())
{
m_activePreset = std::move(m_transitioningPreset);
m_transitioningPreset.reset();
m_transition.reset();
}
else
{
m_transitioningPreset->RenderFrame(audioData, renderContext);
}
}
// ToDo: Call the to-be-implemented render method in Renderer
m_activePreset->RenderFrame(m_beatDetect->GetFrameAudioData(), GetRenderContext());
m_activePreset->RenderFrame(audioData, renderContext);
if (m_transition != nullptr && m_transitioningPreset != nullptr)
{
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
m_transition->Draw(*m_activePreset, *m_transitioningPreset, renderContext, audioData);
}
m_frameCount++;
}
@ -216,6 +244,8 @@ void ProjectM::Initialize()
m_textureManager = std::make_unique<TextureManager>(m_textureSearchPaths);
m_transitionShaderManager = std::make_unique<TransitionShaderManager>();
m_presetFactoryManager->initialize();
/* Set the seed to the current time in seconds */
@ -278,6 +308,8 @@ void ProjectM::StartPresetTransition(std::unique_ptr<Preset>&& preset, bool hard
// ToDo: Continue only if preset is fully loaded.
m_transition.reset();
if (hardCut)
{
m_activePreset = std::move(preset);
@ -287,6 +319,7 @@ void ProjectM::StartPresetTransition(std::unique_ptr<Preset>&& preset, bool hard
{
m_transitioningPreset = std::move(preset);
m_timeKeeper->StartSmoothing();
m_transition = std::make_unique<PresetTransition>(m_transitionShaderManager->RandomTransition(), m_softCutDuration);
}
}

View File

@ -59,8 +59,12 @@ class Renderer;
class TextureManager;
class TransitionShaderManager;
class Preset;
class PresetTransition;
class TimeKeeper;
class PresetFactoryManager;
@ -225,8 +229,8 @@ private:
size_t m_meshX{32}; //!< Per-point mesh horizontal resolution.
size_t m_meshY{24}; //!< Per-point mesh vertical resolution.
size_t m_targetFps{35}; //!< Target frames per second.
int m_windowWidth{0}; //!< EvaluateFrameData window width. If 0, nothing is rendered.
int m_windowHeight{0}; //!< EvaluateFrameData window height. If 0, nothing is rendered.
int m_windowWidth{0}; //!< EvaluateFrameData window width. If 0, nothing is rendered.
int m_windowHeight{0}; //!< EvaluateFrameData window height. If 0, nothing is rendered.
double m_presetDuration{30.0}; //!< Preset duration in seconds.
double m_softCutDuration{3.0}; //!< Soft cut transition time.
double m_hardCutDuration{20.0}; //!< Time after which a hard cut can happen at the earliest.
@ -246,11 +250,13 @@ private:
std::unique_ptr<PresetFactoryManager> m_presetFactoryManager; //!< Provides access to all available preset factories.
std::unique_ptr<TextureManager> m_textureManager; //!< The texture manager.
std::unique_ptr<libprojectM::Audio::BeatDetect> m_beatDetect; //!< The beat detection class.
std::unique_ptr<Preset> m_activePreset; //!< Currently loaded preset.
std::unique_ptr<Preset> m_transitioningPreset; //!< Destination preset when smooth preset switching.
std::unique_ptr<TimeKeeper> m_timeKeeper; //!< Keeps the different timers used to render and switch presets.
std::unique_ptr<TextureManager> m_textureManager; //!< The texture manager.
std::unique_ptr<TransitionShaderManager> m_transitionShaderManager; //!< The transition shader manager.
std::unique_ptr<libprojectM::Audio::BeatDetect> m_beatDetect; //!< The beat detection class.
std::unique_ptr<Preset> m_activePreset; //!< Currently loaded preset.
std::unique_ptr<Preset> m_transitioningPreset; //!< Destination preset when smooth preset switching.
std::unique_ptr<PresetTransition> m_transition; //!< Transition effect used for blending.
std::unique_ptr<TimeKeeper> m_timeKeeper; //!< Keeps the different timers used to render and switch presets.
#if PROJECTM_USE_THREADS
mutable std::recursive_mutex m_presetSwitchMutex; //!< Mutex for locking preset switching while rendering and vice versa.