diff --git a/src/libprojectM/CMakeLists.txt b/src/libprojectM/CMakeLists.txt index 1d9411b7c..2da39f833 100644 --- a/src/libprojectM/CMakeLists.txt +++ b/src/libprojectM/CMakeLists.txt @@ -1,4 +1,5 @@ PROJECT(projectM) +cmake_minimum_required(VERSION 2.6.0) OPTION (USE_DEVIL "Use devIL for image loading rather than the builtin SOIL library" OFF) @@ -32,7 +33,7 @@ Func.cpp Eval.cpp PerFrameEqn.cpp PerPointEqn.cpp fftsg.cpp KeyHandler.cpp timer.cpp wipemalloc.cpp BuiltinFuncs.cpp BuiltinParams.cpp Renderer.cpp PresetLoader.cpp PresetChooser.cpp PresetFrameIO.cpp PresetMerge.cpp PipelineContext.cpp ConfigFile.cpp IdlePreset.cpp TextureManager.cpp TimeKeeper.cpp Filters.cpp Renderable.cpp Pipeline.cpp PerPixelMesh.cpp -MilkdropWaveform.cpp Waveform.cpp VideoEcho.cpp Shader.cpp PerlinNoise.cpp UserTexture.cpp ShaderEngine.cpp ${GLEW_SOURCES}) +MilkdropWaveform.cpp Waveform.cpp VideoEcho.cpp Shader.cpp PerlinNoise.cpp UserTexture.cpp ShaderEngine.cpp Common.cpp ${GLEW_SOURCES}) if (USE_DEVIL) SET (projectM_SOURCES ${projectM_SOURCES}) diff --git a/src/libprojectM/Common.hpp b/src/libprojectM/Common.hpp index 60cb4c16f..a617c2aac 100755 --- a/src/libprojectM/Common.hpp +++ b/src/libprojectM/Common.hpp @@ -133,6 +133,23 @@ extern FILE *fmemopen(void *buf, size_t len, const char *pMode); #else #define PATH_SEPARATOR UNIX_PATH_SEPARATOR #endif /** WIN32 */ +#include + +const std::string PROJECTM_FILE_EXTENSION("prjm"); +const std::string MILKDROP_FILE_EXTENSION("milk"); +const std::string PROJECTM_MODULE_EXTENSION("so"); + + +inline std::string parseExtension(const std::string & filename) { + +std::size_t start = filename.find_last_of('.'); + +if (start == std::string::npos || start >= (filename.length()-1)) + return ""; +else + return filename.substr(start+1, filename.length()); + +} inline void DWRITE( char *fmt, ... ) { return; diff --git a/src/libprojectM/Expr.cpp b/src/libprojectM/Expr.cpp index e830b0af2..bee57e3db 100755 --- a/src/libprojectM/Expr.cpp +++ b/src/libprojectM/Expr.cpp @@ -43,9 +43,6 @@ float GenExpr::eval_gen_expr ( int mesh_i, int mesh_j ) case TREE_T: return ( ( TreeExpr* ) ( item ) )->eval_tree_expr ( mesh_i, mesh_j ); default: -#ifdef EVAL_DEBUG - DWRITE ( "eval_gen_expr: general expression matched no cases!\n" ); -#endif return EVAL_ERROR; } @@ -62,28 +59,16 @@ float PrefunExpr::eval_prefun_expr ( int mesh_i, int mesh_j ) assert(arg_list); -#ifdef EVAL_DEBUG_DOUBLE - DWRITE ( "fn[" ); -#endif - //printf("numargs %d", num_args); /* Evaluate each argument before calling the function itself */ for ( int i = 0; i < num_args; i++ ) { arg_list[i] = expr_list[i]->eval_gen_expr ( mesh_i, mesh_j ); -#ifdef EVAL_DEBUG_DOUBLE - if ( i < ( num_args - 1 ) ) - DWRITE ( ", " ); -#endif //printf("numargs %x", arg_list[i]); } -#ifdef EVAL_DEBUG_DOUBLE - DWRITE ( "]" ); -#endif - /* Now we call the function, passing a list of floats as its argument */ @@ -102,9 +87,6 @@ float ValExpr::eval_val_expr ( int mesh_i, int mesh_j ) /* Value is a constant, return the float value */ if ( type == CONSTANT_TERM_T ) { -#ifdef EVAL_DEBUG - DWRITE ( "%.4f", term.constant ); -#endif return ( term.constant ); } @@ -115,16 +97,10 @@ float ValExpr::eval_val_expr ( int mesh_i, int mesh_j ) { case P_TYPE_BOOL: -#ifdef EVAL_DEBUG - DWRITE ( "(%s:%.4f)", term.param->name.c_str(), ( float ) ( * ( ( bool* ) ( term.param->engine_val ) ) ) ); -#endif return ( float ) ( * ( ( bool* ) ( term.param->engine_val ) ) ); case P_TYPE_INT: -#ifdef EVAL_DEBUG - DWRITE ( "(%s:%.4f)", term.param->name.c_str(), ( float ) ( * ( ( int* ) ( term.param->engine_val ) ) ) ); -#endif return ( float ) ( * ( ( int* ) ( term.param->engine_val ) ) ); @@ -179,54 +155,12 @@ float TreeExpr::eval_tree_expr ( int mesh_i, int mesh_j ) /* Otherwise, this node is an infix operator. Evaluate accordingly */ -#ifdef EVAL_DEBUG - DWRITE ( "(" ); -#endif - assert(left); left_arg = left->eval_tree_expr ( mesh_i, mesh_j ); -#ifdef EVAL_DEBUG - - switch ( infix_op->type ) - { - case INFIX_ADD: - DWRITE ( "+" ); - break; - case INFIX_MINUS: - DWRITE ( "-" ); - break; - case INFIX_MULT: - DWRITE ( "*" ); - break; - case INFIX_MOD: - DWRITE ( "%%" ); - break; - case INFIX_OR: - DWRITE ( "|" ); - break; - case INFIX_AND: - DWRITE ( "&" ); - break; - case INFIX_DIV: - DWRITE ( "/" ); - break; - default: - DWRITE ( "?" ); - } - -#endif - assert(right); right_arg = right->eval_tree_expr ( mesh_i, mesh_j ); -#ifdef EVAL_DEBUG - DWRITE ( ")" ); -#endif - -#ifdef EVAL_DEBUG - DWRITE ( "\n" ); -#endif switch ( infix_op->type ) { @@ -239,9 +173,6 @@ float TreeExpr::eval_tree_expr ( int mesh_i, int mesh_j ) case INFIX_MOD: if ( ( int ) right_arg == 0 ) { -#ifdef EVAL_DEBUG - DWRITE ( "eval_tree_expr: modulo zero!\n" ); -#endif return PROJECTM_DIV_BY_ZERO; } return ( ( int ) left_arg % ( int ) right_arg ); @@ -252,16 +183,10 @@ float TreeExpr::eval_tree_expr ( int mesh_i, int mesh_j ) case INFIX_DIV: if ( right_arg == 0 ) { -#ifdef EVAL_DEBUG - DWRITE ( "eval_tree_expr: division by zero!\n" ); -#endif return MAX_DOUBLE_SIZE; } return ( left_arg / right_arg ); default: -#ifdef EVAL_DEBUG - DWRITE ( "eval_tree_expr: unknown infix operator!\n" ); -#endif return EVAL_ERROR; } diff --git a/src/libprojectM/IdlePreset.cpp b/src/libprojectM/IdlePreset.cpp index 83fc22dbf..f5146fbd1 100644 --- a/src/libprojectM/IdlePreset.cpp +++ b/src/libprojectM/IdlePreset.cpp @@ -2,6 +2,7 @@ #include #include +#if 0 const std::string IdlePreset::IDLE_PRESET_NAME ("Geiss & Sperl - Feedback (projectM idle HDR mix)"); @@ -201,6 +202,10 @@ std::auto_ptr IdlePreset::allocate( PresetInputs & presetInputs, PresetO { std::istringstream in(presetText()); - return std::auto_ptr(new Preset(in, IDLE_PRESET_NAME, presetInputs, presetOutputs)); + return std::auto_ptr(new Preset(in, IDLE_PRESET_NAME, p); + + std::cerr << "fix me" << std::endl; + abort(); } +#endif diff --git a/src/libprojectM/IdlePreset.hpp b/src/libprojectM/IdlePreset.hpp index 15738ed22..45266c66e 100644 --- a/src/libprojectM/IdlePreset.hpp +++ b/src/libprojectM/IdlePreset.hpp @@ -6,14 +6,12 @@ /// A preset that does not depend on the file system to be loaded. This allows projectM to render /// something (ie. self indulgent project advertisting) even when no valid preset directory is found. -class IdlePreset { +class IdlePresetFactory { public: /// Allocate a new idle preset instance - /// \param presetInputs the preset inputs instance to associate with the preset - /// \param presetOutputs the preset output instance to associate with the preset /// \returns a newly allocated auto pointer of an idle preset instance - static std::auto_ptr allocate(PresetInputs & presetInputs, PresetOutputs & presetOutputs); + std::auto_ptr allocate(); private: static std::string presetText(); static const std::string IDLE_PRESET_NAME; diff --git a/src/libprojectM/KeyHandler.cpp b/src/libprojectM/KeyHandler.cpp index 69cd8249a..dc54eb719 100755 --- a/src/libprojectM/KeyHandler.cpp +++ b/src/libprojectM/KeyHandler.cpp @@ -168,7 +168,7 @@ void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode case PROJECTM_K_n: m_presetChooser->nextPreset(*m_presetPos); presetSwitchedEvent(true, **m_presetPos); - m_activePreset = m_presetPos->allocate(this->presetInputs, this->presetOutputs); + m_activePreset = m_presetPos->allocate(); renderer->SetPipeline(presetOutputs); renderer->setPresetName(m_activePreset->name()); timeKeeper->StartPreset(); @@ -181,7 +181,7 @@ void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode *m_presetPos = m_presetChooser->weightedRandom(); presetSwitchedEvent(true, **m_presetPos); - m_activePreset = m_presetPos->allocate(this->presetInputs, this->presetOutputs); + m_activePreset = m_presetPos->allocate(); renderer->SetPipeline(presetOutputs); assert(m_activePreset.get()); @@ -208,7 +208,7 @@ void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode --(*m_presetPos); } - m_activePreset = m_presetPos->allocate(this->presetInputs, this->presetOutputs); + m_activePreset = m_presetPos->allocate(); renderer->SetPipeline(presetOutputs); renderer->setPresetName(m_activePreset->name()); diff --git a/src/libprojectM/Pipeline.cpp b/src/libprojectM/Pipeline.cpp index e442d0dc3..b6bc1b68e 100644 --- a/src/libprojectM/Pipeline.cpp +++ b/src/libprojectM/Pipeline.cpp @@ -44,6 +44,6 @@ if (staticPerPixel) } } -void Pipeline::Render(const BeatDetect &music, const PipelineContext &context){} +//void Pipeline::Render(const BeatDetect &music, const PipelineContext &context){} Point Pipeline::PerPixel(Point p, const PerPixelContext context) {return p;} diff --git a/src/libprojectM/PipelineContext.hpp b/src/libprojectM/PipelineContext.hpp index 576fb22d9..1b7f899e4 100644 --- a/src/libprojectM/PipelineContext.hpp +++ b/src/libprojectM/PipelineContext.hpp @@ -12,11 +12,12 @@ class PipelineContext { public: int fps; - float time; + float time; int frame; float progress; PipelineContext(); + virtual ~PipelineContext(); }; #endif /* PIPELINECONTEXT_HPP_ */ diff --git a/src/libprojectM/PresetChooser.hpp b/src/libprojectM/PresetChooser.hpp index 3971beb60..b11ae5512 100644 --- a/src/libprojectM/PresetChooser.hpp +++ b/src/libprojectM/PresetChooser.hpp @@ -43,14 +43,14 @@ public: /// \param presetInputs the preset inputs to associate with the preset upon construction /// \param presetOutputs the preset outputs to associate with the preset upon construction /// \returns an autopointer of the newly allocated preset - std::auto_ptr allocate( PresetInputs & presetInputs, PresetOutputs & presetOutputs); + std::auto_ptr allocate(); /// Set the chooser asocciated with this iterator void setChooser(const PresetChooser & chooser); private: - std::size_t m_currentIndex; - const PresetChooser * m_presetChooser; + std::size_t _currentIndex; + const PresetChooser * _presetChooser; }; @@ -70,14 +70,12 @@ public: /// \param presetInputs the preset inputs to associate with the preset upon construction /// \param presetOutputs the preset outputs to associate with the preset upon construction /// \returns an auto pointer of the newly allocated preset - std::auto_ptr directoryIndex(std::size_t index, PresetInputs & presetInputs, - PresetOutputs & presetOutputs) const; + std::auto_ptr directoryIndex(std::size_t index) const; /// Gets the number of presets last believed to exist in the preset loader's filename collection /// \returns the number of presets in the collection - std::size_t getNumPresets() const; - - + std::size_t size() const; + /// An STL-esque iterator to begin traversing presets from a directory /// \param index the index to begin iterating at. Assumed valid between [0, num presets) /// \returns the position of the first preset in the collection @@ -103,34 +101,34 @@ public: private: - const PresetLoader * m_presetLoader; + const PresetLoader * _presetLoader; }; -inline PresetChooser::PresetChooser(const PresetLoader & presetLoader):m_presetLoader(&presetLoader) {} +inline PresetChooser::PresetChooser(const PresetLoader & presetLoader):_presetLoader(&presetLoader) {} -inline std::size_t PresetChooser::getNumPresets() const { - return m_presetLoader->getNumPresets(); +inline std::size_t PresetChooser::size() const { + return _presetLoader->size(); } inline void PresetIterator::setChooser(const PresetChooser & chooser) { - m_presetChooser = &chooser; + _presetChooser = &chooser; } inline std::size_t PresetIterator::operator*() const { - return m_currentIndex; + return _currentIndex; } -inline PresetIterator::PresetIterator(std::size_t start):m_currentIndex(start) {} +inline PresetIterator::PresetIterator(std::size_t start):_currentIndex(start) {} inline void PresetIterator::operator++() { - assert(m_currentIndex < m_presetChooser->getNumPresets()); - m_currentIndex++; + assert(_currentIndex < _presetChooser->size()); + _currentIndex++; } inline void PresetIterator::operator--() { - assert(m_currentIndex > 0); - m_currentIndex--; + assert(_currentIndex > 0); + _currentIndex--; } inline bool PresetIterator::operator !=(const PresetIterator & presetPos) const { @@ -142,8 +140,8 @@ inline bool PresetIterator::operator ==(const PresetIterator & presetPos) const return (*presetPos == **this); } -inline std::auto_ptr PresetIterator::allocate( PresetInputs & presetInputs, PresetOutputs & presetOutputs) { - return m_presetChooser->directoryIndex(m_currentIndex, presetInputs, presetOutputs); +inline std::auto_ptr PresetIterator::allocate() { + return _presetChooser->directoryIndex(_currentIndex); } inline void PresetChooser::nextPreset(PresetIterator & presetPos) { @@ -178,26 +176,25 @@ inline PresetIterator PresetChooser::begin(unsigned int index) const{ } inline PresetIterator PresetChooser::end() const { - PresetIterator pos(m_presetLoader->getNumPresets()); + PresetIterator pos(_presetLoader->size()); pos.setChooser(*this); return pos; } inline bool PresetChooser::empty() const { - return m_presetLoader->getNumPresets() == 0; + return _presetLoader->size() == 0; } -inline std::auto_ptr PresetChooser::directoryIndex(std::size_t index, PresetInputs & presetInputs, - PresetOutputs & presetOutputs) const { +inline std::auto_ptr PresetChooser::directoryIndex(std::size_t index) const { - return m_presetLoader->loadPreset(index, presetInputs, presetOutputs); + return _presetLoader->loadPreset(index); } inline PresetChooser::iterator PresetChooser::weightedRandom() const { std::size_t index = RandomNumberGenerators::weightedRandom - (m_presetLoader->getPresetRatings(), m_presetLoader->getPresetRatingsSum()); + (_presetLoader->getPresetRatings(), _presetLoader->getPresetRatingsSum()); return begin(index); } diff --git a/src/libprojectM/PresetFactory.hpp b/src/libprojectM/PresetFactory.hpp new file mode 100644 index 000000000..9d3e1043e --- /dev/null +++ b/src/libprojectM/PresetFactory.hpp @@ -0,0 +1,37 @@ +// +// C++ Interface: PresetFactory +// +// Description: +// +// +// Author: Carmelo Piccione , (C) 2008 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "Preset.hpp" +#include + +#ifndef __PRESET_FACTORY_HPP +#define __PRESET_FACTORY_HPP + +class PresetFactory { + +public: + + + PresetFactory() {} + + virtual ~PresetFactory() {} + + /// Constructs a new preset given an url + /// \param url a locational identifier referencing the preset + /// \returns a valid preset object- otherwise + virtual std::auto_ptr allocate(std::string url, std::string name); + + + +}; + +#endif diff --git a/src/libprojectM/PresetLoader.cpp b/src/libprojectM/PresetLoader.cpp index ceaf5cf12..cb875d05e 100644 --- a/src/libprojectM/PresetLoader.cpp +++ b/src/libprojectM/PresetLoader.cpp @@ -11,6 +11,7 @@ // #include "PresetLoader.hpp" #include "Preset.hpp" +#include "PresetFactory.hpp" #include #include #include @@ -34,122 +35,120 @@ extern "C" #include "Common.hpp" -const std::string PresetLoader::PROJECTM_FILE_EXTENSION(".prjm"); -const std::string PresetLoader::MILKDROP_FILE_EXTENSION(".milk"); - -PresetLoader::PresetLoader(std::string dirname = std::string()) :m_dirname(dirname), m_dir(0), m_ratingsSum(0) +PresetLoader::PresetLoader ( std::string dirname = std::string() ) :_dirname ( dirname ), _dir ( 0 ), _ratingsSum ( 0 ) { - // Do one scan - if (m_dirname != std::string()) - rescan(); + // Do one scan + if ( _dirname != std::string() ) + rescan(); } PresetLoader::~PresetLoader() { - if (m_dir) - closedir(m_dir); + if ( _dir ) + closedir ( _dir ); } -void PresetLoader::setScanDirectory(std::string dirname) +void PresetLoader::setScanDirectory ( std::string dirname ) { - m_dirname = dirname; + _dirname = dirname; } void PresetLoader::rescan() { - // std::cerr << "Rescanning..." << std::endl; + // std::cerr << "Rescanning..." << std::endl; - // Clear the directory entry collection - m_entries.clear(); - m_presetNames.clear(); - m_ratings.clear(); - m_ratingsSum = 0; - // If directory already opened, close it first - if (m_dir) - { - closedir(m_dir); - m_dir = 0; - } + // Clear the directory entry collection + _entries.clear(); + _presetNames.clear(); + _ratings.clear(); + _ratingsSum = 0; + // If directory already opened, close it first + if ( _dir ) + { + closedir ( _dir ); + _dir = 0; + } - // Allocate a new a stream given the current directory name - if ((m_dir = opendir(m_dirname.c_str())) == NULL) - { - handleDirectoryError(); - return; // no files loaded. m_entries is empty - } + // Allocate a new a stream given the current directory name + if ( ( _dir = opendir ( _dirname.c_str() ) ) == NULL ) + { + handleDirectoryError(); + return; // no files loaded. _entries is empty + } - struct dirent * dir_entry; - std::set alphaSortedFileSet; - std::set alphaSortedPresetNameSet; - - while ((dir_entry = readdir(m_dir)) != NULL) - { + struct dirent * dir_entry; + std::set alphaSortedFileSet; + std::set alphaSortedPresetNameSet; - std::ostringstream out; - // Convert char * to friendly string - std::string filename(dir_entry->d_name); + while ( ( dir_entry = readdir ( _dir ) ) != NULL ) + { - // Verify extension is projectm or milkdrop - if ((filename.rfind(PROJECTM_FILE_EXTENSION) != (filename.length() - PROJECTM_FILE_EXTENSION.length())) - && (filename.rfind(MILKDROP_FILE_EXTENSION) != (filename.length() - MILKDROP_FILE_EXTENSION.length()))) - continue; + std::ostringstream out; + // Convert char * to friendly string + std::string filename ( dir_entry->d_name ); - if (filename.length() <= MILKDROP_FILE_EXTENSION.length()) - continue; + // Verify extension is projectm or milkdrop + if ( ( filename.rfind ( PROJECTM_FILE_EXTENSION ) != ( filename.length() - PROJECTM_FILE_EXTENSION.length() ) ) + && ( filename.rfind ( MILKDROP_FILE_EXTENSION ) != ( filename.length() - MILKDROP_FILE_EXTENSION.length() ) ) ) + continue; - if (filename.length() > 0 && filename[0] == '.') - continue; + if ( filename.length() <= MILKDROP_FILE_EXTENSION.length() ) + continue; - // Create full path name - out << m_dirname << PATH_SEPARATOR << filename; + if ( filename.length() > 0 && filename[0] == '.' ) + continue; - // Add to our directory entry collection - alphaSortedFileSet.insert(out.str()); - alphaSortedPresetNameSet.insert(filename); + // Create full path name + out << _dirname << PATH_SEPARATOR << filename; - // the directory entry struct is freed elsewhere - } + // Add to our directory entry collection + alphaSortedFileSet.insert ( out.str() ); + alphaSortedPresetNameSet.insert ( filename ); - // Push all entries in order from the file set to the file entries member (which is an indexed vector) - for (std::set::iterator pos = alphaSortedFileSet.begin(); - pos != alphaSortedFileSet.end();++pos) - m_entries.push_back(*pos); + // the directory entry struct is freed elsewhere + } + + // Push all entries in order from the file set to the file entries member (which is an indexed vector) + for ( std::set::iterator pos = alphaSortedFileSet.begin(); + pos != alphaSortedFileSet.end();++pos ) + _entries.push_back ( *pos ); + + // Push all preset names in similar fashion + for ( std::set::iterator pos = alphaSortedPresetNameSet.begin(); + pos != alphaSortedPresetNameSet.end();++pos ) + _presetNames.push_back ( *pos ); + + // Give all presets equal rating of 3 - why 3? I don't know + _ratings = std::vector ( _presetNames.size(), 3 ); + _ratingsSum = 3 * _ratings.size(); + + assert ( _entries.size() == _presetNames.size() ); + assert ( _ratings.size() == _entries.size() ); - // Push all preset names in similar fashion - for (std::set::iterator pos = alphaSortedPresetNameSet.begin(); - pos != alphaSortedPresetNameSet.end();++pos) - m_presetNames.push_back(*pos); - // Give all presets equal rating of 3 - why 3? I don't know - m_ratings = std::vector(m_presetNames.size(), 3); - m_ratingsSum = 3 * m_ratings.size(); - - assert(m_entries.size() == m_presetNames.size()); - assert(m_ratings.size() == m_entries.size()); - - } -/// Associates a preset loading handler a file extension. -/// Any subsequent call to an extension overrides the previously set handler. -/// \param extension the file extension to attach the handler to -/// \param handler a preset loading handler that will be associated with the extension -void PresetLoader::registerHandler(const std::string & extension, PresetLoadingHandler * handler) { +void PresetLoader::registerFactory ( const std::string & extension, PresetFactory * factory ) { + _factories[extension] = factory; +} -_handlers[extension'] = handler; -// } -std::auto_ptr PresetLoader::loadPreset(unsigned int index, PresetInputs & presetInputs, PresetOutputs & presetOutputs) const +std::auto_ptr PresetLoader::loadPreset ( unsigned int index ) const { - // Check that index isn't insane - assert(index >= 0); - assert(index < m_entries.size()); + // Check that index isn't insane + assert ( index >= 0 ); + assert ( index < _entries.size() ); - // Return a new autopointer to a preset - return std::auto_ptr(new Preset(m_entries[index], m_presetNames[index], presetInputs, presetOutputs)); + // Return a new autopointer to a preset + const std::string extension = parseExtension ( _entries[index] ); + + if ( !_factories.count ( extension ) ) + return std::auto_ptr ( 0 ); + else + return _factories[extension]->allocate ( _entries[index], _presetNames[index] ); } void PresetLoader::handleDirectoryError() @@ -159,99 +158,107 @@ void PresetLoader::handleDirectoryError() std::cerr << "[PresetLoader] warning: errno unsupported on win32 platforms. fix me" << std::endl; #else - switch (errno) - { - case ENOENT: - std::cerr << "[PresetLoader] ENOENT error. The path \"" << this->m_dirname << "\" probably does not exist. \"man open\" for more info." << std::endl; - break; - case ENOMEM: - std::cerr << "[PresetLoader] out of memory! Are you running Windows?" << std::endl; - abort(); - case ENOTDIR: - std::cerr << "[PresetLoader] directory specified is not a preset directory! Trying to continue..." << std::endl; - break; - case ENFILE: - std::cerr << "[PresetLoader] Your system has reached its open file limit. Trying to continue..." << std::endl; - break; - case EMFILE: - std::cerr << "[PresetLoader] too many files in use by projectM! Bailing!" << std::endl; - break; - case EACCES: - std::cerr << "[PresetLoader] permissions issue reading the specified preset directory." << std::endl; - break; - default: - break; - } + switch ( errno ) + { + case ENOENT: + std::cerr << "[PresetLoader] ENOENT error. The path \"" << this->_dirname << "\" probably does not exist. \"man open\" for more info." << std::endl; + break; + case ENOMEM: + std::cerr << "[PresetLoader] out of memory! Are you running Windows?" << std::endl; + abort(); + case ENOTDIR: + std::cerr << "[PresetLoader] directory specified is not a preset directory! Trying to continue..." << std::endl; + break; + case ENFILE: + std::cerr << "[PresetLoader] Your system has reached its open file limit. Trying to continue..." << std::endl; + break; + case EMFILE: + std::cerr << "[PresetLoader] too many files in use by projectM! Bailing!" << std::endl; + break; + case EACCES: + std::cerr << "[PresetLoader] permissions issue reading the specified preset directory." << std::endl; + break; + default: + break; + } #endif } -void PresetLoader::setRating(unsigned int index, int rating) { - assert(index >=0); - assert(index < m_ratings.size()); - - m_ratingsSum -= m_ratings[index]; - m_ratings[index] = rating; - m_ratingsSum += rating; - - assert(m_entries.size() == m_presetNames.size()); - assert(m_ratings.size() == m_entries.size()); - -} - -unsigned int PresetLoader::addPresetURL(const std::string & url, const std::string & presetName, int rating) { - m_entries.push_back(url); - m_presetNames.push_back(presetName); - m_ratings.push_back(rating); - m_ratingsSum += rating; - - assert(m_entries.size() == m_presetNames.size()); - assert(m_ratings.size() == m_entries.size()); - - return m_entries.size()-1; -} - -void PresetLoader::removePreset(unsigned int index) { - - m_entries.erase(m_entries.begin()+index); - m_presetNames.erase(m_presetNames.begin()+index); - m_ratingsSum -= m_ratings[index]; - m_ratings.erase(m_ratings.begin()+index); - - assert(m_entries.size() == m_presetNames.size()); - assert(m_ratings.size() == m_entries.size()); - -} - -const std::string & PresetLoader::getPresetURL ( unsigned int index) const { - return m_entries[index]; -} - -const std::string & PresetLoader::getPresetName ( unsigned int index) const { - return m_presetNames[index]; -} - -int PresetLoader::getPresetRating ( unsigned int index) const { - return m_ratings[index]; -} - - -const std::vector & PresetLoader::getPresetRatings () const { - return m_ratings; -} - - -int PresetLoader::getPresetRatingsSum () const { - return m_ratingsSum; -} - -void PresetLoader::insertPresetURL(unsigned int index, const std::string & url, const std::string & presetName, int rating) +void PresetLoader::setRating ( unsigned int index, int rating ) { - m_entries.insert(m_entries.begin()+index, url); - m_presetNames.insert(m_presetNames.begin() + index, presetName); - m_ratings.insert(m_ratings.begin()+index, rating); - m_ratingsSum += rating; - - assert(m_entries.size() == m_presetNames.size()); - assert(m_ratings.size() == m_entries.size()); - + assert ( index >=0 ); + assert ( index < _ratings.size() ); + + _ratingsSum -= _ratings[index]; + _ratings[index] = rating; + _ratingsSum += rating; + + assert ( _entries.size() == _presetNames.size() ); + assert ( _ratings.size() == _entries.size() ); + +} + +unsigned int PresetLoader::addPresetURL ( const std::string & url, const std::string & presetName, int rating ) +{ + _entries.push_back ( url ); + _presetNames.push_back ( presetName ); + _ratings.push_back ( rating ); + _ratingsSum += rating; + + assert ( _entries.size() == _presetNames.size() ); + assert ( _ratings.size() == _entries.size() ); + + return _entries.size()-1; +} + +void PresetLoader::removePreset ( unsigned int index ) +{ + + _entries.erase ( _entries.begin() +index ); + _presetNames.erase ( _presetNames.begin() +index ); + _ratingsSum -= _ratings[index]; + _ratings.erase ( _ratings.begin() +index ); + + assert ( _entries.size() == _presetNames.size() ); + assert ( _ratings.size() == _entries.size() ); + +} + +const std::string & PresetLoader::getPresetURL ( unsigned int index ) const +{ + return _entries[index]; +} + +const std::string & PresetLoader::getPresetName ( unsigned int index ) const +{ + return _presetNames[index]; +} + +int PresetLoader::getPresetRating ( unsigned int index ) const +{ + return _ratings[index]; +} + + +const std::vector & PresetLoader::getPresetRatings () const +{ + return _ratings; +} + + +int PresetLoader::getPresetRatingsSum () const +{ + return _ratingsSum; +} + +void PresetLoader::insertPresetURL ( unsigned int index, const std::string & url, const std::string & presetName, int rating ) +{ + _entries.insert ( _entries.begin() +index, url ); + _presetNames.insert ( _presetNames.begin() + index, presetName ); + _ratings.insert ( _ratings.begin() +index, rating ); + _ratingsSum += rating; + + assert ( _entries.size() == _presetNames.size() ); + assert ( _ratings.size() == _entries.size() ); + } diff --git a/src/libprojectM/PresetLoader.hpp b/src/libprojectM/PresetLoader.hpp index 8597de0bb..9c6ce0ff1 100644 --- a/src/libprojectM/PresetLoader.hpp +++ b/src/libprojectM/PresetLoader.hpp @@ -18,31 +18,29 @@ #endif #include +#include class Preset; class PresetInputs; class PresetOutputs; +class PresetFactory; class PresetLoader { public: - static const std::string PROJECTM_FILE_EXTENSION; - static const std::string MILKDROP_FILE_EXTENSION; - + /// Initializes the preset loader with the target directory specified PresetLoader(std::string dirname); ~PresetLoader(); /// Load a preset by specifying a filename of the directory (that is, NOT full path) - std::auto_ptr loadPreset(unsigned int index, PresetInputs & presetInputs, - PresetOutputs & presetOutputs) const; + std::auto_ptr loadPreset(unsigned int index) const; - - /// Associates a preset loading handler a file extension. - /// Any subsequent call to an extension overrides the previously set handler. + /// Associates a preset factory to a file extension. + /// Any subsequent registrations of an extension overrides the previously set one /// \param extension the file extension to attach the handler to /// \param handler a preset loading handler that will be associated with the extension - void registerHandler(const std::string & extension, PresetLoadingHandler * handler); + void registerFactory(const std::string & extension, PresetFactory * factory); /// Add a preset to the loader's collection. /// \param url an url referencing the preset @@ -60,7 +58,7 @@ class PresetLoader { void insertPresetURL (unsigned int index, const std::string & url, const std::string & presetName, int rating); /// Clears all presets from the collection - inline void clear() { m_entries.clear(); m_presetNames.clear(); m_ratings.clear(); m_ratingsSum = 0; } + inline void clear() { _entries.clear(); _presetNames.clear(); _ratings.clear(); _ratingsSum = 0; } const std::vector & getPresetRatings() const; int getPresetRatingsSum() const; @@ -70,7 +68,7 @@ class PresetLoader { void setRating(unsigned int index, int rating); /// Get a preset rating given an index - int getPresetRating ( unsigned int index) const; + int getPresetRating ( unsigned int index) const; /// Get a preset url given an index const std::string & getPresetURL ( unsigned int index) const; @@ -79,8 +77,8 @@ class PresetLoader { const std::string & getPresetName ( unsigned int index) const; /** Returns the number of presets in the active directory */ - inline std::size_t getNumPresets() const { - return m_entries.size(); + inline std::size_t size() const { + return _entries.size(); } /** Sets the directory where the loader will search for files */ @@ -88,7 +86,7 @@ class PresetLoader { /// Returns the directory path associated with this preset chooser inline const std::string & directoryName() const { - return m_dirname; + return _dirname; } /** Rescans the active preset directory */ @@ -96,15 +94,15 @@ class PresetLoader { private: void handleDirectoryError(); - std::string m_dirname; - DIR * m_dir; - std::map _handlers; - int m_ratingsSum; + std::string _dirname; + DIR * _dir; + mutable std::map _factories; + int _ratingsSum; // vector chosen for speed, but not great for reverse index lookups - std::vector m_entries; - std::vector m_presetNames; - std::vector m_ratings; + std::vector _entries; + std::vector _presetNames; + std::vector _ratings; }; diff --git a/src/libprojectM/PresetMerge.hpp b/src/libprojectM/PresetMerge.hpp index 7ccdbc777..186c3cf27 100644 --- a/src/libprojectM/PresetMerge.hpp +++ b/src/libprojectM/PresetMerge.hpp @@ -2,6 +2,7 @@ #define PRESET_MERGE_HPP #include "Preset.hpp" #include "Pipeline.hpp" +#include "PresetFrameIO.hpp" class PresetMerger { diff --git a/src/libprojectM/Renderer.cpp b/src/libprojectM/Renderer.cpp index 52052c3b4..36187220d 100644 --- a/src/libprojectM/Renderer.cpp +++ b/src/libprojectM/Renderer.cpp @@ -411,7 +411,9 @@ void Renderer::reset(int w, int h) this -> vw = w; this -> vh = h; +#if USE_CG shaderEngine.setAspect(aspect); +#endif glShadeModel(GL_SMOOTH); diff --git a/src/libprojectM/projectM.cpp b/src/libprojectM/projectM.cpp index fe2da9622..d996862e4 100755 --- a/src/libprojectM/projectM.cpp +++ b/src/libprojectM/projectM.cpp @@ -736,8 +736,9 @@ int projectM::initPresetTools() *m_presetPos = m_presetChooser->end(); // Load idle preset - //std::cerr << "[projectM] Allocating idle preset..." << std::endl; - m_activePreset = IdlePreset::allocate ( presetInputs, presetOutputs ); + std::cerr << "[projectM] Allocating idle preset..." << std::endl; + abort(); + //m_activePreset = IdlePreset::allocate ( presetInputs, presetOutputs ); // Case where no valid presets exist in directory. Could also mean // playlist initialization was deferred @@ -832,12 +833,12 @@ void projectM::selectPreset ( unsigned int index ) if ( m_presetChooser->empty() ) return; - assert ( index < m_presetLoader->getNumPresets() ); + assert ( index < m_presetLoader->size()); assert ( index >= 0 ); *m_presetPos = m_presetChooser->begin ( index ); - m_activePreset = m_presetPos->allocate ( presetInputs, presetOutputs ); + m_activePreset = m_presetPos->allocate (); renderer->setPresetName ( m_activePreset->name() ); @@ -851,7 +852,7 @@ void projectM::switchPreset(std::auto_ptr & targetPreset, PresetInputs & else m_presetChooser->nextPreset(*m_presetPos); - targetPreset = m_presetPos->allocate( inputs, outputs ); + 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() ); @@ -914,7 +915,7 @@ bool projectM::presetPositionValid() const { unsigned int projectM::getPlaylistSize() const { - return m_presetLoader->getNumPresets(); + return m_presetLoader->size(); } void projectM:: changePresetRating (unsigned int index, int rating) {