From f7fee506c9ddece72dded24fa25194574dec2478 Mon Sep 17 00:00:00 2001 From: psperl Date: Sun, 5 Aug 2007 05:04:35 +0000 Subject: [PATCH] various touch ups, minor bug fix. git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/personal/carm/dev-1.0@291 6778bc44-b910-0410-a7a0-be141de4315d --- src/projectM-engine/Common.hpp | 1 + src/projectM-engine/Param.cpp | 9 +- src/projectM-engine/Preset.cpp | 26 +- src/projectM-engine/PresetFrameIO.cpp | 9 +- src/projectM-engine/PresetLoader.cpp | 4 +- src/projectM-engine/Renderer.cpp | 7 +- src/projectM-engine/console_interface.cpp | 50 +- src/projectM-engine/projectM.cpp | 909 ++++++++++++---------- src/projectM-engine/projectM.hpp | 22 +- src/projectM-iTunes/iprojectM.cpp | 2 + src/projectM-xmms/main.cpp | 2 +- 11 files changed, 546 insertions(+), 495 deletions(-) diff --git a/src/projectM-engine/Common.hpp b/src/projectM-engine/Common.hpp index 849703ec6..78fb7b514 100755 --- a/src/projectM-engine/Common.hpp +++ b/src/projectM-engine/Common.hpp @@ -80,6 +80,7 @@ extern FILE *fmemopen(void *buf, size_t len, const char *pMode); #endif /** WIN32 */ inline void DWRITE( char *fmt, ... ) { + return; va_list args; va_start( args, fmt ); //#ifdef DEBUG diff --git a/src/projectM-engine/Param.cpp b/src/projectM-engine/Param.cpp index 8b5a570bc..610605469 100755 --- a/src/projectM-engine/Param.cpp +++ b/src/projectM-engine/Param.cpp @@ -57,8 +57,7 @@ Param::Param( std::string _name, short int _type, short int _flags, void * _engi /** @@FIX THIS */ /// @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; + projectM::currentEngine->getCurrentMeshSize(this->gx, this->gy); } @@ -78,12 +77,12 @@ Param::Param(std::string _name) : upper_bound.float_val = DEFAULT_DOUBLE_UB; lower_bound.float_val = DEFAULT_DOUBLE_LB; - /** @@FIX THIS */ /// @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; + projectM::currentEngine->getCurrentMeshSize(this->gx, this->gy); + + } /* Free's a parameter type */ diff --git a/src/projectM-engine/Preset.cpp b/src/projectM-engine/Preset.cpp index e432592e5..fc6b8ae6c 100755 --- a/src/projectM-engine/Preset.cpp +++ b/src/projectM-engine/Preset.cpp @@ -40,9 +40,18 @@ Preset::Preset(const std::string & filename, const PresetInputs & presetInputs, builtinParams(presetInputs, presetOutputs), customWaves(&presetOutputs.customWaves), customShapes(&presetOutputs.customShapes), - m_presetOutputs(presetOutputs) + m_presetOutputs(presetOutputs) { -{ + m_presetOutputs.zoom_is_mesh = false; + m_presetOutputs.zoomexp_is_mesh =false; + m_presetOutputs.rot_is_mesh =false; + m_presetOutputs.sx_is_mesh =false; + m_presetOutputs.sy_is_mesh = false; + m_presetOutputs.dx_is_mesh = false; + m_presetOutputs.dy_is_mesh =false; + m_presetOutputs.cx_is_mesh = false; + m_presetOutputs.cy_is_mesh = false; + initialize(filename); @@ -51,12 +60,7 @@ Preset::Preset(const std::string & filename, const PresetInputs & presetInputs, Preset::~Preset() { - -#if defined(PRESET_DEBUG) && defined(DEBUG) - DWRITE( "~preset(): in\n" ); -#endif - - + std::cout << "Preset destructor!" << std::endl; Algorithms::traverse >(init_cond_tree); @@ -75,12 +79,6 @@ Preset::~Preset() for (PresetOutputs::cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos) delete(pos->second); - -#if defined(PRESET_DEBUG) && defined(DEBUG) - DWRITE( "~Preset(): out\n" ); -#endif - - } /* Adds a per pixel equation according to its string name. This will be used only by the parser */ diff --git a/src/projectM-engine/PresetFrameIO.cpp b/src/projectM-engine/PresetFrameIO.cpp index c83028cb1..f123460d6 100644 --- a/src/projectM-engine/PresetFrameIO.cpp +++ b/src/projectM-engine/PresetFrameIO.cpp @@ -5,6 +5,7 @@ #include PresetInputs::PresetInputs() { + } void PresetInputs::Initialize(int gx, int gy) @@ -23,8 +24,7 @@ void PresetInputs::Initialize(int gx, int gy) this->y_mesh=(float **)wipemalloc(gx * sizeof(float *)); for(x = 0; x < gx; x++) { - this->y_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); - + this->y_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); } this->rad_mesh=(float **)wipemalloc(gx * sizeof(float *)); for(x = 0; x < gx; x++) @@ -79,6 +79,7 @@ PresetOutputs::PresetOutputs() void PresetOutputs::Initialize(int gx, int gy) { + int x; this->sx_mesh=(float **)wipemalloc(gx * sizeof(float *)); for(x = 0; x < gx; x++) @@ -125,8 +126,8 @@ void PresetOutputs::Initialize(int gx, int gy) { this->rot_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); } - zoom_is_mesh = false; - zoomexp_is_mesh =false; + zoom_is_mesh = false; + zoomexp_is_mesh =false; rot_is_mesh =false; sx_is_mesh =false; diff --git a/src/projectM-engine/PresetLoader.cpp b/src/projectM-engine/PresetLoader.cpp index 463fda62e..f5cdef1b4 100644 --- a/src/projectM-engine/PresetLoader.cpp +++ b/src/projectM-engine/PresetLoader.cpp @@ -103,7 +103,7 @@ Preset * PresetLoader::loadPreset(unsigned int index, const PresetInputs & prese assert(index >= 0); assert(index < m_entries.size()); - // Return a new auto pointer to a present + // Return a new pointer to a present return new Preset(m_entries[index], presetInputs, presetOutputs); } @@ -119,7 +119,7 @@ void PresetLoader::handleDirectoryError() case ENOMEM: std::cerr << "[PresetLoader] out of memory! Are you running Windows?" << std::endl; abort(); - case ENOTDIR: + case ENOTDIR: std::cerr << "[PresetLoader] directory specified is not a preset directory! Cannot continue." << std::endl; break; case ENFILE: diff --git a/src/projectM-engine/Renderer.cpp b/src/projectM-engine/Renderer.cpp index 15cf7d0fe..c7689cb82 100644 --- a/src/projectM-engine/Renderer.cpp +++ b/src/projectM-engine/Renderer.cpp @@ -408,12 +408,13 @@ void Renderer::PerPixelMath(PresetOutputs *presetOutputs, PresetInputs *presetIn { for (x=0;xgx;x++){ for(y=0;ygy;y++){ - presetOutputs->zoomexp_mesh[x][y]=presetOutputs->zoomexp; - }} + presetOutputs->zoomexp_mesh[x][y]=presetOutputs->zoomexp; + } + } } if(!presetOutputs->rot_is_mesh) - { + { for (x=0;xgx;x++){ for(y=0;ygy;y++){ presetOutputs->rot_mesh[x][y]=presetOutputs->rot; diff --git a/src/projectM-engine/console_interface.cpp b/src/projectM-engine/console_interface.cpp index 93b8f9816..9b5cfc8ac 100755 --- a/src/projectM-engine/console_interface.cpp +++ b/src/projectM-engine/console_interface.cpp @@ -32,7 +32,7 @@ #include "event.h" #include "BeatDetect.hpp" #include "PresetChooser.hpp" - +#include interface_t current_interface = DEFAULT_INTERFACE; @@ -155,35 +155,35 @@ void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode case PROJECTM_K_b: break; case PROJECTM_K_n: + // paranoia but could be useful if directory is empty - /// @bug implement == operator - if (!(*m_presetPos != m_presetChooser->end())) - return; - m_presetChooser->getNumPresets(); + if ((*m_presetPos == m_presetChooser->end())) + break; + ++(*m_presetPos); - /// @bug implement == operator - if (!((*m_presetPos) != m_presetChooser->end())) + + if (((*m_presetPos) == m_presetChooser->end())) { --(*m_presetPos); - delete(m_activePreset); - m_activePreset = m_presetPos->allocate(this->presetInputs, this->presetOutputs ); - break; - case PROJECTM_K_r: -// if (PresetSwitcher::switchPreset(RANDOM_NEXT, HARD_CUT) < 0) { - printf("WARNING: Bad preset file, loading idle preset\n"); - abort(); -// } - break; - case PROJECTM_K_p: - if (*m_presetPos != m_presetChooser->begin()) { - --(*m_presetPos); - // ...mroe + break; } - -// if ((PresetSwitcher::switchPreset(ALPHA_PREVIOUS, HARD_CUT)) < 0){ - printf("WARNING: Bad preset file, loading idle preset\n"); - abort(); -// } + if (m_activePreset) + delete(m_activePreset); + m_activePreset = m_presetPos->allocate(this->presetInputs, this->presetOutputs ); + break; + case PROJECTM_K_r: + std::cout << "Warning: random unimplemented" << std::endl; + break; + case PROJECTM_K_p: + + if (*m_presetPos != m_presetChooser->begin()) { + --(*m_presetPos); + if (m_activePreset) + delete(m_activePreset); + m_activePreset = m_presetPos->allocate(this->presetInputs, this->presetOutputs ); + + // ...mroe + } break; case PROJECTM_K_l: if (renderer->noSwitch==0)renderer->noSwitch=1; else renderer->noSwitch=0; diff --git a/src/projectM-engine/projectM.cpp b/src/projectM-engine/projectM.cpp index b470fdc89..523ae4cae 100755 --- a/src/projectM-engine/projectM.cpp +++ b/src/projectM-engine/projectM.cpp @@ -50,303 +50,335 @@ #include "PresetChooser.hpp" #ifdef LINUX -const std::string projectM::PROJECTM_PRESET_PATH("/usr/share/projectM/presets/"); +const std::string projectM::PROJECTM_PRESET_PATH ( "/usr/share/projectM/presets/" ); #endif #ifdef MACOS -const std::string projectM::PROJECTM_PRESET_PATH("/usr/share/projectM/presets/"); +const std::string projectM::PROJECTM_PRESET_PATH ( "/usr/share/projectM/presets/" ); #endif #ifdef WIN32 -const std::string projectM::PROJECTM_PRESET_PATH("C:\\Program Files\\ProjectM\\presets"); +const std::string projectM::PROJECTM_PRESET_PATH ( "C:\\Program Files\\ProjectM\\presets" ); #endif /** Stash current engine */ projectM *projectM::currentEngine = NULL; -/** Static variable initialization involving the render. */ +/** Static variable initialization involving the render. */ /// @bug These probably shouldn't be static! RenderTarget * projectM::renderTarget = NULL; Renderer * projectM::renderer = NULL; -DLLEXPORT projectM::projectM():beatDetect(0), m_activePreset(0) { +DLLEXPORT projectM::projectM() :beatDetect ( 0 ), m_activePreset ( 0 ) +{ + } -DLLEXPORT void projectM::renderFrame() { +DLLEXPORT void projectM::renderFrame() +{ #ifdef DEBUG - char fname[1024]; - FILE *f = NULL; - int index = 0; - int x, y; + char fname[1024]; + FILE *f = NULL; + int index = 0; + int x, y; #endif // printf("Start of loop at %d\n",timestart); - - mspf=(int)(1000.0/(float)presetInputs.fps); //milliseconds per frame + mspf= ( int ) ( 1000.0/ ( float ) presetInputs.fps ); //milliseconds per frame #ifndef WIN32 - presetInputs.time = getTicks( &startTime ) * 0.001; + presetInputs.time = getTicks ( &startTime ) * 0.001; #else - presetInputs.time = getTicks( startTime ) * 0.001; + presetInputs.time = getTicks ( startTime ) * 0.001; #endif /** !WIN32 */ - presetInputs.frame++; //number of frames for current preset - presetInputs.progress= presetInputs.frame/(float)avgtime; - DWRITE( "frame: %d\ttime: %f\tprogress: %f\tavgtime: %d\tang: %f\trot: %f\n", - this->presetInputs.frame, presetInputs.time, this->presetInputs.progress, this->avgtime, this->presetInputs.ang_per_pixel, - this->presetOutputs.rot ); - if (presetInputs.progress>1.0) presetInputs.progress=1.0; + presetInputs.frame++; //number of frames for current preset + presetInputs.progress= presetInputs.frame/ ( float ) avgtime; + DWRITE ( "frame: %d\ttime: %f\tprogress: %f\tavgtime: %d\tang: %f\trot: %f\n", + this->presetInputs.frame, presetInputs.time, this->presetInputs.progress, this->avgtime, this->presetInputs.ang_per_pixel, + this->presetOutputs.rot ); + if ( presetInputs.progress>1.0 ) presetInputs.progress=1.0; // printf("start:%d at:%d min:%d stop:%d on:%d %d\n",startframe, frame frame-startframe,avgtime, noSwitch,progress); - presetInputs.ResetMesh(); - + presetInputs.ResetMesh(); - // assert(m_activePreset.get()); - m_activePreset->evaluateFrame(); + +// assert(m_activePreset.get()); + m_activePreset->evaluateFrame(); // printf("%f %d\n",Time,frame); - beatDetect->detectFromSamples(); - DWRITE( "=== vol: %f\tbass: %f\tmid: %f\ttreb: %f ===\n", - beatDetect->vol,beatDetect->bass,beatDetect->mid,beatDetect->treb); - DWRITE( "=== bass_att: %f ===\n", - beatDetect->bass_att ); + beatDetect->detectFromSamples(); + DWRITE ( "=== vol: %f\tbass: %f\tmid: %f\ttreb: %f ===\n", + beatDetect->vol,beatDetect->bass,beatDetect->mid,beatDetect->treb ); + DWRITE ( "=== bass_att: %f ===\n", + beatDetect->bass_att ); - if (renderer->noSwitch==0) { - nohard--; - if ((beatDetect->bass-beatDetect->bass_old>beatDetect->beat_sensitivity || - avgtime ) && nohard<0) { + if ( renderer->noSwitch==0 ) + { + nohard--; + if ( ( beatDetect->bass-beatDetect->bass_old>beatDetect->beat_sensitivity || + avgtime ) && nohard<0 ) + { // printf("%f %d %d\n", beatDetect->bass-beatDetect->bass_old,this->frame,this->avgtime); // switchPreset(RANDOM_NEXT, HARD_CUT); - nohard=presetInputs.fps*5; - } - } + nohard=presetInputs.fps*5; + } + } - count++; + count++; - renderer->RenderFrame(&presetOutputs, &presetInputs); + renderer->RenderFrame ( &presetOutputs, &presetInputs ); #ifndef WIN32 - /** Frame-rate limiter */ - /** Compute once per preset */ - if (this->count%100==0) { - this->renderer->realfps=100.0/((getTicks(&this->startTime)-this->fpsstart)/1000); - this->fpsstart=getTicks(&this->startTime); - } + /** Frame-rate limiter */ + /** Compute once per preset */ + if ( this->count%100==0 ) + { + this->renderer->realfps=100.0/ ( ( getTicks ( &this->startTime )-this->fpsstart ) /1000 ); + this->fpsstart=getTicks ( &this->startTime ); + } - int timediff = getTicks(&this->startTime)-this->timestart; + int timediff = getTicks ( &this->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(&this->startTime); + 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 ( &this->startTime ); #endif /** !WIN32 */ - DWRITE( "exiting renderFrame()\n" ); + DWRITE ( "exiting renderFrame()\n" ); } -DLLEXPORT void projectM::projectM_reset() { +DLLEXPORT void projectM::projectM_reset() +{ - DWRITE( "projectM_reset(): in\n" ); +// DWRITE( "projectM_reset(): in\n" ); - m_activePreset = 0; + /// @bug uncertain if preset should be played with here - carm +// m_activePreset = 0; - this->presetURL = NULL; - this->fontURL = NULL; +// if (m_activePreset) { +// delete(m_activePreset); + // m_activePreset = 0; + // } - /** Default variable settings */ - this->hasInit = 0; + this->presetURL = NULL; + this->fontURL = NULL; - this->pcmframes = 1; - this->freqframes = 0; + /** Default variable settings */ + this->hasInit = 0; + + this->pcmframes = 1; + this->freqframes = 0; - this->fvw = 800; - this->fvh = 600; - this->wvw = 512; - this->wvh = 512; - this->fullscreen = 0; + this->fvw = 800; + this->fvh = 600; + this->wvw = 512; + this->wvh = 512; + this->fullscreen = 0; - /** Frames per preset */ - this->avgtime = 500; + /** Frames per preset */ + this->avgtime = 500; - /** More other stuff */ - this->mspf = 0; - this->timed = 0; - this->timestart = 0; - this->nohard = 0; - this->count = 0; + /** More other stuff */ + this->mspf = 0; + this->timed = 0; + this->timestart = 0; + this->nohard = 0; + this->count = 0; - this->fpsstart = 0; + this->fpsstart = 0; - projectM_resetengine(); + projectM_resetengine(); } -DLLEXPORT void projectM::projectM_init(int gx, int gy, int fps, int texsize, int width, int height) { +DLLEXPORT void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, int height ) +{ - /** Initialise engine variables */ + /** Initialise engine variables */ - - projectM_initengine(); - presetInputs.Initialize(gx, gy); - presetOutputs.Initialize(gx, gy); + projectM_initengine(); + presetInputs.Initialize ( gx, gy ); + presetOutputs.Initialize ( gx, gy ); - DWRITE("projectM plugin: Initializing\n"); + DWRITE ( "projectM plugin: Initializing\n" ); - /** Initialise start time */ + /** Initialise start time */ #ifndef WIN32 - gettimeofday(&this->startTime, NULL); + gettimeofday ( &this->startTime, NULL ); #else - startTime = GetTickCount(); + startTime = GetTickCount(); #endif /** !WIN32 */ - /** Nullify frame stash */ - fbuffer = NULL; + /** Nullify frame stash */ + fbuffer = NULL; - /** Initialise per-pixel matrix calculations */ + /** Initialise per-pixel matrix calculations */ - presetInputs.fps = fps; + presetInputs.fps = fps; - /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */ - beatDetect = new BeatDetect(); + /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */ + beatDetect = new BeatDetect(); - /* Preset loading function */ - initPresetTools(); + /* Preset loading function */ + initPresetTools(); - /* Load default preset directory */ + /* Load default preset directory */ #ifdef MACOS2 - /** Probe the bundle for info */ - CFBundleRef bundle = CFBundleGetMainBundle(); - char msg[1024]; - sprintf( msg, "bundle: %X\n", bundle ); - DWRITE( msg ); - if ( bundle != NULL ) { - CFPlugInRef pluginRef = CFBundleGetPlugIn( bundle ); - if ( pluginRef != NULL ) { - DWRITE( "located plugin ref\n" ); - } else { - DWRITE( "failed to find plugin ref\n" ); - } + /** Probe the bundle for info */ + CFBundleRef bundle = CFBundleGetMainBundle(); + char msg[1024]; + sprintf ( msg, "bundle: %X\n", bundle ); + DWRITE ( msg ); + if ( bundle != NULL ) + { + CFPlugInRef pluginRef = CFBundleGetPlugIn ( bundle ); + if ( pluginRef != NULL ) + { + DWRITE ( "located plugin ref\n" ); + } + else + { + DWRITE ( "failed to find plugin ref\n" ); + } - CFURLRef bundleURL = CFBundleCopyBundleURL( bundle ); - if ( bundleURL == NULL ) { - DWRITE( "bundleURL failed\n" ); - } else { - DWRITE( "bundleURL OK\n" ); - } - char *bundleName = - (char *)CFStringGetCStringPtr( CFURLGetString( bundleURL ), kCFStringEncodingMacRoman ); - DWRITE( "bundleURL: %s\n", bundleName ); + CFURLRef bundleURL = CFBundleCopyBundleURL ( bundle ); + if ( bundleURL == NULL ) + { + DWRITE ( "bundleURL failed\n" ); + } + else + { + DWRITE ( "bundleURL OK\n" ); + } + char *bundleName = + ( char * ) CFStringGetCStringPtr ( CFURLGetString ( bundleURL ), kCFStringEncodingMacRoman ); + DWRITE ( "bundleURL: %s\n", bundleName ); - presetURL = CFBundleCopyResourceURL( bundle, purl, NULL, NULL ); - if ( presetURL != NULL ) { - this->presetURL = (char *)CFStringGetCStringPtr( CFURLCopyPath( presetURL ), kCFStringEncodingMacRoman); - sprintf( msg, "Preset: %s\n", presetURL ); - DWRITE( msg ); - printf( msg ); + presetURL = CFBundleCopyResourceURL ( bundle, purl, NULL, NULL ); + if ( presetURL != NULL ) + { + this->presetURL = ( char * ) CFStringGetCStringPtr ( CFURLCopyPath ( presetURL ), kCFStringEncodingMacRoman ); + sprintf ( msg, "Preset: %s\n", presetURL ); + DWRITE ( msg ); + printf ( msg ); - /** Stash the short preset name */ + /** Stash the short preset name */ - } else { - DWRITE( "Failed to probe 'presets' bundle ref\n" ); - this->presetURL = NULL; - } + } + else + { + DWRITE ( "Failed to probe 'presets' bundle ref\n" ); + this->presetURL = NULL; + } - fontURL = CFBundleCopyResourceURL( bundle, furl, NULL, NULL ); - if ( fontURL != NULL ) { - fontURL = (char *)CFStringGetCStringPtr( CFURLCopyPath( fontURL ), kCFStringEncodingMacRoman); - sprintf( msg, "Font: %s\n", fontURL ); - DWRITE( msg ); - printf( msg ); - } else { - DWRITE( "Failed to probe 'fonts' bundle ref\n" ); - fontURL = NULL; - } - } + fontURL = CFBundleCopyResourceURL ( bundle, furl, NULL, NULL ); + if ( fontURL != NULL ) + { + fontURL = ( char * ) CFStringGetCStringPtr ( CFURLCopyPath ( fontURL ), kCFStringEncodingMacRoman ); + sprintf ( msg, "Font: %s\n", fontURL ); + DWRITE ( msg ); + printf ( msg ); + } + else + { + DWRITE ( "Failed to probe 'fonts' bundle ref\n" ); + fontURL = NULL; + } + } - /** Sanity check */ - if ( bundle == NULL || presetURL == NULL || fontURL == NULL ) { - sprintf( msg, "defaulting presets\n" ); - DWRITE( msg ); - this->fontURL = (char *)wipemalloc( sizeof( char ) * 512 ); + /** Sanity check */ + if ( bundle == NULL || presetURL == NULL || fontURL == NULL ) + { + sprintf ( msg, "defaulting presets\n" ); + DWRITE ( msg ); + this->fontURL = ( char * ) wipemalloc ( sizeof ( char ) * 512 ); // strcpy( this->fontURL, "../../fonts/" ); - strcpy( fontURL, "/Users/descarte/tmp/projectM/fonts" ); - this->fontURL[34] = '\0'; + strcpy ( fontURL, "/Users/descarte/tmp/projectM/fonts" ); + this->fontURL[34] = '\0'; // loadPresetDir( "../../presets/" ); // loadPresetDir( "/Users/descarte/tmp/projectM-1.00/presets_projectM" ); - } else { - printf( "PresetDir: %s\n", this->presetURL ); - loadPresetDir( presetURL ); - } + } + else + { + printf ( "PresetDir: %s\n", this->presetURL ); + loadPresetDir ( presetURL ); + } #else - if ( presetURL == NULL || fontURL == NULL ) { - char msg[1024]; - sprintf( msg, "defaulting presets\n" ); - DWRITE( msg ); - fontURL = (char *)wipemalloc( sizeof( char ) * 512 ); + if ( presetURL == NULL || fontURL == NULL ) + { + char msg[1024]; + sprintf ( msg, "defaulting presets\n" ); + DWRITE ( msg ); + fontURL = ( char * ) wipemalloc ( sizeof ( char ) * 512 ); #ifdef WIN32 - strcpy( this->fontURL, "c:\\tmp\\projectM\\fonts" ); - fontURL[24] = '\0'; + strcpy ( this->fontURL, "c:\\tmp\\projectM\\fonts" ); + fontURL[24] = '\0'; #else - strcpy( this->fontURL, "/Users/descarte/tmp/projectM/fonts" ); - fontURL[34] = '\0'; + strcpy ( this->fontURL, "/Users/descarte/tmp/projectM/fonts" ); + fontURL[34] = '\0'; #endif - DWRITE( "loading font URL directly: %s\n", this->fontURL ); + DWRITE ( "loading font URL directly: %s\n", this->fontURL ); #ifdef WIN32 - // loadPresetDir( "c:\\tmp\\projectM\\presets_projectM" ); + // loadPresetDir( "c:\\tmp\\projectM\\presets_projectM" ); #else - // loadPresetDir( "/Users/descarte/tmp/projectM-1.00/presets_projectM" ); + // loadPresetDir( "/Users/descarte/tmp/projectM-1.00/presets_projectM" ); #endif - } else { - printf( "PresetDir: %s\n", this->presetURL ); - //loadPresetDir( presetURL ); - } + } + else + { + printf ( "PresetDir: %s\n", this->presetURL ); + //loadPresetDir( presetURL ); + } #endif - mspf=(int)(1000.0/(float)presetInputs.fps); + mspf= ( int ) ( 1000.0/ ( float ) presetInputs.fps ); // initMenu(); //DWRITE( "post initMenu()\n" ); - printf("mesh: %d %d\n", gx,gy ); + printf ( "mesh: %d %d\n", gx,gy ); #ifdef PANTS - printf( "maxsamples: %d\n", this->maxsamples ); - initPCM(this->maxsamples); - DWRITE( "post PCM init\n" ); + printf ( "maxsamples: %d\n", this->maxsamples ); + initPCM ( this->maxsamples ); + DWRITE ( "post PCM init\n" ); #endif - this->avgtime=this->presetInputs.fps*20; + this->avgtime=this->presetInputs.fps*20; - this->hasInit = 1; + this->hasInit = 1; - this->renderTarget = new RenderTarget(texsize, width, height); - this->presetInputs.gx = gx; - this->presetInputs.gy = gy; + this->renderTarget = new RenderTarget ( texsize, width, height ); + this->presetInputs.gx = gx; + this->presetInputs.gy = gy; - this->renderer = new Renderer(width, height, gx, gy, renderTarget, beatDetect, fontURL); + this->renderer = new Renderer ( width, height, gx, gy, renderTarget, beatDetect, fontURL ); - printf( "exiting projectM_init()\n" ); + printf ( "exiting projectM_init()\n" ); } @@ -357,346 +389,361 @@ DLLEXPORT void projectM::projectM_init(int gx, int gy, int fps, int texsize, int -DLLEXPORT void projectM::projectM_initengine() { +DLLEXPORT void projectM::projectM_initengine() +{ - /* PER FRAME CONSTANTS BEGIN */ - this->presetOutputs.zoom=1.0; - this->presetOutputs.zoomexp= 1.0; - this->presetOutputs.rot= 0.0; - this->presetOutputs.warp= 0.0; + /* PER FRAME CONSTANTS BEGIN */ + this->presetOutputs.zoom=1.0; + this->presetOutputs.zoomexp= 1.0; + this->presetOutputs.rot= 0.0; + this->presetOutputs.warp= 0.0; - this->presetOutputs.sx= 1.0; - this->presetOutputs.sy= 1.0; - this->presetOutputs.dx= 0.0; - this->presetOutputs.dy= 0.0; - this->presetOutputs.cx= 0.5; - this->presetOutputs.cy= 0.5; + this->presetOutputs.sx= 1.0; + this->presetOutputs.sy= 1.0; + this->presetOutputs.dx= 0.0; + this->presetOutputs.dy= 0.0; + this->presetOutputs.cx= 0.5; + this->presetOutputs.cy= 0.5; - this->presetOutputs.decay=.98; + this->presetOutputs.decay=.98; - this->presetOutputs.wave_r= 1.0; - this->presetOutputs.wave_g= 0.2; - this->presetOutputs.wave_b= 0.0; - this->presetOutputs.wave_x= 0.5; - this->presetOutputs.wave_y= 0.5; - this->presetOutputs.wave_mystery= 0.0; + this->presetOutputs.wave_r= 1.0; + this->presetOutputs.wave_g= 0.2; + this->presetOutputs.wave_b= 0.0; + this->presetOutputs.wave_x= 0.5; + this->presetOutputs.wave_y= 0.5; + this->presetOutputs.wave_mystery= 0.0; - this->presetOutputs.ob_size= 0.0; - this->presetOutputs.ob_r= 0.0; - this->presetOutputs.ob_g= 0.0; - this->presetOutputs.ob_b= 0.0; - this->presetOutputs.ob_a= 0.0; + this->presetOutputs.ob_size= 0.0; + this->presetOutputs.ob_r= 0.0; + this->presetOutputs.ob_g= 0.0; + this->presetOutputs.ob_b= 0.0; + this->presetOutputs.ob_a= 0.0; - this->presetOutputs.ib_size = 0.0; - this->presetOutputs.ib_r = 0.0; - this->presetOutputs.ib_g = 0.0; - this->presetOutputs.ib_b = 0.0; - this->presetOutputs.ib_a = 0.0; + this->presetOutputs.ib_size = 0.0; + this->presetOutputs.ib_r = 0.0; + this->presetOutputs.ib_g = 0.0; + this->presetOutputs.ib_b = 0.0; + this->presetOutputs.ib_a = 0.0; - this->presetOutputs.mv_a = 0.0; - this->presetOutputs.mv_r = 0.0; - this->presetOutputs.mv_g = 0.0; - this->presetOutputs.mv_b = 0.0; - this->presetOutputs.mv_l = 1.0; - this->presetOutputs.mv_x = 16.0; - this->presetOutputs.mv_y = 12.0; - this->presetOutputs.mv_dy = 0.02; - this->presetOutputs.mv_dx = 0.02; + this->presetOutputs.mv_a = 0.0; + this->presetOutputs.mv_r = 0.0; + this->presetOutputs.mv_g = 0.0; + this->presetOutputs.mv_b = 0.0; + this->presetOutputs.mv_l = 1.0; + this->presetOutputs.mv_x = 16.0; + this->presetOutputs.mv_y = 12.0; + this->presetOutputs.mv_dy = 0.02; + this->presetOutputs.mv_dx = 0.02; //this->presetInputs.meshx = 0; //this->presetInputs.meshy = 0; - this->presetInputs.progress = 0; - this->presetInputs.frame = 0; + this->presetInputs.progress = 0; + this->presetInputs.frame = 0; - this->avgtime = 600; + this->avgtime = 600; //bass_thresh = 0; - /* PER_FRAME CONSTANTS END */ - this->presetOutputs.fRating = 0; - this->presetOutputs.fGammaAdj = 1.0; - this->presetOutputs.fVideoEchoZoom = 1.0; - this->presetOutputs.fVideoEchoAlpha = 0; - this->presetOutputs.nVideoEchoOrientation = 0; + /* PER_FRAME CONSTANTS END */ + this->presetOutputs.fRating = 0; + this->presetOutputs.fGammaAdj = 1.0; + this->presetOutputs.fVideoEchoZoom = 1.0; + this->presetOutputs.fVideoEchoAlpha = 0; + this->presetOutputs.nVideoEchoOrientation = 0; - this->presetOutputs.nWaveMode = 7; - this->presetOutputs.bAdditiveWaves = 0; - this->presetOutputs.bWaveDots = 0; - this->presetOutputs.bWaveThick = 0; - this->presetOutputs.bModWaveAlphaByVolume = 0; - this->presetOutputs.bMaximizeWaveColor = 0; - this->presetOutputs.bTexWrap = 0; - this->presetOutputs.bDarkenCenter = 0; - this->presetOutputs.bRedBlueStereo = 0; - this->presetOutputs.bBrighten = 0; - this->presetOutputs.bDarken = 0; - this->presetOutputs.bSolarize = 0; - this->presetOutputs.bInvert = 0; - this->presetOutputs.bMotionVectorsOn = 1; + this->presetOutputs.nWaveMode = 7; + this->presetOutputs.bAdditiveWaves = 0; + this->presetOutputs.bWaveDots = 0; + this->presetOutputs.bWaveThick = 0; + this->presetOutputs.bModWaveAlphaByVolume = 0; + this->presetOutputs.bMaximizeWaveColor = 0; + this->presetOutputs.bTexWrap = 0; + this->presetOutputs.bDarkenCenter = 0; + this->presetOutputs.bRedBlueStereo = 0; + this->presetOutputs.bBrighten = 0; + this->presetOutputs.bDarken = 0; + this->presetOutputs.bSolarize = 0; + this->presetOutputs.bInvert = 0; + this->presetOutputs.bMotionVectorsOn = 1; - this->presetOutputs.fWaveAlpha =1.0; - this->presetOutputs.fWaveScale = 1.0; - this->presetOutputs.fWaveSmoothing = 0; - this->presetOutputs.fWaveParam = 0; - this->presetOutputs.fModWaveAlphaStart = 0; - this->presetOutputs.fModWaveAlphaEnd = 0; - this->presetOutputs.fWarpAnimSpeed = 0; - this->presetOutputs.fWarpScale = 0; - this->presetOutputs.fShader = 0; + this->presetOutputs.fWaveAlpha =1.0; + this->presetOutputs.fWaveScale = 1.0; + this->presetOutputs.fWaveSmoothing = 0; + this->presetOutputs.fWaveParam = 0; + this->presetOutputs.fModWaveAlphaStart = 0; + this->presetOutputs.fModWaveAlphaEnd = 0; + this->presetOutputs.fWarpAnimSpeed = 0; + this->presetOutputs.fWarpScale = 0; + this->presetOutputs.fShader = 0; - /* PER_PIXEL CONSTANTS BEGIN */ - this->presetInputs.x_per_pixel = 0; - this->presetInputs.y_per_pixel = 0; - this->presetInputs.rad_per_pixel = 0; - this->presetInputs.ang_per_pixel = 0; + /* PER_PIXEL CONSTANTS BEGIN */ + this->presetInputs.x_per_pixel = 0; + this->presetInputs.y_per_pixel = 0; + this->presetInputs.rad_per_pixel = 0; + this->presetInputs.ang_per_pixel = 0; - /* PER_PIXEL CONSTANT END */ + /* PER_PIXEL CONSTANT END */ - /* Q AND T VARIABLES START */ + /* Q AND T VARIABLES START */ - this->presetOutputs.q1 = 0; - this->presetOutputs.q2 = 0; - this->presetOutputs.q3 = 0; - this->presetOutputs.q4 = 0; - this->presetOutputs.q5 = 0; - this->presetOutputs.q6 = 0; - this->presetOutputs.q7 = 0; - this->presetOutputs.q8 = 0; + this->presetOutputs.q1 = 0; + this->presetOutputs.q2 = 0; + this->presetOutputs.q3 = 0; + this->presetOutputs.q4 = 0; + this->presetOutputs.q5 = 0; + this->presetOutputs.q6 = 0; + this->presetOutputs.q7 = 0; + this->presetOutputs.q8 = 0; - /* Q AND T VARIABLES END */ + /* Q AND T VARIABLES END */ //per pixel meshes -/* - // this->presetOutputs.zoom_mesh = NULL; - // this->presetOutputs.zoomexp_mesh = NULL; - //this->presetOutputs.rot_mesh = NULL; + /* + // this->presetOutputs.zoom_mesh = NULL; + // this->presetOutputs.zoomexp_mesh = NULL; + //this->presetOutputs.rot_mesh = NULL; - // this->presetOutputs.sx_mesh = NULL; - // this->presetOutputs.sy_mesh = NULL; - // this->presetOutputs.dx_mesh = NULL; - // this->presetOutputs.dy_mesh = NULL; - // this->presetOutputs.cx_mesh = NULL; - // this->presetOutputs.cy_mesh = NULL; + // this->presetOutputs.sx_mesh = NULL; + // this->presetOutputs.sy_mesh = NULL; + // this->presetOutputs.dx_mesh = NULL; + // this->presetOutputs.dy_mesh = NULL; + // this->presetOutputs.cx_mesh = NULL; + // this->presetOutputs.cy_mesh = NULL; + + // this->presetInputs.x_mesh = NULL; + / this->presetInputs.y_mesh = NULL; + // this->presetInputs.rad_mesh = NULL; + // this->presetInputs.theta_mesh = NULL; + */ - // this->presetInputs.x_mesh = NULL; - / this->presetInputs.y_mesh = NULL; - // this->presetInputs.rad_mesh = NULL; - // this->presetInputs.theta_mesh = NULL; -*/ - //custom wave per point meshes } /* Reinitializes the engine variables to a default (conservative and sane) value */ -DLLEXPORT void projectM::projectM_resetengine() { +DLLEXPORT void projectM::projectM_resetengine() +{ - this->presetOutputs.zoom=1.0; - this->presetOutputs.zoomexp= 1.0; - this->presetOutputs.rot= 0.0; - this->presetOutputs.warp= 0.0; + this->presetOutputs.zoom=1.0; + this->presetOutputs.zoomexp= 1.0; + this->presetOutputs.rot= 0.0; + this->presetOutputs.warp= 0.0; - this->presetOutputs.sx= 1.0; - this->presetOutputs.sy= 1.0; - this->presetOutputs.dx= 0.0; - this->presetOutputs.dy= 0.0; - this->presetOutputs.cx= 0.5; - this->presetOutputs.cy= 0.5; + this->presetOutputs.sx= 1.0; + this->presetOutputs.sy= 1.0; + this->presetOutputs.dx= 0.0; + this->presetOutputs.dy= 0.0; + this->presetOutputs.cx= 0.5; + this->presetOutputs.cy= 0.5; - this->presetOutputs.decay=.98; + this->presetOutputs.decay=.98; - this->presetOutputs.wave_r= 1.0; - this->presetOutputs.wave_g= 0.2; - this->presetOutputs.wave_b= 0.0; - this->presetOutputs.wave_x= 0.5; - this->presetOutputs.wave_y= 0.5; - this->presetOutputs.wave_mystery= 0.0; + this->presetOutputs.wave_r= 1.0; + this->presetOutputs.wave_g= 0.2; + this->presetOutputs.wave_b= 0.0; + this->presetOutputs.wave_x= 0.5; + this->presetOutputs.wave_y= 0.5; + this->presetOutputs.wave_mystery= 0.0; - this->presetOutputs.ob_size= 0.0; - this->presetOutputs.ob_r= 0.0; - this->presetOutputs.ob_g= 0.0; - this->presetOutputs.ob_b= 0.0; - this->presetOutputs.ob_a= 0.0; + this->presetOutputs.ob_size= 0.0; + this->presetOutputs.ob_r= 0.0; + this->presetOutputs.ob_g= 0.0; + this->presetOutputs.ob_b= 0.0; + this->presetOutputs.ob_a= 0.0; - this->presetOutputs.ib_size = 0.0; - this->presetOutputs.ib_r = 0.0; - this->presetOutputs.ib_g = 0.0; - this->presetOutputs.ib_b = 0.0; - this->presetOutputs.ib_a = 0.0; + this->presetOutputs.ib_size = 0.0; + this->presetOutputs.ib_r = 0.0; + this->presetOutputs.ib_g = 0.0; + this->presetOutputs.ib_b = 0.0; + this->presetOutputs.ib_a = 0.0; - this->presetOutputs.mv_a = 0.0; - this->presetOutputs.mv_r = 0.0; - this->presetOutputs.mv_g = 0.0; - this->presetOutputs.mv_b = 0.0; - this->presetOutputs.mv_l = 1.0; - this->presetOutputs.mv_x = 16.0; - this->presetOutputs.mv_y = 12.0; - this->presetOutputs.mv_dy = 0.02; - this->presetOutputs.mv_dx = 0.02; + this->presetOutputs.mv_a = 0.0; + this->presetOutputs.mv_r = 0.0; + this->presetOutputs.mv_g = 0.0; + this->presetOutputs.mv_b = 0.0; + this->presetOutputs.mv_l = 1.0; + this->presetOutputs.mv_x = 16.0; + this->presetOutputs.mv_y = 12.0; + this->presetOutputs.mv_dy = 0.02; + this->presetOutputs.mv_dx = 0.02; - if ( beatDetect != NULL ) { - beatDetect->reset(); - } - this->presetInputs.progress = 0; - this->presetInputs.frame = 0; + if ( beatDetect != NULL ) + { + beatDetect->reset(); + } + this->presetInputs.progress = 0; + this->presetInputs.frame = 0; // bass_thresh = 0; - /* PER_FRAME CONSTANTS END */ - this->presetOutputs.fRating = 0; - this->presetOutputs.fGammaAdj = 1.0; - this->presetOutputs.fVideoEchoZoom = 1.0; - this->presetOutputs.fVideoEchoAlpha = 0; - this->presetOutputs.nVideoEchoOrientation = 0; + /* PER_FRAME CONSTANTS END */ + this->presetOutputs.fRating = 0; + this->presetOutputs.fGammaAdj = 1.0; + this->presetOutputs.fVideoEchoZoom = 1.0; + this->presetOutputs.fVideoEchoAlpha = 0; + this->presetOutputs.nVideoEchoOrientation = 0; - this->presetOutputs.nWaveMode = 7; - this->presetOutputs.bAdditiveWaves = 0; - this->presetOutputs.bWaveDots = 0; - this->presetOutputs.bWaveThick = 0; - this->presetOutputs.bModWaveAlphaByVolume = 0; - this->presetOutputs.bMaximizeWaveColor = 0; - this->presetOutputs.bTexWrap = 0; - this->presetOutputs.bDarkenCenter = 0; - this->presetOutputs.bRedBlueStereo = 0; - this->presetOutputs.bBrighten = 0; - this->presetOutputs.bDarken = 0; - this->presetOutputs.bSolarize = 0; - this->presetOutputs.bInvert = 0; - this->presetOutputs.bMotionVectorsOn = 1; + this->presetOutputs.nWaveMode = 7; + this->presetOutputs.bAdditiveWaves = 0; + this->presetOutputs.bWaveDots = 0; + this->presetOutputs.bWaveThick = 0; + this->presetOutputs.bModWaveAlphaByVolume = 0; + this->presetOutputs.bMaximizeWaveColor = 0; + this->presetOutputs.bTexWrap = 0; + this->presetOutputs.bDarkenCenter = 0; + this->presetOutputs.bRedBlueStereo = 0; + this->presetOutputs.bBrighten = 0; + this->presetOutputs.bDarken = 0; + this->presetOutputs.bSolarize = 0; + this->presetOutputs.bInvert = 0; + this->presetOutputs.bMotionVectorsOn = 1; - this->presetOutputs.fWaveAlpha =1.0; - this->presetOutputs.fWaveScale = 1.0; - this->presetOutputs.fWaveSmoothing = 0; - this->presetOutputs.fWaveParam = 0; - this->presetOutputs.fModWaveAlphaStart = 0; - this->presetOutputs.fModWaveAlphaEnd = 0; - this->presetOutputs.fWarpAnimSpeed = 0; - this->presetOutputs.fWarpScale = 0; - this->presetOutputs.fShader = 0; + this->presetOutputs.fWaveAlpha =1.0; + this->presetOutputs.fWaveScale = 1.0; + this->presetOutputs.fWaveSmoothing = 0; + this->presetOutputs.fWaveParam = 0; + this->presetOutputs.fModWaveAlphaStart = 0; + this->presetOutputs.fModWaveAlphaEnd = 0; + this->presetOutputs.fWarpAnimSpeed = 0; + this->presetOutputs.fWarpScale = 0; + this->presetOutputs.fShader = 0; - /* PER_PIXEL CONSTANTS BEGIN */ - this->presetInputs.x_per_pixel = 0; - this->presetInputs.y_per_pixel = 0; - this->presetInputs.rad_per_pixel = 0; - this->presetInputs.ang_per_pixel = 0; + /* PER_PIXEL CONSTANTS BEGIN */ + this->presetInputs.x_per_pixel = 0; + this->presetInputs.y_per_pixel = 0; + this->presetInputs.rad_per_pixel = 0; + this->presetInputs.ang_per_pixel = 0; - /* PER_PIXEL CONSTANT END */ + /* PER_PIXEL CONSTANT END */ - /* Q VARIABLES START */ + /* Q VARIABLES START */ - this->presetOutputs.q1 = 0; - this->presetOutputs.q2 = 0; - this->presetOutputs.q3 = 0; - this->presetOutputs.q4 = 0; - this->presetOutputs.q5 = 0; - this->presetOutputs.q6 = 0; - this->presetOutputs.q7 = 0; - this->presetOutputs.q8 = 0; + this->presetOutputs.q1 = 0; + this->presetOutputs.q2 = 0; + this->presetOutputs.q3 = 0; + this->presetOutputs.q4 = 0; + this->presetOutputs.q5 = 0; + this->presetOutputs.q6 = 0; + this->presetOutputs.q7 = 0; + this->presetOutputs.q8 = 0; - /* Q VARIABLES END */ + /* Q VARIABLES END */ - /** Stash the current engine */ - currentEngine = this; + /** Stash the current engine */ + currentEngine = this; } /** Resets OpenGL state */ -DLLEXPORT void projectM::projectM_resetGL( int w, int h ) { +DLLEXPORT void projectM::projectM_resetGL ( int w, int h ) +{ - int mindim, origtexsize; + int mindim, origtexsize; - DWRITE( "projectM_resetGL(): in: %d x %d\n", w, h ); + DWRITE ( "projectM_resetGL(): in: %d x %d\n", w, h ); - /** Stash the new dimensions */ + /** Stash the new dimensions */ - renderer->reset(w,h); + renderer->reset ( w,h ); } /** Sets the title to display */ -DLLEXPORT void projectM::projectM_setTitle( char *title ) { - /* - if (strcmp(this->title, title)!=0) - {printf("new title\n"); - this->drawtitle=1; - - if ( this->title != NULL ) { - free( this->title ); - this->title = NULL; - } - - this->title = (char *)wipemalloc( sizeof( char ) * ( strlen( title ) + 1 ) ); - strcpy( this->title, title ); - - } - */ +DLLEXPORT void projectM::projectM_setTitle ( char *title ) +{ + /* + if (strcmp(this->title, title)!=0) + {printf("new title\n"); + this->drawtitle=1; + + if ( this->title != NULL ) { + free( this->title ); + this->title = NULL; + } + + this->title = (char *)wipemalloc( sizeof( char ) * ( strlen( title ) + 1 ) ); + strcpy( this->title, title ); + + } + */ } -int projectM::initPresetTools() { +int projectM::initPresetTools() +{ - /* Initializes the builtin function database */ - BuiltinFuncs::init_builtin_func_db(); + /* Initializes the builtin function database */ + BuiltinFuncs::init_builtin_func_db(); - /* Initializes all infix operators */ - Eval::init_infix_ops(); + /* Initializes all infix operators */ + Eval::init_infix_ops(); - /* Set the seed to the current time in seconds */ + /* Set the seed to the current time in seconds */ #ifdef WIN32 - srand(time(NULL)); + srand ( time ( NULL ) ); #endif - 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_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)) == 0) { - delete(m_presetLoader); - m_presetChooser = 0; - std::cerr << "[projectM] error allocating preset chooser" << std::endl; - return PROJECTM_FAILURE; - } + 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. File path is \"" << m_activePreset->file_path << "\"" << std::endl; - projectM_resetengine(); + 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; + } - /* Done */ + std::cerr << "[projectM] Allocating first preset..." << std::endl; + m_activePreset = m_presetPos->allocate ( presetInputs, presetOutputs ); + + std::cerr << "[projectM] First preset allocated. File path is \"" << m_activePreset->file_path << "\"" << std::endl; + projectM_resetengine(); + + /* Done */ #ifdef PRESET_DEBUG - printf("initPresetLoader: finished\n"); + printf ( "initPresetLoader: finished\n" ); #endif - return PROJECTM_SUCCESS; + return PROJECTM_SUCCESS; } -void projectM::destroyPresetTools() { +void projectM::destroyPresetTools() +{ - if (m_presetChooser) - delete(m_presetChooser); + if ( m_presetChooser ) + delete ( m_presetChooser ); - if (m_presetLoader) - delete(m_presetLoader); + if ( m_presetLoader ) + delete ( m_presetLoader ); - Eval::destroy_infix_ops(); - BuiltinFuncs::destroy_builtin_func_db(); + Eval::destroy_infix_ops(); + BuiltinFuncs::destroy_builtin_func_db(); } + +void projectM::getCurrentMeshSize(int & x, int &y) { + x = this->presetInputs.gx; + y = this->presetInputs.gy; +} \ No newline at end of file diff --git a/src/projectM-engine/projectM.hpp b/src/projectM-engine/projectM.hpp index 84b482827..6ae3c22ad 100755 --- a/src/projectM-engine/projectM.hpp +++ b/src/projectM-engine/projectM.hpp @@ -172,16 +172,9 @@ public: /* PER_FRAME CONSTANTS END */ /** Beat detection engine */ - BeatDetect *beatDetect; + BeatDetect * beatDetect; - /** All readonly variables - * which are passed as inputs - * to presets. See struct definitition above */ - PresetInputs presetInputs; - - /** The presets modify these values. For now this is declared on stack - * but might be better on heap for sake of smooth preset switching */ - PresetOutputs presetOutputs; + /** Functions */ DLLEXPORT projectM(); @@ -223,7 +216,7 @@ public: /// Deinitialize all preset related tools. Usually done before projectM cleanup void destroyPresetTools(); - + void getCurrentMeshSize(int & x, int &y); private: // The current position of the directory iterator @@ -237,5 +230,14 @@ public: // Currently loaded preset- will be fancier when smooth preset switching Preset * m_activePreset; + + /** All readonly variables + * which are passed as inputs + * to presets. See struct definitition above */ + PresetInputs presetInputs; + + /** The presets modify these values. For now this is declared on stack + * but might be better on heap for sake of smooth preset switching */ + PresetOutputs presetOutputs; }; #endif diff --git a/src/projectM-iTunes/iprojectM.cpp b/src/projectM-iTunes/iprojectM.cpp index 1c70b7a0b..150cfc007 100755 --- a/src/projectM-iTunes/iprojectM.cpp +++ b/src/projectM-iTunes/iprojectM.cpp @@ -841,6 +841,8 @@ IMPEXP OSStatus MAIN (OSType message, PluginMessageInfo *messageInfo, void *refC #endif /** Initialise projectM */ + if (globalPM != 0) + delete(globalPM); globalPM = new projectM(); globalPM->projectM_reset(); diff --git a/src/projectM-xmms/main.cpp b/src/projectM-xmms/main.cpp index 242041257..4e5aae352 100755 --- a/src/projectM-xmms/main.cpp +++ b/src/projectM-xmms/main.cpp @@ -106,7 +106,7 @@ SDL_Surface *screen; //SDL_RenderTarget *RenderTarget = NULL; //GLuint RenderTargetTextureID; -projectM *globalPM = NULL; +static projectM * globalPM = NULL; int maxsamples=512;