diff --git a/src/projectM-engine/BeatDetect.cpp b/src/projectM-engine/BeatDetect.cpp index dd785a9fa..fbfad1b28 100755 --- a/src/projectM-engine/BeatDetect.cpp +++ b/src/projectM-engine/BeatDetect.cpp @@ -39,28 +39,24 @@ DLLEXPORT BeatDetect::BeatDetect() { int x,y; - vol_instant=0; - vol_history=0; + this->vol_instant=0; + this->vol_history=0; for (y=0;y<80;y++) { - vol_buffer[y]=0; + this->vol_buffer[y]=0; } - beat_buffer_pos=0; - - beat_val=(float *)wipemalloc(32*sizeof(float)); - beat_att=(float *)wipemalloc(32*sizeof(float)); - beat_variance=(float *)wipemalloc(32*sizeof(float)); + this->beat_buffer_pos=0; for (x=0;x<32;x++) { - beat_instant[x]=0; - beat_history[x]=0; - beat_val[x]=1.0; - beat_att[x]=1.0; - beat_variance[x]=0; + this->beat_instant[x]=0; + this->beat_history[x]=0; + this->beat_val[x]=1.0; + this->beat_att[x]=1.0; + this->beat_variance[x]=0; for (y=0;y<80;y++) { - beat_buffer[x][y]=0; + this->beat_buffer[x][y]=0; } } @@ -74,27 +70,23 @@ DLLEXPORT BeatDetect::BeatDetect() { this->bass_att = 0; this->vol = 0; - pcm = new PCM(); + this->pcm = new PCM(); } -void BeatDetect::initBeatDetect() { - - } - void BeatDetect::reset() { - treb = 0; - mid = 0; - bass = 0; - treb_att = 0; - mid_att = 0; - bass_att = 0; + this->treb = 0; + this->mid = 0; + this->bass = 0; + this->treb_att = 0; + this->mid_att = 0; + this->bass_att = 0; } void BeatDetect::detectFromSamples() { bass_old = bass; bass=0;mid=0;treb=0; - getBeatVals(pcm->vdataL,pcm->vdataR); + getBeatVals(pcm->pcmdataL,pcm->pcmdataR); } void BeatDetect::getBeatVals( float *vdataL,float *vdataR ) { @@ -104,7 +96,6 @@ void BeatDetect::getBeatVals( float *vdataL,float *vdataR ) { float temp2=0; vol_instant=0; - for ( x=0;x<16;x++) { @@ -116,7 +107,7 @@ void BeatDetect::getBeatVals( float *vdataL,float *vdataR ) { vol_instant+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/512.0); } - +//printf("1"); linear=y/2; beat_history[x]-=(beat_buffer[x][beat_buffer_pos])*.0125; beat_buffer[x][beat_buffer_pos]=beat_instant[x]; @@ -126,10 +117,10 @@ void BeatDetect::getBeatVals( float *vdataL,float *vdataR ) { beat_att[x]+=(beat_instant[x])/(beat_history[x]); - +//printf("2\n"); } - +//printf("b\n"); vol_history-=(vol_buffer[beat_buffer_pos])*.0125; vol_buffer[beat_buffer_pos]=vol_instant; vol_history+=(vol_instant)*.0125; @@ -150,6 +141,7 @@ void BeatDetect::getBeatVals( float *vdataL,float *vdataR ) { treb+=(beat_instant[x]); temp2+=(beat_history[x]); } +//printf("c\n"); treb=treb/(1.5*temp2); // *vol=vol_instant/(1.5*vol_history); vol=vol_instant/(1.5*vol_history); @@ -180,13 +172,4 @@ void BeatDetect::getBeatVals( float *vdataL,float *vdataR ) { } -void BeatDetect::freeBeatDetect() { - free(beat_att); - free(beat_val); - free(beat_variance); - - beat_att = NULL; - beat_val = NULL; - beat_variance = NULL; -} diff --git a/src/projectM-engine/BeatDetect.hpp b/src/projectM-engine/BeatDetect.hpp index 6f5f8083f..c43b9f8f1 100755 --- a/src/projectM-engine/BeatDetect.hpp +++ b/src/projectM-engine/BeatDetect.hpp @@ -40,9 +40,9 @@ public: float beat_buffer[32][80], beat_instant[32], beat_history[32]; - float *beat_val, - *beat_att, - *beat_variance; + float beat_val[32], + beat_att[32], + beat_variance[32]; int beat_buffer_pos; float vol_buffer[80], vol_instant, diff --git a/src/projectM-engine/CustomWave.cpp b/src/projectM-engine/CustomWave.cpp index ea40d09a5..8b497a50a 100755 --- a/src/projectM-engine/CustomWave.cpp +++ b/src/projectM-engine/CustomWave.cpp @@ -517,8 +517,6 @@ void CustomWave::evalPerPointEqns() { for (std::map::iterator pos = per_point_eqn_tree.begin(); pos != per_point_eqn_tree.end();++pos) pos->second->evaluate(); - /* Reset index */ - projectM::currentEngine->mesh_i = -1; } void CustomWave::load_unspecified_init_conds() { diff --git a/src/projectM-engine/Expr.cpp b/src/projectM-engine/Expr.cpp index 6a3c672eb..6bde8b82f 100755 --- a/src/projectM-engine/Expr.cpp +++ b/src/projectM-engine/Expr.cpp @@ -125,11 +125,11 @@ float ValExpr::eval_val_expr(int mesh_i, int mesh_j) { assert(term.param->matrix != NULL ); /// @slow boolean check could be expensive in this critical (and common) step of evaluation - if (projectM::currentEngine->mesh_i >= 0) { - if (projectM::currentEngine->mesh_j >= 0) { - return (((float**)term.param->matrix)[projectM::currentEngine->mesh_i][projectM::currentEngine->mesh_j]); + if (mesh_i >= 0) { + if (mesh_j >= 0) { + return (((float**)term.param->matrix)[mesh_i][mesh_j]); } else { - return (((float*)term.param->matrix)[projectM::currentEngine->mesh_i]); + return (((float*)term.param->matrix)[mesh_i]); } } } diff --git a/src/projectM-engine/Param.cpp b/src/projectM-engine/Param.cpp index 3a47da821..0fde8804b 100755 --- a/src/projectM-engine/Param.cpp +++ b/src/projectM-engine/Param.cpp @@ -55,8 +55,11 @@ Param::Param( std::string _name, short int type, short int flags, void * engine_ { /** @@FIX THIS */ - //this->gx = projectM::currentEngine->gx; - //this->gy = projectM::currentEngine->gy; + /// @bug listen to above's advice! + /// @NOTE this is a hack, but will probably work fine + this->gx = projectM::currentEngine->presetInputs.gx; + this->gy = projectM::currentEngine->presetInputs.gy; + } @@ -77,9 +80,10 @@ Param::Param(std::string _name) : /** @@FIX THIS */ - /// @bug listen to above's advice! - //this->gx = projectM::currentEngine->gx; - //this->gy = projectM::currentEngine->gy; + /// @bug listen to above's advice! + /// @NOTE this is a hack, but will probably work fine + this->gx = projectM::currentEngine->presetInputs.gx; + this->gy = projectM::currentEngine->presetInputs.gy; } /* Free's a parameter type */ diff --git a/src/projectM-engine/ParamUtils.hpp b/src/projectM-engine/ParamUtils.hpp index e1344f73b..22cc861c8 100644 --- a/src/projectM-engine/ParamUtils.hpp +++ b/src/projectM-engine/ParamUtils.hpp @@ -33,8 +33,9 @@ public: static Param * find(std::string name, std::map * paramTree) { - Param * param = NULL; + assert(paramTree); + Param * param = NULL; /* First look in the builtin database */ std::map::iterator pos = paramTree->find(name); @@ -42,7 +43,6 @@ public: if ((FLAGS == AUTO_CREATE) && ((pos == paramTree->end()))) { - param = pos->second; /* Check if string is valid */ if (!Param::is_valid_param_string(name.c_str())) return NULL; diff --git a/src/projectM-engine/PerPixelEqn.cpp b/src/projectM-engine/PerPixelEqn.cpp index ed7dcc33e..230b0faf4 100755 --- a/src/projectM-engine/PerPixelEqn.cpp +++ b/src/projectM-engine/PerPixelEqn.cpp @@ -22,7 +22,7 @@ #include #include #include - +#include #include "projectM.hpp" #include "fatal.h" @@ -68,6 +68,7 @@ void PerPixelEqn::evaluate() { // param->matrix_flag = 0; /** Force matrix ignore to update time */ for (int mesh_i = 0; mesh_i < param->gx; mesh_i++) { for (int mesh_j = 0; mesh_j < param->gy; mesh_j++) { +// std::cout << "gx,gy is " << param->gx << "," << param->gy << std::endl; param_matrix[mesh_i][mesh_j] = eqn_ptr->eval_gen_expr(mesh_i, mesh_j); } } diff --git a/src/projectM-engine/Preset.cpp b/src/projectM-engine/Preset.cpp index c2c40742e..a89927b41 100755 --- a/src/projectM-engine/Preset.cpp +++ b/src/projectM-engine/Preset.cpp @@ -33,7 +33,7 @@ #include "Parser.hpp" #include "ParamUtils.hpp" #include "fatal.h" - +#include Preset::Preset(const std::string & filename, const PresetInputs & presetInputs, PresetOutputs & presetOutputs): file_path(filename), @@ -133,26 +133,14 @@ int Preset::add_per_pixel_eqn(char * name, GenExpr * gen_expr) return PROJECTM_FAILURE; } - /** - if ( !param->matrix ) { - if (PER_PIXEL_EQN_DEBUG) printf( "add_per_pixel_eqn: failed to locate param matrix\n" ); - return PROJECTM_FAILURE; - } - */ - - /* Find most largest index in the splaytree */ - std::map::iterator lastPos = per_pixel_eqn_tree->end(); - --lastPos; - - if (lastPos == per_pixel_eqn_tree->end()) + if (per_pixel_eqn_tree->empty()) { - per_pixel_eqn = 0; index = 0; } else { + std::map::iterator lastPos = per_pixel_eqn_tree->end(); index = per_pixel_eqn_tree->size(); - per_pixel_eqn = lastPos->second; } /* Create the per pixel equation given the index, parameter, and general expression */ @@ -274,10 +262,13 @@ void Preset::initialize(const std::string & pathname) memset(this->per_frame_eqn_string_buffer, 0, STRING_BUFFER_SIZE); memset(this->per_frame_init_eqn_string_buffer, 0, STRING_BUFFER_SIZE); int retval; + if ((retval = load_preset_file(pathname.c_str())) < 0) { + #ifdef PRESET_DEBUG - if (PRESET_DEBUG) printf("load_preset: failed to load file \"%s\"\n", pathname); + if (PRESET_DEBUG) std::cerr << "[Preset] failed to load file \"" << + pathname << "\"!" << std::endl; #endif //this->close_preset(); /// @bug how should we handle this problem? a well define exception? diff --git a/src/projectM-engine/Preset.hpp b/src/projectM-engine/Preset.hpp index b9fdaeb06..cebc74cc7 100644 --- a/src/projectM-engine/Preset.hpp +++ b/src/projectM-engine/Preset.hpp @@ -31,7 +31,7 @@ #include "Common.hpp" #include -//#define PRESET_DEBUG 2 /* 0 for no debugging, 1 for normal, 2 for insane */ +#define PRESET_DEBUG 2 /* 0 for no debugging, 1 for normal, 2 for insane */ #include "CustomShape.hpp" #include "CustomWave.hpp" diff --git a/src/projectM-engine/PresetChooser.hpp b/src/projectM-engine/PresetChooser.hpp index e34cc9b78..505915777 100644 --- a/src/projectM-engine/PresetChooser.hpp +++ b/src/projectM-engine/PresetChooser.hpp @@ -35,6 +35,10 @@ public: /// Not equal comparator bool operator !=(const PresetIterator & presetPos) const ; + + /// Equality comparator + bool operator ==(const PresetIterator & presetPos) const ; + /// Returns an integer value representing the iterator position /// @bug might become internal /// \brief Returns the indexing value used by the current iterator. @@ -158,6 +162,11 @@ inline bool PresetIterator::operator !=(const PresetIterator & presetPos) const return (*presetPos != **this); } + +inline bool PresetIterator::operator ==(const PresetIterator & presetPos) const { + return (*presetPos == **this); +} + inline std::auto_ptr PresetIterator::allocate(const PresetInputs & presetInputs, PresetOutputs & presetOutputs) { return m_presetChooser->directoryIndex(m_currentIndex, presetInputs, presetOutputs); } @@ -168,7 +177,7 @@ inline float PresetChooser::UniformRandomFunctor::operator() (std::size_t index) inline PresetIterator PresetChooser::begin() { - PresetIterator pos; + PresetIterator pos(0); pos.setChooser(*this); return pos; } diff --git a/src/projectM-engine/PresetFrameIO.cpp b/src/projectM-engine/PresetFrameIO.cpp index 3c570b98e..76dcb0227 100644 --- a/src/projectM-engine/PresetFrameIO.cpp +++ b/src/projectM-engine/PresetFrameIO.cpp @@ -1,7 +1,8 @@ #include "PresetFrameIO.hpp" #include "wipemalloc.h" #include - +#include +#include PresetInputs::PresetInputs() { } @@ -12,8 +13,9 @@ void PresetInputs::Initialize(int gx, int gy) this->gx =gx; this->gy=gy; - + std::cerr << "Allocating x_mesh, gx,gy is " << gx << "," << gy << std::endl; this->x_mesh=(float **)wipemalloc(gx * sizeof(float *)); + assert(x_mesh); for(x = 0; x < gx; x++) { this->x_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); @@ -159,7 +161,8 @@ PresetInputs::~PresetInputs() free(this->origy); free(this->origrad); free(this->origtheta); - + + //std::cerr << "freeing x_mesh" <x_mesh); free(this->y_mesh); free(this->rad_mesh); @@ -180,11 +183,16 @@ void PresetInputs::ResetMesh() { int x,y; - + assert(x_mesh); + + assert(y_mesh); + assert(rad_mesh); + assert(theta_mesh); + for (x=0;xgx;x++) { for(y=0;ygy;y++) - { + { x_mesh[x][y]=this->origx[x][y]; y_mesh[x][y]=this->origy[x][y]; rad_mesh[x][y]=this->origrad[x][y]; diff --git a/src/projectM-engine/PresetLoader.cpp b/src/projectM-engine/PresetLoader.cpp index e18616207..e2223c317 100644 --- a/src/projectM-engine/PresetLoader.cpp +++ b/src/projectM-engine/PresetLoader.cpp @@ -70,16 +70,17 @@ void PresetLoader::rescan() std::ostringstream out; struct dirent * dir_entry; - std::cerr << "iterating " << m_dirname << std::endl; + while ((dir_entry = readdir(m_dir)) != NULL) { // Convert char * to friendly string std::string filename(dir_entry->d_name); + // Verify extension is projectm or milkdrop - if (filename.rfind(PROJECTM_FILE_EXTENSION) <= 0 - || filename.rfind(MILKDROP_FILE_EXTENSION) <= 0) + if ((filename.rfind(PROJECTM_FILE_EXTENSION) != (filename.length() - PROJECTM_FILE_EXTENSION.length())) + && (filename.rfind(MILKDROP_FILE_EXTENSION) != (filename.length() - MILKDROP_FILE_EXTENSION.length()))) continue; // Create full path name @@ -88,7 +89,7 @@ void PresetLoader::rescan() // Add to our directory entry collection m_entries.push_back(out.str()); - // the directory entry struct is free elsewhere + // the directory entry struct is freed elsewhere } } @@ -131,4 +132,4 @@ void PresetLoader::handleDirectoryError() default: break; } -} \ No newline at end of file +} diff --git a/src/projectM-engine/console_interface.cpp b/src/projectM-engine/console_interface.cpp index 72bb94038..14636712d 100755 --- a/src/projectM-engine/console_interface.cpp +++ b/src/projectM-engine/console_interface.cpp @@ -164,7 +164,6 @@ void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode if (!((*m_presetPos) != m_presetChooser->end())) --(*m_presetPos); m_activePreset = m_presetPos->allocate(this->presetInputs, this->presetOutputs); - //this->activePreset = m_presetPos.allocate( break; case PROJECTM_K_r: // if (PresetSwitcher::switchPreset(RANDOM_NEXT, HARD_CUT) < 0) { diff --git a/src/projectM-engine/projectM.cpp b/src/projectM-engine/projectM.cpp index 2d3275cf1..d6bad8580 100755 --- a/src/projectM-engine/projectM.cpp +++ b/src/projectM-engine/projectM.cpp @@ -28,7 +28,7 @@ #endif #include "timer.h" - +#include #ifdef LINUX #include "time.h" #endif @@ -105,6 +105,8 @@ DLLEXPORT void projectM::renderFrame() { // printf("start:%d at:%d min:%d stop:%d on:%d %d\n",startframe, frame frame-startframe,avgtime, noSwitch,progress); presetInputs.ResetMesh(); + + assert(m_activePreset.get()); m_activePreset->evaluateFrame(); @@ -202,9 +204,10 @@ DLLEXPORT void projectM::projectM_init(int gx, int gy, int fps, int texsize, int /** Initialise engine variables */ + + projectM_initengine(); presetInputs.Initialize(gx, gy); presetOutputs.Initialize(gx, gy); - projectM_initengine(); DWRITE("projectM plugin: Initializing\n"); @@ -469,6 +472,7 @@ DLLEXPORT void projectM::projectM_initengine() { /* Q AND T VARIABLES END */ //per pixel meshes +/* this->presetOutputs.zoom_mesh = NULL; this->presetOutputs.zoomexp_mesh = NULL; this->presetOutputs.rot_mesh = NULL; @@ -485,7 +489,8 @@ DLLEXPORT void projectM::projectM_initengine() { this->presetInputs.y_mesh = NULL; this->presetInputs.rad_mesh = NULL; this->presetInputs.theta_mesh = NULL; - +*/ + //custom wave per point meshes } @@ -535,9 +540,6 @@ DLLEXPORT void projectM::projectM_resetengine() { this->presetOutputs.mv_dy = 0.02; this->presetOutputs.mv_dx = 0.02; - /// @bug think these are just gx/gy - //this->meshx = 0; - //this->meshy = 0; if ( beatDetect != NULL ) { beatDetect->reset(); @@ -655,25 +657,31 @@ int projectM::initPresetTools() { srand(time(NULL)); #endif - /* Initialize the 'idle' preset */ - //Preset::init_idle_preset(); - - projectM_resetengine(); - - if (m_presetLoader = new PresetLoader(PROJECTM_PRESET_PATH)) { + if ((m_presetLoader = new PresetLoader(PROJECTM_PRESET_PATH)) == 0) { m_presetLoader = 0; + std::cerr << "[projectM] error allocating preset loader" << std::endl; return PROJECTM_FAILURE; } - if (m_presetChooser = new PresetChooser(*m_presetLoader)) { + if ((m_presetChooser = new PresetChooser(*m_presetLoader)) == 0) { delete(m_presetLoader); m_presetChooser = 0; + std::cerr << "[projectM] error allocating preset chooser" << std::endl; return PROJECTM_FAILURE; } // Start the iterator m_presetPos = new PresetIterator(); *m_presetPos = m_presetChooser->begin(); + if (*m_presetPos == m_presetChooser->end()) { + std::cerr << "[projectM] error: no valid files found in preset directory \"" << PROJECTM_PRESET_PATH << "\"" << std::endl; + } + + std::cerr << "[projectM] Allocating first preset..." << std::endl; + m_activePreset = m_presetPos->allocate(presetInputs, presetOutputs); + + std::cerr << "[projectM] First preset allocated. Name is \"" << m_activePreset->name << "\"" << std::endl; + projectM_resetengine(); /* Done */ #ifdef PRESET_DEBUG diff --git a/src/projectM-engine/projectM.hpp b/src/projectM-engine/projectM.hpp index 26c17a8e9..843674dfc 100755 --- a/src/projectM-engine/projectM.hpp +++ b/src/projectM-engine/projectM.hpp @@ -134,8 +134,7 @@ public: int pcmframes; int freqframes; - int mesh_i, mesh_j; - + GLubyte *fbuffer; #ifndef WIN32 @@ -177,7 +176,7 @@ public: /** All readonly variables * which are passed as inputs - * to presets. See struct defintition above */ + * to presets. See struct definitition above */ PresetInputs presetInputs; /** The presets modify these values. For now this is declared on stack