From 2c2a83084335a8b39b4d8ca049712ead4d463578 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Mon, 25 Apr 2022 15:08:49 +0200 Subject: [PATCH] Reformatted ProjectM class code --- src/libprojectM/ProjectM.cpp | 77 ++++++++++-------------------- src/libprojectM/ProjectM.hpp | 90 ++++++++++++++++++------------------ 2 files changed, 69 insertions(+), 98 deletions(-) diff --git a/src/libprojectM/ProjectM.cpp b/src/libprojectM/ProjectM.cpp index 69b21f85e..f67de8409 100644 --- a/src/libprojectM/ProjectM.cpp +++ b/src/libprojectM/ProjectM.cpp @@ -23,7 +23,7 @@ #include "BeatDetect.hpp" #include "ConfigFile.h" -#include "PCM.hpp" //Sound data handler (buffering, FFT, etc.) +#include "PCM.hpp" //Sound data handler (buffering, FFT, etc.) #include "PipelineContext.hpp" #include "PipelineMerger.hpp" #include "Preset.hpp" @@ -77,7 +77,6 @@ ProjectM::ProjectM(const std::string& configurationFilename, Flags flags) ReadConfig(configurationFilename); Reset(); ResetOpenGL(m_settings.windowWidth, m_settings.windowHeight); - } ProjectM::ProjectM(const class Settings& settings, Flags flags) @@ -136,8 +135,7 @@ void ProjectM::ReadConfig(const std::string& configurationFilename) m_settings.fps = config.read("FPS", 35); m_settings.windowWidth = config.read("Window Width", 512); m_settings.windowHeight = config.read("Window Height", 512); - m_settings.softCutDuration = config.read - ("Smooth Preset Duration", config.read("Smooth Transition Duration", 10)); + m_settings.softCutDuration = config.read("Smooth Preset Duration", config.read("Smooth Transition Duration", 10)); m_settings.presetDuration = config.read("Preset Duration", 15); #ifdef __unix__ @@ -146,32 +144,26 @@ void ProjectM::ReadConfig(const std::string& configurationFilename) #ifdef __APPLE__ /// @bug awful hardcoded hack- need to add intelligence to cmake wrt bundling - carm - _settings.presetURL = config.read ( "Preset Path", "../Resources/presets" ); + _settings.presetURL = config.read("Preset Path", "../Resources/presets"); #endif #ifdef WIN32 - _settings.presetURL = config.read ( "Preset Path", "/usr/local/share/projectM/presets" ); + _settings.presetURL = config.read("Preset Path", "/usr/local/share/projectM/presets"); #endif #ifdef __APPLE__ - _settings.titleFontURL = config.read - ( "Title Font", "../Resources/fonts/Vera.tff"); - _settings.menuFontURL = config.read - ( "Menu Font", "../Resources/fonts/VeraMono.ttf"); + _settings.titleFontURL = config.read("Title Font", "../Resources/fonts/Vera.tff"); + _settings.menuFontURL = config.read("Menu Font", "../Resources/fonts/VeraMono.ttf"); #endif #ifdef __unix__ - m_settings.titleFontURL = config.read - ("Title Font", "/usr/local/share/projectM/fonts/Vera.tff"); - m_settings.menuFontURL = config.read - ("Menu Font", "/usr/local/share/projectM/fonts/VeraMono.tff"); + m_settings.titleFontURL = config.read("Title Font", "/usr/local/share/projectM/fonts/Vera.tff"); + m_settings.menuFontURL = config.read("Menu Font", "/usr/local/share/projectM/fonts/VeraMono.tff"); #endif #ifdef WIN32 - _settings.titleFontURL = config.read - ( "Title Font", projectM_FONT_TITLE ); - _settings.menuFontURL = config.read - ( "Menu Font", projectM_FONT_MENU ); + _settings.titleFontURL = config.read("Title Font", projectM_FONT_TITLE); + _settings.menuFontURL = config.read("Menu Font", projectM_FONT_MENU); #endif @@ -188,7 +180,7 @@ void ProjectM::ReadConfig(const std::string& configurationFilename) // Hard Cut sensitivity is the volume difference before a "hard cut" is triggered. m_settings.hardCutSensitivity = config.read("Hard Cut Sensitivity", 1.0); - // Beat Sensitivity impacts how reactive your visualizations are to volume, bass, mid-range, and treble. + // Beat Sensitivity impacts how reactive your visualizations are to volume, bass, mid-range, and treble. // Preset authors have developed their visualizations with the default of 1.0. m_settings.beatSensitivity = config.read("Beat Sensitivity", 1.0); @@ -206,8 +198,6 @@ void ProjectM::ReadConfig(const std::string& configurationFilename) m_settings.aspectCorrection = false; m_renderer->correction = false; } - - } @@ -372,7 +362,6 @@ auto ProjectM::RenderFrameOnlyPass1( return pipeline; - } else { @@ -389,15 +378,10 @@ auto ProjectM::RenderFrameOnlyPass1( m_activePreset->Render(*m_beatDetect, PipelineContext()); m_renderer->RenderFrameOnlyPass1(m_activePreset->pipeline(), PipelineContext()); return NULL; // indicating no transition - } // std::cout<< m_activePreset->absoluteFilePath()<presetName = m_activePreset->absoluteFilePath(); - - - - } @@ -414,7 +398,7 @@ void ProjectM::RenderFrameOnlyPass2(Pipeline* pipeline, #endif if (pipeline) -// if ( timeKeeper->IsSmoothing() && timeKeeper->SmoothRatio() <= 1.0 && !m_presetChooser->empty() ) + // if ( timeKeeper->IsSmoothing() && timeKeeper->SmoothRatio() <= 1.0 && !m_presetChooser->empty() ) { // printf("start thread\n"); assert(m_activePreset2.get()); @@ -423,17 +407,13 @@ void ProjectM::RenderFrameOnlyPass2(Pipeline* pipeline, /* was other stuff */ m_renderer->RenderFrameOnlyPass2(*pipeline, PipelineContext(), offsetX, offsetY, 0); - } else { m_renderer->RenderFrameOnlyPass2(m_activePreset->pipeline(), PipelineContext(), offsetX, offsetY, 0); - - } - } @@ -443,7 +423,7 @@ void ProjectM::RenderFrameEndOnSeparatePasses(Pipeline* pipeline) if (pipeline) { // mergePipelines() sets masterAlpha for each RenderItem, reset it before we forget - for (RenderItem* drawable: pipeline->drawables) + for (RenderItem* drawable : pipeline->drawables) { drawable->masterAlpha = 1.0; } @@ -464,7 +444,7 @@ void ProjectM::Initialize(int meshResolutionX, int meshResolutionY, int targetFp { /** Initialise start time */ m_timeKeeper = std::make_unique(m_settings.presetDuration, m_settings.softCutDuration, m_settings.hardCutDuration, - m_settings.easterEgg); + m_settings.easterEgg); /** Nullify frame stash */ @@ -491,7 +471,6 @@ void ProjectM::Initialize(int meshResolutionX, int meshResolutionY, int targetFp // ToDo: Calculate the real FPS instead PipelineContext().fps = targetFps; PipelineContext2().fps = targetFps; - } /* Reinitializes the engine variables to a default (conservative and sane) value */ @@ -503,7 +482,6 @@ void ProjectM::ResetEngine() m_beatDetect->Reset(); m_beatDetect->beatSensitivity = m_settings.beatSensitivity; } - } /** Resets OpenGL state */ @@ -575,9 +553,8 @@ auto ProjectM::InitializePresetTools(int meshResolutionX, int meshResolutionY) - *m_presetPos = m_presetChooser->end(); // Load idle preset -// std::cerr << "[projectM] Allocating idle preset..." << std::endl; - m_activePreset = m_presetLoader->loadPreset - ("idle://Geiss & Sperl - Feedback (projectM idle HDR mix).milk"); + // std::cerr << "[projectM] Allocating idle preset..." << std::endl; + m_activePreset = m_presetLoader->loadPreset("idle://Geiss & Sperl - Feedback (projectM idle HDR mix).milk"); m_renderer->setPresetName("Geiss & Sperl - Feedback (projectM idle HDR mix)"); PopulatePresetMenu(); @@ -643,18 +620,15 @@ void ProjectM::RemovePreset(unsigned int index) *m_presetPos = m_presetChooser->begin(chooserIndex); } - // Case: we have deleted the active preset position - // Set iterator to end of chooser + // 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 +auto ProjectM::AddPresetURL(const std::string& presetFilename, const std::string& presetName, const RatingList& ratingList) -> unsigned int { bool restorePosition = false; @@ -693,7 +667,7 @@ void ProjectM::SelectPreset(unsigned int index, bool hardCut) void ProjectM::PopulatePresetMenu() { if (m_renderer->showmenu) - { // only track a preset list buffer if the preset menu is up. + { // only track a preset list buffer if the preset menu is up. m_renderer->m_presetList.clear(); // clear preset list buffer from renderer. if (TextInputActive()) @@ -710,7 +684,7 @@ void ProjectM::PopulatePresetMenu() { h++; m_renderer->m_presetList.push_back( - { h, PresetName(i), "" }); // populate the renders preset list. + {h, PresetName(i), ""}); // populate the renders preset list. if (h == presetIndex) { m_renderer->m_activePresetID = h; @@ -749,7 +723,7 @@ void ProjectM::PopulatePresetMenu() while (page_start < page_end) { m_renderer->m_presetList.push_back( - { page_start, PresetName(page_start), "" }); // populate the renders preset list. + {page_start, PresetName(page_start), ""}); // populate the renders preset list. page_start++; } } @@ -809,7 +783,6 @@ void ProjectM::SelectRandom(const bool hardCut) m_presetHistory.erase(m_presetHistory.begin()); } m_presetFuture.clear(); - } void ProjectM::SelectPrevious(const bool hardCut) @@ -1047,7 +1020,7 @@ void ProjectM::InsertPresetURL(unsigned int index, const std::string& presetFile newSelectedIndex++; } - else // Case: inserting at selected preset + else // Case: inserting at selected preset { newSelectedIndex++; } @@ -1062,8 +1035,6 @@ void ProjectM::InsertPresetURL(unsigned int index, const std::string& presetFile { *m_presetPos = m_presetChooser->begin(newSelectedIndex); } - - } void ProjectM::ChangePresetName(unsigned int index, std::string presetName) @@ -1196,7 +1167,7 @@ void ProjectM::ToggleSearchText() // 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) + for (auto& it : m_renderer->m_presetList) { if (it.name == presetName) { diff --git a/src/libprojectM/ProjectM.hpp b/src/libprojectM/ProjectM.hpp index d2475505e..be336ae47 100644 --- a/src/libprojectM/ProjectM.hpp +++ b/src/libprojectM/ProjectM.hpp @@ -30,8 +30,8 @@ #pragma comment(lib, "psapi.lib") #pragma comment(lib, "kernel32.lib") -#pragma warning (disable:4244) -#pragma warning (disable:4305) +#pragma warning(disable : 4244) +#pragma warning(disable : 4305) #include #else @@ -46,9 +46,9 @@ #if USE_THREADS +#include "BackgroundWorker.h" #include #include -#include "BackgroundWorker.h" #endif @@ -97,33 +97,33 @@ public: */ enum Flags { - None = 0, //!< No special flags. + None = 0, //!< No special flags. DisablePlaylistLoad = 1 << 0 //!< Prevent automatic playlist loading on startup. }; class Settings { public: - size_t meshX{ 32 }; - size_t meshY{ 24 }; - size_t fps{ 35 }; - size_t textureSize{ 512 }; - size_t windowWidth{ 512 }; - size_t windowHeight{ 512 }; + size_t meshX{32}; + size_t meshY{24}; + size_t fps{35}; + size_t textureSize{512}; + size_t windowWidth{512}; + size_t windowHeight{512}; std::string presetURL; std::string titleFontURL; std::string menuFontURL; std::string datadir; - double presetDuration{ 15.0 }; - double softCutDuration{ 10.0 }; - double hardCutDuration{ 60.0 }; - bool hardCutEnabled{ false }; - float hardCutSensitivity{ 2.0 }; - float beatSensitivity{ 1.0 }; - bool aspectCorrection{ true }; - float easterEgg{ 0.0 }; - bool shuffleEnabled{ true }; - bool softCutRatingsEnabled{ false }; + double presetDuration{15.0}; + double softCutDuration{10.0}; + double hardCutDuration{60.0}; + bool hardCutEnabled{false}; + float hardCutSensitivity{2.0}; + float beatSensitivity{1.0}; + bool aspectCorrection{true}; + float easterEgg{0.0}; + bool shuffleEnabled{true}; + bool softCutRatingsEnabled{false}; }; explicit ProjectM(const std::string& configurationFilename, Flags flags = Flags::None); @@ -384,42 +384,42 @@ private: void RecreateRenderer(); - #if USE_THREADS +#if USE_THREADS - void ThreadWorker(); + void ThreadWorker(); - #endif +#endif - class Pcm m_pcm;//!< Audio data buffer and analyzer instance. + class Pcm m_pcm; //!< Audio data buffer and analyzer instance. - class Settings m_settings;//!< The projectM Settings. + class Settings m_settings; //!< The projectM Settings. - Flags m_flags{Flags::None};//!< Behaviour flags. + Flags m_flags{Flags::None}; //!< Behaviour flags. - std::vector m_presetHistory;//!< List of previously played preset indices. - std::vector m_presetFuture; //!< List of preset indices queued for playing. + std::vector m_presetHistory; //!< List of previously played preset indices. + std::vector m_presetFuture; //!< List of preset indices queued for playing. /** Timing information */ - int m_count{0};//!< Rendered frame count since start + int m_count{0}; //!< Rendered frame count since start - bool m_errorLoadingCurrentPreset{false};//!< Error flag for preset loading errors. + bool m_errorLoadingCurrentPreset{false}; //!< Error flag for preset loading errors. - std::unique_ptr m_renderer; //!< The Preset renderer. - std::unique_ptr m_beatDetect; //!< The beat detection class. - std::unique_ptr m_pipelineContext; //!< Pipeline context for the first/current preset. - std::unique_ptr m_pipelineContext2;//!< Pipeline context for the next/transitioning preset. - std::unique_ptr m_presetPos; //!< The current position of the directory iterator. - std::unique_ptr m_presetLoader; //!< Required by the preset chooser. Manages a loaded preset directory. - std::unique_ptr m_presetChooser; //!< Provides accessor functions to choose presets. - std::unique_ptr m_activePreset; //!< Currently loaded preset. - std::unique_ptr m_activePreset2; //!< Destination preset when smooth preset switching. - std::unique_ptr m_timeKeeper; //!< Keeps the different timers used to render and switch presets. - std::unique_ptr m_matcher; //!< Render item matcher for preset transitions. - std::unique_ptr m_merger; //!< Render item merger for preset transitions. + std::unique_ptr m_renderer; //!< The Preset renderer. + std::unique_ptr m_beatDetect; //!< The beat detection class. + std::unique_ptr m_pipelineContext; //!< Pipeline context for the first/current preset. + std::unique_ptr m_pipelineContext2; //!< Pipeline context for the next/transitioning preset. + std::unique_ptr m_presetPos; //!< The current position of the directory iterator. + std::unique_ptr m_presetLoader; //!< Required by the preset chooser. Manages a loaded preset directory. + std::unique_ptr m_presetChooser; //!< Provides accessor functions to choose presets. + std::unique_ptr m_activePreset; //!< Currently loaded preset. + std::unique_ptr m_activePreset2; //!< Destination preset when smooth preset switching. + std::unique_ptr m_timeKeeper; //!< Keeps the different timers used to render and switch presets. + std::unique_ptr m_matcher; //!< Render item matcher for preset transitions. + std::unique_ptr m_merger; //!< Render item merger for preset transitions. #if USE_THREADS - mutable std::recursive_mutex m_presetSwitchMutex;//!< Mutex for locking preset switching while rendering and vice versa. - std::thread m_workerThread; //!< Background worker for preloading presets. - BackgroundWorkerSync m_workerSync; //!< Background work synchronizer. + mutable std::recursive_mutex m_presetSwitchMutex; //!< Mutex for locking preset switching while rendering and vice versa. + std::thread m_workerThread; //!< Background worker for preloading presets. + BackgroundWorkerSync m_workerSync; //!< Background work synchronizer. #endif };