diff --git a/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.cpp b/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.cpp index 2dc1eabdb..4e3151e5c 100644 --- a/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.cpp +++ b/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.cpp @@ -17,14 +17,16 @@ #include "IdlePreset.hpp" #include "PresetFrameIO.hpp" -MilkdropPresetFactory::MilkdropPresetFactory(int gx, int gy) { +MilkdropPresetFactory::MilkdropPresetFactory(int gx, int gy): _usePresetOutputs(false) +{ /* Initializes the builtin function database */ BuiltinFuncs::init_builtin_func_db(); /* Initializes all infix operators */ Eval::init_infix_ops(); - initializePresetOutputs(gx,gy); + _presetOutputs = createPresetOutputs(gx,gy); + _presetOutputs2 = createPresetOutputs(gx, gy); } MilkdropPresetFactory::~MilkdropPresetFactory() { @@ -35,120 +37,129 @@ MilkdropPresetFactory::~MilkdropPresetFactory() { BuiltinFuncs::destroy_builtin_func_db(); std::cerr << "[~MilkdropPresetFactory] delete preset out puts" << std::endl; delete(_presetOutputs); + delete(_presetOutputs2); std::cerr << "[~MilkdropPresetFactory] done" << std::endl; } /* Reinitializes the engine variables to a default (conservative and sane) value */ -void MilkdropPresetFactory::reset() +void resetPresetOutputs(PresetOutputs *presetOutputs) { - _presetOutputs->zoom=1.0; - _presetOutputs->zoomexp = 1.0; - _presetOutputs->rot= 0.0; - _presetOutputs->warp= 0.0; + presetOutputs->zoom=1.0; + presetOutputs->zoomexp = 1.0; + presetOutputs->rot= 0.0; + presetOutputs->warp= 0.0; - _presetOutputs->sx= 1.0; - _presetOutputs->sy= 1.0; - _presetOutputs->dx= 0.0; - _presetOutputs->dy= 0.0; - _presetOutputs->cx= 0.5; - _presetOutputs->cy= 0.5; + presetOutputs->sx= 1.0; + presetOutputs->sy= 1.0; + presetOutputs->dx= 0.0; + presetOutputs->dy= 0.0; + presetOutputs->cx= 0.5; + presetOutputs->cy= 0.5; - _presetOutputs->screenDecay=.98; + presetOutputs->screenDecay=.98; - _presetOutputs->wave.r= 1.0; - _presetOutputs->wave.g= 0.2; - _presetOutputs->wave.b= 0.0; - _presetOutputs->wave.x= 0.5; - _presetOutputs->wave.y= 0.5; - _presetOutputs->wave.mystery= 0.0; + presetOutputs->wave.r= 1.0; + presetOutputs->wave.g= 0.2; + presetOutputs->wave.b= 0.0; + presetOutputs->wave.x= 0.5; + presetOutputs->wave.y= 0.5; + presetOutputs->wave.mystery= 0.0; - _presetOutputs->border.outer_size= 0.0; - _presetOutputs->border.outer_r= 0.0; - _presetOutputs->border.outer_g= 0.0; - _presetOutputs->border.outer_b= 0.0; - _presetOutputs->border.outer_a= 0.0; + presetOutputs->border.outer_size= 0.0; + presetOutputs->border.outer_r= 0.0; + presetOutputs->border.outer_g= 0.0; + presetOutputs->border.outer_b= 0.0; + presetOutputs->border.outer_a= 0.0; - _presetOutputs->border.inner_size = 0.0; - _presetOutputs->border.inner_r = 0.0; - _presetOutputs->border.inner_g = 0.0; - _presetOutputs->border.inner_b = 0.0; - _presetOutputs->border.inner_a = 0.0; + presetOutputs->border.inner_size = 0.0; + presetOutputs->border.inner_r = 0.0; + presetOutputs->border.inner_g = 0.0; + presetOutputs->border.inner_b = 0.0; + presetOutputs->border.inner_a = 0.0; - _presetOutputs->mv.a = 0.0; - _presetOutputs->mv.r = 0.0; - _presetOutputs->mv.g = 0.0; - _presetOutputs->mv.b = 0.0; - _presetOutputs->mv.length = 1.0; - _presetOutputs->mv.x_num = 16.0; - _presetOutputs->mv.y_num = 12.0; - _presetOutputs->mv.x_offset = 0.02; - _presetOutputs->mv.y_offset = 0.02; + presetOutputs->mv.a = 0.0; + presetOutputs->mv.r = 0.0; + presetOutputs->mv.g = 0.0; + presetOutputs->mv.b = 0.0; + presetOutputs->mv.length = 1.0; + presetOutputs->mv.x_num = 16.0; + presetOutputs->mv.y_num = 12.0; + presetOutputs->mv.x_offset = 0.02; + presetOutputs->mv.y_offset = 0.02; - /* PER_FRAME CONSTANTS END */ - _presetOutputs->fRating = 0; - _presetOutputs->fGammaAdj = 1.0; - _presetOutputs->videoEcho.zoom = 1.0; - _presetOutputs->videoEcho.a = 0; - _presetOutputs->videoEcho.orientation = Normal; + /* PER_FRAME CONSTANTS END */ + presetOutputs->fRating = 0; + presetOutputs->fGammaAdj = 1.0; + presetOutputs->videoEcho.zoom = 1.0; + presetOutputs->videoEcho.a = 0; + presetOutputs->videoEcho.orientation = Normal; - _presetOutputs->wave.additive = false; - _presetOutputs->wave.dots = false; - _presetOutputs->wave.thick = false; - _presetOutputs->wave.modulateAlphaByVolume = 0; - _presetOutputs->wave.maximizeColors = 0; - _presetOutputs->textureWrap = 0; - _presetOutputs->bDarkenCenter = 0; - _presetOutputs->bRedBlueStereo = 0; - _presetOutputs->bBrighten = 0; - _presetOutputs->bDarken = 0; - _presetOutputs->bSolarize = 0; - _presetOutputs->bInvert = 0; - _presetOutputs->bMotionVectorsOn = 1; + presetOutputs->wave.additive = false; + presetOutputs->wave.dots = false; + presetOutputs->wave.thick = false; + presetOutputs->wave.modulateAlphaByVolume = 0; + presetOutputs->wave.maximizeColors = 0; + presetOutputs->textureWrap = 0; + presetOutputs->bDarkenCenter = 0; + presetOutputs->bRedBlueStereo = 0; + presetOutputs->bBrighten = 0; + presetOutputs->bDarken = 0; + presetOutputs->bSolarize = 0; + presetOutputs->bInvert = 0; + presetOutputs->bMotionVectorsOn = 1; - _presetOutputs->wave.a =1.0; - _presetOutputs->wave.scale = 1.0; - _presetOutputs->wave.smoothing = 0; - _presetOutputs->wave.mystery = 0; - _presetOutputs->wave.modOpacityEnd = 0; - _presetOutputs->wave.modOpacityStart = 0; - _presetOutputs->fWarpAnimSpeed = 0; - _presetOutputs->fWarpScale = 0; - _presetOutputs->fShader = 0; + presetOutputs->wave.a =1.0; + presetOutputs->wave.scale = 1.0; + presetOutputs->wave.smoothing = 0; + presetOutputs->wave.mystery = 0; + presetOutputs->wave.modOpacityEnd = 0; + presetOutputs->wave.modOpacityStart = 0; + presetOutputs->fWarpAnimSpeed = 0; + presetOutputs->fWarpScale = 0; + presetOutputs->fShader = 0; - /* PER_PIXEL CONSTANT END */ - /* Q VARIABLES START */ + /* PER_PIXEL CONSTANT END */ + /* Q VARIABLES START */ - for (int i = 0;i< 32;i++) - _presetOutputs->q[i] = 0; + for (int i = 0;i< 32;i++) + presetOutputs->q[i] = 0; - /* Q VARIABLES END */ + /* Q VARIABLES END */ } -void MilkdropPresetFactory::initializePresetOutputs(int gx, int gy) + +/* Reinitializes the engine variables to a default (conservative and sane) value */ +void MilkdropPresetFactory::reset() +{ + resetPresetOutputs(_presetOutputs); + resetPresetOutputs(_presetOutputs2); +} + +PresetOutputs* MilkdropPresetFactory::createPresetOutputs(int gx, int gy) { - _presetOutputs = new PresetOutputs(); + PresetOutputs *presetOutputs = new PresetOutputs(); - _presetOutputs->Initialize(gx,gy); + presetOutputs->Initialize(gx,gy); /* PER FRAME CONSTANTS BEGIN */ - _presetOutputs->zoom=1.0; - _presetOutputs->zoomexp = 1.0; - _presetOutputs->rot= 0.0; - _presetOutputs->warp= 0.0; + presetOutputs->zoom=1.0; + presetOutputs->zoomexp = 1.0; + presetOutputs->rot= 0.0; + presetOutputs->warp= 0.0; - _presetOutputs->sx= 1.0; - _presetOutputs->sy= 1.0; - _presetOutputs->dx= 0.0; - _presetOutputs->dy= 0.0; - _presetOutputs->cx= 0.5; - _presetOutputs->cy= 0.5; + presetOutputs->sx= 1.0; + presetOutputs->sy= 1.0; + presetOutputs->dx= 0.0; + presetOutputs->dy= 0.0; + presetOutputs->cx= 0.5; + presetOutputs->cy= 0.5; - _presetOutputs->screenDecay=.98; + presetOutputs->screenDecay=.98; //_presetInputs.meshx = 0; @@ -156,24 +167,24 @@ void MilkdropPresetFactory::initializePresetOutputs(int gx, int gy) /* PER_FRAME CONSTANTS END */ - _presetOutputs->fRating = 0; - _presetOutputs->fGammaAdj = 1.0; - _presetOutputs->videoEcho.zoom = 1.0; - _presetOutputs->videoEcho.a = 0; - _presetOutputs->videoEcho.orientation = Normal; + presetOutputs->fRating = 0; + presetOutputs->fGammaAdj = 1.0; + presetOutputs->videoEcho.zoom = 1.0; + presetOutputs->videoEcho.a = 0; + presetOutputs->videoEcho.orientation = Normal; - _presetOutputs->textureWrap = 0; - _presetOutputs->bDarkenCenter = 0; - _presetOutputs->bRedBlueStereo = 0; - _presetOutputs->bBrighten = 0; - _presetOutputs->bDarken = 0; - _presetOutputs->bSolarize = 0; - _presetOutputs->bInvert = 0; - _presetOutputs->bMotionVectorsOn = 1; + presetOutputs->textureWrap = 0; + presetOutputs->bDarkenCenter = 0; + presetOutputs->bRedBlueStereo = 0; + presetOutputs->bBrighten = 0; + presetOutputs->bDarken = 0; + presetOutputs->bSolarize = 0; + presetOutputs->bInvert = 0; + presetOutputs->bMotionVectorsOn = 1; - _presetOutputs->fWarpAnimSpeed = 0; - _presetOutputs->fWarpScale = 0; - _presetOutputs->fShader = 0; + presetOutputs->fWarpAnimSpeed = 0; + presetOutputs->fWarpScale = 0; + presetOutputs->fShader = 0; /* PER_PIXEL CONSTANTS BEGIN */ @@ -182,22 +193,24 @@ void MilkdropPresetFactory::initializePresetOutputs(int gx, int gy) /* Q AND T VARIABLES START */ for (int i = 0;iq[i] = 0; + presetOutputs->q[i] = 0; /* Q AND T VARIABLES END */ - + return presetOutputs; } std::auto_ptr MilkdropPresetFactory::allocate(const std::string & url, const std::string & name, const std::string & author) { - _presetOutputs->customWaves.clear(); - _presetOutputs->customShapes.clear(); + PresetOutputs *presetOutputs = _usePresetOutputs ? _presetOutputs : _presetOutputs2; + _usePresetOutputs = !_usePresetOutputs; + presetOutputs->customWaves.clear(); + presetOutputs->customShapes.clear(); std::string path; if (PresetFactory::protocol(url, path) == PresetFactory::IDLE_PRESET_PROTOCOL) { - return IdlePresets::allocate(path, *_presetOutputs); + return IdlePresets::allocate(path, *presetOutputs); } else - return std::auto_ptr(new MilkdropPreset(url, name, *_presetOutputs)); + return std::auto_ptr(new MilkdropPreset(url, name, *presetOutputs)); } diff --git a/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.hpp b/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.hpp index ec347605c..2a5a46afb 100644 --- a/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.hpp +++ b/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.hpp @@ -1,7 +1,7 @@ // // C++ Interface: MilkdropPresetFactory // -// Description: +// Description: // // // Author: Carmelo Piccione , (C) 2008 @@ -21,7 +21,7 @@ class DLLEXPORT PresetInputs; class MilkdropPresetFactory : public PresetFactory { public: - + MilkdropPresetFactory(int gx, int gy); virtual ~MilkdropPresetFactory(); @@ -32,9 +32,11 @@ public: std::string supportedExtensions() const { return "milk prjm"; } private: - void initializePresetOutputs(int gx, int gy); + static PresetOutputs* createPresetOutputs(int gx, int gy); void reset(); PresetOutputs * _presetOutputs; + PresetOutputs * _presetOutputs2; + bool _usePresetOutputs; //PresetInputs _presetInputs; }; diff --git a/src/libprojectM/PipelineMerger.cpp b/src/libprojectM/PipelineMerger.cpp index 5e4328e71..d5cdfebc7 100644 --- a/src/libprojectM/PipelineMerger.cpp +++ b/src/libprojectM/PipelineMerger.cpp @@ -10,26 +10,46 @@ void PipelineMerger::mergePipelines(const Pipeline & a, const Pipeline & b, Pipe out.textureWrap = (ratio < 0.5) ? a.textureWrap : b.textureWrap; out.screenDecay = lerp( b.screenDecay, a.screenDecay, ratio); - out.drawables.clear(); + out.drawables.clear(); + out.compositeDrawables.clear(); for (std::vector::const_iterator pos = a.drawables.begin(); pos != a.drawables.end(); ++pos) { - (*pos)->masterAlpha = invratio; + (*pos)->masterAlpha = invratio; out.drawables.push_back(*pos); } - for (std::vector::const_iterator pos = b.drawables.begin(); + for (std::vector::const_iterator pos = b.drawables.begin(); pos != b.drawables.end();++pos) { - (*pos)->masterAlpha = ratio; + (*pos)->masterAlpha = ratio; out.drawables.push_back(*pos); } - + + if (ratio < 0.5) + { + for (std::vector::const_iterator pos = a.compositeDrawables.begin(); + pos != a.compositeDrawables.end(); ++pos) + { + //(*pos)->masterAlpha = invratio; + out.compositeDrawables.push_back(*pos); + } + } + else + { + for (std::vector::const_iterator pos = b.compositeDrawables.begin(); + pos != b.compositeDrawables.end();++pos) + { + //(*pos)->masterAlpha = ratio; + out.compositeDrawables.push_back(*pos); + } + } + /* - for (RenderItemMatchList::iterator pos = results.matches.begin(); pos != results.matches.end(); ++pos) { - + for (RenderItemMatchList::iterator pos = results.matches.begin(); pos != results.matches.end(); ++pos) { + RenderItem * itemA = pos->first; RenderItem * itemB = pos->second; @@ -40,11 +60,11 @@ void PipelineMerger::mergePipelines(const Pipeline & a, const Pipeline & b, Pipe out.drawables.push_back(itemA); itemB->masterAlpha = invratio; out.drawables.push_back(itemB); - } else + } else out.drawables.push_back(itemC); - + } - + for (std::vector::const_iterator pos = results.unmatchedLeft.begin(); pos != results.unmatchedLeft.end(); ++pos) diff --git a/src/libprojectM/Renderer/MilkdropWaveform.cpp b/src/libprojectM/Renderer/MilkdropWaveform.cpp index e39284a71..b2d7dbec1 100644 --- a/src/libprojectM/Renderer/MilkdropWaveform.cpp +++ b/src/libprojectM/Renderer/MilkdropWaveform.cpp @@ -4,6 +4,7 @@ * Created on: Jun 25, 2008 * Author: pete */ +#include #ifdef LINUX #include @@ -156,7 +157,6 @@ void MilkdropWaveform::MaximizeColors(RenderContext &context) { glColor4f(r, g, b, temp_a * masterAlpha); } - } diff --git a/src/libprojectM/Renderer/Renderer.cpp b/src/libprojectM/Renderer/Renderer.cpp index 38dcf3145..186ce9191 100644 --- a/src/libprojectM/Renderer/Renderer.cpp +++ b/src/libprojectM/Renderer/Renderer.cpp @@ -162,7 +162,9 @@ void Renderer::RenderItems(const Pipeline &pipeline, const PipelineContext &pipe renderContext.beatDetect = beatDetect; for (std::vector::const_iterator pos = pipeline.drawables.begin(); pos != pipeline.drawables.end(); ++pos) + { (*pos)->Draw(renderContext); + } } void Renderer::FinishPass1() diff --git a/src/libprojectM/projectM.cpp b/src/libprojectM/projectM.cpp index c0b6d32b0..4de2acab1 100755 --- a/src/libprojectM/projectM.cpp +++ b/src/libprojectM/projectM.cpp @@ -1,23 +1,23 @@ /** - * projectM -- Milkdrop-esque visualisation SDK - * Copyright (C)2003-2004 projectM Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * See 'LICENSE.txt' included within this release - * - */ +* projectM -- Milkdrop-esque visualisation SDK +* Copyright (C)2003-2004 projectM Team +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* See 'LICENSE.txt' included within this release +* +*/ #include "RenderItemMatcher.hpp" #include "RenderItemMergeFunction.hpp" @@ -62,59 +62,60 @@ projectM::~projectM() { - #ifdef USE_THREADS - std::cout << "[projectM] thread "; - printf("c"); - running = false; - printf("l"); - pthread_cond_signal(&condition); - printf("e"); - pthread_mutex_unlock( &mutex ); - printf("a"); - pthread_detach(thread); - printf("n"); - pthread_cond_destroy(&condition); - printf("u"); - pthread_mutex_destroy( &mutex ); - printf("p"); - std::cout << std::endl; -#endif - destroyPresetTools(); + #ifdef USE_THREADS + std::cout << "[projectM] thread "; + printf("c"); + running = false; + printf("l"); + pthread_cond_signal(&condition); + printf("e"); + pthread_mutex_unlock( &mutex ); + printf("a"); + pthread_detach(thread); + printf("n"); + pthread_cond_destroy(&condition); + printf("u"); + pthread_mutex_destroy( &mutex ); + printf("p"); + std::cout << std::endl; + #endif + destroyPresetTools(); - if ( renderer ) - delete ( renderer ); - if ( beatDetect ) - delete ( beatDetect ); - if ( _pcm ) { - delete ( _pcm ); - _pcm = 0; - } + if ( renderer ) + delete ( renderer ); + if ( beatDetect ) + delete ( beatDetect ); + if ( _pcm ) { + delete ( _pcm ); + _pcm = 0; + } -delete(_pipelineContext); + delete(_pipelineContext); + delete(_pipelineContext2); } unsigned projectM::initRenderToTexture() { - return renderer->initRenderToTexture(); + return renderer->initRenderToTexture(); } void projectM::projectM_resetTextures() { - renderer->ResetTextures(); + renderer->ResetTextures(); } projectM::projectM ( std::string config_file, int flags) : - beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pipelineContext(new PipelineContext()) +beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pipelineContext(new PipelineContext()), _pipelineContext2(new PipelineContext()) { - readConfig(config_file); - projectM_reset(); - projectM_resetGL(_settings.windowWidth, _settings.windowHeight); + readConfig(config_file); + projectM_reset(); + projectM_resetGL(_settings.windowWidth, _settings.windowHeight); } projectM::projectM(Settings settings, int flags): - beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pipelineContext(new PipelineContext()) +beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pipelineContext(new PipelineContext()), _pipelineContext2(new PipelineContext()) { readSettings(settings); projectM_reset(); @@ -124,99 +125,99 @@ projectM::projectM(Settings settings, int flags): bool projectM::writeConfig(const std::string & configFile, const Settings & settings) { - ConfigFile config ( configFile ); + ConfigFile config ( configFile ); - config.add("Mesh X", settings.meshX); - config.add("Mesh Y", settings.meshY); - config.add("Texture Size", settings.textureSize); - config.add("FPS", settings.fps); - config.add("Window Width", settings.windowWidth); - config.add("Window Height", settings.windowHeight); - config.add("Smooth Preset Duration", settings.smoothPresetDuration); - config.add("Preset Duration", settings.presetDuration); - config.add("Preset Path", settings.presetURL); - config.add("Title Font", settings.titleFontURL); - config.add("Menu Font", settings.menuFontURL); - 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("Mesh X", settings.meshX); + config.add("Mesh Y", settings.meshY); + config.add("Texture Size", settings.textureSize); + config.add("FPS", settings.fps); + config.add("Window Width", settings.windowWidth); + config.add("Window Height", settings.windowHeight); + config.add("Smooth Preset Duration", settings.smoothPresetDuration); + config.add("Preset Duration", settings.presetDuration); + config.add("Preset Path", settings.presetURL); + config.add("Title Font", settings.titleFontURL); + config.add("Menu Font", settings.menuFontURL); + 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); - std::fstream file(configFile.c_str()); - if (file) { - file << config; - return true; - } else - return false; + std::fstream file(configFile.c_str()); + if (file) { + file << config; + return true; + } else + return false; } void projectM::readConfig (const std::string & configFile ) { - std::cout << "[projectM] config file: " << configFile << std::endl; + std::cout << "[projectM] config file: " << configFile << std::endl; - ConfigFile config ( configFile ); - _settings.meshX = config.read ( "Mesh X", 32 ); - _settings.meshY = config.read ( "Mesh Y", 24 ); - _settings.textureSize = config.read ( "Texture Size", 512 ); - _settings.fps = config.read ( "FPS", 35 ); - _settings.windowWidth = config.read ( "Window Width", 512 ); - _settings.windowHeight = config.read ( "Window Height", 512 ); - _settings.smoothPresetDuration = config.read - ( "Smooth Preset Duration", config.read("Smooth Transition Duration", 10)); - _settings.presetDuration = config.read ( "Preset Duration", 15 ); + ConfigFile config ( configFile ); + _settings.meshX = config.read ( "Mesh X", 32 ); + _settings.meshY = config.read ( "Mesh Y", 24 ); + _settings.textureSize = config.read ( "Texture Size", 512 ); + _settings.fps = config.read ( "FPS", 35 ); + _settings.windowWidth = config.read ( "Window Width", 512 ); + _settings.windowHeight = config.read ( "Window Height", 512 ); + _settings.smoothPresetDuration = config.read + ( "Smooth Preset Duration", config.read("Smooth Transition Duration", 10)); + _settings.presetDuration = config.read ( "Preset Duration", 15 ); - #ifdef LINUX - _settings.presetURL = config.read ( "Preset Path", CMAKE_INSTALL_PREFIX "/share/projectM/presets" ); - #endif + #ifdef LINUX + _settings.presetURL = config.read ( "Preset Path", CMAKE_INSTALL_PREFIX "/share/projectM/presets" ); + #endif - #ifdef __APPLE__ - /// @bug awful hardcoded hack- need to add intelligence to cmake wrt bundling - carm - _settings.presetURL = config.read ( "Preset Path", "../Resources/presets" ); - #endif + #ifdef __APPLE__ + /// @bug awful hardcoded hack- need to add intelligence to cmake wrt bundling - carm + _settings.presetURL = config.read ( "Preset Path", "../Resources/presets" ); + #endif - #ifdef WIN32 - _settings.presetURL = config.read ( "Preset Path", CMAKE_INSTALL_PREFIX "/share/projectM/presets" ); - #endif + #ifdef WIN32 + _settings.presetURL = config.read ( "Preset Path", CMAKE_INSTALL_PREFIX "/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"); - #endif + #ifdef __APPLE__ + _settings.titleFontURL = config.read + ( "Title Font", "../Resources/fonts/Vera.tff"); + _settings.menuFontURL = config.read + ( "Menu Font", "../Resources/fonts/VeraMono.ttf"); + #endif - #ifdef LINUX - _settings.titleFontURL = config.read - ( "Title Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/Vera.ttf" ); - _settings.menuFontURL = config.read - ( "Menu Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/VeraMono.ttf" ); - #endif + #ifdef LINUX + _settings.titleFontURL = config.read + ( "Title Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/Vera.ttf" ); + _settings.menuFontURL = config.read + ( "Menu Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/VeraMono.ttf" ); + #endif - #ifdef WIN32 - _settings.titleFontURL = config.read - ( "Title Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/Vera.ttf" ); - _settings.menuFontURL = config.read - ( "Menu Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/VeraMono.ttf" ); - #endif + #ifdef WIN32 + _settings.titleFontURL = config.read + ( "Title Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/Vera.ttf" ); + _settings.menuFontURL = config.read + ( "Menu Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/VeraMono.ttf" ); + #endif - _settings.shuffleEnabled = config.read ( "Shuffle Enabled", true); + _settings.shuffleEnabled = config.read ( "Shuffle Enabled", true); - _settings.easterEgg = config.read ( "Easter Egg Parameter", 0.0); + _settings.easterEgg = config.read ( "Easter Egg Parameter", 0.0); - projectM_init ( _settings.meshX, _settings.meshY, _settings.fps, - _settings.textureSize, _settings.windowWidth,_settings.windowHeight); + projectM_init ( _settings.meshX, _settings.meshY, _settings.fps, + _settings.textureSize, _settings.windowWidth,_settings.windowHeight); - _settings.beatSensitivity = beatDetect->beat_sensitivity = config.read ( "Hard Cut Sensitivity", 10.0 ); + _settings.beatSensitivity = beatDetect->beat_sensitivity = config.read ( "Hard Cut Sensitivity", 10.0 ); - if ( config.read ( "Aspect Correction", true ) ) - _settings.aspectCorrection = renderer->correction = true; - else - _settings.aspectCorrection = renderer->correction = false; + if ( config.read ( "Aspect Correction", true ) ) + _settings.aspectCorrection = renderer->correction = true; + else + _settings.aspectCorrection = renderer->correction = false; } @@ -245,555 +246,559 @@ void projectM::readSettings (const Settings & settings ) _settings.textureSize, _settings.windowWidth,_settings.windowHeight); - _settings.beatSensitivity = settings.beatSensitivity; - _settings.aspectCorrection = settings.aspectCorrection; + _settings.beatSensitivity = settings.beatSensitivity; + _settings.aspectCorrection = settings.aspectCorrection; } #ifdef USE_THREADS static void *thread_callback(void *prjm) { - projectM *p = (projectM *)prjm; + projectM *p = (projectM *)prjm; - p->thread_func(prjm); -return NULL;} + p->thread_func(prjm); + return NULL;} -void *projectM::thread_func(void *vptr_args) -{ - pthread_mutex_lock( &mutex ); - // printf("in thread: %f\n", timeKeeper->PresetProgressB()); - while (true) + void *projectM::thread_func(void *vptr_args) { - pthread_cond_wait( &condition, &mutex ); - if(!running) - { - pthread_mutex_unlock( &mutex ); - return NULL; - } - evaluateSecondPreset(); + pthread_mutex_lock( &mutex ); + // printf("in thread: %f\n", timeKeeper->PresetProgressB()); + while (true) + { + pthread_cond_wait( &condition, &mutex ); + if(!running) + { + pthread_mutex_unlock( &mutex ); + return NULL; + } + evaluateSecondPreset(); + } } -} -#endif + #endif -void projectM::evaluateSecondPreset() -{ + void projectM::evaluateSecondPreset() + { + pipelineContext2().time = timeKeeper->GetRunningTime(); + pipelineContext2().frame = timeKeeper->PresetFrameB(); + pipelineContext2().progress = timeKeeper->PresetProgressB(); + + m_activePreset2->Render(*beatDetect, pipelineContext2()); + } + + void projectM::renderFrame() + { + + #ifdef DEBUG + char fname[1024]; + FILE *f = NULL; + int index = 0; + int x, y; + #endif + + timeKeeper->UpdateTimers(); /* - m_activePreset2->presetInputs().frame = timeKeeper->PresetFrameB(); - m_activePreset2->presetInputs().progress= timeKeeper->PresetProgressB(); + if (timeKeeper->IsSmoothing()) + { + printf("Smoothing A:%f, B:%f, S:%f\n", timeKeeper->PresetProgressA(), timeKeeper->PresetProgressB(), timeKeeper->SmoothRatio()); + } + else + { + printf(" A:%f\n", timeKeeper->PresetProgressA()); + }*/ - assert ( m_activePreset2.get() ); - m_activePreset2->evaluateFrame(); - m_activePreset2->presetOutputs().Render(*beatDetect,presetInputs2); -*/ + mspf= ( int ) ( 1000.0/ ( float ) settings().fps ); //milliseconds per frame -} + /// @bug whois is responsible for updating this now?" + pipelineContext().time = timeKeeper->GetRunningTime(); + pipelineContext().frame = timeKeeper->PresetFrameA(); + pipelineContext().progress = timeKeeper->PresetProgressA(); -void projectM::renderFrame() -{ + //m_activePreset->Render(*beatDetect, pipelineContext()); -#ifdef DEBUG - char fname[1024]; - FILE *f = NULL; - int index = 0; - int x, y; -#endif + beatDetect->detectFromSamples(); - timeKeeper->UpdateTimers(); + //m_activePreset->evaluateFrame(); - //printf("A:%f, B:%f, S:%f\n", timeKeeper->PresetProgressA(), timeKeeper->PresetProgressB(), timeKeeper->SmoothRatio()); + //if the preset isn't locked and there are more presets + if ( renderer->noSwitch==false && !m_presetChooser->empty() ) + { + //if preset is done and we're not already switching + if ( timeKeeper->PresetProgressA()>=1.0 && !timeKeeper->IsSmoothing()) + { - mspf= ( int ) ( 1000.0/ ( float ) settings().fps ); //milliseconds per frame + timeKeeper->StartSmoothing(); + switchPreset(m_activePreset2); - /// @bug whois is responsible for updating this now?" - pipelineContext().time = timeKeeper->GetRunningTime(); - pipelineContext().frame = timeKeeper->PresetFrameA(); - pipelineContext().progress = timeKeeper->PresetProgressA(); + // Compute best matching between the render items. + /* + (*_matcher)(m_activePreset.get()->pipeline().drawables, + m_activePreset2.get()->pipeline().drawables); + */ + presetSwitchedEvent(false, **m_presetPos); + } - m_activePreset->Render(*beatDetect, pipelineContext()); + else if ((beatDetect->vol-beatDetect->vol_old>beatDetect->beat_sensitivity ) && + timeKeeper->CanHardCut()) + { + // printf("Hard Cut\n"); - beatDetect->detectFromSamples(); + switchPreset(m_activePreset); - //m_activePreset->evaluateFrame(); + //fz(m_activePreset, presetInputs, presetOutputs); - if ( renderer->noSwitch==false && !m_presetChooser->empty() ) - { - if ( timeKeeper->PresetProgressA()>=1.0 && !timeKeeper->IsSmoothing()) - { - - timeKeeper->StartSmoothing(); - switchPreset(m_activePreset2); - - // Compute best matching between the render items. - (*_matcher)(m_activePreset.get()->pipeline().drawables, - m_activePreset2.get()->pipeline().drawables); - - presetSwitchedEvent(false, **m_presetPos); - } - - else if ((beatDetect->vol-beatDetect->vol_old>beatDetect->beat_sensitivity ) && - timeKeeper->CanHardCut()) - { - // printf("Hard Cut\n"); - - switchPreset(m_activePreset); - - //fz(m_activePreset, presetInputs, presetOutputs); - - timeKeeper->StartPreset(); - presetSwitchedEvent(true, **m_presetPos); - } - } + timeKeeper->StartPreset(); + presetSwitchedEvent(true, **m_presetPos); + } + } - 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_activePreset.get() ); + // printf("start thread\n"); + assert ( m_activePreset2.get() ); -#ifdef USE_THREADS - pthread_cond_signal(&condition); - pthread_mutex_unlock( &mutex ); -#endif - m_activePreset->Render(*beatDetect, pipelineContext()); + #ifdef USE_THREADS + pthread_cond_signal(&condition); + pthread_mutex_unlock( &mutex ); + #endif + m_activePreset->Render(*beatDetect, pipelineContext()); -#ifdef USE_THREADS - pthread_mutex_lock( &mutex ); -#else - evaluateSecondPreset(); -#endif + #ifdef USE_THREADS + pthread_mutex_lock( &mutex ); + #else + evaluateSecondPreset(); + #endif - //PresetMerger::MergePresets(m_activePreset->presetOutputs(), m_activePreset2->presetOutputs(), - // timeKeeper->SmoothRatio(), presetInputs.gx, presetInputs.gy); + //PresetMerger::MergePresets(m_activePreset->presetOutputs(), m_activePreset2->presetOutputs(), + // timeKeeper->SmoothRatio(), presetInputs.gx, presetInputs.gy); - Pipeline pipeline; + Pipeline pipeline; - pipeline.setStaticPerPixel(settings().meshX, settings().meshY); + pipeline.setStaticPerPixel(settings().meshX, settings().meshY); - assert(_matcher); - PipelineMerger::mergePipelines( m_activePreset->pipeline(), - m_activePreset2->pipeline(), pipeline, _matcher->matchResults(), - *_merger, 1.0 - timeKeeper->SmoothRatio()); + assert(_matcher); + PipelineMerger::mergePipelines( m_activePreset->pipeline(), + m_activePreset2->pipeline(), pipeline, _matcher->matchResults(), + *_merger, timeKeeper->SmoothRatio()); - /// @bug not sure if this is correct - renderer->RenderFrame(pipeline, pipelineContext()); + /// @bug not sure if this is correct + renderer->RenderFrame(pipeline, pipelineContext()); - for (int i = 0; i < _matcher->matchResults().matches.size(); i++) { - //delete(pipeline.drawables[i]); - } - pipeline.drawables.clear(); - } - else - { - if ( timeKeeper->IsSmoothing() && timeKeeper->SmoothRatio() > 1.0 ) - { - //printf("End Smooth\n"); - m_activePreset = m_activePreset2; - timeKeeper->EndSmoothing(); - } - //printf("Normal\n"); + for (int i = 0; i < _matcher->matchResults().matches.size(); i++) { + //delete(pipeline.drawables[i]); + } + pipeline.drawables.clear(); + } + else + { + if ( timeKeeper->IsSmoothing() && timeKeeper->SmoothRatio() > 1.0 ) + { + //printf("End Smooth\n"); + m_activePreset = m_activePreset2; + timeKeeper->EndSmoothing(); + } + //printf("Normal\n"); - m_activePreset->Render(*beatDetect, pipelineContext()); + m_activePreset->Render(*beatDetect, pipelineContext()); -// m_activePreset->evaluateFrame(); -// m_activePreset->presetOutputs().Render(*beatDetect,presetInputs); + // m_activePreset->evaluateFrame(); + // m_activePreset->presetOutputs().Render(*beatDetect,presetInputs); - renderer->RenderFrame (m_activePreset->pipeline(), pipelineContext()); - } + renderer->RenderFrame (m_activePreset->pipeline(), pipelineContext()); + } - // std::cout<< m_activePreset->absoluteFilePath()<presetName = m_activePreset->absoluteFilePath(); + // std::cout<< m_activePreset->absoluteFilePath()<presetName = m_activePreset->absoluteFilePath(); - count++; -#ifndef WIN32 - /** Frame-rate limiter */ - /** Compute once per preset */ - if ( this->count%100==0 ) - { - this->renderer->realfps=100.0/ ( ( getTicks ( &timeKeeper->startTime )-this->fpsstart ) /1000 ); - this->fpsstart=getTicks ( &timeKeeper->startTime ); - } + count++; + #ifndef WIN32 + /** Frame-rate limiter */ + /** Compute once per preset */ + if ( this->count%100==0 ) + { + this->renderer->realfps=100.0/ ( ( getTicks ( &timeKeeper->startTime )-this->fpsstart ) /1000 ); + this->fpsstart=getTicks ( &timeKeeper->startTime ); + } - int timediff = getTicks ( &timeKeeper->startTime )-this->timestart; + int timediff = getTicks ( &timeKeeper->startTime )-this->timestart; - if ( timediff < this->mspf ) - { - // printf("%s:",this->mspf-timediff); - int sleepTime = ( unsigned int ) ( this->mspf-timediff ) * 1000; -// DWRITE ( "usleep: %d\n", sleepTime ); - if ( sleepTime > 0 && sleepTime < 100000 ) - { - if ( usleep ( sleepTime ) != 0 ) {}} - } - this->timestart=getTicks ( &timeKeeper->startTime ); -#endif /** !WIN32 */ + if ( timediff < this->mspf ) + { + // printf("%s:",this->mspf-timediff); + int sleepTime = ( unsigned int ) ( this->mspf-timediff ) * 1000; + // DWRITE ( "usleep: %d\n", sleepTime ); + if ( sleepTime > 0 && sleepTime < 100000 ) + { + if ( usleep ( sleepTime ) != 0 ) {}} + } + this->timestart=getTicks ( &timeKeeper->startTime ); + #endif /** !WIN32 */ -} + } -void projectM::projectM_reset() -{ - this->mspf = 0; - this->timed = 0; - this->timestart = 0; - this->count = 0; + void projectM::projectM_reset() + { + this->mspf = 0; + this->timed = 0; + this->timestart = 0; + this->count = 0; - this->fpsstart = 0; + this->fpsstart = 0; - projectM_resetengine(); -} + projectM_resetengine(); + } -void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, int height ) -{ + void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, int height ) + { - /** Initialise start time */ + /** Initialise start time */ timeKeeper = new TimeKeeper(_settings.presetDuration,_settings.smoothPresetDuration, _settings.easterEgg); - /** Nullify frame stash */ + /** Nullify frame stash */ - /** Initialise per-pixel matrix calculations */ - /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */ - assert ( !beatDetect ); + /** Initialise per-pixel matrix calculations */ + /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */ + assert ( !beatDetect ); - if (!_pcm) - _pcm = new PCM(); - assert(pcm()); - beatDetect = new BeatDetect ( _pcm ); + if (!_pcm) + _pcm = new PCM(); + assert(pcm()); + beatDetect = new BeatDetect ( _pcm ); - if ( _settings.fps > 0 ) - mspf= ( int ) ( 1000.0/ ( float ) _settings.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 ); + 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; - //renderer->SetPipeline(presetOutputs); - running = true; + running = true; - initPresetTools(gx, gy); + initPresetTools(gx, gy); -#ifdef USE_THREADS - pthread_mutex_init(&mutex, NULL); - pthread_cond_init(&condition, NULL); - if (pthread_create(&thread, NULL, thread_callback, this) != 0) - { + #ifdef USE_THREADS + pthread_mutex_init(&mutex, NULL); + pthread_cond_init(&condition, NULL); + if (pthread_create(&thread, NULL, thread_callback, this) != 0) + { - 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 + 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 - /// @bug order of operatoins here is busted - //renderer->setPresetName ( m_activePreset->name() ); - timeKeeper->StartPreset(); - assert(pcm()); + /// @bug order of operatoins here is busted + //renderer->setPresetName ( m_activePreset->name() ); + timeKeeper->StartPreset(); + assert(pcm()); -} + } -/* Reinitializes the engine variables to a default (conservative and sane) value */ -void projectM::projectM_resetengine() -{ + /* Reinitializes the engine variables to a default (conservative and sane) value */ + void projectM::projectM_resetengine() + { - if ( beatDetect != NULL ) - { - beatDetect->reset(); - } + if ( beatDetect != NULL ) + { + beatDetect->reset(); + } - /// @bug call factory clear here? - std::cerr << "call factory clear here?" << std::endl; -// abort(); + /// @bug call factory clear here? + std::cerr << "call factory clear here?" << std::endl; + // abort(); -} + } -/** Resets OpenGL state */ -void projectM::projectM_resetGL ( int w, int h ) -{ + /** Resets OpenGL state */ + void projectM::projectM_resetGL ( int w, int h ) + { - /** Stash the new dimensions */ + /** Stash the new dimensions */ - renderer->reset ( w,h ); -} + renderer->reset ( w,h ); + } -/** Sets the title to display */ -void projectM::projectM_setTitle ( std::string title ) { + /** Sets the title to display */ + void projectM::projectM_setTitle ( std::string title ) { - if ( title != renderer->title ) - { - renderer->title=title; - renderer->drawtitle=1; - } -} + if ( title != renderer->title ) + { + renderer->title=title; + renderer->drawtitle=1; + } + } -int projectM::initPresetTools(int gx, int gy) -{ + int projectM::initPresetTools(int gx, int gy) + { - /* Set the seed to the current time in seconds */ - srand ( time ( NULL ) ); + /* Set the seed to the current time in seconds */ + srand ( time ( NULL ) ); - std::string url = (m_flags & FLAG_DISABLE_PLAYLIST_LOAD) ? std::string() : settings().presetURL; + std::string url = (m_flags & FLAG_DISABLE_PLAYLIST_LOAD) ? std::string() : settings().presetURL; - if ( ( m_presetLoader = new PresetLoader ( gx, gy, url) ) == 0 ) - { - m_presetLoader = 0; - std::cerr << "[projectM] error allocating preset loader" << std::endl; - return PROJECTM_FAILURE; - } + if ( ( m_presetLoader = new PresetLoader ( gx, gy, url) ) == 0 ) + { + m_presetLoader = 0; + std::cerr << "[projectM] error allocating preset loader" << std::endl; + return PROJECTM_FAILURE; + } - if ( ( m_presetChooser = new PresetChooser ( *m_presetLoader ) ) == 0 ) - { - delete ( m_presetLoader ); + if ( ( m_presetChooser = new PresetChooser ( *m_presetLoader ) ) == 0 ) + { + delete ( m_presetLoader ); - m_presetChooser = 0; - m_presetLoader = 0; + m_presetChooser = 0; + m_presetLoader = 0; - std::cerr << "[projectM] error allocating preset chooser" << std::endl; - return PROJECTM_FAILURE; - } + std::cerr << "[projectM] error allocating preset chooser" << std::endl; + return PROJECTM_FAILURE; + } - // Start the iterator - if (!m_presetPos) - m_presetPos = new PresetIterator(); + // Start the iterator + if (!m_presetPos) + m_presetPos = new PresetIterator(); - // Initialize a preset queue position as well -// m_presetQueuePos = new PresetIterator(); + // Initialize a preset queue position as well + // m_presetQueuePos = new PresetIterator(); - // Start at end ptr- this allows next/previous to easily be done from this position. - *m_presetPos = m_presetChooser->end(); + // Start at end ptr- this allows next/previous to easily be done from this position. + *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"); + // 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"); - renderer->SetPipeline(m_activePreset->pipeline()); + renderer->SetPipeline(m_activePreset->pipeline()); - // 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; - } + // 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; + } - _matcher = new RenderItemMatcher(); - _merger = new MasterRenderItemMerge(); - //_merger->add(new WaveFormMergeFunction()); - _merger->add(new ShapeMerge()); - _merger->add(new BorderMerge()); - //_merger->add(new BorderMergeFunction()); + _matcher = new RenderItemMatcher(); + _merger = new MasterRenderItemMerge(); + //_merger->add(new WaveFormMergeFunction()); + _merger->add(new ShapeMerge()); + _merger->add(new BorderMerge()); + //_merger->add(new BorderMergeFunction()); - /// @bug These should be requested by the preset factories. - _matcher->distanceFunction().addMetric(new ShapeXYDistance()); + /// @bug These should be requested by the preset factories. + _matcher->distanceFunction().addMetric(new ShapeXYDistance()); - //std::cerr << "[projectM] Idle preset allocated." << std::endl; + //std::cerr << "[projectM] Idle preset allocated." << std::endl; - projectM_resetengine(); + projectM_resetengine(); - //std::cerr << "[projectM] engine has been reset." << std::endl; - return PROJECTM_SUCCESS; -} + //std::cerr << "[projectM] engine has been reset." << std::endl; + return PROJECTM_SUCCESS; + } -void projectM::destroyPresetTools() -{ + void projectM::destroyPresetTools() + { - if ( m_presetPos ) - delete ( m_presetPos ); + if ( m_presetPos ) + delete ( m_presetPos ); - /// @slow might not be necessary - m_presetPos = 0; + /// @slow might not be necessary + m_presetPos = 0; - if ( m_presetChooser ) - delete ( m_presetChooser ); + if ( m_presetChooser ) + delete ( m_presetChooser ); - /// @slow might not be necessary - m_presetChooser = 0; + /// @slow might not be necessary + m_presetChooser = 0; - if ( m_presetLoader ) - delete ( m_presetLoader ); + if ( m_presetLoader ) + delete ( m_presetLoader ); - /// @slow might not be necessary - m_presetLoader = 0; + /// @slow might not be necessary + m_presetLoader = 0; -} + } -/// @bug queuePreset case isn't handled -void projectM::removePreset(unsigned int index) { + /// @bug queuePreset case isn't handled + void projectM::removePreset(unsigned int index) { - unsigned int chooserIndex = **m_presetPos; + unsigned int chooserIndex = **m_presetPos; - m_presetLoader->removePreset(index); + m_presetLoader->removePreset(index); - // Case: no more presets, set iterator to end - if (m_presetChooser->empty()) - *m_presetPos = m_presetChooser->end(); + // 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: 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(); - } + // Case: we have deleted the active preset position + // Set iterator to end of chooser + else if (chooserIndex == index) { + *m_presetPos = m_presetChooser->end(); + } -} + } -unsigned int projectM::addPresetURL ( const std::string & presetURL, const std::string & presetName, int rating ) -{ - bool restorePosition = false; + unsigned int projectM::addPresetURL ( const std::string & presetURL, const std::string & presetName, int rating ) + { + bool restorePosition = false; - if (*m_presetPos == m_presetChooser->end()) - restorePosition = true; + if (*m_presetPos == m_presetChooser->end()) + restorePosition = true; - int index = m_presetLoader->addPresetURL ( presetURL, presetName, rating); + int index = m_presetLoader->addPresetURL ( presetURL, presetName, rating); - if (restorePosition) - *m_presetPos = m_presetChooser->end(); + if (restorePosition) + *m_presetPos = m_presetChooser->end(); - return index; -} + return index; + } -void projectM::selectPreset ( unsigned int index ) -{ + void projectM::selectPreset ( unsigned int index ) + { - if ( m_presetChooser->empty() ) - return; + if ( m_presetChooser->empty() ) + return; - assert ( index < m_presetLoader->size()); - assert ( index >= 0 ); + assert ( index < m_presetLoader->size()); + assert ( index >= 0 ); - *m_presetPos = m_presetChooser->begin ( index ); + *m_presetPos = m_presetChooser->begin ( index ); - m_activePreset = m_presetPos->allocate (); + m_activePreset = m_presetPos->allocate (); - renderer->setPresetName ( m_activePreset->name() ); + renderer->setPresetName ( m_activePreset->name() ); - timeKeeper->StartPreset(); -} + timeKeeper->StartPreset(); + } -void projectM::switchPreset(std::auto_ptr & targetPreset) { + void projectM::switchPreset(std::auto_ptr & targetPreset) { - if (_settings.shuffleEnabled) - *m_presetPos = m_presetChooser->weightedRandom(); - else - m_presetChooser->nextPreset(*m_presetPos); + if (_settings.shuffleEnabled) + *m_presetPos = m_presetChooser->weightedRandom(); + else + m_presetChooser->nextPreset(*m_presetPos); - targetPreset = m_presetPos->allocate(); + targetPreset = m_presetPos->allocate(); - // Set preset name here- event is not done because at the moment this function is oblivious to smooth/hard switches - renderer->setPresetName ( targetPreset->name() ); - renderer->SetPipeline(targetPreset->pipeline()); + // Set preset name here- event is not done because at the moment this function is oblivious to smooth/hard switches + renderer->setPresetName ( targetPreset->name() ); + renderer->SetPipeline(targetPreset->pipeline()); -} + } -void projectM::setPresetLock ( bool isLocked ) -{ - renderer->noSwitch = isLocked; -} + void projectM::setPresetLock ( bool isLocked ) + { + renderer->noSwitch = isLocked; + } -bool projectM::isPresetLocked() const -{ - return renderer->noSwitch; -} + bool projectM::isPresetLocked() const + { + return renderer->noSwitch; + } -std::string projectM::getPresetURL ( unsigned int index ) const -{ - return m_presetLoader->getPresetURL(index); -} + std::string projectM::getPresetURL ( unsigned int index ) const + { + return m_presetLoader->getPresetURL(index); + } -int projectM::getPresetRating ( unsigned int index ) const -{ - return m_presetLoader->getPresetRating(index); -} + int projectM::getPresetRating ( unsigned int index ) const + { + return m_presetLoader->getPresetRating(index); + } -std::string projectM::getPresetName ( unsigned int index ) const -{ - return m_presetLoader->getPresetName(index); -} + std::string projectM::getPresetName ( unsigned int index ) const + { + return m_presetLoader->getPresetName(index); + } -void projectM::clearPlaylist ( ) -{ - m_presetLoader->clear(); - *m_presetPos = m_presetChooser->end(); -} + void projectM::clearPlaylist ( ) + { + m_presetLoader->clear(); + *m_presetPos = m_presetChooser->end(); + } -void projectM::selectPresetPosition(unsigned int index) { - *m_presetPos = m_presetChooser->begin(index); -} + void projectM::selectPresetPosition(unsigned int index) { + *m_presetPos = m_presetChooser->begin(index); + } -bool projectM::selectedPresetIndex(unsigned int & index) const { + bool projectM::selectedPresetIndex(unsigned int & index) const { - if (*m_presetPos == m_presetChooser->end()) - return false; + if (*m_presetPos == m_presetChooser->end()) + return false; - index = **m_presetPos; - return true; -} + index = **m_presetPos; + return true; + } -bool projectM::presetPositionValid() const { + bool projectM::presetPositionValid() const { - return (*m_presetPos != m_presetChooser->end()); -} + return (*m_presetPos != m_presetChooser->end()); + } -unsigned int projectM::getPlaylistSize() const -{ - return m_presetLoader->size(); -} + unsigned int projectM::getPlaylistSize() const + { + return m_presetLoader->size(); + } -void projectM:: changePresetRating (unsigned int index, int rating) { - m_presetLoader->setRating(index, rating); -} + void projectM:: changePresetRating (unsigned int index, int rating) { + m_presetLoader->setRating(index, rating); + } -void projectM::insertPresetURL(unsigned int index, const std::string & presetURL, const std::string & presetName, int rating) -{ - bool atEndPosition = false; + void projectM::insertPresetURL(unsigned int index, const std::string & presetURL, const std::string & presetName, int rating) + { + bool atEndPosition = false; - int newSelectedIndex; + int newSelectedIndex; - if (*m_presetPos == m_presetChooser->end()) // Case: preset not selected - { - atEndPosition = true; - } + 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 before selected preset + { + newSelectedIndex = **m_presetPos; + } - else if (**m_presetPos > index) // Case: inserting after selected preset - { - newSelectedIndex++; - } + else if (**m_presetPos > index) // Case: inserting after selected preset + { + newSelectedIndex++; + } - else // Case: inserting at selected preset - { - newSelectedIndex++; - } + else // Case: inserting at selected preset + { + newSelectedIndex++; + } - m_presetLoader->insertPresetURL (index, presetURL, presetName, rating); + m_presetLoader->insertPresetURL (index, presetURL, presetName, rating); - if (atEndPosition) - *m_presetPos = m_presetChooser->end(); - else - *m_presetPos = m_presetChooser->begin(newSelectedIndex); + if (atEndPosition) + *m_presetPos = m_presetChooser->end(); + else + *m_presetPos = m_presetChooser->begin(newSelectedIndex); -} + } diff --git a/src/libprojectM/projectM.hpp b/src/libprojectM/projectM.hpp index c523604cb..0889d3832 100755 --- a/src/libprojectM/projectM.hpp +++ b/src/libprojectM/projectM.hpp @@ -250,6 +250,7 @@ public: } void *thread_func(void *vptr_args); PipelineContext & pipelineContext() { return *_pipelineContext; } + PipelineContext & pipelineContext2() { return *_pipelineContext2; } private: PCM * _pcm; @@ -257,6 +258,7 @@ private: BeatDetect * beatDetect; Renderer *renderer; PipelineContext * _pipelineContext; + PipelineContext * _pipelineContext2; Settings _settings;