diff --git a/src/libprojectM/BackgroundWorker.h b/src/libprojectM/BackgroundWorker.hpp similarity index 100% rename from src/libprojectM/BackgroundWorker.h rename to src/libprojectM/BackgroundWorker.hpp diff --git a/src/libprojectM/CMakeLists.txt b/src/libprojectM/CMakeLists.txt index cc02082de..af2174772 100644 --- a/src/libprojectM/CMakeLists.txt +++ b/src/libprojectM/CMakeLists.txt @@ -140,9 +140,8 @@ set_target_properties(projectM PROPERTIES ) if(BUILD_SHARED_LIBS) - target_compile_definitions(projectM - PRIVATE - projectM_api_EXPORTS + set_source_files_properties(ProjectMCWrapper.cpp PROPERTIES + COMPILE_DEFINITIONS projectM_api_EXPORTS ) target_link_libraries(projectM @@ -150,9 +149,8 @@ if(BUILD_SHARED_LIBS) ${CMAKE_DL_LIBS} ) else() - target_compile_definitions(projectM - PUBLIC - PROJECTM_STATIC_DEFINE + set_source_files_properties(ProjectMCWrapper.cpp PROPERTIES + COMPILE_DEFINITIONS PROJECTM_STATIC_DEFINE ) set_target_properties(projectM PROPERTIES @@ -172,14 +170,23 @@ install(TARGETS projectM ) if(ENABLE_CXX_INTERFACE) + set_source_files_properties(ProjectM.cpp PCM.cpp PROPERTIES + COMPILE_DEFINITIONS projectM_api_EXPORTS + ) + install(FILES Common.hpp PCM.hpp - fatal.h ProjectM.hpp DESTINATION "${PROJECTM_INCLUDE_DIR}/libprojectM" COMPONENT Devel ) +else() + # Set PROJECTM_STATIC_EXPORT for C++ implementations to use project default visibility + # and no dllimport/dllexport. + set_source_files_properties(ProjectM.cpp PCM.cpp PROPERTIES + COMPILE_DEFINITIONS PROJECTM_STATIC_DEFINE + ) endif() diff --git a/src/libprojectM/Common.hpp b/src/libprojectM/Common.hpp index dfe8ae786..2c539f2e9 100755 --- a/src/libprojectM/Common.hpp +++ b/src/libprojectM/Common.hpp @@ -18,14 +18,8 @@ * See 'LICENSE.txt' included within this release * */ -/** - * $Id$ - * - * $Log$ - */ -#ifndef COMMON_HPP -#define COMMON_HPP +#pragma once #include #include @@ -93,5 +87,3 @@ inline auto ParseFilename(const std::string& filename) -> std::string return filename.substr(start + 1, filename.length()); } - -#endif diff --git a/src/libprojectM/MilkdropPresetFactory/CMakeLists.txt b/src/libprojectM/MilkdropPresetFactory/CMakeLists.txt index f1031a84d..e0ed06e3b 100644 --- a/src/libprojectM/MilkdropPresetFactory/CMakeLists.txt +++ b/src/libprojectM/MilkdropPresetFactory/CMakeLists.txt @@ -47,6 +47,8 @@ target_include_directories(MilkdropPresetFactory ) target_link_libraries(MilkdropPresetFactory + PRIVATE + libprojectM::API # For export header PUBLIC GLM::GLM ${PROJECTM_OPENGL_LIBRARIES} diff --git a/src/libprojectM/PCM.hpp b/src/libprojectM/PCM.hpp index ba8a5e540..dd7191f0b 100755 --- a/src/libprojectM/PCM.hpp +++ b/src/libprojectM/PCM.hpp @@ -26,8 +26,9 @@ * $Log$ */ -#ifndef _PCM_H -#define _PCM_H +#pragma once + +#include "libprojectM/projectM_export.h" #include #include @@ -46,7 +47,7 @@ enum CHANNEL CHANNEL_1 = 1 }; -class Pcm +PROJECTM_EXPORT class Pcm { public: /* maximum number of sound samples that are actually stored. */ @@ -155,5 +156,3 @@ private: double m_level{1.f}; AutoLevel m_leveler{}; }; - -#endif /** !_PCM_H */ diff --git a/src/libprojectM/ProjectM.cpp b/src/libprojectM/ProjectM.cpp index 75bdc69b0..0d66db825 100644 --- a/src/libprojectM/ProjectM.cpp +++ b/src/libprojectM/ProjectM.cpp @@ -30,10 +30,19 @@ #include "Renderer/PipelineContext.hpp" #include "TimeKeeper.hpp" +#if USE_THREADS + +#include "libprojectM/BackgroundWorker.hpp" + +#endif ProjectM::ProjectM() - : m_pipelineContext(std::make_unique()) + : m_presetFactoryManager(std::make_unique()) + , m_pipelineContext(std::make_unique()) , m_pipelineContext2(std::make_unique()) +#if USE_THREADS + , m_workerSync(std::make_unique()) +#endif { Initialize(); } @@ -41,7 +50,7 @@ ProjectM::ProjectM() ProjectM::~ProjectM() { #if USE_THREADS - m_workerSync.FinishUp(); + m_workerSync->FinishUp(); m_workerThread.join(); #endif } @@ -64,7 +73,7 @@ void ProjectM::LoadPresetFile(const std::string& presetFilename, bool smoothTran try { - StartPresetTransition(m_presetFactoryManager.CreatePresetFromFile(presetFilename), !smoothTransition); + StartPresetTransition(m_presetFactoryManager->CreatePresetFromFile(presetFilename), !smoothTransition); } catch (const PresetFactoryException& ex) { @@ -82,7 +91,7 @@ void ProjectM::LoadPresetData(std::istream& presetData, bool smoothTransition) try { - StartPresetTransition(m_presetFactoryManager.CreatePresetFromStream(".milk", presetData), !smoothTransition); + StartPresetTransition(m_presetFactoryManager->CreatePresetFromStream(".milk", presetData), !smoothTransition); } catch (const PresetFactoryException& ex) { @@ -117,12 +126,12 @@ void ProjectM::ThreadWorker() { while (true) { - if (!m_workerSync.WaitForWork()) + if (!m_workerSync->WaitForWork()) { return; } EvaluateSecondPreset(); - m_workerSync.FinishedWork(); + m_workerSync->FinishedWork(); } } @@ -194,9 +203,9 @@ auto ProjectM::RenderFrameOnlyPass1(Pipeline* pipeline) -> Pipeline* if (m_timeKeeper->IsSmoothing() && m_transitioningPreset != nullptr) { #if USE_THREADS - m_workerSync.WakeUpBackgroundTask(); + m_workerSync->WakeUpBackgroundTask(); // FIXME: Instead of waiting after a single render pass, check every frame if it's done. - m_workerSync.WaitForBackgroundTaskToFinish(); + m_workerSync->WaitForBackgroundTaskToFinish(); #endif EvaluateSecondPreset(); @@ -265,7 +274,7 @@ void ProjectM::Reset() { this->m_count = 0; - m_presetFactoryManager.initialize(m_meshX, m_meshY); + m_presetFactoryManager->initialize(m_meshX, m_meshY); ResetEngine(); } @@ -293,7 +302,7 @@ void ProjectM::Initialize() m_beatDetect.get(), m_textureSearchPaths); - m_presetFactoryManager.initialize(m_meshX, m_meshY); + m_presetFactoryManager->initialize(m_meshX, m_meshY); /* Set the seed to the current time in seconds */ srand(time(nullptr)); @@ -302,7 +311,7 @@ void ProjectM::Initialize() LoadIdlePreset(); #if USE_THREADS - m_workerSync.Reset(); + m_workerSync->Reset(); m_workerThread = std::thread(&ProjectM::ThreadWorker, this); #endif @@ -523,7 +532,7 @@ void ProjectM::SetMeshSize(size_t meshResolutionX, size_t meshResolutionY) // Update mesh size in all sorts of classes. m_renderer->SetPerPixelMeshSize(m_meshX, m_meshY); - m_presetFactoryManager.initialize(m_meshX, m_meshY); + m_presetFactoryManager->initialize(m_meshX, m_meshY); // Unload all presets and reload idle preset m_activePreset.reset(); diff --git a/src/libprojectM/ProjectM.hpp b/src/libprojectM/ProjectM.hpp index 7cf236ed4..b2e6d719f 100644 --- a/src/libprojectM/ProjectM.hpp +++ b/src/libprojectM/ProjectM.hpp @@ -20,10 +20,10 @@ */ #pragma once -#include "Common.hpp" -#include "PCM.hpp" -#include "PresetFactoryManager.hpp" -#include "fatal.h" +#include "libprojectM/projectM_export.h" + +#include "libprojectM/Common.hpp" +#include "libprojectM/PCM.hpp" #ifdef _WIN32 @@ -41,13 +41,13 @@ #if USE_THREADS -#include "BackgroundWorker.h" - #include #include #endif +class BackgroundWorkerSync; + class BeatDetect; class Pcm; @@ -64,7 +64,9 @@ class Pipeline; class PipelineContext; -class ProjectM +class PresetFactoryManager; + +PROJECTM_EXPORT class ProjectM { public: ProjectM(); @@ -246,43 +248,43 @@ private: class Pcm m_pcm; //!< Audio data buffer and analyzer instance. - 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. - size_t m_textureSize{512}; //!< Render texture size. - size_t m_windowWidth{0}; //!< Render window width. If 0, nothing is rendered. - size_t m_windowHeight{0}; //!< Render 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. - bool m_hardCutEnabled{false}; //!< If true, hard cuts based on beat detection are enabled. + 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. + size_t m_textureSize{512}; //!< Render texture size. + size_t m_windowWidth{0}; //!< Render window width. If 0, nothing is rendered. + size_t m_windowHeight{0}; //!< Render 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. + bool m_hardCutEnabled{false}; //!< If true, hard cuts based on beat detection are enabled. float m_hardCutSensitivity{2.0}; //!< Loudness sensitivity value for hard cuts. - float m_beatSensitivity{1.0}; //!< General beat sensitivity modifier for presets. - bool m_aspectCorrection{true}; //!< If true, corrects aspect ratio for non-rectangular windows. - float m_easterEgg{0.0}; //!< Random preset duration modifier. See TimeKeeper class. + float m_beatSensitivity{1.0}; //!< General beat sensitivity modifier for presets. + bool m_aspectCorrection{true}; //!< If true, corrects aspect ratio for non-rectangular windows. + float m_easterEgg{0.0}; //!< Random preset duration modifier. See TimeKeeper class. std::vector m_textureSearchPaths; ///!< List of paths to search for texture files /** Timing information */ int m_count{0}; //!< Rendered frame count since start - bool m_presetLocked{false}; //!< If true, the preset change event will not be sent. + bool m_presetLocked{false}; //!< If true, the preset change event will not be sent. bool m_presetChangeNotified{false}; //!< Stores whether the user has been notified that projectM wants to switch the preset. - PresetFactoryManager m_presetFactoryManager; //!< Provides access to all available preset factories. + std::unique_ptr m_presetFactoryManager; //!< Provides access to all available preset factories. 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_renderer; //!< The Preset renderer. - std::unique_ptr m_beatDetect; //!< The beat detection class. - std::unique_ptr m_activePreset; //!< Currently loaded preset. - std::unique_ptr m_transitioningPreset; //!< 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_renderer; //!< The Preset renderer. + std::unique_ptr m_beatDetect; //!< The beat detection class. + std::unique_ptr m_activePreset; //!< Currently loaded preset. + std::unique_ptr m_transitioningPreset; //!< Destination preset when smooth preset switching. + std::unique_ptr m_timeKeeper; //!< Keeps the different timers used to render and switch presets. #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. + std::unique_ptr m_workerSync; //!< Background work synchronizer. #endif }; diff --git a/src/libprojectM/Renderer/CMakeLists.txt b/src/libprojectM/Renderer/CMakeLists.txt index 9d922cb95..0f823d4b5 100644 --- a/src/libprojectM/Renderer/CMakeLists.txt +++ b/src/libprojectM/Renderer/CMakeLists.txt @@ -55,6 +55,8 @@ target_include_directories(Renderer ) target_link_libraries(Renderer + PRIVATE + libprojectM::API # For export header PUBLIC GLM::GLM hlslparser