From d1efb370609d91208b6495691a4602474760e91c Mon Sep 17 00:00:00 2001 From: w1z7ard Date: Wed, 19 Sep 2007 21:00:58 +0000 Subject: [PATCH] lots of changes - project init / destroy memory leak bugs fixed. some still exist - moodbar partial integration. will be removed later git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@443 6778bc44-b910-0410-a7a0-be141de4315d --- src/projectM-engine/BuiltinParams.cpp | 28 +++++++++---------- src/projectM-engine/CustomWave.cpp | 18 ++++++------- src/projectM-engine/MoodBar.cpp | 12 +++++---- src/projectM-engine/MoodBar.hpp | 7 +++-- src/projectM-engine/PBuffer.cpp | 25 +++++++++++++---- src/projectM-engine/PBuffer.hpp | 8 +++--- src/projectM-engine/Param.cpp | 31 +-------------------- src/projectM-engine/Param.hpp | 2 -- src/projectM-engine/PerPixelEqn.cpp | 10 ++----- src/projectM-engine/PresetLoader.cpp | 5 ++-- src/projectM-engine/Renderer.cpp | 25 +++++++++++++---- src/projectM-engine/projectM.cpp | 39 ++++++++++++++------------- src/projectM-engine/projectM.hpp | 5 +++- 13 files changed, 111 insertions(+), 104 deletions(-) diff --git a/src/projectM-engine/BuiltinParams.cpp b/src/projectM-engine/BuiltinParams.cpp index f81ba3f0a..50e1f7e40 100644 --- a/src/projectM-engine/BuiltinParams.cpp +++ b/src/projectM-engine/BuiltinParams.cpp @@ -302,18 +302,18 @@ int BuiltinParams::load_all_builtin_param(const PresetInputs & presetInputs, Pre load_builtin_param_bool("bmotionvectorson", (void*)&presetOutputs.bMotionVectorsOn, P_FLAG_NONE, false, ""); load_builtin_param_bool("wave_dots", (void*)&presetOutputs.bWaveDots, P_FLAG_NONE, false, "bwavedots"); load_builtin_param_bool("wave_thick", (void*)&presetOutputs.bWaveThick, P_FLAG_NONE, false, "bwavethick"); - load_builtin_param_float("warp", (void*)&presetOutputs.warp, presetOutputs.warp_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); - load_builtin_param_float("zoom", (void*)&presetOutputs.zoom, presetOutputs.zoom_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); - load_builtin_param_float("rot", (void*)&presetOutputs.rot, presetOutputs.rot_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); + load_builtin_param_float("warp", (void*)&presetOutputs.warp, presetOutputs.warp_mesh, P_FLAG_PER_PIXEL |P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); + load_builtin_param_float("zoom", (void*)&presetOutputs.zoom, presetOutputs.zoom_mesh, P_FLAG_PER_PIXEL |P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); + load_builtin_param_float("rot", (void*)&presetOutputs.rot, presetOutputs.rot_mesh, P_FLAG_PER_PIXEL |P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); /// @note added huge bug fix here potentially by prevening zoomexp_mesh from being freed when presets dealloc - load_builtin_param_float("zoomexp", (void*)&presetOutputs.zoomexp, presetOutputs.zoomexp_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX , 0.0, MAX_DOUBLE_SIZE, 0, "fzoomexponent"); + load_builtin_param_float("zoomexp", (void*)&presetOutputs.zoomexp, presetOutputs.zoomexp_mesh, P_FLAG_PER_PIXEL |P_FLAG_NONE , 0.0, MAX_DOUBLE_SIZE, 0, "fzoomexponent"); - load_builtin_param_float("cx", (void*)&presetOutputs.cx, presetOutputs.cx_mesh, P_FLAG_PER_PIXEL | P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); - load_builtin_param_float("cy", (void*)&presetOutputs.cy, presetOutputs.cy_mesh, P_FLAG_PER_PIXEL | P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); - load_builtin_param_float("dx", (void*)&presetOutputs.dx, presetOutputs.dx_mesh, P_FLAG_PER_PIXEL | P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); - load_builtin_param_float("dy", (void*)&presetOutputs.dy, presetOutputs.dy_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); - load_builtin_param_float("sx", (void*)&presetOutputs.sx, presetOutputs.sx_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); - load_builtin_param_float("sy", (void*)&presetOutputs.sy, presetOutputs.sy_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); + load_builtin_param_float("cx", (void*)&presetOutputs.cx, presetOutputs.cx_mesh, P_FLAG_PER_PIXEL | P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); + load_builtin_param_float("cy", (void*)&presetOutputs.cy, presetOutputs.cy_mesh, P_FLAG_PER_PIXEL | P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); + load_builtin_param_float("dx", (void*)&presetOutputs.dx, presetOutputs.dx_mesh, P_FLAG_PER_PIXEL | P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); + load_builtin_param_float("dy", (void*)&presetOutputs.dy, presetOutputs.dy_mesh, P_FLAG_PER_PIXEL |P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); + load_builtin_param_float("sx", (void*)&presetOutputs.sx, presetOutputs.sx_mesh, P_FLAG_PER_PIXEL |P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); + load_builtin_param_float("sy", (void*)&presetOutputs.sy, presetOutputs.sy_mesh, P_FLAG_PER_PIXEL |P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, ""); load_builtin_param_float("wave_r", (void*)&presetOutputs.wave_r, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); load_builtin_param_float("wave_g", (void*)&presetOutputs.wave_g, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, ""); @@ -362,13 +362,13 @@ int BuiltinParams::load_all_builtin_param(const PresetInputs & presetInputs, Pre load_builtin_param_float("progress", (void*)&presetInputs.progress, NULL,P_FLAG_READONLY, 0.0, 1, 0, ""); load_builtin_param_int("fps", (void*)&presetInputs.fps, P_FLAG_READONLY, 15, MAX_INT_SIZE, 0, ""); - load_builtin_param_float("x", (void*)&presetInputs.x_per_pixel, presetInputs.x_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX, + load_builtin_param_float("x", (void*)&presetInputs.x_per_pixel, presetInputs.x_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_NONE, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("y", (void*)&presetInputs.y_per_pixel, presetInputs.y_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX |P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX, + load_builtin_param_float("y", (void*)&presetInputs.y_per_pixel, presetInputs.y_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX |P_FLAG_READONLY | P_FLAG_NONE, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("ang", (void*)&presetInputs.ang_per_pixel, presetInputs.theta_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX, + load_builtin_param_float("ang", (void*)&presetInputs.ang_per_pixel, presetInputs.theta_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_NONE, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); - load_builtin_param_float("rad", (void*)&presetInputs.rad_per_pixel, presetInputs.rad_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX, + load_builtin_param_float("rad", (void*)&presetInputs.rad_per_pixel, presetInputs.rad_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_NONE, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); load_builtin_param_float("q1", (void*)&presetOutputs.q1, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, ""); diff --git a/src/projectM-engine/CustomWave.cpp b/src/projectM-engine/CustomWave.cpp index 13cf5bde1..00ba8f6eb 100755 --- a/src/projectM-engine/CustomWave.cpp +++ b/src/projectM-engine/CustomWave.cpp @@ -79,7 +79,7 @@ CustomWave::CustomWave(int _id): /* Start: Load custom wave parameters */ - if ((param = Param::new_param_float("r", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &this->r, this->r_mesh, 1.0, 0.0, .5)) == NULL) + if ((param = Param::new_param_float("r", P_FLAG_NONE | P_FLAG_PER_POINT, &this->r, this->r_mesh, 1.0, 0.0, .5)) == NULL) { delete(this); /// @bug make exception @@ -92,7 +92,7 @@ CustomWave::CustomWave(int _id): abort(); } - if ((param = Param::new_param_float("g", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &this->g, this->g_mesh, 1.0, 0.0, .5)) == NULL) + if ((param = Param::new_param_float("g", P_FLAG_NONE | P_FLAG_PER_POINT, &this->g, this->g_mesh, 1.0, 0.0, .5)) == NULL) { delete(this); /// @bug make exception @@ -106,7 +106,7 @@ CustomWave::CustomWave(int _id): abort(); } - if ((param = Param::new_param_float("b", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &this->b, this->b_mesh, 1.0, 0.0, .5)) == NULL) + if ((param = Param::new_param_float("b", P_FLAG_NONE | P_FLAG_PER_POINT, &this->b, this->b_mesh, 1.0, 0.0, .5)) == NULL) { delete(this); /// @bug make exception @@ -121,7 +121,7 @@ CustomWave::CustomWave(int _id): abort(); } - if ((param = Param::new_param_float("a", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &this->a, this->a_mesh, 1.0, 0.0, .5)) == NULL) + if ((param = Param::new_param_float("a", P_FLAG_NONE | P_FLAG_PER_POINT, &this->a, this->a_mesh, 1.0, 0.0, .5)) == NULL) { delete(this); /// @bug make exception @@ -135,7 +135,7 @@ CustomWave::CustomWave(int _id): abort(); } - if ((param = Param::new_param_float("x", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &this->x, this->x_mesh, 1.0, 0.0, .5)) == NULL) + if ((param = Param::new_param_float("x", P_FLAG_NONE | P_FLAG_PER_POINT, &this->x, this->x_mesh, 1.0, 0.0, .5)) == NULL) { delete(this); /// @bug make exception @@ -149,7 +149,7 @@ CustomWave::CustomWave(int _id): abort(); } - if ((param = Param::new_param_float("y", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &this->y, this->y_mesh, 1.0, 0.0, .5)) == NULL) + if ((param = Param::new_param_float("y", P_FLAG_NONE | P_FLAG_PER_POINT, &this->y, this->y_mesh, 1.0, 0.0, .5)) == NULL) { delete(this); /// @bug make exception @@ -272,7 +272,7 @@ CustomWave::CustomWave(int _id): abort(); } - if ((param = Param::new_param_float("sample", P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT, + if ((param = Param::new_param_float("sample", P_FLAG_READONLY | P_FLAG_NONE | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT, &this->sample, this->sample_mesh, 1.0, 0.0, 0.0)) == NULL) { delete(this); @@ -286,7 +286,7 @@ CustomWave::CustomWave(int _id): abort(); } - if ((param = Param::new_param_float("value1", P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT, &this->v1, this->value1, 1.0, -1.0, 0.0)) == NULL) + if ((param = Param::new_param_float("value1", P_FLAG_READONLY | P_FLAG_NONE | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT, &this->v1, this->value1, 1.0, -1.0, 0.0)) == NULL) { delete(this); abort(); @@ -298,7 +298,7 @@ CustomWave::CustomWave(int _id): abort(); } - if ((param = Param::new_param_float("value2", P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT, &this->v2, this->value2, 1.0, -1.0, 0.0)) == NULL) + if ((param = Param::new_param_float("value2", P_FLAG_READONLY | P_FLAG_NONE | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT, &this->v2, this->value2, 1.0, -1.0, 0.0)) == NULL) { delete(this); abort(); diff --git a/src/projectM-engine/MoodBar.cpp b/src/projectM-engine/MoodBar.cpp index f4024dc9f..3f9251173 100644 --- a/src/projectM-engine/MoodBar.cpp +++ b/src/projectM-engine/MoodBar.cpp @@ -17,6 +17,7 @@ extern "C" { } #include #include +#include "PCM.hpp" const unsigned int MoodBar::s_bark_bands[] = { 100, 200, 300, 400, 510, 630, 770, 920, @@ -24,17 +25,18 @@ const unsigned int MoodBar::s_bark_bands[] = 5300, 6400, 7700, 9500, 12000, 15500 }; void MoodBar::calculateMood - (const float * out, float * rgb) { + (float * rgb) { - int i; + unsigned int i; float real, imag; for (i = 0; i < 24; ++i) m_amplitudes[i] = 0.f; - + for (i = 0; i < m_numFreqs; ++i) { - real = out[2*i]; imag = out[2*i + 1]; + /// @bug handle both left and right channels + real = m_pcm->vdataL[2*i]; imag = m_pcm->vdataL[2*i + 1]; m_amplitudes[m_barkband_table[i]] += sqrtf (real*real + imag*imag); } @@ -82,4 +84,4 @@ MoodBar::calcBarkbandTable () m_barkband_table[i] = barkband; } -} \ No newline at end of file +} diff --git a/src/projectM-engine/MoodBar.hpp b/src/projectM-engine/MoodBar.hpp index b9a322592..3189fbe05 100644 --- a/src/projectM-engine/MoodBar.hpp +++ b/src/projectM-engine/MoodBar.hpp @@ -21,9 +21,11 @@ #ifndef _MOODBAR_HPP #define _MOODBAR_HPP +class PCM; + class MoodBar { public: - MoodBar(unsigned int numFreqs, int size, int rate) : m_numFreqs(numFreqs), m_size(size), m_rate(rate) { + MoodBar(unsigned int numFreqs, int size, int rate, PCM * pcm) : m_numFreqs(numFreqs), m_size(size), m_rate(rate), m_pcm(pcm) { calcBarkbandTable(); } @@ -31,7 +33,7 @@ public: /// Calculate rgb mood values. Out should be an array containing /// numFreqs pairs of real/complex values. - void calculateMood(const float * out, float * rgb); + void calculateMood(float * rgb); private: unsigned int m_numFreqs; @@ -40,6 +42,7 @@ private: /* This calculates a table that caches which bark band slot each * incoming band is supposed to go in. */ void calcBarkbandTable (); + PCM * m_pcm; float m_amplitudes[24]; static const unsigned int s_bark_bands[24]; diff --git a/src/projectM-engine/PBuffer.cpp b/src/projectM-engine/PBuffer.cpp index 50fc23376..134cb43ea 100755 --- a/src/projectM-engine/PBuffer.cpp +++ b/src/projectM-engine/PBuffer.cpp @@ -34,14 +34,28 @@ #include #endif /** MACOS */ +RenderTarget::~RenderTarget() { + + + glDeleteTextures( 1, &this->textureID[0]); + + if (usePbuffers) +{ + glDeleteTextures( 1, &this->textureID[1] ); + glDeleteRenderbuffersEXT(1, &this->depthb); + glDeleteFramebuffersEXT(1, &this->fbuffer); +} + +} + /** Creates new pbuffers */ RenderTarget::RenderTarget(int texsize, int width, int height) : usePbuffers(false) { int mindim = 0; int origtexsize = 0; - this->usePbuffers = 1; + this->usePbuffers = true; - this->texsize=texsize; + this->texsize = texsize; if(this->usePbuffers) @@ -57,8 +71,9 @@ RenderTarget::RenderTarget(int texsize, int width, int height) : usePbuffers(fal glGenRenderbuffersEXT(1, &depth_rb); glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depth_rb ); glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, this->texsize,this->texsize ); - glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb ); - this->fbuffer[0] = depth_rb; + glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb ); + this->fbuffer = fb; + this->depthb = depth_rb; glGenTextures(1, &other_tex); glBindTexture(GL_TEXTURE_2D,other_tex); @@ -148,7 +163,7 @@ void RenderTarget::lock() { if(this->usePbuffers) { - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this->fbuffer[0]); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this->fbuffer); } } diff --git a/src/projectM-engine/PBuffer.hpp b/src/projectM-engine/PBuffer.hpp index f5474860e..03e572e1f 100755 --- a/src/projectM-engine/PBuffer.hpp +++ b/src/projectM-engine/PBuffer.hpp @@ -69,7 +69,9 @@ public: int usePbuffers; - + + ~RenderTarget(); + RenderTarget( int texsize, int width, int height ); void lock(); void unlock(); @@ -85,8 +87,8 @@ int usePbuffers; */ /** Render target texture ID for non-pbuffer systems */ GLuint textureID[2]; - GLuint fbuffer[1]; - GLuint depthb[1]; + GLuint fbuffer; + GLuint depthb; }; diff --git a/src/projectM-engine/Param.cpp b/src/projectM-engine/Param.cpp index 51e6223b8..045e621cb 100755 --- a/src/projectM-engine/Param.cpp +++ b/src/projectM-engine/Param.cpp @@ -37,6 +37,7 @@ #include "Param.hpp" #include "Preset.hpp" #include +#include /** Constructor */ Param::Param( std::string _name, short int _type, short int _flags, void * _engine_val, void * _matrix, @@ -52,11 +53,6 @@ Param::Param( std::string _name, short int _type, short int _flags, void * _engi lower_bound (_lower_bound) { - /** @@FIX THIS */ - /// @bug listen to above's advice! - /// @NOTE this is a hack, but will probably work fine - projectM::currentEngine->getCurrentMeshSize(this->gx, this->gy); - } @@ -78,42 +74,17 @@ Param::Param(std::string _name) : /// @note may have fixed a recent bug. testing *((float*)engine_val) = default_init_val.float_val; - - /** @@FIX THIS */ - /// @bug listen to above's advice! - /// @NOTE this is a hack, but will probably work fine - - projectM::currentEngine->getCurrentMeshSize(this->gx, this->gy); - assert(this->gx > 0); - assert(this->gy > 0); } /* Free's a parameter type */ Param::~Param() { - int x; - // I hate this, but will let it be for now if (flags & P_FLAG_USERDEF) { delete((double*)engine_val); } - //if (!(param->flags & P_FLAG_DONT_FREE_MATRIX)) { - if (matrix && !(flags & P_FLAG_DONT_FREE_MATRIX)) { - - if (flags & P_FLAG_PER_POINT) { - free(matrix); - matrix = 0; - } //FIX THIS NOW XMAS05 - else if (flags & P_FLAG_PER_PIXEL) { - for (x = 0; x < gx; x++) - free(((float**)matrix)[x]); - free(matrix); - matrix = 0; - } - } - if (PARAM_DEBUG) printf("~Param: freeing \"%s\".\n", name.c_str()); } diff --git a/src/projectM-engine/Param.hpp b/src/projectM-engine/Param.hpp index cdb8e3fe5..0ad2b614d 100755 --- a/src/projectM-engine/Param.hpp +++ b/src/projectM-engine/Param.hpp @@ -46,7 +46,6 @@ #define P_FLAG_QVAR (1 << 2) #define P_FLAG_TVAR (1 << 3) #define P_FLAG_ALWAYS_MATRIX (1 << 4) -#define P_FLAG_DONT_FREE_MATRIX (1 << 5) #define P_FLAG_PER_PIXEL (1 << 6) #define P_FLAG_PER_POINT (1 << 7) @@ -72,7 +71,6 @@ public: CValue default_init_val; /* a default initial condition value */ CValue upper_bound; /* this parameter's upper bound */ CValue lower_bound; /* this parameter's lower bound */ - int gx, gy; /// Create a new parameter Param(std::string name, short int type, short int flags, diff --git a/src/projectM-engine/PerPixelEqn.cpp b/src/projectM-engine/PerPixelEqn.cpp index ebeb95aeb..f6ac690be 100755 --- a/src/projectM-engine/PerPixelEqn.cpp +++ b/src/projectM-engine/PerPixelEqn.cpp @@ -54,14 +54,8 @@ void PerPixelEqn::evaluate(int mesh_i, int mesh_j) { assert(!(eqn_ptr == NULL || param_matrix == NULL)); -// 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); - // } - - + param_matrix[mesh_i][mesh_j] = eqn_ptr->eval_gen_expr(mesh_i, mesh_j); + /* Now that this parameter has been referenced with a per pixel equation, we let the evaluator know by setting this flag */ diff --git a/src/projectM-engine/PresetLoader.cpp b/src/projectM-engine/PresetLoader.cpp index 962e23756..fe330051a 100644 --- a/src/projectM-engine/PresetLoader.cpp +++ b/src/projectM-engine/PresetLoader.cpp @@ -96,7 +96,8 @@ void PresetLoader::rescan() } // 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) + for (std::set::iterator pos = alphaSortedFileSet.begin(); + pos != alphaSortedFileSet.end();++pos) m_entries.push_back(*pos); } @@ -107,7 +108,7 @@ std::auto_ptr PresetLoader::loadPreset(unsigned int index, const PresetI assert(index >= 0); assert(index < m_entries.size()); - // Return a new pointer to a present + // Return a new autopointer to a present return std::auto_ptr(new Preset(m_entries[index], presetInputs, presetOutputs)); } diff --git a/src/projectM-engine/Renderer.cpp b/src/projectM-engine/Renderer.cpp index ab369121a..cbdd7aed0 100644 --- a/src/projectM-engine/Renderer.cpp +++ b/src/projectM-engine/Renderer.cpp @@ -7,6 +7,7 @@ #include "CustomWave.hpp" #include "TextureManager.hpp" #include +#include class Preset; @@ -72,8 +73,10 @@ Renderer::Renderer(int width, int height, int gx, int gy, RenderTarget *renderTa this->origx2[x][y]=( origx-.5)*2; this->origy2[x][y]=( origy-.5)*2; - }} + } + } + /// @bug put these on member init list this->renderTarget = renderTarget; this->beatDetect = beatDetect; this->textureManager = textureManager; @@ -272,33 +275,45 @@ Renderer::~Renderer() { int x; +#if 1 + std::cerr << "freeing grid elements" << std::endl; + assert(gx > 0); for(x = 0; x < this->gx; x++) { free(this->gridx[x]); - free(this->gridy[x]); + free(this->gridy[x]); free(this->origx2[x]); - free(this->origy2[x]); + free(this->origy2[x]); } + + std::cerr << "freeing grids" << std::endl; free(this->origx2); free(this->origy2); free(this->gridx); free(this->gridy); - +#endif +#if 1 +std::cerr << "grid assign begin " << std::endl; this->origx2 = NULL; this->origy2 = NULL; this->gridx = NULL; this->gridy = NULL; + +std::cerr << "grid assign end" << std::endl; +#endif #ifdef USE_FTGL + std::cerr << "freeing title fonts" << std::endl; if (title_font) delete title_font; if (poly_font) delete poly_font; if (other_font) delete other_font; + std::cerr << "freeing title fonts finished" << std::endl; #endif - + std::cerr << "exiting destructor" << std::endl; } diff --git a/src/projectM-engine/projectM.cpp b/src/projectM-engine/projectM.cpp index fd9e49913..2c7aaec28 100755 --- a/src/projectM-engine/projectM.cpp +++ b/src/projectM-engine/projectM.cpp @@ -48,6 +48,7 @@ #include "CustomWave.hpp" #include "CustomShape.hpp" #include "IdlePreset.hpp" +#include "MoodBar.hpp" #include @@ -56,8 +57,6 @@ #include "ConfigFile.h" #include "TextureManager.hpp" -/** Stash current engine */ -projectM *projectM::currentEngine = NULL; double presetDuration = 15; @@ -77,29 +76,30 @@ DLLEXPORT projectM::~projectM() { std::cerr << "[projectM] DESTROY PRESET TOOLS BEGIN" << std::endl; destroyPresetTools(); std::cerr << "[projectM] DESTROY PRESET TOOLS END" << std::endl; - + std::cerr << "[projectM] 1" << std::endl; - if (beatDetect) - delete(beatDetect); -std::cerr << "[projectM] 2" << std::endl; if (renderer) delete(renderer); +std::cerr << "[projectM] 2" << std::endl; + if (textureManager) + delete(textureManager); std::cerr << "[projectM] 3" << std::endl; + if (beatDetect) + delete(beatDetect); +std::cerr << "[projectM] 4" << std::endl; if (renderTarget) delete(renderTarget); -std::cerr << "[projectM] 4" << std::endl; - if (textureManager) - delete(textureManager); std::cerr << "[projectM] 5" << std::endl; + } -DLLEXPORT projectM::projectM(std::string config_file) :smoothFrame(0), beatDetect ( 0 ) +DLLEXPORT projectM::projectM(std::string config_file) : + renderer(0), renderTarget(0), smoothFrame(0), beatDetect ( 0 ) { projectM_reset(); readConfig(config_file); - } void projectM::readConfig(std::string config_file) @@ -163,6 +163,14 @@ DLLEXPORT void projectM::renderFrame() beatDetect->detectFromSamples(); +#ifdef USE_MOODBAR + float rgb[3]; + moodBar->calculateMood(rgb); + presetInputs.mood_r = rgb[0]; + presetInputs.mood_g = rgb[1]; + presetInputs.mood_b = rgb[2]; +#endif + DWRITE ( "=== vol: %f\tbass: %f\tmid: %f\ttreb: %f ===\n", beatDetect->vol,beatDetect->bass,beatDetect->mid,beatDetect->treb ); DWRITE ( "=== bass_att: %f ===\n", @@ -174,7 +182,7 @@ DLLEXPORT void projectM::renderFrame() presetInputs.bass_att = beatDetect->bass_att; presetInputs.mid_att = beatDetect->mid_att; presetInputs.treb_att = beatDetect->treb_att; - + assert(m_activePreset.get()); m_activePreset->evaluateFrame(); @@ -367,6 +375,7 @@ DLLEXPORT void projectM::projectM_reset() presetInputs.fps = fps; /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */ + assert(!beatDetect); beatDetect = new BeatDetect(); /* Preset loading function */ @@ -771,8 +780,6 @@ void projectM::projectM_resetengine() /* Q VARIABLES END */ - /** Stash the current engine */ - currentEngine = this; } /** Resets OpenGL state */ @@ -894,7 +901,3 @@ void projectM::destroyPresetTools() } -void projectM::getCurrentMeshSize(int & x, int & y) { - x = this->presetInputs.gx; - y = this->presetInputs.gy; -} diff --git a/src/projectM-engine/projectM.hpp b/src/projectM-engine/projectM.hpp index 7412e4ba2..21c7c3919 100755 --- a/src/projectM-engine/projectM.hpp +++ b/src/projectM-engine/projectM.hpp @@ -82,6 +82,7 @@ class PresetIterator; class PresetChooser; class PresetLoader; class TextureManager; +class MoodBar; #include #ifdef WIN32 @@ -207,7 +208,7 @@ public: /// Deinitialize all preset related tools. Usually done before projectM cleanup void destroyPresetTools(); - void getCurrentMeshSize(int & x, int & y); + ~projectM(); private: @@ -225,6 +226,8 @@ public: std::auto_ptr m_activePreset; std::auto_ptr m_activePreset2; + MoodBar * moodBar; + /** All readonly variables * which are passed as inputs * to presets. See struct definitition above */