From a4a3fdc4b64437ff141f7a13eaa2fa4676e9aa60 Mon Sep 17 00:00:00 2001 From: w1z7ard Date: Sun, 14 Sep 2008 05:22:58 +0000 Subject: [PATCH] removed some temp aborts from projectM top level git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/personal/carm/represet@1160 6778bc44-b910-0410-a7a0-be141de4315d --- src/libprojectM/CompiledPreset.hpp | 2 +- src/libprojectM/CompiledPresetFactory.hpp | 2 +- src/libprojectM/MilkdropPreset.cpp | 15 +--- src/libprojectM/PresetFactory.hpp | 4 +- src/libprojectM/PresetFactoryManager.cpp | 8 +-- src/libprojectM/Renderer.cpp | 1 - src/libprojectM/RingBuffer.hpp | 65 ----------------- src/libprojectM/projectM.cpp | 87 +++++++++-------------- src/libprojectM/projectM.hpp | 26 +++---- 9 files changed, 55 insertions(+), 155 deletions(-) delete mode 100644 src/libprojectM/RingBuffer.hpp diff --git a/src/libprojectM/CompiledPreset.hpp b/src/libprojectM/CompiledPreset.hpp index c877799e4..53a3277ce 100644 --- a/src/libprojectM/CompiledPreset.hpp +++ b/src/libprojectM/CompiledPreset.hpp @@ -21,7 +21,7 @@ template class CompiledPreset : public Preset { public: - inline CompiledPreset(const std::string & name=std::string(), + inline CompiledPreset(const std::string & name=std::string(), const std::string & author = std::string()) : Preset(name, author) {} virtual ~CompiledPreset() {} diff --git a/src/libprojectM/CompiledPresetFactory.hpp b/src/libprojectM/CompiledPresetFactory.hpp index c17b65923..abd6272cc 100644 --- a/src/libprojectM/CompiledPresetFactory.hpp +++ b/src/libprojectM/CompiledPresetFactory.hpp @@ -29,7 +29,7 @@ public: virtual std::auto_ptr allocate(const std::string & url, const std::string & name = std::string(), const std::string & author = std::string()); - std::string supportedExtensions() const { return "so"; } + virtual std::string supportedExtensions() const { return "so"; } private: PresetLibrary * loadLibrary(const std::string & url); diff --git a/src/libprojectM/MilkdropPreset.cpp b/src/libprojectM/MilkdropPreset.cpp index 6e70e4834..81d79d675 100755 --- a/src/libprojectM/MilkdropPreset.cpp +++ b/src/libprojectM/MilkdropPreset.cpp @@ -52,14 +52,6 @@ MilkdropPreset::MilkdropPreset(std::istream & in, const std::string & presetName } - -/** - * - * @param absoluteFilePath - * @param presetName - * @param presetInputs - * @param presetOutputs - */ MilkdropPreset::MilkdropPreset(const std::string & absoluteFilePath, const std::string & presetName, PresetOutputs & presetOutputs): builtinParams(_presetInputs, presetOutputs), _absoluteFilePath(absoluteFilePath), @@ -275,8 +267,7 @@ void MilkdropPreset::Render(const BeatDetect &music, const PipelineContext &cont { _presetInputs.update(music, context); - // set stuff here - this->evaluateFrame(); + evaluateFrame(); } void MilkdropPreset::initialize(const std::string & pathname) @@ -332,7 +323,6 @@ void MilkdropPreset::loadBuiltinParamsUnspecInitConds() { void MilkdropPreset::loadCustomWaveUnspecInitConds() { - for (PresetOutputs::cwave_container::iterator pos = customWaves.begin(); pos != customWaves.end(); ++pos) { assert(*pos); @@ -344,7 +334,8 @@ void MilkdropPreset::loadCustomWaveUnspecInitConds() void MilkdropPreset::loadCustomShapeUnspecInitConds() { - for (PresetOutputs::cshape_container::iterator pos = customShapes.begin(); pos != customShapes.end(); ++pos) + for (PresetOutputs::cshape_container::iterator pos = customShapes.begin(); + pos != customShapes.end(); ++pos) { assert(*pos); (*pos)->loadUnspecInitConds(); diff --git a/src/libprojectM/PresetFactory.hpp b/src/libprojectM/PresetFactory.hpp index 025ccacbb..8f6f64648 100644 --- a/src/libprojectM/PresetFactory.hpp +++ b/src/libprojectM/PresetFactory.hpp @@ -26,8 +26,8 @@ public: /// Constructs a new preset given an url /// \param url a locational identifier referencing the preset -/// \param name the preset name -/// \param author the preset author + /// \param name the preset name + /// \param author the preset author /// \returns a valid preset object virtual std::auto_ptr allocate(const std::string & url, const std::string & name=std::string(), const std::string & author=std::string()) = 0; diff --git a/src/libprojectM/PresetFactoryManager.cpp b/src/libprojectM/PresetFactoryManager.cpp index 8226d0791..3f38f541d 100644 --- a/src/libprojectM/PresetFactoryManager.cpp +++ b/src/libprojectM/PresetFactoryManager.cpp @@ -53,9 +53,9 @@ void PresetFactoryManager::registerFactory(const std::string & extensions, Prese std::string extension; while (ss >> extension) { - if (_factoryMap.count(extension)) { - std::cerr << "[PresetFactoryManager] Warning: extension \"" << extension << - "\" already has a factory. New factory handler ignored." << std::endl; + if (_factoryMap.count(extension)) { + std::cerr << "[PresetFactoryManager] Warning: extension \"" << extension << + "\" already has a factory. New factory handler ignored." << std::endl; } else { _factoryMap.insert(std::make_pair(extension, factory)); _factoryList.push_back(factory); @@ -65,7 +65,7 @@ void PresetFactoryManager::registerFactory(const std::string & extensions, Prese PresetFactory & PresetFactoryManager::factory(const std::string & extension) { - if (!_factoryMap.count(extension)) { + if (!_factoryMap.count(extension)) { std::ostringstream os; os << "No factory associated with \"" << extension << "\"." << std::endl; throw PresetFactoryException(os.str()); diff --git a/src/libprojectM/Renderer.cpp b/src/libprojectM/Renderer.cpp index 36187220d..4f3799a48 100644 --- a/src/libprojectM/Renderer.cpp +++ b/src/libprojectM/Renderer.cpp @@ -105,7 +105,6 @@ void Renderer::SetPipeline(Pipeline &pipeline) shaderEngine.reset(); shaderEngine.loadShader(pipeline.warpShader); shaderEngine.loadShader(pipeline.compositeShader); - #endif } diff --git a/src/libprojectM/RingBuffer.hpp b/src/libprojectM/RingBuffer.hpp deleted file mode 100644 index 414139211..000000000 --- a/src/libprojectM/RingBuffer.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef RING_BUFFER_HPP -#define RING_BUFFER_HPP -/// Code courtesy of: http://www.osix.net/modules/article/?id=464 - -template -class RingBuffer { -public: - - //static const unsigned long RING_BUFFER_SIZE = 1024; - static const unsigned long RING_BUFFER_SIZE = 32768; -private: - - kind buffer[RING_BUFFER_SIZE]; - unsigned int current_element; -public: - RingBuffer() : current_element(0) { - } - - RingBuffer(const RingBuffer& old_ring_buf) { - memcpy(buffer, old_ring_buf.buffer, RING_BUFFER_SIZE*sizeof(kind)); - current_element = old_ring_buf.current_element; - } - - RingBuffer operator = (const RingBuffer& old_ring_buf) { - memcpy(buffer, old_ring_buf.buffer, RING_BUFFER_SIZE*sizeof(kind)); - current_element = old_ring_buf.current_element; - } - - ~RingBuffer() { } - - void append(kind value) { - if (current_element == RING_BUFFER_SIZE) { - current_element = 0; - } - - buffer[current_element] = value; - - ++current_element; - } - - - kind back() { - - if (current_element == 0) { - current_element = RING_BUFFER_SIZE; - } - --current_element; - return buffer[current_element]; - } - - - kind forward() { - if(current_element >= RING_BUFFER_SIZE) { - current_element = 0; - } - - ++current_element; - return( buffer[(current_element-1)] ); - } - - int current() { - return (current_element % RING_BUFFER_SIZE); - } -}; -#endif diff --git a/src/libprojectM/projectM.cpp b/src/libprojectM/projectM.cpp index 314a5ae40..05b779936 100755 --- a/src/libprojectM/projectM.cpp +++ b/src/libprojectM/projectM.cpp @@ -62,6 +62,7 @@ projectM::~projectM() { #ifdef USE_THREADS + std::cout << "[projectM] thread "; printf("c"); running = false; printf("l"); @@ -75,10 +76,10 @@ projectM::~projectM() printf("u"); pthread_mutex_destroy( &mutex ); printf("p"); + std::cout << std::endl; #endif destroyPresetTools(); - if ( renderer ) delete ( renderer ); if ( beatDetect ) @@ -143,7 +144,7 @@ bool projectM::writeConfig(const std::string & configFile, const Settings & sett void projectM::readConfig (const std::string & configFile ) { - std::cout << "configFile: " << configFile << std::endl; + std::cout << "[projectM] config file: " << configFile << std::endl; ConfigFile config ( configFile ); _settings.meshX = config.read ( "Mesh X", 32 ); @@ -237,9 +238,7 @@ void *projectM::thread_func(void *vptr_args) void projectM::evaluateSecondPreset() { - -/* setupPresetInputs(&m_activePreset2->presetInputs()); - +/* m_activePreset2->presetInputs().frame = timeKeeper->PresetFrameB(); m_activePreset2->presetInputs().progress= timeKeeper->PresetProgressB(); @@ -264,13 +263,11 @@ DLLEXPORT void projectM::renderFrame() //printf("A:%f, B:%f, S:%f\n", timeKeeper->PresetProgressA(), timeKeeper->PresetProgressB(), timeKeeper->SmoothRatio()); -std::cerr << "mspf: FIX ME!"; - abort(); + mspf= ( int ) ( 1000.0/ ( float ) settings().fps ); //milliseconds per frame - //mspf= ( int ) ( 1000.0/ ( float ) presetInputs.fps ); //milliseconds per frame - - //m_activePreset->Render(beatDetect, pipelineContext); - //setupPresetInputs(&m_activePreset->presetInputs()); + m_activePreset->Render(*beatDetect, pipelineContext); + + /// @bug whois is responsible for updating this now?" //m_activePreset->presetInputs().frame = timeKeeper->PresetFrameA(); //m_activePreset->presetInputs().progress= timeKeeper->PresetProgressA(); @@ -286,19 +283,16 @@ std::cerr << "mspf: FIX ME!"; timeKeeper->StartSmoothing(); // printf("Start Smooth\n"); // if(timeKeeper->IsSmoothing())printf("Confirmed\n"); -assert(false); -/* switchPreset(m_activePreset2, - &m_activePreset->presetInputs() == &presetInputs ? presetInputs2 : presetInputs, - &m_activePreset->presetOutputs() == &presetOutputs ? presetOutputs2 : presetOutputs); -*/ + switchPreset(m_activePreset2); presetSwitchedEvent(false, **m_presetPos); } else if ( ( beatDetect->vol-beatDetect->vol_old>beatDetect->beat_sensitivity ) && timeKeeper->CanHardCut() ) { // printf("Hard Cut\n"); -std::cerr << "HARD CUT. SWITCH PRESET BROKEN" << std::endl; - abort(); + + switchPreset(m_activePreset); + //switchPreset(m_activePreset, presetInputs, presetOutputs); timeKeeper->StartPreset(); @@ -318,12 +312,9 @@ std::cerr << "HARD CUT. SWITCH PRESET BROKEN" << std::endl; #ifdef USE_THREADS pthread_cond_signal(&condition); pthread_mutex_unlock( &mutex ); -#endif - //m_activePreset->evaluateFrame(); +#endif m_activePreset->Render(*beatDetect, pipelineContext); - //m_activePreset->presetOutputs().Render(*beatDetect,presetInputs); - #ifdef USE_THREADS pthread_mutex_lock( &mutex ); #else @@ -336,14 +327,13 @@ std::cerr << "HARD CUT. SWITCH PRESET BROKEN" << std::endl; Pipeline pipeline; -std::cerr << "FIX ME STATIC PER PIXEL" << std::endl; -abort(); -//pipeline.setStaticPerPixel(presetInputs.gx,presetInputs.gy); +pipeline.setStaticPerPixel(settings().meshX, settings().meshY); + PipelineMerger::MergePipelines( m_activePreset->pipeline(),m_activePreset2->pipeline(), pipeline,timeKeeper->SmoothRatio()); +/// @bug not sure if this is correct +renderer->RenderFrame(pipeline, pipelineContext); -std::cerr << "FIX ME RENDER FRAME" << std::endl; -abort(); //renderer->RenderFrame ( pipeline, presetInputs ); } else @@ -434,17 +424,13 @@ void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, assert(pcm()); beatDetect = new BeatDetect ( _pcm ); - - std::cerr << "fps broken FIX ME" << std::endl; - abort(); - //if ( presetInputs.fps > 0 ) - // mspf= ( int ) ( 1000.0/ ( float ) presetInputs.fps ); - //else mspf = 0; + if ( _settings.fps > 0 ) + mspf= ( int ) ( 1000.0/ ( float ) _settings.fps ); + else mspf = 0; this->renderer = new Renderer ( width, height, gx, gy, texsize, beatDetect, settings().presetURL, settings().titleFontURL, settings().menuFontURL ); - std::cerr << "set pipeline broken FIX ME" << std::endl; - abort(); + std::cerr << "set pipeline broken FIX ME" << std::endl; //renderer->SetPipeline(presetOutputs); running = true; @@ -456,8 +442,8 @@ void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, if (pthread_create(&thread, NULL, thread_callback, this) != 0) { - std::cerr << "failed to allocate a thread! try building with option USE_THREADS turned off" << std::endl;; - exit(1); + std::cerr << "[projectM] failed to allocate a thread! try building with option USE_THREADS turned off" << std::endl;; + exit(EXIT_FAILURE); } pthread_mutex_lock( &mutex ); #endif @@ -466,8 +452,6 @@ void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, timeKeeper->StartPreset(); assert(pcm()); - -// printf ( "exiting projectM_init()\n" ); } /* Reinitializes the engine variables to a default (conservative and sane) value */ @@ -480,9 +464,9 @@ void projectM::projectM_resetengine() } /// @bug call factory clear here? - std::cerr << "call factory clear?" << std::endl; - abort(); - /* Q VARIABLES END */ + std::cerr << "call factory clear here?" << std::endl; +// abort(); + } @@ -496,8 +480,8 @@ DLLEXPORT void projectM::projectM_resetGL ( int w, int h ) } /** Sets the title to display */ -DLLEXPORT void projectM::projectM_setTitle ( std::string title ) -{ +DLLEXPORT void projectM::projectM_setTitle ( std::string title ) { + if ( title != renderer->title ) { renderer->title=title; @@ -549,11 +533,11 @@ int projectM::initPresetTools(int gx, int gy) // Case where no valid presets exist in directory. Could also mean // playlist initialization was deferred - //if ( m_presetChooser->empty() ) - //{ - //std::cerr << "[projectM] warning: no valid files found in preset directory \"" - //<< m_presetLoader->directoryName() << "\"" << std::endl; - //} + if ( m_presetChooser->empty() ) + { + std::cerr << "[projectM] warning: no valid files found in preset directory \"" + << m_presetLoader->directoryName() << "\"" << std::endl; + } //std::cerr << "[projectM] Idle preset allocated." << std::endl; @@ -607,8 +591,6 @@ void projectM::removePreset(unsigned int index) { // Case: we have deleted the active preset position // Set iterator to end of chooser else if (chooserIndex == index) { - //*m_presetPos = m_presetChooser->begin(chooserIndex); - std::cerr << "deleted active preset!"; *m_presetPos = m_presetChooser->end(); } @@ -691,13 +673,10 @@ std::string projectM::getPresetName ( unsigned int index ) const void projectM::clearPlaylist ( ) { - m_presetLoader->clear(); *m_presetPos = m_presetChooser->end(); - } -/// Sets preset iterator position to the passed in index void projectM::selectPresetPosition(unsigned int index) { *m_presetPos = m_presetChooser->begin(index); } diff --git a/src/libprojectM/projectM.hpp b/src/libprojectM/projectM.hpp index f7a301a23..a89ddc6eb 100755 --- a/src/libprojectM/projectM.hpp +++ b/src/libprojectM/projectM.hpp @@ -26,19 +26,18 @@ * $Log$ */ -#ifndef _PROJECTM_H -#define _PROJECTM_H +#ifndef _PROJECTM_HPP +#define _PROJECTM_HPP #ifdef WIN32 #include "win32-dirent.h" #else #include #endif /** WIN32 */ -#include -#include -#include +#include +#include #include -#include +#include #ifndef WIN32 #include #endif @@ -103,8 +102,7 @@ typedef enum { /// A functor class that allows users of this library to specify random preset behavior class RandomizerFunctor { - public: - //RandomizerFunctor(); + public: RandomizerFunctor(PresetChooser & chooser) ; virtual ~RandomizerFunctor(); virtual double operator() (int index); @@ -247,7 +245,7 @@ public: void *thread_func(void *vptr_args); private: - PCM * _pcm; + PCM * _pcm; double sampledPresetDuration(); BeatDetect * beatDetect; Renderer *renderer; @@ -271,6 +269,7 @@ private: void projectM_initengine(); void projectM_resetengine(); + /// Initializes preset loading / management libraries int initPresetTools(int gx, int gy); @@ -293,16 +292,13 @@ private: /// Destination preset when smooth preset switching std::auto_ptr m_activePreset2; - TimeKeeper *timeKeeper; - int m_flags; - -pthread_mutex_t mutex; -pthread_cond_t condition; -pthread_t thread; + pthread_mutex_t mutex; + pthread_cond_t condition; + pthread_t thread; bool running; Pipeline* currentPipe;