diff --git a/src/linux/projectmDev10.kdevelop b/src/linux/projectmDev10.kdevelop index 745e0e430..711f28a9e 100644 --- a/src/linux/projectmDev10.kdevelop +++ b/src/linux/projectmDev10.kdevelop @@ -1,8 +1,8 @@ - Carmelo Piccione, Peter Sperl - carmelo.piccione@gmail.com, psperl@gmail.com + Carmelo Piccione + carmelo.piccione@gmail.com 1 KDevCustomProject C++ @@ -10,24 +10,23 @@ projectmDev10 ../../ false - + - + kdevsubversion - custom - /usr/local/bin/xmms - + executable + /home/pete/personal/carm/dev-1.0 + - /home/carm/projects/projectM/dev-1.0 + /home/pete/personal/carm/dev-1.0 false false - true - true + false + false false - /home/carm/projects/dev-1.0/src/ *.java @@ -48,7 +47,7 @@ make - /home/carm/projects/dev-1.0/src + src 0 @@ -66,8 +65,8 @@ 0 false make - - + + default @@ -76,18 +75,17 @@ - - - - - + + + + + true false false - - true + false true 10 @@ -161,7 +159,7 @@ true false true - 150 + 300 400 250 false @@ -179,13 +177,9 @@ true true .; - true - true - true - true - + set m_,_ theValue @@ -197,7 +191,9 @@ true Vertical - + + automatic_%2Fhome%2Fpete%2Fpersonal%2Fcarm%2Fdev-1.0 + diff --git a/src/linux/projectmDev10.kdevses b/src/linux/projectmDev10.kdevses index adba10e62..fdae90158 100644 --- a/src/linux/projectmDev10.kdevses +++ b/src/linux/projectmDev10.kdevses @@ -1,139 +1,26 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - + + + diff --git a/src/projectM-engine-backup/Algorithms.hpp b/src/projectM-engine-backup/Algorithms.hpp new file mode 100644 index 000000000..e7aed3712 --- /dev/null +++ b/src/projectM-engine-backup/Algorithms.hpp @@ -0,0 +1,50 @@ +#ifndef PROJECTM_ALGORITHMS_HPP +#define PROJECTM_ALGORITHMS_HPP + +namespace Algorithms +{ + + template + void traverse(Container & container) + { + + TraverseFunctor functor; + + for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos) + { + functor(pos->second); + } + + } + + + template + void traverse(Container & container, TraverseFunctor & functor) + { + + for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos) + { + functor(pos->second); + } + + } + + namespace TraverseFunctors + { + template + class DeleteFunctor + { + + public: + + void operator() (Data * data) + { + delete(data); + } + + }; + } + + +} +#endif diff --git a/src/projectM-engine-backup/BeatDetect.cpp b/src/projectM-engine-backup/BeatDetect.cpp new file mode 100755 index 000000000..fbfad1b28 --- /dev/null +++ b/src/projectM-engine-backup/BeatDetect.cpp @@ -0,0 +1,175 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * Takes sound data from wherever and returns beat detection values + * Uses statistical Energy-Based methods. Very simple + * + * Some stuff was taken from Frederic Patin's beat-detection article, + * you'll find it online + */ + +#include +#include + +#include "wipemalloc.h" + +#include "Common.hpp" +#include "projectM.hpp" +#include "BeatDetect.hpp" +#include "PCM.hpp" + +DLLEXPORT BeatDetect::BeatDetect() { + int x,y; + + this->vol_instant=0; + this->vol_history=0; + + for (y=0;y<80;y++) + { + this->vol_buffer[y]=0; + } + + this->beat_buffer_pos=0; + + for (x=0;x<32;x++) { + 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++) { + this->beat_buffer[x][y]=0; + } + } + + this->treb = 0; + this->mid = 0; + this->bass = 0; + this->bass_old = 0; + this->beat_sensitivity = 8.00; + this->treb_att = 0; + this->mid_att = 0; + this->bass_att = 0; + this->vol = 0; + + this->pcm = new PCM(); + } + +void BeatDetect::reset() { + 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->pcmdataL,pcm->pcmdataR); + } + +void BeatDetect::getBeatVals( float *vdataL,float *vdataR ) { + + int linear=0; + int x,y; + float temp2=0; + + vol_instant=0; + for ( x=0;x<16;x++) + { + + beat_instant[x]=0; + for ( y=linear*2;y<(linear+8+x)*2;y++) + { + beat_instant[x]+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/(8+x)); +// printf( "beat_instant[%d]: %f %f %f\n", x, beat_instant[x], vdataL[y], vdataR[y] ); + 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]; + beat_history[x]+=(beat_instant[x])*.0125; + + beat_val[x]=(beat_instant[x])/(beat_history[x]); + + 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; + + mid=0; + for(x=1;x<10;x++) + { + mid+=(beat_instant[x]); + temp2+=(beat_history[x]); + + } + + mid=mid/(1.5*temp2); + temp2=0; + treb=0; + for(x=10;x<16;x++) + { + 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); + + bass=(beat_instant[0])/(1.5*beat_history[0]); + + if ( isnan( treb ) ) { + treb = 0.0; + } + if ( isnan( mid ) ) { + mid = 0.0; + } + if ( isnan( bass ) ) { + bass = 0.0; + } + treb_att=.6 * treb_att + .4 * treb; + mid_att=.6 * mid_att + .4 * mid; + bass_att=.6 * bass_att + .4 * bass; + + DWRITE( "BeatDetect::getBeatVals: treb: %f\tmid: %f\tbass: %f\n", + treb, mid, bass ); + DWRITE( "BeatDetect::getBeatVals: treb_att: %f\tmid_att: %f\tbass_att: %f\n", + treb_att, mid_att, bass_att ); + + // *vol=(beat_instant[3])/(beat_history[3]); + beat_buffer_pos++; + if( beat_buffer_pos>79)beat_buffer_pos=0; + +} + + diff --git a/src/projectM-engine-backup/BeatDetect.hpp b/src/projectM-engine-backup/BeatDetect.hpp new file mode 100755 index 000000000..c43b9f8f1 --- /dev/null +++ b/src/projectM-engine-backup/BeatDetect.hpp @@ -0,0 +1,72 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Beat detection class. Takes decompressed sound buffers and returns + * various characteristics + * + * $Log$ + * + */ + +#ifndef _BEAT_DETECT_H +#define _BEAT_DETECT_H + +#include "projectM.hpp" +#include "PCM.hpp" + +class BeatDetect { +public: + /** Vars */ + float beat_buffer[32][80], + beat_instant[32], + beat_history[32]; + float beat_val[32], + beat_att[32], + beat_variance[32]; + int beat_buffer_pos; + float vol_buffer[80], + vol_instant, + vol_history; + + float treb ; + float mid ; + float bass ; + float bass_old ; + float beat_sensitivity; + float treb_att ; + float mid_att ; + float bass_att ; + float vol; + + PCM *pcm; + + /** Methods */ + DLLEXPORT BeatDetect(); + void initBeatDetect(); + void reset(); + void detectFromSamples(); + void getBeatVals( float *vdataL, float *vdataR); + void freeBeatDetect(); + }; + +#endif /** !_BEAT_DETECT_H */ diff --git a/src/projectM-engine-backup/BuiltinFuncs.cpp b/src/projectM-engine-backup/BuiltinFuncs.cpp new file mode 100644 index 000000000..80494efe9 --- /dev/null +++ b/src/projectM-engine-backup/BuiltinFuncs.cpp @@ -0,0 +1,166 @@ +// +// C++ Implementation: BuiltinFuncs +// +// Description: +// +// +// Author: Carmelo Piccione , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +/* Loads all builtin functions */ + + +/* Loads a builtin function */ +#include "BuiltinFuncs.hpp" +#include +#include "Algorithms.hpp" +#include + +using namespace Algorithms; + +std::map * BuiltinFuncs::builtin_func_tree = 0; + +int BuiltinFuncs::load_builtin_func(char * name, float (*func_ptr)(float*), int num_args) { + + Func * func; + int retval; + + /* Create new function */ + func = Func::create_func(name, func_ptr, num_args); + + if (func == NULL) + return PROJECTM_OUTOFMEM_ERROR; + + retval = insert_func( func ); + + return retval; + +} + + + +Func * BuiltinFuncs::find_func(char * name) { + + std::map::iterator pos = builtin_func_tree->find(std::string(name)); + + // Case: function not found, return null + if (pos == builtin_func_tree->end()) + return 0; + + // Case: function found, return a pointer to it + return pos->second; + +} + + + + +int BuiltinFuncs::load_all_builtin_func() { + + if (load_builtin_func("int", FuncWrappers::int_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("abs", FuncWrappers::abs_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("sin", FuncWrappers::sin_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("cos", FuncWrappers::cos_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("tan", FuncWrappers::tan_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("asin", FuncWrappers::asin_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("acos", FuncWrappers::acos_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("atan", FuncWrappers::atan_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("sqr", FuncWrappers::sqr_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("sqrt", FuncWrappers::sqrt_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("pow", FuncWrappers::pow_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("exp", FuncWrappers::exp_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("log", FuncWrappers::log_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("log10", FuncWrappers::log10_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("sign", FuncWrappers::sign_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("min", FuncWrappers::min_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("max", FuncWrappers::max_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("sigmoid", FuncWrappers::sigmoid_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("atan2", FuncWrappers::atan2_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("rand", FuncWrappers::rand_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("band", FuncWrappers::band_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("bor", FuncWrappers::bor_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("bnot", FuncWrappers::bnot_wrapper, 1) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("if", FuncWrappers::if_wrapper, 3) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("equal", FuncWrappers::equal_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("above", FuncWrappers::above_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("below", FuncWrappers::below_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("nchoosek", FuncWrappers::nchoosek_wrapper, 2) < 0) + return PROJECTM_ERROR; + if (load_builtin_func("fact", FuncWrappers::fact_wrapper, 1) < 0) + return PROJECTM_ERROR; + + return PROJECTM_SUCCESS; +} + + +/* Initialize the builtin function database. + Should only be necessary once */ +int BuiltinFuncs::init_builtin_func_db() { + int retval; + + builtin_func_tree = + new std::map(); + + if (builtin_func_tree == NULL) + return PROJECTM_OUTOFMEM_ERROR; + + retval = load_all_builtin_func(); + return PROJECTM_SUCCESS; +} + + + +/* Destroy the builtin function database. + Generally, do this on projectm exit */ +int BuiltinFuncs::destroy_builtin_func_db() { + +traverse >(*builtin_func_tree); +return PROJECTM_SUCCESS; +} + +/* Insert a function into the database */ +int BuiltinFuncs::insert_func( Func *func ) { + + std::pair::iterator, bool> inserteePair = + builtin_func_tree->insert(std::make_pair(std::string(func->name), func)); + + if (!inserteePair.second) { + std::cerr << "Failed to insert builtin function \"" << func->name << "\" into collection! Bailing..." << std::endl; + abort(); + + } + + return PROJECTM_SUCCESS; +} + + diff --git a/src/projectM-engine-backup/BuiltinFuncs.hpp b/src/projectM-engine-backup/BuiltinFuncs.hpp new file mode 100644 index 000000000..636e63cf5 --- /dev/null +++ b/src/projectM-engine-backup/BuiltinFuncs.hpp @@ -0,0 +1,232 @@ +// +// C++ Interface: BuiltinFuncs +// +// Description: +// +// +// Author: Carmelo Piccione , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef _BUILTIN_FUNCS_HPP +#define _BUILTIN_FUNCS_HPP + +#include "Common.hpp" +#include "Func.hpp" +#include +#include +#include +#include "projectM.hpp" +/* Wrappers for all the builtin functions + The arg_list pointer is a list of floats. Its + size is equal to the number of arguments the parameter + takes */ +class FuncWrappers { + +/* Values to optimize the sigmoid function */ +static const int R = 32767; +static const int RR = 65534; + +public: + +static inline float int_wrapper(float * arg_list) { + +return floor(arg_list[0]); + +} + + +static inline float sqr_wrapper(float * arg_list) { + +return pow(2, arg_list[0]); +} + + +static inline float sign_wrapper(float * arg_list) { + +return -arg_list[0]; +} + +static inline float min_wrapper(float * arg_list) { + +if (arg_list[0] > arg_list[1]) +return arg_list[1]; + +return arg_list[0]; +} + +static inline float max_wrapper(float * arg_list) { + +if (arg_list[0] > arg_list[1]) +return arg_list[0]; + +return arg_list[1]; +} + +/* consult your AI book */ +static inline float sigmoid_wrapper(float * arg_list) { +return (RR / (1 + exp( -(((float)(arg_list[0])) * arg_list[1]) / R) - R)); +} + + +static inline float bor_wrapper(float * arg_list) { + +return (float)((int)arg_list[0] || (int)arg_list[1]); +} + +static inline float band_wrapper(float * arg_list) { +return (float)((int)arg_list[0] && (int)arg_list[1]); +} + +static inline float bnot_wrapper(float * arg_list) { +return (float)(!(int)arg_list[0]); +} + +static inline float if_wrapper(float * arg_list) { + +if ((int)arg_list[0] == 0) +return arg_list[2]; +return arg_list[1]; +} + + +static inline float rand_wrapper(float * arg_list) { +float l=1; + +// printf("RAND ARG:(%d)\n", (int)arg_list[0]); +if ((int)arg_list[0] > 0) +l = (float)((rand()) % ((int)arg_list[0])); +//printf("VAL: %f\n", l); +return l; +} + +static inline float equal_wrapper(float * arg_list) { + return (arg_list[0] == arg_list[1]); +} + + +static inline float above_wrapper(float * arg_list) { + +return (arg_list[0] > arg_list[1]); +} + + +static inline float below_wrapper(float * arg_list) { + +return (arg_list[0] < arg_list[1]); +} + +static float sin_wrapper(float * arg_list) { + + assert(arg_list); +//return .5; +float d = sinf(*arg_list); +return d; +//return (sin (arg_list[0])); +} + + +static inline float cos_wrapper(float * arg_list) { +return (cos (arg_list[0])); +} + +static inline float tan_wrapper(float * arg_list) { +return (tan(arg_list[0])); +} + +static inline float asin_wrapper(float * arg_list) { +return (asin (arg_list[0])); +} + +static inline float acos_wrapper(float * arg_list) { +return (acos (arg_list[0])); +} + +static inline float atan_wrapper(float * arg_list) { +return (atan (arg_list[0])); +} + +static inline float atan2_wrapper(float * arg_list) { +return (atan2 (arg_list[0], arg_list[1])); +} + +static inline float pow_wrapper(float * arg_list) { +return (pow (arg_list[0], arg_list[1])); +} + +static inline float exp_wrapper(float * arg_list) { +return (exp(arg_list[0])); +} + +static inline float abs_wrapper(float * arg_list) { +return (fabs(arg_list[0])); +} + +static inline float log_wrapper(float* arg_list) { +return (log (arg_list[0])); +} + +static inline float log10_wrapper(float * arg_list) { +return (log10 (arg_list[0])); +} + +static inline float sqrt_wrapper(float * arg_list) { +return (sqrt (arg_list[0])); +} + + +static inline float nchoosek_wrapper(float * arg_list) { +unsigned long cnm = 1UL; +int i, f; +int n, m; + +n = (int)arg_list[0]; +m = (int)arg_list[1]; + +if (m*2 >n) m = n-m; +for (i=1 ; i <= m; n--, i++) +{ +if ((f=n) % i == 0) +f /= i; +else cnm /= i; +cnm *= f; +} +return (float)cnm; +} + + +static inline float fact_wrapper(float * arg_list) { + + +int result = 1; + +int n = (int)arg_list[0]; + +while (n > 1) { +result = result * n; +n--; +} +return (float)result; +} +}; + +#include +class BuiltinFuncs { + +public: + + static int init_builtin_func_db(); + static int destroy_builtin_func_db(); + static int load_all_builtin_func(); + static int load_builtin_func( char * name, float (*func_ptr)(float*), int num_args ); + + static int insert_func( Func *func ); + static int remove_func( Func *func ); + static Func *find_func( char *name ); +private: + static std::map * builtin_func_tree; +}; + +#endif diff --git a/src/projectM-engine-backup/BuiltinParams.cpp b/src/projectM-engine-backup/BuiltinParams.cpp new file mode 100644 index 000000000..fc5ee6d57 --- /dev/null +++ b/src/projectM-engine-backup/BuiltinParams.cpp @@ -0,0 +1,364 @@ + + +#include "BuiltinParams.hpp" +#include "projectM.hpp" +#include +#include "Algorithms.hpp" + +using namespace Algorithms; + +BuiltinParams::BuiltinParams() {} + +BuiltinParams::BuiltinParams(const PresetInputs & presetInputs, PresetOutputs & presetOutputs) +{ + + int ret; + if ((ret = init_builtin_param_db(presetInputs, presetOutputs)) != PROJECTM_SUCCESS) + { + throw ret; + } + +} + +BuiltinParams::~BuiltinParams() +{ + destroy_builtin_param_db(); +} + +/* Loads a float parameter into the builtin database */ +int BuiltinParams::load_builtin_param_float(char * name, void * engine_val, void * matrix, short int flags, + float init_val, float upper_bound, float lower_bound, char * alt_name) +{ + + Param * param = NULL; + CValue iv, ub, lb; + + iv.float_val = init_val; + ub.float_val = upper_bound; + lb.float_val = lower_bound; + + /* Create new parameter of type float */ + if (BUILTIN_PARAMS_DEBUG == 2) + { + printf("load_builtin_param_float: (name \"%s\") (alt_name = \"%s\") ", name, alt_name); + fflush(stdout); + } + + if ((param = new Param(name, P_TYPE_DOUBLE, flags, engine_val, matrix, iv, ub, lb)) == NULL) + { + return PROJECTM_OUTOFMEM_ERROR; + } + + if (BUILTIN_PARAMS_DEBUG == 2) + { + printf("created..."); + fflush(stdout); + } + + /* Insert the paremeter into the database */ + + if (insert_builtin_param( param ) < 0) + { + delete param; + return PROJECTM_ERROR; + } + + if (BUILTIN_PARAMS_DEBUG == 2) + { + printf("inserted..."); + fflush(stdout); + } + + /* If this parameter has an alternate name, insert it into the database as link */ + + if (alt_name != NULL) + { + insert_param_alt_name(param,alt_name); + + if (BUILTIN_PARAMS_DEBUG == 2) + { + printf("alt_name inserted..."); + fflush(stdout); + } + + + } + + if (BUILTIN_PARAMS_DEBUG == 2) printf("finished\n"); + + /* Finished, return success */ + return PROJECTM_SUCCESS; +} + + + +/* Destroy the builtin parameter database. + Generally, do this on projectm exit */ +int BuiltinParams::destroy_builtin_param_db() +{ + + Algorithms::traverse >(*builtin_param_tree); + delete builtin_param_tree; + builtin_param_tree = NULL; + return PROJECTM_SUCCESS; +} + + +/* Insert a parameter into the database with an alternate name */ +int BuiltinParams::insert_param_alt_name(Param *param, char * alt_name) +{ + + assert(alt_name); + + aliasMap.insert(std::make_pair(std::string(alt_name), std::string(param->name))); + + return PROJECTM_SUCCESS; +} + +Param * BuiltinParams::find_builtin_param(const std::string & name) +{ + + AliasMap::iterator pos = aliasMap.find(name); + Param * param = 0; + + if (pos == aliasMap.end()) + { + std::map::iterator builtinPos = builtin_param_tree->find(name); + + if (builtinPos != builtin_param_tree->end()) + param = builtinPos->second; + } + else + { + + std::map::iterator builtinPos = builtin_param_tree->find(pos->second); + + if (builtinPos != builtin_param_tree->end()) + param = builtinPos->second; + } + return param; +} + + +/* Loads a integer parameter into the builtin database */ +int BuiltinParams::load_builtin_param_int(char * name, void * engine_val, short int flags, + int init_val, int upper_bound, int lower_bound, char * alt_name) +{ + + Param * param; + CValue iv, ub, lb; + + iv.int_val = init_val; + ub.int_val = upper_bound; + lb.int_val = lower_bound; + + param = new Param(name, P_TYPE_INT, flags, engine_val, NULL, iv, ub, lb); + + if (param == NULL) + { + return PROJECTM_OUTOFMEM_ERROR; + } + + if (insert_builtin_param( param ) < 0) + { + delete param; + return PROJECTM_ERROR; + } + + if (alt_name != NULL) + { + insert_param_alt_name(param,alt_name); + } + + return PROJECTM_SUCCESS; + +} + +/* Loads a boolean parameter */ +int BuiltinParams::load_builtin_param_bool(char * name, void * engine_val, short int flags, + int init_val, char * alt_name) +{ + + Param * param; + CValue iv, ub, lb; + + iv.int_val = init_val; + ub.int_val = TRUE; + lb.int_val = FALSE; + + param = new Param(name, P_TYPE_BOOL, flags, engine_val, NULL, iv, ub, lb); + + if (param == NULL) + { + return PROJECTM_OUTOFMEM_ERROR; + } + + if (insert_builtin_param(param) < 0) + { + delete param; + return PROJECTM_ERROR; + } + + if (alt_name != NULL) + { + insert_param_alt_name(param,alt_name); + } + + return PROJECTM_SUCCESS; + +} + +/* Inserts a parameter into the builtin database */ +int BuiltinParams::insert_builtin_param( Param *param ) +{ + std::pair::iterator, bool> inserteePos = builtin_param_tree->insert(std::make_pair(param->name, param)); + + return inserteePos.second; +} + + + +/* Initialize the builtin parameter database. + Should only be necessary once */ +int BuiltinParams::init_builtin_param_db(const PresetInputs & presetInputs, PresetOutputs & presetOutputs) +{ + + /* Create the builtin parameter splay tree (go Sleator...) */ + if ((this->builtin_param_tree = new std::map()) == NULL) + { + if (BUILTIN_PARAMS_DEBUG) printf("init_builtin_param_db: failed to initialize database (FATAL)\n"); + return PROJECTM_OUTOFMEM_ERROR; + } + + if (BUILTIN_PARAMS_DEBUG) + { + printf("init_builtin_param: loading database..."); + fflush(stdout); + } + + /* Loads all builtin parameters into the database */ + if (load_all_builtin_param(presetInputs, presetOutputs) < 0) + { + if (BUILTIN_PARAMS_DEBUG) printf("failed loading builtin parameters (FATAL)\n"); + return PROJECTM_ERROR; + } + + if (BUILTIN_PARAMS_DEBUG) printf("success!\n"); + + /* Finished, no errors */ + return PROJECTM_SUCCESS; +} + + + +/* Loads all builtin parameters, limits are also defined here */ +int BuiltinParams::load_all_builtin_param(const PresetInputs & presetInputs, PresetOutputs & presetOutputs) +{ + + load_builtin_param_float("fRating", (void*)&presetOutputs.fRating, NULL, P_FLAG_NONE, 0.0 , 5.0, 0.0, NULL); + load_builtin_param_float("fWaveScale", (void*)&presetOutputs.fWaveScale, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + load_builtin_param_float("gamma", (void*)&presetOutputs.fGammaAdj, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fGammaAdj"); + load_builtin_param_float("echo_zoom", (void*)&presetOutputs.fVideoEchoZoom, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fVideoEchoZoom"); + load_builtin_param_float("echo_alpha", (void*)&presetOutputs.fVideoEchoAlpha, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fVideoEchoAlpha"); + load_builtin_param_float("wave_a", (void*)&presetOutputs.fWaveAlpha, NULL, P_FLAG_NONE, 0.0, 1.0, 0, "fWaveAlpha"); + load_builtin_param_float("fWaveSmoothing", (void*)&presetOutputs.fWaveSmoothing, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL); + load_builtin_param_float("fModWaveAlphaStart", (void*)&presetOutputs.fModWaveAlphaStart, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL); + load_builtin_param_float("fModWaveAlphaEnd", (void*)&presetOutputs.fModWaveAlphaEnd, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL); + load_builtin_param_float("fWarpAnimSpeed", (void*)&presetOutputs.fWarpAnimSpeed, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL); + // load_builtin_param_float("warp", (void*)&presetOutputs.warp, warp_mesh, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, NULL); + + load_builtin_param_float("fShader", (void*)&presetOutputs.fShader, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL); + load_builtin_param_float("decay", (void*)&presetOutputs.decay, NULL, P_FLAG_NONE, 0.0, 1.0, 0, "fDecay"); + + load_builtin_param_int("echo_orient", (void*)&presetOutputs.nVideoEchoOrientation, P_FLAG_NONE, 0, 3, 0, "nVideoEchoOrientation"); + load_builtin_param_int("wave_mode", (void*)&presetOutputs.nWaveMode, P_FLAG_NONE, 0, 7, 0, "nWaveMode"); + + load_builtin_param_bool("wave_additive", (void*)&presetOutputs.bAdditiveWaves, P_FLAG_NONE, FALSE, "bAdditiveWaves"); + load_builtin_param_bool("bModWaveAlphaByVolume", (void*)&presetOutputs.bModWaveAlphaByVolume, P_FLAG_NONE, FALSE, NULL); + load_builtin_param_bool("wave_brighten", (void*)&presetOutputs.bMaximizeWaveColor, P_FLAG_NONE, FALSE, "bMaximizeWaveColor"); + load_builtin_param_bool("wrap", (void*)&presetOutputs.bTexWrap, P_FLAG_NONE, FALSE, "bTexWrap"); + load_builtin_param_bool("darken_center", (void*)&presetOutputs.bDarkenCenter, P_FLAG_NONE, FALSE, "bDarkenCenter"); + load_builtin_param_bool("bRedBlueStereo", (void*)&presetOutputs.bRedBlueStereo, P_FLAG_NONE, FALSE, NULL); + load_builtin_param_bool("brighten", (void*)&presetOutputs.bBrighten, P_FLAG_NONE, FALSE, "bBrighten"); + load_builtin_param_bool("darken", (void*)&presetOutputs.bDarken, P_FLAG_NONE, FALSE, "bDarken"); + load_builtin_param_bool("solarize", (void*)&presetOutputs.bSolarize, P_FLAG_NONE, FALSE, "bSolarize"); + load_builtin_param_bool("invert", (void*)&presetOutputs.bInvert, P_FLAG_NONE, FALSE, "bInvert"); + load_builtin_param_bool("bMotionVectorsOn", (void*)&presetOutputs.bMotionVectorsOn, P_FLAG_NONE, FALSE, NULL); + 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("zoom", (void*)&presetOutputs.zoom, presetOutputs.zoom_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, 0, NULL); + 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, NULL); + 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, 1.0, 0, NULL); + load_builtin_param_float("cy", (void*)&presetOutputs.cy, presetOutputs.cy_mesh, P_FLAG_PER_PIXEL | P_FLAG_DONT_FREE_MATRIX, 0.0, 1.0, 0, NULL); + 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, NULL); + 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, NULL); + 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, 0, NULL); + 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, 0, NULL); + + load_builtin_param_float("wave_r", (void*)&presetOutputs.wave_r, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("wave_g", (void*)&presetOutputs.wave_g, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("wave_b", (void*)&presetOutputs.wave_b, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("wave_x", (void*)&presetOutputs.wave_x, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("wave_y", (void*)&presetOutputs.wave_y, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("wave_mystery", (void*)&presetOutputs.wave_mystery, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, "fWaveParam"); + + load_builtin_param_float("ob_size", (void*)&presetOutputs.ob_size, NULL, P_FLAG_NONE, 0.0, 0.5, 0, NULL); + load_builtin_param_float("ob_r", (void*)&presetOutputs.ob_r, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("ob_g", (void*)&presetOutputs.ob_g, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("ob_b", (void*)&presetOutputs.ob_b, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("ob_a", (void*)&presetOutputs.ob_a, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + + load_builtin_param_float("ib_size", (void*)&presetOutputs.ib_size, NULL,P_FLAG_NONE, 0.0, .5, 0.0, NULL); + load_builtin_param_float("ib_r", (void*)&presetOutputs.ib_r, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("ib_g", (void*)&presetOutputs.ib_g, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("ib_b", (void*)&presetOutputs.ib_b, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("ib_a", (void*)&presetOutputs.ib_a, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + + load_builtin_param_float("mv_r", (void*)&presetOutputs.mv_r, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("mv_g", (void*)&presetOutputs.mv_g, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("mv_b", (void*)&presetOutputs.mv_b, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + load_builtin_param_float("mv_x", (void*)&presetOutputs.mv_x, NULL,P_FLAG_NONE, 0.0, 64.0, 0.0, "nMotionVectorsX"); + load_builtin_param_float("mv_y", (void*)&presetOutputs.mv_y, NULL,P_FLAG_NONE, 0.0, 48.0, 0.0, "nMotionVectorsY"); + load_builtin_param_float("mv_l", (void*)&presetOutputs.mv_l, NULL,P_FLAG_NONE, 0.0, 5.0, 0.0, NULL); + load_builtin_param_float("mv_dy", (void*)&presetOutputs.mv_dy, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL); + load_builtin_param_float("mv_dx", (void*)&presetOutputs.mv_dx, NULL,P_FLAG_NONE, 0.0, 1.0, -1.0, NULL); + load_builtin_param_float("mv_a", (void*)&presetOutputs.mv_a, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL); + + load_builtin_param_float("time", (void*)&presetInputs.time, NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0.0, NULL); + load_builtin_param_float("bass", (void*)&presetInputs.bass, NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0.0, NULL); + load_builtin_param_float("mid", (void*)&presetInputs.mid, NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL); + load_builtin_param_float("bass_att", (void*)&presetInputs.bass_att, NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL); + load_builtin_param_float("mid_att", (void*)&presetInputs.mid_att, NULL, P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL); + load_builtin_param_float("treb_att", (void*)&presetInputs.treb_att, NULL, P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL); + load_builtin_param_int("frame", (void*)&presetInputs.frame, P_FLAG_READONLY, 0, MAX_INT_SIZE, 0, NULL); + load_builtin_param_float("progress", (void*)&presetInputs.progress, NULL,P_FLAG_READONLY, 0.0, 1, 0, NULL); + load_builtin_param_int("fps", (void*)&presetInputs.fps, P_FLAG_READONLY, 15, MAX_INT_SIZE, 0, NULL); + + 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, + 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + 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, + 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + 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, + 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + 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, + 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + + load_builtin_param_float("q1", (void*)&presetOutputs.q1, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + load_builtin_param_float("q2", (void*)&presetOutputs.q2, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + load_builtin_param_float("q3", (void*)&presetOutputs.q3, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + load_builtin_param_float("q4", (void*)&presetOutputs.q4, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + load_builtin_param_float("q5", (void*)&presetOutputs.q5, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + load_builtin_param_float("q6", (void*)&presetOutputs.q6, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + load_builtin_param_float("q7", (void*)&presetOutputs.q7, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + load_builtin_param_float("q8", (void*)&presetOutputs.q8, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL); + + /* variables added in 1.04 */ + load_builtin_param_int("meshx", (void*)&presetInputs.gx, P_FLAG_READONLY, 32, 96, 8, NULL); + load_builtin_param_int("meshy", (void*)&presetInputs.gy, P_FLAG_READONLY, 24, 72, 6, NULL); + + return PROJECTM_SUCCESS; + +} diff --git a/src/projectM-engine-backup/BuiltinParams.hpp b/src/projectM-engine-backup/BuiltinParams.hpp new file mode 100644 index 000000000..b3fc3997f --- /dev/null +++ b/src/projectM-engine-backup/BuiltinParams.hpp @@ -0,0 +1,85 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + + +/** BuiltinParams.hpp :: a class to encapsulate and centralize + * all projectm builtin parameter methods and state. Used primarily + * by preset class +**/ +#ifndef _BUILTIN_PARAMS_HPP +#define _BUILTIN_PARAMS_HPP + +#include +#include "PresetFrameIO.hpp" +#include "Param.hpp" +#include +#include "Algorithms.hpp" + +class BuiltinParams { + +public: + typedef std::map AliasMap; + + /** Default constructor leaves database in an uninitialized state. */ + BuiltinParams(); + + /** Construct a new builtin parameter database with variables references given by + * the preset input and output structures */ + BuiltinParams(const PresetInputs & presetInputs, PresetOutputs & presetOutputs); + + ~BuiltinParams(); + + /** Param database initalizer / destructor functions */ + int init_builtin_param_db(const PresetInputs & presetInputs, PresetOutputs & presetOutputs); + int load_all_builtin_param(const PresetInputs & presetInputs, PresetOutputs & presetOutputs); + int destroy_builtin_param_db(); + + int insert_param_alt_name( Param *param, char *alt_name ); + Param *find_builtin_param( const std::string & name ); + int load_builtin_param_float( char *name, void *engine_val, void *matrix, + short int flags, + float init_val, float upper_bound, + float lower_bound, char *alt_name ); + int load_builtin_param_int( char *name, void *engine_val, short int flags, + int init_val, int upper_bound, + int lower_bound, char *alt_name ); + int load_builtin_param_bool( char *name, void *engine_val, short int flags, + int init_val, char *alt_name ); + int insert_builtin_param( Param *param ); + + template + void traverse(Fun & fun) { + Algorithms::traverse(*builtin_param_tree, fun); + } + + + void traverse(void (*func_ptr)(void*)); + +private: + static const bool BUILTIN_PARAMS_DEBUG = false; + + // Used to associate multiple string names to one parameter + AliasMap aliasMap; + + // Internal datastructure to store the parameters + std::map * builtin_param_tree; +}; +#endif diff --git a/src/projectM-engine-backup/CMakeLists.txt b/src/projectM-engine-backup/CMakeLists.txt new file mode 100644 index 000000000..8afd95f54 --- /dev/null +++ b/src/projectM-engine-backup/CMakeLists.txt @@ -0,0 +1,33 @@ +PROJECT(projectM) +ADD_LIBRARY(projectM SHARED projectM.cpp projectM.hpp PBuffer.cpp PBuffer.hpp InitCond.cpp InitCond.hpp + Expr.cpp PCM.cpp Parser.cpp Preset.cpp Common.hpp BeatDetect.cpp PCM.hpp PerPixelEqn.cpp Eval.hpp +Param.cpp CustomWave.cpp CustomShape.hpp CustomShape.cpp Param.hpp CustomWave.hpp BeatDetect.hpp menu.cpp console_interface.h +Func.hpp Func.cpp Eval.cpp wipemalloc.h browser.cpp PerFrameEqn.cpp PerPointEqn.cpp editor.cpp fftsg.cpp glConsole.cpp console_interface.cpp +CValue.hpp Expr.hpp timer.cpp wipemalloc.cpp PerFrameEqn.hpp PerPixelEqn.hpp PerPointEqn.hpp browser.h BuiltinFuncs.hpp +BuiltinFuncs.cpp compare.h editor.h event.h fatal.h fftsg.h glConsole.h menu.h timer.h SplayNode.hpp BuiltinParams.hpp BuiltinParams.cpp Preset.hpp Renderer.cpp Renderer.hpp ParamUtils.hpp PresetLoader.cpp PresetLoader.hpp PresetChooser.hpp PresetChooser.cpp PresetFrameIO.cpp PresetFrameIO.hpp) + +OPTION(USE_FTGL "Use FTGL for on-screen fonts" ON) + +ADD_DEFINITIONS(-DLINUX -DUSE_FBO) + +FIND_PACKAGE(OpenGL) + +INCLUDE(FindPkgConfig.cmake) + +TARGET_LINK_LIBRARIES(projectM GLEW m) + +IF(USE_FTGL) + pkg_search_module (FTGL ftgl) + ADD_DEFINITIONS(-DUSE_FTGL) + INCLUDE_DIRECTORIES(${FTGL_INCLUDE_DIRS}) + LINK_DIRECTORIES(${FTGL_LIBRARY_DIRS}) + TARGET_LINK_LIBRARIES(projectM GLEW m ftgl) +ENDIF(USE_FTGL) + +INSTALL(TARGETS projectM DESTINATION lib) +INSTALL(FILES projectM.hpp PBuffer.hpp PCM.hpp BeatDetect.hpp Preset.hpp event.h console_interface.h dlldefs.h fatal.h PresetFrameIO.hpp PCM.hpp Renderer.hpp PresetChooser.hpp DESTINATION include/libprojectM) +INSTALL(FILES config DESTINATION share/projectM) +FILE(GLOB presets "presets/*.milk") +INSTALL(FILES ${presets} DESTINATION share/projectM/presets) +FILE(GLOB fonts "fonts/*.ttf") +INSTALL(FILES ${fonts} DESTINATION share/projectM/fonts) diff --git a/src/projectM-engine-backup/CValue.hpp b/src/projectM-engine-backup/CValue.hpp new file mode 100755 index 000000000..bc55e11f7 --- /dev/null +++ b/src/projectM-engine-backup/CValue.hpp @@ -0,0 +1,38 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Value + * + * $Log$ + */ + +#ifndef _CVALUE_H +#define _CVALUE_H + +typedef union CValue_t { + int bool_val; + int int_val; + float float_val; + } CValue; + +#endif /** _CVALUE_H */ diff --git a/src/projectM-engine-backup/Common.hpp b/src/projectM-engine-backup/Common.hpp new file mode 100755 index 000000000..849703ec6 --- /dev/null +++ b/src/projectM-engine-backup/Common.hpp @@ -0,0 +1,98 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * $Log$ + */ + +#ifndef COMMON_H +#define COMMON_H + +#include + +#ifdef _MSC_VER +# define strcasecmp(s, t) _strcmpi(s, t) +#endif + +#ifdef DEBUG +extern FILE *debugFile; +#endif + +#ifdef MACOS +#include +extern FILE *fmemopen(void *buf, size_t len, const char *pMode); +#endif /** MACOS */ + +#include "dlldefs.h" + +#define DEFAULT_FONT_PATH "/home/carm/fonts/courier1.glf" +#define MAX_TOKEN_SIZE 512 +#define MAX_PATH_SIZE 4096 + +#define STRING_BUFFER_SIZE 1024*150 +#define STRING_LINE_SIZE 1024 + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + + +#define MAX_DOUBLE_SIZE 10000000.0 +#define MIN_DOUBLE_SIZE -10000000.0 + +#define MAX_INT_SIZE 10000000 +#define MIN_INT_SIZE -10000000 + +/* default float initial value */ +#define DEFAULT_DOUBLE_IV 0.0 + +/* default float lower bound */ +#define DEFAULT_DOUBLE_LB MIN_DOUBLE_SIZE + +/* default float upper bound */ +#define DEFAULT_DOUBLE_UB MAX_DOUBLE_SIZE + +#ifdef WIN32 +#include +#define isnan _isnan#endif /** WIN32 */ +#endif /** WIN32 */ + +inline void DWRITE( char *fmt, ... ) { + va_list args; + va_start( args, fmt ); +//#ifdef DEBUG +//#ifdef MACOS + // if ( debugFile != NULL ) {\ + vprintf(fmt, args ); + // fflush( debugFile );\ + // } else {\ + // printf( fmt, args );\ + // } +//#endif +//#endif + va_end( args ); + } + +#endif diff --git a/src/projectM-engine-backup/CustomShape.cpp b/src/projectM-engine-backup/CustomShape.cpp new file mode 100755 index 000000000..507786640 --- /dev/null +++ b/src/projectM-engine-backup/CustomShape.cpp @@ -0,0 +1,227 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include +#include +#include + +#include "Common.hpp" +#include "fatal.h" + +#include "CustomShape.hpp" +#include "Eval.hpp" +#include "Expr.hpp" +#include "InitCond.hpp" +#include "Param.hpp" +#include "PerFrameEqn.hpp" +#include "Preset.hpp" +#include +#include "ParamUtils.hpp" +#include "InitCondUtils.hpp" +#include "wipemalloc.h" +#include "Algorithms.hpp" + + +using namespace Algorithms; + +void eval_custom_shape_init_conds(CustomShape * custom_shape); +void load_unspec_init_cond_shape(Param * param); + + +CustomShape::CustomShape( int id ) { + + Param * param; + + this->id = id; + this->per_frame_count = 0; + this->per_frame_eqn_string_index = 0; + this->per_frame_init_eqn_string_index = 0; + + /* Initialize tree data structures */ + this->param_tree = new + std::map(); + + this->per_frame_eqn_tree = + std::map(); + + this->init_cond_tree = + std::map(); + + this->per_frame_init_eqn_tree = + std::map(); + + /* Start: Load custom shape parameters */ + param = Param::new_param_float("r", P_FLAG_NONE, &this->r, NULL, 1.0, 0.0, 0.5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("g", P_FLAG_NONE, &this->g, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("b", P_FLAG_NONE, &this->b, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("a", P_FLAG_NONE, &this->a, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("border_r", P_FLAG_NONE, &this->border_r, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("border_g", P_FLAG_NONE, &this->border_g, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("border_b", P_FLAG_NONE, &this->border_b, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("border_a", P_FLAG_NONE, &this->border_a, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("r2", P_FLAG_NONE, &this->r2, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("g2", P_FLAG_NONE, &this->g2, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("b2", P_FLAG_NONE, &this->b2, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("a2", P_FLAG_NONE, &this->a2, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("x", P_FLAG_NONE, &this->x, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("y", P_FLAG_NONE, &this->y, NULL, 1.0, 0.0, .5); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_bool("thickOutline", P_FLAG_NONE, &this->thickOutline, 1, 0, 0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_bool("enabled", P_FLAG_NONE, &this->enabled, 1, 0, 0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_int("sides", P_FLAG_NONE, &this->sides, 100, 3, 3); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_bool("additive", P_FLAG_NONE, &this->additive, 1, 0, 0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_bool("textured", P_FLAG_NONE, &this->textured, 1, 0, 0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("rad", P_FLAG_NONE, &this->radius, NULL, MAX_DOUBLE_SIZE, 0, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("ang", P_FLAG_NONE, &this->ang, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("tex_zoom", P_FLAG_NONE, &this->tex_zoom, NULL, MAX_DOUBLE_SIZE, .00000000001, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("tex_ang", P_FLAG_NONE, &this->tex_ang, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("t1", P_FLAG_TVAR, &this->t1, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("t2", P_FLAG_TVAR, &this->t2, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("t3", P_FLAG_TVAR, &this->t3, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("t4", P_FLAG_TVAR, &this->t4, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("t5", P_FLAG_TVAR, &this->t5, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("t6", P_FLAG_TVAR, &this->t6, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("t7", P_FLAG_TVAR, &this->t7, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + param = Param::new_param_float("t8", P_FLAG_TVAR, &this->t8, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0); + if ( ParamUtils::insert(param, this->param_tree) < 0 ) { + DWRITE( "%s\n", "failed to insert param!" ); + } + } + +/* Frees a custom shape form object */ +CustomShape::~CustomShape() { + + if (param_tree == NULL) + return; + + traverse >(per_frame_eqn_tree); + traverse >(init_cond_tree); + traverse >(*param_tree); + traverse >(per_frame_init_eqn_tree); + + return; + +} + +void CustomShape::load_custom_shape_init() { + + // NOTE: This is verified to be same behavior as trunk + + InitCondUtils::LoadUnspecInitCond fun(this->init_cond_tree, this->per_frame_init_eqn_tree); + + traverse(*param_tree, fun); +} + +void CustomShape::eval_custom_shape_init_conds() { + + // NOTE: This is verified to be same behavior as trunk + for (std::map::iterator pos = per_frame_init_eqn_tree.begin(); pos != per_frame_init_eqn_tree.end();++pos) + pos->second->evaluate(); +} diff --git a/src/projectM-engine-backup/CustomShape.hpp b/src/projectM-engine-backup/CustomShape.hpp new file mode 100755 index 000000000..d8dca4256 --- /dev/null +++ b/src/projectM-engine-backup/CustomShape.hpp @@ -0,0 +1,117 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Encapsulation of a custom shape + * + * $Log$ + */ + +#ifndef _CUSTOM_SHAPE_H +#define _CUSTOM_SHAPE_H + +#define CUSTOM_SHAPE_DEBUG 0 +#include +#include "Param.hpp" +#include "PerFrameEqn.hpp" +#include "InitCond.hpp" + +class Preset; + + +class CustomShape { +public: + /* Numerical id */ + int id; + int per_frame_count; + + /* Parameter tree associated with this custom shape */ + std::map * param_tree; + + /* Engine variables */ + int sides; + int thickOutline; + int enabled; + int additive; + int textured; + + float tex_zoom; + float tex_ang; + + float x; /* x position for per point equations */ + float y; /* y position for per point equations */ + float radius; + float ang; + + float r; /* red color value */ + float g; /* green color value */ + float b; /* blue color value */ + float a; /* alpha color value */ + + float r2; /* red color value */ + float g2; /* green color value */ + float b2; /* blue color value */ + float a2; /* alpha color value */ + + float border_r; /* red color value */ + float border_g; /* green color value */ + float border_b; /* blue color value */ + float border_a; /* alpha color value */ + + /* stupid t variables */ + float t1; + float t2; + float t3; + float t4; + float t5; + float t6; + float t7; + float t8; + + /* Data structure to hold per frame / per frame init equations */ + std::map init_cond_tree; + std::map per_frame_eqn_tree; + std::map per_frame_init_eqn_tree; + + /* Denotes the index of the last character for each stdring buffer */ + int per_frame_eqn_string_index; + int per_frame_init_eqn_string_index; + + + /* String buffers for per frame / per frame init equations */ + char per_frame_eqn_string_buffer[STRING_BUFFER_SIZE]; + char per_frame_init_eqn_string_buffer[STRING_BUFFER_SIZE]; + + /* Per point equation array */ + CustomShape( int id ); + ~CustomShape(); + + /** Checks all internal trees are built correctly */ + int checkTrees(); + + void load_custom_shape_init(); + void eval_custom_shape_init_conds(); + }; + + +#endif /** !_CUSTOM_SHAPE_H */ + diff --git a/src/projectM-engine-backup/CustomWave.cpp b/src/projectM-engine-backup/CustomWave.cpp new file mode 100755 index 000000000..8b497a50a --- /dev/null +++ b/src/projectM-engine-backup/CustomWave.cpp @@ -0,0 +1,530 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include +#include +#include + +#include "projectM.hpp" + +#include "Common.hpp" +#include "fatal.h" + +#include "CustomWave.hpp" +#include "Eval.hpp" +#include "Expr.hpp" +#include "InitCond.hpp" +#include "Param.hpp" +#include "PerFrameEqn.hpp" +#include "PerPointEqn.hpp" +#include "Preset.hpp" +#include +#include "ParamUtils.hpp" +#include "InitCondUtils.hpp" +#include "wipemalloc.h" + +#define MAX_SAMPLE_SIZE 4096 + + +int interface_id = 0; + +CustomWave::CustomWave(int _id): + id(_id), + per_frame_count(0), + samples(512), + bSpectrum(0), + sep(1), + smoothing(0.0), + bUseDots(0), + bAdditive(0), + r(0), + g(0), + b(0), + a(0), + scaling(1.0), + per_frame_eqn_string_index(0), + per_frame_init_eqn_string_index(0), + per_point_eqn_string_index(0) +{ + + Param * param; + + /// @bug deprecate the use of wipemalloc + this->r_mesh = (float*)wipemalloc(MAX_SAMPLE_SIZE*sizeof(float)); + this->g_mesh = (float*)wipemalloc(MAX_SAMPLE_SIZE*sizeof(float)); + this->b_mesh = (float*)wipemalloc(MAX_SAMPLE_SIZE*sizeof(float)); + this->a_mesh = (float*)wipemalloc(MAX_SAMPLE_SIZE*sizeof(float)); + this->x_mesh = (float*)wipemalloc(MAX_SAMPLE_SIZE*sizeof(float)); + this->y_mesh = (float*)wipemalloc(MAX_SAMPLE_SIZE*sizeof(float)); + this->value1 = (float*) wipemalloc(MAX_SAMPLE_SIZE*sizeof(float)); + this->value2 = (float*)wipemalloc(MAX_SAMPLE_SIZE*sizeof(float)); + this->sample_mesh = (float*)wipemalloc(MAX_SAMPLE_SIZE*sizeof(float)); + + + /* 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) { + delete(this); + /// @bug make exception + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + /// @bug make exception + 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){ + delete(this); +/// @bug make exception + abort(); + + } + + if (ParamUtils::insert(param, param_tree) < 0) { + delete(this); +/// @bug make exception + 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){ + delete(this); +/// @bug make exception + abort(); + + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); +/// @bug make exception + 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){ + delete(this); +/// @bug make exception + abort(); + + + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); +/// @bug make exception + 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) { + delete(this); +/// @bug make exception + abort(); + + + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); +/// @bug make exception + 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) { + delete(this); +/// @bug make exception + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + +/// @bug make exception + abort(); + + } + + if ((param = Param::new_param_bool("enabled", P_FLAG_NONE, &this->enabled, 1, 0, 0)) == NULL) { + delete(this); +/// @bug make exception + abort(); + + + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + +/// @bug make exception + abort(); + + } + + if ((param = Param::new_param_int("sep", P_FLAG_NONE, &this->sep, 100, -100, 0)) == NULL) { + delete(this); +/// @bug make exception + abort(); + + + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); +/// @bug make exception + abort(); + + + } + + if ((param = Param::new_param_bool("bSpectrum", P_FLAG_NONE, &this->bSpectrum, 1, 0, 0)) == NULL) { + delete(this); +/// @bug make exception + abort(); + + + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); +/// @bug make exception + abort(); + + } + + if ((param = Param::new_param_bool("bDrawThick", P_FLAG_NONE, &this->bDrawThick, 1, 0, 0)) == NULL) { + delete(this); +/// @bug make exception + abort(); + + + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); +/// @bug make exception + abort(); + + } + + if ((param = Param::new_param_bool("bUseDots", P_FLAG_NONE, &this->bUseDots, 1, 0, 0)) == NULL) { + delete(this); +/// @bug make exception + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + + if ((param = Param::new_param_bool("bAdditive", P_FLAG_NONE, &this->bAdditive, 1, 0, 0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + + if ((param = Param::new_param_int("samples", P_FLAG_NONE, &this->samples, 2048, 1, 512)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + + if ((param = Param::new_param_float("sample", P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT, + &this->sample, this->sample_mesh, 1.0, 0.0, 0.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + printf("failed to insert sample\n"); + delete(this); + 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) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + 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) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + + if ((param = Param::new_param_float("smoothing", P_FLAG_NONE, &this->smoothing, NULL, 1.0, 0.0, 0.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + + if ((param = Param::new_param_float("scaling", P_FLAG_NONE, &this->scaling, NULL, MAX_DOUBLE_SIZE, 0.0, 1.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + + if ((param = Param::new_param_float("t1", P_FLAG_PER_POINT | P_FLAG_TVAR, &this->t1, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + + if ((param = Param::new_param_float("t2", P_FLAG_PER_POINT |P_FLAG_TVAR, &this->t2, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + + if ((param = Param::new_param_float("t3", P_FLAG_PER_POINT |P_FLAG_TVAR, &this->t3, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + if ((param = Param::new_param_float("t4", P_FLAG_PER_POINT |P_FLAG_TVAR, &this->t4, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + if ((param = Param::new_param_float("t5", P_FLAG_TVAR, &this->t5, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + if ((param = Param::new_param_float("t6", P_FLAG_TVAR | P_FLAG_PER_POINT, &this->t6, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + if ((param = Param::new_param_float("t7", P_FLAG_TVAR | P_FLAG_PER_POINT, &this->t7, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + + if ((param = Param::new_param_float("t8", P_FLAG_TVAR | P_FLAG_PER_POINT, &this->t8, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) { + delete(this); + abort(); + } + + if (ParamUtils::insert(param, this->param_tree) < 0) { + delete(this); + abort(); + } + + /* End of parameter loading. Note that the read only parameters associated + with custom waves (ie, sample) are variables stored in PresetFrameIO.hpp, + and not specific to the custom wave datastructure. */ + +} + +CustomWave::~CustomWave() { + + if (param_tree == NULL) + return; + + + for (std::map::iterator pos = per_point_eqn_tree.begin(); pos != per_point_eqn_tree.end(); ++pos) + delete(pos->second); + + for (std::map::iterator pos = per_frame_eqn_tree.begin(); pos != per_frame_eqn_tree.end(); ++pos) + delete(pos->second); + + for (std::map::iterator pos = init_cond_tree.begin(); pos != init_cond_tree.end(); ++pos) + delete(pos->second); + + for (std::map::iterator pos = per_frame_init_eqn_tree.begin(); pos != per_frame_init_eqn_tree.end(); ++pos) + delete(pos->second); + + for (std::map::iterator pos = param_tree->begin(); pos != param_tree->end(); ++pos) + delete(pos->second); + + + free(r_mesh); + free(g_mesh); + free(b_mesh); + free(a_mesh); + free(x_mesh); + free(y_mesh); + free(value1); + free(value2); + free(sample_mesh); + + r_mesh = NULL; + g_mesh = NULL; + b_mesh = NULL; + a_mesh = NULL; + x_mesh = NULL; + y_mesh = NULL; + value1 = NULL; + value2 = NULL; + sample_mesh = NULL; + + +} + + + + + +int CustomWave::add_per_point_eqn(char * name, GenExpr * gen_expr) { + + PerPointEqn * per_point_eqn; + int index; + Param * param = NULL; + + /* Argument checks */ + if (gen_expr == NULL) + return PROJECTM_FAILURE; + if (name == NULL) + return PROJECTM_FAILURE; + + if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: per pixel equation (name = \"%s\")\n", name); + + /* Search for the parameter so we know what matrix the per pixel equation is referencing */ + + if ((param = ParamUtils::find(name,param_tree)) == NULL) { + if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: failed to allocate a new parameter!\n"); + return PROJECTM_FAILURE; + + } + + /* Find most largest index in the splaytree */ + + std::map::iterator pos = --per_point_eqn_tree.end(); + + if (pos == per_point_eqn_tree.end()) + index = 0; + else + index = pos->second->index+1; + + /* Create the per pixel equation given the index, parameter, and general expression */ + + if ((per_point_eqn = new PerPointEqn(index, param, gen_expr, samples)) == NULL) + return PROJECTM_FAILURE; + if (CUSTOM_WAVE_DEBUG) + printf("add_per_point_eqn: created new equation (index = %d) (name = \"%s\")\n", per_point_eqn->index, per_point_eqn->param->name.c_str()); + + /* Insert the per pixel equation into the preset per pixel database */ + + per_point_eqn_tree.insert(std::make_pair(per_point_eqn->index, per_point_eqn)); + + /* Done */ + return PROJECTM_SUCCESS; +} + + +void CustomWave::eval_custom_wave_init_conds() { + + for (std::map::iterator pos = init_cond_tree.begin(); pos != init_cond_tree.end(); ++pos) + pos->second->evaluate(); + + for (std::map::iterator pos = per_frame_init_eqn_tree.begin(); pos != per_frame_init_eqn_tree.end(); ++pos) + pos->second->evaluate(); +} + +/** Evaluate per-point equations */ +void CustomWave::evalPerPointEqns() { + + int x; + + for (x = 0; x < samples; x++) + r_mesh[x] = r; + for (x = 0; x < samples; x++) + g_mesh[x] = g; + for (x = 0; x < samples; x++) + b_mesh[x] = b; + for (x = 0; x < samples; x++) + a_mesh[x] = a; + for (x = 0; x < samples; x++) + x_mesh[x] = x; + for (x = 0; x < samples; x++) + y_mesh[x] = y; + + /* Evaluate per pixel equations */ + for (std::map::iterator pos = per_point_eqn_tree.begin(); pos != per_point_eqn_tree.end();++pos) + pos->second->evaluate(); + +} + +void CustomWave::load_unspecified_init_conds() { + + InitCondUtils::LoadUnspecInitCond fun(this->init_cond_tree, this->per_frame_init_eqn_tree); + Algorithms::traverse(*param_tree, fun); +} + + + + diff --git a/src/projectM-engine-backup/CustomWave.hpp b/src/projectM-engine-backup/CustomWave.hpp new file mode 100755 index 000000000..3e6b2767d --- /dev/null +++ b/src/projectM-engine-backup/CustomWave.hpp @@ -0,0 +1,158 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Encapsulation of a custom wave + * + * $Log$ + */ + +#ifndef _CUSTOM_WAVE_H +#define _CUSTOM_WAVE_H + +#define CUSTOM_WAVE_DEBUG 0 + +#define X_POINT_OP 0 +#define Y_POINT_OP 1 +#define R_POINT_OP 2 +#define G_POINT_OP 3 +#define B_POINT_OP 4 +#define A_POINT_OP 5 +#define NUM_POINT_OPS 6 + +class CustomWave; +class GenExpr; +class PerPointEqn; +class Preset; + +#include "Common.hpp" +#include "Param.hpp" +#include "PerFrameEqn.hpp" + +#include + +class CustomWave { +public: + + /** Empty constructor leaves wave in undefined state **/ + CustomWave() {} + + /** Initializes a custom wave id given the integer id */ + CustomWave(int id); + + /** Destructor is necessary so we can free the per point matrices **/ + ~CustomWave(); + + /* Numerical id */ + int id; + int per_frame_count; + + /* Parameter tree associated with this custom wave */ + std::map * param_tree; + + /* Engine variables */ + float x; /* x position for per point equations */ + float y; /* y position for per point equations */ + float r; /* red color value */ + float g; /* green color value */ + float b; /* blue color value */ + float a; /* alpha color value */ + float * x_mesh; + float * y_mesh; + float * r_mesh; + float * b_mesh; + float * g_mesh; + float * a_mesh; + float * value1; + float * value2; + float * sample_mesh; + + int enabled; /* if nonzero then wave is visible, hidden otherwise */ + int samples; /* number of samples associated with this wave form. Usually powers of 2 */ + float sample; + int bSpectrum; /* spectrum data or pcm data */ + int bUseDots; /* draw wave as dots or lines */ + int bDrawThick; /* draw thicker lines */ + int bAdditive; /* add color values together */ + + float scaling; /* scale factor of waveform */ + float smoothing; /* smooth factor of waveform */ + int sep; /* no idea what this is yet... */ + + /* stupid t variables */ + float t1; + float t2; + float t3; + float t4; + float t5; + float t6; + float t7; + float t8; + float v1,v2; + + /* Data structures to hold per frame and per point equations */ + std::map init_cond_tree; + std::map per_frame_eqn_tree; + std::map per_point_eqn_tree; + std::map per_frame_init_eqn_tree; + + /* Denotes the index of the last character for each string buffer */ + int per_point_eqn_string_index; + int per_frame_eqn_string_index; + int per_frame_init_eqn_string_index; + + /* String buffers for per point and per frame equations */ + char per_point_eqn_string_buffer[STRING_BUFFER_SIZE]; + char per_frame_eqn_string_buffer[STRING_BUFFER_SIZE]; + char per_frame_init_eqn_string_buffer[STRING_BUFFER_SIZE]; + + /* Per point equation array */ + GenExpr * per_point_eqn_array[NUM_POINT_OPS]; + + void reset_per_point_eqn_array(CustomWave *custom_wave); + + int add_per_point_eqn(char * name, GenExpr * gen_expr); + void evalCustomWaveInitConditions(Preset *preset); + void evalPerPointEqns(); + + void load_unspecified_init_conds(); + + void eval_custom_wave_init_conds(); + void evalPerPointEqn(PerPointEqn * per_point_eqn); + + +}; + +/** Splaytree traversal helpers */ +inline void free_custom_wave_helper( void *custom_wave ) { + delete((CustomWave *)custom_wave); + } + +inline void load_custom_wave_init_helper( void *custom_wave ) { + ((CustomWave *)custom_wave)->load_unspecified_init_conds(); + } + +inline void eval_custom_wave_init_conds_helper( void *custom_wave ) { + ((CustomWave *)custom_wave)->eval_custom_wave_init_conds(); + } + +#endif /** !_CUSTOM_WAVE_H */ diff --git a/src/projectM-engine-backup/Eval.cpp b/src/projectM-engine-backup/Eval.cpp new file mode 100755 index 000000000..a2cdf359a --- /dev/null +++ b/src/projectM-engine-backup/Eval.cpp @@ -0,0 +1,91 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/* Evaluation Code */ + +#include +#include + +#include "projectM.hpp" +#include "Common.hpp" +#include "fatal.h" + +#include "Eval.hpp" +#include "Expr.hpp" +#include "Param.hpp" +#include "Func.hpp" +#include "BuiltinFuncs.hpp" +#include "wipemalloc.h" + +InfixOp *Eval::infix_add = NULL; +InfixOp *Eval::infix_minus = NULL; +InfixOp *Eval::infix_div = NULL; +InfixOp *Eval::infix_mult = NULL; +InfixOp *Eval::infix_or = NULL; +InfixOp *Eval::infix_and = NULL; +InfixOp *Eval::infix_mod = NULL; +InfixOp *Eval::infix_negative = NULL; +InfixOp *Eval::infix_positive = NULL; + +/* Initializes all infix operators */ +int Eval::init_infix_ops() { + + Eval::infix_add = new InfixOp(INFIX_ADD, 4); + Eval::infix_minus = new InfixOp(INFIX_MINUS, 3); + Eval::infix_div = new InfixOp(INFIX_DIV, 2); + Eval::infix_or = new InfixOp(INFIX_OR, 5); + Eval::infix_and = new InfixOp(INFIX_AND,4); + Eval::infix_mod = new InfixOp(INFIX_MOD, 1); + Eval::infix_mult = new InfixOp(INFIX_MULT, 2); + + /* Prefix operators */ + Eval::infix_positive = new InfixOp(INFIX_ADD, 0); + Eval::infix_negative = new InfixOp(INFIX_MINUS, 0); + + return PROJECTM_SUCCESS; +} + +/* Destroys the infix operator list. This should + be done on program exit */ +int Eval::destroy_infix_ops() +{ + + delete(Eval::infix_add); + delete(Eval::infix_minus); + delete(Eval::infix_div); + delete(Eval::infix_or); + delete(Eval::infix_and); + delete(Eval::infix_mod); + delete(Eval::infix_mult); + delete(Eval::infix_positive); + delete(Eval::infix_negative); + + Eval::infix_add = NULL; + Eval::infix_minus = NULL; + Eval::infix_div = NULL; + Eval::infix_or = NULL; + Eval::infix_and = NULL; + Eval::infix_mod = NULL; + Eval::infix_mult = NULL; + Eval::infix_positive = NULL; + Eval::infix_negative = NULL; + + return PROJECTM_SUCCESS; +} diff --git a/src/projectM-engine-backup/Eval.hpp b/src/projectM-engine-backup/Eval.hpp new file mode 100755 index 000000000..bdf0113f1 --- /dev/null +++ b/src/projectM-engine-backup/Eval.hpp @@ -0,0 +1,93 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Expression evaluators + * + * $Log$ + */ + +/* Eval.hpp: evaluation functions of expressions */ + +#ifndef _EVAL_H +#define _EVAL_H + +#include "projectM.hpp" +#include "Func.hpp" +#include "Param.hpp" + +//#define EVAL_DEBUG 2 +//#define EVAL_DEBUG_DOUBLE 2 + +#define VAL_T 1 +#define PREFUN_T 3 +#define TREE_T 4 +#define NONE_T 0 + +#define CONSTANT_TERM_T 0 +#define PARAM_TERM_T 1 + +#define INFIX_ADD 0 +#define INFIX_MINUS 1 +#define INFIX_MOD 2 +#define INFIX_DIV 3 +#define INFIX_MULT 4 +#define INFIX_OR 5 +#define INFIX_AND 6 + +class InfixOp; + +class Eval { +public: + static InfixOp *infix_add, + *infix_minus, + *infix_div, + *infix_mult, + *infix_or, + *infix_and, + *infix_mod, + *infix_negative, + *infix_positive; + + float eval_gen_expr(GenExpr * gen_expr); + inline GenExpr * opt_gen_expr(GenExpr * gen_expr, int ** param_list); + + GenExpr * const_to_expr(float val); + GenExpr * param_to_expr(Param * param); + GenExpr * prefun_to_expr(float (*func_ptr)(), GenExpr ** expr_list, int num_args); + + static TreeExpr * new_tree_expr(InfixOp * infix_op, GenExpr * gen_expr, TreeExpr * left, TreeExpr * right); + static GenExpr * new_gen_expr(int type, void * item); + static ValExpr * new_val_expr(int type, Term *term); + + static InfixOp * new_infix_op(int type, int precedence); + static int init_infix_ops(); + static int destroy_infix_ops(); + void reset_engine_vars(); + + GenExpr * clone_gen_expr(GenExpr * gen_expr); + TreeExpr * clone_tree_expr(TreeExpr * tree_expr); + ValExpr * clone_val_expr(ValExpr * val_expr); + PrefunExpr * clone_prefun_expr(PrefunExpr * prefun_expr); + }; + +#endif /** !_EVAL_H */ diff --git a/src/projectM-engine-backup/Expr.cpp b/src/projectM-engine-backup/Expr.cpp new file mode 100755 index 000000000..1453c6aa8 --- /dev/null +++ b/src/projectM-engine-backup/Expr.cpp @@ -0,0 +1,549 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include "wipemalloc.h" + +#include "Expr.hpp" +#include "Eval.hpp" +#include +#include + +float GenExpr::eval_gen_expr(int mesh_i, int mesh_j) { + float l; + + assert(item); + switch(this->type) { + case VAL_T: + return ((ValExpr*)item)->eval_val_expr(mesh_i, mesh_j); + case PREFUN_T: + l = ((PrefunExpr *)item)->eval_prefun_expr(mesh_i, mesh_j); + //if (EVAL_DEBUG) DWRITE( "eval_gen_expr: prefix function return value: %f\n", l); + return l; + 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; + } + +} + +/* Evaluates functions in prefix form */ +float PrefunExpr::eval_prefun_expr(int mesh_i, int mesh_j) { + + + assert(func_ptr); + /* This is slightly less than safe, since + who knows if the passed argument is valid. For + speed purposes we'll go with this */ + float arg_list[this->num_args]; + + #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 */ + + return (func_ptr)(arg_list); + +} + + +/* Evaluates a value expression */ +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); + } + + /* Value is variable, dereference it */ + if (type == PARAM_TERM_T) { + switch (term.param->type) { + + case P_TYPE_BOOL: + #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))); + 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))); + case P_TYPE_DOUBLE: + + if (term.param->matrix_flag | (term.param->flags & P_FLAG_ALWAYS_MATRIX)) { + + /* Sanity check the matrix is there... */ + assert(term.param->matrix != NULL ); + + /// @slow boolean check could be expensive in this critical (and common) step of evaluation + if (mesh_i >= 0) { + if (mesh_j >= 0) { + return (((float**)term.param->matrix)[mesh_i][mesh_j]); + } else { + return (((float*)term.param->matrix)[mesh_i]); + } + } + //assert(mesh_i >=0); + } + //std::cout << term.param->name << ": " << (*((float*)term.param->engine_val)) << std::endl; + return *((float*)(term.param->engine_val)); + default: + return EVAL_ERROR; + } + } + /* Unknown type, return failure */ + return PROJECTM_FAILURE; +} + +/* Evaluates an expression tree */ +float TreeExpr::eval_tree_expr(int mesh_i, int mesh_j) { + + float left_arg, right_arg; + + /* A leaf node, evaluate the general expression. If the expression is null as well, return zero */ + if (infix_op == NULL) { + if (gen_expr == NULL) + return 0; + else + return gen_expr->eval_gen_expr( mesh_i, mesh_j); + } + + /* Otherwise, this node is an infix operator. Evaluate + accordingly */ + + #ifdef EVAL_DEBUG + DWRITE( "("); + #endif + + 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 + + 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) { + case INFIX_ADD: + return (left_arg + right_arg); + case INFIX_MINUS: + return (left_arg - right_arg); + case INFIX_MULT: + return (left_arg * right_arg); + 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); + case INFIX_OR: + return ((int)left_arg | (int)right_arg); + case INFIX_AND: + return ((int)left_arg & (int)right_arg); + 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; + } + + return EVAL_ERROR; +} + +/* Converts a float value to a general expression */ +GenExpr * GenExpr::const_to_expr(float val) { + + GenExpr * gen_expr; + ValExpr * val_expr; + Term term; + + term.constant = val; + + if ((val_expr = ValExpr::new_val_expr(CONSTANT_TERM_T, &term)) == NULL) + return NULL; + + gen_expr = GenExpr::new_gen_expr(VAL_T, (void*)val_expr); + + if (gen_expr == NULL) { + delete val_expr; + } + + return gen_expr; +} + +/* Converts a regular parameter to an expression */ +GenExpr * GenExpr::param_to_expr(Param * param) { + + GenExpr * gen_expr = NULL; + ValExpr * val_expr = NULL; + Term term; + + if (param == NULL) + return NULL; + + /* This code is still a work in progress. We need + to figure out if the initial condition is used for + each per frame equation or not. I am guessing that + it isn't, and it is thusly implemented this way */ + + /* Current guess of true behavior (08/01/03) note from carm + First try to use the per_pixel_expr (with cloning). + If it is null however, use the engine variable instead. */ + + /* 08/20/03 : Presets are now objects, as well as per pixel equations. This ends up + making the parser handle the case where parameters are essentially per pixel equation + substitutions */ + + + term.param = param; + if ((val_expr = ValExpr::new_val_expr(PARAM_TERM_T, &term)) == NULL) + return NULL; + + if ((gen_expr = GenExpr::new_gen_expr(VAL_T, (void*)val_expr)) == NULL) { + delete val_expr; + return NULL; + } + return gen_expr; +} + +/* Converts a prefix function to an expression */ +GenExpr * GenExpr::prefun_to_expr(float (*func_ptr)(void *), GenExpr ** expr_list, int num_args) { + + GenExpr * gen_expr; + PrefunExpr * prefun_expr; + + + /* Malloc a new prefix function expression */ + prefun_expr = (PrefunExpr*)wipemalloc(sizeof(PrefunExpr)); + + if (prefun_expr == NULL) + return NULL; + + prefun_expr->num_args = num_args; + prefun_expr->func_ptr =(float (*)(void*)) func_ptr; + prefun_expr->expr_list = expr_list; + + gen_expr = new_gen_expr(PREFUN_T, (void*)prefun_expr); + + if (gen_expr == NULL) + delete prefun_expr; + + return gen_expr; +} + +/* Creates a new tree expression */ +TreeExpr *TreeExpr::new_tree_expr(InfixOp * infix_op, GenExpr * gen_expr, TreeExpr * left, TreeExpr * right) { + + TreeExpr * tree_expr; + tree_expr = (TreeExpr*)wipemalloc(sizeof(TreeExpr)); + assert(tree_expr); + + tree_expr->infix_op = infix_op; + tree_expr->gen_expr = gen_expr; + tree_expr->left = left; + tree_expr->right = right; + return tree_expr; +} + + +/* Creates a new value expression */ +ValExpr *ValExpr::new_val_expr(int _type, Term * _term) { + + ValExpr * val_expr; + val_expr = (ValExpr*)wipemalloc(sizeof(ValExpr)); + + if (val_expr == NULL) + return NULL; + + val_expr->type = _type; + val_expr->term.constant = _term->constant; + val_expr->term.param = _term->param; + + return val_expr; +} + +/* Creates a new general expression */ +GenExpr * GenExpr::new_gen_expr(int _type, void * _item) { + + GenExpr * gen_expr; + + gen_expr = (GenExpr*)wipemalloc(sizeof(GenExpr)); + if (gen_expr == NULL) + return NULL; + gen_expr->type = _type; + gen_expr->item = _item; + + return gen_expr; +} + +/* Frees a general expression */ +GenExpr::~GenExpr() { + + switch (type) { + case VAL_T: + delete ((ValExpr*)item); + break; + case PREFUN_T: + delete ((PrefunExpr*)item); + break; + case TREE_T: + delete ((TreeExpr*)item); + break; + } +} + +/* Frees a function in prefix notation */ +PrefunExpr::~PrefunExpr() { + + int i; + + /* Free every element in expression list */ + for (i = 0 ; i < num_args; i++) { + delete expr_list[i]; + } + free(expr_list); +} + +/* Frees values of type VARIABLE and CONSTANT */ +ValExpr::~ValExpr() { + } + +/* Frees a tree expression */ +TreeExpr::~TreeExpr() { + + /* free left tree */ + if ( left != NULL ) { + delete left; + } + + /* free general expression object */ + if ( gen_expr != NULL ) { + delete gen_expr; + } + + /* Note that infix operators are always + stored in memory unless the program + exits, so we don't remove them here */ + + /* free right tree */ + if ( right != NULL ) { + delete right; + } + } + +/* Initializes an infix operator */ +DLLEXPORT InfixOp::InfixOp(int type, int precedence) { + + this->type = type; + this->precedence = precedence; + } + +/* Clones a general expression */ +GenExpr *GenExpr::clone_gen_expr() { + + GenExpr * new_gen_expr; + ValExpr * val_expr; + TreeExpr * tree_expr; + PrefunExpr * prefun_expr; + + /* Out of memory */ + if ((new_gen_expr = (GenExpr*)wipemalloc(sizeof(GenExpr))) == NULL) + return NULL; + + /* Case on the type of general expression */ + switch (new_gen_expr->type = type) { + + case VAL_T: /* val expression */ + if ((val_expr = ((ValExpr*)item)->clone_val_expr()) == NULL) { + free(new_gen_expr); + new_gen_expr = NULL; + return NULL; + } + new_gen_expr->item = (void*)val_expr; + break; + + case PREFUN_T: /* prefix function expression */ + if ((prefun_expr = ((PrefunExpr*)item)->clone_prefun_expr()) == NULL) { + free(new_gen_expr); + new_gen_expr = NULL; + return NULL; + } + new_gen_expr->item = (void*)prefun_expr; + break; + + case TREE_T: /* tree expression */ + if ((tree_expr = ((TreeExpr*)item)->clone_tree_expr()) == NULL) { + free(new_gen_expr); + new_gen_expr = NULL; + return NULL; + } + new_gen_expr->item = (void*)tree_expr; + break; + + default: /* unknown type, ut oh.. */ + free(new_gen_expr); + new_gen_expr = NULL; + return NULL; + } + + return new_gen_expr; /* Return the new (cloned) general expression */ +} + + +/* Clones a tree expression */ +TreeExpr *TreeExpr::clone_tree_expr() { + + TreeExpr * new_tree_expr; + + /* Out of memory */ + if ((new_tree_expr = (TreeExpr*)wipemalloc(sizeof(TreeExpr))) == NULL) + return NULL; + + /* Set each argument in TreeExpr struct */ + new_tree_expr->infix_op = infix_op; /* infix operators are in shared memory */ + new_tree_expr->gen_expr = gen_expr->clone_gen_expr(); /* clone the general expression */ + new_tree_expr->left = left->clone_tree_expr(); /* clone the left tree expression */ + new_tree_expr->right = right->clone_tree_expr(); /* clone the right tree expression */ + + return new_tree_expr; /* Return the new (cloned) tree expression */ +} + +/* Clones a value expression, currently only passes the pointer to + the value that this object represents, not a pointer to a copy of the value */ +ValExpr *ValExpr::clone_val_expr() { + + ValExpr * new_val_expr; + + /* Allocate space, check for out of memory */ + if ((new_val_expr = (ValExpr*)wipemalloc(sizeof(ValExpr))) == NULL) + return NULL; + + /* Set the values in the ValExpr struct */ + new_val_expr->type = type; + new_val_expr->term = term; + + /* Return the new (cloned) value expression */ + return new_val_expr; +} + +/* Clones a prefix function with its arguments */ +PrefunExpr *PrefunExpr::clone_prefun_expr() { + + int i; + PrefunExpr * new_prefun_expr; + + /* Out of memory */ + if ((new_prefun_expr = (PrefunExpr*)wipemalloc(sizeof(PrefunExpr))) == NULL) + return NULL; + + /* Set the function argument paired with its number of arguments */ + new_prefun_expr->num_args = num_args; + new_prefun_expr->func_ptr = func_ptr; + + /* Allocate space for the expression list pointers */ + if ((new_prefun_expr->expr_list = (GenExpr**)wipemalloc(sizeof(GenExpr*)*new_prefun_expr->num_args)) == NULL) { + free( new_prefun_expr ); + new_prefun_expr = NULL; + return NULL; + } + + /* Now copy each general expression from the argument expression list */ + for (i = 0; i < new_prefun_expr->num_args;i++) + new_prefun_expr->expr_list[i] = expr_list[i]->clone_gen_expr(); + + /* Finally, return the new (cloned) prefix function expression */ + return new_prefun_expr; +} diff --git a/src/projectM-engine-backup/Expr.hpp b/src/projectM-engine-backup/Expr.hpp new file mode 100755 index 000000000..799eb43b3 --- /dev/null +++ b/src/projectM-engine-backup/Expr.hpp @@ -0,0 +1,125 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Expression + * + * $Log$ + */ + +#ifndef _EXPR_H +#define _EXPR_H + +#include "dlldefs.h" +#include "CValue.hpp" + +class Param; + +#define CONST_STACK_ELEMENT 0 +#define EXPR_STACK_ELEMENT 1 + +#define EVAL_ERROR -1 + +/* Infix Operator Function */ +class InfixOp +{ +public: + int type; + int precedence; + + DLLEXPORT InfixOp( int type, int precedence ); +}; + +/** Term */ +class Term +{ +public: + float constant; /* static variable */ + Param *param; /* pointer to a changing variable */ + + Term() { this->constant = 0; this->param = 0; } +}; + +/* General Expression Type */ +class GenExpr +{ +public: + int type; + void * item; + + ~GenExpr(); + + static GenExpr *new_gen_expr( int type, void *item ); + GenExpr *clone_gen_expr(); + float eval_gen_expr(int mesh_i, int mesh_j); + + static GenExpr *const_to_expr( float val ); + static GenExpr *param_to_expr( Param *param ); + static GenExpr *prefun_to_expr( float (*func_ptr)(void *), GenExpr **expr_list, int num_args ); +}; + +/* Value expression, contains a term union */ +class ValExpr +{ +public: + int type; + Term term; + + ~ValExpr(); + static ValExpr *new_val_expr( int type, Term *term ); + ValExpr *clone_val_expr(); + + float eval_val_expr(int mesh_i, int mesh_j); +}; + +/* A binary expression tree ordered by operator precedence */ +class TreeExpr +{ +public: + InfixOp * infix_op; /* null if leaf */ + GenExpr * gen_expr; + TreeExpr *left, *right; + + ~TreeExpr(); + static TreeExpr *new_tree_expr( InfixOp *infix_op, GenExpr *gen_expr, + TreeExpr *left, TreeExpr *right ); + TreeExpr *clone_tree_expr(); + float eval_tree_expr(int mesh_i, int mesh_j); +}; + +/* A function expression in prefix form */ +class PrefunExpr +{ +public: + float (*func_ptr)(void*); + int num_args; + GenExpr **expr_list; + + ~PrefunExpr(); + PrefunExpr *clone_prefun_expr(); + + /* Evaluates functions in prefix form */ + float eval_prefun_expr(int mesh_i, int mesh_j); + +}; + +#endif /** _EXPR_H */ diff --git a/src/projectM-engine-backup/FindPkgConfig.cmake b/src/projectM-engine-backup/FindPkgConfig.cmake new file mode 100644 index 000000000..afae15cb0 --- /dev/null +++ b/src/projectM-engine-backup/FindPkgConfig.cmake @@ -0,0 +1,360 @@ +# - a pkg-config module for CMake +# +# Usage: +# pkg_check_modules( [REQUIRED] []*) +# checks for all the given modules +# +# pkg_search_module( [REQUIRED] []*) +# checks for given modules and uses the first working one +# +# When the 'REQUIRED' argument was set, macros will fail with an error +# when module(s) could not be found +# +# It sets the following variables: +# PKG_CONFIG_FOUND ... true iff pkg-config works on the system +# PKG_CONFIG_EXECUTABLE ... pathname of the pkg-config program +# _FOUND ... set to 1 iff module(s) exist +# +# For the following variables two sets of values exist; first one is the +# common one and has the given PREFIX. The second set contains flags +# which are given out when pkgconfig was called with the '--static' +# option. +# _LIBRARIES ... only the libraries (w/o the '-l') +# _LIBRARY_DIRS ... the paths of the libraries (w/o the '-L') +# _LDFLAGS ... all required linker flags +# _LDFLAGS_OTHERS ... all other linker flags +# _INCLUDE_DIRS ... the '-I' preprocessor flags (w/o the '-I') +# _CFLAGS ... all required cflags +# _CFLAGS_OTHERS ... the other compiler flags +# +# = for common case +# = _STATIC for static linking +# +# There are some special variables whose prefix depends on the count +# of given modules. When there is only one module, stays +# unchanged. When there are multiple modules, the prefix will be +# changed to _: +# _VERSION ... version of the module +# _PREFIX ... prefix-directory of the module +# _INCLUDEDIR ... include-dir of the module +# _LIBDIR ... lib-dir of the module +# +# = when |MODULES| == 1, else +# = _ +# +# A parameter can have the following formats: +# {MODNAME} ... matches any version +# {MODNAME}>={VERSION} ... at least version is required +# {MODNAME}={VERSION} ... exactly version is required +# {MODNAME}<={VERSION} ... modules must not be newer than +# +# Examples +# pkg_check_modules (GLIB2 glib-2.0) +# +# pkg_check_modules (GLIB2 glib-2.0>=2.10) +# requires at least version 2.10 of glib2 and defines e.g. +# GLIB2_VERSION=2.10.3 +# +# pkg_check_modules (FOO glib-2.0>=2.10 gtk+-2.0) +# requires both glib2 and gtk2, and defines e.g. +# FOO_glib-2.0_VERSION=2.10.3 +# FOO_gtk+-2.0_VERSION=2.8.20 +# +# pkg_check_modules (XRENDER REQUIRED xrender) +# defines e.g.: +# XRENDER_LIBRARIES=Xrender;X11 +# XRENDER_STATIC_LIBRARIES=Xrender;X11;pthread;Xau;Xdmcp +# +# pkg_search_module (BAR libxml-2.0 libxml2 libxml>=2) + + +# Copyright (C) 2006 Enrico Scholz +# +# Redistribution and use, with or without modification, are permitted +# provided that the following conditions are met: +# +# 1. Redistributions must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. The name of the author may not be used to endorse or promote +# products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +### Common stuff #### +set(PKG_CONFIG_VERSION 1) +set(PKG_CONFIG_FOUND 0) + +find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config DOC "pkg-config executable") +mark_as_advanced(PKG_CONFIG_EXECUTABLE) + +if(PKG_CONFIG_EXECUTABLE) + set(PKG_CONFIG_FOUND 1) +endif(PKG_CONFIG_EXECUTABLE) + + +# Unsets the given variables +macro(_pkgconfig_unset var) + set(${var} "" CACHE INTERNAL "") +endmacro(_pkgconfig_unset) + +macro(_pkgconfig_set var value) + set(${var} ${value} CACHE INTERNAL "") +endmacro(_pkgconfig_set) + +# Invokes pkgconfig, cleans up the result and sets variables +macro(_pkgconfig_invoke _pkglist _prefix _varname _regexp) + set(_pkgconfig_invoke_result) + + execute_process( + COMMAND ${PKG_CONFIG_EXECUTABLE} ${ARGN} ${_pkglist} + OUTPUT_VARIABLE _pkgconfig_invoke_result + RESULT_VARIABLE _pkgconfig_failed) + + if (_pkgconfig_failed) + set(_pkgconfig_${_varname} "") + _pkgconfig_unset(${_prefix}_${_varname}) + else(_pkgconfig_failed) + string(REGEX REPLACE "[\r\n]" " " _pkgconfig_invoke_result "${_pkgconfig_invoke_result}") + string(REGEX REPLACE " +$" "" _pkgconfig_invoke_result "${_pkgconfig_invoke_result}") + + if (NOT ${_regexp} STREQUAL "") + string(REGEX REPLACE "${_regexp}" " " _pkgconfig_invoke_result "${_pkgconfig_invoke_result}") + endif(NOT ${_regexp} STREQUAL "") + + separate_arguments(_pkgconfig_invoke_result) + + #message(STATUS " ${_varname} ... ${_pkgconfig_invoke_result}") + set(_pkgconfig_${_varname} ${_pkgconfig_invoke_result}) + _pkgconfig_set(${_prefix}_${_varname} "${_pkgconfig_invoke_result}") + endif(_pkgconfig_failed) +endmacro(_pkgconfig_invoke) + +# Invokes pkgconfig two times; once without '--static' and once with +# '--static' +macro(_pkgconfig_invoke_dyn _pkglist _prefix _varname cleanup_regexp) + _pkgconfig_invoke("${_pkglist}" ${_prefix} ${_varname} "${cleanup_regexp}" ${ARGN}) + _pkgconfig_invoke("${_pkglist}" ${_prefix} STATIC_${_varname} "${cleanup_regexp}" --static ${ARGN}) +endmacro(_pkgconfig_invoke_dyn) + +# Splits given arguments into options and a package list +macro(_pkgconfig_parse_options _result _is_req) + set(${_is_req} 0) + + foreach(_pkg ${ARGN}) + if (_pkg STREQUAL "REQUIRED") + set(${_is_req} 1) + endif (_pkg STREQUAL "REQUIRED") + endforeach(_pkg ${ARGN}) + + set(${_result} ${ARGN}) + list(REMOVE_ITEM ${_result} "REQUIRED") +endmacro(_pkgconfig_parse_options) + +### +macro(_pkg_check_modules_internal _is_required _is_silent _prefix) + _pkgconfig_unset(${_prefix}_FOUND) + _pkgconfig_unset(${_prefix}_VERSION) + _pkgconfig_unset(${_prefix}_PREFIX) + _pkgconfig_unset(${_prefix}_INCLUDEDIR) + _pkgconfig_unset(${_prefix}_LIBDIR) + _pkgconfig_unset(${_prefix}_LIBS) + _pkgconfig_unset(${_prefix}_LIBS_L) + _pkgconfig_unset(${_prefix}_LIBS_PATHS) + _pkgconfig_unset(${_prefix}_LIBS_OTHER) + _pkgconfig_unset(${_prefix}_CFLAGS) + _pkgconfig_unset(${_prefix}_CFLAGS_I) + _pkgconfig_unset(${_prefix}_CFLAGS_OTHER) + _pkgconfig_unset(${_prefix}_STATIC_LIBDIR) + _pkgconfig_unset(${_prefix}_STATIC_LIBS) + _pkgconfig_unset(${_prefix}_STATIC_LIBS_L) + _pkgconfig_unset(${_prefix}_STATIC_LIBS_PATHS) + _pkgconfig_unset(${_prefix}_STATIC_LIBS_OTHER) + _pkgconfig_unset(${_prefix}_STATIC_CFLAGS) + _pkgconfig_unset(${_prefix}_STATIC_CFLAGS_I) + _pkgconfig_unset(${_prefix}_STATIC_CFLAGS_OTHER) + + # create a better addressable variable of the modules and calculate its size + set(_pkg_check_modules_list ${ARGN}) + list(LENGTH _pkg_check_modules_list _pkg_check_modules_cnt) + + if(PKG_CONFIG_EXECUTABLE) + # give out status message telling checked module + if (NOT ${_is_silent}) + if (_pkg_check_modules_cnt EQUAL 1) + message(STATUS "checking for module '${_pkg_check_modules_list}'") + else(_pkg_check_modules_cnt EQUAL 1) + message(STATUS "checking for modules '${_pkg_check_modules_list}'") + endif(_pkg_check_modules_cnt EQUAL 1) + endif(NOT ${_is_silent}) + + set(_pkg_check_modules_packages) + set(_pkg_check_modules_failed) + + # iterate through module list and check whether they exist and match the required version + foreach (_pkg_check_modules_pkg ${_pkg_check_modules_list}) + set(_pkg_check_modules_exist_query) + + # check whether version is given + if (_pkg_check_modules_pkg MATCHES ".*(>=|=|<=).*") + string(REGEX REPLACE "(.*[^><])(>=|=|<=)(.*)" "\\1" _pkg_check_modules_pkg_name "${_pkg_check_modules_pkg}") + string(REGEX REPLACE "(.*[^><])(>=|=|<=)(.*)" "\\2" _pkg_check_modules_pkg_op "${_pkg_check_modules_pkg}") + string(REGEX REPLACE "(.*[^><])(>=|=|<=)(.*)" "\\3" _pkg_check_modules_pkg_ver "${_pkg_check_modules_pkg}") + else(_pkg_check_modules_pkg MATCHES ".*(>=|=|<=).*") + set(_pkg_check_modules_pkg_name "${_pkg_check_modules_pkg}") + set(_pkg_check_modules_pkg_op) + set(_pkg_check_modules_pkg_ver) + endif(_pkg_check_modules_pkg MATCHES ".*(>=|=|<=).*") + + # handle the operands + if (_pkg_check_modules_pkg_op STREQUAL ">=") + list(APPEND _pkg_check_modules_exist_query --atleast-version) + endif(_pkg_check_modules_pkg_op STREQUAL ">=") + + if (_pkg_check_modules_pkg_op STREQUAL "=") + list(APPEND _pkg_check_modules_exist_query --exact-version) + endif(_pkg_check_modules_pkg_op STREQUAL "=") + + if (_pkg_check_modules_pkg_op STREQUAL "<=") + list(APPEND _pkg_check_modules_exist_query --max-version) + endif(_pkg_check_modules_pkg_op STREQUAL "<=") + + # create the final query which is of the format: + # * --atleast-version + # * --exact-version + # * --max-version + # * --exists + if (_pkg_check_modules_pkg_op) + list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_ver}") + else(_pkg_check_modules_pkg_op) + list(APPEND _pkg_check_modules_exist_query --exists) + endif(_pkg_check_modules_pkg_op) + + _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_VERSION) + _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_PREFIX) + _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_INCLUDEDIR) + _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_LIBDIR) + + list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_name}") + list(APPEND _pkg_check_modules_packages "${_pkg_check_modules_pkg_name}") + + # execute the query + execute_process( + COMMAND ${PKG_CONFIG_EXECUTABLE} ${_pkg_check_modules_exist_query} + RESULT_VARIABLE _pkgconfig_retval) + + # evaluate result and tell failures + if (_pkgconfig_retval) + if(NOT ${_is_silent}) + message(STATUS " package '${_pkg_check_modules_pkg}' not found") + endif(NOT ${_is_silent}) + + set(_pkg_check_modules_failed 1) + endif(_pkgconfig_retval) + endforeach(_pkg_check_modules_pkg) + + if(_pkg_check_modules_failed) + # fail when requested + if (${_is_required}) + message(SEND_ERROR "A required package was not found") + endif (${_is_required}) + else(_pkg_check_modules_failed) + # when we are here, we checked whether requested modules + # exist. Now, go through them and set variables + + _pkgconfig_set(${_prefix}_FOUND 1) + list(LENGTH _pkg_check_modules_packages pkg_count) + + # iterate through all modules again and set individual variables + foreach (_pkg_check_modules_pkg ${_pkg_check_modules_packages}) + # handle case when there is only one package required + if (pkg_count EQUAL 1) + set(_pkg_check_prefix "${_prefix}") + else(pkg_count EQUAL 1) + set(_pkg_check_prefix "${_prefix}_${_pkg_check_modules_pkg}") + endif(pkg_count EQUAL 1) + + _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" VERSION "" --modversion ) + _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" PREFIX "" --variable=prefix ) + _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" INCLUDEDIR "" --variable=includedir ) + _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" LIBDIR "" --variable=libdir ) + + message(STATUS " found ${_pkg_check_modules_pkg}, version ${_pkgconfig_VERSION}") + endforeach(_pkg_check_modules_pkg) + + # set variables which are combined for multiple modules + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARIES "(^| )-l" --libs-only-l ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARY_DIRS "(^| )-L" --libs-only-L ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS "" --libs ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS_OTHER "" --libs-only-other ) + + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" INCLUDE_DIRS "(^| )-I" --cflags-only-I ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS "" --cflags ) + _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS_OTHER "" --cflags-only-other ) + endif(_pkg_check_modules_failed) + else(PKG_CONFIG_EXECUTABLE) + if (${_is_required}) + message(SEND_ERROR "pkg-config tool not found") + endif (${_is_required}) + endif(PKG_CONFIG_EXECUTABLE) +endmacro(_pkg_check_modules_internal) + +### +### User visible macros start here +### + +### +macro(pkg_check_modules _prefix _module0) + # check cached value + if (NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION}) + _pkgconfig_parse_options (_pkg_modules _pkg_is_required "${_module0}" ${ARGN}) + _pkg_check_modules_internal("${_pkg_is_required}" 0 "${_prefix}" ${_pkg_modules}) + + _pkgconfig_set(__pkg_config_checked_${_prefix} ${PKG_CONFIG_VERSION}) + endif(NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION}) +endmacro(pkg_check_modules) + +### +macro(pkg_search_module _prefix _module0) + # check cached value + if (NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION}) + set(_pkg_modules_found 0) + _pkgconfig_parse_options(_pkg_modules_alt _pkg_is_required "${_module0}" ${ARGN}) + + message(STATUS "checking for one of the modules '${_pkg_modules_alt}'") + + # iterate through all modules and stop at the first working one. + foreach(_pkg_alt ${_pkg_modules_alt}) + if(NOT _pkg_modules_found) + _pkg_check_modules_internal(0 1 "${_prefix}" "${_pkg_alt}") + endif(NOT _pkg_modules_found) + + if (${_prefix}_FOUND) + set(_pkg_modules_found 1) + endif(${_prefix}_FOUND) + endforeach(_pkg_alt) + + if (NOT ${_prefix}_FOUND) + if(${_pkg_is_required}) + message(SEND_ERROR "None of the required '${_pkg_modules_alt}' found") + endif(${_pkg_is_required}) + endif(NOT ${_prefix}_FOUND) + + _pkgconfig_set(__pkg_config_checked_${_prefix} ${PKG_CONFIG_VERSION}) + endif(NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION}) +endmacro(pkg_search_module) + +### Local Variables: +### mode: cmake +### End: diff --git a/src/projectM-engine-backup/Func.cpp b/src/projectM-engine-backup/Func.cpp new file mode 100755 index 000000000..febc81d76 --- /dev/null +++ b/src/projectM-engine-backup/Func.cpp @@ -0,0 +1,87 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/* Function management */ + +#include +#include +#include + +#include "Common.hpp" +#include "fatal.h" + +#include "Func.hpp" +#include + +#include "wipemalloc.h" + + + + +/* Private function prototypes */ +void *Func::copy_func_key(char * string) { + + char * clone_string; + + if ((clone_string = (char*)wipemalloc(MAX_TOKEN_SIZE)) == NULL) + return NULL; + + strncpy(clone_string, string, MAX_TOKEN_SIZE-1); + + return (void*)clone_string; +} + +/* Compare string name with function name */ +int Func::compare_func(char * name, char * name2) { + + int cmpval; + + /* Uses string comparison function */ + cmpval = strncmp(name, name2, MAX_TOKEN_SIZE-1); + + return cmpval; +} + +Func * Func::create_func (char * name, float (*func_ptr)(float*), int num_args) { + + Func * func; + func = (Func*)wipemalloc(sizeof(Func)); + + if (func == NULL) + return NULL; + + + /* Clear name space */ + memset(func->name, 0, MAX_TOKEN_SIZE); + + /* Copy given name into function structure */ + strncpy(func->name, name, MAX_TOKEN_SIZE); + + /* Assign value pointer */ + func->func_ptr = func_ptr; + func->num_args = num_args; + /* Return instantiated function */ + return func; + +} + +/* Frees a function type, real complicated... */ +Func::~Func() { + } diff --git a/src/projectM-engine-backup/Func.hpp b/src/projectM-engine-backup/Func.hpp new file mode 100755 index 000000000..2d07e7215 --- /dev/null +++ b/src/projectM-engine-backup/Func.hpp @@ -0,0 +1,58 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Function + * + * $Log$ + */ + +#ifndef _FUNC_H +#define _FUNC_H + +#include "Common.hpp" + +class Func; +//#include + +/* Function Type */ +class Func { +public: + char name[MAX_TOKEN_SIZE]; + float (*func_ptr)(float*); + int num_args; + + Func() {} + + /* Public Prototypes */ + DLLEXPORT ~Func(); + static Func *create_func ( char *name, float (*func_ptr)(float*), int num_args ); + static void * copy_func_key(char * string); + int compare_func(char * name, char * name2); + }; + +/** Splay traversal */ +inline void free_func_helper( void *func ) { + delete (Func *)func; +} + +#endif /** !_FUNC_H */ diff --git a/src/projectM-engine-backup/InitCond.cpp b/src/projectM-engine-backup/InitCond.cpp new file mode 100755 index 000000000..79ea005a3 --- /dev/null +++ b/src/projectM-engine-backup/InitCond.cpp @@ -0,0 +1,137 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/* Library functions to manipulate initial condition values */ + +#include +#include +#include + +#include "Common.hpp" +#include "fatal.h" + +#include "Expr.hpp" +#include "InitCond.hpp" +#include "Param.hpp" +#include + +#include "wipemalloc.h" + +char InitCond::init_cond_string_buffer[STRING_BUFFER_SIZE]; +int InitCond::init_cond_string_buffer_index = 0; + +/* Creates a new initial condition */ +InitCond::InitCond( Param * param, CValue init_val ) { + + this->param = param; + this->init_val = init_val; + + if ( INIT_COND_DEBUG ) { + DWRITE( "InitCond::InitCond: %s -> %X -> %X\n", + this->param->name.c_str(), this->param, this->param->engine_val ); + } +} + +/* Frees initial condition structure */ +InitCond::~InitCond() { + } + +/* Evaluate an initial conditon */ +void InitCond::evaluate() { + + /* Parameter is of boolean type, either a 1 or 0 value integer */ + /* Set matrix flag to zero. This ensures + its constant value will be used rather than a matrix value + */ + param->matrix_flag = 0; + if (param->type == P_TYPE_BOOL) { + if (INIT_COND_DEBUG) { + DWRITE( "init_cond: %s = %d (TYPE BOOL)\n", param->name.c_str(), init_val.bool_val); + } + *((int*)param->engine_val) = init_val.bool_val; + return; + } + + /* Parameter is an integer type, just like C */ + + if ( param->type == P_TYPE_INT) { + if ((param->name == "wave_mode") == 0 ) { + } + if (INIT_COND_DEBUG) { + DWRITE( "init_cond: %s = %d (TYPE INT)\n", param->name.c_str(), init_val.int_val); + } + *((int*)param->engine_val) = init_val.int_val; + return; + } + + /* Parameter is of a float type, just like C */ + + if (param->type == P_TYPE_DOUBLE) { + if (INIT_COND_DEBUG) { + DWRITE( "init_cond: %s = %f (TYPE DOUBLE) -> %f -> %X -> %X\n", param->name.c_str(), + init_val.float_val, *((float *)param->engine_val), + param, param->engine_val ); + } + *((float*)param->engine_val) = init_val.float_val; + return; + } + + /* Unknown type of parameter */ + return; +} + +/* WIP */ +void InitCond::init_cond_to_string() { + + int string_length; + char string[MAX_TOKEN_SIZE]; + + /* Create a string "param_name=val" */ + switch (param->type) { + + case P_TYPE_BOOL: + sprintf(string, "%s=%d\n", param->name.c_str(), init_val.bool_val); + break; + case P_TYPE_INT: + sprintf(string, "%s=%d\n", param->name.c_str(), init_val.int_val); + break; + case P_TYPE_DOUBLE: + sprintf(string, "%s=%f\n", param->name.c_str(), init_val.float_val); + break; + default: + return; + } + + /* Compute the length of the string */ + string_length = strlen(string); + + /* Buffer overflow check */ + if ((init_cond_string_buffer_index + string_length + 1) > (STRING_BUFFER_SIZE - 1)) + return; + + /* Copy the string into the initial condition string buffer */ + + strncpy(init_cond_string_buffer + init_cond_string_buffer_index, string, string_length); + + /* Increment the string buffer, offset by one for the null terminator, which will be + overwritten by the next call to this function */ + init_cond_string_buffer_index+= string_length + 1; +} + diff --git a/src/projectM-engine-backup/InitCond.hpp b/src/projectM-engine-backup/InitCond.hpp new file mode 100755 index 000000000..66cc46b33 --- /dev/null +++ b/src/projectM-engine-backup/InitCond.hpp @@ -0,0 +1,59 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Initial condition + * + * $Log$ + */ + +#ifndef _INIT_COND_HPP +#define _INIT_COND_HPP + + +//#define INIT_COND_DEBUG 2 +#define INIT_COND_DEBUG 0 + +#include "Param.hpp" + +class InitCond; +class Param; +#include + +class InitCond { +public: + Param *param; + CValue init_val; + + static char init_cond_string_buffer[STRING_BUFFER_SIZE]; + static int init_cond_string_buffer_index; + + InitCond( Param * param, CValue init_val ); + ~InitCond(); + void evaluate(); + + void init_cond_to_string(); + void write_init(); + }; + + +#endif /** !_INIT_COND_H */ diff --git a/src/projectM-engine-backup/InitCondUtils.hpp b/src/projectM-engine-backup/InitCondUtils.hpp new file mode 100644 index 000000000..4ff0d90c9 --- /dev/null +++ b/src/projectM-engine-backup/InitCondUtils.hpp @@ -0,0 +1,69 @@ +#ifndef _INIT_COND_UTILS_HPP +#define _INIT_COND_UTILS_HPP +#include +#include "InitCond.hpp" + +namespace InitCondUtils { +class LoadUnspecInitCond { + public: + + LoadUnspecInitCond(std::map & initCondTree, std::map & perFrameInitEqnTree): + m_initCondTree(initCondTree), m_perFrameInitEqnTree(perFrameInitEqnTree) {} + + void operator()(Param * param); + + private: + std::map & m_initCondTree; + std::map & m_perFrameInitEqnTree; +}; + + +inline void LoadUnspecInitCond::operator() (Param * param) { + + InitCond * init_cond; + CValue init_val; + + /* Don't count these parameters as initial conditions */ + if (param->flags & P_FLAG_READONLY) + return; + if (param->flags & P_FLAG_QVAR) + return; + if (param->flags & P_FLAG_TVAR) + return; + if (param->flags & P_FLAG_USERDEF) + return; + + /* If initial condition was not defined by the preset file, force a default one + with the following code */ + + if (m_initCondTree.find(param->name) == m_initCondTree.end()) { + + /* Make sure initial condition does not exist in the set of per frame initial equations */ + if (m_perFrameInitEqnTree.find(param->name) != m_perFrameInitEqnTree.end()) + return; + + // Set an initial vialue via correct union member + if (param->type == P_TYPE_BOOL) + init_val.bool_val = 0; + + else if (param->type == P_TYPE_INT) + init_val.int_val = *(int*)param->engine_val; + + else if (param->type == P_TYPE_DOUBLE) + init_val.float_val = *(float*)param->engine_val; + + //printf("%s\n", param->name); + /* Create new initial condition */ + if ((init_cond = new InitCond(param, init_val)) == NULL) + return; + + /* Insert the initial condition into this presets tree */ + /// @bug check the reult status of insert + m_initCondTree.insert(std::make_pair(init_cond->param->name, init_cond)); + + } + + +} +} +#endif diff --git a/src/projectM-engine-backup/Makefile.am b/src/projectM-engine-backup/Makefile.am new file mode 100755 index 000000000..88b9f0087 --- /dev/null +++ b/src/projectM-engine-backup/Makefile.am @@ -0,0 +1,48 @@ +lib_LTLIBRARIES = libprojectM.la + +libprojectM_la_SOURCES=\ +PCM.cc \ +beat_detect.cc \ +browser.cc \ +builtin_funcs.cc \ +console_interface.cc \ +custom_shape.cc \ +custom_wave.cc \ +editor.cc \ +eval.cc \ +fftsg.cc \ +func.cc \ +glConsole.cc \ +init_cond.cc \ +menu.cc \ +param.cc \ +parser.cc \ +pbuffer.cc \ +per_frame_eqn.cc \ +per_pixel_eqn.cc \ +preset.cc \ +projectM.cc \ +splaytree.cc \ +timer.cc \ +tree_types.cc \ +wipemalloc.cc + +libprojectMincludedir = $(includedir)/projectM +libprojectMinclude_HEADERS = projectM.h pbuffer.h event.h console_interface.h PCM.h + +libprojectM_la_LDFLAGS = -version-info 0:0:0 + +AM_LIBS = @GL_LIBS@ @FTGL_LIBS@ +AM_CXXFLAGS= -DLINUX -D__CPLUSPLUS @GL_CFLAGS@ @FTGL_CFLAGS@ + +libprojectM_la_LIBADD = $(AM_LIBS) + +libprojectMconfigdir = $(datadir)/projectM +libprojectMconfig_DATA = share/config share/config.fastcomputers share/config.slowcomputers + +libprojectMfontdir = $(datadir)/projectM/fonts +libprojectMfont_DATA = share/fonts/*.ttf + +libprojectMpresetdir = $(datadir)/projectM/presets +libprojectMpreset_DATA= share/presets/*.milk + diff --git a/src/projectM-engine-backup/Makefile.dist b/src/projectM-engine-backup/Makefile.dist new file mode 100644 index 000000000..1b8b8d0ae --- /dev/null +++ b/src/projectM-engine-backup/Makefile.dist @@ -0,0 +1,24 @@ +# +# projectM -- Milkdrop-esque visualisation SDK +# Copyright (C)2003-2007 projectM Team +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# See 'LICENSE.txt' included within this release + +clean: + rm -rf Debug + rm -rf Release + rm projectM.ncb + rm projectM.opt diff --git a/src/projectM-engine-backup/Makefile.in b/src/projectM-engine-backup/Makefile.in new file mode 100755 index 000000000..0f72972a2 --- /dev/null +++ b/src/projectM-engine-backup/Makefile.in @@ -0,0 +1,621 @@ +# Makefile.in generated by automake 1.9.6 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src +DIST_COMMON = $(libprojectMinclude_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/acx_pthread.m4 \ + $(top_srcdir)/m4/ax_check_gl.m4 \ + $(top_srcdir)/m4/ax_lang_compiler_ms.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(libdir)" \ + "$(DESTDIR)$(libprojectMconfigdir)" \ + "$(DESTDIR)$(libprojectMfontdir)" \ + "$(DESTDIR)$(libprojectMpresetdir)" \ + "$(DESTDIR)$(libprojectMincludedir)" +libLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(lib_LTLIBRARIES) +am__DEPENDENCIES_1 = +libprojectM_la_DEPENDENCIES = $(am__DEPENDENCIES_1) +am_libprojectM_la_OBJECTS = PCM.lo beat_detect.lo browser.lo \ + builtin_funcs.lo console_interface.lo custom_shape.lo \ + custom_wave.lo editor.lo eval.lo fftsg.lo func.lo glConsole.lo \ + init_cond.lo menu.lo param.lo parser.lo pbuffer.lo \ + per_frame_eqn.lo per_pixel_eqn.lo preset.lo projectM.lo \ + splaytree.lo timer.lo tree_types.lo wipemalloc.lo +libprojectM_la_OBJECTS = $(am_libprojectM_la_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libprojectM_la_SOURCES) +DIST_SOURCES = $(libprojectM_la_SOURCES) +libprojectMconfigDATA_INSTALL = $(INSTALL_DATA) +libprojectMfontDATA_INSTALL = $(INSTALL_DATA) +libprojectMpresetDATA_INSTALL = $(INSTALL_DATA) +DATA = $(libprojectMconfig_DATA) $(libprojectMfont_DATA) \ + $(libprojectMpreset_DATA) +libprojectMincludeHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(libprojectMinclude_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +FTGL_CFLAGS = @FTGL_CFLAGS@ +FTGL_LIBS = @FTGL_LIBS@ +GL_CFLAGS = @GL_CFLAGS@ +GL_LIBS = @GL_LIBS@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +POW_LIB = @POW_LIB@ +PTHREAD_CC = @PTHREAD_CC@ +PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ +PTHREAD_LIBS = @PTHREAD_LIBS@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +acx_pthread_config = @acx_pthread_config@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +lib_LTLIBRARIES = libprojectM.la +libprojectM_la_SOURCES = \ +PCM.cc \ +beat_detect.cc \ +browser.cc \ +builtin_funcs.cc \ +console_interface.cc \ +custom_shape.cc \ +custom_wave.cc \ +editor.cc \ +eval.cc \ +fftsg.cc \ +func.cc \ +glConsole.cc \ +init_cond.cc \ +menu.cc \ +param.cc \ +parser.cc \ +pbuffer.cc \ +per_frame_eqn.cc \ +per_pixel_eqn.cc \ +preset.cc \ +projectM.cc \ +splaytree.cc \ +timer.cc \ +tree_types.cc \ +wipemalloc.cc + +libprojectMincludedir = $(includedir)/projectM +libprojectMinclude_HEADERS = projectM.h pbuffer.h event.h console_interface.h PCM.h +libprojectM_la_LDFLAGS = -version-info 0:0:0 +AM_LIBS = @GL_LIBS@ @FTGL_LIBS@ +AM_CXXFLAGS = -DLINUX -D__CPLUSPLUS @GL_CFLAGS@ @FTGL_CFLAGS@ +libprojectM_la_LIBADD = $(AM_LIBS) +libprojectMconfigdir = $(datadir)/projectM +libprojectMconfig_DATA = share/config share/config.fastcomputers share/config.slowcomputers +libprojectMfontdir = $(datadir)/projectM/fonts +libprojectMfont_DATA = share/fonts/*.ttf +libprojectMpresetdir = $(datadir)/projectM/presets +libprojectMpreset_DATA = share/presets/*.milk +all: all-am + +.SUFFIXES: +.SUFFIXES: .cc .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + p=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \ + $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libprojectM.la: $(libprojectM_la_OBJECTS) $(libprojectM_la_DEPENDENCIES) + $(CXXLINK) -rpath $(libdir) $(libprojectM_la_LDFLAGS) $(libprojectM_la_OBJECTS) $(libprojectM_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PCM.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/beat_detect.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/browser.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/builtin_funcs.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/console_interface.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/custom_shape.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/custom_wave.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/editor.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eval.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fftsg.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/func.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glConsole.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/init_cond.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/menu.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/param.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parser.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pbuffer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/per_frame_eqn.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/per_pixel_eqn.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/preset.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/projectM.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/splaytree.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tree_types.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wipemalloc.Plo@am__quote@ + +.cc.o: +@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cc.obj: +@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ +@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cc.lo: +@am__fastdepCXX_TRUE@ if $(LTCXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-libprojectMconfigDATA: $(libprojectMconfig_DATA) + @$(NORMAL_INSTALL) + test -z "$(libprojectMconfigdir)" || $(mkdir_p) "$(DESTDIR)$(libprojectMconfigdir)" + @list='$(libprojectMconfig_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(libprojectMconfigDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(libprojectMconfigdir)/$$f'"; \ + $(libprojectMconfigDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(libprojectMconfigdir)/$$f"; \ + done + +uninstall-libprojectMconfigDATA: + @$(NORMAL_UNINSTALL) + @list='$(libprojectMconfig_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(libprojectMconfigdir)/$$f'"; \ + rm -f "$(DESTDIR)$(libprojectMconfigdir)/$$f"; \ + done +install-libprojectMfontDATA: $(libprojectMfont_DATA) + @$(NORMAL_INSTALL) + test -z "$(libprojectMfontdir)" || $(mkdir_p) "$(DESTDIR)$(libprojectMfontdir)" + @list='$(libprojectMfont_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(libprojectMfontDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(libprojectMfontdir)/$$f'"; \ + $(libprojectMfontDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(libprojectMfontdir)/$$f"; \ + done + +uninstall-libprojectMfontDATA: + @$(NORMAL_UNINSTALL) + @list='$(libprojectMfont_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(libprojectMfontdir)/$$f'"; \ + rm -f "$(DESTDIR)$(libprojectMfontdir)/$$f"; \ + done +install-libprojectMpresetDATA: $(libprojectMpreset_DATA) + @$(NORMAL_INSTALL) + test -z "$(libprojectMpresetdir)" || $(mkdir_p) "$(DESTDIR)$(libprojectMpresetdir)" + @list='$(libprojectMpreset_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(libprojectMpresetDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(libprojectMpresetdir)/$$f'"; \ + $(libprojectMpresetDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(libprojectMpresetdir)/$$f"; \ + done + +uninstall-libprojectMpresetDATA: + @$(NORMAL_UNINSTALL) + @list='$(libprojectMpreset_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(libprojectMpresetdir)/$$f'"; \ + rm -f "$(DESTDIR)$(libprojectMpresetdir)/$$f"; \ + done +install-libprojectMincludeHEADERS: $(libprojectMinclude_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(libprojectMincludedir)" || $(mkdir_p) "$(DESTDIR)$(libprojectMincludedir)" + @list='$(libprojectMinclude_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(libprojectMincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(libprojectMincludedir)/$$f'"; \ + $(libprojectMincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(libprojectMincludedir)/$$f"; \ + done + +uninstall-libprojectMincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(libprojectMinclude_HEADERS)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(libprojectMincludedir)/$$f'"; \ + rm -f "$(DESTDIR)$(libprojectMincludedir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(DATA) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(libprojectMconfigdir)" "$(DESTDIR)$(libprojectMfontdir)" "$(DESTDIR)$(libprojectMpresetdir)" "$(DESTDIR)$(libprojectMincludedir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-libprojectMconfigDATA \ + install-libprojectMfontDATA install-libprojectMincludeHEADERS \ + install-libprojectMpresetDATA + +install-exec-am: install-libLTLIBRARIES + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES \ + uninstall-libprojectMconfigDATA uninstall-libprojectMfontDATA \ + uninstall-libprojectMincludeHEADERS \ + uninstall-libprojectMpresetDATA + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-exec \ + install-exec-am install-info install-info-am \ + install-libLTLIBRARIES install-libprojectMconfigDATA \ + install-libprojectMfontDATA install-libprojectMincludeHEADERS \ + install-libprojectMpresetDATA install-man install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-info-am \ + uninstall-libLTLIBRARIES uninstall-libprojectMconfigDATA \ + uninstall-libprojectMfontDATA \ + uninstall-libprojectMincludeHEADERS \ + uninstall-libprojectMpresetDATA + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/projectM-engine-backup/PBuffer.cpp b/src/projectM-engine-backup/PBuffer.cpp new file mode 100755 index 000000000..744517569 --- /dev/null +++ b/src/projectM-engine-backup/PBuffer.cpp @@ -0,0 +1,217 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: pbuffer.c,v 1.1.1.1 2005/12/23 18:05:00 psperl Exp $ + * + * Render this methods + */ + +#include +//#include + +#include "Common.hpp" +#include "PBuffer.hpp" + +#ifdef MACOS +#include +#endif /** MACOS */ + +/** Creates new pbuffers */ +RenderTarget::RenderTarget(int texsize, int width, int height) : usePbuffers(true) { + + int mindim = 0; + int origtexsize = 0; + int usePbuffers = 1; + + this->texsize=texsize; + +#ifdef USE_FBO + if(this->usePbuffers) + { + glewInit(); + + GLuint fb, color_rb, depth_rb, rgba_tex, depth_tex, i, other_tex; + glGenFramebuffersEXT(1, &fb); + glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fb ); + + 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; + + glGenTextures(1, &other_tex); + glBindTexture(GL_TEXTURE_2D,other_tex); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, texsize, texsize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + //glGenerateMipmapEXT(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + + + glGenTextures(1, &rgba_tex); + glBindTexture(GL_TEXTURE_2D, rgba_tex); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, texsize, texsize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + //glGenerateMipmapEXT(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + + + glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, rgba_tex, 0 ); + this->textureID[0] = rgba_tex; + this->textureID[1] = other_tex; + + GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status == GL_FRAMEBUFFER_COMPLETE_EXT) { + return; + } + } +#endif + +fallback: + DWRITE( "using teximage hack fallback\n" ); + + /** Fallback pbuffer creation via teximage hack */ + /** Check the texture size against the viewport size */ + /** If the viewport is smaller, then we'll need to scale the texture size down */ + /** If the viewport is larger, scale it up */ + mindim = width < height ? width : height; + origtexsize = this->texsize; + this->texsize = nearestPower2( mindim, SCALE_MINIFY ); + + /* Create the texture that will be bound to the render this */ + if ( glIsTexture( this->textureID[0] ) ) { + DWRITE( "texture already exists\n" ); + if ( this->texsize != origtexsize ) { + DWRITE( "deleting existing texture due to resize\n" ); + glDeleteTextures( 1, &this->textureID[0] ); + } + } + + if ( !glIsTexture( this->textureID[0] ) ) { + glGenTextures(1, &this->textureID[0] ); + + DWRITE( "allocate texture: %d\ttexsize: %d x %d\n", + this->textureID[0], this->texsize, this->texsize ); + glBindTexture(GL_TEXTURE_2D, this->textureID[0] ); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, + 0, + 3, + this->texsize, this->texsize, + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + NULL); + } + + this->usePbuffers=0; + return; + } + +/** Destroys the pbuffer */ + +/** Locks the pbuffer */ +void RenderTarget::lock() { + +#ifdef USE_FBO + if(this->usePbuffers) + { + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this->fbuffer[0]); + } + +#endif + } + +/** Unlocks the pbuffer */ +void RenderTarget::unlock() { + +#ifdef USE_FBO + if(this->usePbuffers) + { + glBindTexture( GL_TEXTURE_2D, this->textureID[1] ); + glCopyTexSubImage2D( GL_TEXTURE_2D, + 0, 0, 0, 0, 0, + this->texsize, this->texsize ); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + return; + } + +#endif + + /** Fallback texture path */ + DWRITE( "copying framebuffer to texture\n" ); + glBindTexture( GL_TEXTURE_2D, this->textureID[0] ); + glCopyTexSubImage2D( GL_TEXTURE_2D, + 0, 0, 0, 0, 0, + this->texsize, this->texsize ); + } + +/** + * Calculates the nearest power of two to the given number using the + * appropriate rule + */ +int RenderTarget::nearestPower2( int value, TextureScale scaleRule ) { + + int x = value; + int power = 0; + + DWRITE( "nearestPower2(): %d\n", value ); + + while ( ( x & 0x01 ) != 1 ) { + x >>= 1; + } + + if ( x == 1 ) { + return value; + } else { + x = value; + while ( x != 0 ) { + x >>= 1; + power++; + } + switch ( scaleRule ) { + case SCALE_NEAREST: + if ( ( ( 1 << power ) - value ) <= ( value - ( 1 << ( power - 1 ) ) ) ) { + return 1 << power; + } else { + return 1 << ( power - 1 ); + } + case SCALE_MAGNIFY: + return 1 << power; + case SCALE_MINIFY: + return 1 << ( power - 1 ); + default: + break; + } + } + return 0; + } diff --git a/src/projectM-engine-backup/PBuffer.hpp b/src/projectM-engine-backup/PBuffer.hpp new file mode 100755 index 000000000..f5474860e --- /dev/null +++ b/src/projectM-engine-backup/PBuffer.hpp @@ -0,0 +1,94 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: PBuffer.hpp,v 1.1.1.1 2005/12/23 18:05:00 psperl Exp $ + * + * Opaque render target + * + */ + +#ifndef _RENDERTARGET_H +#define _RENDERTARGET_H + +#ifdef USE_FBO +#include +#endif + +#if defined(MACOS) && !defined(USE_FBO) +#include +#endif /** MACOS */ + +#ifdef WIN32 +#include +#include +#endif /** WIN32 */ + +#ifdef LINUX +#include +#include +#endif + +typedef enum { SCALE_NEAREST, SCALE_MAGNIFY, SCALE_MINIFY } TextureScale; +typedef enum { + AGL_CONTEXT, + CGL_CONTEXT, + NSGL_CONTEXT, + GLX_CONTEXT, + WGL_CONTEXT, + } ContextType; + +typedef enum { PBUFFER_PASS1, PBUFFER_PASS2 } PBufferPass; + +class RenderTarget { + + +public: + /** Texture size */ + int texsize; + + /** Application context */ + ContextType origContextType; + + +int usePbuffers; + + RenderTarget( int texsize, int width, int height ); + void lock(); + void unlock(); + int nearestPower2( int value, TextureScale scaleRule ); + + /** Opaque pbuffer context and pbuffer */ +/* +#ifdef MACOS + void *origContext; + void *pbufferContext; + void *pbuffer; +#endif +*/ + /** Render target texture ID for non-pbuffer systems */ + GLuint textureID[2]; + GLuint fbuffer[1]; + GLuint depthb[1]; + }; + + + +#endif /** !_RENDERTARGET_H */ diff --git a/src/projectM-engine-backup/PCM.cpp b/src/projectM-engine-backup/PCM.cpp new file mode 100755 index 000000000..d4db5f17e --- /dev/null +++ b/src/projectM-engine-backup/PCM.cpp @@ -0,0 +1,325 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: PCM.c,v 1.3 2006/03/13 20:35:26 psperl Exp $ + * + * Takes sound data from wherever and hands it back out. + * Returns PCM Data or spectrum data, or the derivative of the PCM data + */ + +#include +#include + +#include "Common.hpp" +#include "wipemalloc.h" +#include "fftsg.h" +#include "PCM.hpp" + +//initPCM(int samples) +// +//Initializes the PCM buffer to +// number of samples specified. + +PCM::PCM() { + initPCM( 2048 ); + } + +void PCM::initPCM(int samples) { + int i; + + DWRITE( "initPCM()\n" ); + + waveSmoothing = 0; + + //Allocate memory for PCM data buffer + PCMd = (float **)wipemalloc(2 * sizeof(float *)); + PCMd[0] = (float *)wipemalloc(samples * sizeof(float)); + PCMd[1] = (float *)wipemalloc(samples * sizeof(float)); + + maxsamples=samples; + newsamples=0; + numsamples = maxsamples; + + //Initialize buffers to 0 + for (i=0;imaxsamples = 2048; +// this->numsamples = 0; +// this->pcmdataL = NULL; +// this->pcmdataR = NULL; + + /** Allocate PCM data structures */ + pcmdataL=(float *)wipemalloc(this->maxsamples*sizeof(float)); + pcmdataR=(float *)wipemalloc(this->maxsamples*sizeof(float)); + +} + + +void PCM::addPCMfloat(float *PCMdata, int samples) +{ + int i,j; + + + for(i=0;imaxsamples) newsamples=maxsamples; + numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0); + getPCMnew(pcmdataL,0,0,waveSmoothing,0,1); + getPCM(vdataL,512,0,1,0,0); + getPCM(vdataR,512,1,1,0,0); +} + +void PCM::addPCM16Data(const short* pcm_data, short samples) { + int i, j; + + for (i = 0; i < samples; ++i) { + j=i+start; + PCMd[0][j % maxsamples]=(pcm_data[i * 2 + 0]/16384.0); + PCMd[1][j % maxsamples]=(pcm_data[i * 2 + 1]/16384.0); + } + + start = (start + samples) % maxsamples; + + newsamples+=samples; + if (newsamples>maxsamples) newsamples=maxsamples; + numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0); + getPCMnew(pcmdataL,0,0,waveSmoothing,0,1); + getPCM(vdataL,512,0,1,0,0); + getPCM(vdataR,512,1,1,0,0); +} + + +void PCM::addPCM16(short PCMdata[2][512]) +{ + int i,j; + int samples=512; + + DWRITE( "start: %d\n", start ); + + for(i=0;imaxsamples) newsamples=maxsamples; + + numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0); + getPCMnew(pcmdataL,0,0,waveSmoothing,0,1); + getPCM(vdataL,512,0,1,0,0); + getPCM(vdataR,512,1,1,0,0); +} + + +void PCM::addPCM8( unsigned char PCMdata[2][512]) +{ + int i,j; + int samples=512; + + + for(i=0;imaxsamples) newsamples=maxsamples; + numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0); + getPCMnew(pcmdataL,0,0,waveSmoothing,0,1); + getPCM(vdataL,512,0,1,0,0); + getPCM(vdataR,512,1,1,0,0); +} + + +//puts sound data requested at provided pointer +// +//samples is number of PCM samples to return +//freq = 0 gives PCM data +//freq = 1 gives FFT data +//smoothing is the smoothing coefficient + +//returned values are normalized from -1 to 1 + +void PCM::getPCM(float *PCMdata, int samples, int channel, int freq, float smoothing, int derive) +{ + int i,index; + + index=start-1; + + if (index<0) index=maxsamples+index; + + PCMdata[0]=PCMd[channel][index]; + + for(i=1;i +#include +#include +#include +#include "projectM.hpp" + +#include "fatal.h" +#include "Common.hpp" + +#include "CustomShape.hpp" +#include "Eval.hpp" +#include "Expr.hpp" +#include "InitCond.hpp" +#include "Param.hpp" +#include "Preset.hpp" +#include + +#include "wipemalloc.h" + +/** Constructor */ +Param::Param( std::string _name, short int _type, short int _flags, void * _engine_val, void * _matrix, + CValue _default_init_val, CValue _upper_bound, CValue _lower_bound): + name(_name), + type(_type), + flags (_flags), + matrix_flag (0), + matrix (_matrix), + engine_val(_engine_val), + default_init_val (_default_init_val), + upper_bound (_upper_bound), + lower_bound (_lower_bound) + { + + /** @@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; + +} + + +/* Creates a user defined parameter */ +Param::Param(std::string _name) : + type(P_TYPE_DOUBLE), + flags(P_FLAG_USERDEF), + matrix_flag(0), + matrix(0), + name(_name) + { + + engine_val = new float(); + + default_init_val.float_val = DEFAULT_DOUBLE_IV; + 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; +} + +/* Free's a parameter type */ +Param::~Param() { + + int x; + if (flags & P_FLAG_USERDEF) { + free(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); + } //FIX THIS NOW XMAS05 + else if (flags & P_FLAG_PER_PIXEL) { + for (x = 0; x < gx; x++) + free(((float**)matrix)[x]); + free(matrix); + matrix = NULL; + } + } + + if (PARAM_DEBUG) printf("~Param: freeing \"%s\".\n", name.c_str()); +} + + +/* Returns nonzero if the string is valid parameter name */ +int Param::is_valid_param_string( const char * string ) { + + if (string == NULL) + return FALSE; + + /* This ensures the first character is non numeric */ + if ( ((*string) >= 48) && ((*string) <= 57)) + return FALSE; + + /* These probably should never happen */ + if (*string == '.') + return FALSE; + + if (*string == '+') + return FALSE; + + if (*string == '-') + return FALSE; + + /* Could also add checks for other symbols. May do later */ + + return TRUE; + +} + +/* Sets the parameter engine value to value val. + clipping occurs if necessary */ +void Param::set_param( float val) { + + switch (type) { + + case P_TYPE_BOOL: + if (val < 0) + *((int*)engine_val) = 0; + else if (val > 0) + *((int*)engine_val) = 1; + else + *((int*)engine_val) = 0; + break; + case P_TYPE_INT: + /* Make sure value is an integer */ + val = floor(val); + if (val < lower_bound.int_val) + *((int*)engine_val) = lower_bound.int_val; + else if (val > upper_bound.int_val) + *((int*)engine_val) = upper_bound.int_val; + else + *((int*)engine_val) = (int)val; + break; + case P_TYPE_DOUBLE: + /* Make sure value is an integer */ + + + if (val < lower_bound.float_val) + *((float*)engine_val) = lower_bound.float_val; + else if (val > upper_bound.float_val) + *((float*)engine_val) = upper_bound.float_val; + else + *((float*)engine_val) = val; + break; + default: + abort(); + break; + + } + + return; +} + + +/* Loads a float parameter into the builtin database */ +Param * Param::new_param_float(char * name, short int flags, void * engine_val, void * matrix, + float upper_bound, float lower_bound, float init_val) { + + Param * param; + CValue iv, ub, lb; + + iv.float_val = init_val; + ub.float_val = upper_bound; + lb.float_val = lower_bound; + + if ((param = new Param(name, P_TYPE_DOUBLE, flags, engine_val, matrix,iv, ub, lb)) == NULL) + return NULL; + + + /* Finished, return success */ + return param; +} + +/* Creates a new parameter of type int */ +Param * Param::new_param_int(char * name, short int flags, void * engine_val, + int upper_bound, int lower_bound, int init_val) { + + Param * param; + CValue iv, ub, lb; + + iv.int_val = init_val; + ub.int_val = upper_bound; + lb.int_val = lower_bound; + + if ((param = new Param(name, P_TYPE_INT, flags, engine_val, NULL, iv, ub, lb)) == NULL) + return NULL; + + + /* Finished, return success */ + return param; +} + +/* Creates a new parameter of type bool */ +Param * Param::new_param_bool(char * name, short int flags, void * engine_val, + int upper_bound, int lower_bound, int init_val) { + + Param * param; + CValue iv, ub, lb; + + iv.bool_val = init_val; + ub.bool_val = upper_bound; + lb.bool_val = lower_bound; + + if ((param = new Param(name, P_TYPE_BOOL, flags, engine_val, NULL, iv, ub, lb)) == NULL) + return NULL; + + + /* Finished, return success */ + return param; +} + + diff --git a/src/projectM-engine-backup/Param.hpp b/src/projectM-engine-backup/Param.hpp new file mode 100755 index 000000000..09a8e895d --- /dev/null +++ b/src/projectM-engine-backup/Param.hpp @@ -0,0 +1,110 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Parameter used within a preset + * + * $Log$ + */ + +#ifndef _PARAM_H +#define _PARAM_H + +/* Debug level, zero for none */ +#define PARAM_DEBUG 0 + +#define P_CREATE 1 +#define P_NONE 0 + +#define P_TYPE_BOOL 0 +#define P_TYPE_INT 1 +#define P_TYPE_DOUBLE 2 + +#define P_FLAG_NONE 0 +#define P_FLAG_READONLY 1 +#define P_FLAG_USERDEF (1 << 1) +#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) + +#include "Expr.hpp" +#include "Common.hpp" +#include +class InitCond; +class Param; +class Preset; +//#include + +/* Parameter Type */ +class Param { +public: + std::string name; /* name of the parameter, not necessary but useful neverthless */ + short int type; /* parameter number type (int, bool, or float) */ + short int flags; /* read, write, user defined, etc */ + short int matrix_flag; /* for optimization purposes */ + void * engine_val; /* pointer to the engine variable */ + void * matrix; /* per pixel / per point matrix for this variable */ + 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; + + /* Function prototypes */ + Param(std::string name, short int type, short int flags, + void * eqn_val, void *matrix, + CValue default_init_val, CValue upper_bound, + CValue lower_bound); + + ~Param(); + + /** Create a user defined parameter **/ + Param( std::string name ); + static int init_user_param_db(); + static int destroy_user_param_db(); + + void load_unspec_init_cond_shape(); + + + int compare_param( char *name, char *name2 ); + static int is_valid_param_string( const char *string ); + void set_param( float val ); + + static Param *new_param_float( char *name, short int flags, void *engine_val, + void *matrix, float upper_bound, + float lower_bound, + float init_val ); + static Param *new_param_double( char *name, short int flags, void *engine_val, + void *matrix, double upper_bound, + double lower_bound, + double init_val ); + static Param * new_param_int( char * name, short int flags, void * engine_val, + int upper_bound, int lower_bound, int init_val ); + static Param * new_param_bool( char * name, short int flags, void * engine_val, + int upper_bound, int lower_bound, int init_val ); + +}; + +#endif /** !_PARAM_TYPES_H */ + diff --git a/src/projectM-engine-backup/ParamUtils.hpp b/src/projectM-engine-backup/ParamUtils.hpp new file mode 100644 index 000000000..866e3d143 --- /dev/null +++ b/src/projectM-engine-backup/ParamUtils.hpp @@ -0,0 +1,138 @@ +/** ParamUtils.hpp: + * A collection of utility functions to make using parameter types easier. + * In reality, this stuff belongs elsewhere, but one step at a time + */ +#ifndef _PARAM_UTILS_HPP +#define _PARAM_UTILS_HPP + +#include "Param.hpp" +#include +#include + + +class BuiltinParams; + +class ParamUtils +{ +public: + static bool insert(Param * param, std::map * paramTree) + { + + assert(param); + assert(paramTree); + + + return ((paramTree->insert(std::make_pair(param->name,param))).second); + + } + + static const int AUTO_CREATE = 1; + static const int NO_CREATE = 0; + + template + static Param * find(std::string name, std::map * paramTree) + { + + assert(paramTree); + + Param * param = NULL; + + /* First look in the builtin database */ + std::map::iterator pos = paramTree->find(name); + + + if ((FLAGS == AUTO_CREATE) && ((pos == paramTree->end()))) + { + /* Check if string is valid */ + if (!Param::is_valid_param_string(name.c_str())) + return NULL; + + /* Now, create the user defined parameter given the passed name */ + if ((param = new Param(name)) == NULL) + return NULL; + + /* Finally, insert the new parameter into this preset's proper splaytree */ + std::pair::iterator, bool> insertRetPair = + paramTree->insert(std::make_pair(param->name, param)); + + if (insertRetPair.second) + param = insertRetPair.first->second; + + } else + param = pos->second; + + + /* Return the found (or created) parameter. Note that this could be null */ + return param; + + + } + + /// Checks attempt + static Param * find(const std::string & name, BuiltinParams * builtinParams, std::map * insertionTree) + { + + Param * param; + + // Check first db + if ((param = builtinParams->find_builtin_param(name)) != 0) + return param; + + // Check second db, create if necessary + return find(name, insertionTree); + + } + + class LoadInitCondFunctor + { + public: + LoadInitCondFunctor(Preset * preset) :m_preset(preset) {} + + void operator() (Param * param) + { + + InitCond * init_cond; + CValue init_val; + + /* Don't count read only parameters as initial conditions */ + if (param->flags & P_FLAG_READONLY) + return; + + /* If initial condition was not defined by the preset file, force a default one + with the following code */ + std::map::iterator pos; + if ((pos = (m_preset->init_cond_tree.find(param->name))) == m_preset->init_cond_tree.end()) + { + + std::map::iterator per_frame_init_pos; + /* Make sure initial condition does not exist in the set of per frame initial equations */ + if ((per_frame_init_pos = (m_preset->per_frame_init_eqn_tree.find(param->name))) != m_preset->per_frame_init_eqn_tree.end()) + return; + + if (param->type == P_TYPE_BOOL) + init_val.bool_val = 0; + + else if (param->type == P_TYPE_INT) + init_val.int_val = *(int*)param->engine_val; + + else if (param->type == P_TYPE_DOUBLE) + init_val.float_val = *(float*)param->engine_val; + + /* Create new initial condition */ + if ((init_cond = new InitCond(param, init_val)) == NULL) + return; + + /* Insert the initial condition into this presets tree */ + /// @bug not error checking + m_preset->init_cond_tree.insert(std::make_pair(init_cond->param->name,init_cond)); + } + + } + + private : + Preset * m_preset; + }; + +}; + +#endif diff --git a/src/projectM-engine-backup/Parser.cpp b/src/projectM-engine-backup/Parser.cpp new file mode 100755 index 000000000..ed1a663b9 --- /dev/null +++ b/src/projectM-engine-backup/Parser.cpp @@ -0,0 +1,2143 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU +* License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/* parser.c */ + +#include +#include +#include + +#include "Common.hpp" +#include "fatal.h" + +#include "BuiltinFuncs.hpp" +#include "CustomWave.hpp" +#include "CustomShape.hpp" +#include "Expr.hpp" +#include "Eval.hpp" +#include "Func.hpp" +#include "InitCond.hpp" +#include "Param.hpp" +#include "Preset.hpp" +#include "Parser.hpp" +#include "PerFrameEqn.hpp" +#include "PerPixelEqn.hpp" +#include +#include "ParamUtils.hpp" + +#include "wipemalloc.h" + +/* Grabs the next token from the file. The second argument points + to the raw string */ + +line_mode_t Parser::line_mode; +CustomWave *Parser::current_wave; +CustomShape *Parser::current_shape; +int Parser::string_line_buffer_index; +char Parser::string_line_buffer[STRING_LINE_SIZE]; +unsigned int Parser::line_count; +int Parser::per_frame_eqn_count; +int Parser::per_frame_init_eqn_count; +int Parser::last_custom_wave_id; +int Parser::last_custom_shape_id; +char Parser::last_eqn_type[MAX_TOKEN_SIZE]; +int Parser::last_token_size; + +token_t Parser::parseToken(FILE * fs, char * string) { + + char c; + int i; + + if (string != NULL) + memset(string, 0, MAX_TOKEN_SIZE); + + /* Loop until a delimiter is found, or the maximum string size is found */ + for (i = 0; i < MAX_TOKEN_SIZE;i++) { + c = fgetc(fs); + last_token_size++; + /* If the string line buffer is full, quit */ + if (string_line_buffer_index == (STRING_LINE_SIZE - 1)) + return tStringBufferFilled; + + /* Otherwise add this character to the string line buffer */ + string_line_buffer[string_line_buffer_index++] = c; + /* Now interpret the character */ + switch (c) { + + case '+': + return tPlus; + case '-': + return tMinus; + case '%': + return tMod; + case '/': + + /* check for line comment here */ + if ((c = fgetc(fs)) == '/') { + while(1) { + c = fgetc(fs); + if (c == EOF) { + line_mode = NORMAL_LINE_MODE; + return tEOF; + } + if (c == '\n') { + line_mode = NORMAL_LINE_MODE; + return tEOL; + } + } + + } + + /* Otherwise, just a regular division operator */ + ungetc(c, fs); + return tDiv; + + case '*': + return tMult; + case '|': + return tOr; + case '&': + return tAnd; + case '(': + return tLPr; + case ')': + return tRPr; + case '[': + return tLBr; + case ']': + return tRBr; + case '=': + return tEq; + case '\n': + line_count++; + line_mode = NORMAL_LINE_MODE; + return tEOL; + case ',': + return tComma; + case ';': + return tSemiColon; + case ' ': /* space, skip the character */ + i--; + break; + case EOF: + line_count = 1; + line_mode = NORMAL_LINE_MODE; + return tEOF; + + default: + if (string != NULL) + string[i] = c; + } + + } + + /* String reached maximum length, return special token error */ + return tStringTooLong; + +} + +/* Parse input in the form of "exp, exp, exp, ...)" + Returns a general expression list */ + +GenExpr **Parser::parse_prefix_args(FILE * fs, int num_args, Preset * preset) { + + int i, j; + GenExpr ** expr_list; /* List of arguments to function */ + GenExpr * gen_expr; + + /* Malloc the expression list */ + expr_list = (GenExpr**)wipemalloc(sizeof(GenExpr*)*num_args); + + /* Malloc failed */ + if (expr_list == NULL) + return NULL; + + + i = 0; + + while (i < num_args) { + //if (PARSE_DEBUG) printf("parse_prefix_args: parsing argument %d...\n", i+1); + /* Parse the ith expression in the list */ + if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) { + //if (PARSE_DEBUG) printf("parse_prefix_args: failed to get parameter # %d for function (LINE %d)\n", i+1, line_count); + for (j = 0; j < i; j++) + delete expr_list[j]; + free(expr_list); + expr_list = NULL; + return NULL; + } + /* Assign entry in expression list */ + expr_list[i++] = gen_expr; + } + + //if (PARSE_DEBUG) printf("parse_prefix_args: finished parsing %d arguments (LINE %d)\n", num_args, line_count); + /* Finally, return the resulting expression list */ + return expr_list; +} + +/* Parses a comment at the top of the file. Stops when left bracket is found */ +int Parser::parse_top_comment(FILE * fs) { + + char string[MAX_TOKEN_SIZE]; + token_t token; + + /* Process tokens until left bracket is found */ + while ((token = parseToken(fs, string)) != tLBr) { + if (token == tEOF) + return PROJECTM_PARSE_ERROR; + } + + /* Done, return success */ + return PROJECTM_SUCCESS; +} + +/* Right Bracket is parsed by this function. + puts a new string into name */ +int Parser::parse_preset_name(FILE * fs, char * name) { + + token_t token; + + if (name == NULL) + return PROJECTM_FAILURE; + + if ((token = parseToken(fs, name)) != tRBr) + return PROJECTM_PARSE_ERROR; + +#ifdef DEBUG + if (PARSE_DEBUG) DWRITE("parse_preset_name: parsed preset (name = \"%s\")\n", name); +#endif + + return PROJECTM_SUCCESS; +} + + +/* Parses per pixel equations */ +int Parser::parse_per_pixel_eqn(FILE * fs, Preset * preset, char * init_string) { + + + char string[MAX_TOKEN_SIZE]; + GenExpr * gen_expr; + +#ifdef DEBUG + if (PARSE_DEBUG) DWRITE("parse_per_pixel: per_pixel equation parsing start...(LINE %d)\n", line_count); +#endif + +if (init_string != 0) { + strncpy(string, init_string, strlen(init_string)); +} else { + + if (parseToken(fs, string) != tEq) { /* parse per pixel operator name */ +#ifdef DEBUG + if (PARSE_DEBUG) DWRITE("parse_per_pixel: equal operator expected after per pixel operator \"%s\", but not found (LINE %d)\n", + string, line_count); +#endif + return PROJECTM_PARSE_ERROR; + } +} + + /* Parse right side of equation as an expression */ + if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) { +#ifdef DEBUG + if (PARSE_DEBUG) DWRITE("parse_per_pixel: equation evaluated to null? (LINE %d)\n", line_count); +#endif + return PROJECTM_PARSE_ERROR; + } + + /* Add the per pixel equation */ + if (preset->add_per_pixel_eqn(string, gen_expr) < 0) { + if (PARSE_DEBUG) { + DWRITE( "parse_per_pixel: no param associated with \"%s\" (LINE %d)", string, line_count); + + } + delete gen_expr; + return PROJECTM_PARSE_ERROR; + } + + return PROJECTM_SUCCESS; +} + +/* Parses an equation line, this function is way too big, should add some helper functions */ +int Parser::parse_line(FILE * fs, Preset * preset) { + + char eqn_string[MAX_TOKEN_SIZE]; + token_t token; + InitCond * init_cond; + PerFrameEqn * per_frame_eqn; + //PerFrameEqn * per_frame_init_eqn; + + /* Clear the string line buffer */ + memset(string_line_buffer, 0, STRING_LINE_SIZE); + string_line_buffer_index = 0; + + token = parseToken( fs, eqn_string ); + switch (token ) { + + /* Invalid Cases */ + case tRBr: + case tLPr: + case tRPr: + case tComma: + case tLBr: + case tPlus: + case tMinus: + case tMod: + case tMult: + case tOr: + case tAnd: + case tDiv: + + // if (PARSE_DEBUG) printf("parse_line: invalid token found at start of line (LINE %d)\n", line_count); + /* Invalid token found, return a parse error */ + return PROJECTM_PARSE_ERROR; + + + case tEOL: /* Empty line */ + line_mode = NORMAL_LINE_MODE; + return PROJECTM_SUCCESS; + + case tEOF: /* End of File */ + line_mode = NORMAL_LINE_MODE; + line_count = 1; + return EOF; + + case tSemiColon: /* Indicates end of expression */ + return PROJECTM_SUCCESS; + + /* Valid Case, either an initial condition or equation should follow */ + case tEq: + + /* CASE: PER FRAME INIT EQUATION */ + if (!strncmp(eqn_string, PER_FRAME_INIT_STRING, PER_FRAME_INIT_STRING_LENGTH)) { + + //if (PARSE_DEBUG) printf("parse_line: per frame init equation found...(LINE %d)\n", line_count); + + /* Parse the per frame equation */ + if ((init_cond = parse_per_frame_init_eqn(fs, preset, NULL)) == NULL) { + //if (PARSE_DEBUG) printf("parse_line: per frame init equation parsing failed (LINE %d)\n", line_count); + return PROJECTM_PARSE_ERROR; + } + + /* Insert the equation in the per frame equation tree */ + preset->per_frame_init_eqn_tree.insert(std::make_pair(init_cond->param->name, init_cond)); + + if (update_string_buffer(preset->per_frame_init_eqn_string_buffer, + &preset->per_frame_init_eqn_string_index) < 0) + { return PROJECTM_FAILURE;} + line_mode = PER_FRAME_INIT_LINE_MODE; + return PROJECTM_SUCCESS; + } + + /* Per frame equation case */ + if (!strncmp(eqn_string, PER_FRAME_STRING, PER_FRAME_STRING_LENGTH)) { + + /* Sometimes per frame equations are implicitly defined without the + per_frame_ prefix. This informs the parser that one could follow */ + line_mode = PER_FRAME_LINE_MODE; + + //if (PARSE_DEBUG) printf("parse_line: per frame equation found...(LINE %d)\n", line_count); + + /* Parse the per frame equation */ + if ((per_frame_eqn = parse_per_frame_eqn(fs, ++per_frame_eqn_count, preset)) == NULL) { + if (PARSE_DEBUG) printf("parse_line: per frame equation parsing failed (LINE %d)\n", line_count); + return PROJECTM_PARSE_ERROR; + } + + /* Insert the equation in the per frame equation tree */ + preset->per_frame_eqn_tree.insert(std::make_pair(per_frame_eqn_count, per_frame_eqn)); + + if (update_string_buffer(preset->per_frame_eqn_string_buffer, + &preset->per_frame_eqn_string_index) < 0) + return PROJECTM_FAILURE; + + return PROJECTM_SUCCESS; + + } + + /* Wavecode initial condition case */ + if (!strncmp(eqn_string, WAVECODE_STRING, WAVECODE_STRING_LENGTH)) { + + line_mode = CUSTOM_WAVE_WAVECODE_LINE_MODE; + + //if (PARSE_DEBUG) + // printf("parse_line: wavecode prefix found: \"%s\"\n", eqn_string); + + // printf("string:%d\n", 5); + + //SUPER MYSTERIO-BUG - Don't Remove + printf(""); + + return parse_wavecode(eqn_string, fs, preset); + } + + /* Custom Wave Prefix */ + if ((!strncmp(eqn_string, WAVE_STRING, WAVE_STRING_LENGTH)) && + ((eqn_string[5] >= 48) && (eqn_string[5] <= 57))) { + + // if (PARSE_DEBUG) printf("parse_line wave prefix found: \"%s\"\n", eqn_string); + + return parse_wave(eqn_string, fs, preset); + + } + + + /* Shapecode initial condition case */ + if (!strncmp(eqn_string, SHAPECODE_STRING, SHAPECODE_STRING_LENGTH)) { + + line_mode = CUSTOM_SHAPE_SHAPECODE_LINE_MODE; + + if (PARSE_DEBUG) printf("parse_line: shapecode prefix found: \"%s\"\n", eqn_string); + + return parse_shapecode(eqn_string, fs, preset); + } + + /* Custom Shape Prefix */ + if ((!strncmp(eqn_string, SHAPE_STRING, SHAPE_STRING_LENGTH)) && + ((eqn_string[6] >= 48) && (eqn_string[6] <= 57))) { + + if (PARSE_DEBUG) printf("parse_line shape prefix found: \"%s\"\n", eqn_string); + return parse_shape(eqn_string, fs, preset); + + } + + /* Per pixel equation case */ + if (!strncmp(eqn_string, PER_PIXEL_STRING, PER_PIXEL_STRING_LENGTH)) { + line_mode = PER_PIXEL_LINE_MODE; + + if (parse_per_pixel_eqn(fs, preset, 0) < 0) + return PROJECTM_PARSE_ERROR; + + + if (update_string_buffer(preset->per_pixel_eqn_string_buffer, + &preset->per_pixel_eqn_string_index) < 0) + return PROJECTM_FAILURE; + + if (PARSE_DEBUG) printf("parse_line: finished parsing per pixel equation (LINE %d)\n", line_count); + return PROJECTM_SUCCESS; + } + + /* Sometimes equations are written implicitly in milkdrop files, in the form + + per_frame_1 = p1 = eqn1; p2 = eqn2; p3 = eqn3;..; + + which is analagous to: + + per_frame_1 = p1 = eqn1; per_frame_2 = p2 = eqn2; per_frame_3 = p3 = eqn3; ...; + + The following line mode hack allows such implicit declaration of the + prefix that specifies the equation type. An alternative method + may be to associate each equation line as list of equations separated + by semicolons (and a new line ends the list). Instead, however, a global + variable called "line_mode" specifies the last type of equation found, + and bases any implicitly typed input on this fact + + Note added by Carmelo Piccione (cep@andrew.cmu.edu) 10/19/03 + */ + + /* Per frame line mode previously, try to parse the equation implicitly */ + if (line_mode == PER_FRAME_LINE_MODE) { + if ((per_frame_eqn = parse_implicit_per_frame_eqn(fs, eqn_string, ++per_frame_eqn_count, preset)) == NULL) + return PROJECTM_PARSE_ERROR; + + /* Insert the equation in the per frame equation tree */ + preset->per_frame_eqn_tree.insert(std::make_pair(per_frame_eqn_count, per_frame_eqn)); + + if (update_string_buffer(preset->per_frame_eqn_string_buffer, + &preset->per_frame_eqn_string_index) < 0) + return PROJECTM_FAILURE; + + return PROJECTM_SUCCESS; + + } else if (line_mode == PER_FRAME_INIT_LINE_MODE) { + if (PARSE_DEBUG) printf("parse_line: parsing impliict per frame init eqn)\n"); + if ((init_cond = parse_per_frame_init_eqn(fs, preset, NULL)) == NULL) + return PROJECTM_PARSE_ERROR; + + ++per_frame_init_eqn_count; + + /* Insert the equation in the per frame equation tree */ + preset->per_frame_init_eqn_tree.insert(std::make_pair(init_cond->param->name, init_cond)); + + + if (update_string_buffer(preset->per_frame_init_eqn_string_buffer, + &preset->per_frame_init_eqn_string_index) < 0) + return PROJECTM_FAILURE; + + return PROJECTM_SUCCESS; + } else if (line_mode == PER_PIXEL_LINE_MODE) { + + if (PARSE_DEBUG) printf("parse_line: implicit per pixel eqn\n", line_count); + return parse_per_pixel_eqn(fs, preset, eqn_string); + + + } else if (line_mode == CUSTOM_WAVE_PER_POINT_LINE_MODE) { + + if (PARSE_DEBUG) printf("parse_line: implicit cwave ppoint eqn found (LINE %d)\n", line_count); + //int len = strlen(eqn_string); + + if (parse_wave_helper(fs, preset, last_custom_wave_id, last_eqn_type, eqn_string) < 0) { + if (PARSE_DEBUG) printf("parse_line: failed to parse an implicit custom wave per point eqn\n"); + return PROJECTM_FAILURE; + } + return PROJECTM_SUCCESS; + } else if (line_mode == CUSTOM_WAVE_PER_FRAME_LINE_MODE) { + + //Added by PJS. I hope I did it right + CustomWave * custom_wave; + + /* Retrieve custom shape associated with this id */ + if ((custom_wave = preset->find_custom_wave(last_custom_wave_id, TRUE)) == NULL) + return PROJECTM_FAILURE; + return parse_wave_per_frame_eqn(fs, custom_wave, preset); + + } else if (line_mode == CUSTOM_WAVE_WAVECODE_LINE_MODE) { + if (PARSE_DEBUG) printf("unsupported line mode: CUSTOM_WAVE_WAVECODE_LINE_MODE\n"); + return PROJECTM_FAILURE; + } else if (line_mode == CUSTOM_SHAPE_SHAPECODE_LINE_MODE) { + if (PARSE_DEBUG) printf("unsupported line mode: CUSTOM_SHAPE_SHAPECODE_LINE_MODE\n"); + return PROJECTM_FAILURE; + } else if (line_mode == CUSTOM_SHAPE_PER_FRAME_LINE_MODE) { + + CustomShape * custom_shape; + + /* Retrieve custom shape associated with this id */ + if ((custom_shape = preset->find_custom_shape(last_custom_shape_id, TRUE)) == NULL) + return PROJECTM_FAILURE; + + return parse_shape_per_frame_eqn(fs, custom_shape, preset); + + } else if (line_mode == CUSTOM_SHAPE_PER_FRAME_INIT_LINE_MODE) { + + CustomShape * custom_shape; + + /* Retrieve custom shape associated with this id */ + if ((custom_shape = preset->find_custom_shape(last_custom_shape_id, TRUE)) == NULL) + return PROJECTM_FAILURE; + + return parse_shape_per_frame_init_eqn(fs, custom_shape, preset); + + } + + //if (PARSE_DEBUG) printf("parse_line: found initial condition: name = \"%s\" (LINE %d)\n", eqn_string, line_count); + /* Evaluate the initial condition */ + if ((init_cond = parse_init_cond(fs, eqn_string, preset)) == NULL) { + if (PARSE_DEBUG) printf("parse_line: failed to parse initial condition (LINE %d)\n", line_count); + return PROJECTM_PARSE_ERROR; + } + + /* Add equation to initial condition tree */ + preset->init_cond_tree.insert(std::make_pair(init_cond->param->name, init_cond)); + + /* Finished with initial condition line */ + // if (PARSE_DEBUG) printf("parse_line: initial condition parsed successfully\n"); + + return PROJECTM_SUCCESS; + + /* END INITIAL CONDITIONING PARSING */ + + default: /* an uncaught type or an error has occurred */ + if (PARSE_DEBUG) printf("parse_line: uncaught case, token val = %d\n", token); + return PROJECTM_PARSE_ERROR; + } + + /* Because of the default in the case statement, + control flow should never actually reach here */ + return PROJECTM_PARSE_ERROR; +} + + + +/* Parses a general expression, this function is the meat of the parser */ +GenExpr * Parser::parse_gen_expr ( FILE * fs, TreeExpr * tree_expr, Preset * preset) { + + int i; + char string[MAX_TOKEN_SIZE]; + token_t token; + GenExpr * gen_expr; + float val; + Param * param = NULL; + Func * func; + GenExpr ** expr_list; + + switch (token = parseToken(fs,string)) { + /* Left Parentice Case */ + case tLPr: + + /* CASE 1 (Left Parentice): See if the previous string before this parentice is a function name */ + if ((func = BuiltinFuncs::find_func(string)) != NULL) { + if (PARSE_DEBUG) { + DWRITE( "parse_gen_expr: found prefix function (name = %s) (LINE %d)\n", func->name, line_count); + + } + + /* Parse the functions arguments */ + if ((expr_list = parse_prefix_args(fs, func->num_args, preset)) == NULL) { + if (PARSE_DEBUG) { + DWRITE( "parse_prefix_args: failed to generate an expresion list! (LINE %d) \n", line_count); + + } + if ( tree_expr != NULL ) { + delete tree_expr; + } + return NULL; + } + + /* Convert function to expression */ + if ((gen_expr = GenExpr::prefun_to_expr((float (*)(void *))func->func_ptr, expr_list, func->num_args)) == NULL) { + if (PARSE_DEBUG) printf("parse_prefix_args: failed to convert prefix function to general expression (LINE %d) \n", + line_count); + delete tree_expr; + for (i = 0; i < func->num_args;i++) + delete expr_list[i]; + free(expr_list); + expr_list = NULL; + return NULL; + } + + + + token = parseToken(fs, string); + + if (*string != 0) { + if (PARSE_DEBUG) printf("parse_prefix_args: empty string expected, but not found...(LINE %d)\n", line_count); + /* continue anyway for now, could be implicit multiplication */ + } + + return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset); + } + + + /* Case 2: (Left Parentice), a string coupled with a left parentice. Either an error or implicit + multiplication operator. For now treat it as an error */ + if (*string != 0) { + if (PARSE_DEBUG) printf("parse_gen_expr: implicit multiplication case unimplemented!\n"); + delete tree_expr; + return NULL; + } + + /* CASE 3 (Left Parentice): the following is enclosed parentices to change order + of operations. So we create a new expression tree */ + + if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) { + //if (PARSE_DEBUG) printf("parse_gen_expr: found left parentice, but failed to create new expression tree \n"); + delete tree_expr; + return NULL; + } + + if (PARSE_DEBUG) printf("parse_gen_expr: finished enclosed expression tree...\n"); + token = parseToken(fs, string); + return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset); + + /* Plus is a prefix operator check */ + case tPlus: + if (*string == 0) { + + //if (PARSE_DEBUG) printf("parse_gen_expr: plus used as prefix (LINE %d)\n", line_count); + + /* Treat prefix plus as implict 0 preceding operator */ + gen_expr = GenExpr::const_to_expr(0); + + return parse_infix_op(fs, tPositive, insert_gen_expr(gen_expr, &tree_expr), preset); + } + + /* Minus is a prefix operator check */ + case tMinus: + if (*string == 0) { + + /* Use the negative infix operator, but first add an implicit zero to the operator tree */ + gen_expr = GenExpr::const_to_expr(0); + //return parse_gen_expr(fs, insert_gen_expr(gen_expr, &tree_expr), preset); + return parse_infix_op(fs, tNegative, insert_gen_expr(gen_expr, &tree_expr), preset); + } + + /* All the following cases are strings followed by an infix operator or terminal */ + case tRPr: + case tEOL: + case tEOF: + case tSemiColon: + case tComma: + + /* CASE 1 (terminal): string is empty, but not null. Not sure if this will actually happen + any more. */ + if (*string == 0) { + //if (PARSE_DEBUG) printf("parse_gen_expr: empty string coupled with terminal (LINE %d) \n", line_count); + return parse_infix_op(fs, token, tree_expr, preset); + + } + + default: + + /* CASE 0: Empty string, parse error */ + if (*string == 0) { + if (PARSE_DEBUG) { + DWRITE( "parse_gen_expr: empty string coupled with infix op (ERROR!) (LINE %d) \n", line_count); + + } + delete tree_expr; + return NULL; + } + + /* CASE 1: Check if string is a just a floating point number */ + if (string_to_float(string, &val) != PROJECTM_PARSE_ERROR) { + if ((gen_expr = GenExpr::const_to_expr(val)) == NULL) { + delete tree_expr; + return NULL; + } + + /* Parse the rest of the line */ + return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset); + + } + + + /* CASE 4: custom shape variable */ + if (current_shape != NULL) { + if ((param = ParamUtils::find(string, current_shape->param_tree)) == NULL) { + if ((param = preset->builtinParams.find_builtin_param(string)) == NULL) + if ((param = ParamUtils::find(string, current_shape->param_tree)) == NULL) { + delete tree_expr; + return NULL; + } + } + + if (PARSE_DEBUG) { + DWRITE( "parse_gen_expr: custom shape parameter (name = %s)... \n", param->name.c_str()); + + } + + /* Convert parameter to an expression */ + if ((gen_expr = GenExpr::param_to_expr(param)) == NULL) { + delete tree_expr; + return NULL; + } + + //if (PARSE_DEBUG) printf("converted to expression (LINE %d)\n", line_count); + + /* Parse the rest of the line */ + return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset); + } + + /* CASE 5: custom wave variable */ + if (current_wave != NULL) { + if ((param = ParamUtils::find(string, current_wave->param_tree)) == NULL) { + if ((param = preset->builtinParams.find_builtin_param(string)) == NULL) + if ((param = ParamUtils::find(string, current_wave->param_tree)) == NULL) { + delete tree_expr; + return NULL; + } + } + + if (PARSE_DEBUG) { + DWRITE("parse_gen_expr: custom wave parameter (name = %s)... \n", param->name.c_str()); + + } + + /* Convert parameter to an expression */ + if ((gen_expr = GenExpr::param_to_expr(param)) == NULL) { + delete tree_expr; + return NULL; + } + + if (PARSE_DEBUG) printf("converted to expression (LINE %d)\n", line_count); + + /* Parse the rest of the line */ + return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset); + + } + + /* CASE 6: regular parameter. Will be created if necessary and the string has no invalid characters */ + if ((param = ParamUtils::find(string, &preset->builtinParams, &preset->user_param_tree)) != NULL) { + + if (PARSE_DEBUG) { + DWRITE("parse_gen_expr: parameter (name = %s)...\n", param->name.c_str()); + + } + + /* Convert parameter to an expression */ + if ((gen_expr = GenExpr::param_to_expr(param)) == NULL) { + delete tree_expr; + return NULL; + } + + if (PARSE_DEBUG) printf("converted to expression (LINE %d)\n", line_count); + + /* Parse the rest of the line */ + return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset); + + } + + /* CASE 7: Bad string, give up */ + if (PARSE_DEBUG) { + DWRITE( "parse_gen_expr: syntax error [string = \"%s\"] (LINE %d)\n", string, line_count); + + } + delete tree_expr; + return NULL; + } +} + + + +/* Inserts expressions into tree according to operator precedence. + If root is null, a new tree is created, with gen_expr as only element */ + +TreeExpr * Parser::insert_infix_op(InfixOp * infix_op, TreeExpr **root) { + + TreeExpr * new_root; + + /* Sanity check */ + if (infix_op == NULL) + return NULL; + + /* The root is null, so make this operator + the new root */ + + if (*root == NULL) { + new_root = TreeExpr::new_tree_expr(infix_op, NULL, NULL, NULL); + *root = new_root; + return new_root; + } + + /* The root node is not an infix function, + so we make this infix operator the new root */ + + if ((*root)->infix_op == NULL) { + new_root = TreeExpr::new_tree_expr(infix_op, NULL, *root, NULL); + (*root) = new_root; + return new_root; + } + + /* The root is an infix function. If the precedence + of the item to be inserted is greater than the root's + precedence, then make gen_expr the root */ + + if (infix_op->precedence > (*root)->infix_op->precedence) { + new_root = TreeExpr::new_tree_expr(infix_op, NULL, *root, NULL); + (*root) = new_root; + return new_root; + } + + /* If control flow reaches here, use a recursive helper + with the knowledge that the root is higher precedence + than the item to be inserted */ + + insert_infix_rec(infix_op, *root); + return *root; + +} + + +TreeExpr * Parser::insert_gen_expr(GenExpr * gen_expr, TreeExpr ** root) { + + TreeExpr * new_root; + + /* If someone foolishly passes a null + pointer to insert, return the original tree */ + + if (gen_expr == NULL) { + return *root; + } + + /* If the root is null, generate a new expression tree, + using the passed expression as the root element */ + + if (*root == NULL) { + new_root = TreeExpr::new_tree_expr(NULL, gen_expr, NULL, NULL); + *root = new_root; + return new_root; + } + + + /* Otherwise. the new element definitely will not replace the current root. + Use a recursive helper function to do insertion */ + + insert_gen_rec(gen_expr, *root); + return *root; +} + +/* A recursive helper function to insert general expression elements into the operator tree */ +int Parser::insert_gen_rec(GenExpr * gen_expr, TreeExpr * root) { + + /* Trivial Case: root is null */ + + if (root == NULL) { + ////if (PARSE_DEBUG) printf("insert_gen_rec: root is null, returning failure\n"); + return PROJECTM_FAILURE; + } + + + /* The current node's left pointer is null, and this + current node is an infix operator, so insert the + general expression at the left pointer */ + + if ((root->left == NULL) && (root->infix_op != NULL)) { + root->left = TreeExpr::new_tree_expr(NULL, gen_expr, NULL, NULL); + return PROJECTM_SUCCESS; + } + + /* The current node's right pointer is null, and this + current node is an infix operator, so insert the + general expression at the right pointer */ + + if ((root->right == NULL) && (root->infix_op != NULL)) { + root->right = TreeExpr::new_tree_expr(NULL, gen_expr, NULL, NULL); + return PROJECTM_SUCCESS; + } + + /* Otherwise recurse down to the left. If + this succeeds then return. If it fails, try + recursing down to the right */ + + if (insert_gen_rec(gen_expr, root->left) == PROJECTM_FAILURE) + return insert_gen_rec(gen_expr, root->right); + + /* Impossible for control flow to reach here, but in + the world of C programming, who knows... */ + //if (PARSE_DEBUG) printf("insert_gen_rec: should never reach here!\n"); + return PROJECTM_FAILURE; +} + + +/* A recursive helper function to insert infix arguments by operator precedence */ +int Parser::insert_infix_rec(InfixOp * infix_op, TreeExpr * root) { + + /* Shouldn't happen, implies a parse error */ + + if (root == NULL) + return PROJECTM_FAILURE; + + /* Also shouldn't happen, also implies a (different) parse error */ + + if (root->infix_op == NULL) + return PROJECTM_FAILURE; + + /* Left tree is empty, attach this operator to it. + I don't think this will ever happen */ + if (root->left == NULL) { + root->left = TreeExpr::new_tree_expr(infix_op, NULL, root->left, NULL); + return PROJECTM_SUCCESS; + } + + /* Right tree is empty, attach this operator to it */ + if (root->right == NULL) { + root->right = TreeExpr::new_tree_expr(infix_op, NULL, root->right, NULL); + return PROJECTM_SUCCESS; + } + + /* The left element can now be ignored, since there is no way for this + operator to use those expressions */ + + /* If the right element is not an infix operator, + then insert the expression here, attaching the old right branch + to the left of the new expression */ + + if (root->right->infix_op == NULL) { + root->right = TreeExpr::new_tree_expr(infix_op, NULL, root->right, NULL); + return PROJECTM_SUCCESS; + } + + /* Traverse deeper if the inserting operator precedence is less than the + the root's right operator precedence */ + if (infix_op->precedence < root->right->infix_op->precedence) + return insert_infix_rec(infix_op, root->right); + + /* Otherwise, insert the operator here */ + + root->right = TreeExpr::new_tree_expr(infix_op, NULL, root->right, NULL); + return PROJECTM_SUCCESS; + +} + +/* Parses an infix operator */ +GenExpr * Parser::parse_infix_op(FILE * fs, token_t token, TreeExpr * tree_expr, Preset * preset) { + + GenExpr * gen_expr; + + switch (token) { + /* All the infix operators */ + case tPlus: + //if (PARSE_DEBUG) printf("parse_infix_op: found addition operator (LINE %d)\n", line_count); + return parse_gen_expr(fs, insert_infix_op(Eval::infix_add, &tree_expr), preset); + case tMinus: + //if (PARSE_DEBUG) printf("parse_infix_op: found subtraction operator (LINE %d)\n", line_count); + return parse_gen_expr(fs, insert_infix_op(Eval::infix_minus, &tree_expr), preset); + case tMult: + //if (PARSE_DEBUG) printf("parse_infix_op: found multiplication operator (LINE %d)\n", line_count); + return parse_gen_expr(fs, insert_infix_op(Eval::infix_mult, &tree_expr), preset); + case tDiv: + //if (PARSE_DEBUG) printf("parse_infix_op: found division operator (LINE %d)\n", line_count); + return parse_gen_expr(fs, insert_infix_op(Eval::infix_div, &tree_expr), preset); + case tMod: + //if (PARSE_DEBUG) printf("parse_infix_op: found modulo operator (LINE %d)\n", line_count); + return parse_gen_expr(fs, insert_infix_op(Eval::infix_mod, &tree_expr), preset); + case tOr: + //if (PARSE_DEBUG) printf("parse_infix_op: found bitwise or operator (LINE %d)\n", line_count); + return parse_gen_expr(fs, insert_infix_op(Eval::infix_or, &tree_expr), preset); + case tAnd: + //if (PARSE_DEBUG) printf("parse_infix_op: found bitwise and operator (LINE %d)\n", line_count); + return parse_gen_expr(fs, insert_infix_op(Eval::infix_and, &tree_expr), preset); + case tPositive: + //if (PARSE_DEBUG) printf("parse_infix_op: found positive operator (LINE %d)\n", line_count); + return parse_gen_expr(fs, insert_infix_op(Eval::infix_positive, &tree_expr), preset); + case tNegative: + //if (PARSE_DEBUG) printf("parse_infix_op: found negative operator (LINE %d)\n", line_count); + return parse_gen_expr(fs, insert_infix_op(Eval::infix_negative, &tree_expr), preset); + + case tEOL: + case tEOF: + case tSemiColon: + case tRPr: + case tComma: + //if (PARSE_DEBUG) printf("parse_infix_op: terminal found (LINE %d)\n", line_count); + gen_expr = GenExpr::new_gen_expr(TREE_T, (void*)tree_expr); + return gen_expr; + default: + //if (PARSE_DEBUG) printf("parse_infix_op: operator or terminal expected, but not found (LINE %d)\n", line_count); + delete tree_expr; + return NULL; + } + + /* Will never happen */ + return NULL; + +} + +/* Parses an integer, checks for +/- prefix */ +int Parser::parse_int(FILE * fs, int * int_ptr) { + +char string[MAX_TOKEN_SIZE]; + token_t token; + int sign; + char * end_ptr = " "; + + token = parseToken(fs, string); + + + switch (token) { + case tMinus: + sign = -1; + token = parseToken(fs, string); + break; + case tPlus: + sign = 1; + token = parseToken(fs, string); + break; + default: + sign = 1; + break; + } + + + if (string[0] == 0) + return PROJECTM_PARSE_ERROR; + + /* Convert the string to an integer. *end_ptr + should end up pointing to null terminator of 'string' + if the conversion was successful. */ + // printf("STRING: \"%s\"\n", string); + + (*int_ptr) = sign*strtol(string, &end_ptr, 10); + + /* If end pointer is a return character or null terminator, all is well */ + if ((*end_ptr == '\r') || (*end_ptr == '\0')) + return PROJECTM_SUCCESS; + + return PROJECTM_PARSE_ERROR; + +} +/* Parses a floating point number */ +int Parser::string_to_float(char * string, float * float_ptr) { + + char ** error_ptr; + + if (*string == 0) + return PROJECTM_PARSE_ERROR; + + error_ptr = (char**)wipemalloc(sizeof(char**)); + + (*float_ptr) = strtod(string, error_ptr); + + /* These imply a succesful parse of the string */ + if ((**error_ptr == '\0') || (**error_ptr == '\r')) { + free(error_ptr); + error_ptr = NULL; + return PROJECTM_SUCCESS; + } + + (*float_ptr) = 0; + free(error_ptr); + error_ptr = NULL; + return PROJECTM_PARSE_ERROR; +} + +/* Parses a floating point number */ +int Parser::parse_float(FILE * fs, float * float_ptr) { + + char string[MAX_TOKEN_SIZE]; + char ** error_ptr; + token_t token; + int sign; + + error_ptr =(char**) wipemalloc(sizeof(char**)); + + token = parseToken(fs, string); + + switch (token) { + case tMinus: + sign = -1; + token = parseToken(fs, string); + break; + case tPlus: + sign = 1; + token = parseToken(fs, string); + break; + default: + sign = 1; + } + + if (string[0] == 0) { + free(error_ptr); + error_ptr = NULL; + return PROJECTM_PARSE_ERROR; + } + + (*float_ptr) = sign*strtod(string, error_ptr); + + /* No conversion was performed */ + if ((**error_ptr == '\0') || (**error_ptr == '\r')) { + free(error_ptr); + error_ptr = NULL; + return PROJECTM_SUCCESS; + } + + //if (PARSE_DEBUG) printf("parse_float: float conversion failed for string \"%s\"\n", string); + + (*float_ptr) = 0; + free(error_ptr); + error_ptr = NULL; + return PROJECTM_PARSE_ERROR; + +} + +/* Parses a per frame equation. That is, interprets a stream of data as a per frame equation */ +PerFrameEqn * Parser::parse_per_frame_eqn(FILE * fs, int index, Preset * preset) { + + char string[MAX_TOKEN_SIZE]; + Param * param; + PerFrameEqn * per_frame_eqn; + GenExpr * gen_expr; + + if (parseToken(fs, string) != tEq) { + //if (PARSE_DEBUG) printf("parse_per_frame_eqn: no equal sign after string \"%s\" (LINE %d)\n", string, line_count); + return NULL; + } + + /* Find the parameter associated with the string, create one if necessary */ + if ((param = ParamUtils::find(string, &preset->builtinParams, &preset->user_param_tree)) == NULL) { + return NULL; + } + + /* Make sure parameter is writable */ + if (param->flags & P_FLAG_READONLY) { + //if (PARSE_DEBUG) printf("parse_per_frame_eqn: parameter %s is marked as read only (LINE %d)\n", param->name, line_count); + return NULL; + } + + /* Parse right side of equation as an expression */ + if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) { + //if (PARSE_DEBUG) printf("parse_per_frame_eqn: equation evaluated to null (LINE %d)\n", line_count); + return NULL; + } + + //if (PARSE_DEBUG) printf("parse_per_frame_eqn: finished per frame equation evaluation (LINE %d)\n", line_count); + + /* Create a new per frame equation */ + if ((per_frame_eqn = new PerFrameEqn(index, param, gen_expr)) == NULL) { + //if (PARSE_DEBUG) printf("parse_per_frame_eqn: failed to create a new per frame eqn, out of memory?\n"); + delete gen_expr; + return NULL; + } + + //if (PARSE_DEBUG) printf("parse_per_frame_eqn: per_frame eqn parsed succesfully\n"); + + return per_frame_eqn; +} + +/* Parses an 'implicit' per frame equation. That is, interprets a stream of data as a per frame equation without a prefix */ +PerFrameEqn * Parser::parse_implicit_per_frame_eqn(FILE * fs, char * param_string, int index, Preset * preset) { + + Param * param; + PerFrameEqn * per_frame_eqn; + GenExpr * gen_expr; + + if (fs == NULL) + return NULL; + if (param_string == NULL) + return NULL; + if (preset == NULL) + return NULL; + + //rintf("param string: %s\n", param_string); + /* Find the parameter associated with the string, create one if necessary */ + if ((param = ParamUtils::find(param_string, &preset->builtinParams, &preset->user_param_tree)) == NULL) { + return NULL; + } + + //printf("parse_implicit_per_frame_eqn: param is %s\n", param->name); + + /* Make sure parameter is writable */ + if (param->flags & P_FLAG_READONLY) { + //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: parameter %s is marked as read only (LINE %d)\n", param->name, line_count); + return NULL; + } + + /* Parse right side of equation as an expression */ + if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) { + //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: equation evaluated to null (LINE %d)\n", line_count); + return NULL; + } + + //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: finished per frame equation evaluation (LINE %d)\n", line_count); + + /* Create a new per frame equation */ + if ((per_frame_eqn = new PerFrameEqn(index, param, gen_expr)) == NULL) { + //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: failed to create a new per frame eqn, out of memory?\n"); + delete gen_expr; + return NULL; + } + + //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: per_frame eqn parsed succesfully\n"); + + return per_frame_eqn; +} + +/* Parses an initial condition */ +InitCond * Parser::parse_init_cond(FILE * fs, char * name, Preset * preset) { + + Param * param; + CValue init_val; + InitCond * init_cond; + + if (name == NULL) + return NULL; + if (preset == NULL) + return NULL; + + /* Search for the paramater in the database, creating it if necessary */ + if ((param = ParamUtils::find(name, &preset->builtinParams, &preset->user_param_tree)) == NULL) { + return NULL; + } + + //if (PARSE_DEBUG) printf("parse_init_cond: parameter = \"%s\" (LINE %d)\n", param->name, line_count); + + if (param->flags & P_FLAG_READONLY) { + //if (PARSE_DEBUG) printf("parse_init_cond: builtin parameter \"%s\" marked as read only!\n", param->name); + return NULL; + } + + /* At this point, a parameter has been created or was found + in the database. */ + + //if (PARSE_DEBUG) printf("parse_init_cond: parsing initial condition value... (LINE %d)\n", line_count); + + /* integer value (boolean is an integer in C) */ + if ((param->type == P_TYPE_INT) || (param->type == P_TYPE_BOOL)) { + if ((parse_int(fs, (int*)&init_val.int_val)) == PROJECTM_PARSE_ERROR) { + //if (PARSE_DEBUG) printf("parse_init_cond: error parsing integer!\n"); + return NULL; + } + } + + /* float value */ + else if (param->type == P_TYPE_DOUBLE) { + if ((parse_float(fs, (float*)&init_val.float_val)) == PROJECTM_PARSE_ERROR) { + //if (PARSE_DEBUG) printf("parse_init_cond: error parsing float!\n"); + return NULL; + } + } + + /* Unknown value */ + else { + //if (PARSE_DEBUG) printf("parse_init_cond: unknown parameter type!\n"); + return NULL; + } + + /* Create new initial condition */ + if ((init_cond = new InitCond(param, init_val)) == NULL) { + //if (PARSE_DEBUG) printf("parse_init_cond: new_init_cond failed!\n"); + return NULL; + } + + /* Finished */ + return init_cond; +} + +/* Parses a per frame init equation, not sure if this works right now */ +InitCond * Parser::parse_per_frame_init_eqn(FILE * fs, Preset * preset, std::map * database) { + + char name[MAX_TOKEN_SIZE]; + Param * param = NULL; + CValue init_val; + InitCond * init_cond; + GenExpr * gen_expr; + float val; + token_t token; + + + if (preset == NULL) + return NULL; + if (fs == NULL) + return NULL; + + if ((token = parseToken(fs, name)) != tEq) + return NULL; + + + /* If a database was specified,then use ParamUtils::find_db instead */ + if ((database != NULL) && ((param = ParamUtils::find(name, database)) == NULL)) { + return NULL; + } + + /* Otherwise use the builtin parameter and user databases. This is confusing. Sorry. */ + if ((param == NULL) && ((param = ParamUtils::find(name, &preset->builtinParams, &preset->user_param_tree)) == NULL)) { + return NULL; + } + + if (PARSE_DEBUG) printf("parse_per_frame_init_eqn: parameter = \"%s\" (LINE %d)\n", param->name.c_str(), line_count); + + if (param->flags & P_FLAG_READONLY) { + //if (PARSE_DEBUG) printf("pars_per_frame_init_eqn: builtin parameter \"%s\" marked as read only!\n", param->name); + return NULL; + } + + /* At this point, a parameter has been created or was found + in the database. */ + + if (PARSE_DEBUG) printf("parse_per_frame_init_eqn: parsing right hand side of per frame init equation.. (LINE %d)\n", line_count); + + if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) { + if (PARSE_DEBUG) printf("parse_per_frame_init_eqn: failed to parse general expresion!\n"); + return NULL; + } + + /* Compute initial condition value */ + val = gen_expr->eval_gen_expr(-1,-1); + + /* Free the general expression now that we are done with it */ + delete gen_expr; + + /* integer value (boolean is an integer in C) */ + if ((param->type == P_TYPE_INT) || (param->type == P_TYPE_BOOL)) { + init_val.int_val = (int)val; + } + + /* float value */ + else if (param->type == P_TYPE_DOUBLE) { + init_val.float_val = val; + } + + /* Unknown value */ + else { + if (PARSE_DEBUG) printf("pase_per_frame_init_eqn: unknown parameter type!\n"); + return NULL; + } + + + /* Create new initial condition */ + if ((init_cond = new InitCond(param, init_val)) == NULL) { + if (PARSE_DEBUG) printf("parse_per_frame_init_eqn: new_init_cond failed!\n"); + return NULL; + } + + + /* Finished */ + return init_cond; +} + +int Parser::parse_wavecode(char * token, FILE * fs, Preset * preset) { + + char * var_string; + InitCond * init_cond; + CustomWave * custom_wave; + int id; + CValue init_val; + Param * param; + + /* Null argument checks */ + if (preset == NULL) + return PROJECTM_FAILURE; + if (fs == NULL) + return PROJECTM_FAILURE; + if (token == NULL) + return PROJECTM_FAILURE; + + /* token should be in the form wavecode_N_var, such as wavecode_1_samples */ + + /* Get id and variable name from token string */ + if (parse_wavecode_prefix(token, &id, &var_string) < 0) + return PROJECTM_PARSE_ERROR; + + //if (PARSE_DEBUG) printf("parse_wavecode: wavecode id = %d, parameter = \"%s\"\n", id, var_string); + + /* Retrieve custom wave information from preset. The 3rd argument + if true creates a custom wave if one does not exist */ + if ((custom_wave = preset->find_custom_wave(id, TRUE)) == NULL) { + //if (PARSE_DEBUG) printf("parse_wavecode: failed to load (or create) custom wave (id = %d)!\n", id); + return PROJECTM_FAILURE; + } + //if (PARSE_DEBUG) printf("parse_wavecode: custom wave found (id = %d)\n", custom_wave->id); + + /* Retrieve parameter from this custom waves parameter db */ + if ((param = ParamUtils::find(var_string,custom_wave->param_tree)) == NULL) + return PROJECTM_FAILURE; + + //if (PARSE_DEBUG) printf("parse_wavecode: custom wave parameter found (name = %s)\n", param->name); + + /* integer value (boolean is an integer in C) */ + if ((param->type == P_TYPE_INT) || (param->type == P_TYPE_BOOL)) { + if ((parse_int(fs, (int*)&init_val.int_val)) == PROJECTM_PARSE_ERROR) { + //if (PARSE_DEBUG) printf("parse_wavecode: error parsing integer!\n"); + return PROJECTM_PARSE_ERROR; + } + } + + /* float value */ + else if (param->type == P_TYPE_DOUBLE) { + if ((parse_float(fs, (float*)&init_val.float_val)) == PROJECTM_PARSE_ERROR) { + //if (PARSE_DEBUG) printf("parse_wavecode: error parsing float!\n"); + return PROJECTM_PARSE_ERROR; + } + } + + /* Unknown value */ + else { + //if (PARSE_DEBUG) printf("parse_wavecode: unknown parameter type!\n"); + return PROJECTM_PARSE_ERROR; + } + + /* Create new initial condition */ + if ((init_cond = new InitCond(param, init_val)) == NULL) { + //if (PARSE_DEBUG) printf("parse_wavecode: new_init_cond failed!\n"); + return PROJECTM_FAILURE; + } + + custom_wave->init_cond_tree.insert(std::make_pair(param->name, init_cond)); + + line_mode = CUSTOM_WAVE_WAVECODE_LINE_MODE; + + //if (PARSE_DEBUG) printf("parse_wavecode: [success]\n"); + return PROJECTM_SUCCESS; +} + +int Parser::parse_shapecode(char * token, FILE * fs, Preset * preset) { + + char * var_string; + InitCond * init_cond; + CustomShape * custom_shape; + int id; + CValue init_val; + Param * param; + + /* Null argument checks */ + if (preset == NULL) + return PROJECTM_FAILURE; + if (fs == NULL) + return PROJECTM_FAILURE; + if (token == NULL) + return PROJECTM_FAILURE; + + /* token should be in the form shapecode_N_var, such as shapecode_1_samples */ + + /* Get id and variable name from token string */ + if (parse_shapecode_prefix(token, &id, &var_string) < 0) + return PROJECTM_PARSE_ERROR; + + last_custom_shape_id = id; + + //if (PARSE_DEBUG) printf("parse_shapecode: shapecode id = %d, parameter = \"%s\"\n", id, var_string); + + /* Retrieve custom shape information from preset. The 3rd argument + if true creates a custom shape if one does not exist */ + + if ((custom_shape = preset->find_custom_shape(id, TRUE)) == NULL) { + //if (PARSE_DEBUG) printf("parse_shapecode: failed to load (or create) custom shape (id = %d)!\n", id); + return PROJECTM_FAILURE; + } + //if (PARSE_DEBUG) printf("parse_shapecode: custom shape found (id = %d)\n", custom_shape->id); + + /* Retrieve parameter from this custom shapes parameter db */ + + + if ((param = ParamUtils::find(var_string, custom_shape->param_tree)) == NULL) { + //if (PARSE_DEBUG) printf("parse_shapecode: failed to create parameter.\n"); + return PROJECTM_FAILURE; + } + //if (PARSE_DEBUG) printf("parse_shapecode: custom shape parameter found (name = %s)\n", param->name); + + /* integer value (boolean is an integer in C) */ + if ((param->type == P_TYPE_INT) || (param->type == P_TYPE_BOOL)) { + if ((parse_int(fs, (int*)&init_val.int_val)) == PROJECTM_PARSE_ERROR) { + //if (PARSE_DEBUG) printf("parse_shapecode: error parsing integer!\n"); + return PROJECTM_PARSE_ERROR; + } + } + + /* float value */ + else if (param->type == P_TYPE_DOUBLE) { + if ((parse_float(fs, (float*)&init_val.float_val)) == PROJECTM_PARSE_ERROR) { + //if (PARSE_DEBUG) printf("parse_shapecode: error parsing float!\n"); + return PROJECTM_PARSE_ERROR; + } + } + + /* Unknown value */ + else { + //if (PARSE_DEBUG) printf("parse_shapecode: unknown parameter type!\n"); + return PROJECTM_PARSE_ERROR; + } + + /* Create new initial condition */ + if ((init_cond = new InitCond(param, init_val)) == NULL) { + //if (PARSE_DEBUG) printf("parse_shapecode: new_init_cond failed!\n"); + return PROJECTM_FAILURE; + } + + custom_shape->init_cond_tree.insert(std::make_pair(param->name,init_cond)); + line_mode = CUSTOM_SHAPE_SHAPECODE_LINE_MODE; + + //if (PARSE_DEBUG) printf("parse_shapecode: [success]\n"); + return PROJECTM_SUCCESS; +} + + +int Parser::parse_wavecode_prefix(char * token, int * id, char ** var_string) { + + int len, i, j; + + if (token == NULL) + return PROJECTM_FAILURE; + /* + if (*var_string == NULL) + return PROJECTM_FAILURE; + */ + if (id == NULL) + return PROJECTM_FAILURE; + + len = strlen(token); + + /* Move pointer passed "wavecode_" prefix */ + if (len <= WAVECODE_STRING_LENGTH) + return PROJECTM_FAILURE; + i = WAVECODE_STRING_LENGTH; + j = 0; + (*id) = 0; + + /* This loop grabs the integer id for this custom wave */ + while ((i < len) && (token[i] >= 48) && (token[i] <= 57)) { + if (j >= MAX_TOKEN_SIZE) + return PROJECTM_FAILURE; + + (*id) = 10*(*id) + (token[i]-48); + j++; + i++; + } + + + if (i > (len - 2)) + return PROJECTM_FAILURE; + + *var_string = token + i + 1; + + return PROJECTM_SUCCESS; + +} + + +int Parser::parse_shapecode_prefix(char * token, int * id, char ** var_string) { + + int len, i, j; + + if (token == NULL) + return PROJECTM_FAILURE; + /* + if (*var_string == NULL) + return PROJECTM_FAILURE; + */ + if (id == NULL) + return PROJECTM_FAILURE; + + len = strlen(token); + + /* Move pointer passed "shapecode_" prefix */ + if (len <= SHAPECODE_STRING_LENGTH) + return PROJECTM_FAILURE; + i = SHAPECODE_STRING_LENGTH; + j = 0; + (*id) = 0; + + /* This loop grabs the integer id for this custom shape */ + while ((i < len) && (token[i] >= 48) && (token[i] <= 57)) { + if (j >= MAX_TOKEN_SIZE) + return PROJECTM_FAILURE; + + (*id) = 10*(*id) + (token[i]-48); + j++; + i++; + } + + + if (i > (len - 2)) + return PROJECTM_FAILURE; + + *var_string = token + i + 1; + + return PROJECTM_SUCCESS; + +} + +int Parser::parse_wave_prefix(char * token, int * id, char ** eqn_string) { + + int len, i, j; + + if (token == NULL) + return PROJECTM_FAILURE; + if (eqn_string == NULL) + return PROJECTM_FAILURE; + if (id == NULL) + return PROJECTM_FAILURE; + + len = strlen(token); + + if (len <= WAVE_STRING_LENGTH) + return PROJECTM_FAILURE; + + + i = WAVE_STRING_LENGTH; + j = 0; + (*id) = 0; + + /* This loop grabs the integer id for this custom wave */ + while ((i < len) && (token[i] >= 48) && (token[i] <= 57)) { + if (j >= MAX_TOKEN_SIZE) + return PROJECTM_FAILURE; + + (*id) = 10*(*id) + (token[i]-48); + j++; + i++; + } + + if (i > (len - 2)) + return PROJECTM_FAILURE; + + *eqn_string = token + i + 1; + + if (PARSE_DEBUG) printf("parse_wave_prefix: prefix = %s\n (LINE %d)", *eqn_string, line_count); + return PROJECTM_SUCCESS; + +} + +int Parser::parse_shape_prefix(char * token, int * id, char ** eqn_string) { + + int len, i, j; + + if (token == NULL) + return PROJECTM_FAILURE; + if (eqn_string == NULL) + return PROJECTM_FAILURE; + if (id == NULL) + return PROJECTM_FAILURE; + + len = strlen(token); + + if (len <= SHAPE_STRING_LENGTH) + return PROJECTM_FAILURE; + + + i = SHAPE_STRING_LENGTH; + j = 0; + (*id) = 0; + + /* This loop grabs the integer id for this custom wave */ + while ((i < len) && (token[i] >= 48) && (token[i] <= 57)) { + if (j >= MAX_TOKEN_SIZE) + return PROJECTM_FAILURE; + + (*id) = 10*(*id) + (token[i]-48); + j++; + i++; + } + + if (i > (len - 2)) + return PROJECTM_FAILURE; + + *eqn_string = token + i + 1; + + return PROJECTM_SUCCESS; + +} + +/* Parses custom wave equations */ +int Parser::parse_wave(char * token, FILE * fs, Preset * preset) { + + int id; + char * eqn_type; + + if (PARSE_DEBUG) printf("parse_wave:begin\n"); + + if (token == NULL) + return PROJECTM_FAILURE; + if (fs == NULL) + return PROJECTM_FAILURE; + if (preset == NULL) + return PROJECTM_FAILURE; + + /* Grab custom wave id and equation type (per frame or per point) from string token */ + if (parse_wave_prefix(token, &id, &eqn_type) < 0) { + if (PARSE_DEBUG) printf("parse_wave: syntax error in custom wave prefix!\n"); + return PROJECTM_FAILURE; + } + + int last_custom_wave_id = id; + strncpy(last_eqn_type, eqn_type, MAX_TOKEN_SIZE); + + return parse_wave_helper(fs, preset, id, eqn_type, 0); + +} + +int Parser::parse_wave_helper(FILE * fs, Preset * preset, int id, char * eqn_type, char * init_string) { + + Param * param; + GenExpr * gen_expr; + char string[MAX_TOKEN_SIZE]; + PerFrameEqn * per_frame_eqn; + CustomWave * custom_wave; + InitCond * init_cond; + + /* Retrieve custom wave associated with this id */ + if ((custom_wave = preset->find_custom_wave(id, TRUE)) == NULL) { + if (PARSE_DEBUG) printf("parse_wave_helper: custom wave id %d not found!\n", id); + return PROJECTM_FAILURE; + } + + /* per frame init equation case */ + if (!strncmp(eqn_type, WAVE_INIT_STRING, WAVE_INIT_STRING_LENGTH)) { + + if (PARSE_DEBUG) printf("parse_wave_helper (per frame init): [begin] (LINE %d)\n", line_count); + + /* Parse the per frame init equation */ + if ((init_cond = parse_per_frame_init_eqn(fs, preset, custom_wave->param_tree)) == NULL) { + if (PARSE_DEBUG) printf("parse_wave_helper (per frame init): equation parsing failed (LINE %d)\n", line_count); + return PROJECTM_PARSE_ERROR; + } + + /* Insert the equation in the per frame equation tree */ + custom_wave->per_frame_init_eqn_tree.insert(std::make_pair(init_cond->param->name,init_cond)); + + if (update_string_buffer(custom_wave->per_frame_init_eqn_string_buffer, + &custom_wave->per_frame_init_eqn_string_index) < 0) { + if (PARSE_DEBUG) printf("parse_wave_helper: failed to update string buffer (LINE %d)\n", line_count); + return PROJECTM_FAILURE; + } + line_mode = CUSTOM_WAVE_PER_FRAME_INIT_LINE_MODE; + + return PROJECTM_SUCCESS; + + } + + /* per frame equation case */ + if (!strncmp(eqn_type, PER_FRAME_STRING_NO_UNDERSCORE, PER_FRAME_STRING_NO_UNDERSCORE_LENGTH)) { + + if (PARSE_DEBUG) printf("parse_wave_helper (per_frame): [start] (custom wave id = %d)\n", custom_wave->id); + + if (parseToken(fs, string) != tEq) { + //if (PARSE_DEBUG) printf("parse_wave (per_frame): no equal sign after string \"%s\" (LINE %d)\n", string, line_count); + return PROJECTM_PARSE_ERROR; + } + + /* Find the parameter associated with the string in the custom wave database */ + if ((param = ParamUtils::find(string, custom_wave->param_tree)) == NULL) { + //if (PARSE_DEBUG) printf("parse_wave (per_frame): parameter \"%s\" not found or cannot be wipemalloc'ed!!\n", string); + return PROJECTM_FAILURE; + } + + + /* Make sure parameter is writable */ + if (param->flags & P_FLAG_READONLY) { + //if (PARSE_DEBUG) printf("parse_wave (per_frame): parameter %s is marked as read only (LINE %d)\n", param->name, line_count); + return PROJECTM_FAILURE; + } + + /* Parse right side of equation as an expression */ + + current_wave = custom_wave; + if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) { + //if (PARSE_DEBUG) printf("parse_wave (per_frame): equation evaluated to null (LINE %d)\n", line_count); + current_wave = NULL; + return PROJECTM_PARSE_ERROR; + + } + + current_wave = NULL; + + //if (PARSE_DEBUG) printf("parse_wave (per_frame): [finished parsing equation] (LINE %d)\n", line_count); + + /* Create a new per frame equation */ + if ((per_frame_eqn = new PerFrameEqn(custom_wave->per_frame_count++, param, gen_expr)) == NULL) { + //if (PARSE_DEBUG) printf("parse_wave (per_frame): failed to create a new per frame eqn, out of memory?\n"); + delete gen_expr; + return PROJECTM_FAILURE; + } + + custom_wave->per_frame_eqn_tree.insert(std::make_pair(per_frame_eqn->index, per_frame_eqn)); + //if (PARSE_DEBUG) printf("parse_wave (per_frame): equation %d associated with custom wave %d [success]\n", + // per_frame_eqn->index, custom_wave->id); + + + /* Need to add stuff to string buffer so the editor can read the equations. + Why not make a nice little helper function for this? - here it is: */ + + if (update_string_buffer(custom_wave->per_frame_eqn_string_buffer, &custom_wave->per_frame_eqn_string_index) < 0) + return PROJECTM_FAILURE; + + line_mode = CUSTOM_WAVE_PER_FRAME_LINE_MODE; + return PROJECTM_SUCCESS; + } + + + /* per point equation case */ + if (!strncmp(eqn_type, PER_POINT_STRING, PER_POINT_STRING_LENGTH)) { + + if (PARSE_DEBUG) printf("parse_wave_helper (per_point): per_pixel equation parsing start...(LINE %d)\n", line_count); + + /// HACK the parse_line code already parsed the per_pixel variable name. This handles that case + /// Parser needs reworked. Don't have time for it. So this is the result. + if (init_string) + strncpy(string, init_string, strlen(init_string)); + else { + if (parseToken(fs, string) != tEq) { /* parse per pixel operator name */ + if (PARSE_DEBUG) printf("parse_wave_helper (per_point): equal operator missing after per pixel operator. Last token = \"%s\" (LINE %d)\n", string, line_count); + + return PROJECTM_PARSE_ERROR; + } + } + + /* Parse right side of equation as an expression, First tell parser we are parsing a custom wave */ + current_wave = custom_wave; + if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) { + if (PARSE_DEBUG) printf("parse_wave_helper (per_point): equation evaluated to null? (LINE %d)\n", line_count); + + return PROJECTM_PARSE_ERROR; + } + + + /* Add the per point equation */ + if (custom_wave->add_per_point_eqn(string, gen_expr) < 0) { + delete gen_expr; + + return PROJECTM_PARSE_ERROR; + } + // This tells the parser we are no longer parsing a custom wave + current_wave = NULL; + + if (update_string_buffer(custom_wave->per_point_eqn_string_buffer, &custom_wave->per_point_eqn_string_index) < 0) + return PROJECTM_FAILURE; + + line_mode = CUSTOM_WAVE_PER_POINT_LINE_MODE; + if (PARSE_DEBUG) printf("parse_wave_helper (per_point): [finished] (custom wave id = %d)\n", custom_wave->id); + return PROJECTM_SUCCESS; + } + + return PROJECTM_FAILURE; +} + +/* Parses custom shape equations */ +int Parser::parse_shape(char * token, FILE * fs, Preset * preset) { + + int id; + char * eqn_type; + char string[MAX_TOKEN_SIZE]; + CustomShape * custom_shape; + InitCond * init_cond; + + if (token == NULL) + + return PROJECTM_FAILURE; + if (fs == NULL) + return PROJECTM_FAILURE; + if (preset == NULL) + return PROJECTM_FAILURE; + + /* Grab custom shape id and equation type (per frame or per point) from string token */ + if (parse_shape_prefix(token, &id, &eqn_type) < 0) { + //if (PARSE_DEBUG) printf("parse_shape: syntax error in custom shape prefix!\n"); + return PROJECTM_PARSE_ERROR; + } + + /* Retrieve custom shape associated with this id */ + if ((custom_shape = preset->find_custom_shape(id, TRUE)) == NULL) + return PROJECTM_FAILURE; + + + /* per frame init equation case */ + if (!strncmp(eqn_type, SHAPE_INIT_STRING, SHAPE_INIT_STRING_LENGTH)) { + return parse_shape_per_frame_init_eqn(fs, custom_shape, preset); + } + + /* per frame equation case */ + if (!strncmp(eqn_type, PER_FRAME_STRING_NO_UNDERSCORE, PER_FRAME_STRING_NO_UNDERSCORE_LENGTH)) { + return parse_shape_per_frame_eqn(fs, custom_shape, preset); + } + + + /* Syntax error, return parse error */ + return PROJECTM_PARSE_ERROR; +} + +/* Helper function to update the string buffers used by the editor */ +int Parser::update_string_buffer(char * buffer, int * index) { + + int string_length; + int skip_size; + + if (!buffer) + return PROJECTM_FAILURE; + if (!index) + return PROJECTM_FAILURE; + + + /* If the string line buffer used by the parser is already full then quit */ + if (string_line_buffer_index == (STRING_LINE_SIZE-1)) + return PROJECTM_FAILURE; + + if ((skip_size = get_string_prefix_len(string_line_buffer)) == PROJECTM_FAILURE) + return PROJECTM_FAILURE; + + string_line_buffer[string_line_buffer_index++] = '\n'; + + // string_length = strlen(string_line_buffer + strlen(eqn_string)+1); + if (skip_size >= STRING_LINE_SIZE) + return PROJECTM_FAILURE; + + string_length = strlen(string_line_buffer + skip_size); + + if (skip_size > (STRING_LINE_SIZE-1)) + return PROJECTM_FAILURE; + + /* Add line to string buffer */ + strncpy(buffer + (*index), + string_line_buffer + skip_size, string_length); + + /* Buffer full, quit */ + if ((*index) > (STRING_BUFFER_SIZE - 1)) { + //if (PARSE_DEBUG) printf("update_string_buffer: string buffer full!\n"); + return PROJECTM_FAILURE; + } + + /* Otherwise, increment string index by the added string length */ + (*index)+=string_length; + + return PROJECTM_SUCCESS; + +} + + +/* Helper function: returns the length of the prefix portion in the line + buffer (the passed string here). In other words, given + the string 'per_frame_1 = x = ....', return the length of 'per_frame_1 = ' + Returns -1 if syntax error +*/ + +int Parser::get_string_prefix_len(char * string) { + + int i = 0; + + /* Null argument check */ + if (string == NULL) + return PROJECTM_FAILURE; + + /* First find the equal sign */ + while (string[i] != '=') { + if (string[i] == 0) + return PROJECTM_FAILURE; + i++; + } + + /* If the string already ends at the next char then give up */ + if (string[i+1] == 0) + return PROJECTM_FAILURE; + + /* Move past the equal sign */ + i++; + + /* Now found the start of the LHS variable, ie skip the spaces */ + while(string[i] == ' ') { + i++; + } + + /* If this is the end of the string then its a syntax error */ + if (string[i] == 0) + return PROJECTM_FAILURE; + + /* Finished succesfully, return the length */ + return i; +} + +int Parser::parse_shape_per_frame_init_eqn(FILE * fs, CustomShape * custom_shape, Preset * preset) { + InitCond * init_cond; + + //if (PARSE_DEBUG) printf("parse_shape (per frame init): [begin] (LINE %d)\n", line_count); + + /* Parse the per frame equation */ + if ((init_cond = parse_per_frame_init_eqn(fs, preset, custom_shape->param_tree)) == NULL) { + //if (PARSE_DEBUG) printf("parse_shape (per frame init): equation parsing failed (LINE %d)\n", line_count); + return PROJECTM_PARSE_ERROR; + } + + /* Insert the equation in the per frame equation tree */ + custom_shape->per_frame_init_eqn_tree.insert(std::make_pair(init_cond->param->name,init_cond)); + if (update_string_buffer(custom_shape->per_frame_init_eqn_string_buffer, + &custom_shape->per_frame_init_eqn_string_index) < 0) + return PROJECTM_FAILURE; + + line_mode = CUSTOM_SHAPE_PER_FRAME_INIT_LINE_MODE; + return PROJECTM_SUCCESS; + } + +int Parser::parse_shape_per_frame_eqn(FILE * fs, CustomShape * custom_shape, Preset * preset) { + +Param * param; +GenExpr * gen_expr; +PerFrameEqn * per_frame_eqn; + +char string[MAX_TOKEN_SIZE]; + +//if (PARSE_DEBUG) printf("parse_shape (per_frame): [start] (custom shape id = %d)\n", custom_shape->id); + + if (parseToken(fs, string) != tEq) { + //if (PARSE_DEBUG) printf("parse_shape (per_frame): no equal sign after string \"%s\" (LINE %d)\n", string, line_count); + return PROJECTM_PARSE_ERROR; + } + + /* Find the parameter associated with the string in the custom shape database */ + if ((param = ParamUtils::find(string, custom_shape->param_tree)) == NULL) { + //if (PARSE_DEBUG) printf("parse_shape (per_frame): parameter \"%s\" not found or cannot be wipemalloc'ed!!\n", string); + return PROJECTM_FAILURE; + } + + + /* Make sure parameter is writable */ + if (param->flags & P_FLAG_READONLY) { + //if (PARSE_DEBUG) printf("parse_shape (per_frame): parameter %s is marked as read only (LINE %d)\n", param->name, line_count); + return PROJECTM_FAILURE; + } + + /* Parse right side of equation as an expression */ + + current_shape = custom_shape; + if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) { + //if (PARSE_DEBUG) printf("parse_shape (per_frame): equation evaluated to null (LINE %d)\n", line_count); + current_shape = NULL; + return PROJECTM_PARSE_ERROR; + } + + current_shape = NULL; + + //if (PARSE_DEBUG) printf("parse_shape (per_frame): [finished parsing equation] (LINE %d)\n", line_count); + + /* Create a new per frame equation */ + if ((per_frame_eqn = new PerFrameEqn(custom_shape->per_frame_count++, param, gen_expr)) == NULL) { + //if (PARSE_DEBUG) printf("parse_shape (per_frame): failed to create a new per frame eqn, out of memory?\n"); + delete gen_expr; + return PROJECTM_FAILURE; + } + + custom_shape->per_frame_eqn_tree.insert(std::make_pair(per_frame_eqn->index, per_frame_eqn)); + + /* Need to add stuff to string buffer so the editor can read the equations. + Why not make a nice little helper function for this? - here it is: */ + + if (update_string_buffer(custom_shape->per_frame_eqn_string_buffer, &custom_shape->per_frame_eqn_string_index) < 0) + return PROJECTM_FAILURE; + + line_mode = CUSTOM_SHAPE_PER_FRAME_LINE_MODE; + return PROJECTM_SUCCESS; +} + +int Parser::parse_wave_per_frame_eqn(FILE * fs, CustomWave * custom_wave, Preset * preset) { + +Param * param; +GenExpr * gen_expr; +PerFrameEqn * per_frame_eqn; + +char string[MAX_TOKEN_SIZE]; + +//if (PARSE_DEBUG) printf("parse_shape (per_frame): [start] (custom shape id = %d)\n", custom_shape->id); + + if (parseToken(fs, string) != tEq) { + //if (PARSE_DEBUG) printf("parse_shape (per_frame): no equal sign after string \"%s\" (LINE %d)\n", string, line_count); + return PROJECTM_PARSE_ERROR; + } + + /* Find the parameter associated with the string in the custom shape database */ + if ((param = ParamUtils::find(string, custom_wave->param_tree)) == NULL) { + //if (PARSE_DEBUG) printf("parse_shape (per_frame): parameter \"%s\" not found or cannot be wipemalloc'ed!!\n", string); + return PROJECTM_FAILURE; + } + + + /* Make sure parameter is writable */ + if (param->flags & P_FLAG_READONLY) { + //if (PARSE_DEBUG) printf("parse_shape (per_frame): parameter %s is marked as read only (LINE %d)\n", param->name, line_count); + return PROJECTM_FAILURE; + } + + /* Parse right side of equation as an expression */ + + current_wave = custom_wave; + if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) { + //if (PARSE_DEBUG) printf("parse_shape (per_frame): equation evaluated to null (LINE %d)\n", line_count); + current_wave = NULL; + return PROJECTM_PARSE_ERROR; + } + + current_wave = NULL; + + //if (PARSE_DEBUG) printf("parse_shape (per_frame): [finished parsing equation] (LINE %d)\n", line_count); + + /* Create a new per frame equation */ + if ((per_frame_eqn = new PerFrameEqn(custom_wave->per_frame_count++, param, gen_expr)) == NULL) { + //if (PARSE_DEBUG) printf("parse_shape (per_frame): failed to create a new per frame eqn, out of memory?\n"); + delete gen_expr; + return PROJECTM_FAILURE; + } + + custom_wave->per_frame_eqn_tree.insert(std::make_pair(per_frame_eqn->index, per_frame_eqn)); + //if (PARSE_DEBUG) printf("parse_shape (per_frame): equation %d associated with custom shape %d [success]\n", + // per_frame_eqn->index, custom_shape->id); + + + /* Need to add stuff to string buffer so the editor can read the equations. + Why not make a nice little helper function for this? - here it is: */ + + if (update_string_buffer(custom_wave->per_frame_eqn_string_buffer, &custom_wave->per_frame_eqn_string_index) < 0) + return PROJECTM_FAILURE; + + line_mode = CUSTOM_WAVE_PER_FRAME_LINE_MODE; + return PROJECTM_SUCCESS; +} diff --git a/src/projectM-engine-backup/Parser.hpp b/src/projectM-engine-backup/Parser.hpp new file mode 100755 index 000000000..3a5b248f6 --- /dev/null +++ b/src/projectM-engine-backup/Parser.hpp @@ -0,0 +1,180 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Preset parser + * + * $Log$ + */ + +#ifndef _PARSER_H +#define _PARSER_H + +//#define PARSE_DEBUG 2 +#define PARSE_DEBUG 2 + +#include + +#include "Expr.hpp" +#include "PerFrameEqn.hpp" +#include "InitCond.hpp" +#include "Preset.hpp" + +/* Strings that prefix (and denote the type of) equations */ +#define PER_FRAME_STRING "per_frame_" +#define PER_FRAME_STRING_LENGTH 10 + +#define PER_PIXEL_STRING "per_pixel_" +#define PER_PIXEL_STRING_LENGTH 10 + +#define PER_FRAME_INIT_STRING "per_frame_init_" +#define PER_FRAME_INIT_STRING_LENGTH 15 + +#define WAVECODE_STRING "wavecode_" +#define WAVECODE_STRING_LENGTH 9 + +#define WAVE_STRING "wave_" +#define WAVE_STRING_LENGTH 5 + +#define PER_POINT_STRING "per_point" +#define PER_POINT_STRING_LENGTH 9 + +#define PER_FRAME_STRING_NO_UNDERSCORE "per_frame" +#define PER_FRAME_STRING_NO_UNDERSCORE_LENGTH 9 + +#define SHAPECODE_STRING "shapecode_" +#define SHAPECODE_STRING_LENGTH 10 + +#define SHAPE_STRING "shape_" +#define SHAPE_STRING_LENGTH 6 + +#define SHAPE_INIT_STRING "init" +#define SHAPE_INIT_STRING_LENGTH 4 + +#define WAVE_INIT_STRING "init" +#define WAVE_INIT_STRING_LENGTH 4 + +typedef enum { + NORMAL_LINE_MODE, + PER_FRAME_LINE_MODE, + PER_PIXEL_LINE_MODE, + PER_FRAME_INIT_LINE_MODE, + INIT_COND_LINE_MODE, + CUSTOM_WAVE_PER_POINT_LINE_MODE, + CUSTOM_WAVE_PER_FRAME_LINE_MODE, + CUSTOM_WAVE_WAVECODE_LINE_MODE, + CUSTOM_SHAPE_SHAPECODE_LINE_MODE, + CUSTOM_SHAPE_PER_FRAME_LINE_MODE, + CUSTOM_SHAPE_PER_FRAME_INIT_LINE_MODE, + CUSTOM_WAVE_PER_FRAME_INIT_LINE_MODE +} line_mode_t; + +/** Token enumeration type */ +typedef enum { + tEOL, /* end of a line, usually a '/n' or '/r' */ + tEOF, /* end of file */ + tLPr, /* ( */ + tRPr, /* ) */ + tLBr, /* [ */ + tRBr, /* ] */ + tEq, /* = */ + tPlus, /* + */ + tMinus, /* - */ + tMult, /* * */ + tMod, /* % */ + tDiv, /* / */ + tOr, /* | */ + tAnd, /* & */ + tComma, /* , */ + tPositive, /* + as a prefix operator */ + tNegative, /* - as a prefix operator */ + tSemiColon, /* ; */ + tStringTooLong, /* special token to indicate an invalid string length */ + tStringBufferFilled /* the string buffer for this line is maxed out */ + } token_t; + +class CustomShape; +class CustomWave; +class GenExpr; +class InfixOp; +class PerFrameEqn; +class Preset; +class TreeExpr; + +class Parser { +public: + static line_mode_t line_mode; + static CustomWave *current_wave; + static CustomShape *current_shape; + static int string_line_buffer_index; + static char string_line_buffer[STRING_LINE_SIZE]; + static unsigned int line_count; + static int per_frame_eqn_count; + static int per_frame_init_eqn_count; + static int last_custom_wave_id; + static int last_custom_shape_id; + static char last_eqn_type[MAX_TOKEN_SIZE]; + static int last_token_size; + + static PerFrameEqn *parse_per_frame_eqn( FILE * fs, int index, + Preset * preset); + static int parse_per_pixel_eqn( FILE * fs, Preset * preset, + char * init_string); + static InitCond *parse_init_cond( FILE * fs, char * name, Preset * preset ); + static int parse_preset_name( FILE * fs, char * name ); + static int parse_top_comment( FILE * fs ); + static int parse_line( FILE * fs, Preset * preset ); + + static int get_string_prefix_len(char * string); + static TreeExpr * insert_gen_expr(GenExpr * gen_expr, TreeExpr ** root); + static TreeExpr * insert_infix_op(InfixOp * infix_op, TreeExpr ** root); + static token_t parseToken(FILE * fs, char * string); + static GenExpr ** parse_prefix_args(FILE * fs, int num_args, Preset * preset); + static GenExpr * parse_infix_op(FILE * fs, token_t token, TreeExpr * tree_expr, Preset * preset); + static GenExpr * parse_sign_arg(FILE * fs); + static int parse_float(FILE * fs, float * float_ptr); + static int parse_int(FILE * fs, int * int_ptr); + static int insert_gen_rec(GenExpr * gen_expr, TreeExpr * root); + static int insert_infix_rec(InfixOp * infix_op, TreeExpr * root); + static GenExpr * parse_gen_expr(FILE * fs, TreeExpr * tree_expr, Preset * preset); + static PerFrameEqn * parse_implicit_per_frame_eqn(FILE * fs, char * param_string, int index, Preset * preset); + static InitCond * parse_per_frame_init_eqn(FILE * fs, Preset * preset, std::map * database); + static int parse_wavecode_prefix(char * token, int * id, char ** var_string); + static int parse_wavecode(char * token, FILE * fs, Preset * preset); + static int parse_wave_prefix(char * token, int * id, char ** eqn_string); + static int parse_wave_helper(FILE * fs, Preset * preset, int id, char * eqn_type, char * init_string); + static int parse_shapecode(char * eqn_string, FILE * fs, Preset * preset); + static int parse_shapecode_prefix(char * token, int * id, char ** var_string); + + static int parse_wave(char * eqn_string, FILE * fs, Preset * preset); + static int parse_shape(char * eqn_string, FILE * fs, Preset * preset); + static int parse_shape_prefix(char * token, int * id, char ** eqn_string); + + static int update_string_buffer(char * buffer, int * index); + static int string_to_float(char * string, float * float_ptr); + static int parse_shape_per_frame_init_eqn(FILE * fs, CustomShape * custom_shape, Preset * preset); + static int parse_shape_per_frame_eqn(FILE * fs, CustomShape * custom_shape, Preset * preset); + static int parse_wave_per_frame_eqn(FILE * fs, CustomWave * custom_wave, Preset * preset); + }; + +#endif /** !_PARSER_H */ + diff --git a/src/projectM-engine-backup/PerFrameEqn.cpp b/src/projectM-engine-backup/PerFrameEqn.cpp new file mode 100755 index 000000000..592b7b343 --- /dev/null +++ b/src/projectM-engine-backup/PerFrameEqn.cpp @@ -0,0 +1,65 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include +#include +#include + +#include "fatal.h" +#include "Common.hpp" + +#include "Param.hpp" +#include "PerFrameEqn.hpp" + +#include "Eval.hpp" +#include "Expr.hpp" + +#include "wipemalloc.h" +#include + +/* Evaluate an equation */ +void PerFrameEqn::evaluate() { + + if (PER_FRAME_EQN_DEBUG) { + printf("per_frame_%d=%s= ", index, param->name.c_str()); + fflush(stdout); + } + + //*((float*)per_frame_eqn->param->engine_val) = eval_gen_expr(per_frame_eqn->gen_expr); + assert(gen_expr); + assert(param); + param->set_param(gen_expr->eval_gen_expr(-1,-1)); + if (PER_FRAME_EQN_DEBUG) printf(" = %.4f\n", *((float*)param->engine_val)); + +} + + +/* Frees perframe equation structure. Warning: assumes gen_expr pointer is not freed by anyone else! */ +PerFrameEqn::~PerFrameEqn() { + + delete gen_expr; + + /** @bug Destroy param? - great question, don't know yet*/ +} + +/* Create a new per frame equation */ +PerFrameEqn::PerFrameEqn(int _index, Param * _param, GenExpr * _gen_expr) : + index(_index), param(_param), gen_expr(_gen_expr) {} diff --git a/src/projectM-engine-backup/PerFrameEqn.hpp b/src/projectM-engine-backup/PerFrameEqn.hpp new file mode 100755 index 000000000..39640805d --- /dev/null +++ b/src/projectM-engine-backup/PerFrameEqn.hpp @@ -0,0 +1,53 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Per-frame equation + * + * $Log$ + */ + +#ifndef _PER_FRAME_EQN_H +#define _PER_FRAME_EQN_H + +#define PER_FRAME_EQN_DEBUG 0 + +class GenExpr; +class Param; +class PerFrameEqn; + +class PerFrameEqn { +public: + int index; /* a unique id for each per frame eqn (generated by order in preset files) */ + Param *param; /* parameter to be assigned a value */ + GenExpr *gen_expr; /* expression that paremeter is equal to */ + + PerFrameEqn(int index, Param * param, GenExpr * gen_expr); + ~PerFrameEqn(); + + /// Evaluate the per frame equation + void evaluate(); + + }; + + +#endif /** !_PER_FRAME_EQN_H */ diff --git a/src/projectM-engine-backup/PerPixelEqn.cpp b/src/projectM-engine-backup/PerPixelEqn.cpp new file mode 100755 index 000000000..25f739800 --- /dev/null +++ b/src/projectM-engine-backup/PerPixelEqn.cpp @@ -0,0 +1,90 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include +#include +#include +#include +#include "projectM.hpp" + +#include "fatal.h" +#include "Common.hpp" + +#include "Expr.hpp" +#include "Eval.hpp" +#include "Param.hpp" +#include "PerPixelEqn.hpp" +#include + +#include "wipemalloc.h" +#include +/* Evaluates a per pixel equation */ +void PerPixelEqn::evaluate() { + + GenExpr * eqn_ptr = 0; + int x,y; + + eqn_ptr = this->gen_expr; + + float ** param_matrix = (float**)this->param->matrix; + + if (param_matrix == 0) { + if (PER_PIXEL_EQN_DEBUG) printf("evalPerPixelEqn: [begin initializing matrix] (index = %d) (name = %s)\n", + index, param->name.c_str()); + + param_matrix = (float**)wipemalloc(param->gx*sizeof(float*)); + for(x = 0; x < param->gx; x++) + param_matrix[x] = (float *)wipemalloc(param->gy * sizeof(float)); + + for (x = 0; x < param->gx; x++) + for (y = 0; y < param->gy; y++) { + /// @slow is this necessary? + param_matrix[x][y] = 0.0; + } + this->param->matrix = param_matrix; + } + + 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); + } + } + + /* Now that this parameter has been referenced with a per + pixel equation, we let the evaluator know by setting + this flag */ + /// @bug review and verify this behavior + param->matrix_flag = true; + param->flags |= P_FLAG_PER_PIXEL; +} + +PerPixelEqn::PerPixelEqn(int _index, Param * _param, GenExpr * _gen_expr):index(_index), param(_param), gen_expr(_gen_expr) { + + assert(index >= 0); + assert(param != 0); + assert(gen_expr != 0); + +} + diff --git a/src/projectM-engine-backup/PerPixelEqn.hpp b/src/projectM-engine-backup/PerPixelEqn.hpp new file mode 100755 index 000000000..fbb2be15b --- /dev/null +++ b/src/projectM-engine-backup/PerPixelEqn.hpp @@ -0,0 +1,66 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Per-pixel equation + * + * $Log$ + */ + +#ifndef _PER_PIXEL_EQN_H +#define _PER_PIXEL_EQN_H + +#define PER_PIXEL_EQN_DEBUG 0 + +#define ZOOM_OP 0 +#define ZOOMEXP_OP 1 +#define ROT_OP 2 +#define CX_OP 3 +#define CY_OP 4 +#define SX_OP 5 +#define SY_OP 6 +#define DX_OP 7 +#define DY_OP 8 +#define WARP_OP 9 +#define NUM_OPS 10 /* obviously, this number is dependent on the number of existing per pixel operations */ + +class GenExpr; +class Param; +class PerPixelEqn; +class Preset; + +class PerPixelEqn { +public: + int index; /* used for splay tree ordering. */ + int flags; /* primarily to specify if this variable is user-defined */ + Param *param; + GenExpr *gen_expr; + + void evalPerPixelEqns( Preset *preset ); + void evaluate(); + + PerPixelEqn(int index, Param * param, GenExpr * gen_expr); + + }; + + +#endif /** !_PER_PIXEL_EQN_H */ diff --git a/src/projectM-engine-backup/PerPointEqn.cpp b/src/projectM-engine-backup/PerPointEqn.cpp new file mode 100755 index 000000000..ba3736974 --- /dev/null +++ b/src/projectM-engine-backup/PerPointEqn.cpp @@ -0,0 +1,84 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include +#include +#include + +#include "projectM.hpp" + +#include "fatal.h" +#include "Common.hpp" + +#include "CustomWave.hpp" +#include "Eval.hpp" +#include "Expr.hpp" +#include "Param.hpp" +#include "PerPixelEqn.hpp" +#include "PerPointEqn.hpp" +#include + +#include "wipemalloc.h" + +/* Evaluates a per point equation for the current custom wave given by interface_wave ptr */ +void PerPointEqn::evaluate() { + + int size; + float * param_matrix; + GenExpr * eqn_ptr; + +// samples = CustomWave::interface_wave->samples; + + eqn_ptr = gen_expr; + + if (param->matrix == NULL) { + + if ((param_matrix = (float*) (param->matrix = wipemalloc(size = samples*sizeof(float)))) == NULL) + return; + + memset(param_matrix, 0, size); + } + else + param_matrix = (float*)param->matrix; + + for (int i = 0; i < samples; i++) { + // -1 is because per points only use one dimension + param_matrix[i] = eqn_ptr->eval_gen_expr(i, -1); + } + + /* Now that this parameter has been referenced with a per + point equation, we let the evaluator know by setting + this flag */ +if (!param->matrix_flag) + param->matrix_flag = true; +} + +PerPointEqn::PerPointEqn(int _index, Param * _param, GenExpr * _gen_expr, int _samples): + index(_index), + param(_param), + gen_expr(_gen_expr), + samples(_samples) +{} + + +PerPointEqn::~PerPointEqn() { + delete gen_expr; + } diff --git a/src/projectM-engine-backup/PerPointEqn.hpp b/src/projectM-engine-backup/PerPointEqn.hpp new file mode 100755 index 000000000..89ad22b47 --- /dev/null +++ b/src/projectM-engine-backup/PerPointEqn.hpp @@ -0,0 +1,54 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Per-point equation + * + * $Log$ + */ + +#ifndef _PER_POINT_EQN_H +#define _PER_POINT_EQN_H + +class CustomWave; +class GenExpr; +class Param; +class PerPointEqn; + +class PerPointEqn { +public: + int index; + int samples; // the number of samples to iterate over + Param *param; + GenExpr * gen_expr; + + ~PerPointEqn(); + void evaluate(); + PerPointEqn( int index, Param *param, GenExpr *gen_expr, int samples); + }; + + +//inline void eval_per_point_eqn_helper( void *per_point_eqn ) { +// ((PerPointEqn *)per_point_eqn)->evalPerPointEqn(); +// } + +#endif /** !_PER_POINT_EQN_H */ diff --git a/src/projectM-engine-backup/Preset.cpp b/src/projectM-engine-backup/Preset.cpp new file mode 100755 index 000000000..80bd77c7d --- /dev/null +++ b/src/projectM-engine-backup/Preset.cpp @@ -0,0 +1,764 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include +#include +#include +#ifdef WIN32 +#include "win32-dirent.h" +#else +#include +#endif /** WIN32 */ +#include + +#include "Preset.hpp" +#include "Parser.hpp" +#include "ParamUtils.hpp" +#include "fatal.h" +#include + +Preset::Preset(const std::string & filename, const PresetInputs & presetInputs, PresetOutputs & presetOutputs): + file_path(filename), + builtinParams(presetInputs, presetOutputs), + customWaves(&presetOutputs.customWaves), + customShapes(&presetOutputs.customShapes), + m_presetOutputs(presetOutputs) + +{ + + + initialize(filename); + +} + +Preset::~Preset() +{ + +#if defined(PRESET_DEBUG) && defined(DEBUG) + DWRITE( "~preset(): in\n" ); +#endif + + + + Algorithms::traverse >(init_cond_tree); + + Algorithms::traverse >(per_frame_init_eqn_tree); + + Algorithms::traverse >(per_pixel_eqn_tree); + + Algorithms::traverse >(per_frame_eqn_tree); + + Algorithms::traverse >(user_param_tree); + + /// @note no need to clear the actual container itself + for (PresetOutputs::cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos) + delete(*pos); + + for (PresetOutputs::cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos) + delete(*pos); + + +#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 */ + +int Preset::add_per_pixel_eqn(char * name, GenExpr * gen_expr) +{ + + PerPixelEqn * per_pixel_eqn = NULL; + int index; + Param * param = NULL; + + /* Argument checks */ + if (gen_expr == NULL) + return PROJECTM_FAILURE; + if (name == NULL) + return PROJECTM_FAILURE; + + if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: per pixel equation (name = \"%s\")\n", name); + + if (!strncmp(name, "dx", strlen("dx"))) + this->m_presetOutputs.dx_is_mesh = true; + else if (!strncmp(name, "dy", strlen("dy"))) + this->m_presetOutputs.dy_is_mesh = true; + else if (!strncmp(name, "cx", strlen("cx"))) + this->m_presetOutputs.cx_is_mesh = true; + else if (!strncmp(name, "cy", strlen("cy"))) + this->m_presetOutputs.cy_is_mesh = true; + else if (!strncmp(name, "zoom", strlen("zoom"))) + this->m_presetOutputs.zoom_is_mesh = true; + else if (!strncmp(name, "zoomexp", strlen("zoomexp"))) + this->m_presetOutputs.zoomexp_is_mesh = true; + else if (!strncmp(name, "rot", strlen("rot"))) + this->m_presetOutputs.rot_is_mesh= true; + else if (!strncmp(name, "sx", strlen("sx"))) + this->m_presetOutputs.sx_is_mesh = true; + else if (!strncmp(name, "sy", strlen("sy"))) + this->m_presetOutputs.sy_is_mesh = true; + + /* Search for the parameter so we know what matrix the per pixel equation is referencing */ + + param = ParamUtils::find(name, &this->builtinParams, &this->user_param_tree); + if ( !param ) + { + if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: failed to allocate a new parameter!\n"); + return PROJECTM_FAILURE; + } + + if (per_pixel_eqn_tree.empty()) + { + index = 0; + } + else + { + std::map::iterator lastPos = per_pixel_eqn_tree.end(); + index = per_pixel_eqn_tree.size(); + } + + /* Create the per pixel equation given the index, parameter, and general expression */ + if ((per_pixel_eqn = new PerPixelEqn(index, param, gen_expr)) == NULL) + { + if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: failed to create new per pixel equation!\n"); + return PROJECTM_FAILURE; + + } + + if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: new equation (index = %d,matrix=%X) (param = \"%s\")\n", + per_pixel_eqn->index, per_pixel_eqn->param->matrix, per_pixel_eqn->param->name.c_str()); + + /* Insert the per pixel equation into the preset per pixel database */ + std::pair::iterator, bool> inserteeOption = per_pixel_eqn_tree.insert + (std::make_pair(per_pixel_eqn->index, per_pixel_eqn)); + + if (!inserteeOption.second) + { + printf("failed to add per pixel eqn!\n"); + delete(per_pixel_eqn); + return PROJECTM_FAILURE; + } + + /* Done */ + return PROJECTM_SUCCESS; +} + +void Preset::evalCustomShapeInitConditions() +{ + + for (PresetOutputs::cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos) + (*pos)->eval_custom_shape_init_conds(); +} + + +void Preset::evalCustomWaveInitConditions() +{ + + for (PresetOutputs::cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos) + (*pos)->eval_custom_wave_init_conds(); +} + + +void Preset::evalCustomWavePerFrameEquations() +{ + + /// @bug see above + for (PresetOutputs::cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos) + { + + std::map & init_cond_tree = (*pos)->init_cond_tree; + for (std::map::iterator _pos = init_cond_tree.begin(); _pos != init_cond_tree.end(); ++_pos) + _pos->second->evaluate(); + + std::map & per_frame_eqn_tree = (*pos)->per_frame_eqn_tree; + for (std::map::iterator _pos = per_frame_eqn_tree.begin(); _pos != per_frame_eqn_tree.end(); ++_pos) + _pos->second->evaluate(); + } + +} + +void Preset::evalCustomShapePerFrameEquations() +{ + + for (PresetOutputs::cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos) + { + + std::map & init_cond_tree = (*pos)->init_cond_tree; + for (std::map::iterator _pos = init_cond_tree.begin(); _pos != init_cond_tree.end(); ++_pos) + _pos->second->evaluate(); + + std::map & per_frame_eqn_tree = (*pos)->per_frame_eqn_tree; + for (std::map::iterator _pos = per_frame_eqn_tree.begin(); _pos != per_frame_eqn_tree.end(); ++_pos) + _pos->second->evaluate(); + } + +} + +void Preset::evalInitConditions() +{ + + for (std::map::iterator pos = per_frame_init_eqn_tree.begin(); pos != per_frame_init_eqn_tree.end(); ++pos) + pos->second->evaluate(); + +} + +void Preset::evalPerFrameEquations() +{ + + for (std::map::iterator pos = init_cond_tree.begin(); pos != init_cond_tree.end(); ++pos) + pos->second->evaluate(); + + for (std::map::iterator pos = per_frame_eqn_tree.begin(); pos != per_frame_eqn_tree.end(); ++pos) + pos->second->evaluate(); + +} + + +void Preset::initialize(const std::string & pathname) +{ + + // Clear equation trees + init_cond_tree.clear(); + user_param_tree.clear(); + per_frame_eqn_tree.clear(); + per_pixel_eqn_tree.clear(); + per_frame_init_eqn_tree.clear(); + + /* Set initial index values */ + this->per_pixel_eqn_string_index = 0; + this->per_frame_eqn_string_index = 0; + this->per_frame_init_eqn_string_index = 0; + + /* Clear string buffers */ + memset(this->per_pixel_eqn_string_buffer, 0, STRING_BUFFER_SIZE); + 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) 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? + throw retval; + } + + /* It's kind of ugly to reset these values here. Should definitely be placed in the parser somewhere */ + this->per_frame_eqn_count = 0; + this->per_frame_init_eqn_count = 0; + +} + +/// @bug broken / unimplemented +void Preset::savePreset(char * filename) +{ + + return; + +#ifdef PANTS + FILE * fs; + + if (filename == NULL) + return; + + /* Open the file corresponding to pathname */ + if ((fs = fopen(filename, "w+")) == 0) + { +#ifdef PRESET_DEBUG + if (PRESET_DEBUG) printf("savePreset: failed to create filename \"%s\"!\n", filename); +#endif + return; + } + + write_stream = fs; + + if (write_preset_name(fs) < 0) + { + write_stream = NULL; + fclose(fs); + return; + } + + if (write_init_conditions(fs) < 0) + { + write_stream = NULL; + fclose(fs); + return; + } + + if (write_per_frame_init_equations(fs) < 0) + { + write_stream = NULL; + fclose(fs); + return; + } + + if (write_per_frame_equations(fs) < 0) + { + write_stream = NULL; + fclose(fs); + return; + } + + if (write_per_pixel_equations(fs) < 0) + { + write_stream = NULL; + fclose(fs); + return; + } + + write_stream = NULL; + fclose(fs); +#endif +} + +int Preset::write_preset_name(FILE * fs) +{ + + char s[256]; + int len; + + memset(s, 0, 256); + + if (fs == NULL) + return PROJECTM_FAILURE; + + /* Format the preset name in a string */ + /// @bug removed, code is dead + // sprintf(s, "[%s]\n", name); + + len = strlen(s); + + /* Write preset name to file stream */ + if (fwrite(s, 1, len, fs) != len) + return PROJECTM_FAILURE; + + return PROJECTM_SUCCESS; + +} + +#ifdef NEEDS_MOVED +int Preset::write_init_conditions(FILE * fs) +{ + + if (fs == NULL) + return PROJECTM_FAILURE; + + init_cond_tree.splay_traverse( (void (*)(void*))write_init); + + return PROJECTM_SUCCESS; +} + +void Preset::write_init( InitCond * init_cond ) +{ + + char s[512]; + int len; + + if (write_stream == NULL) + return; + + memset(s, 0, 512); + + if (init_cond->param->type == P_TYPE_BOOL) + sprintf(s, "%s=%d\n", init_cond->param->name, init_cond->init_val.bool_val); + + else if (init_cond->param->type == P_TYPE_INT) + sprintf(s, "%s=%d\n", init_cond->param->name, init_cond->init_val.int_val); + + else if (init_cond->param->type == P_TYPE_DOUBLE) + sprintf(s, "%s=%f\n", init_cond->param->name, init_cond->init_val.float_val); + +else { printf("write_init: unknown parameter type!\n"); return; } + + len = strlen(s); + + if ((fwrite(s, 1, len, write_stream)) != len) + printf("write_init: failed writing to file stream! Out of disk space?\n"); + +} + + +int Preset::write_per_frame_init_equations(FILE * fs) +{ + + int len; + + if (fs == NULL) + return PROJECTM_FAILURE; + + len = strlen(per_frame_init_eqn_string_buffer); + + if (fwrite(per_frame_init_eqn_string_buffer, 1, len, fs) != len) + return PROJECTM_FAILURE; + + return PROJECTM_SUCCESS; +} + + +int Preset::write_per_frame_equations(FILE * fs) +{ + + int len; + + if (fs == NULL) + return PROJECTM_FAILURE; + + len = strlen(per_frame_eqn_string_buffer); + + if (fwrite(per_frame_eqn_string_buffer, 1, len, fs) != len) + return PROJECTM_FAILURE; + + return PROJECTM_SUCCESS; +} + + +int Preset::write_per_pixel_equations(FILE * fs) +{ + + int len; + + if (fs == NULL) + return PROJECTM_FAILURE; + + len = strlen(per_pixel_eqn_string_buffer); + + if (fwrite(per_pixel_eqn_string_buffer, 1, len, fs) != len) + return PROJECTM_FAILURE; + + return PROJECTM_SUCCESS; +} +#endif /** NEEDS_MOVED */ + +void Preset::load_custom_wave_init_conditions() +{ + + for (PresetOutputs::cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos) + (*pos)->load_unspecified_init_conds(); + +} + +void Preset::load_custom_shape_init_conditions() +{ + + // void eval_custom_shape_init_conds(); + + for (PresetOutputs::cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos) + (*pos)->load_custom_shape_init(); +} + + + + +void Preset::evaluateFrame() +{ + + /* Evaluate all equation objects in same order as the renderer */ + + evalInitConditions(); + evalPerFrameEquations(); + evalPerPixelEqns(); + evalInitConditions(); + evalCustomShapeInitConditions(); + evalCustomWavePerFrameEquations(); + evalCustomShapePerFrameEquations(); + +} + +/** Evaluates all per-pixel equations */ +void Preset::evalPerPixelEqns() +{ + + /* Evaluate all per pixel equations using splay traversal */ + for (std::map::iterator pos = per_pixel_eqn_tree.begin(); + pos != per_pixel_eqn_tree.end(); ++pos) + pos->second->evaluate(); + + +} + +/** Finds / Creates (if necessary) initial condition associated with passed parameter */ +InitCond * Preset::get_init_cond( Param *param ) +{ + + InitCond * init_cond; + CValue init_val; + + assert(param); + + std::map::iterator pos = init_cond_tree.find(param->name); + + init_cond = pos == init_cond_tree.end() ? 0 : pos->second; + + if (init_cond == NULL) + { + + if (param->type == P_TYPE_BOOL) + init_val.bool_val = 0; + + else if (param->type == P_TYPE_INT) + init_val.int_val = *(int*)param->engine_val; + + else if (param->type == P_TYPE_DOUBLE) + init_val.float_val = *(float*)param->engine_val; + + /* Create new initial condition */ + if ((init_cond = new InitCond(param, init_val)) == NULL) + return NULL; + + /* Insert the initial condition into this presets tree */ + std::pair::iterator, bool> inserteePair = + init_cond_tree.insert(std::make_pair(init_cond->param->name, init_cond)); + + if (!inserteePair.second) + { + delete init_cond; + return NULL; + } + } + + return init_cond; + +} + +/* load_preset_file: private function that loads a specific preset denoted + by the given pathname */ +int Preset::load_preset_file(const char * pathname) +{ + + FILE * fs; + int retval; + int lineno; + line_mode_t line_mode; + + if (pathname == NULL) + return PROJECTM_FAILURE; + + /* Open the file corresponding to pathname */ + if ((fs = fopen(pathname, "rb")) == 0) + { +#if defined(PRESET_DEBUG) && defined(DEBUG) + DWRITE( "load_preset_file: loading of file %s failed!\n", pathname); +#endif + return PROJECTM_ERROR; + } + +#if defined(PRESET_DEBUG) && defined(DEBUG) + DWRITE( "load_preset_file: file stream \"%s\" opened successfully\n", pathname); +#endif + + /* Parse any comments */ + if (Parser::parse_top_comment(fs) < 0) + { +#if defined(PRESET_DEBUG) && defined(DEBUG) + DWRITE( "load_preset_file: no left bracket found...\n"); +#endif + fclose(fs); + return PROJECTM_FAILURE; + } + + /* Parse the preset name and a left bracket */ + char tmp_name[MAX_TOKEN_SIZE]; + + if (Parser::parse_preset_name(fs, tmp_name) < 0) + { +#if defined(PRESET_DEBUG) && defined(DEBUG) + DWRITE( "load_preset_file: loading of preset name in file \"%s\" failed\n", pathname); +#endif + fclose(fs); + return PROJECTM_ERROR; + } + name = std::string(tmp_name); + +#if defined(PRESET_DEBUG) && defined(DEBUG) + DWRITE( "load_preset_file: preset \"%s\" parsed\n", this->name); +#endif + + /* Parse each line until end of file */ + lineno = 0; +#if defined(PRESET_DEBUG) && defined(DEBUG) + DWRITE( "load_preset_file: beginning line parsing...\n"); +#endif + while ((retval = Parser::parse_line(fs, this)) != EOF) + { + if (retval == PROJECTM_PARSE_ERROR) + { + line_mode = NORMAL_LINE_MODE; +#if defined(PRESET_DEBUG) && defined(DEBUG) + DWRITE( "load_preset_file: parse error in file \"%s\": line %d\n", pathname,lineno); +#endif + + } + lineno++; + } + +#if defined(PRESET_DEBUG) && defined(DEBUG) + DWRITE("load_preset_file: finished line parsing successfully\n"); +#endif + + /* Now the preset has been loaded. + Evaluation calls can be made at appropiate + times in the frame loop */ + + fclose(fs); +#if defined(PRESET_DEBUG) && defined(DEBUG) + DWRITE("load_preset_file: file \"%s\" closed, preset ready\n", pathname); +#endif + return PROJECTM_SUCCESS; +} + + +void Preset::load_init_conditions() +{ + + ParamUtils::LoadInitCondFunctor functor(this); + builtinParams.traverse(functor); + +} + + + +CustomWave * Preset::find_custom_wave(int id, bool create_flag) +{ + CustomWave * custom_wave = NULL; + + assert(customWaves); + + if ((custom_wave = (*customWaves)[id]) == NULL) + { + + if (CUSTOM_WAVE_DEBUG) { printf("find_custom_wave: creating custom wave (id = %d)...", id);fflush(stdout);} + + if (create_flag == FALSE) + { + if (CUSTOM_WAVE_DEBUG) printf("you specified not to (create flag = false), returning null\n"); + return NULL; + } + + if ((custom_wave = new CustomWave(id)) == NULL) + { + if (CUSTOM_WAVE_DEBUG) printf("failed...out of memory?\n"); + return NULL; + } + + customWaves->push_back(custom_wave); + } + + return custom_wave; + +} + + +CustomShape * Preset::find_custom_shape(int id, bool create_flag) +{ + + CustomShape * custom_shape = NULL; + assert(customShapes); + if ((custom_shape = (*customShapes)[id]) == NULL) + { + + if (CUSTOM_SHAPE_DEBUG) { printf("find_custom_shape: creating custom shape (id = %d)...", id);fflush(stdout);} + + if (create_flag == FALSE) + { + if (CUSTOM_SHAPE_DEBUG) printf("you specified not to (create flag = false), returning null\n"); + return NULL; + } + + if ((custom_shape = new CustomShape(id)) == NULL) + { + if (CUSTOM_SHAPE_DEBUG) printf("failed...out of memory?\n"); + return NULL; + } + + customShapes->push_back(custom_shape); + + } + + return custom_shape; +} + +/* Find a parameter given its name, will create one if not found */ +Param * Preset::find(char * name, int flags) +{ + + Param * param = NULL; + + /* Null argument checks */ + assert(name); + + /* First look in the builtin database */ + param = (Param *)this->builtinParams.find_builtin_param(name); + + /* If the search failed, check the user database */ + if (param == NULL) + { + std::map::iterator pos = user_param_tree.find(name); + + if (pos == user_param_tree.end()) + param = 0; + else + param = pos->second; + } + + /* If it doesn't exist in the user (or builtin) database and + create_flag is set, then make it and insert into the database + */ + + if ((param == NULL) && (flags & P_CREATE)) + { + + /* Check if string is valid */ + if (!Param::is_valid_param_string(name)) + { + if (PARAM_DEBUG) printf("find: invalid parameter name:\"%s\"\n", name); + return NULL; + } + /* Now, create the user defined parameter given the passed name */ + if ((param = new Param(name)) == NULL) + { + if (PARAM_DEBUG) printf("find: failed to create a new user parameter!\n"); + return NULL; + } + /* Finally, insert the new parameter into this preset's proper splaytree */ + std::pair::iterator, bool> inserteePair + = user_param_tree.insert(std::make_pair(param->name, param)); + + if (!inserteePair.second) + { + if (PARAM_DEBUG) printf("PARAM \"%s\" already exists in user parameter tree!\n", param->name.c_str()); + delete param; + return NULL; + } + + } + + /* Return the found (or created) parameter. Note that if P_CREATE is not set, this could be null */ + return param; + +} diff --git a/src/projectM-engine-backup/Preset.hpp b/src/projectM-engine-backup/Preset.hpp new file mode 100644 index 000000000..95b7745ce --- /dev/null +++ b/src/projectM-engine-backup/Preset.hpp @@ -0,0 +1,141 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Preset + * + * $Log$ + */ + +#ifndef _PRESET_HPP +#define _PRESET_HPP + +#include "Common.hpp" +#include +#define PRESET_DEBUG 2 /* 0 for no debugging, 1 for normal, 2 for insane */ + +#include "CustomShape.hpp" +#include "CustomWave.hpp" +#include "Expr.hpp" +#include "PerPixelEqn.hpp" +#include "PerFrameEqn.hpp" +#include "BuiltinParams.hpp" +#include "PresetFrameIO.hpp" +#include +#include "InitCond.hpp" +#include + + +class CustomWave; +class CustomShape; +class InitCond; + +//#include + + +class Preset { +protected: + + +public: + + /** Load a preset by filename with input and output buffers specified. + * This is the only poper way to allocate a new preset. */ + Preset(const std::string & filename, const PresetInputs & presetInputs, PresetOutputs & presetOutputs); + + ~Preset(); + + /** Evaluates the preset for a frame given the current values of preset inputs / outputs */ + void evaluateFrame(); + + BuiltinParams builtinParams; + + std::string name; + std::string file_path; + + void load_init_conditions(); + CustomShape * find_custom_shape(int id, bool create_flag); + CustomWave * find_custom_wave(int id, bool create_flag); + + int per_pixel_eqn_string_index; + int per_frame_eqn_string_index; + int per_frame_init_eqn_string_index; + + int per_frame_eqn_count, + per_frame_init_eqn_count; + + char per_pixel_eqn_string_buffer[STRING_BUFFER_SIZE]; + char per_frame_eqn_string_buffer[STRING_BUFFER_SIZE]; + char per_frame_init_eqn_string_buffer[STRING_BUFFER_SIZE]; + + /* Data structures that contain equation and initial condition information */ + std::map per_frame_eqn_tree; /* per frame equations */ + std::map per_pixel_eqn_tree; /* per pixel equation tree */ + std::map per_frame_init_eqn_tree; /* per frame initial equations */ + std::map init_cond_tree; /* initial conditions */ + std::map user_param_tree; /* user parameter splay tree */ + + int add_per_pixel_eqn( char *name, GenExpr *gen_expr ); + + int resetPerPixelEqns(); + int resetPerPixelEqnFlags(); + + InitCond *get_init_cond( Param *param ); + + void load_custom_wave_init_conditions(); + void load_custom_wave_init( CustomWave *customWave ); + void load_custom_shape_init_conditions(); + void load_custom_shape_init( CustomShape *customShape ); + void initialize(const std::string & pathname); + + void reloadPerFrame(char * s); + void reloadPerFrameInit(char *s); + void reloadPerPixel(char *s); + int load_preset_file(const char * pathname); + static Preset *load_preset( const char *pathname ); + void savePreset(char * name); + int write_preset_name( FILE *fs ); + int write_init_conditions( FILE *fs ); + int write_init( InitCond *initCond ); + int write_per_frame_init_equations( FILE *fs ); + int write_per_frame_equations( FILE *fs ); + int write_per_pixel_equations( FILE *fs ); + Param * find(char * name, int flags) ; + int destroy(); + void load_init_cond(char *name, int flags); + +private: + + void evalCustomWavePerFrameEquations(); + void evalCustomShapePerFrameEquations(); + void evalInitConditions(); + void evalCustomWaveInitConditions(); + void evalCustomShapeInitConditions(); + void evalPerPixelEqns(); + void evalPerFrameEquations(); + + PresetOutputs::cwave_container * customWaves; + PresetOutputs::cshape_container * customShapes; + PresetOutputs & m_presetOutputs; +}; + +#endif /** !_PRESET_HPP */ diff --git a/src/projectM-engine-backup/PresetChooser.cpp b/src/projectM-engine-backup/PresetChooser.cpp new file mode 100644 index 000000000..b2397590e --- /dev/null +++ b/src/projectM-engine-backup/PresetChooser.cpp @@ -0,0 +1,14 @@ +// +// C++ Implementation: PresetChooser +// +// Description: +// +// +// Author: Carmelo Piccione , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "PresetChooser.hpp" + diff --git a/src/projectM-engine-backup/PresetChooser.hpp b/src/projectM-engine-backup/PresetChooser.hpp new file mode 100644 index 000000000..505915777 --- /dev/null +++ b/src/projectM-engine-backup/PresetChooser.hpp @@ -0,0 +1,225 @@ +/** PresetChooser.hpp: + * Provides functions and iterators to select presets. Requires a preset loader upon construction. + */ + +/// @idea Weighted random based on user stats + +#ifndef PRESET_CHOOSER_HPP +#define PRESET_CHOOSER_HPP + +#include "Preset.hpp" + +#include "PresetLoader.hpp" + +#include +#include + + +class PresetChooser; + +/// A simple iterator class to traverse back and forth a preset directory +class PresetIterator { + +public: + PresetIterator() {} + + /// Instantiate a preset iterator at the given starting position + PresetIterator(std::size_t start); + + /// Move iterator forward + void operator++(); + + /// Move iterator backword + void operator--() ; + + /// 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. + std::size_t operator*() const; + + /// Allocate a new preset given this iterator's associated preset name + /// \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 allocate(const PresetInputs & presetInputs, PresetOutputs & presetOutputs); + + /// Set the chooser asocciated with this iterator + void setChooser(const PresetChooser & chooser); + +private: + std::size_t m_currentIndex; + const PresetChooser * m_presetChooser; + +}; + +class PresetChooser { + +public: + typedef PresetIterator iterator; + + /// Initializes a chooser with an established preset loader. + /// \param presetLoader an initialized preset loader to choose presets from + /// \note The preset loader is refreshed via events or otherwise outside this class's scope + PresetChooser(const PresetLoader & presetLoader); + + + /// Choose a preset via the passed in index. Must be between 0 and num valid presets in directory + /// \param index An index lying in the interval [0, this->getNumPresets()] + /// \param presetInputs the preset inputs to associate with the preset upon construction + /// \param presetOutputs the preset outputs to associate with the preset upon construction + std::auto_ptr directoryIndex(std::size_t index, const PresetInputs & presetInputs, + PresetOutputs & presetOutputs) 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; + + /// A functor, for all preset indices, returns probability 1 / (number of presets in directory) + class UniformRandomFunctor { + + public: + /// Initialize a new functor with a particular collection size + /// \param collectionSize the number of presets one is sampling over + UniformRandomFunctor(std::size_t collectionSize); + + /// Returns uniform (fixed) probability for any index + /// \param index the index position of the preset to load + float operator() (std::size_t index) const; + + private: + std::size_t m_collectionSize; + + }; + + + /// An STL-esque iterator to beginning traversing presets from a directory + /// \returns the position of the first preset in the collection + PresetIterator begin(); + + /// An STL-esque iterator to retrieve an end position from a directory + /// \returns the end position of the collection + PresetIterator end() const; + + /// Perform a weighted sample to select a preset given a weight functor. + /// \param presetInputs the preset inputs to associate with the preset upon construction + /// \param presetOutputs the preset outputs to associate with the preset upon construction + /// \param WeightFunctor a functor that returns a probability for each index (see UniformRandomFunctor) + /// \returns an auto pointer of the newly allocated preset + template + std::auto_ptr weightedRandom(const PresetInputs & presetInputs, PresetOutputs & presetOutputs, WeightFunctor & weightFunctor) const; + + + /// Do a weighted sample given a weight functor and default construction (ie. element size) of the weight functor + /// \param presetInputs the preset inputs to associate with the preset upon construction + /// \param presetOutputs the preset outputs to associate with the preset upon construction + /// \param WeightFunctor a functor that returns a probability for each index (see UniformRandomFunctor) + /// \returns an auto pointer of the newly allocated preset + template + std::auto_ptr weightedRandom(const PresetInputs & presetInputs, PresetOutputs & preseOutputs) const; + +private: + template + std::auto_ptr doWeightedSample(WeightFunctor & weightFunctor, const PresetInputs & presetInputs, PresetOutputs & presetOutputs); + + const PresetLoader * m_presetLoader; +}; + + +inline PresetChooser::PresetChooser(const PresetLoader & presetLoader):m_presetLoader(&presetLoader) {} + +inline std::size_t PresetChooser::getNumPresets() const { + return m_presetLoader->getNumPresets(); +} + +inline void PresetIterator::setChooser(const PresetChooser & chooser) { + m_presetChooser = &chooser; +} + +inline std::size_t PresetIterator::operator*() const { + return m_currentIndex; +} + +inline PresetIterator::PresetIterator(std::size_t start):m_currentIndex(start) {} + +inline void PresetIterator::operator++() { + assert(m_currentIndex < m_presetChooser->getNumPresets()); + m_currentIndex++; +} + +inline void PresetIterator::operator--() { + assert(m_currentIndex > 0); + m_currentIndex--; +} + +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); +} + +inline float PresetChooser::UniformRandomFunctor::operator() (std::size_t index) const { + return (1.0 / m_collectionSize); +} + + +inline PresetIterator PresetChooser::begin() { + PresetIterator pos(0); + pos.setChooser(*this); + return pos; +} + +inline PresetIterator PresetChooser::end() const { + PresetIterator pos(m_presetLoader->getNumPresets()); + return pos; +} + +template +std::auto_ptr PresetChooser::weightedRandom(const PresetInputs & presetInputs, PresetOutputs & presetOutputs, WeightFunctor & weightFunctor) const { + doWeightedSample(weightFunctor); +} + +template +inline std::auto_ptr PresetChooser::weightedRandom(const PresetInputs & presetInputs, PresetOutputs & presetOutputs) const { + + WeightFunctor weightFunctor(m_presetLoader->getNumPresets()); + doWeightedSample(weightFunctor, presetInputs, presetOutputs); + +} + +inline std::auto_ptr PresetChooser::directoryIndex(std::size_t index, const PresetInputs & presetInputs, + PresetOutputs & presetOutputs) const { + + return m_presetLoader->loadPreset(index,presetInputs, presetOutputs); +} + +template +inline std::auto_ptr PresetChooser::doWeightedSample(WeightFunctor & weightFunctor, const PresetInputs & presetInputs, PresetOutputs & presetOutputs) { + + // Choose a random bounded mass between 0 and 1 + float cutoff = ((float)(random())) / RAND_MAX; + + // Sum up mass, stopping when cutoff is reached. This is the typical + // weighted sampling algorithm. + float mass = 0; + for (PresetIterator pos = this->begin();pos != this->end() ; ++pos) { + mass += weightFunctor(*pos); + if (mass >= cutoff) + return pos.allocate(presetInputs, presetOutputs); + } +} + +#endif diff --git a/src/projectM-engine-backup/PresetFilters.hpp b/src/projectM-engine-backup/PresetFilters.hpp new file mode 100644 index 000000000..0a7b98c6c --- /dev/null +++ b/src/projectM-engine-backup/PresetFilters.hpp @@ -0,0 +1,38 @@ +#ifndef PRESET_FILTERS_HPP +#define PRESET_FILTERS_HPP +#include "Preset.hpp" + +class PresetFilters { + +/// The merge functor decides how to put the presets together. +/// Assumes getMergedPreset() is implemented. +/// A sample is below +/// @bug this is screwed up, but functor idea still has merit once design is resolved +class LinearMergeFunctor { + +public: + LinearMergeFunctor(PresetOutputs & presetOutputsAB):m_presetOutputsAB(presetOutputsAB) {} + + + void operator() (const PresetInputs & inputsA, const PresetInputs & inputsB, + const PresetOutputs & outputsA, const PresetOutputs & outputsB) { + + // use time variables from inputsA/B to determine how presets should be merged + + } + + PresetOutputs & getMergedOutputs() { + return m_presetAB; + } + + +private: + PresetOutputs & m_presetOutputsAB; + +}; + +template +static void merge(const PresetOutput & outputsA, const Preset & outputsB, MergeFunctor & functor); + +}; +#endif diff --git a/src/projectM-engine-backup/PresetFrameIO.cpp b/src/projectM-engine-backup/PresetFrameIO.cpp new file mode 100644 index 000000000..c83028cb1 --- /dev/null +++ b/src/projectM-engine-backup/PresetFrameIO.cpp @@ -0,0 +1,202 @@ +#include "PresetFrameIO.hpp" +#include "wipemalloc.h" +#include +#include +#include +PresetInputs::PresetInputs() +{ +} + +void PresetInputs::Initialize(int gx, int gy) +{ + int x, y; + + 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)); + } + this->y_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->y_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + + } + this->rad_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->rad_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->theta_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x theta_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + + this->origtheta=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->origtheta[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->origrad=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->origrad[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->origx=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->origx[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->origy=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->origy[x] = (float *)wipemalloc(gy * sizeof(float)); + } + +for (x=0;xorigx[x][y]=x/(float)(gx-1); + this->origy[x][y]=-((y/(float)(gy-1))-1); + this->origrad[x][y]=hypot((this->origx[x][y]-.5)*2,(this->origy[x][y]-.5)*2) * .7071067; + this->origtheta[x][y]=atan2(((this->origy[x][y]-.5)*2),((this->origx[x][y]-.5)*2)); + } + } + + + +} + +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++) + { + this->sx_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->sy_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->sy_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->dx_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->dx_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->dy_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->dy_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->cx_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->cx_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->cy_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->cy_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->zoom_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->zoom_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->zoomexp_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->zoomexp_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->rot_mesh=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->rot_mesh[x] = (float *)wipemalloc(gy * sizeof(float)); + } + zoom_is_mesh = false; + zoomexp_is_mesh =false; + rot_is_mesh =false; + + sx_is_mesh =false; + sy_is_mesh = false; + dx_is_mesh = false; + dy_is_mesh =false; + cx_is_mesh = false; + cy_is_mesh = false;; + +} + +PresetInputs::~PresetInputs() +{ + for(int x = 0; x < this->gx; x++) + { + + + free(this->origtheta[x]); + free(this->origrad[x]); + free(this->origx[x]); + free(this->origy[x]); + + free(this->x_mesh[x]); + free(this->y_mesh[x]); + free(this->rad_mesh[x]); + free(this->theta_mesh[x]); + + } + + + free(this->origx); + free(this->origy); + free(this->origrad); + free(this->origtheta); + + //std::cerr << "freeing x_mesh" <x_mesh); + free(this->y_mesh); + free(this->rad_mesh); + free(this->theta_mesh); + + this->origx = NULL; + this->origy = NULL; + this->origtheta = NULL; + this->origrad = NULL; + + this->x_mesh = NULL; + this->y_mesh = NULL; + this->rad_mesh = NULL; + this->theta_mesh = NULL; +} + +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]; + theta_mesh[x][y]=this->origtheta[x][y]; + } + } + + } diff --git a/src/projectM-engine-backup/PresetFrameIO.hpp b/src/projectM-engine-backup/PresetFrameIO.hpp new file mode 100644 index 000000000..7ca6cfa0f --- /dev/null +++ b/src/projectM-engine-backup/PresetFrameIO.hpp @@ -0,0 +1,188 @@ +#ifndef PRESET_FRAME_IO_HPP +#define PRESET_FRAME_IO_HPP +#include + +class CustomWave; +class CustomShape; + + +/** Container for all preset writeable engine variables. It's a struct + * so that it's light weight. Access is done directly on + * members for Mr. Sperl's convenience */ +class PresetOutputs { +public: + typedef std::vector cwave_container; + typedef std::vector cshape_container; + + cwave_container customWaves; + cshape_container customShapes; + + void Initialize(int gx, int gy); + PresetOutputs(); + /* PER FRAME VARIABLES BEGIN */ + float zoom; + float zoomexp; + float rot; + float warp; + + float sx; + float sy; + float dx; + float dy; + float cx; + float cy; + + float decay; + + float wave_r; + float wave_g; + float wave_b; + float wave_o; + float wave_x; + float wave_y; + float wave_mystery; + + float ob_size; + float ob_r; + float ob_g; + float ob_b; + float ob_a; + + float ib_size; + float ib_r; + float ib_g; + float ib_b; + float ib_a; + + float mv_a ; + float mv_r ; + float mv_g ; + float mv_b ; + float mv_l; + float mv_x; + float mv_y; + float mv_dy; + float mv_dx; + + /* PER_FRAME VARIABLES END */ + + float fRating; + float fGammaAdj; + float fVideoEchoZoom; + float fVideoEchoAlpha; + + int nVideoEchoOrientation; + int nWaveMode; + int bAdditiveWaves; + int bWaveDots; + int bWaveThick; + int bModWaveAlphaByVolume; + int bMaximizeWaveColor; + int bTexWrap; + int bDarkenCenter; + int bRedBlueStereo; + int bBrighten; + int bDarken; + int bSolarize; + int bInvert; + int bMotionVectorsOn; + + + float fWaveAlpha ; + float fWaveScale; + float fWaveSmoothing; + float fWaveParam; + float fModWaveAlphaStart; + float fModWaveAlphaEnd; + float fWarpAnimSpeed; + float fWarpScale; + float fShader; + + /* Q VARIABLES START */ + + float q1; + float q2; + float q3; + float q4; + float q5; + float q6; + float q7; + float q8; + + + /* Q VARIABLES END */ + + float **zoom_mesh; + float **zoomexp_mesh; + float **rot_mesh; + + float **sx_mesh; + float **sy_mesh; + float **dx_mesh; + float **dy_mesh; + float **cx_mesh; + float **cy_mesh; + + bool zoom_is_mesh; + bool zoomexp_is_mesh; + bool rot_is_mesh; + + bool sx_is_mesh; + bool sy_is_mesh; + bool dx_is_mesh; + bool dy_is_mesh; + bool cx_is_mesh; + bool cy_is_mesh; + + +}; + +/** Container for all *read only* engine variables. It's a struct + * so that it's light weight. Access is done directly on + * members for Mr. Sperl's convenience */ +class PresetInputs { + +public: + /* PER_PIXEL VARIBLES BEGIN */ + + float x_per_pixel; + float y_per_pixel; + float rad_per_pixel; + float ang_per_pixel; + + /* PER_PIXEL VARIBLES END */ + + int fps; + + + float time; + float bass; + float mid; + float bass_att; + float mid_att; + float treb_att; + int frame; + float progress; + + + /* variables were added in milkdrop 1.04 */ + int gx,gy; + + + float **x_mesh; + float **y_mesh; + float **rad_mesh; + float **theta_mesh; + + float **origtheta; //grid containing interpolated mesh reference values + float **origrad; + float **origx; //original mesh + float **origy; + + void ResetMesh(); + ~PresetInputs(); + PresetInputs(); + void Initialize(int gx, int gy); +}; + +#endif diff --git a/src/projectM-engine-backup/PresetLoader.cpp b/src/projectM-engine-backup/PresetLoader.cpp new file mode 100644 index 000000000..a08bad4d9 --- /dev/null +++ b/src/projectM-engine-backup/PresetLoader.cpp @@ -0,0 +1,137 @@ +// +// C++ Implementation: PresetLoader +// +// Description: +// +// +// Author: Carmelo Piccione , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "PresetLoader.hpp" +#include "Preset.hpp" +#include +#include +extern "C" +{ +#include +#include +} +#include +#include "projectM.hpp" + +const std::string PresetLoader::PROJECTM_FILE_EXTENSION(".prjm"); +const std::string PresetLoader::MILKDROP_FILE_EXTENSION(".milk"); + +PresetLoader::PresetLoader(std::string dirname) :m_dirname(dirname), m_dir(0) +{ + // Do one scan + rescan(); +} + +PresetLoader::~PresetLoader() +{ + if (m_dir) + closedir(m_dir); +} + +void PresetLoader::setScanDirectory(std::string dirname) +{ + m_dirname = dirname; +} + + +void PresetLoader::rescan() +{ + std::cerr << "Rescanning..." << std::endl; + + // Clear the directory entry collection + m_entries.clear(); + + std::cerr << "cleared!" << std::endl; + + // If directory already opened, close it first + if (m_dir) + { + std::cerr << "m_dir" << std::endl; + closedir(m_dir); + m_dir = 0; + } + + std::cerr << "opening " << m_dirname << std::endl; + // Allocate a new a stream given the current directory name + if ((m_dir = opendir(m_dirname.c_str())) == NULL) + { + handleDirectoryError(); + abort(); + } + + struct dirent * dir_entry; + + while ((dir_entry = readdir(m_dir)) != NULL) + { + + + + std::ostringstream out; + // Convert char * to friendly string + std::string filename(dir_entry->d_name); + + + // 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; + + // Create full path name + out << m_dirname << PATH_SEPARATOR << filename; + + // std::cerr << "[PresetLoader]" << filename << std::endl; + // Add to our directory entry collection + m_entries.push_back(out.str()); + + // the directory entry struct is freed elsewhere + } + +} + +std::auto_ptr PresetLoader::loadPreset(unsigned int index, const PresetInputs & presetInputs, PresetOutputs & presetOutputs) const +{ + + // Check that index isn't insane + assert(index >= 0); + assert(index < m_entries.size()); + + // Return a new auto pointer to a present + return std::auto_ptr(new Preset(m_entries[index], presetInputs, presetOutputs)); +} + + + +void PresetLoader::handleDirectoryError() +{ + switch (errno) + { + case ENOENT: + std::cerr << "[PresetLoader] ENOENT error. \"man fopen\" 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! Cannot continue." << std::endl; + break; + case ENFILE: + std::cerr << "[PresetLoader] Your system has reached its open file limit. Giving up..." << std::endl; + abort(); + case EMFILE: + std::cerr << "[PresetLoader] too many files in use by projectM! Bailing!" << std::endl; + abort(); + case EACCES: + std::cerr << "[PresetLoader] permissions issue reading the specified preset directory." << std::endl; + break; + default: + break; + } +} diff --git a/src/projectM-engine-backup/PresetLoader.hpp b/src/projectM-engine-backup/PresetLoader.hpp new file mode 100644 index 000000000..a23571367 --- /dev/null +++ b/src/projectM-engine-backup/PresetLoader.hpp @@ -0,0 +1,51 @@ +#ifndef __PRESET_LOADER_HPP +#define __PRESET_LOADER_HPP + +#include // used for path / filename stuff + +#include // for auto pointers +#include +#include +#include + +class Preset; +class PresetInputs; +class PresetOutputs; + +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); + + /** Destructor will remove all alllocated presets */ + ~PresetLoader(); + + /** Load a preset by specifying a filename of the directory (that is, NOT full path) */ + /** Autopointers: when you take it, I leave it */ + std::auto_ptr loadPreset(unsigned int index, const PresetInputs & presetInputs, + PresetOutputs & presetOutputs) const; + + /** Returns the number of presets in the active directory */ + inline std::size_t getNumPresets() const { + return m_entries.size(); + } + + /** Sets the directory where the loader will search for files */ + void setScanDirectory(std::string pathname); + + /** Rescans the active preset directory */ + void rescan(); + + private: + void handleDirectoryError(); + std::string m_dirname; + DIR * m_dir; + + // vector chosen for speed, but not great for reverse index lookups + std::vector m_entries; +}; + +#endif diff --git a/src/projectM-engine-backup/Renderer.cpp b/src/projectM-engine-backup/Renderer.cpp new file mode 100644 index 000000000..15cf7d0fe --- /dev/null +++ b/src/projectM-engine-backup/Renderer.cpp @@ -0,0 +1,1996 @@ +#include "Renderer.hpp" +#include "wipemalloc.h" +#include "math.h" +#include "Common.hpp" +#include "console_interface.h" +#include "CustomShape.hpp" +#include "CustomWave.hpp" + +class Preset; + +Renderer::Renderer(int width, int height, int gx, int gy, RenderTarget *renderTarget, BeatDetect *beatDetect, char* fontURL) +{ + int x; int y; + + this->gx=gx; + this->gy=gy; + + this->totalframes = 1; + this->noSwitch = 0; + this->showfps = 0; + this->showtitle = 0; + this->showpreset = 0; + this->showhelp = 0; + this->showstats = 0; + this->studio = 0; +this->realfps=0; + + this->drawtitle=0; + + this->title = NULL; + + /** Other stuff... */ + this->correction = 1; + this->aspect=1.33333333; + + this->gridx=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->gridx[x] = (float *)wipemalloc(gy * sizeof(float)); + } + this->gridy=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->gridy[x] = (float *)wipemalloc(gy * sizeof(float)); + } + + this->origx2=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->origx2[x] = (float *)wipemalloc(gy * sizeof(float)); + } +this->origy2=(float **)wipemalloc(gx * sizeof(float *)); + for(x = 0; x < gx; x++) + { + this->origy2[x] = (float *)wipemalloc(gy * sizeof(float)); + } + + + //initialize reference grid values + for (x=0;xgridx[x][y]=origx*renderTarget->texsize; + this->gridy[x][y]=origy*renderTarget->texsize; + this->origx2[x][y]=( origx-.5)*2; + this->origy2[x][y]=( origy-.5)*2; + }} + +this->renderTarget = renderTarget; +this->beatDetect = beatDetect; +this->fontURL = fontURL; + +#ifdef USE_FTGL + /** Reset fonts */ + title_font = NULL; + other_font = NULL; + poly_font = NULL; +#endif /** USE_FTGL */ + +} + +void Renderer::RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInputs) +{ + totalframes++; + + DWRITE( "start Pass 1 \n" ); + + //BEGIN PASS 1 + // + //This pass is used to render our texture + //the texture is drawn to a subsection of the framebuffer + //and then we perform our manipulations on it + //in pass 2 we will copy the texture into texture memory + + + renderTarget->lock(); + + + // glPushAttrib( GL_ALL_ATTRIB_BITS ); /* Overkill, but safe */ + + glViewport( 0, 0, renderTarget->texsize, renderTarget->texsize ); + + glEnable( GL_TEXTURE_2D ); + if(this->renderTarget->usePbuffers) + { + glBindTexture( GL_TEXTURE_2D, renderTarget->textureID[1] ); + } + else + { + glBindTexture( GL_TEXTURE_2D, renderTarget->textureID[0] ); + } + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); + + glMatrixMode( GL_PROJECTION ); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0.0, 1, 0.0, 1,10,40); + + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + glLoadIdentity(); + + DWRITE( "renderFrame: renderTarget->texsize: %d x %d\n", this->renderTarget->texsize, this->renderTarget->texsize ); + + + PerPixelMath(presetOutputs, presetInputs); + + if(this->renderTarget->usePbuffers) + { + //draw_motion_vectors(); //draw motion vectors + //unlockPBuffer( this->renderTarget); + //lockPBuffer( this->renderTarget, PBUFFER_PASS1 ); + } + PerFrame(presetOutputs); //apply per-frame effects + Interpolation(presetOutputs,presetInputs); //apply per-pixel effects + + draw_title_to_texture(); //draw title to texture + +// if(!this->renderTarget->usePbuffers) + { + draw_motion_vectors(presetOutputs); //draw motion vectors + } + draw_shapes(presetOutputs); + draw_custom_waves(presetOutputs); + draw_waveform(presetOutputs, presetInputs); + if(presetOutputs->bDarkenCenter)darken_center(); + draw_borders(presetOutputs); //draw borders + + /** Restore original view state */ + glMatrixMode( GL_MODELVIEW ); + glPopMatrix(); + + glMatrixMode( GL_PROJECTION ); + glPopMatrix(); + + /** Restore all original attributes */ + // glPopAttrib(); + glFlush(); + + renderTarget->unlock(); + + +#ifdef DEBUG + GLint msd = 0, + psd = 0; + glGetIntegerv( GL_MODELVIEW_STACK_DEPTH, &msd ); + glGetIntegerv( GL_PROJECTION_STACK_DEPTH, &psd ); + DWRITE( "end pass1: modelview matrix depth: %d\tprojection matrix depth: %d\n", + msd, psd ); + DWRITE( "begin pass2\n" ); +#endif + + //BEGIN PASS 2 + // + //end of texture rendering + //now we copy the texture from the framebuffer to + //video texture memory and render fullscreen on a quad surface. + + /** Reset the viewport size */ + DWRITE( "viewport: %d x %d\n", this->vw, this->vh ); + glViewport( 0, 0, this->vw, this->vh ); + glClear( GL_COLOR_BUFFER_BIT ); + + if ( this->renderTarget ) { + glBindTexture( GL_TEXTURE_2D, this->renderTarget->textureID[0] ); + } + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-0.5, 0.5, -0.5,0.5,10,40); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glLineWidth( this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512.0); + //if(this->studio%2)render_texture_to_studio(); + //else + render_texture_to_screen(presetOutputs); + + // glClear(GL_COLOR_BUFFER_BIT); + //render_Studio(); + + //preset editing menu + glMatrixMode(GL_MODELVIEW); + glTranslated(-0.5,-0.5,-1); + + // When console refreshes, there is a chance the preset has been changed by the user + refreshConsole(); + draw_title_to_screen(); + if(this->showhelp%2)draw_help(); + if(this->showtitle%2)draw_title(); + if(this->showfps%2)draw_fps(this->realfps); + if(this->showpreset%2)draw_preset(); + if(this->showstats%2)draw_stats(presetInputs); + glTranslatef(0.5 ,0.5,1); + + DWRITE( "end pass2\n" ); +} + + +void Renderer::Interpolation(PresetOutputs *presetOutputs, PresetInputs *presetInputs) +{ + int x,y; + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslated( 0, 0, -1 ); + + glColor4f(0.0, 0.0, 0.0,presetOutputs->decay); + + glEnable(GL_TEXTURE_2D); + +#ifdef MACOS2 + /** Bind the stashed texture */ + if ( this->renderTarget->pbuffer != NULL ) { + glBindTexture( GL_TEXTURE_2D, this->renderTarget->textureID[0] ); +#ifdef DEBUG + if ( glGetError() ) { + DWRITE( "failed to bind texture\n" ); + } +#endif + } +#endif + + for (x=0;xgx - 1;x++){ + glBegin(GL_TRIANGLE_STRIP); + for(y=0;ygy;y++){ + glTexCoord2f(presetInputs->x_mesh[x][y], presetInputs->y_mesh[x][y]); + glVertex2f(this->gridx[x][y], this->gridy[x][y]); + glTexCoord2f(presetInputs->x_mesh[x+1][y], presetInputs->y_mesh[x+1][y]); + glVertex2f(this->gridx[x+1][y], this->gridy[x+1][y]); + } + glEnd(); + } + +#ifdef MACOS2 + /** Re-bind the pbuffer */ + if ( this->renderTarget->pbuffer != NULL ) { + glBindTexture( GL_TEXTURE_2D, this->renderTarget->textureID[0] ); + } +#endif + + glDisable(GL_TEXTURE_2D); + + glPopMatrix(); +} + + +void Renderer::PerFrame(PresetOutputs *presetOutputs) +{ + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslated(0, 0, -9); + + //Texture wrapping( clamp vs. wrap) + if (presetOutputs->bTexWrap==0){ + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);} + else{ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);} + + + // glRasterPos2i(0,0); + // glClear(GL_COLOR_BUFFER_BIT); + // glColor4d(0.0, 0.0, 0.0,1.0); + + // glMatrixMode(GL_TEXTURE); + // glLoadIdentity(); + + glRasterPos2i(0,0); + glClear(GL_COLOR_BUFFER_BIT); + glColor4d(0.0, 0.0, 0.0,1.0); + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + + /* + glTranslatef(presetOutputs->cx,presetOutputs->cy, 0); + if(this->correction) glScalef(1,this->vw/(float)this->vh,1); + + if(!isPerPixelEqn(ROT_OP)) { + // printf("ROTATING: rot = %f\n", rot); + glRotatef(presetOutputs->rot*90, 0, 0, 1); + } + if(!isPerPixelEqn(SX_OP)) glScalef(1/presetOutputs->sx,1,1); + if(!isPerPixelEqn(SY_OP)) glScalef(1,1/presetOutputs->sy,1); + + if(this->correction)glScalef(1,this->vh/(float)this->vw,1); + glTranslatef((-presetOutputs->cx) ,(-presetOutputs->cy),0); + */ + + if(!presetOutputs->dx_is_mesh) glTranslatef(-presetOutputs->dx,0,0); + if(!presetOutputs->dy_is_mesh) glTranslatef(0 ,-presetOutputs->dy,0); + } + + +Renderer::~Renderer() { + + int x; + + for(x = 0; x < this->gx; x++) + { + + free(this->gridx[x]); + free(this->gridy[x]); + free(this->origx2[x]); + free(this->origy2[x]); + + + } + + free(this->origx2); + free(this->origy2); + free(this->gridx); + free(this->gridy); + + + + this->origx2 = NULL; + this->origy2 = NULL; + this->gridx = NULL; + this->gridy = NULL; + +} + + +void Renderer::PerPixelMath(PresetOutputs *presetOutputs, PresetInputs *presetInputs) { + + int x,y; + float fZoom2,fZoom2Inv; + + + + if(!presetOutputs->cx_is_mesh) + { + for (x=0;xgx;x++){ + + for(y=0;ygy;y++){ + presetOutputs->cx_mesh[x][y]=presetOutputs->cx; + } + + } + } + + if(!presetOutputs->cy_is_mesh) + { + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + presetOutputs->cy_mesh[x][y]=presetOutputs->cy; + }} + } + + if(!presetOutputs->sx_is_mesh) + { + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + presetOutputs->sx_mesh[x][y]=presetOutputs->sx; + }} + } + + if(!presetOutputs->sy_is_mesh) + { + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + presetOutputs->sy_mesh[x][y]=presetOutputs->sy; + }} + } + + if(!presetOutputs->zoom_is_mesh) + { + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + presetOutputs->zoom_mesh[x][y]=presetOutputs->zoom; + }} + } + + if(!presetOutputs->zoomexp_is_mesh) + { + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + 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; + } + } + } + + /* + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + x_mesh[x][y]=(x_mesh[x][y]-.5)*2; + } + } + + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + y_mesh[x][y]=(y_mesh[x][y]-.5)*2; + } + } + */ + + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + fZoom2 = powf( presetOutputs->zoom_mesh[x][y], powf( presetOutputs->zoomexp_mesh[x][y], presetInputs->rad_mesh[x][y]*2.0f - 1.0f)); + fZoom2Inv = 1.0f/fZoom2; + presetInputs->x_mesh[x][y]= this->origx2[x][y]*0.5f*fZoom2Inv + 0.5f; + presetInputs->y_mesh[x][y]= this->origy2[x][y]*0.5f*fZoom2Inv + 0.5f; + } + } + + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + presetInputs->x_mesh[x][y] = ( presetInputs->x_mesh[x][y] - presetOutputs->cx_mesh[x][y])/presetOutputs->sx_mesh[x][y] + presetOutputs->cx_mesh[x][y]; + } + } + + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + presetInputs->y_mesh[x][y] = ( presetInputs->y_mesh[x][y] - presetOutputs->cy_mesh[x][y])/presetOutputs->sy_mesh[x][y] + presetOutputs->cy_mesh[x][y]; + } + } + + + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + float u2 = presetInputs->x_mesh[x][y] - presetOutputs->cx_mesh[x][y]; + float v2 = presetInputs->y_mesh[x][y] - presetOutputs->cy_mesh[x][y]; + + float cos_rot = cosf(presetOutputs->rot_mesh[x][y]); + float sin_rot = sinf(presetOutputs->rot_mesh[x][y]); + + presetInputs->x_mesh[x][y] = u2*cos_rot - v2*sin_rot + presetOutputs->cx_mesh[x][y]; + presetInputs->y_mesh[x][y] = u2*sin_rot + v2*cos_rot + presetOutputs->cy_mesh[x][y]; + + } + } + + if(presetOutputs->dx_is_mesh) + { + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + presetInputs->x_mesh[x][y] -= presetOutputs->dx_mesh[x][y]; + } + } + } + + if(presetOutputs->dy_is_mesh) + { + for (x=0;xgx;x++){ + for(y=0;ygy;y++){ + presetInputs->y_mesh[x][y] -= presetOutputs->dy_mesh[x][y]; + } + } + + } + +} + + + +void Renderer::reset(int w, int h) +{ + this->aspect=(float)h / (float)w; + this -> vw = w; + this -> vh = h; + +//FIXME maybe needs called elsewhere + //if (!this->renderTarget->usePbuffers) { + // renderTarge->createPBuffers(w,h,this->renderTarget); + // } + + /* Our shading model--Gouraud (smooth). */ + glShadeModel( GL_SMOOTH); + /* Culling. */ + // glCullFace( GL_BACK ); + // glFrontFace( GL_CCW ); + // glEnable( GL_CULL_FACE ); + /* Set the clear color. */ + glClearColor( 0, 0, 0, 0 ); + /* Setup our viewport. */ + glViewport( 0, 0, w, h ); + /* + * Change to the projection matrix and set + * our viewing volume. + */ + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + + // gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + // glFrustum(0.0, height, 0.0,width,10,40); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glDrawBuffer(GL_BACK); + glReadBuffer(GL_BACK); + glEnable(GL_BLEND); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glEnable( GL_LINE_SMOOTH ); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + + glEnable(GL_POINT_SMOOTH); + + // glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,renderTarget->texsize,renderTarget->texsize,0); + //glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,renderTarget->texsize,renderTarget->texsize); + glLineStipple(2, 0xAAAA); + + /** (Re)create the offscreen for pass 1 */ + + //REME: necesary? + //rescale_per_pixel_matrices(); + + /** Load TTF font **/ + + + +#ifdef USE_FTGL + /**f Load the standard fonts */ + if ( title_font == NULL && other_font == NULL ) { + char path[1024]; + + sprintf( path, "%s%cVera.ttf", this->fontURL, PATH_SEPARATOR ); + title_font = new FTGLPixmapFont(path); + poly_font = new FTGLPolygonFont(path); + sprintf( path, "%s%cVeraMono.ttf", this->fontURL, PATH_SEPARATOR ); + other_font = new FTGLPixmapFont(path); + + } +#endif /** USE_FTGL */ +} + + + + + +void Renderer::draw_custom_waves(PresetOutputs *presetOutputs) { + + int x; + CustomWave *wavecode; + + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + glTranslatef( 0, 0, -1 ); + + glPointSize(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512); + + /// @bug SPERL: this is a starting point at least + for (PresetOutputs::cwave_container::const_iterator pos = presetOutputs->customWaves.begin(); + pos != presetOutputs->customWaves.end(); ++pos) + { + + if(wavecode->enabled==1) + { + + if (wavecode->bAdditive==0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + else glBlendFunc(GL_SRC_ALPHA, GL_ONE); + if (wavecode->bDrawThick==1) glLineWidth(this->renderTarget->texsize < 512 ? 1 : 2*this->renderTarget->texsize/512); + + beatDetect->pcm->getPCM(wavecode->value1,wavecode->samples,0,wavecode->bSpectrum,wavecode->smoothing,0); + beatDetect->pcm->getPCM(wavecode->value2,wavecode->samples,1,wavecode->bSpectrum,wavecode->smoothing,0); + // printf("%f\n",pcmL[0]); + + + float mult=wavecode->scaling*presetOutputs->fWaveScale*(wavecode->bSpectrum ? 0.015f :1.0f); + + for(x=0;xsamples;x++) + {wavecode->value1[x]*=mult;} + + for(x=0;xsamples;x++) + {wavecode->value2[x]*=mult;} + + for(x=0;xsamples;x++) + {wavecode->sample_mesh[x]=((float)x)/((float)(wavecode->samples-1));} + + // printf("mid inner loop\n"); + wavecode->evalPerPointEqns(); + + //put drawing code here + if (wavecode->bUseDots==1) glBegin(GL_POINTS); + else glBegin(GL_LINE_STRIP); + + for(x=0;xsamples;x++) + { + + glColor4f(wavecode->r_mesh[x],wavecode->g_mesh[x],wavecode->b_mesh[x],wavecode->a_mesh[x]); + glVertex3f(wavecode->x_mesh[x],-(wavecode->y_mesh[x]-1),-1); + } + glEnd(); + glPointSize(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512); + glLineWidth(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512); + glDisable(GL_LINE_STIPPLE); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // glPopMatrix(); + + } + + } + + glPopMatrix(); +} + + +void Renderer::draw_shapes(PresetOutputs *presetOutputs) { + + int i; + + float theta; + float radius; + + CustomShape *shapecode; + + float pi = 3.14159265; + float start,inc,xval,yval; + + float t; + + // more=isMoreCustomWave(); + // printf("not inner loop\n"); + + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + glTranslatef( 0, 0, -1 ); + +/// @bug SPERL: this is a starting point at least + for (PresetOutputs::cshape_container::const_iterator pos = presetOutputs->customShapes.begin(); + pos != presetOutputs->customShapes.end(); ++pos) + { + + if(shapecode->enabled==1) + { + // printf("drawing shape %f\n",shapecode->ang); + shapecode->y=-((shapecode->y)-1); + radius=.5; + shapecode->radius=shapecode->radius*(.707*.707*.707*1.04); + //Additive Drawing or Overwrite + if (shapecode->additive==0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + else glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + /* DEPRECATED + if(this->correction) + { + glTranslatef(0.5,0.5, 0); + glScalef(1.0,this->vw/(float)this->vh,1.0); + glTranslatef(-0.5 ,-0.5,0); + } + */ + + xval=shapecode->x; + yval=shapecode->y; + + if (shapecode->textured) + { + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + //glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + //glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + //glTranslatef(.5,.5, 0); + //if (this->correction) glScalef(1,this->vw/(float)this->vh,1); + + //glRotatef((shapecode->tex_ang*360/6.280), 0, 0, 1); + + //glScalef(1/(shapecode->tex_zoom),1/(shapecode->tex_zoom),1); + + // glScalef(1,vh/(float)vw,1); + //glTranslatef((-.5) ,(-.5),0); + // glScalef(1,this->vw/(float)this->vh,1); + glEnable(GL_TEXTURE_2D); + + + glBegin(GL_TRIANGLE_FAN); + glColor4f(0.0,0.0,0.0,shapecode->a); + //glColor4f(shapecode->r,shapecode->g,shapecode->b,shapecode->a); + + glTexCoord2f(.5,.5); + glVertex3f(xval,yval,-1); + //glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2); + glColor4f(0.0,0.0,0.0,shapecode->a2); + + for ( i=1;isides+2;i++) + { + + // theta+=inc; + // glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2); + //glTexCoord2f(radius*cos(theta)+.5 ,radius*sin(theta)+.5 ); + //glVertex3f(shapecode->radius*cos(theta)+xval,shapecode->radius*sin(theta)+yval,-1); + t = (i-1)/(float)shapecode->sides; + + glTexCoord2f( 0.5f + 0.5f*cosf(t*3.1415927f*2 + shapecode->tex_ang + 3.1415927f*0.25f)*(this->correction ? this->aspect : 1.0)/shapecode->tex_zoom, 0.5f + 0.5f*sinf(t*3.1415927f*2 + shapecode->tex_ang + 3.1415927f*0.25f)/shapecode->tex_zoom); + glVertex3f(shapecode->radius*cosf(t*3.1415927f*2 + shapecode->ang + 3.1415927f*0.25f)*(this->correction ? this->aspect : 1.0)+xval, shapecode->radius*sinf(t*3.1415927f*2 + shapecode->ang + 3.1415927f*0.25f)+yval,-1); + } + glEnd(); + + + + + glDisable(GL_TEXTURE_2D); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + } + else{//Untextured (use color values) + //printf("untextured %f %f %f @:%f,%f %f %f\n",shapecode->a2,shapecode->a,shapecode->border_a, shapecode->x,shapecode->y,shapecode->radius,shapecode->ang); + //draw first n-1 triangular pieces + glBegin(GL_TRIANGLE_FAN); + + glColor4f(shapecode->r,shapecode->g,shapecode->b,shapecode->a); + + // glTexCoord2f(.5,.5); + glVertex3f(xval,yval,-1); + glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2); + + for ( i=1;isides+2;i++) + { + + //theta+=inc; + // glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2); + // glTexCoord2f(radius*cos(theta)+.5 ,radius*sin(theta)+.5 ); + //glVertex3f(shapecode->radius*cos(theta)+xval,shapecode->radius*sin(theta)+yval,-1); + + t = (i-1)/(float)shapecode->sides; + glVertex3f(shapecode->radius*cosf(t*3.1415927f*2 + shapecode->ang + 3.1415927f*0.25f)*(this->correction ? this->aspect : 1.0)+xval, shapecode->radius*sinf(t*3.1415927f*2 + shapecode->ang + 3.1415927f*0.25f)+yval,-1); + + } + glEnd(); + + + } + if (presetOutputs->bWaveThick==1) glLineWidth(this->renderTarget->texsize < 512 ? 1 : 2*this->renderTarget->texsize/512); + glBegin(GL_LINE_LOOP); + glColor4f(shapecode->border_r,shapecode->border_g,shapecode->border_b,shapecode->border_a); + for ( i=1;isides+1;i++) + { + + t = (i-1)/(float)shapecode->sides; + glVertex3f(shapecode->radius*cosf(t*3.1415927f*2 + shapecode->ang + 3.1415927f*0.25f)*(this->correction ? this->aspect : 1.0)+xval, shapecode->radius*sinf(t*3.1415927f*2 + shapecode->ang + 3.1415927f*0.25f)+yval,-1); + + //theta+=inc; + //glVertex3f(shapecode->radius*cos(theta)+xval,shapecode->radius*sin(theta)+yval,-1); + } + glEnd(); + if (presetOutputs->bWaveThick==1) glLineWidth(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512); + + glPopMatrix(); + } + } + + glPopMatrix(); +} + + +void Renderer::draw_waveform(PresetOutputs *presetOutputs, PresetInputs *presetInputs) { + + int x; + + float r,theta; + + float offset,scale,dy2_adj; + + float co; + + float wave_x_temp=0; + float wave_y_temp=0; + float dy_adj; + float xx,yy; + + float cos_rot; + float sin_rot; + + DWRITE( "draw_waveform: %d\n", presetOutputs->nWaveMode ); + + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + + modulate_opacity_by_volume(presetOutputs); + maximize_colors(presetOutputs); + + if(presetOutputs->bWaveDots==1) glEnable(GL_LINE_STIPPLE); + + offset=presetOutputs->wave_x-.5; + scale=505.0/512.0; + + + + + //Thick wave drawing + if (presetOutputs->bWaveThick==1) glLineWidth( (this->renderTarget->texsize < 512 ) ? 2 : 2*this->renderTarget->texsize/512); + + //Additive wave drawing (vice overwrite) + if (presetOutputs->bAdditiveWaves==0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + else glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + switch(presetOutputs->nWaveMode) + { + + case 8://monitor + + glTranslatef(0.5,0.5, 0); + glRotated(-presetOutputs->wave_mystery*90,0,0,1); + + glTranslatef(-0.5,-0.825, 0); + glTranslatef( 0, 0, -1 ); + + /* + for (x=0;x<16;x++) + { + glBegin(GL_LINE_STRIP); + glColor4f(1.0-(x/15.0),.5,x/15.0,1.0); + glVertex3f((this->totalframes%256)*2*scale, -this->beat_val[x]*presetOutputs->fWaveScale+renderTarget->texsize*wave_y,-1); + glColor4f(.5,.5,.5,1.0); + glVertex3f((this->totalframes%256)*2*scale, this->renderTarget->texsize*presetOutputs->wave_y,-1); + glColor4f(1.0,1.0,0,1.0); + //glVertex3f((this->totalframes%256)*scale*2, this->beat_val_att[x]*presetOutputs->fWaveScale+this->renderTarget->texsize*presetOutputs->wave_y,-1); + glEnd(); + + glTranslatef(0,this->renderTarget->texsize*(1/36.0), 0); + } + */ + + glTranslatef(0,(1/18.0), 0); + + + glBegin(GL_LINE_STRIP); + glColor4f(1.0,1.0,0.5,1.0); + glVertex2f((this->totalframes%256)*2*scale, beatDetect->treb_att*5*presetOutputs->fWaveScale+presetOutputs->wave_y); + glColor4f(.2,.2,.2,1.0); + glVertex2f((this->totalframes%256)*2*scale, presetOutputs->wave_y); + glColor4f(1.0,1.0,0,1.0); + glVertex2f((this->totalframes%256)*scale*2, beatDetect->treb*-5*presetOutputs->fWaveScale+presetOutputs->wave_y); + glEnd(); + + glTranslatef(0,.075, 0); + glBegin(GL_LINE_STRIP); + glColor4f(0,1.0,0.0,1.0); + glVertex2f((this->totalframes%256)*2*scale, beatDetect->mid_att*5*presetOutputs->fWaveScale+presetOutputs->wave_y); + glColor4f(.2,.2,.2,1.0); + glVertex2f((this->totalframes%256)*2*scale, presetOutputs->wave_y); + glColor4f(.5,1.0,.5,1.0); + glVertex2f((this->totalframes%256)*scale*2, beatDetect->mid*-5*presetOutputs->fWaveScale+presetOutputs->wave_y); + glEnd(); + + + glTranslatef(0,.075, 0); + glBegin(GL_LINE_STRIP); + glColor4f(1.0,0,0,1.0); + glVertex2f((this->totalframes%256)*2*scale, beatDetect->bass_att*5*presetOutputs->fWaveScale+presetOutputs->wave_y); + glColor4f(.2,.2,.2,1.0); + glVertex2f((this->totalframes%256)*2*scale, presetOutputs->wave_y); + glColor4f(1.0,.5,.5,1.0); + glVertex2f((this->totalframes%256)*scale*2, beatDetect->bass*-5*presetOutputs->fWaveScale+presetOutputs->wave_y); + glEnd(); + + break; + + case 0://circular waveforms + // float co; + // glPushMatrix(); + /* + if(this->correction) + { + glTranslatef(this->renderTarget->texsize*.5,this->renderTarget->texsize*.5, 0); + glScalef(1.0,this->vw/(float)this->vh,1.0); + glTranslatef((-this->renderTarget->texsize*.5) ,(-this->renderTarget->texsize*.5),0); + } + */ + + glTranslatef( 0, 0, -1 ); + + presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0); + + glBegin(GL_LINE_STRIP); + + DWRITE( "nsamples: %d\n", beatDetect->pcm->numsamples ); + + for ( x=0;xpcm->numsamples;x++) + { float inv_nverts_minus_one = 1.0f/(float)(beatDetect->pcm->numsamples); + //co= -(fabs(x-((beatDetect->pcm->numsamples*.5)-1))/beatDetect->pcm->numsamples)+1; + // printf("%d %f\n",x,co); + //theta=x*(6.28/beatDetect->pcm->numsamples); + //r= ((1+2*presetOutputs->wave_mystery)*(this->renderTarget->texsize/5.0)+ + // ( co*beatDetect->pcm->pcmdataL[x]+ (1-co)*beatDetect->pcm->pcmdataL[-(x-(beatDetect->pcm->numsamples-1))]) + // *25*presetOutputs->fWaveScale); + r=(0.5 + 0.4f*.12*beatDetect->pcm->pcmdataR[x]*presetOutputs->fWaveScale + presetOutputs->wave_mystery)*.5; + theta=(x)*inv_nverts_minus_one*6.28f + presetInputs->time*0.2f; + /* + if (x < 51) + { + float mix = x/51.0; + mix = 0.5f - 0.5f*cosf(mix * 3.1416f); + float rad_2 = 0.5f + 0.4f*.12*beatDetect->pcm->pcmdataR[x]*presetOutputs->fWaveScale + presetOutputs->wave_mystery; + r = rad_2*(1.0f-mix) + r*(mix); + } + */ + glVertex2f((r*cos(theta)*(this->correction ? this->aspect : 1.0)+presetOutputs->wave_x), (r*sin(theta)+presetOutputs->wave_y)); + + } + + // r= ( (1+2*presetOutputs->wave_mystery)*(this->renderTarget->texsize/5.0)+ + // (0.5*beatDetect->pcm->pcmdataL[0]+ 0.5*beatDetect->pcm->pcmdataL[beatDetect->pcm->numsamples-1]) + // *20*presetOutputs->fWaveScale); + + //glVertex3f(r*cos(0)+(presetOutputs->wave_x*this->renderTarget->texsize),r*sin(0)+(presetOutputs->wave_y*this->renderTarget->texsize),-1); + + glEnd(); + /* + glBegin(GL_LINE_LOOP); + + for ( x=0;x<(512/pcmbreak);x++) + { + theta=(blockstart+x)*((6.28*pcmbreak)/512.0); + r= ((1+2*presetOutputs->wave_mystery)*(this->renderTarget->texsize/5.0)+fdata_buffer[fbuffer][0][blockstart+x]*.0025*presetOutputs->fWaveScale); + + glVertex3f(r*cos(theta)+(presetOutputs->wave_x*this->renderTarget->texsize),r*sin(theta)+(wave_y*this->renderTarget->texsize),-1); + } + glEnd(); + */ + //glPopMatrix(); + + break; + + case 1://circularly moving waveform + // float co; + + glTranslatef(.5,.5, 0); + glScalef(1.0,this->vw/(float)this->vh,1.0); + glTranslatef((-.5) ,(-.5),0); + glTranslatef( 0, 0, -1 ); + + presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0); + + glBegin(GL_LINE_STRIP); + //theta=(frame%512)*(6.28/512.0); + + for ( x=1;x<(512-32);x++) + { + //co= -(abs(x-255)/512.0)+1; + // printf("%d %f\n",x,co); + //theta=((this->frame%256)*(2*6.28/512.0))+beatDetect->pcm->pcmdataL[x]*.2*presetOutputs->fWaveScale; + //r= ((1+2*presetOutputs->wave_mystery)*(this->renderTarget->texsize/5.0)+ + // (beatDetect->pcm->pcmdataL[x]-beatDetect->pcm->pcmdataL[x-1])*80*presetOutputs->fWaveScale); + theta=beatDetect->pcm->pcmdataL[x+32]*0.06*presetOutputs->fWaveScale * 1.57 + presetInputs->time*2.3; + r=(0.53 + 0.43*beatDetect->pcm->pcmdataR[x]*0.12*presetOutputs->fWaveScale+ presetOutputs->wave_mystery)*.5; + + + glVertex2f((r*cos(theta)*(this->correction ? this->aspect : 1.0)+presetOutputs->wave_x),(r*sin(theta)+presetOutputs->wave_y)); + } + + glEnd(); + /* + presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0); + wave_x_temp=(presetOutputs->wave_x*.75)+.125; + wave_x_temp=-(wave_x_temp-1); + + glBegin(GL_LINE_STRIP); + + + + for (x=0; x<512-32; x++) + { + float rad = (.53 + 0.43*beatDetect->pcm->pcmdataR[x]) + presetOutputs->wave_mystery; + float ang = beatDetect->pcm->pcmdataL[x+32] * 1.57f + this->Time*2.3f; + glVertex3f((rad*cosf(ang)*.2*scale*presetOutputs->fWaveScale + wave_x_temp)*this->renderTarget->texsize,(rad*sinf(ang)*presetOutputs->fWaveScale*.2*scale + presetOutputs->wave_y)*this->renderTarget->texsize,-1); + + } + glEnd(); + */ + + break; + + case 2://EXPERIMENTAL + + glTranslatef( 0, 0, -1 ); + presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0); + + + glBegin(GL_LINE_STRIP); + + for (x=0; x<512-32; x++) + { + + glVertex2f((beatDetect->pcm->pcmdataR[x]*presetOutputs->fWaveScale*0.5*(this->correction ? this->aspect : 1.0) + presetOutputs->wave_x),( (beatDetect->pcm->pcmdataL[x+32]*presetOutputs->fWaveScale*0.5 + presetOutputs->wave_y))); + } + glEnd(); + + break; + + case 3://EXPERIMENTAL + + glTranslatef( 0, 0, -9 ); + presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0); + //wave_x_temp=(presetOutputs->wave_x*.75)+.125; + //wave_x_temp=-(wave_x_temp-1); + + + + glBegin(GL_LINE_STRIP); + + for (x=0; x<512-32; x++) + { + + glVertex2f((beatDetect->pcm->pcmdataR[x] * presetOutputs->fWaveScale*0.5 + presetOutputs->wave_x),( (beatDetect->pcm->pcmdataL[x+32]*presetOutputs->fWaveScale*0.5 + presetOutputs->wave_y))); + + } + glEnd(); + + break; + + case 4://single x-axis derivative waveform + { + presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0); + glTranslatef(.5,.5, 0); + glRotated(-presetOutputs->wave_mystery*90,0,0,1); + glTranslatef(-.5,-.5, 0); + glTranslatef( 0, 0, -1 ); + + float w1 = 0.45f + 0.5f*(presetOutputs->wave_mystery*0.5f + 0.5f); + float w2 = 1.0f - w1; + float xx[512],yy[512]; + + glBegin(GL_LINE_STRIP); + for (int i=0; i<512; i++) + { + xx[i] = -1.0f + 2.0f*(i/512.0) + presetOutputs->wave_x; + yy[i] =0.4* beatDetect->pcm->pcmdataL[i]*0.47f*presetOutputs->fWaveScale + presetOutputs->wave_y; + xx[i] += 0.4*beatDetect->pcm->pcmdataR[i]*0.44f*presetOutputs->fWaveScale; + + if (i>1) + { + xx[i] = xx[i]*w2 + w1*(xx[i-1]*2.0f - xx[i-2]); + yy[i] = yy[i]*w2 + w1*(yy[i-1]*2.0f - yy[i-2]); + } + glVertex2f(xx[i],yy[i]); + } + + glEnd(); + + /* + presetOutputs->wave_x=(presetOutputs->wave_x*.75)+.125; + presetOutputs->wave_x=-(presetOutputs->wave_x-1); + glBegin(GL_LINE_STRIP); + + for ( x=1;x<512;x++) + { + dy_adj= beatDetect->pcm->pcmdataL[x]*20*presetOutputs->fWaveScale-beatDetect->pcm->pcmdataL[x-1]*20*presetOutputs->fWaveScale; + glVertex3f((x*(this->renderTarget->texsize/512))+dy_adj, beatDetect->pcm->pcmdataL[x]*20*presetOutputs->fWaveScale+this->renderTarget->texsize*presetOutputs->wave_x,-1); + } + glEnd(); + */ + } + break; + + case 5://EXPERIMENTAL + + glTranslatef( 0, 0, -5 ); + + presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0); + + cos_rot = cosf(presetInputs->time*0.3f); + sin_rot = sinf(presetInputs->time*0.3f); + + glBegin(GL_LINE_STRIP); + + for (x=0; x<512; x++) + { + float x0 = (beatDetect->pcm->pcmdataR[x]*beatDetect->pcm->pcmdataL[x+32] + beatDetect->pcm->pcmdataL[x+32]*beatDetect->pcm->pcmdataR[x]); + float y0 = (beatDetect->pcm->pcmdataR[x]*beatDetect->pcm->pcmdataR[x] - beatDetect->pcm->pcmdataL[x+32]*beatDetect->pcm->pcmdataL[x+32]); + + glVertex2f(((x0*cos_rot - y0*sin_rot)*presetOutputs->fWaveScale*0.5*(this->correction ? this->aspect : 1.0) + presetOutputs->wave_x),( (x0*sin_rot + y0*cos_rot)*presetOutputs->fWaveScale*0.5 + presetOutputs->wave_y)); + + } + glEnd(); + + + break; + + case 6://single waveform + + + //glMatrixMode(GL_MODELVIEW); + // glLoadIdentity(); + + glTranslatef(.5,.5, 0); + glRotated(-presetOutputs->wave_mystery*90,0,0,1); + glTranslatef(0,0, -1); + + wave_x_temp=-2*0.4142*(fabs(fabs(presetOutputs->wave_mystery)-.5)-.5); + glScalef(1.0+wave_x_temp,1.0,1.0); + glTranslatef(-.5,-.5, 0); + wave_x_temp=-1*(presetOutputs->wave_x-1.0); + + glBegin(GL_LINE_STRIP); + // wave_x_temp=(wave_x*.75)+.125; + // wave_x_temp=-(wave_x_temp-1); + for ( x=0;xpcm->numsamples;x++) + { + + //glVertex3f(x*scale, fdata_buffer[fbuffer][0][blockstart+x]*.0012*fWaveScale+renderTarget->texsize*wave_x_temp,-1); + glVertex2f(x/(float)beatDetect->pcm->numsamples, beatDetect->pcm->pcmdataR[x]*.04*presetOutputs->fWaveScale+wave_x_temp); + + //glVertex3f(x*scale, renderTarget->texsize*wave_y_temp,-1); + } + // printf("%f %f\n",renderTarget->texsize*wave_y_temp,wave_y_temp); + glEnd(); + break; + + case 7://dual waveforms + + glTranslatef(.5,.5, 0); + glRotated(-presetOutputs->wave_mystery*90,0,0,1); + + wave_x_temp=-2*0.4142*(fabs(fabs(presetOutputs->wave_mystery)-.5)-.5); + glScalef(1.0+wave_x_temp,1.0,1.0); + glTranslatef(-.5,-.5, -1); + glTranslatef( 0, 0, -1 ); + + wave_y_temp=-1*(presetOutputs->wave_x-1); + + glBegin(GL_LINE_STRIP); + + for ( x=0;xpcm->numsamples;x++) + { + + glVertex2f(x/(float)beatDetect->pcm->numsamples, beatDetect->pcm->pcmdataL[x]*.04*presetOutputs->fWaveScale+(wave_y_temp+(presetOutputs->wave_y*presetOutputs->wave_y*.5))); + } + glEnd(); + + glBegin(GL_LINE_STRIP); + + + for ( x=0;xpcm->numsamples;x++) + { + + glVertex2f(x/(float)beatDetect->pcm->numsamples, beatDetect->pcm->pcmdataR[x]*.04*presetOutputs->fWaveScale+(wave_y_temp-(presetOutputs->wave_y*presetOutputs->wave_y*.5))); + } + glEnd(); + glPopMatrix(); + break; + + default: + glTranslatef( 0, 0, -1 ); + glBegin(GL_LINE_LOOP); + + for ( x=0;x<512;x++) + { + theta=(x)*(6.28/512.0); + r= (0.2+beatDetect->pcm->pcmdataL[x]*.002); + + glVertex2f(r*cos(theta)+presetOutputs->wave_x,r*sin(theta)+presetOutputs->wave_y); + } + glEnd(); + +glBegin(GL_LINE_STRIP); + + for ( x=0;x<512;x++) + { + glVertex3f(x*scale, beatDetect->pcm->pcmdataL[x]*.04*presetOutputs->fWaveScale+((presetOutputs->wave_x+.1)),-1); + } + glEnd(); + + glBegin(GL_LINE_STRIP); + + for ( x=0;x<512;x++) + { + glVertex3f(x*scale, beatDetect->pcm->pcmdataR[x]*.04*presetOutputs->fWaveScale+((presetOutputs->wave_x-.1)),-1); + + } + glEnd(); + break; + if (presetOutputs->bWaveThick==1) glLineWidth( (this->renderTarget->texsize < 512) ? 1 : 2*this->renderTarget->texsize/512); +} + glLineWidth( this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512); + glDisable(GL_LINE_STIPPLE); + + glPopMatrix(); +} + +void Renderer::maximize_colors(PresetOutputs *presetOutputs) { + + float wave_r_switch=0,wave_g_switch=0,wave_b_switch=0; + //wave color brightening + // + //forces max color value to 1.0 and scales + // the rest accordingly + if(presetOutputs->nWaveMode==2 || presetOutputs->nWaveMode==5) + { + switch(this->renderTarget->texsize) + { + case 256: presetOutputs->wave_o *= 0.07f; break; + case 512: presetOutputs->wave_o *= 0.09f; break; + case 1024: presetOutputs->wave_o *= 0.11f; break; + case 2048: presetOutputs->wave_o *= 0.13f; break; + } + } + + else if(presetOutputs->nWaveMode==3) + { + switch(this->renderTarget->texsize) + { + case 256: presetOutputs->wave_o *= 0.075f; break; + case 512: presetOutputs->wave_o *= 0.15f; break; + case 1024: presetOutputs->wave_o *= 0.22f; break; + case 2048: presetOutputs->wave_o *= 0.33f; break; + } + presetOutputs->wave_o*=1.3f; + presetOutputs->wave_o*=powf(beatDetect->treb ,2.0f); + } + + if (presetOutputs->bMaximizeWaveColor==1) + { + if(presetOutputs->wave_r>=presetOutputs->wave_g && presetOutputs->wave_r>=presetOutputs->wave_b) //red brightest + { + wave_b_switch=presetOutputs->wave_b*(1/presetOutputs->wave_r); + wave_g_switch=presetOutputs->wave_g*(1/presetOutputs->wave_r); + wave_r_switch=1.0; + } + else if (presetOutputs->wave_b>=presetOutputs->wave_g && presetOutputs->wave_b>=presetOutputs->wave_r) //blue brightest + { + wave_r_switch=presetOutputs->wave_r*(1/presetOutputs->wave_b); + wave_g_switch=presetOutputs->wave_g*(1/presetOutputs->wave_b); + wave_b_switch=1.0; + + } + + else if (presetOutputs->wave_g>=presetOutputs->wave_b && presetOutputs->wave_g>=presetOutputs->wave_r) //green brightest + { + wave_b_switch=presetOutputs->wave_b*(1/presetOutputs->wave_g); + wave_r_switch=presetOutputs->wave_r*(1/presetOutputs->wave_g); + wave_g_switch=1.0; + } + + + glColor4f(wave_r_switch, wave_g_switch, wave_b_switch, presetOutputs->wave_o); + } + else + { + glColor4f(presetOutputs->wave_r, presetOutputs->wave_g, presetOutputs->wave_b, presetOutputs->wave_o); + } + +} + +void Renderer::darken_center() { + + float unit=0.05f; + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glTranslatef(0.5,0.5, 0); + + glBegin(GL_TRIANGLE_FAN); + glColor4f(0,0,0,3.0f/32.0f); + glVertex3f(0,0,-1); + glColor4f(0,0,0,-1); + glVertex3f(-unit,0,-1); + glVertex3f(0,-unit,-1); + glVertex3f(unit,0,-1); + glVertex3f(0,unit,-1); + glVertex3f(-unit,0,-1); + glEnd(); + + glPopMatrix(); +} + + +void Renderer::modulate_opacity_by_volume(PresetOutputs *presetOutputs) { + + //modulate volume by opacity + // + //set an upper and lower bound and linearly + //calculate the opacity from 0=lower to 1=upper + //based on current volume + + + if (presetOutputs->bModWaveAlphaByVolume==1) + {if (beatDetect->vol<=presetOutputs->fModWaveAlphaStart) presetOutputs->wave_o=0.0; + else if (beatDetect->vol>=presetOutputs->fModWaveAlphaEnd) presetOutputs->wave_o=presetOutputs->fWaveAlpha; + else presetOutputs->wave_o=presetOutputs->fWaveAlpha*((beatDetect->vol-presetOutputs->fModWaveAlphaStart)/(presetOutputs->fModWaveAlphaEnd-presetOutputs->fModWaveAlphaStart));} + else presetOutputs->wave_o=presetOutputs->fWaveAlpha; +} + +void Renderer::draw_motion_vectors(PresetOutputs *presetOutputs) { + + int x,y; + + float offsetx=presetOutputs->mv_dx, intervalx=1.0/(float)presetOutputs->mv_x; + float offsety=presetOutputs->mv_dy, intervaly=1.0/(float)presetOutputs->mv_y; + + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glPointSize(presetOutputs->mv_l); + glColor4f(presetOutputs->mv_r, presetOutputs->mv_g, presetOutputs->mv_b, presetOutputs->mv_a); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslatef( 0, 0, -1 ); + + glBegin(GL_POINTS); + for (x=0;xmv_x;x++){ + for(y=0;ymv_y;y++){ + float lx, ly, lz; + lx = offsetx+x*intervalx; + ly = offsety+y*intervaly; + lz = -1; + glVertex2f(lx,ly); + } + } + + glEnd(); + + glPopMatrix(); +} + + +void Renderer::draw_borders(PresetOutputs *presetOutputs) { + + //Draw Borders + float of=presetOutputs->ob_size*.5; + float iff=presetOutputs->ib_size*.5; + float texof=1.0-of; + + //no additive drawing for borders + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glColor4d(presetOutputs->ob_r,presetOutputs->ob_g,presetOutputs->ob_b,presetOutputs->ob_a); + + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + glTranslatef( 0, 0, -1 ); + + glRectd(0,0,of,1); + glRectd(of,0,texof,of); + glRectd(texof,0,1,1); + glRectd(of,1,texof,texof); + glColor4d(presetOutputs->ib_r,presetOutputs->ib_g,presetOutputs->ib_b,presetOutputs->ib_a); + glRectd(of,of,of+iff,texof); + glRectd(of+iff,of,texof-iff,of+iff); + glRectd(texof-iff,of,texof,texof); + glRectd(of+iff,texof,texof-iff,texof-iff); + + glPopMatrix(); +} + + + +void Renderer::draw_title_to_texture() { + +#ifdef USE_FTGL + if (this->drawtitle>80) + // if(1) + { + glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + glColor4f(1.0,1.0,1.0,1.0); + glPushMatrix(); + + glTranslatef(0,0.5, -1); + + glScalef(0.0025,-0.0025,30*.0025); + //glTranslatef(0,0, 1.0); + poly_font->FaceSize( 22); + + glRasterPos2f(0.0, 0.0); + + if ( this->title != NULL ) { + poly_font->Render(this->title ); + } else { + poly_font->Render("Unknown" ); + } + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glPopMatrix(); + this->drawtitle=0; + } +#endif /** USE_FTGL */ +} + +void Renderer::draw_title_to_screen() { + +#ifdef USE_FTGL + if(this->drawtitle>0) + { + float easein = ((80-this->drawtitle)*.0125); + float easein2 = easein * easein; + float easein3 = .0025/((-easein2)+1.0); + + glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + glColor4f(1.0,1.0,1.0,1.0); + glPushMatrix(); + + + //glTranslatef(this->vw*.5,this->vh*.5 , -1.0); + glTranslatef(0,0.5 , -1.0); + + glScalef(easein3,easein3,30*.0025); + + glRotatef(easein2*360,1,0,0); + + + //glTranslatef(-.5*this->vw,0, 0.0); + + //poly_font->Depth(1.0); + poly_font->FaceSize(22); + + glRasterPos2f(0.0, 0.0); + if ( this->title != NULL ) { + poly_font->Render(this->title ); + } else { + poly_font->Render("Unknown" ); + } + // poly_font->Depth(0.0); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glPopMatrix(); + + this->drawtitle++; + + } +#endif /** USE_FTGL */ +} + +void Renderer::draw_title() { +#ifdef USE_FTGL + //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + + glColor4f(1.0,1.0,1.0,1.0); + // glPushMatrix(); + // glTranslatef(this->vw*.001,this->vh*.03, -1); + // glScalef(this->vw*.015,this->vh*.025,0); + + glRasterPos2f(0.01, 0.05); + title_font->FaceSize( (unsigned)(20*(this->vh/512.0))); + + if ( this->title != NULL ) { + title_font->Render(this->title ); + } else { + title_font->Render("Unknown" ); + } + // glPopMatrix(); + //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + +#endif /** USE_FTGL */ +} +void Renderer::draw_preset() { +#ifdef USE_FTGL + //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + + glColor4f(1.0,1.0,1.0,1.0); + // glPushMatrix(); + //glTranslatef(this->vw*.001,this->vh*-.01, -1); + //glScalef(this->vw*.003,this->vh*.004,0); + + + glRasterPos2f(0.01, 0.01); + + title_font->FaceSize((unsigned)(12*(this->vh/512.0))); + if(this->noSwitch) title_font->Render("[LOCKED] " ); + title_font->FaceSize((unsigned)(20*(this->vh/512.0))); + if (this->presetName) + title_font->Render(this->presetName ); + + + + //glPopMatrix(); + // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); +#endif /** USE_FTGL */ +} + +void Renderer::draw_help( ) { + +#ifdef USE_FTGL +//glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + DWRITE("pre-help"); + glColor4f(1.0,1.0,1.0,1.0); + glPushMatrix(); + glTranslatef(0,1, 0); + //glScalef(this->vw*.02,this->vh*.02 ,0); + + + title_font->FaceSize((unsigned)( 18*(this->vh/512.0))); + + glRasterPos2f(0.01, -0.05); + title_font->Render("Help"); + + glRasterPos2f(0.01, -0.09); + title_font->Render("----------------------------"); + + glRasterPos2f(0.01, -0.13); + title_font->Render("F1: This help menu"); + + glRasterPos2f(0.01, -0.17); + title_font->Render("F2: Show song title"); + + glRasterPos2f(0.01, -0.21); + title_font->Render("F3: Show preset name"); + + glRasterPos2f(0.01, -0.25); + title_font->Render("F4: Show Rendering Settings"); + + glRasterPos2f(0.01, -0.29); + title_font->Render("F5: Show FPS"); + + glRasterPos2f(0.01, -0.35); + title_font->Render("F: Fullscreen"); + + glRasterPos2f(0.01, -0.39); + title_font->Render("L: Lock/Unlock Preset"); + + glRasterPos2f(0.01, -0.43); + title_font->Render("M: Show Menu"); + + glRasterPos2f(0.01, -0.49); + title_font->Render("R: Random preset"); + glRasterPos2f(0.01, -0.53); + title_font->Render("N: Next preset"); + + glRasterPos2f(0.01, -0.57); + title_font->Render("P: Previous preset"); + + glPopMatrix(); + // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + DWRITE("post-help"); +#endif /** USE_FTGL */ +} + +void Renderer::draw_stats(PresetInputs *presetInputs) { + +#ifdef USE_FTGL + char buffer[128]; + float offset= (this->showfps%2 ? -0.05 : 0.0); + // glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + + glColor4f(1.0,1.0,1.0,1.0); + glPushMatrix(); + glTranslatef(0.01,1, 0); + glRasterPos2f(0, -.05+offset); + other_font->Render(this->correction ? " aspect: corrected" : " aspect: stretched"); +sprintf( buffer, " (%f)", this->aspect); + other_font->Render(buffer); + + + + glRasterPos2f(0, -.09+offset); + other_font->FaceSize((unsigned)(18*(this->vh/512.0))); + + sprintf( buffer, " texsize: %d", this->renderTarget->texsize); + other_font->Render(buffer); + + glRasterPos2f(0, -.13+offset); + sprintf( buffer, "viewport: %d x %d", this->vw, this->vh); + other_font->Render(buffer); + /* REME: FIX + glRasterPos2f(0, -.17+offset); + other_font->Render((this->renderer->renderTarget->usePbuffers ? " FBO: on" : " FBO: off")); + */ + glRasterPos2f(0, -.21+offset); + sprintf( buffer, " mesh: %d x %d", presetInputs->gx,presetInputs->gy); + other_font->Render(buffer); + + + glPopMatrix(); + // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + + +#endif /** USE_FTGL */ +} +void Renderer::draw_fps( float realfps ) { +#ifdef USE_FTGL + char bufferfps[20]; + sprintf( bufferfps, "%.1f fps", realfps); + // glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + + glColor4f(1.0,1.0,1.0,1.0); + glPushMatrix(); + glTranslatef(0.01,1, 0); + glRasterPos2f(0, -0.05); + title_font->FaceSize((unsigned)(20*(this->vh/512.0))); + title_font->Render(bufferfps); + + glPopMatrix(); + // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + +#endif /** USE_FTGL */ +} + + +//Actually draws the texture to the screen +// +//The Video Echo effect is also applied here +void Renderer::render_texture_to_screen(PresetOutputs *presetOutputs) { + + int flipx=1,flipy=1; + //glBindTexture( GL_TEXTURE_2D,this->renderTarget->textureID[0] ); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + + glClear( GL_DEPTH_BUFFER_BIT ); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -15); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); + + // glClear(GL_ACCUM_BUFFER_BIT); + glColor4d(0.0, 0.0, 0.0,1.0f); + + DWRITE( "rendering texture to screen\n" ); + + glBegin(GL_QUADS); + glVertex3d( 0, 0, -1 ); + glVertex4d(-0.5,-0.5,-1,1); + glVertex4d(-0.5, 0.5,-1,1); + glVertex4d(0.5, 0.5,-1,1); + glVertex4d(0.5, -0.5,-1,1); + glEnd(); + + + glEnable(GL_TEXTURE_2D); + //glBindTexture( GL_TEXTURE_2D, this->renderTarget->textureID[0] ); +// glBindTexture( GL_TEXTURE_2D, this->renderTarget->textureID ); + + // glAccum(GL_LOAD,0); + // if (bDarken==1) glBlendFunc(GL_SRC_COLOR,GL_ZERO); + + //Draw giant rectangle and texture it with our texture! + glBegin(GL_QUADS); + glTexCoord4d(0, 1,0,1); glVertex4d(-0.5,-0.5,-1,1); + glTexCoord4d(0, 0,0,1); glVertex4d(-0.5, 0.5,-1,1); + glTexCoord4d(1, 0,0,1); glVertex4d(0.5, 0.5,-1,1); + glTexCoord4d(1, 1,0,1); glVertex4d(0.5, -0.5,-1,1); + glEnd(); + + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + // if (bDarken==1) glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_ALPHA); + + // if (bDarken==1) { glAccum(GL_ACCUM,1-fVideoEchoAlpha); glBlendFunc(GL_SRC_COLOR,GL_ZERO); } + + glMatrixMode(GL_TEXTURE); + + //draw video echo + glColor4f(0.0, 0.0, 0.0,presetOutputs->fVideoEchoAlpha); + glTranslatef(.5,.5,0); + glScalef(1.0/presetOutputs->fVideoEchoZoom,1.0/presetOutputs->fVideoEchoZoom,1); + glTranslatef(-.5,-.5,0); + + switch (((int)presetOutputs->nVideoEchoOrientation)) + { + case 0: flipx=1;flipy=1;break; + case 1: flipx=-1;flipy=1;break; + case 2: flipx=1;flipy=-1;break; + case 3: flipx=-1;flipy=-1;break; + default: flipx=1;flipy=1; break; + } + glBegin(GL_QUADS); + glTexCoord4d(0, 1,0,1); glVertex4f(-0.5*flipx,-0.5*flipy,-1,1); + glTexCoord4d(0, 0,0,1); glVertex4f(-0.5*flipx, 0.5*flipy,-1,1); + glTexCoord4d(1, 0,0,1); glVertex4f(0.5*flipx, 0.5*flipy,-1,1); + glTexCoord4d(1, 1,0,1); glVertex4f(0.5*flipx, -0.5*flipy,-1,1); + glEnd(); + + + glDisable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + + if (presetOutputs->bBrighten==1) + { + glColor4f(1.0, 1.0, 1.0,1.0); + glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + glBegin(GL_QUADS); + glVertex4f(-0.5*flipx,-0.5*flipy,-1,1); + glVertex4f(-0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, -0.5*flipy,-1,1); + glEnd(); + glBlendFunc(GL_ZERO, GL_DST_COLOR); + glBegin(GL_QUADS); + glVertex4f(-0.5*flipx,-0.5*flipy,-1,1); + glVertex4f(-0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, -0.5*flipy,-1,1); + glEnd(); + glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + glBegin(GL_QUADS); + glVertex4f(-0.5*flipx,-0.5*flipy,-1,1); + glVertex4f(-0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, -0.5*flipy,-1,1); + glEnd(); + + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + } + + if (presetOutputs->bDarken==1) + { + + glColor4f(1.0, 1.0, 1.0,1.0); + glBlendFunc(GL_ZERO,GL_DST_COLOR); + glBegin(GL_QUADS); + glVertex4f(-0.5*flipx,-0.5*flipy,-1,1); + glVertex4f(-0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, -0.5*flipy,-1,1); + glEnd(); + + + + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + } + + + if (presetOutputs->bSolarize) + { + + glColor4f(1.0, 1.0, 1.0,1.0); + glBlendFunc(GL_ZERO,GL_ONE_MINUS_DST_COLOR); + glBegin(GL_QUADS); + glVertex4f(-0.5*flipx,-0.5*flipy,-1,1); + glVertex4f(-0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, -0.5*flipy,-1,1); + glEnd(); + glBlendFunc(GL_DST_COLOR,GL_ONE); + glBegin(GL_QUADS); + glVertex4f(-0.5*flipx,-0.5*flipy,-1,1); + glVertex4f(-0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, -0.5*flipy,-1,1); + glEnd(); + + + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + } + + if (presetOutputs->bInvert) + { + glColor4f(1.0, 1.0, 1.0,1.0); + glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + glBegin(GL_QUADS); + glVertex4f(-0.5*flipx,-0.5*flipy,-1,1); + glVertex4f(-0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, -0.5*flipy,-1,1); + glEnd(); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + } +} +/* +void Renderer::render_texture_to_studio() { + + int x,y; + int flipx=1,flipy=1; + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + + glClear( GL_DEPTH_BUFFER_BIT ); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -15); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); + + // glClear(GL_ACCUM_BUFFER_BIT); + glColor4f(0.0, 0.0, 0.0,0.04); + + + glBegin(GL_QUADS); + glVertex4d(-0.5,-0.5,-1,1); + glVertex4d(-0.5, 0.5,-1,1); + glVertex4d(0.5, 0.5,-1,1); + glVertex4d(0.5, -0.5,-1,1); + glEnd(); + + + glColor4f(0.0, 0.0, 0.0,1.0); + + glBegin(GL_QUADS); + glVertex4d(-0.5,0,-1,1); + glVertex4d(-0.5, 0.5,-1,1); + glVertex4d(0.5, 0.5,-1,1); + glVertex4d(0.5, 0,-1,1); + glEnd(); + + glBegin(GL_QUADS); + glVertex4d(0,-0.5,-1,1); + glVertex4d(0, 0.5,-1,1); + glVertex4d(0.5, 0.5,-1,1); + glVertex4d(0.5, -0.5,-1,1); + glEnd(); + + glPushMatrix(); + glTranslatef(.25, .25, 0); + glScalef(.5,.5,1); + + glEnable(GL_TEXTURE_2D); + + + //Draw giant rectangle and texture it with our texture! + glBegin(GL_QUADS); + glTexCoord4d(0, 1,0,1); glVertex4d(-0.5,-0.5,-1,1); + glTexCoord4d(0, 0,0,1); glVertex4d(-0.5, 0.5,-1,1); + glTexCoord4d(1, 0,0,1); glVertex4d(0.5, 0.5,-1,1); + glTexCoord4d(1, 1,0,1); glVertex4d(0.5, -0.5,-1,1); + glEnd(); + + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + + glMatrixMode(GL_TEXTURE); + + //draw video echo + glColor4f(0.0, 0.0, 0.0,presetOutputs->fVideoEchoAlpha); + glTranslated(.5,.5,0); + glScaled(1/presetOutputs->fVideoEchoZoom,1/presetOutputs->fVideoEchoZoom,1); + glTranslated(-.5,-.5,0); + + switch (((int)presetOutputs->nVideoEchoOrientation)) + { + case 0: flipx=1;flipy=1;break; + case 1: flipx=-1;flipy=1;break; + case 2: flipx=1;flipy=-1;break; + case 3: flipx=-1;flipy=-1;break; + default: flipx=1;flipy=1; break; + } + glBegin(GL_QUADS); + glTexCoord4d(0, 1,0,1); glVertex4f(-0.5*flipx,-0.5*flipy,-1,1); + glTexCoord4d(0, 0,0,1); glVertex4f(-0.5*flipx, 0.5*flipy,-1,1); + glTexCoord4d(1, 0,0,1); glVertex4f(0.5*flipx, 0.5*flipy,-1,1); + glTexCoord4d(1, 1,0,1); glVertex4f(0.5*flipx, -0.5*flipy,-1,1); + glEnd(); + + + //glDisable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + // if (bDarken==1) { glAccum(GL_ACCUM,fVideoEchoAlpha); glAccum(GL_RETURN,1);} + + + if (presetOutputs->bInvert) + { + glColor4f(1.0, 1.0, 1.0,1.0); + glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + glBegin(GL_QUADS); + glVertex4f(-0.5*flipx,-0.5*flipy,-1,1); + glVertex4f(-0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, 0.5*flipy,-1,1); + glVertex4f(0.5*flipx, -0.5*flipy,-1,1); + glEnd(); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + } + + // glTranslated(.5,.5,0); + // glScaled(1/fVideoEchoZoom,1/fVideoEchoZoom,1); + // glTranslated(-.5,-.5,0); + //glTranslatef(0,.5*vh,0); + + + //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); + + glDisable(GL_TEXTURE_2D); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glPushMatrix(); + glTranslatef(.25, -.25, 0); + glScalef(.5,.5,1); + glColor4f(1.0,1.0,1.0,1.0); + + for (x=0;xgx;x++){ + glBegin(GL_LINE_STRIP); + for(y=0;ygy;y++){ + glVertex4f((presetInputs->x_mesh[x][y]-.5), (presetInputs->y_mesh[x][y]-.5),-1,1); + //glVertex4f((origx[x+1][y]-.5) * vw, (origy[x+1][y]-.5) *vh ,-1,1); + } + glEnd(); + } + + for (y=0;ygy;y++){ + glBegin(GL_LINE_STRIP); + for(x=0;xgx;x++){ + glVertex4f((presetInputs->x_mesh[x][y]-.5), (presetInputs->y_mesh[x][y]-.5),-1,1); + //glVertex4f((origx[x+1][y]-.5) * vw, (origy[x+1][y]-.5) *vh ,-1,1); + } + glEnd(); + } + + glEnable( GL_TEXTURE_2D ); + + + // glTranslated(-.5,-.5,0); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + // Waveform display -- bottom-left + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslatef(-.5,0, 0); + + glTranslatef(0,-0.10, 0); + glBegin(GL_LINE_STRIP); + glColor4f(0,1.0,1.0,1.0); + glVertex3f((((this->totalframes%256)/551.0)), beatDetect->treb_att*-7,-1); + glColor4f(1.0,1.0,1.0,1.0); + glVertex3f((((this->totalframes%256)/551.0)),0 ,-1); + glColor4f(.5,1.0,1.0,1.0); + glVertex3f((((this->totalframes%256)/551.0)), beatDetect->treb*7,-1); + glEnd(); + + glTranslatef(0,-0.13, 0); + glBegin(GL_LINE_STRIP); + glColor4f(0,1.0,0.0,1.0); + glVertex3f((((this->totalframes%256)/551.0)), beatDetect->mid_att*-7,-1); + glColor4f(1.0,1.0,1.0,1.0); + glVertex3f((((this->totalframes%256)/551.0)),0 ,-1); + glColor4f(.5,1.0,0.0,0.5); + glVertex3f((((this->totalframes%256)/551.0)), beatDetect->mid*7,-1); + glEnd(); + + + glTranslatef(0,-0.13, 0); + glBegin(GL_LINE_STRIP); + glColor4f(1.0,0.0,0.0,1.0); + glVertex3f((((this->totalframes%256)/551.0)), beatDetect->bass_att*-7,-1); + glColor4f(1.0,1.0,1.0,1.0); + glVertex3f((((this->totalframes%256)/551.0)),0 ,-1); + glColor4f(.7,0.2,0.2,1.0); + glVertex3f((((this->totalframes%256)/551.0)), beatDetect->bass*7,-1); + glEnd(); + + glTranslatef(0,-0.13, 0); + glBegin(GL_LINES); + + glColor4f(1.0,1.0,1.0,1.0); + glVertex3f((((this->totalframes%256)/551.0)),0 ,-1); + glColor4f(1.0,0.6,1.0,1.0); + glVertex3f((((this->totalframes%256)/551.0)), beatDetect->vol*7,-1); + glEnd(); + + glPopMatrix(); + + glDisable(GL_TEXTURE_2D); +} + +*/ + diff --git a/src/projectM-engine-backup/Renderer.hpp b/src/projectM-engine-backup/Renderer.hpp new file mode 100644 index 000000000..128ba663a --- /dev/null +++ b/src/projectM-engine-backup/Renderer.hpp @@ -0,0 +1,93 @@ +#ifndef Renderer_HPP +#define Renderer_HPP + +#include "PBuffer.hpp" +#include "PresetFrameIO.hpp" +#include "BeatDetect.hpp" + +#ifdef USE_FTGL +#include +#include +#include +#endif /** USE_FTGL */ + +class BeatDetect; + +class Renderer +{ + RenderTarget *renderTarget; + BeatDetect *beatDetect; + //per pixel equation variables + float **gridx; //grid containing interpolated mesh + float **gridy; + float **origx2; //original mesh + float **origy2; + int gx; + int gy; + + int vw; + int vh; + + float aspect; + + + + public: + /// @bug hack to get glConsol + +#ifdef USE_FTGL +FTGLPixmapFont *title_font; +FTGLPixmapFont *other_font; +FTGLPolygonFont *poly_font; +#endif /** USE_FTGL */ + + int showfps; + int showtitle; + int showpreset; + int showhelp; + int showstats; + + int studio; + int correction; + + char *presetName; + char *fontURL; + + int noSwitch; + + int totalframes; +float realfps; +char *title; + int drawtitle; + + Renderer( int width, int height, int gx, int gy, RenderTarget *renderTarget, BeatDetect *beatDetect, char *fontURL); + ~Renderer(); + void RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInputs); + void reset(int w, int h); + +private: + + void PerFrame(PresetOutputs *presetOutputs); + void Interpolation(PresetOutputs *presetOutputs, PresetInputs *presetInputs); + void PerPixelMath(PresetOutputs *presetOutputs, PresetInputs *presetInputs); + void rescale_per_pixel_matrices(); + void maximize_colors(PresetOutputs *presetOutputs); + void render_texture_to_screen(PresetOutputs *presetOutputs); + void draw_fps( float realfps ); + void draw_stats(PresetInputs *presetInputs); + void draw_help( ); + void draw_preset(); + void draw_title(); + void draw_title_to_screen(); + void maximize_colors(); + void draw_title_to_texture(); + void draw_motion_vectors(PresetOutputs *presetOutputs); + void draw_borders(PresetOutputs *presetOutputs); + void draw_shapes(PresetOutputs *presetOutputs); + void draw_custom_waves(PresetOutputs *presetOutputs); + void draw_waveform(PresetOutputs *presetOutputs, PresetInputs *presetInputs); + void modulate_opacity_by_volume(PresetOutputs *presetOutputs) ; + void darken_center(); +}; + +#endif diff --git a/src/projectM-engine-backup/SplayNode.hpp b/src/projectM-engine-backup/SplayNode.hpp new file mode 100644 index 000000000..09fb19ce0 --- /dev/null +++ b/src/projectM-engine-backup/SplayNode.hpp @@ -0,0 +1,91 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * Node of a splay tree + * + * $Log$ + */ + +#ifndef _SPLAYNODE_HPP +#define _SPLAYNODE_HPP + +//#include "projectM.hpp" + +#include "compare.h" + +typedef void Object; +template +class SplayNode { +public: + SplayNode *left, *right; + Data *data; + void *key; + void (*free_key)(void*); + SplayNode(); + SplayNode(void *key, Data *data, void (*free_key)(void*)); + ~SplayNode(); + }; + +/** Create a new default splaynode */ +template +SplayNode::SplayNode() { + this->data = NULL; + this->key = NULL; + this->free_key = free_key; + } + +/* Create a new splay node type */ +template +SplayNode::SplayNode(void * key, Data * data, void (*free_key)(void*)) { + + /* Creates the new splay node struct */ + this->data = data; + this->key = key; + this->free_key = free_key; + } + +/* Recursively free all the splaynodes */ +template +SplayNode::~SplayNode() { + + /* Ok if this happens, a recursive base case */ + /* Free left node */ + if ( left != NULL ) { + delete left; + } + + /* Free right node */ + if ( right != NULL ) { + delete right; + } + + /* Free this node's key */ +// printf( "~SplayNode: %X\t%X\n", key, tree->free_key ); + + this->free_key(key); + + /* Note that the data pointers are not freed here. + Should be freed with a splay traversal function */ + } + +#endif /** !_SPLAYNODE_HPP */ diff --git a/src/projectM-engine-backup/StaticArray.hpp b/src/projectM-engine-backup/StaticArray.hpp new file mode 100644 index 000000000..9593edd68 --- /dev/null +++ b/src/projectM-engine-backup/StaticArray.hpp @@ -0,0 +1,212 @@ +#ifndef PROJECTM_STATIC_ARRAY_HPP +#define PROJECTM_STATIC_ARRAY_HPP +#include +/** +* A simple array implementation with a few important features: + * (1) static array length, resulting in compile time optimizations + * (2) bounds checking when compiling with assertions + * Note that this data structure is generally useful only for smaller sized arrays. +*/ + +template +class StaticArray { +public: + + typedef T * iterator; + typedef const T * const_iterator; + + StaticArray(); + StaticArray(const std::size_t logical_size); + StaticArray(const std::size_t logical_size, const T & defaultValue); + const T & operator[] (std::size_t index) const; + T & operator[] (std::size_t index); + + iterator begin(); + iterator end(); + + const_iterator begin() const; + const_iterator end() const; + + void clear(); + bool empty() const; + + bool operator==(const StaticArray & rhs) const; + bool operator!=(const StaticArray & rhs) const; + bool operator<(const StaticArray & rhs) const; + bool operator>(const StaticArray & rhs) const; + + /// Do nothing implementation that will be optimized out. Bit of a hack to make it interface with vector. + void reserve(const std::size_t amount) const {} + + void push_back(const T & element); + void pop_back(); + + void erase(iterator first, iterator last); + + std::size_t size() const; + std::size_t capacity() const; + +private: + std::size_t m_logical_size; + T m_array[STATIC_ARRAY_MAX_SIZE+1]; +}; + + +template +StaticArray::StaticArray():m_logical_size(0) {} + +template +StaticArray::StaticArray(const std::size_t logical_size):m_logical_size(logical_size) { + assert(logical_size <= STATIC_ARRAY_MAX_SIZE); +} + +template +StaticArray::StaticArray(const std::size_t logical_size, const T & defaultValue):m_logical_size(logical_size) { + assert(logical_size <= STATIC_ARRAY_MAX_SIZE); + for (iterator pos = begin(); pos != end();++pos) + *pos = defaultValue; +} + +template +inline const T & StaticArray::operator[] (std::size_t index) const { + assert(index <= (m_logical_size-1)); + return m_array[index]; +} + +template +inline T & StaticArray::operator[] (std::size_t index) { + assert(index <= (m_logical_size-1)); + return m_array[index]; +} + +template +inline std::size_t StaticArray::size() const { + return m_logical_size; +} + + +template +inline std::size_t StaticArray::capacity() const { + return STATIC_ARRAY_MAX_SIZE; +} + + +template +inline bool StaticArray::empty() const { + return m_logical_size == 0; +} + +template +inline void StaticArray::clear() { + m_logical_size = 0; +} + +template +inline typename StaticArray::const_iterator StaticArray::begin() const { + return m_array; +} + + +template +inline typename StaticArray::iterator StaticArray::begin() { + return m_array; +} + + +template +inline typename StaticArray::const_iterator StaticArray::end() const { + return m_array+m_logical_size; +} + + +template +inline void StaticArray::push_back(const T & element) { + (*this)[m_logical_size++] = element; +} + + +template +inline void StaticArray::pop_back() { + assert(m_logical_size > 0); + m_logical_size--; +} + + +/// @slow worst case is around N^2 + N. +template +inline void StaticArray::erase(iterator first, iterator last) { + + StaticArray tmpArray; + + for (iterator pos = begin(); pos != end();++pos) { + for (iterator spos = first; spos != last;++spos) { + if (pos != spos) + tmpArray.push_back(*pos); + } + } + (*this) =tmpArray; +} + +template +inline typename StaticArray::iterator StaticArray::end() { + return m_array+m_logical_size; +} + + +/// Lexographic comparison +template +inline bool StaticArray::operator< (const StaticArray & rhs) const { + + const StaticArray & lhs = *this; + + std::size_t len = rhs.size() < lhs.size() ? rhs.size(): lhs.size(); + + for (std::size_t i = 0; i < len;i++) { + if (lhs[i] < rhs[i]) + return true; + else if (!(lhs[i] == rhs[i])) + return false; + } + + // rhs has less elements than lhs + if (len < lhs.size()) + return false; + + // lhs has less elements than rhs + if (len < rhs.size()) + return true; + + // Equal + return false; + +} + + +template +inline bool StaticArray::operator!=(const StaticArray & rhs) const { + return !(*this == rhs); +} + +template +inline bool StaticArray::operator==(const StaticArray & rhs) const { + + const StaticArray & lhs = *this; + + if (rhs.size() != lhs.size()) + return false; + + for (std::size_t i = 0; i < rhs.size() ;i++) { + if (!(rhs[i] == lhs[i])) + return false; + } + return true; + +} + + +template +inline bool StaticArray ::operator> (const StaticArray & rhs) const { + return ((!((*this) == rhs)) && (!((*this) < rhs))); +} + +#endif diff --git a/src/projectM-engine-backup/browser.cpp b/src/projectM-engine-backup/browser.cpp new file mode 100755 index 000000000..e8a76a5bd --- /dev/null +++ b/src/projectM-engine-backup/browser.cpp @@ -0,0 +1,145 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +#include +#include +#include + +#include "Common.hpp" +#include "fatal.h" +#include "projectM.hpp" +#include "glConsole.h" +#include "event.h" + +extern interface_t current_interface; + +gl_console_t * browser_console = NULL; +int active_font2 = 0; +char input_buffer[MAX_PATH_SIZE]; +int buf_pos = 0; + +int loadBrowser() { + + + + if ((browser_console = glConsoleCreate(40, 10, 80, 20, 1, 1, active_font2)) < 0) + return PROJECTM_FAILURE; + + glConsoleSetFGColor(CONSOLE_RED, browser_console); + glConsoleSetBGColor(CONSOLE_BLACK, browser_console); + glConsoleSetFlags(CONSOLE_FLAG_CURSOR_BLINKING | CONSOLE_FLAG_ALWAYS_DRAW_BACKGROUND, browser_console); + glConsoleClearBuffer(browser_console); + + buf_pos = 0; + memset(input_buffer, 0, MAX_PATH_SIZE); + + return PROJECTM_SUCCESS; +} + +int closeBrowser() { + + + active_font2 = 0; + + glConsoleDestroy(browser_console); + browser_console = NULL; + + return PROJECTM_SUCCESS; +} + +void browser_key_handler( projectMEvent event, projectMKeycode keycode, projectMModifier modifier ) { + + char s[2]; + + s[0] = 0; + s[1] = 0; + + + switch( event ) { + case PROJECTM_KEYDOWN: + switch(keycode) { + case PROJECTM_K_UP: + glConsoleMoveCursorUp(browser_console); + break; + case PROJECTM_K_RETURN: +//@@ loadPresetByFile(input_buffer); + closeBrowser(); + current_interface = DEFAULT_INTERFACE; + break; + case PROJECTM_K_RIGHT: + glConsoleMoveCursorForward(browser_console); + break; + case PROJECTM_K_LEFT: + printf("CURSOR BACKWARD\n"); + glConsoleMoveCursorBackward(browser_console); + break; + case PROJECTM_K_DOWN: + glConsoleMoveCursorDown(browser_console); + break; + case PROJECTM_K_PAGEUP: + glConsoleAlignCursorUp(browser_console); + break; + case PROJECTM_K_PAGEDOWN: + glConsoleAlignCursorDown(browser_console); + break; + case PROJECTM_K_INSERT: + glConsoleAlignCursorLeft(browser_console); + break; + case PROJECTM_K_DELETE: + glConsoleAlignCursorRight(browser_console); + break; + case PROJECTM_K_LSHIFT: + break; + case PROJECTM_K_RSHIFT: + break; + case PROJECTM_K_CAPSLOCK: + break; + case PROJECTM_K_ESCAPE: + closeBrowser(); + current_interface = DEFAULT_INTERFACE; + break; + + default: /* All regular characters */ + if (buf_pos == MAX_PATH_SIZE) { + buf_pos = 0; + } + input_buffer[buf_pos] = (char)keycode; + if ((modifier == PROJECTM_KMOD_LSHIFT) || (modifier == PROJECTM_KMOD_RSHIFT) || (modifier == PROJECTM_KMOD_CAPS)) + input_buffer[buf_pos] -= 32; + + *s = input_buffer[buf_pos]; + glConsolePrintString(s, browser_console); + buf_pos++; + break; + } + } + + +} + +void refreshBrowser() { + + // glConsoleClearBuffer(browser_console); + // glConsoleSetCursorPos(1, 1, browser_console); + //glConsolePrintString("Enter a file to load:\n", browser_console); + //glConsolePrintString(input_buffer, browser_console); + glConsoleDraw(browser_console); +} + diff --git a/src/projectM-engine-backup/browser.h b/src/projectM-engine-backup/browser.h new file mode 100755 index 000000000..958719b6f --- /dev/null +++ b/src/projectM-engine-backup/browser.h @@ -0,0 +1,45 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * + * + * $Log$ + */ +/** + * $Id: browser.h,v 1.1.1.1 2005/12/23 18:05:03 psperl Exp $ + * + * Browser interface + * + */ + +#ifndef _BROWSER_H +#define _BROWSER_H + +#include "event.h" + +void browser_key_handler( projectMEvent event, projectMKeycode keycode, projectMModifier modifier ); +int loadBrowser(); +int closeBrowser(); +void refreshBrowser(); + +#endif /** !_BROWSER_H */ diff --git a/src/projectM-engine-backup/carbontoprojectM.h b/src/projectM-engine-backup/carbontoprojectM.h new file mode 100755 index 000000000..68f2567d6 --- /dev/null +++ b/src/projectM-engine-backup/carbontoprojectM.h @@ -0,0 +1,104 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: carbontoprojectM.hpp,v 1.2 2004/11/12 15:12:58 cvs Exp $ + * + * Translates CARBON -> projectM variables + * + * $Log$ + */ + +#ifndef _CARBONTOPROJECTM_H +#define _CARBONTOPROJECTM_H + +#include "projectM.hpp" +#ifdef WIN32 +#else +#endif + +projectMEvent carbon2pmEvent( EventRecord *event ) { \ +\ + switch ( event->what ) { \ + case updateEvt: \ + return PROJECTM_VIDEORESIZE; \ + case keyUp: \ + return PROJECTM_KEYUP; \ + case keyDown: \ + return PROJECTM_KEYDOWN; \ + default: + return PROJECTM_KEYUP; \ + } \ + } \ + +projectMKeycode carbon2pmKeycode( EventRecord *event ) { \ + projectMKeycode char_code = (projectMKeycode)(event->message & charCodeMask); \ + switch ( char_code ) { \ + case kFunctionKeyCharCode: { \ + switch ( ( event->message << 16 ) >> 24 ) { \ + case 111: { \ + return PROJECTM_K_F12; \ + } \ + case 103: { \ + return PROJECTM_K_F11; \ + } \ + case 109: { \ + return PROJECTM_K_F10; \ + } \ + case 101: { \ + return PROJECTM_K_F9; \ + } \ + case 100: { \ + return PROJECTM_K_F8; \ + } \ + case 98: { \ + return PROJECTM_K_F7; \ + } \ + case 97: { \ + return PROJECTM_K_F6; \ + } \ + case 96: { \ + return PROJECTM_K_F5; \ + } \ + case 118: { \ + return PROJECTM_K_F4; \ + } \ + case 99: { \ + return PROJECTM_K_F3; \ + } \ + case 120: { \ + return PROJECTM_K_F2; \ + } \ + case 122: { \ + return PROJECTM_K_F1; \ + } \ + } \ + } \ + default: { \ + return char_code; \ + } \ + } \ + } \ + +projectMModifier carbon2pmModifier( EventRecord *event ) { \ + return (projectMModifier)PROJECTM_K_LSHIFT; \ + } \ + +#endif /** _CARBONTOPROJECTM_H */ diff --git a/src/projectM-engine-backup/compare.h b/src/projectM-engine-backup/compare.h new file mode 100755 index 000000000..b5b64b977 --- /dev/null +++ b/src/projectM-engine-backup/compare.h @@ -0,0 +1,114 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * $Log$ + */ + +#ifndef _COMPARE_H +#define _COMPARE_H +#include "wipemalloc.h" +#include "Common.hpp" + +/// @bug this will be ripped away when splaytree is more standardly written or its removed in favor of stl-esque data structure +class SplayKeyFunctions { +public: +static int compare_int(const int * num1, const int * num2); +static int compare_string(const char * string1, const char * string2); + +static void free_int(int * num); +static void free_string(char * string); +static void * copy_int(int * num); +static void * copy_string(char * string); +static int compare_string_version(const char * str1, const char * str2); +}; + + +/** tree_types.cpp */ +/* Compares integer value numbers in 32 bit range */ +inline int SplayKeyFunctions::compare_int(const int * num1, const int * num2) { + + if ((*num1) < (*num2)) + return -1; + if ((*num1) > (*num2)) + return 1; + + return 0; +} + +/* Compares strings in lexographical order */ +inline int SplayKeyFunctions::compare_string(const char * str1, const char * str2) { + + // printf("comparing \"%s\" to \"%s\"\n", str1, str2); + //return strcmp(str1, str2); + return strncmp(str1, str2, MAX_TOKEN_SIZE-1); + +} + +/* Compares a string in version order. That is, file1 < file2 < file10 */ +inline int SplayKeyFunctions::compare_string_version(const char * str1, const char * str2) { + + return strcmp( str1, str2 ); +#ifdef PANTS + return strverscmp(str1, str2); +#endif +} + + +inline void SplayKeyFunctions::free_int(int * num) { + free(num); +} + + + + inline void SplayKeyFunctions::free_string(char * string) { + free(string); +} + + + + inline void * SplayKeyFunctions::copy_int(int * num) { + + int * new_num; + + if ((new_num = (int*)wipemalloc(sizeof(int))) == NULL) + return NULL; + + *new_num = *num; + + return (void*)new_num; +} + + +inline void * SplayKeyFunctions::copy_string(char * string) { + + char * new_string; + + if ((new_string = (char*)wipemalloc(MAX_TOKEN_SIZE)) == NULL) + return NULL; + + strncpy(new_string, string, MAX_TOKEN_SIZE-1); + + return (void*)new_string; +} + +#endif /** !_COMPARE_H */ diff --git a/src/projectM-engine-backup/config b/src/projectM-engine-backup/config new file mode 100644 index 000000000..bf066ae2f --- /dev/null +++ b/src/projectM-engine-backup/config @@ -0,0 +1,22 @@ +projectM Config file (ONLY CHANGE THE NUMBERS!!!!!!) +------------------------------------------------------ +Texture Size (Must be power of 2) [256,512,1024,2048, etc] +512 +Grid X Dimension (Higher is Better but much slower) 12-60 +32 +Grid Y Dimension (Higher is Better but much slower) 8-45 +24 +Windowed Width (Initial window width) +512 +Windowed Height (Initial window width) +512 +Fullscreen Width (set to your native screen resolution) +1024 +Fullscreen Height (set to your native screen resolution) +768 +FPS (Higher the Better) 30-90 is realisitc +35 +Fullscreen on Startup (1=yes, 0=no) +0 +X Server to Display projectM default is ":0.0" +:0.0 diff --git a/src/projectM-engine-backup/console_interface.cpp b/src/projectM-engine-backup/console_interface.cpp new file mode 100755 index 000000000..0e9959bd3 --- /dev/null +++ b/src/projectM-engine-backup/console_interface.cpp @@ -0,0 +1,230 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include + +#include "projectM.hpp" +#include "Common.hpp" +#include "fatal.h" +//#include "menu.h" +#include "console_interface.h" +#include "Preset.hpp" +#include "browser.h" +#include "editor.h" +#include "event.h" +#include "BeatDetect.hpp" +#include "PresetChooser.hpp" + + +interface_t current_interface = DEFAULT_INTERFACE; + +void refreshConsole() { + + switch (current_interface) { + + case MENU_INTERFACE: +// refreshMenu(); + break; + case SHELL_INTERFACE: + break; + case EDITOR_INTERFACE: + refreshEditor(); + break; + case DEFAULT_INTERFACE: + break; + case BROWSER_INTERFACE: + refreshBrowser(); + break; + default: + break; + } + +} + +void projectM::key_handler( projectMEvent event, + projectMKeycode keycode, projectMModifier modifier ) { + + switch( event ) { + + + case PROJECTM_KEYDOWN: + + //default_key_handler(); + switch (current_interface) + { + + case MENU_INTERFACE: +// menu_key_handler(this, event, keycode); + break; + case SHELL_INTERFACE: + //shell_key_handler(); + break; + case EDITOR_INTERFACE: + editor_key_handler(event,keycode); + break; + case BROWSER_INTERFACE: + browser_key_handler(event,keycode,modifier); + break; + case DEFAULT_INTERFACE: + default_key_handler(event,keycode); + break; + default: + default_key_handler(event,keycode); + break; + + } + break; + } +} + +void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode) { + + switch( event ) { + + case PROJECTM_KEYDOWN: + + switch( keycode ) + { + case PROJECTM_K_UP: + beatDetect->beat_sensitivity += 0.25; + if (beatDetect->beat_sensitivity > 5.0) beatDetect->beat_sensitivity = 5.0; + break; + case PROJECTM_K_DOWN: + beatDetect->beat_sensitivity -= 0.25; + if (beatDetect->beat_sensitivity < 0) beatDetect->beat_sensitivity = 0; + break; + case PROJECTM_K_F1: + renderer->showhelp++; + renderer->showstats=0; + renderer->showfps=0; + break; + case PROJECTM_K_F5: + if(renderer->showhelp%2==0) renderer->showfps++; + break; + case PROJECTM_K_F4: + if(renderer->showhelp%2==0) renderer->showstats++; + break; + case PROJECTM_K_F3: { + renderer->showpreset++; + printf( "F3 pressed: %d\n", renderer->showpreset ); + break; + } + case PROJECTM_K_F2: + renderer->showtitle++; + break; +#ifndef MACOS + case PROJECTM_K_F9: +#else + case PROJECTM_K_F8: +#endif + renderer->studio++; + break; + + case PROJECTM_K_ESCAPE: { +// exit( 1 ); + break; + } + case PROJECTM_K_f: + + break; + case PROJECTM_K_a: + if (renderer->correction) { + renderer->correction = 0; + } else { + renderer->correction = 1; + } + break; + 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(); + ++(*m_presetPos); + /// @bug implement == operator + if (!((*m_presetPos) != m_presetChooser->end())) + --(*m_presetPos); + 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 + } + + +// if ((PresetSwitcher::switchPreset(ALPHA_PREVIOUS, HARD_CUT)) < 0){ + printf("WARNING: Bad preset file, loading idle preset\n"); + abort(); +// } + break; + case PROJECTM_K_l: + if (renderer->noSwitch==0)renderer->noSwitch=1; else renderer->noSwitch=0; + // current_interface = BROWSER_INTERFACE; + // loadBrowser(); + break; + case PROJECTM_K_e: + current_interface = EDITOR_INTERFACE; +// loadEditor(active_preset->per_frame_eqn_string_buffer,(void (*)()) reloadPerFrame, +// 80, 24, 140, 60, 0, 0); + break; + case PROJECTM_K_s: + renderer->studio++; +// current_interface = EDITOR_INTERFACE; +// loadEditor("[FILE NAME HERE]", (void (*)())savePreset, +// 50, 1, 100, 5, 0, .92); + case PROJECTM_K_i: + DWRITE( "PROJECTM_K_i\n" ); + + break; + case PROJECTM_K_z: + break; + case PROJECTM_K_0: +// nWaveMode=0; + break; + case PROJECTM_K_6: +// nWaveMode=6; + break; + case PROJECTM_K_7: +// nWaveMode=7; + break; + case PROJECTM_K_m: + renderer->showhelp=0; + renderer->showstats=0; + renderer->showfps=0; +// current_interface = MENU_INTERFACE; +// showMenu(); + break; + case PROJECTM_K_t: + break; + default: + break; + } + } +} diff --git a/src/projectM-engine-backup/console_interface.h b/src/projectM-engine-backup/console_interface.h new file mode 100755 index 000000000..ca9c5221d --- /dev/null +++ b/src/projectM-engine-backup/console_interface.h @@ -0,0 +1,39 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: console_interface.h,v 1.1.1.1 2005/12/23 18:05:03 psperl Exp $ + * + * $Log$ + */ + +#ifndef _CONSOLE_INTERFACE_H +#define _CONSOLE_INTERFACE_H + +#include "event.h" + +void default_key_handler(projectM *PM, projectMEvent event, projectMKeycode keycode); +void refreshConsole(); +#if defined(__CPLUSPLUS) && !defined(MACOS) +xtern "C" void key_handler(projectM *PM, projectMEvent event, projectMKeycode keycode, projectMModifier modifier ); +#else +extern void key_handler(projectM *PM, projectMEvent event, projectMKeycode keycode, projectMModifier modifier ); +#endif +#endif /** !_CONSOLE_INTERFACE_H */ diff --git a/src/projectM-engine-backup/dlldefs.h b/src/projectM-engine-backup/dlldefs.h new file mode 100755 index 000000000..b944fe730 --- /dev/null +++ b/src/projectM-engine-backup/dlldefs.h @@ -0,0 +1,40 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * DLL definitions for exporting symbols on various platforms + * + * $Log$ + */ + +#ifndef _DLLDEFS_H +#define _DLLDEFS_H + +#ifndef DLLEXPORT +#ifdef WIN32 +#define DLLEXPORT __declspec(dllexport) +#else /** !WIN32 */ +#define DLLEXPORT +#endif /** WIN32 */ +#endif /** !DLLEXPORT */ + +#endif /** !_DLLDEFS_H */ diff --git a/src/projectM-engine-backup/editor.cpp b/src/projectM-engine-backup/editor.cpp new file mode 100755 index 000000000..fbc97dfce --- /dev/null +++ b/src/projectM-engine-backup/editor.cpp @@ -0,0 +1,870 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/* Editor written on top of glConsole */ +#include +#include +#include + +#include "projectM.hpp" + +#ifdef MACOS +#include +#else +#include +#endif /** MACOS */ +#include "Common.hpp" +#include "fatal.h" +#include "event.h" + +//#include "preset_types.h" +#include "Preset.hpp" + +#include "glConsole.h" + +#include "editor.h" + +#define MAX_BUFFER_SIZE 50000 +#define KEY_REFRESH_RATE 2 +#define KEY_DELAY_TIME 15 + +extern interface_t current_interface; + +typedef enum { + OVERWRITE, + INSERT +} edit_mode_t; + +edit_mode_t edit_mode = OVERWRITE; + +void refresh_from_cursor(char * s); +void save_cursor_pos(); +void restore_cursor_pos(); +void writeChar(char c); +void replace_char(char c); +void insert_char(char c); +void shift_buffer_right(); +void insert_newline(); +void shift_buffer_left(); +void delete_newline(); +void complete_refresh(); + +void moveCursorLeft(); +void moveCursorRight(); + +int moveCursorUp(); +int moveCursorDown(); + +int get_prev_newline_dist(); +int get_next_newline_dist(); +int key_delay_cnt = 0; +int move_to_next_newline(); +int move_to_prev_newline(); +void handle_home(); +void handle_end(); +void handle_pageup(); +void handle_pagedown(); + +gl_console_t * editor_console = NULL; +int current_font = 0; +char editor_buffer[MAX_BUFFER_SIZE]; +int key_refresh_cnt = 0; +int cursor_pos = 0; +int backup_pos = -1; +int cursorx = 0; +int cursory = 0; +int key_held_down = 0; +projectMKeycode last_sdl_key = (projectMKeycode) 0; +projectMEvent last_sdl_event; + +void (*callfunc)(void*, void*) = NULL; + +int loadEditor(char * string, void (*func)(), int screen_width, int screen_height, + int scroll_width, int scroll_height, float start_x, float start_y) { + + if (string == NULL) + return PROJECTM_FAILURE; + + + + if ((editor_console = + glConsoleCreate(screen_width, screen_height, scroll_width, scroll_height, start_x, start_y, current_font)) < 0) + return PROJECTM_FAILURE; + + /* Set colors */ + glConsoleSetFGColor(CONSOLE_GREEN, editor_console); + glConsoleSetBGColor(CONSOLE_BLACK, editor_console); + glConsoleSetCursorColor(CONSOLE_RED, editor_console); + + /* Set flags */ + glConsoleSetFlags(CONSOLE_FLAG_CURSOR_BLINKING|CONSOLE_FLAG_ALWAYS_DRAW_BACKGROUND, editor_console); + + /* Clear the console buffer */ + // glConsoleClearBuffer(editor_console); + + /* Print the characters of the passed string, realign cursor to top left */ + glConsolePrintString(string, editor_console); + glConsoleAlignCursorLeft(editor_console); + glConsoleAlignCursorUp(editor_console); + + /* Copy string into editor buffer */ + strncpy(editor_buffer, string, MAX_BUFFER_SIZE-1); + cursor_pos = 0; + + callfunc = (void (*)(void*, void*))func; + backup_pos = -1; + edit_mode = OVERWRITE; + glConsoleSetCursorStyle(BAR_STYLE, editor_console); + return PROJECTM_SUCCESS; +} + +int closeEditor() { + + + current_font = 0; + key_held_down = 0; + + glConsoleDestroy(editor_console); + editor_console = NULL; + callfunc = NULL; + return PROJECTM_SUCCESS; +} + + +void key_helper( projectMKeycode key, projectMEvent event, projectMModifier modifier) { + char c; + + switch(key) { + case PROJECTM_K_INSERT: + if (edit_mode == OVERWRITE) { + edit_mode = INSERT; + glConsoleSetCursorStyle(UNDERLINE_STYLE, editor_console); + } + else { + edit_mode = OVERWRITE; + glConsoleSetCursorStyle(BAR_STYLE, editor_console); + } + break; + case PROJECTM_K_RETURN: + if (modifier== PROJECTM_KMOD_LCTRL) { +/// @bug editor is busted +// callfunc(editor_buffer, active_preset); + } + else { + writeChar('\n'); + } + break; + case PROJECTM_K_LCTRL: + break; + case PROJECTM_K_RIGHT: + moveCursorRight(); + // glConsoleMoveCursorForward(editor_console); + break; + case PROJECTM_K_LEFT: + moveCursorLeft(); + // glConsoleMoveCursorBackward(editor_console); + break; + case PROJECTM_K_UP: + moveCursorUp(); + break; + case PROJECTM_K_DOWN: + moveCursorDown(); + // glConsoleMoveCursorDown(editor_console); + break; + case PROJECTM_K_PAGEUP: + handle_pageup(); + // glConsoleAlignCursorUp(editor_console); + break; + case PROJECTM_K_PAGEDOWN: + handle_pagedown(); + // glConsoleAlignCursorDown(editor_console); + break; + case PROJECTM_K_HOME: + handle_home(); + // glConsoleAlignCursorLeft(editor_console); + break; + case PROJECTM_K_END: + handle_end(); + // glConsoleAlignCursorRight(editor_console); + break; + case PROJECTM_K_LSHIFT: + break; + case PROJECTM_K_RSHIFT: + break; + case PROJECTM_K_CAPSLOCK: + break; + case PROJECTM_K_BACKSPACE: + writeChar('\b'); + break; + + case PROJECTM_K_ESCAPE: + closeEditor(); + current_interface = DEFAULT_INTERFACE; + break; + + default: + /* All regular characters */ + c = (char)key; + + writeChar(c); + break; + } +} + + +void editor_key_handler( projectMEvent event, projectMKeycode keycode ) { + + switch( event ) { + + case PROJECTM_KEYUP: + // printf("KEY UP\n"); + key_held_down = 0; + return; + + case PROJECTM_KEYDOWN: + // printf("KEY DOWN FIRST\n"); + key_held_down = 1; + last_sdl_key = keycode; + last_sdl_event = event; + key_helper(last_sdl_key, event, (projectMModifier)0); + key_delay_cnt = KEY_DELAY_TIME; + return; + + default: + + break; + } + + + + + + +} + +void refreshEditor() { + + /* Refresh the editor console */ + glConsoleDraw(editor_console); + + /* Update keyboard related events */ + if (key_delay_cnt > 0) + key_delay_cnt--; + else if ((key_held_down) && ((key_refresh_cnt % KEY_REFRESH_RATE) == 0)) { + key_helper(last_sdl_key, last_sdl_event, (projectMModifier)0); + } + + key_refresh_cnt++; + +} + +void moveCursorRight() { + + /* Out of bounds check */ + if (cursor_pos >= (MAX_BUFFER_SIZE-1)) + return; + + if (editor_buffer[cursor_pos+1] == 0) + return; + + /* If we are at a new line character jump down to next line */ + if (editor_buffer[cursor_pos] == '\n') { + glConsoleAlignCursorLeft(editor_console); + glConsoleMoveCursorDown(editor_console); + + } + + /* Otherwise just advance cursor forward */ + else + glConsoleMoveCursorForward(editor_console); + + //printf("editor: %c\n", editor_buffer[cursor_pos]); + /* Move cursor forward in editor buffer */ + cursor_pos++; + +} + +void moveCursorLeft() { + + /* Out of bounds check */ + if (cursor_pos <= 0) + return; + + /* If the previous (left) character is a new line jump up a line and all the way to the end of character string */ + if (editor_buffer[cursor_pos-1] == '\n') { + glConsoleMoveCursorUp(editor_console); + glConsoleCursorToNextChar('\n', editor_console); + } + + /* Otherwise just move cursor back a space */ + else + glConsoleMoveCursorBackward(editor_console); + + /* Move cursor forward in editor buffer */ + cursor_pos--; + +} + + +int moveCursorUp() { + + + int dist1, dist2; + int return_flag = PROJECTM_SUCCESS; + + /* We need this distance to: + 1) move the cursor back to the previous new line + 2) position the cursor at the same column on the previous line + */ + + /* Move cursor to previous newline character */ + if (cursor_pos == 0) + return PROJECTM_FAILURE; + + dist1 = move_to_prev_newline(); + + if (cursor_pos == 0) + return_flag = PROJECTM_FAILURE; + else { + moveCursorLeft(); + /* Again move to previous newline */ + dist2 = move_to_prev_newline(); + } + + /* Move cursor forward appropiately, stopping prematurely if new line is reached */ + while ((dist1 > 1) && (editor_buffer[cursor_pos] !='\n') && (cursor_pos <= (MAX_BUFFER_SIZE-1))) { + cursor_pos++; + glConsoleMoveCursorForward(editor_console); + dist1--; + } + return return_flag; +} + + +int moveCursorDown() { + + int dist1, dist2; + + dist2 = get_prev_newline_dist(); + + //printf("prev new line distance: %d\n", dist2); + /* Move cursor to next line, store the distance + away from the newline. If this distance is + less than (error value) or equal to zero do nothing */ + if ((dist1 = move_to_next_newline()) <= 0) { + return PROJECTM_FAILURE; + } + // printf("distance away from next newline: %d\n", dist1); + while ((cursor_pos != (MAX_BUFFER_SIZE-1)) && (editor_buffer[cursor_pos] != '\n') && (dist2 > 0)) { + cursor_pos++; + glConsoleMoveCursorForward(editor_console); + dist2--; + } + + return PROJECTM_SUCCESS; +; +} + +int get_prev_newline_dist() { + + int cnt = 0; + + if (cursor_pos == 0) + return 0; + + /* If we are already at the newline, then skip the first character + and increment cnt */ + if (editor_buffer[cursor_pos] == '\n') { + /* Top of buffer, return 0 */ + if (cursor_pos == 0) + return 0; + /* Otherwise set count to one */ + cnt++; + } + while (editor_buffer[cursor_pos-cnt] != '\n') { + + /* In this case we are the top of the editor buffer, so stop */ + if ((cursor_pos-cnt) <= 0) + return cnt; + + cnt++; + + } + + //printf("Returning %d\n", cnt-1); + return cnt-1; +} + + +int get_next_newline_dist() { + + int cnt = 0; + + + while (editor_buffer[cursor_pos+cnt] != '\n') { + + /* In this case we have exceeded the cursor buffer, so abort action */ + if ((cursor_pos+cnt) >= (MAX_BUFFER_SIZE-1)) + return 0; + + cnt++; + + } + + return cnt; +} + +/* Moves cursor to next line, returns length away from next one. + If this is the last line, returns 0. + On error returns -1 (PROJECTM_FAILURE) +*/ + +int move_to_next_newline() { + + int cnt = 0; + + + while (editor_buffer[cursor_pos+cnt] != '\n') { + + /* In this case we have exceeded the cursor buffer, so abort action */ + if ((cursor_pos+cnt) >= (MAX_BUFFER_SIZE-1)) + return 0; + + cnt++; + + } + + + /* New line is the last character in buffer, so quit */ + if ((cursor_pos+cnt+1) > (MAX_BUFFER_SIZE-1)) + return 0; + + if (editor_buffer[cursor_pos+cnt+1] == 0) + return 0; + + /* One more time to skip past new line character */ + cnt++; + + /* Now we can move the cursor position accordingly */ + cursor_pos += cnt; + + /* Now move the console cursor to beginning of next line + These functions are smart enough to not exceed the console + without bounds checking */ + glConsoleMoveCursorDown(editor_console); + glConsoleAlignCursorLeft(editor_console); + + /* Finally, return distance cursor was away from the new line */ + return cnt; +} + +/* Moves cursor to previous line, returns length away from previous one. + If this is the first line, returns 0. + On error returns -1 (PROJECTM_FAILURE) + More specifically, the cursor will be exactly at the new line character + of the previous line. + Now its the beginning of the line, not the newline +*/ + +int move_to_prev_newline() { + + int cnt = 0; + + if (editor_buffer[cursor_pos] == '\n') { + if (cursor_pos == 0) + return 0; + else { + cnt++; + glConsoleMoveCursorBackward(editor_console); + } + } + while (((cursor_pos - cnt) > -1) && (editor_buffer[cursor_pos-cnt] != '\n')) { + + + glConsoleMoveCursorBackward(editor_console); + + cnt++; + + } + + //for (i=0;i < cnt; i++) + + + /* New line is the last character in buffer, so quit */ + // if ((cursor_pos-cnt-1) <= 0) + // return 0; + + + /* Now we can move the cursor position accordingly */ + cursor_pos -= cnt-1; + + /* Now move the console cursor to end of previous line + These functions are smart enough to not exceed the console + without bounds checking */ ; + // glConsoleMoveCursorUp(editor_console); + // glConsoleCursorToNextChar('\n', editor_console); + + /* Finally, return distance cursor was away from the new line */ + return cnt; + +} + +void handle_return() { + + +} + + +void handle_backspace() { + + +} + +void handle_home() { + + while ((cursor_pos > 0) && (editor_buffer[cursor_pos-1] != '\n')) { + cursor_pos--; + } + + glConsoleAlignCursorLeft(editor_console); + +} + +void handle_end() { + + while ((cursor_pos < (MAX_BUFFER_SIZE-1)) && (editor_buffer[cursor_pos+1] != 0) && (editor_buffer[cursor_pos] != '\n')) { + cursor_pos++; + glConsoleMoveCursorForward(editor_console); + } + + // glConsoleCursorToNextChar('\n', editor_console); + +} + +void handle_pageup() { + + int dist1; + + dist1 = move_to_prev_newline(); + + while (cursor_pos != 0) + moveCursorLeft(); + + while ((dist1 > 1) && (cursor_pos < (MAX_BUFFER_SIZE-1)) && (editor_buffer[cursor_pos+1] != 0) && (editor_buffer[cursor_pos] != '\n')) { + cursor_pos++; + glConsoleMoveCursorForward(editor_console); + dist1--; + } + +} + + +void handle_pagedown() { + + int dist1; + + dist1 = get_prev_newline_dist(); + + while (cursor_pos < (MAX_BUFFER_SIZE-2) && (editor_buffer[cursor_pos+1] != 0)) + moveCursorRight(); + + move_to_prev_newline(); + moveCursorRight(); + + while ((dist1 > 1) && (cursor_pos < (MAX_BUFFER_SIZE-1)) && (editor_buffer[cursor_pos+1] != 0) && (editor_buffer[cursor_pos] != '\n')) { + cursor_pos++; + glConsoleMoveCursorForward(editor_console); + dist1--; + } + +} + + +/* Writes a character to console and editor according to editor mode */ +void writeChar(char c) { + + switch (edit_mode) { + /* Overwrite mode, replaces cursor character with passed character. + Cursor remains standing */ + case OVERWRITE: + + /* Case on c to catch special characters */ + switch (c) { + + case '\b': /* Backspace */ + // printf("backspace case, overwrite mode:\n"); + /* At beginning of buffer, do nothing */ + if (cursor_pos == 0) + return; + + /* At first character of current line. + Default behavior is to delete the new line, + and squeeze the rest of the editor buffer back one character */ + if (editor_buffer[cursor_pos-1] == '\n') { + delete_newline(); + return; + } + + /* Normal overwrite back space case. + Here the previous character is replaced with a space, + and the cursor moves back one */ + + editor_buffer[--cursor_pos]= ' '; + (editor_console->cursor_ptr-1)->symbol = ' '; + glConsoleMoveCursorBackward(editor_console); + return; + case '\n': /* New line character */ + insert_newline(); + return; + default: /* not a special character, do typical behavior */ + // printf("DEFAULT CASE: char = %c\n", c); + + /* If cursor is sitting on the new line, then we + squeeze the pressed character between the last character + and the new line */ + if (editor_buffer[cursor_pos] == '\n') { + insert_char(c); + return; + } + + /* Otherwise, replace character in editor buffer */ + replace_char(c); + return; + } + + return; + + case INSERT: /* Insert Mode */ + switch (c) { + case '\b': /* Backspace case */ + + + if (editor_buffer[cursor_pos-1] == '\n') { + delete_newline(); + return; + } + + shift_buffer_left(); + cursor_pos--; + glConsoleMoveCursorBackward(editor_console); + refresh_from_cursor(editor_buffer+cursor_pos); + return; + + case '\n': + insert_newline(); + return; + + default: + // printf("insert_char: char = %c\n", c); + insert_char(c); + return; + } + default: /* Shouldn't happen */ + return; + + + + + } + + + + +} + +void delete_newline() { + + + if (cursor_pos == 0) + return; + + /* Move console cursor to previous line's end of character */ + glConsoleMoveCursorUp(editor_console); + glConsoleCursorToNextChar('\n', editor_console); + + shift_buffer_left(); + cursor_pos--; + + /* Lazy unoptimal refresh here */ + complete_refresh(); + return; + + + +} + +/* Refreshes entire console but retains initial cursor position */ +void complete_refresh() { + + int sx, sy; + + glConsoleGetCursorPos(&sx, &sy, editor_console); + + glConsoleSetCursorPos(0, 0, editor_console); + + glConsoleClearBuffer(editor_console); + glConsolePrintString(editor_buffer, editor_console); + glConsoleSetCursorPos(sx, sy, editor_console); + + +} +/* Helper function to insert a newline and adjust the graphical console + accordingly. Behavior is same regardless of edit mode type */ +void insert_newline() { + + + /* End of buffer, deny request */ + if (cursor_pos == (MAX_BUFFER_SIZE-1)) + return; + + shift_buffer_right(); + editor_buffer[cursor_pos] = '\n'; + + /* Lazy unoptimal refresh */ + complete_refresh(); + + cursor_pos++; + glConsoleAlignCursorLeft(editor_console); + glConsoleMoveCursorDown(editor_console); +} + +/* Helper function to insert a character. Updates the console and editor buffer + by inserting character at cursor position with passed argument, and moving + the cursor forward if possible */ +void insert_char(char c) { + + /* End of editor buffer, just replace the character instead */ + if (cursor_pos == (MAX_BUFFER_SIZE-1)) { + editor_buffer[cursor_pos] = c; + editor_console->cursor_ptr->symbol = c; + return; + } + + //printf("EDITOR BUFFER WAS:\n%s\n-----------------------------------\n", editor_buffer+cursor_pos); + + /* Shift contents of editor buffer right */ + shift_buffer_right(); + + + /* Now place the passed character at the desired location */ + editor_buffer[cursor_pos] = c; + + // printf("EDITOR BUFFER IS NOW:\n%s\n-----------------------------------\n", editor_buffer+cursor_pos); + + /* Refresh console from current cursor position */ + refresh_from_cursor(editor_buffer+cursor_pos); + + /* Move cursor forward */ + cursor_pos++; + glConsoleMoveCursorForward(editor_console); + +} + +/* Helper function to replace a character. Updates the console and editor buffer + by replacing character at cursor position with passed argument, and + moving the cursor forward if possible */ +void replace_char(char c) { + + /* End of buffer, replace character but dont go forward */ + if (cursor_pos == (MAX_BUFFER_SIZE-1)) { + editor_buffer[cursor_pos] = c; + editor_console->cursor_ptr->symbol = c; + return; + } + + /* Replace character, move cursor forward one */ + editor_buffer[cursor_pos++] = c; + editor_console->cursor_ptr->symbol = c; + glConsoleMoveCursorForward(editor_console); + +} + + +void save_cursor_pos() { + + backup_pos = cursor_pos; + glConsoleGetCursorPos(&cursorx, &cursory, editor_console); + // printf("cursor_x: %d, cursor_y: %d\n", cursorx, cursory); +} + +void restore_cursor_pos() { + + if (backup_pos == -1) + return; + cursor_pos = backup_pos; + glConsoleSetCursorPos(cursorx, cursory, editor_console); + backup_pos = -1; +} + +/* Primarily for optimization, this function refreshs the editor console from the cursor position onward + rather than the entire screen buffer */ +void refresh_from_cursor(char * s) { + + if (s == NULL) + return; + + save_cursor_pos(); + glConsolePrintString(s, editor_console); + restore_cursor_pos(); +} + + +/* Shifts editor buffer right from current cursor position */ +void shift_buffer_right() { + + int i; + char backup, backup2; + + if (cursor_pos == (MAX_BUFFER_SIZE-1)) + return; + + backup = editor_buffer[cursor_pos]; + + for (i = cursor_pos; i < (MAX_BUFFER_SIZE-1); i++) { + backup2 = editor_buffer[i+1]; + editor_buffer[i+1] = backup; + backup = backup2; + } + +} + +/* Shifts editor buffer left from current position */ +void shift_buffer_left() { + + + int i; + char backup, backup2; + + if (cursor_pos == 0) + return; + + //printf("cursor at: %c\n", editor_buffer[cursor_pos]); + backup = editor_buffer[MAX_BUFFER_SIZE-1]; + + //printf("shift_buffer_left: [before]\n%s\n", editor_buffer); + + for (i = MAX_BUFFER_SIZE-1; i >= cursor_pos; i--) { + backup2 = editor_buffer[i-1]; + editor_buffer[i-1] = backup; + backup = backup2; + } + // printf("shift_buffer_left: [after]\n%s\n", editor_buffer); + +} diff --git a/src/projectM-engine-backup/editor.h b/src/projectM-engine-backup/editor.h new file mode 100755 index 000000000..697b872df --- /dev/null +++ b/src/projectM-engine-backup/editor.h @@ -0,0 +1,43 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: editor.h,v 1.1.1.1 2005/12/23 18:05:00 psperl Exp $ + * + * $Log: editor.h,v $ + * Revision 1.1.1.1 2005/12/23 18:05:00 psperl + * Imported + */ + +#ifndef _EDITOR_H +#define _EDITOR_H + +#include "event.h" + +void editor_key_handler( projectMEvent event, projectMKeycode keycode ); +void key_helper( projectMKeycode key, projectMEvent event, projectMModifier modifier); +int loadEditor(char * s, void (*func)(), int screen_width, int screen_height, + int scroll_width, int scroll_height, float start_x, float start_y); +int closeEditor(); +void refreshEditor(); + + + +#endif /** !_EDITOR_H */ diff --git a/src/projectM-engine-backup/event.h b/src/projectM-engine-backup/event.h new file mode 100755 index 000000000..c480926e3 --- /dev/null +++ b/src/projectM-engine-backup/event.h @@ -0,0 +1,151 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: event.h,v 1.2 2004/10/08 10:54:27 cvs Exp $ + * + * projectM keycodes. Enables translation from various event schemes such as Win32, SDL + * &c. + * + * $Log: event.h,v $ + */ + +#ifndef _PROJECTM_EVENT_H +#define _PROJECTM_EVENT_H + +typedef enum { + /** Event types */ + PROJECTM_KEYUP, + PROJECTM_KEYDOWN, + PROJECTM_VIDEORESIZE, + PROJECTM_VIDEOQUIT, + } projectMEvent; + +typedef enum { + /** Keycodes */ + PROJECTM_K_RETURN, + PROJECTM_K_RIGHT, + PROJECTM_K_LEFT, + PROJECTM_K_UP, + PROJECTM_K_DOWN, + PROJECTM_K_PAGEUP, + PROJECTM_K_PAGEDOWN, + PROJECTM_K_INSERT, + PROJECTM_K_DELETE, + PROJECTM_K_ESCAPE, + PROJECTM_K_LSHIFT, + PROJECTM_K_RSHIFT, + PROJECTM_K_CAPSLOCK, + PROJECTM_K_LCTRL, + PROJECTM_K_HOME, + PROJECTM_K_END, + PROJECTM_K_BACKSPACE, + + PROJECTM_K_F1, + PROJECTM_K_F2, + PROJECTM_K_F3, + PROJECTM_K_F4, + PROJECTM_K_F5, + PROJECTM_K_F6, + PROJECTM_K_F7, + PROJECTM_K_F8, + PROJECTM_K_F9, + PROJECTM_K_F10, + PROJECTM_K_F11, + PROJECTM_K_F12, + + PROJECTM_K_0 = 48, + PROJECTM_K_1, + PROJECTM_K_2, + PROJECTM_K_3, + PROJECTM_K_4, + PROJECTM_K_5, + PROJECTM_K_6, + PROJECTM_K_7, + PROJECTM_K_8, + PROJECTM_K_9, + + PROJECTM_K_A = 65, + PROJECTM_K_B, + PROJECTM_K_C, + PROJECTM_K_D, + PROJECTM_K_E, + PROJECTM_K_F, + PROJECTM_K_G, + PROJECTM_K_H, + PROJECTM_K_I, + PROJECTM_K_J, + PROJECTM_K_K, + PROJECTM_K_L, + PROJECTM_K_M, + PROJECTM_K_N, + PROJECTM_K_O, + PROJECTM_K_P, + PROJECTM_K_Q, + PROJECTM_K_R, + PROJECTM_K_S, + PROJECTM_K_T, + PROJECTM_K_U, + PROJECTM_K_V, + PROJECTM_K_W, + PROJECTM_K_X, + PROJECTM_K_Y, + PROJECTM_K_Z, + + PROJECTM_K_a = 97, + PROJECTM_K_b, + PROJECTM_K_c, + PROJECTM_K_d, + PROJECTM_K_e, + PROJECTM_K_f, + PROJECTM_K_g, + PROJECTM_K_h, + PROJECTM_K_i, + PROJECTM_K_j, + PROJECTM_K_k, + PROJECTM_K_l, + PROJECTM_K_m, + PROJECTM_K_n, + PROJECTM_K_o, + PROJECTM_K_p, + PROJECTM_K_q, + PROJECTM_K_r, + PROJECTM_K_s, + PROJECTM_K_t, + PROJECTM_K_u, + PROJECTM_K_v, + PROJECTM_K_w, + PROJECTM_K_x, + PROJECTM_K_y, + PROJECTM_K_z, + PROJECTM_K_NONE, + } projectMKeycode; + +typedef enum { + /** Modifiers */ + PROJECTM_KMOD_LSHIFT, + PROJECTM_KMOD_RSHIFT, + PROJECTM_KMOD_CAPS, + PROJECTM_KMOD_LCTRL, + PROJECTM_KMOD_RCTRL, + } projectMModifier; + +#endif /** !_PROJECTM_EVENT_H */ + diff --git a/src/projectM-engine-backup/fatal.h b/src/projectM-engine-backup/fatal.h new file mode 100755 index 000000000..57a62850e --- /dev/null +++ b/src/projectM-engine-backup/fatal.h @@ -0,0 +1,43 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: fatal.h,v 1.1.1.1 2005/12/23 18:05:05 psperl Exp $ + * + * Error codes + * + * $Log$ + */ + +#ifndef _FATAL_H +#define _FATAL_H + +/* Fatal Error Definitions */ + +#define PROJECTM_OUTOFMEM_ERROR -7; /* out of memory */ +#define PROJECTM_ERROR -1 /* non specific error */ +#define PROJECTM_SUCCESS 1 +#define PROJECTM_FAILURE -1 +#define PROJECTM_PARSE_ERROR -11 +#define PROJECTM_DIV_BY_ZERO -3 +#define PROJECTM_OK 2 + +#endif /** !_FATAL_H */ + diff --git a/src/projectM-engine-backup/fftsg.cpp b/src/projectM-engine-backup/fftsg.cpp new file mode 100755 index 000000000..d005f77c5 --- /dev/null +++ b/src/projectM-engine-backup/fftsg.cpp @@ -0,0 +1,3314 @@ +/* +Fast Fourier/Cosine/Sine Transform + dimension :one + data length :power of 2 + decimation :frequency + radix :split-radix + data :inplace + table :use +functions + cdft: Complex Discrete Fourier Transform + rdft: Real Discrete Fourier Transform + ddct: Discrete Cosine Transform + ddst: Discrete Sine Transform + dfct: Cosine Transform of RDFT (Real Symmetric DFT) + dfst: Sine Transform of RDFT (Real Anti-symmetric DFT) +function prototypes + void cdft(int, int, double *, int *, double *); + void rdft(int, int, double *, int *, double *); + void ddct(int, int, double *, int *, double *); + void ddst(int, int, double *, int *, double *); + void dfct(int, double *, double *, int *, double *); + void dfst(int, double *, double *, int *, double *); +macro definitions + USE_CDFT_PTHREADS : default=not defined + CDFT_THREADS_BEGIN_N : must be >= 512, default=8192 + CDFT_4THREADS_BEGIN_N : must be >= 512, default=65536 + USE_CDFT_WINTHREADS : default=not defined + CDFT_THREADS_BEGIN_N : must be >= 512, default=32768 + CDFT_4THREADS_BEGIN_N : must be >= 512, default=524288 + + +-------- Complex DFT (Discrete Fourier Transform) -------- + [definition] + + X[k] = sum_j=0^n-1 x[j]*exp(2*pi*i*j*k/n), 0<=k + X[k] = sum_j=0^n-1 x[j]*exp(-2*pi*i*j*k/n), 0<=k + ip[0] = 0; // first time only + cdft(2*n, 1, a, ip, w); + + ip[0] = 0; // first time only + cdft(2*n, -1, a, ip, w); + [parameters] + 2*n :data length (int) + n >= 1, n = power of 2 + a[0...2*n-1] :input/output data (double *) + input data + a[2*j] = Re(x[j]), + a[2*j+1] = Im(x[j]), 0<=j= 2+sqrt(n) + strictly, + length of ip >= + 2+(1<<(int)(log(n+0.5)/log(2))/2). + ip[0],ip[1] are pointers of the cos/sin table. + w[0...n/2-1] :cos/sin table (double *) + w[],ip[] are initialized if ip[0] == 0. + [remark] + Inverse of + cdft(2*n, -1, a, ip, w); + is + cdft(2*n, 1, a, ip, w); + for (j = 0; j <= 2 * n - 1; j++) { + a[j] *= 1.0 / n; + } + . + + +-------- Real DFT / Inverse of Real DFT -------- + [definition] + RDFT + R[k] = sum_j=0^n-1 a[j]*cos(2*pi*j*k/n), 0<=k<=n/2 + I[k] = sum_j=0^n-1 a[j]*sin(2*pi*j*k/n), 0 IRDFT (excluding scale) + a[k] = (R[0] + R[n/2]*cos(pi*k))/2 + + sum_j=1^n/2-1 R[j]*cos(2*pi*j*k/n) + + sum_j=1^n/2-1 I[j]*sin(2*pi*j*k/n), 0<=k + ip[0] = 0; // first time only + rdft(n, 1, a, ip, w); + + ip[0] = 0; // first time only + rdft(n, -1, a, ip, w); + [parameters] + n :data length (int) + n >= 2, n = power of 2 + a[0...n-1] :input/output data (double *) + + output data + a[2*k] = R[k], 0<=k + input data + a[2*j] = R[j], 0<=j= 2+sqrt(n/2) + strictly, + length of ip >= + 2+(1<<(int)(log(n/2+0.5)/log(2))/2). + ip[0],ip[1] are pointers of the cos/sin table. + w[0...n/2-1] :cos/sin table (double *) + w[],ip[] are initialized if ip[0] == 0. + [remark] + Inverse of + rdft(n, 1, a, ip, w); + is + rdft(n, -1, a, ip, w); + for (j = 0; j <= n - 1; j++) { + a[j] *= 2.0 / n; + } + . + + +-------- DCT (Discrete Cosine Transform) / Inverse of DCT -------- + [definition] + IDCT (excluding scale) + C[k] = sum_j=0^n-1 a[j]*cos(pi*j*(k+1/2)/n), 0<=k DCT + C[k] = sum_j=0^n-1 a[j]*cos(pi*(j+1/2)*k/n), 0<=k + ip[0] = 0; // first time only + ddct(n, 1, a, ip, w); + + ip[0] = 0; // first time only + ddct(n, -1, a, ip, w); + [parameters] + n :data length (int) + n >= 2, n = power of 2 + a[0...n-1] :input/output data (double *) + output data + a[k] = C[k], 0<=k= 2+sqrt(n/2) + strictly, + length of ip >= + 2+(1<<(int)(log(n/2+0.5)/log(2))/2). + ip[0],ip[1] are pointers of the cos/sin table. + w[0...n*5/4-1] :cos/sin table (double *) + w[],ip[] are initialized if ip[0] == 0. + [remark] + Inverse of + ddct(n, -1, a, ip, w); + is + a[0] *= 0.5; + ddct(n, 1, a, ip, w); + for (j = 0; j <= n - 1; j++) { + a[j] *= 2.0 / n; + } + . + + +-------- DST (Discrete Sine Transform) / Inverse of DST -------- + [definition] + IDST (excluding scale) + S[k] = sum_j=1^n A[j]*sin(pi*j*(k+1/2)/n), 0<=k DST + S[k] = sum_j=0^n-1 a[j]*sin(pi*(j+1/2)*k/n), 0 + ip[0] = 0; // first time only + ddst(n, 1, a, ip, w); + + ip[0] = 0; // first time only + ddst(n, -1, a, ip, w); + [parameters] + n :data length (int) + n >= 2, n = power of 2 + a[0...n-1] :input/output data (double *) + + input data + a[j] = A[j], 0 + output data + a[k] = S[k], 0= 2+sqrt(n/2) + strictly, + length of ip >= + 2+(1<<(int)(log(n/2+0.5)/log(2))/2). + ip[0],ip[1] are pointers of the cos/sin table. + w[0...n*5/4-1] :cos/sin table (double *) + w[],ip[] are initialized if ip[0] == 0. + [remark] + Inverse of + ddst(n, -1, a, ip, w); + is + a[0] *= 0.5; + ddst(n, 1, a, ip, w); + for (j = 0; j <= n - 1; j++) { + a[j] *= 2.0 / n; + } + . + + +-------- Cosine Transform of RDFT (Real Symmetric DFT) -------- + [definition] + C[k] = sum_j=0^n a[j]*cos(pi*j*k/n), 0<=k<=n + [usage] + ip[0] = 0; // first time only + dfct(n, a, t, ip, w); + [parameters] + n :data length - 1 (int) + n >= 2, n = power of 2 + a[0...n] :input/output data (double *) + output data + a[k] = C[k], 0<=k<=n + t[0...n/2] :work area (double *) + ip[0...*] :work area for bit reversal (int *) + length of ip >= 2+sqrt(n/4) + strictly, + length of ip >= + 2+(1<<(int)(log(n/4+0.5)/log(2))/2). + ip[0],ip[1] are pointers of the cos/sin table. + w[0...n*5/8-1] :cos/sin table (double *) + w[],ip[] are initialized if ip[0] == 0. + [remark] + Inverse of + a[0] *= 0.5; + a[n] *= 0.5; + dfct(n, a, t, ip, w); + is + a[0] *= 0.5; + a[n] *= 0.5; + dfct(n, a, t, ip, w); + for (j = 0; j <= n; j++) { + a[j] *= 2.0 / n; + } + . + + +-------- Sine Transform of RDFT (Real Anti-symmetric DFT) -------- + [definition] + S[k] = sum_j=1^n-1 a[j]*sin(pi*j*k/n), 0= 2, n = power of 2 + a[0...n-1] :input/output data (double *) + output data + a[k] = S[k], 0= 2+sqrt(n/4) + strictly, + length of ip >= + 2+(1<<(int)(log(n/4+0.5)/log(2))/2). + ip[0],ip[1] are pointers of the cos/sin table. + w[0...n*5/8-1] :cos/sin table (double *) + w[],ip[] are initialized if ip[0] == 0. + [remark] + Inverse of + dfst(n, a, t, ip, w); + is + dfst(n, a, t, ip, w); + for (j = 1; j <= n - 1; j++) { + a[j] *= 2.0 / n; + } + . + + +Appendix : + The cos/sin table is recalculated when the larger table required. + w[] and ip[] are compatible with all routines. +*/ + + +void cdft(int n, int isgn, double *a, int *ip, double *w) +{ + void makewt(int nw, int *ip, double *w); + void cftfsub(int n, double *a, int *ip, int nw, double *w); + void cftbsub(int n, double *a, int *ip, int nw, double *w); + int nw; + + nw = ip[0]; + if (n > (nw << 2)) { + nw = n >> 2; + makewt(nw, ip, w); + } + if (isgn >= 0) { + cftfsub(n, a, ip, nw, w); + } else { + cftbsub(n, a, ip, nw, w); + } +} + + +void rdft(int n, int isgn, double *a, int *ip, double *w) +{ + void makewt(int nw, int *ip, double *w); + void makect(int nc, int *ip, double *c); + void cftfsub(int n, double *a, int *ip, int nw, double *w); + void cftbsub(int n, double *a, int *ip, int nw, double *w); + void rftfsub(int n, double *a, int nc, double *c); + void rftbsub(int n, double *a, int nc, double *c); + int nw, nc; + double xi; + + nw = ip[0]; + if (n > (nw << 2)) { + nw = n >> 2; + makewt(nw, ip, w); + } + nc = ip[1]; + if (n > (nc << 2)) { + nc = n >> 2; + makect(nc, ip, w + nw); + } + if (isgn >= 0) { + if (n > 4) { + cftfsub(n, a, ip, nw, w); + rftfsub(n, a, nc, w + nw); + } else if (n == 4) { + cftfsub(n, a, ip, nw, w); + } + xi = a[0] - a[1]; + a[0] += a[1]; + a[1] = xi; + } else { + a[1] = 0.5 * (a[0] - a[1]); + a[0] -= a[1]; + if (n > 4) { + rftbsub(n, a, nc, w + nw); + cftbsub(n, a, ip, nw, w); + } else if (n == 4) { + cftbsub(n, a, ip, nw, w); + } + } +} + + +void ddct(int n, int isgn, double *a, int *ip, double *w) +{ + void makewt(int nw, int *ip, double *w); + void makect(int nc, int *ip, double *c); + void cftfsub(int n, double *a, int *ip, int nw, double *w); + void cftbsub(int n, double *a, int *ip, int nw, double *w); + void rftfsub(int n, double *a, int nc, double *c); + void rftbsub(int n, double *a, int nc, double *c); + void dctsub(int n, double *a, int nc, double *c); + int j, nw, nc; + double xr; + + nw = ip[0]; + if (n > (nw << 2)) { + nw = n >> 2; + makewt(nw, ip, w); + } + nc = ip[1]; + if (n > nc) { + nc = n; + makect(nc, ip, w + nw); + } + if (isgn < 0) { + xr = a[n - 1]; + for (j = n - 2; j >= 2; j -= 2) { + a[j + 1] = a[j] - a[j - 1]; + a[j] += a[j - 1]; + } + a[1] = a[0] - xr; + a[0] += xr; + if (n > 4) { + rftbsub(n, a, nc, w + nw); + cftbsub(n, a, ip, nw, w); + } else if (n == 4) { + cftbsub(n, a, ip, nw, w); + } + } + dctsub(n, a, nc, w + nw); + if (isgn >= 0) { + if (n > 4) { + cftfsub(n, a, ip, nw, w); + rftfsub(n, a, nc, w + nw); + } else if (n == 4) { + cftfsub(n, a, ip, nw, w); + } + xr = a[0] - a[1]; + a[0] += a[1]; + for (j = 2; j < n; j += 2) { + a[j - 1] = a[j] - a[j + 1]; + a[j] += a[j + 1]; + } + a[n - 1] = xr; + } +} + + +void ddst(int n, int isgn, double *a, int *ip, double *w) +{ + void makewt(int nw, int *ip, double *w); + void makect(int nc, int *ip, double *c); + void cftfsub(int n, double *a, int *ip, int nw, double *w); + void cftbsub(int n, double *a, int *ip, int nw, double *w); + void rftfsub(int n, double *a, int nc, double *c); + void rftbsub(int n, double *a, int nc, double *c); + void dstsub(int n, double *a, int nc, double *c); + int j, nw, nc; + double xr; + + nw = ip[0]; + if (n > (nw << 2)) { + nw = n >> 2; + makewt(nw, ip, w); + } + nc = ip[1]; + if (n > nc) { + nc = n; + makect(nc, ip, w + nw); + } + if (isgn < 0) { + xr = a[n - 1]; + for (j = n - 2; j >= 2; j -= 2) { + a[j + 1] = -a[j] - a[j - 1]; + a[j] -= a[j - 1]; + } + a[1] = a[0] + xr; + a[0] -= xr; + if (n > 4) { + rftbsub(n, a, nc, w + nw); + cftbsub(n, a, ip, nw, w); + } else if (n == 4) { + cftbsub(n, a, ip, nw, w); + } + } + dstsub(n, a, nc, w + nw); + if (isgn >= 0) { + if (n > 4) { + cftfsub(n, a, ip, nw, w); + rftfsub(n, a, nc, w + nw); + } else if (n == 4) { + cftfsub(n, a, ip, nw, w); + } + xr = a[0] - a[1]; + a[0] += a[1]; + for (j = 2; j < n; j += 2) { + a[j - 1] = -a[j] - a[j + 1]; + a[j] -= a[j + 1]; + } + a[n - 1] = -xr; + } +} + + +void dfct(int n, double *a, double *t, int *ip, double *w) +{ + void makewt(int nw, int *ip, double *w); + void makect(int nc, int *ip, double *c); + void cftfsub(int n, double *a, int *ip, int nw, double *w); + void rftfsub(int n, double *a, int nc, double *c); + void dctsub(int n, double *a, int nc, double *c); + int j, k, l, m, mh, nw, nc; + double xr, xi, yr, yi; + + nw = ip[0]; + if (n > (nw << 3)) { + nw = n >> 3; + makewt(nw, ip, w); + } + nc = ip[1]; + if (n > (nc << 1)) { + nc = n >> 1; + makect(nc, ip, w + nw); + } + m = n >> 1; + yi = a[m]; + xi = a[0] + a[n]; + a[0] -= a[n]; + t[0] = xi - yi; + t[m] = xi + yi; + if (n > 2) { + mh = m >> 1; + for (j = 1; j < mh; j++) { + k = m - j; + xr = a[j] - a[n - j]; + xi = a[j] + a[n - j]; + yr = a[k] - a[n - k]; + yi = a[k] + a[n - k]; + a[j] = xr; + a[k] = yr; + t[j] = xi - yi; + t[k] = xi + yi; + } + t[mh] = a[mh] + a[n - mh]; + a[mh] -= a[n - mh]; + dctsub(m, a, nc, w + nw); + if (m > 4) { + cftfsub(m, a, ip, nw, w); + rftfsub(m, a, nc, w + nw); + } else if (m == 4) { + cftfsub(m, a, ip, nw, w); + } + a[n - 1] = a[0] - a[1]; + a[1] = a[0] + a[1]; + for (j = m - 2; j >= 2; j -= 2) { + a[2 * j + 1] = a[j] + a[j + 1]; + a[2 * j - 1] = a[j] - a[j + 1]; + } + l = 2; + m = mh; + while (m >= 2) { + dctsub(m, t, nc, w + nw); + if (m > 4) { + cftfsub(m, t, ip, nw, w); + rftfsub(m, t, nc, w + nw); + } else if (m == 4) { + cftfsub(m, t, ip, nw, w); + } + a[n - l] = t[0] - t[1]; + a[l] = t[0] + t[1]; + k = 0; + for (j = 2; j < m; j += 2) { + k += l << 2; + a[k - l] = t[j] - t[j + 1]; + a[k + l] = t[j] + t[j + 1]; + } + l <<= 1; + mh = m >> 1; + for (j = 0; j < mh; j++) { + k = m - j; + t[j] = t[m + k] - t[m + j]; + t[k] = t[m + k] + t[m + j]; + } + t[mh] = t[m + mh]; + m = mh; + } + a[l] = t[0]; + a[n] = t[2] - t[1]; + a[0] = t[2] + t[1]; + } else { + a[1] = a[0]; + a[2] = t[0]; + a[0] = t[1]; + } +} + + +void dfst(int n, double *a, double *t, int *ip, double *w) +{ + void makewt(int nw, int *ip, double *w); + void makect(int nc, int *ip, double *c); + void cftfsub(int n, double *a, int *ip, int nw, double *w); + void rftfsub(int n, double *a, int nc, double *c); + void dstsub(int n, double *a, int nc, double *c); + int j, k, l, m, mh, nw, nc; + double xr, xi, yr, yi; + + nw = ip[0]; + if (n > (nw << 3)) { + nw = n >> 3; + makewt(nw, ip, w); + } + nc = ip[1]; + if (n > (nc << 1)) { + nc = n >> 1; + makect(nc, ip, w + nw); + } + if (n > 2) { + m = n >> 1; + mh = m >> 1; + for (j = 1; j < mh; j++) { + k = m - j; + xr = a[j] + a[n - j]; + xi = a[j] - a[n - j]; + yr = a[k] + a[n - k]; + yi = a[k] - a[n - k]; + a[j] = xr; + a[k] = yr; + t[j] = xi + yi; + t[k] = xi - yi; + } + t[0] = a[mh] - a[n - mh]; + a[mh] += a[n - mh]; + a[0] = a[m]; + dstsub(m, a, nc, w + nw); + if (m > 4) { + cftfsub(m, a, ip, nw, w); + rftfsub(m, a, nc, w + nw); + } else if (m == 4) { + cftfsub(m, a, ip, nw, w); + } + a[n - 1] = a[1] - a[0]; + a[1] = a[0] + a[1]; + for (j = m - 2; j >= 2; j -= 2) { + a[2 * j + 1] = a[j] - a[j + 1]; + a[2 * j - 1] = -a[j] - a[j + 1]; + } + l = 2; + m = mh; + while (m >= 2) { + dstsub(m, t, nc, w + nw); + if (m > 4) { + cftfsub(m, t, ip, nw, w); + rftfsub(m, t, nc, w + nw); + } else if (m == 4) { + cftfsub(m, t, ip, nw, w); + } + a[n - l] = t[1] - t[0]; + a[l] = t[0] + t[1]; + k = 0; + for (j = 2; j < m; j += 2) { + k += l << 2; + a[k - l] = -t[j] - t[j + 1]; + a[k + l] = t[j] - t[j + 1]; + } + l <<= 1; + mh = m >> 1; + for (j = 1; j < mh; j++) { + k = m - j; + t[j] = t[m + k] + t[m + j]; + t[k] = t[m + k] - t[m + j]; + } + t[0] = t[m + mh]; + m = mh; + } + a[l] = t[0]; + } + a[0] = 0; +} + + +/* -------- initializing routines -------- */ + + +#include + +void makewt(int nw, int *ip, double *w) +{ + void makeipt(int nw, int *ip); + int j, nwh, nw0, nw1; + double delta, wn4r, wk1r, wk1i, wk3r, wk3i; + + ip[0] = nw; + ip[1] = 1; + if (nw > 2) { + nwh = nw >> 1; + delta = atan(1.0) / nwh; + wn4r = cos(delta * nwh); + w[0] = 1; + w[1] = wn4r; + if (nwh == 4) { + w[2] = cos(delta * 2); + w[3] = sin(delta * 2); + } else if (nwh > 4) { + makeipt(nw, ip); + w[2] = 0.5 / cos(delta * 2); + w[3] = 0.5 / cos(delta * 6); + for (j = 4; j < nwh; j += 4) { + w[j] = cos(delta * j); + w[j + 1] = sin(delta * j); + w[j + 2] = cos(3 * delta * j); + w[j + 3] = -sin(3 * delta * j); + } + } + nw0 = 0; + while (nwh > 2) { + nw1 = nw0 + nwh; + nwh >>= 1; + w[nw1] = 1; + w[nw1 + 1] = wn4r; + if (nwh == 4) { + wk1r = w[nw0 + 4]; + wk1i = w[nw0 + 5]; + w[nw1 + 2] = wk1r; + w[nw1 + 3] = wk1i; + } else if (nwh > 4) { + wk1r = w[nw0 + 4]; + wk3r = w[nw0 + 6]; + w[nw1 + 2] = 0.5 / wk1r; + w[nw1 + 3] = 0.5 / wk3r; + for (j = 4; j < nwh; j += 4) { + wk1r = w[nw0 + 2 * j]; + wk1i = w[nw0 + 2 * j + 1]; + wk3r = w[nw0 + 2 * j + 2]; + wk3i = w[nw0 + 2 * j + 3]; + w[nw1 + j] = wk1r; + w[nw1 + j + 1] = wk1i; + w[nw1 + j + 2] = wk3r; + w[nw1 + j + 3] = wk3i; + } + } + nw0 = nw1; + } + } +} + + +void makeipt(int nw, int *ip) +{ + int j, l, m, m2, p, q; + + ip[2] = 0; + ip[3] = 16; + m = 2; + for (l = nw; l > 32; l >>= 2) { + m2 = m << 1; + q = m2 << 3; + for (j = m; j < m2; j++) { + p = ip[j] << 2; + ip[m + j] = p; + ip[m2 + j] = p + q; + } + m = m2; + } +} + + +void makect(int nc, int *ip, double *c) +{ + int j, nch; + double delta; + + ip[1] = nc; + if (nc > 1) { + nch = nc >> 1; + delta = atan(1.0) / nch; + c[0] = cos(delta * nch); + c[nch] = 0.5 * c[0]; + for (j = 1; j < nch; j++) { + c[j] = 0.5 * cos(delta * j); + c[nc - j] = 0.5 * sin(delta * j); + } + } +} + + +/* -------- child routines -------- */ + + +#ifdef USE_CDFT_PTHREADS +#define USE_CDFT_THREADS +#ifndef CDFT_THREADS_BEGIN_N +#define CDFT_THREADS_BEGIN_N 8192 +#endif +#ifndef CDFT_4THREADS_BEGIN_N +#define CDFT_4THREADS_BEGIN_N 65536 +#endif +#include +#include +#include +#define cdft_thread_t pthread_t +#define cdft_thread_create(thp,func,argp) { \ + if (pthread_create(thp, NULL, func, (void *) argp) != 0) { \ + fprintf(stderr, "cdft thread error\n"); \ + exit(1); \ + } \ +} +#define cdft_thread_wait(th) { \ + if (pthread_join(th, NULL) != 0) { \ + fprintf(stderr, "cdft thread error\n"); \ + exit(1); \ + } \ +} +#endif /* USE_CDFT_PTHREADS */ + + +#ifdef USE_CDFT_WINTHREADS +#define USE_CDFT_THREADS +#ifndef CDFT_THREADS_BEGIN_N +#define CDFT_THREADS_BEGIN_N 32768 +#endif +#ifndef CDFT_4THREADS_BEGIN_N +#define CDFT_4THREADS_BEGIN_N 524288 +#endif +#include +#include +#include +#define cdft_thread_t HANDLE +#define cdft_thread_create(thp,func,argp) { \ + DWORD thid; \ + *(thp) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, (LPVOID) argp, 0, &thid); \ + if (*(thp) == 0) { \ + fprintf(stderr, "cdft thread error\n"); \ + exit(1); \ + } \ +} +#define cdft_thread_wait(th) { \ + WaitForSingleObject(th, INFINITE); \ + CloseHandle(th); \ +} +#endif /* USE_CDFT_WINTHREADS */ + + +void cftfsub(int n, double *a, int *ip, int nw, double *w) +{ + void bitrv2(int n, int *ip, double *a); + void bitrv216(double *a); + void bitrv208(double *a); + void cftf1st(int n, double *a, double *w); + void cftrec4(int n, double *a, int nw, double *w); + void cftleaf(int n, int isplt, double *a, int nw, double *w); + void cftfx41(int n, double *a, int nw, double *w); + void cftf161(double *a, double *w); + void cftf081(double *a, double *w); + void cftf040(double *a); + void cftx020(double *a); +#ifdef USE_CDFT_THREADS + void cftrec4_th(int n, double *a, int nw, double *w); +#endif /* USE_CDFT_THREADS */ + + if (n > 8) { + if (n > 32) { + cftf1st(n, a, &w[nw - (n >> 2)]); +#ifdef USE_CDFT_THREADS + if (n > CDFT_THREADS_BEGIN_N) { + cftrec4_th(n, a, nw, w); + } else +#endif /* USE_CDFT_THREADS */ + if (n > 512) { + cftrec4(n, a, nw, w); + } else if (n > 128) { + cftleaf(n, 1, a, nw, w); + } else { + cftfx41(n, a, nw, w); + } + bitrv2(n, ip, a); + } else if (n == 32) { + cftf161(a, &w[nw - 8]); + bitrv216(a); + } else { + cftf081(a, w); + bitrv208(a); + } + } else if (n == 8) { + cftf040(a); + } else if (n == 4) { + cftx020(a); + } +} + + +void cftbsub(int n, double *a, int *ip, int nw, double *w) +{ + void bitrv2conj(int n, int *ip, double *a); + void bitrv216neg(double *a); + void bitrv208neg(double *a); + void cftb1st(int n, double *a, double *w); + void cftrec4(int n, double *a, int nw, double *w); + void cftleaf(int n, int isplt, double *a, int nw, double *w); + void cftfx41(int n, double *a, int nw, double *w); + void cftf161(double *a, double *w); + void cftf081(double *a, double *w); + void cftb040(double *a); + void cftx020(double *a); +#ifdef USE_CDFT_THREADS + void cftrec4_th(int n, double *a, int nw, double *w); +#endif /* USE_CDFT_THREADS */ + + if (n > 8) { + if (n > 32) { + cftb1st(n, a, &w[nw - (n >> 2)]); +#ifdef USE_CDFT_THREADS + if (n > CDFT_THREADS_BEGIN_N) { + cftrec4_th(n, a, nw, w); + } else +#endif /* USE_CDFT_THREADS */ + if (n > 512) { + cftrec4(n, a, nw, w); + } else if (n > 128) { + cftleaf(n, 1, a, nw, w); + } else { + cftfx41(n, a, nw, w); + } + bitrv2conj(n, ip, a); + } else if (n == 32) { + cftf161(a, &w[nw - 8]); + bitrv216neg(a); + } else { + cftf081(a, w); + bitrv208neg(a); + } + } else if (n == 8) { + cftb040(a); + } else if (n == 4) { + cftx020(a); + } +} + + +void bitrv2(int n, int *ip, double *a) +{ + int j, j1, k, k1, l, m, nh, nm; + double xr, xi, yr, yi; + + m = 1; + for (l = n >> 2; l > 8; l >>= 2) { + m <<= 1; + } + nh = n >> 1; + nm = 4 * m; + if (l == 8) { + for (k = 0; k < m; k++) { + for (j = 0; j < k; j++) { + j1 = 4 * j + 2 * ip[m + k]; + k1 = 4 * k + 2 * ip[m + j]; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += 2 * nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 -= nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += 2 * nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nh; + k1 += 2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= 2 * nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 += nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= 2 * nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += 2; + k1 += nh; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += 2 * nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 -= nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += 2 * nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nh; + k1 -= 2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= 2 * nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 += nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= 2 * nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + } + k1 = 4 * k + 2 * ip[m + k]; + j1 = k1 + 2; + k1 += nh; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += 2 * nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 -= nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= 2; + k1 -= nh; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nh + 2; + k1 += nh + 2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nh - nm; + k1 += 2 * nm - 2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + } + } else { + for (k = 0; k < m; k++) { + for (j = 0; j < k; j++) { + j1 = 4 * j + ip[m + k]; + k1 = 4 * k + ip[m + j]; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nh; + k1 += 2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += 2; + k1 += nh; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nh; + k1 -= 2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + } + k1 = 4 * k + ip[m + k]; + j1 = k1 + 2; + k1 += nh; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += nm; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + } + } +} + + +void bitrv2conj(int n, int *ip, double *a) +{ + int j, j1, k, k1, l, m, nh, nm; + double xr, xi, yr, yi; + + m = 1; + for (l = n >> 2; l > 8; l >>= 2) { + m <<= 1; + } + nh = n >> 1; + nm = 4 * m; + if (l == 8) { + for (k = 0; k < m; k++) { + for (j = 0; j < k; j++) { + j1 = 4 * j + 2 * ip[m + k]; + k1 = 4 * k + 2 * ip[m + j]; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += 2 * nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 -= nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += 2 * nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nh; + k1 += 2; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= 2 * nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 += nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= 2 * nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += 2; + k1 += nh; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += 2 * nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 -= nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += 2 * nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nh; + k1 -= 2; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= 2 * nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 += nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= 2 * nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + } + k1 = 4 * k + 2 * ip[m + k]; + j1 = k1 + 2; + k1 += nh; + a[j1 - 1] = -a[j1 - 1]; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + a[k1 + 3] = -a[k1 + 3]; + j1 += nm; + k1 += 2 * nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 -= nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= 2; + k1 -= nh; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nh + 2; + k1 += nh + 2; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nh - nm; + k1 += 2 * nm - 2; + a[j1 - 1] = -a[j1 - 1]; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + a[k1 + 3] = -a[k1 + 3]; + } + } else { + for (k = 0; k < m; k++) { + for (j = 0; j < k; j++) { + j1 = 4 * j + ip[m + k]; + k1 = 4 * k + ip[m + j]; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nh; + k1 += 2; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += 2; + k1 += nh; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += nm; + k1 += nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nh; + k1 -= 2; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 -= nm; + k1 -= nm; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + } + k1 = 4 * k + ip[m + k]; + j1 = k1 + 2; + k1 += nh; + a[j1 - 1] = -a[j1 - 1]; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + a[k1 + 3] = -a[k1 + 3]; + j1 += nm; + k1 += nm; + a[j1 - 1] = -a[j1 - 1]; + xr = a[j1]; + xi = -a[j1 + 1]; + yr = a[k1]; + yi = -a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + a[k1 + 3] = -a[k1 + 3]; + } + } +} + + +void bitrv216(double *a) +{ + double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i, + x5r, x5i, x7r, x7i, x8r, x8i, x10r, x10i, + x11r, x11i, x12r, x12i, x13r, x13i, x14r, x14i; + + x1r = a[2]; + x1i = a[3]; + x2r = a[4]; + x2i = a[5]; + x3r = a[6]; + x3i = a[7]; + x4r = a[8]; + x4i = a[9]; + x5r = a[10]; + x5i = a[11]; + x7r = a[14]; + x7i = a[15]; + x8r = a[16]; + x8i = a[17]; + x10r = a[20]; + x10i = a[21]; + x11r = a[22]; + x11i = a[23]; + x12r = a[24]; + x12i = a[25]; + x13r = a[26]; + x13i = a[27]; + x14r = a[28]; + x14i = a[29]; + a[2] = x8r; + a[3] = x8i; + a[4] = x4r; + a[5] = x4i; + a[6] = x12r; + a[7] = x12i; + a[8] = x2r; + a[9] = x2i; + a[10] = x10r; + a[11] = x10i; + a[14] = x14r; + a[15] = x14i; + a[16] = x1r; + a[17] = x1i; + a[20] = x5r; + a[21] = x5i; + a[22] = x13r; + a[23] = x13i; + a[24] = x3r; + a[25] = x3i; + a[26] = x11r; + a[27] = x11i; + a[28] = x7r; + a[29] = x7i; +} + + +void bitrv216neg(double *a) +{ + double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i, + x5r, x5i, x6r, x6i, x7r, x7i, x8r, x8i, + x9r, x9i, x10r, x10i, x11r, x11i, x12r, x12i, + x13r, x13i, x14r, x14i, x15r, x15i; + + x1r = a[2]; + x1i = a[3]; + x2r = a[4]; + x2i = a[5]; + x3r = a[6]; + x3i = a[7]; + x4r = a[8]; + x4i = a[9]; + x5r = a[10]; + x5i = a[11]; + x6r = a[12]; + x6i = a[13]; + x7r = a[14]; + x7i = a[15]; + x8r = a[16]; + x8i = a[17]; + x9r = a[18]; + x9i = a[19]; + x10r = a[20]; + x10i = a[21]; + x11r = a[22]; + x11i = a[23]; + x12r = a[24]; + x12i = a[25]; + x13r = a[26]; + x13i = a[27]; + x14r = a[28]; + x14i = a[29]; + x15r = a[30]; + x15i = a[31]; + a[2] = x15r; + a[3] = x15i; + a[4] = x7r; + a[5] = x7i; + a[6] = x11r; + a[7] = x11i; + a[8] = x3r; + a[9] = x3i; + a[10] = x13r; + a[11] = x13i; + a[12] = x5r; + a[13] = x5i; + a[14] = x9r; + a[15] = x9i; + a[16] = x1r; + a[17] = x1i; + a[18] = x14r; + a[19] = x14i; + a[20] = x6r; + a[21] = x6i; + a[22] = x10r; + a[23] = x10i; + a[24] = x2r; + a[25] = x2i; + a[26] = x12r; + a[27] = x12i; + a[28] = x4r; + a[29] = x4i; + a[30] = x8r; + a[31] = x8i; +} + + +void bitrv208(double *a) +{ + double x1r, x1i, x3r, x3i, x4r, x4i, x6r, x6i; + + x1r = a[2]; + x1i = a[3]; + x3r = a[6]; + x3i = a[7]; + x4r = a[8]; + x4i = a[9]; + x6r = a[12]; + x6i = a[13]; + a[2] = x4r; + a[3] = x4i; + a[6] = x6r; + a[7] = x6i; + a[8] = x1r; + a[9] = x1i; + a[12] = x3r; + a[13] = x3i; +} + + +void bitrv208neg(double *a) +{ + double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i, + x5r, x5i, x6r, x6i, x7r, x7i; + + x1r = a[2]; + x1i = a[3]; + x2r = a[4]; + x2i = a[5]; + x3r = a[6]; + x3i = a[7]; + x4r = a[8]; + x4i = a[9]; + x5r = a[10]; + x5i = a[11]; + x6r = a[12]; + x6i = a[13]; + x7r = a[14]; + x7i = a[15]; + a[2] = x7r; + a[3] = x7i; + a[4] = x3r; + a[5] = x3i; + a[6] = x5r; + a[7] = x5i; + a[8] = x1r; + a[9] = x1i; + a[10] = x6r; + a[11] = x6i; + a[12] = x2r; + a[13] = x2i; + a[14] = x4r; + a[15] = x4i; +} + + +void cftf1st(int n, double *a, double *w) +{ + int j, j0, j1, j2, j3, k, m, mh; + double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i, + wd1r, wd1i, wd3r, wd3i; + double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, + y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i; + + mh = n >> 3; + m = 2 * mh; + j1 = m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[0] + a[j2]; + x0i = a[1] + a[j2 + 1]; + x1r = a[0] - a[j2]; + x1i = a[1] - a[j2 + 1]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + a[0] = x0r + x2r; + a[1] = x0i + x2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i - x2i; + a[j2] = x1r - x3i; + a[j2 + 1] = x1i + x3r; + a[j3] = x1r + x3i; + a[j3 + 1] = x1i - x3r; + wn4r = w[1]; + csc1 = w[2]; + csc3 = w[3]; + wd1r = 1; + wd1i = 0; + wd3r = 1; + wd3i = 0; + k = 0; + for (j = 2; j < mh - 2; j += 4) { + k += 4; + wk1r = csc1 * (wd1r + w[k]); + wk1i = csc1 * (wd1i + w[k + 1]); + wk3r = csc3 * (wd3r + w[k + 2]); + wk3i = csc3 * (wd3i + w[k + 3]); + wd1r = w[k]; + wd1i = w[k + 1]; + wd3r = w[k + 2]; + wd3i = w[k + 3]; + j1 = j + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j] + a[j2]; + x0i = a[j + 1] + a[j2 + 1]; + x1r = a[j] - a[j2]; + x1i = a[j + 1] - a[j2 + 1]; + y0r = a[j + 2] + a[j2 + 2]; + y0i = a[j + 3] + a[j2 + 3]; + y1r = a[j + 2] - a[j2 + 2]; + y1i = a[j + 3] - a[j2 + 3]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + y2r = a[j1 + 2] + a[j3 + 2]; + y2i = a[j1 + 3] + a[j3 + 3]; + y3r = a[j1 + 2] - a[j3 + 2]; + y3i = a[j1 + 3] - a[j3 + 3]; + a[j] = x0r + x2r; + a[j + 1] = x0i + x2i; + a[j + 2] = y0r + y2r; + a[j + 3] = y0i + y2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i - x2i; + a[j1 + 2] = y0r - y2r; + a[j1 + 3] = y0i - y2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j2] = wk1r * x0r - wk1i * x0i; + a[j2 + 1] = wk1r * x0i + wk1i * x0r; + x0r = y1r - y3i; + x0i = y1i + y3r; + a[j2 + 2] = wd1r * x0r - wd1i * x0i; + a[j2 + 3] = wd1r * x0i + wd1i * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j3] = wk3r * x0r + wk3i * x0i; + a[j3 + 1] = wk3r * x0i - wk3i * x0r; + x0r = y1r + y3i; + x0i = y1i - y3r; + a[j3 + 2] = wd3r * x0r + wd3i * x0i; + a[j3 + 3] = wd3r * x0i - wd3i * x0r; + j0 = m - j; + j1 = j0 + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j0] + a[j2]; + x0i = a[j0 + 1] + a[j2 + 1]; + x1r = a[j0] - a[j2]; + x1i = a[j0 + 1] - a[j2 + 1]; + y0r = a[j0 - 2] + a[j2 - 2]; + y0i = a[j0 - 1] + a[j2 - 1]; + y1r = a[j0 - 2] - a[j2 - 2]; + y1i = a[j0 - 1] - a[j2 - 1]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + y2r = a[j1 - 2] + a[j3 - 2]; + y2i = a[j1 - 1] + a[j3 - 1]; + y3r = a[j1 - 2] - a[j3 - 2]; + y3i = a[j1 - 1] - a[j3 - 1]; + a[j0] = x0r + x2r; + a[j0 + 1] = x0i + x2i; + a[j0 - 2] = y0r + y2r; + a[j0 - 1] = y0i + y2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i - x2i; + a[j1 - 2] = y0r - y2r; + a[j1 - 1] = y0i - y2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j2] = wk1i * x0r - wk1r * x0i; + a[j2 + 1] = wk1i * x0i + wk1r * x0r; + x0r = y1r - y3i; + x0i = y1i + y3r; + a[j2 - 2] = wd1i * x0r - wd1r * x0i; + a[j2 - 1] = wd1i * x0i + wd1r * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j3] = wk3i * x0r + wk3r * x0i; + a[j3 + 1] = wk3i * x0i - wk3r * x0r; + x0r = y1r + y3i; + x0i = y1i - y3r; + a[j3 - 2] = wd3i * x0r + wd3r * x0i; + a[j3 - 1] = wd3i * x0i - wd3r * x0r; + } + wk1r = csc1 * (wd1r + wn4r); + wk1i = csc1 * (wd1i + wn4r); + wk3r = csc3 * (wd3r - wn4r); + wk3i = csc3 * (wd3i - wn4r); + j0 = mh; + j1 = j0 + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j0 - 2] + a[j2 - 2]; + x0i = a[j0 - 1] + a[j2 - 1]; + x1r = a[j0 - 2] - a[j2 - 2]; + x1i = a[j0 - 1] - a[j2 - 1]; + x2r = a[j1 - 2] + a[j3 - 2]; + x2i = a[j1 - 1] + a[j3 - 1]; + x3r = a[j1 - 2] - a[j3 - 2]; + x3i = a[j1 - 1] - a[j3 - 1]; + a[j0 - 2] = x0r + x2r; + a[j0 - 1] = x0i + x2i; + a[j1 - 2] = x0r - x2r; + a[j1 - 1] = x0i - x2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j2 - 2] = wk1r * x0r - wk1i * x0i; + a[j2 - 1] = wk1r * x0i + wk1i * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j3 - 2] = wk3r * x0r + wk3i * x0i; + a[j3 - 1] = wk3r * x0i - wk3i * x0r; + x0r = a[j0] + a[j2]; + x0i = a[j0 + 1] + a[j2 + 1]; + x1r = a[j0] - a[j2]; + x1i = a[j0 + 1] - a[j2 + 1]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + a[j0] = x0r + x2r; + a[j0 + 1] = x0i + x2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i - x2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j2] = wn4r * (x0r - x0i); + a[j2 + 1] = wn4r * (x0i + x0r); + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j3] = -wn4r * (x0r + x0i); + a[j3 + 1] = -wn4r * (x0i - x0r); + x0r = a[j0 + 2] + a[j2 + 2]; + x0i = a[j0 + 3] + a[j2 + 3]; + x1r = a[j0 + 2] - a[j2 + 2]; + x1i = a[j0 + 3] - a[j2 + 3]; + x2r = a[j1 + 2] + a[j3 + 2]; + x2i = a[j1 + 3] + a[j3 + 3]; + x3r = a[j1 + 2] - a[j3 + 2]; + x3i = a[j1 + 3] - a[j3 + 3]; + a[j0 + 2] = x0r + x2r; + a[j0 + 3] = x0i + x2i; + a[j1 + 2] = x0r - x2r; + a[j1 + 3] = x0i - x2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j2 + 2] = wk1i * x0r - wk1r * x0i; + a[j2 + 3] = wk1i * x0i + wk1r * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j3 + 2] = wk3i * x0r + wk3r * x0i; + a[j3 + 3] = wk3i * x0i - wk3r * x0r; +} + + +void cftb1st(int n, double *a, double *w) +{ + int j, j0, j1, j2, j3, k, m, mh; + double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i, + wd1r, wd1i, wd3r, wd3i; + double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, + y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i; + + mh = n >> 3; + m = 2 * mh; + j1 = m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[0] + a[j2]; + x0i = -a[1] - a[j2 + 1]; + x1r = a[0] - a[j2]; + x1i = -a[1] + a[j2 + 1]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + a[0] = x0r + x2r; + a[1] = x0i - x2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i + x2i; + a[j2] = x1r + x3i; + a[j2 + 1] = x1i + x3r; + a[j3] = x1r - x3i; + a[j3 + 1] = x1i - x3r; + wn4r = w[1]; + csc1 = w[2]; + csc3 = w[3]; + wd1r = 1; + wd1i = 0; + wd3r = 1; + wd3i = 0; + k = 0; + for (j = 2; j < mh - 2; j += 4) { + k += 4; + wk1r = csc1 * (wd1r + w[k]); + wk1i = csc1 * (wd1i + w[k + 1]); + wk3r = csc3 * (wd3r + w[k + 2]); + wk3i = csc3 * (wd3i + w[k + 3]); + wd1r = w[k]; + wd1i = w[k + 1]; + wd3r = w[k + 2]; + wd3i = w[k + 3]; + j1 = j + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j] + a[j2]; + x0i = -a[j + 1] - a[j2 + 1]; + x1r = a[j] - a[j2]; + x1i = -a[j + 1] + a[j2 + 1]; + y0r = a[j + 2] + a[j2 + 2]; + y0i = -a[j + 3] - a[j2 + 3]; + y1r = a[j + 2] - a[j2 + 2]; + y1i = -a[j + 3] + a[j2 + 3]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + y2r = a[j1 + 2] + a[j3 + 2]; + y2i = a[j1 + 3] + a[j3 + 3]; + y3r = a[j1 + 2] - a[j3 + 2]; + y3i = a[j1 + 3] - a[j3 + 3]; + a[j] = x0r + x2r; + a[j + 1] = x0i - x2i; + a[j + 2] = y0r + y2r; + a[j + 3] = y0i - y2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i + x2i; + a[j1 + 2] = y0r - y2r; + a[j1 + 3] = y0i + y2i; + x0r = x1r + x3i; + x0i = x1i + x3r; + a[j2] = wk1r * x0r - wk1i * x0i; + a[j2 + 1] = wk1r * x0i + wk1i * x0r; + x0r = y1r + y3i; + x0i = y1i + y3r; + a[j2 + 2] = wd1r * x0r - wd1i * x0i; + a[j2 + 3] = wd1r * x0i + wd1i * x0r; + x0r = x1r - x3i; + x0i = x1i - x3r; + a[j3] = wk3r * x0r + wk3i * x0i; + a[j3 + 1] = wk3r * x0i - wk3i * x0r; + x0r = y1r - y3i; + x0i = y1i - y3r; + a[j3 + 2] = wd3r * x0r + wd3i * x0i; + a[j3 + 3] = wd3r * x0i - wd3i * x0r; + j0 = m - j; + j1 = j0 + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j0] + a[j2]; + x0i = -a[j0 + 1] - a[j2 + 1]; + x1r = a[j0] - a[j2]; + x1i = -a[j0 + 1] + a[j2 + 1]; + y0r = a[j0 - 2] + a[j2 - 2]; + y0i = -a[j0 - 1] - a[j2 - 1]; + y1r = a[j0 - 2] - a[j2 - 2]; + y1i = -a[j0 - 1] + a[j2 - 1]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + y2r = a[j1 - 2] + a[j3 - 2]; + y2i = a[j1 - 1] + a[j3 - 1]; + y3r = a[j1 - 2] - a[j3 - 2]; + y3i = a[j1 - 1] - a[j3 - 1]; + a[j0] = x0r + x2r; + a[j0 + 1] = x0i - x2i; + a[j0 - 2] = y0r + y2r; + a[j0 - 1] = y0i - y2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i + x2i; + a[j1 - 2] = y0r - y2r; + a[j1 - 1] = y0i + y2i; + x0r = x1r + x3i; + x0i = x1i + x3r; + a[j2] = wk1i * x0r - wk1r * x0i; + a[j2 + 1] = wk1i * x0i + wk1r * x0r; + x0r = y1r + y3i; + x0i = y1i + y3r; + a[j2 - 2] = wd1i * x0r - wd1r * x0i; + a[j2 - 1] = wd1i * x0i + wd1r * x0r; + x0r = x1r - x3i; + x0i = x1i - x3r; + a[j3] = wk3i * x0r + wk3r * x0i; + a[j3 + 1] = wk3i * x0i - wk3r * x0r; + x0r = y1r - y3i; + x0i = y1i - y3r; + a[j3 - 2] = wd3i * x0r + wd3r * x0i; + a[j3 - 1] = wd3i * x0i - wd3r * x0r; + } + wk1r = csc1 * (wd1r + wn4r); + wk1i = csc1 * (wd1i + wn4r); + wk3r = csc3 * (wd3r - wn4r); + wk3i = csc3 * (wd3i - wn4r); + j0 = mh; + j1 = j0 + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j0 - 2] + a[j2 - 2]; + x0i = -a[j0 - 1] - a[j2 - 1]; + x1r = a[j0 - 2] - a[j2 - 2]; + x1i = -a[j0 - 1] + a[j2 - 1]; + x2r = a[j1 - 2] + a[j3 - 2]; + x2i = a[j1 - 1] + a[j3 - 1]; + x3r = a[j1 - 2] - a[j3 - 2]; + x3i = a[j1 - 1] - a[j3 - 1]; + a[j0 - 2] = x0r + x2r; + a[j0 - 1] = x0i - x2i; + a[j1 - 2] = x0r - x2r; + a[j1 - 1] = x0i + x2i; + x0r = x1r + x3i; + x0i = x1i + x3r; + a[j2 - 2] = wk1r * x0r - wk1i * x0i; + a[j2 - 1] = wk1r * x0i + wk1i * x0r; + x0r = x1r - x3i; + x0i = x1i - x3r; + a[j3 - 2] = wk3r * x0r + wk3i * x0i; + a[j3 - 1] = wk3r * x0i - wk3i * x0r; + x0r = a[j0] + a[j2]; + x0i = -a[j0 + 1] - a[j2 + 1]; + x1r = a[j0] - a[j2]; + x1i = -a[j0 + 1] + a[j2 + 1]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + a[j0] = x0r + x2r; + a[j0 + 1] = x0i - x2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i + x2i; + x0r = x1r + x3i; + x0i = x1i + x3r; + a[j2] = wn4r * (x0r - x0i); + a[j2 + 1] = wn4r * (x0i + x0r); + x0r = x1r - x3i; + x0i = x1i - x3r; + a[j3] = -wn4r * (x0r + x0i); + a[j3 + 1] = -wn4r * (x0i - x0r); + x0r = a[j0 + 2] + a[j2 + 2]; + x0i = -a[j0 + 3] - a[j2 + 3]; + x1r = a[j0 + 2] - a[j2 + 2]; + x1i = -a[j0 + 3] + a[j2 + 3]; + x2r = a[j1 + 2] + a[j3 + 2]; + x2i = a[j1 + 3] + a[j3 + 3]; + x3r = a[j1 + 2] - a[j3 + 2]; + x3i = a[j1 + 3] - a[j3 + 3]; + a[j0 + 2] = x0r + x2r; + a[j0 + 3] = x0i - x2i; + a[j1 + 2] = x0r - x2r; + a[j1 + 3] = x0i + x2i; + x0r = x1r + x3i; + x0i = x1i + x3r; + a[j2 + 2] = wk1i * x0r - wk1r * x0i; + a[j2 + 3] = wk1i * x0i + wk1r * x0r; + x0r = x1r - x3i; + x0i = x1i - x3r; + a[j3 + 2] = wk3i * x0r + wk3r * x0i; + a[j3 + 3] = wk3i * x0i - wk3r * x0r; +} + + +#ifdef USE_CDFT_THREADS +struct cdft_arg_st { + int n0; + int n; + double *a; + int nw; + double *w; +}; +typedef struct cdft_arg_st cdft_arg_t; + + +void cftrec4_th(int n, double *a, int nw, double *w) +{ + void *cftrec1_th(void *p); + void *cftrec2_th(void *p); + int i, idiv4, m, nthread; + cdft_thread_t th[4]; + cdft_arg_t ag[4]; + + nthread = 2; + idiv4 = 0; + m = n >> 1; + if (n > CDFT_4THREADS_BEGIN_N) { + nthread = 4; + idiv4 = 1; + m >>= 1; + } + for (i = 0; i < nthread; i++) { + ag[i].n0 = n; + ag[i].n = m; + ag[i].a = &a[i * m]; + ag[i].nw = nw; + ag[i].w = w; + if (i != idiv4) { + cdft_thread_create(&th[i], cftrec1_th, &ag[i]); + } else { + cdft_thread_create(&th[i], cftrec2_th, &ag[i]); + } + } + for (i = 0; i < nthread; i++) { + cdft_thread_wait(th[i]); + } +} + + +void *cftrec1_th(void *p) +{ + int cfttree(int n, int j, int k, double *a, int nw, double *w); + void cftleaf(int n, int isplt, double *a, int nw, double *w); + void cftmdl1(int n, double *a, double *w); + int isplt, j, k, m, n, n0, nw; + double *a, *w; + + n0 = ((cdft_arg_t *) p)->n0; + n = ((cdft_arg_t *) p)->n; + a = ((cdft_arg_t *) p)->a; + nw = ((cdft_arg_t *) p)->nw; + w = ((cdft_arg_t *) p)->w; + m = n0; + while (m > 512) { + m >>= 2; + cftmdl1(m, &a[n - m], &w[nw - (m >> 1)]); + } + cftleaf(m, 1, &a[n - m], nw, w); + k = 0; + for (j = n - m; j > 0; j -= m) { + k++; + isplt = cfttree(m, j, k, a, nw, w); + cftleaf(m, isplt, &a[j - m], nw, w); + } + return (void *) 0; +} + + +void *cftrec2_th(void *p) +{ + int cfttree(int n, int j, int k, double *a, int nw, double *w); + void cftleaf(int n, int isplt, double *a, int nw, double *w); + void cftmdl2(int n, double *a, double *w); + int isplt, j, k, m, n, n0, nw; + double *a, *w; + + n0 = ((cdft_arg_t *) p)->n0; + n = ((cdft_arg_t *) p)->n; + a = ((cdft_arg_t *) p)->a; + nw = ((cdft_arg_t *) p)->nw; + w = ((cdft_arg_t *) p)->w; + k = 1; + m = n0; + while (m > 512) { + m >>= 2; + k <<= 2; + cftmdl2(m, &a[n - m], &w[nw - m]); + } + cftleaf(m, 0, &a[n - m], nw, w); + k >>= 1; + for (j = n - m; j > 0; j -= m) { + k++; + isplt = cfttree(m, j, k, a, nw, w); + cftleaf(m, isplt, &a[j - m], nw, w); + } + return (void *) 0; +} +#endif /* USE_CDFT_THREADS */ + + +void cftrec4(int n, double *a, int nw, double *w) +{ + int cfttree(int n, int j, int k, double *a, int nw, double *w); + void cftleaf(int n, int isplt, double *a, int nw, double *w); + void cftmdl1(int n, double *a, double *w); + int isplt, j, k, m; + + m = n; + while (m > 512) { + m >>= 2; + cftmdl1(m, &a[n - m], &w[nw - (m >> 1)]); + } + cftleaf(m, 1, &a[n - m], nw, w); + k = 0; + for (j = n - m; j > 0; j -= m) { + k++; + isplt = cfttree(m, j, k, a, nw, w); + cftleaf(m, isplt, &a[j - m], nw, w); + } +} + + +int cfttree(int n, int j, int k, double *a, int nw, double *w) +{ + void cftmdl1(int n, double *a, double *w); + void cftmdl2(int n, double *a, double *w); + int i, isplt, m; + + if ((k & 3) != 0) { + isplt = k & 1; + if (isplt != 0) { + cftmdl1(n, &a[j - n], &w[nw - (n >> 1)]); + } else { + cftmdl2(n, &a[j - n], &w[nw - n]); + } + } else { + m = n; + for (i = k; (i & 3) == 0; i >>= 2) { + m <<= 2; + } + isplt = i & 1; + if (isplt != 0) { + while (m > 128) { + cftmdl1(m, &a[j - m], &w[nw - (m >> 1)]); + m >>= 2; + } + } else { + while (m > 128) { + cftmdl2(m, &a[j - m], &w[nw - m]); + m >>= 2; + } + } + } + return isplt; +} + + +void cftleaf(int n, int isplt, double *a, int nw, double *w) +{ + void cftmdl1(int n, double *a, double *w); + void cftmdl2(int n, double *a, double *w); + void cftf161(double *a, double *w); + void cftf162(double *a, double *w); + void cftf081(double *a, double *w); + void cftf082(double *a, double *w); + + if (n == 512) { + cftmdl1(128, a, &w[nw - 64]); + cftf161(a, &w[nw - 8]); + cftf162(&a[32], &w[nw - 32]); + cftf161(&a[64], &w[nw - 8]); + cftf161(&a[96], &w[nw - 8]); + cftmdl2(128, &a[128], &w[nw - 128]); + cftf161(&a[128], &w[nw - 8]); + cftf162(&a[160], &w[nw - 32]); + cftf161(&a[192], &w[nw - 8]); + cftf162(&a[224], &w[nw - 32]); + cftmdl1(128, &a[256], &w[nw - 64]); + cftf161(&a[256], &w[nw - 8]); + cftf162(&a[288], &w[nw - 32]); + cftf161(&a[320], &w[nw - 8]); + cftf161(&a[352], &w[nw - 8]); + if (isplt != 0) { + cftmdl1(128, &a[384], &w[nw - 64]); + cftf161(&a[480], &w[nw - 8]); + } else { + cftmdl2(128, &a[384], &w[nw - 128]); + cftf162(&a[480], &w[nw - 32]); + } + cftf161(&a[384], &w[nw - 8]); + cftf162(&a[416], &w[nw - 32]); + cftf161(&a[448], &w[nw - 8]); + } else { + cftmdl1(64, a, &w[nw - 32]); + cftf081(a, &w[nw - 8]); + cftf082(&a[16], &w[nw - 8]); + cftf081(&a[32], &w[nw - 8]); + cftf081(&a[48], &w[nw - 8]); + cftmdl2(64, &a[64], &w[nw - 64]); + cftf081(&a[64], &w[nw - 8]); + cftf082(&a[80], &w[nw - 8]); + cftf081(&a[96], &w[nw - 8]); + cftf082(&a[112], &w[nw - 8]); + cftmdl1(64, &a[128], &w[nw - 32]); + cftf081(&a[128], &w[nw - 8]); + cftf082(&a[144], &w[nw - 8]); + cftf081(&a[160], &w[nw - 8]); + cftf081(&a[176], &w[nw - 8]); + if (isplt != 0) { + cftmdl1(64, &a[192], &w[nw - 32]); + cftf081(&a[240], &w[nw - 8]); + } else { + cftmdl2(64, &a[192], &w[nw - 64]); + cftf082(&a[240], &w[nw - 8]); + } + cftf081(&a[192], &w[nw - 8]); + cftf082(&a[208], &w[nw - 8]); + cftf081(&a[224], &w[nw - 8]); + } +} + + +void cftmdl1(int n, double *a, double *w) +{ + int j, j0, j1, j2, j3, k, m, mh; + double wn4r, wk1r, wk1i, wk3r, wk3i; + double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; + + mh = n >> 3; + m = 2 * mh; + j1 = m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[0] + a[j2]; + x0i = a[1] + a[j2 + 1]; + x1r = a[0] - a[j2]; + x1i = a[1] - a[j2 + 1]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + a[0] = x0r + x2r; + a[1] = x0i + x2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i - x2i; + a[j2] = x1r - x3i; + a[j2 + 1] = x1i + x3r; + a[j3] = x1r + x3i; + a[j3 + 1] = x1i - x3r; + wn4r = w[1]; + k = 0; + for (j = 2; j < mh; j += 2) { + k += 4; + wk1r = w[k]; + wk1i = w[k + 1]; + wk3r = w[k + 2]; + wk3i = w[k + 3]; + j1 = j + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j] + a[j2]; + x0i = a[j + 1] + a[j2 + 1]; + x1r = a[j] - a[j2]; + x1i = a[j + 1] - a[j2 + 1]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + a[j] = x0r + x2r; + a[j + 1] = x0i + x2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i - x2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j2] = wk1r * x0r - wk1i * x0i; + a[j2 + 1] = wk1r * x0i + wk1i * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j3] = wk3r * x0r + wk3i * x0i; + a[j3 + 1] = wk3r * x0i - wk3i * x0r; + j0 = m - j; + j1 = j0 + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j0] + a[j2]; + x0i = a[j0 + 1] + a[j2 + 1]; + x1r = a[j0] - a[j2]; + x1i = a[j0 + 1] - a[j2 + 1]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + a[j0] = x0r + x2r; + a[j0 + 1] = x0i + x2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i - x2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j2] = wk1i * x0r - wk1r * x0i; + a[j2 + 1] = wk1i * x0i + wk1r * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j3] = wk3i * x0r + wk3r * x0i; + a[j3 + 1] = wk3i * x0i - wk3r * x0r; + } + j0 = mh; + j1 = j0 + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j0] + a[j2]; + x0i = a[j0 + 1] + a[j2 + 1]; + x1r = a[j0] - a[j2]; + x1i = a[j0 + 1] - a[j2 + 1]; + x2r = a[j1] + a[j3]; + x2i = a[j1 + 1] + a[j3 + 1]; + x3r = a[j1] - a[j3]; + x3i = a[j1 + 1] - a[j3 + 1]; + a[j0] = x0r + x2r; + a[j0 + 1] = x0i + x2i; + a[j1] = x0r - x2r; + a[j1 + 1] = x0i - x2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j2] = wn4r * (x0r - x0i); + a[j2 + 1] = wn4r * (x0i + x0r); + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j3] = -wn4r * (x0r + x0i); + a[j3 + 1] = -wn4r * (x0i - x0r); +} + + +void cftmdl2(int n, double *a, double *w) +{ + int j, j0, j1, j2, j3, k, kr, m, mh; + double wn4r, wk1r, wk1i, wk3r, wk3i, wd1r, wd1i, wd3r, wd3i; + double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, y0r, y0i, y2r, y2i; + + mh = n >> 3; + m = 2 * mh; + wn4r = w[1]; + j1 = m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[0] - a[j2 + 1]; + x0i = a[1] + a[j2]; + x1r = a[0] + a[j2 + 1]; + x1i = a[1] - a[j2]; + x2r = a[j1] - a[j3 + 1]; + x2i = a[j1 + 1] + a[j3]; + x3r = a[j1] + a[j3 + 1]; + x3i = a[j1 + 1] - a[j3]; + y0r = wn4r * (x2r - x2i); + y0i = wn4r * (x2i + x2r); + a[0] = x0r + y0r; + a[1] = x0i + y0i; + a[j1] = x0r - y0r; + a[j1 + 1] = x0i - y0i; + y0r = wn4r * (x3r - x3i); + y0i = wn4r * (x3i + x3r); + a[j2] = x1r - y0i; + a[j2 + 1] = x1i + y0r; + a[j3] = x1r + y0i; + a[j3 + 1] = x1i - y0r; + k = 0; + kr = 2 * m; + for (j = 2; j < mh; j += 2) { + k += 4; + wk1r = w[k]; + wk1i = w[k + 1]; + wk3r = w[k + 2]; + wk3i = w[k + 3]; + kr -= 4; + wd1i = w[kr]; + wd1r = w[kr + 1]; + wd3i = w[kr + 2]; + wd3r = w[kr + 3]; + j1 = j + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j] - a[j2 + 1]; + x0i = a[j + 1] + a[j2]; + x1r = a[j] + a[j2 + 1]; + x1i = a[j + 1] - a[j2]; + x2r = a[j1] - a[j3 + 1]; + x2i = a[j1 + 1] + a[j3]; + x3r = a[j1] + a[j3 + 1]; + x3i = a[j1 + 1] - a[j3]; + y0r = wk1r * x0r - wk1i * x0i; + y0i = wk1r * x0i + wk1i * x0r; + y2r = wd1r * x2r - wd1i * x2i; + y2i = wd1r * x2i + wd1i * x2r; + a[j] = y0r + y2r; + a[j + 1] = y0i + y2i; + a[j1] = y0r - y2r; + a[j1 + 1] = y0i - y2i; + y0r = wk3r * x1r + wk3i * x1i; + y0i = wk3r * x1i - wk3i * x1r; + y2r = wd3r * x3r + wd3i * x3i; + y2i = wd3r * x3i - wd3i * x3r; + a[j2] = y0r + y2r; + a[j2 + 1] = y0i + y2i; + a[j3] = y0r - y2r; + a[j3 + 1] = y0i - y2i; + j0 = m - j; + j1 = j0 + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j0] - a[j2 + 1]; + x0i = a[j0 + 1] + a[j2]; + x1r = a[j0] + a[j2 + 1]; + x1i = a[j0 + 1] - a[j2]; + x2r = a[j1] - a[j3 + 1]; + x2i = a[j1 + 1] + a[j3]; + x3r = a[j1] + a[j3 + 1]; + x3i = a[j1 + 1] - a[j3]; + y0r = wd1i * x0r - wd1r * x0i; + y0i = wd1i * x0i + wd1r * x0r; + y2r = wk1i * x2r - wk1r * x2i; + y2i = wk1i * x2i + wk1r * x2r; + a[j0] = y0r + y2r; + a[j0 + 1] = y0i + y2i; + a[j1] = y0r - y2r; + a[j1 + 1] = y0i - y2i; + y0r = wd3i * x1r + wd3r * x1i; + y0i = wd3i * x1i - wd3r * x1r; + y2r = wk3i * x3r + wk3r * x3i; + y2i = wk3i * x3i - wk3r * x3r; + a[j2] = y0r + y2r; + a[j2 + 1] = y0i + y2i; + a[j3] = y0r - y2r; + a[j3 + 1] = y0i - y2i; + } + wk1r = w[m]; + wk1i = w[m + 1]; + j0 = mh; + j1 = j0 + m; + j2 = j1 + m; + j3 = j2 + m; + x0r = a[j0] - a[j2 + 1]; + x0i = a[j0 + 1] + a[j2]; + x1r = a[j0] + a[j2 + 1]; + x1i = a[j0 + 1] - a[j2]; + x2r = a[j1] - a[j3 + 1]; + x2i = a[j1 + 1] + a[j3]; + x3r = a[j1] + a[j3 + 1]; + x3i = a[j1 + 1] - a[j3]; + y0r = wk1r * x0r - wk1i * x0i; + y0i = wk1r * x0i + wk1i * x0r; + y2r = wk1i * x2r - wk1r * x2i; + y2i = wk1i * x2i + wk1r * x2r; + a[j0] = y0r + y2r; + a[j0 + 1] = y0i + y2i; + a[j1] = y0r - y2r; + a[j1 + 1] = y0i - y2i; + y0r = wk1i * x1r - wk1r * x1i; + y0i = wk1i * x1i + wk1r * x1r; + y2r = wk1r * x3r - wk1i * x3i; + y2i = wk1r * x3i + wk1i * x3r; + a[j2] = y0r - y2r; + a[j2 + 1] = y0i - y2i; + a[j3] = y0r + y2r; + a[j3 + 1] = y0i + y2i; +} + + +void cftfx41(int n, double *a, int nw, double *w) +{ + void cftf161(double *a, double *w); + void cftf162(double *a, double *w); + void cftf081(double *a, double *w); + void cftf082(double *a, double *w); + + if (n == 128) { + cftf161(a, &w[nw - 8]); + cftf162(&a[32], &w[nw - 32]); + cftf161(&a[64], &w[nw - 8]); + cftf161(&a[96], &w[nw - 8]); + } else { + cftf081(a, &w[nw - 8]); + cftf082(&a[16], &w[nw - 8]); + cftf081(&a[32], &w[nw - 8]); + cftf081(&a[48], &w[nw - 8]); + } +} + + +void cftf161(double *a, double *w) +{ + double wn4r, wk1r, wk1i, + x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, + y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, + y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i, + y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i, + y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i; + + wn4r = w[1]; + wk1r = w[2]; + wk1i = w[3]; + x0r = a[0] + a[16]; + x0i = a[1] + a[17]; + x1r = a[0] - a[16]; + x1i = a[1] - a[17]; + x2r = a[8] + a[24]; + x2i = a[9] + a[25]; + x3r = a[8] - a[24]; + x3i = a[9] - a[25]; + y0r = x0r + x2r; + y0i = x0i + x2i; + y4r = x0r - x2r; + y4i = x0i - x2i; + y8r = x1r - x3i; + y8i = x1i + x3r; + y12r = x1r + x3i; + y12i = x1i - x3r; + x0r = a[2] + a[18]; + x0i = a[3] + a[19]; + x1r = a[2] - a[18]; + x1i = a[3] - a[19]; + x2r = a[10] + a[26]; + x2i = a[11] + a[27]; + x3r = a[10] - a[26]; + x3i = a[11] - a[27]; + y1r = x0r + x2r; + y1i = x0i + x2i; + y5r = x0r - x2r; + y5i = x0i - x2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + y9r = wk1r * x0r - wk1i * x0i; + y9i = wk1r * x0i + wk1i * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + y13r = wk1i * x0r - wk1r * x0i; + y13i = wk1i * x0i + wk1r * x0r; + x0r = a[4] + a[20]; + x0i = a[5] + a[21]; + x1r = a[4] - a[20]; + x1i = a[5] - a[21]; + x2r = a[12] + a[28]; + x2i = a[13] + a[29]; + x3r = a[12] - a[28]; + x3i = a[13] - a[29]; + y2r = x0r + x2r; + y2i = x0i + x2i; + y6r = x0r - x2r; + y6i = x0i - x2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + y10r = wn4r * (x0r - x0i); + y10i = wn4r * (x0i + x0r); + x0r = x1r + x3i; + x0i = x1i - x3r; + y14r = wn4r * (x0r + x0i); + y14i = wn4r * (x0i - x0r); + x0r = a[6] + a[22]; + x0i = a[7] + a[23]; + x1r = a[6] - a[22]; + x1i = a[7] - a[23]; + x2r = a[14] + a[30]; + x2i = a[15] + a[31]; + x3r = a[14] - a[30]; + x3i = a[15] - a[31]; + y3r = x0r + x2r; + y3i = x0i + x2i; + y7r = x0r - x2r; + y7i = x0i - x2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + y11r = wk1i * x0r - wk1r * x0i; + y11i = wk1i * x0i + wk1r * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + y15r = wk1r * x0r - wk1i * x0i; + y15i = wk1r * x0i + wk1i * x0r; + x0r = y12r - y14r; + x0i = y12i - y14i; + x1r = y12r + y14r; + x1i = y12i + y14i; + x2r = y13r - y15r; + x2i = y13i - y15i; + x3r = y13r + y15r; + x3i = y13i + y15i; + a[24] = x0r + x2r; + a[25] = x0i + x2i; + a[26] = x0r - x2r; + a[27] = x0i - x2i; + a[28] = x1r - x3i; + a[29] = x1i + x3r; + a[30] = x1r + x3i; + a[31] = x1i - x3r; + x0r = y8r + y10r; + x0i = y8i + y10i; + x1r = y8r - y10r; + x1i = y8i - y10i; + x2r = y9r + y11r; + x2i = y9i + y11i; + x3r = y9r - y11r; + x3i = y9i - y11i; + a[16] = x0r + x2r; + a[17] = x0i + x2i; + a[18] = x0r - x2r; + a[19] = x0i - x2i; + a[20] = x1r - x3i; + a[21] = x1i + x3r; + a[22] = x1r + x3i; + a[23] = x1i - x3r; + x0r = y5r - y7i; + x0i = y5i + y7r; + x2r = wn4r * (x0r - x0i); + x2i = wn4r * (x0i + x0r); + x0r = y5r + y7i; + x0i = y5i - y7r; + x3r = wn4r * (x0r - x0i); + x3i = wn4r * (x0i + x0r); + x0r = y4r - y6i; + x0i = y4i + y6r; + x1r = y4r + y6i; + x1i = y4i - y6r; + a[8] = x0r + x2r; + a[9] = x0i + x2i; + a[10] = x0r - x2r; + a[11] = x0i - x2i; + a[12] = x1r - x3i; + a[13] = x1i + x3r; + a[14] = x1r + x3i; + a[15] = x1i - x3r; + x0r = y0r + y2r; + x0i = y0i + y2i; + x1r = y0r - y2r; + x1i = y0i - y2i; + x2r = y1r + y3r; + x2i = y1i + y3i; + x3r = y1r - y3r; + x3i = y1i - y3i; + a[0] = x0r + x2r; + a[1] = x0i + x2i; + a[2] = x0r - x2r; + a[3] = x0i - x2i; + a[4] = x1r - x3i; + a[5] = x1i + x3r; + a[6] = x1r + x3i; + a[7] = x1i - x3r; +} + + +void cftf162(double *a, double *w) +{ + double wn4r, wk1r, wk1i, wk2r, wk2i, wk3r, wk3i, + x0r, x0i, x1r, x1i, x2r, x2i, + y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, + y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i, + y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i, + y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i; + + wn4r = w[1]; + wk1r = w[4]; + wk1i = w[5]; + wk3r = w[6]; + wk3i = -w[7]; + wk2r = w[8]; + wk2i = w[9]; + x1r = a[0] - a[17]; + x1i = a[1] + a[16]; + x0r = a[8] - a[25]; + x0i = a[9] + a[24]; + x2r = wn4r * (x0r - x0i); + x2i = wn4r * (x0i + x0r); + y0r = x1r + x2r; + y0i = x1i + x2i; + y4r = x1r - x2r; + y4i = x1i - x2i; + x1r = a[0] + a[17]; + x1i = a[1] - a[16]; + x0r = a[8] + a[25]; + x0i = a[9] - a[24]; + x2r = wn4r * (x0r - x0i); + x2i = wn4r * (x0i + x0r); + y8r = x1r - x2i; + y8i = x1i + x2r; + y12r = x1r + x2i; + y12i = x1i - x2r; + x0r = a[2] - a[19]; + x0i = a[3] + a[18]; + x1r = wk1r * x0r - wk1i * x0i; + x1i = wk1r * x0i + wk1i * x0r; + x0r = a[10] - a[27]; + x0i = a[11] + a[26]; + x2r = wk3i * x0r - wk3r * x0i; + x2i = wk3i * x0i + wk3r * x0r; + y1r = x1r + x2r; + y1i = x1i + x2i; + y5r = x1r - x2r; + y5i = x1i - x2i; + x0r = a[2] + a[19]; + x0i = a[3] - a[18]; + x1r = wk3r * x0r - wk3i * x0i; + x1i = wk3r * x0i + wk3i * x0r; + x0r = a[10] + a[27]; + x0i = a[11] - a[26]; + x2r = wk1r * x0r + wk1i * x0i; + x2i = wk1r * x0i - wk1i * x0r; + y9r = x1r - x2r; + y9i = x1i - x2i; + y13r = x1r + x2r; + y13i = x1i + x2i; + x0r = a[4] - a[21]; + x0i = a[5] + a[20]; + x1r = wk2r * x0r - wk2i * x0i; + x1i = wk2r * x0i + wk2i * x0r; + x0r = a[12] - a[29]; + x0i = a[13] + a[28]; + x2r = wk2i * x0r - wk2r * x0i; + x2i = wk2i * x0i + wk2r * x0r; + y2r = x1r + x2r; + y2i = x1i + x2i; + y6r = x1r - x2r; + y6i = x1i - x2i; + x0r = a[4] + a[21]; + x0i = a[5] - a[20]; + x1r = wk2i * x0r - wk2r * x0i; + x1i = wk2i * x0i + wk2r * x0r; + x0r = a[12] + a[29]; + x0i = a[13] - a[28]; + x2r = wk2r * x0r - wk2i * x0i; + x2i = wk2r * x0i + wk2i * x0r; + y10r = x1r - x2r; + y10i = x1i - x2i; + y14r = x1r + x2r; + y14i = x1i + x2i; + x0r = a[6] - a[23]; + x0i = a[7] + a[22]; + x1r = wk3r * x0r - wk3i * x0i; + x1i = wk3r * x0i + wk3i * x0r; + x0r = a[14] - a[31]; + x0i = a[15] + a[30]; + x2r = wk1i * x0r - wk1r * x0i; + x2i = wk1i * x0i + wk1r * x0r; + y3r = x1r + x2r; + y3i = x1i + x2i; + y7r = x1r - x2r; + y7i = x1i - x2i; + x0r = a[6] + a[23]; + x0i = a[7] - a[22]; + x1r = wk1i * x0r + wk1r * x0i; + x1i = wk1i * x0i - wk1r * x0r; + x0r = a[14] + a[31]; + x0i = a[15] - a[30]; + x2r = wk3i * x0r - wk3r * x0i; + x2i = wk3i * x0i + wk3r * x0r; + y11r = x1r + x2r; + y11i = x1i + x2i; + y15r = x1r - x2r; + y15i = x1i - x2i; + x1r = y0r + y2r; + x1i = y0i + y2i; + x2r = y1r + y3r; + x2i = y1i + y3i; + a[0] = x1r + x2r; + a[1] = x1i + x2i; + a[2] = x1r - x2r; + a[3] = x1i - x2i; + x1r = y0r - y2r; + x1i = y0i - y2i; + x2r = y1r - y3r; + x2i = y1i - y3i; + a[4] = x1r - x2i; + a[5] = x1i + x2r; + a[6] = x1r + x2i; + a[7] = x1i - x2r; + x1r = y4r - y6i; + x1i = y4i + y6r; + x0r = y5r - y7i; + x0i = y5i + y7r; + x2r = wn4r * (x0r - x0i); + x2i = wn4r * (x0i + x0r); + a[8] = x1r + x2r; + a[9] = x1i + x2i; + a[10] = x1r - x2r; + a[11] = x1i - x2i; + x1r = y4r + y6i; + x1i = y4i - y6r; + x0r = y5r + y7i; + x0i = y5i - y7r; + x2r = wn4r * (x0r - x0i); + x2i = wn4r * (x0i + x0r); + a[12] = x1r - x2i; + a[13] = x1i + x2r; + a[14] = x1r + x2i; + a[15] = x1i - x2r; + x1r = y8r + y10r; + x1i = y8i + y10i; + x2r = y9r - y11r; + x2i = y9i - y11i; + a[16] = x1r + x2r; + a[17] = x1i + x2i; + a[18] = x1r - x2r; + a[19] = x1i - x2i; + x1r = y8r - y10r; + x1i = y8i - y10i; + x2r = y9r + y11r; + x2i = y9i + y11i; + a[20] = x1r - x2i; + a[21] = x1i + x2r; + a[22] = x1r + x2i; + a[23] = x1i - x2r; + x1r = y12r - y14i; + x1i = y12i + y14r; + x0r = y13r + y15i; + x0i = y13i - y15r; + x2r = wn4r * (x0r - x0i); + x2i = wn4r * (x0i + x0r); + a[24] = x1r + x2r; + a[25] = x1i + x2i; + a[26] = x1r - x2r; + a[27] = x1i - x2i; + x1r = y12r + y14i; + x1i = y12i - y14r; + x0r = y13r - y15i; + x0i = y13i + y15r; + x2r = wn4r * (x0r - x0i); + x2i = wn4r * (x0i + x0r); + a[28] = x1r - x2i; + a[29] = x1i + x2r; + a[30] = x1r + x2i; + a[31] = x1i - x2r; +} + + +void cftf081(double *a, double *w) +{ + double wn4r, x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, + y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, + y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i; + + wn4r = w[1]; + x0r = a[0] + a[8]; + x0i = a[1] + a[9]; + x1r = a[0] - a[8]; + x1i = a[1] - a[9]; + x2r = a[4] + a[12]; + x2i = a[5] + a[13]; + x3r = a[4] - a[12]; + x3i = a[5] - a[13]; + y0r = x0r + x2r; + y0i = x0i + x2i; + y2r = x0r - x2r; + y2i = x0i - x2i; + y1r = x1r - x3i; + y1i = x1i + x3r; + y3r = x1r + x3i; + y3i = x1i - x3r; + x0r = a[2] + a[10]; + x0i = a[3] + a[11]; + x1r = a[2] - a[10]; + x1i = a[3] - a[11]; + x2r = a[6] + a[14]; + x2i = a[7] + a[15]; + x3r = a[6] - a[14]; + x3i = a[7] - a[15]; + y4r = x0r + x2r; + y4i = x0i + x2i; + y6r = x0r - x2r; + y6i = x0i - x2i; + x0r = x1r - x3i; + x0i = x1i + x3r; + x2r = x1r + x3i; + x2i = x1i - x3r; + y5r = wn4r * (x0r - x0i); + y5i = wn4r * (x0r + x0i); + y7r = wn4r * (x2r - x2i); + y7i = wn4r * (x2r + x2i); + a[8] = y1r + y5r; + a[9] = y1i + y5i; + a[10] = y1r - y5r; + a[11] = y1i - y5i; + a[12] = y3r - y7i; + a[13] = y3i + y7r; + a[14] = y3r + y7i; + a[15] = y3i - y7r; + a[0] = y0r + y4r; + a[1] = y0i + y4i; + a[2] = y0r - y4r; + a[3] = y0i - y4i; + a[4] = y2r - y6i; + a[5] = y2i + y6r; + a[6] = y2r + y6i; + a[7] = y2i - y6r; +} + + +void cftf082(double *a, double *w) +{ + double wn4r, wk1r, wk1i, x0r, x0i, x1r, x1i, + y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, + y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i; + + wn4r = w[1]; + wk1r = w[2]; + wk1i = w[3]; + y0r = a[0] - a[9]; + y0i = a[1] + a[8]; + y1r = a[0] + a[9]; + y1i = a[1] - a[8]; + x0r = a[4] - a[13]; + x0i = a[5] + a[12]; + y2r = wn4r * (x0r - x0i); + y2i = wn4r * (x0i + x0r); + x0r = a[4] + a[13]; + x0i = a[5] - a[12]; + y3r = wn4r * (x0r - x0i); + y3i = wn4r * (x0i + x0r); + x0r = a[2] - a[11]; + x0i = a[3] + a[10]; + y4r = wk1r * x0r - wk1i * x0i; + y4i = wk1r * x0i + wk1i * x0r; + x0r = a[2] + a[11]; + x0i = a[3] - a[10]; + y5r = wk1i * x0r - wk1r * x0i; + y5i = wk1i * x0i + wk1r * x0r; + x0r = a[6] - a[15]; + x0i = a[7] + a[14]; + y6r = wk1i * x0r - wk1r * x0i; + y6i = wk1i * x0i + wk1r * x0r; + x0r = a[6] + a[15]; + x0i = a[7] - a[14]; + y7r = wk1r * x0r - wk1i * x0i; + y7i = wk1r * x0i + wk1i * x0r; + x0r = y0r + y2r; + x0i = y0i + y2i; + x1r = y4r + y6r; + x1i = y4i + y6i; + a[0] = x0r + x1r; + a[1] = x0i + x1i; + a[2] = x0r - x1r; + a[3] = x0i - x1i; + x0r = y0r - y2r; + x0i = y0i - y2i; + x1r = y4r - y6r; + x1i = y4i - y6i; + a[4] = x0r - x1i; + a[5] = x0i + x1r; + a[6] = x0r + x1i; + a[7] = x0i - x1r; + x0r = y1r - y3i; + x0i = y1i + y3r; + x1r = y5r - y7r; + x1i = y5i - y7i; + a[8] = x0r + x1r; + a[9] = x0i + x1i; + a[10] = x0r - x1r; + a[11] = x0i - x1i; + x0r = y1r + y3i; + x0i = y1i - y3r; + x1r = y5r + y7r; + x1i = y5i + y7i; + a[12] = x0r - x1i; + a[13] = x0i + x1r; + a[14] = x0r + x1i; + a[15] = x0i - x1r; +} + + +void cftf040(double *a) +{ + double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; + + x0r = a[0] + a[4]; + x0i = a[1] + a[5]; + x1r = a[0] - a[4]; + x1i = a[1] - a[5]; + x2r = a[2] + a[6]; + x2i = a[3] + a[7]; + x3r = a[2] - a[6]; + x3i = a[3] - a[7]; + a[0] = x0r + x2r; + a[1] = x0i + x2i; + a[2] = x1r - x3i; + a[3] = x1i + x3r; + a[4] = x0r - x2r; + a[5] = x0i - x2i; + a[6] = x1r + x3i; + a[7] = x1i - x3r; +} + + +void cftb040(double *a) +{ + double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; + + x0r = a[0] + a[4]; + x0i = a[1] + a[5]; + x1r = a[0] - a[4]; + x1i = a[1] - a[5]; + x2r = a[2] + a[6]; + x2i = a[3] + a[7]; + x3r = a[2] - a[6]; + x3i = a[3] - a[7]; + a[0] = x0r + x2r; + a[1] = x0i + x2i; + a[2] = x1r + x3i; + a[3] = x1i - x3r; + a[4] = x0r - x2r; + a[5] = x0i - x2i; + a[6] = x1r - x3i; + a[7] = x1i + x3r; +} + + +void cftx020(double *a) +{ + double x0r, x0i; + + x0r = a[0] - a[2]; + x0i = a[1] - a[3]; + a[0] += a[2]; + a[1] += a[3]; + a[2] = x0r; + a[3] = x0i; +} + + +void rftfsub(int n, double *a, int nc, double *c) +{ + int j, k, kk, ks, m; + double wkr, wki, xr, xi, yr, yi; + + m = n >> 1; + ks = 2 * nc / m; + kk = 0; + for (j = 2; j < m; j += 2) { + k = n - j; + kk += ks; + wkr = 0.5 - c[nc - kk]; + wki = c[kk]; + xr = a[j] - a[k]; + xi = a[j + 1] + a[k + 1]; + yr = wkr * xr - wki * xi; + yi = wkr * xi + wki * xr; + a[j] -= yr; + a[j + 1] -= yi; + a[k] += yr; + a[k + 1] -= yi; + } +} + + +void rftbsub(int n, double *a, int nc, double *c) +{ + int j, k, kk, ks, m; + double wkr, wki, xr, xi, yr, yi; + + m = n >> 1; + ks = 2 * nc / m; + kk = 0; + for (j = 2; j < m; j += 2) { + k = n - j; + kk += ks; + wkr = 0.5 - c[nc - kk]; + wki = c[kk]; + xr = a[j] - a[k]; + xi = a[j + 1] + a[k + 1]; + yr = wkr * xr + wki * xi; + yi = wkr * xi - wki * xr; + a[j] -= yr; + a[j + 1] -= yi; + a[k] += yr; + a[k + 1] -= yi; + } +} + + +void dctsub(int n, double *a, int nc, double *c) +{ + int j, k, kk, ks, m; + double wkr, wki, xr; + + m = n >> 1; + ks = nc / n; + kk = 0; + for (j = 1; j < m; j++) { + k = n - j; + kk += ks; + wkr = c[kk] - c[nc - kk]; + wki = c[kk] + c[nc - kk]; + xr = wki * a[j] - wkr * a[k]; + a[j] = wkr * a[j] + wki * a[k]; + a[k] = xr; + } + a[m] *= c[0]; +} + + +void dstsub(int n, double *a, int nc, double *c) +{ + int j, k, kk, ks, m; + double wkr, wki, xr; + + m = n >> 1; + ks = nc / n; + kk = 0; + for (j = 1; j < m; j++) { + k = n - j; + kk += ks; + wkr = c[kk] - c[nc - kk]; + wki = c[kk] + c[nc - kk]; + xr = wki * a[k] - wkr * a[j]; + a[k] = wkr * a[k] + wki * a[j]; + a[j] = xr; + } + a[m] *= c[0]; +} + diff --git a/src/projectM-engine-backup/fftsg.h b/src/projectM-engine-backup/fftsg.h new file mode 100755 index 000000000..ff9da6e41 --- /dev/null +++ b/src/projectM-engine-backup/fftsg.h @@ -0,0 +1,35 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: fftsg.h,v 1.1.1.1 2005/12/23 18:05:00 psperl Exp $ + * + * Wrapper for rdft() and friends + * + * $Log$ + */ + +#ifndef _FFTSG_H +#define _FFTSG_H + +extern void rdft(int n, int isgn, double *a, int *ip, double *w); + +#endif /** !_FFTSG_H */ + diff --git a/src/projectM-engine-backup/fonts b/src/projectM-engine-backup/fonts new file mode 120000 index 000000000..8b289e24f --- /dev/null +++ b/src/projectM-engine-backup/fonts @@ -0,0 +1 @@ +../../fonts \ No newline at end of file diff --git a/src/projectM-engine-backup/glConsole.cpp b/src/projectM-engine-backup/glConsole.cpp new file mode 100755 index 000000000..580d6b354 --- /dev/null +++ b/src/projectM-engine-backup/glConsole.cpp @@ -0,0 +1,1028 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: glConsole.c,v 1.2 2005/12/28 18:51:18 psperl Exp $ + * + * Encapsulation of an OpenGL-based console + * + */ + +#include +#include +#include +#include +#ifdef MACOS +#include +#endif /** MACOS */ +#include + +#include "projectM.hpp" + +#ifdef MACOS +#include +#else +#include +#endif /** MACOS */ +#include "glConsole.h" +#include "Common.hpp" +#include "fatal.h" + +#include "wipemalloc.h" + +#ifdef USE_FTGL +#include +#include +#endif /** USE_FTGL */ + +#define HEIGHT_SPACE 8 /* pixel space between lines */ +#define DEFAULT_CONSOLE_FOREGROUND_COLOR CONSOLE_WHITE +#define DEFAULT_CONSOLE_BACKGROUND_COLOR CONSOLE_BLACK +#define DEFAULT_CURSOR_COLOR CONSOLE_GREEN +#define CURSOR_REFRESH_RATE 10 + +static int gl_console_set_color(color_t color); +int clear_console_screen_buffer(gl_console_t * gl_console); +int clear_console_scroll_buffer(gl_console_t * gl_console); +//float screen_width = 800; +//float screen_height = 600; + +extern projectM *PM; +int refresh_count = 0; + +/* Creates a new console of (width X height) with left corner at + (x, y) */ +gl_console_t * glConsoleCreate(int screen_width, int screen_height, int scroll_width, int scroll_height, + float start_x, float start_y, int Font_Descriptor) { + + console_char_t * buffer; + gl_console_t * gl_console; + + if ((screen_width > MAX_CONSOLE_WIDTH) || (screen_width < 1)) + return NULL; + + if ((screen_height > MAX_CONSOLE_HEIGHT) || (screen_height < 1)) + return NULL; + + if ((gl_console = (gl_console_t*)wipemalloc(sizeof(gl_console_t))) == NULL) + return NULL; + + if ((scroll_height < screen_height)) + return NULL; + + if ((scroll_width < screen_width)) + return NULL; + + if ((buffer = (console_char_t*)wipemalloc(scroll_width*scroll_height*sizeof(console_char_t))) == NULL) + return NULL; + /* Need to know height and width of screen so we can see if the + if x and y are valid, will do later */ + + /* Set struct parameters */ + gl_console->screen_buffer = buffer; + gl_console->font_descriptor = Font_Descriptor; + gl_console->screen_width = screen_width; + gl_console->screen_height = screen_height; + gl_console->scroll_width = scroll_width; + gl_console->scroll_height = scroll_height; + gl_console->start_x = start_x; /* x coordinate of console's upper left corner */ + gl_console->start_y = start_y; /* y coordinate of console's upper left corner */ + gl_console->screen_start_x = gl_console->screen_start_y = 0; + gl_console->screen_x = gl_console->screen_y = 0; /* set cursor positions to zero */ + gl_console->cursor_ptr = buffer; /* start cursor pointer at beginning of buffer */ + gl_console->current_fg = DEFAULT_CONSOLE_FOREGROUND_COLOR; + gl_console->current_bg = DEFAULT_CONSOLE_BACKGROUND_COLOR; + gl_console->scroll_buffer = buffer; + gl_console->cursor_color = DEFAULT_CURSOR_COLOR; + gl_console->cursor_style = BAR_STYLE; + gl_console->flags = 0; + /* Clears the console buffer */ + clear_console_scroll_buffer(gl_console); + + if (GL_CONSOLE_DEBUG) printf("glConsoleCreate: finished initializing\n"); + + /* Finished, return new console */ + return gl_console; +} + +/* Destroy the passed console */ +int glConsoleDestroy(gl_console_t * console) { + + if (console == NULL) + return PROJECTM_FAILURE; + + free(console->scroll_buffer); + free(console); + + console = NULL; + + return PROJECTM_SUCCESS; + +} + + +int glConsoleClearScreen(gl_console_t * console) { + + if (console == NULL) + return PROJECTM_FAILURE; + + clear_console_screen_buffer(console); + + return PROJECTM_SUCCESS; +} + + +int glConsoleClearBuffer(gl_console_t * console) { + + if (console == NULL) + return PROJECTM_FAILURE; + + clear_console_scroll_buffer(console); + glConsoleAlignCursorLeft(console); + glConsoleAlignCursorUp(console); + + return PROJECTM_SUCCESS; +} + +/* Aligns cursor to the next character 'c' */ +int glConsoleCursorToNextChar(char c, gl_console_t * gl_console) { + + console_char_t * endofbuf; + if (gl_console == NULL) + return PROJECTM_FAILURE; + + endofbuf = gl_console->scroll_buffer + (gl_console->scroll_width*gl_console->scroll_height) - 1; + + while ((gl_console->cursor_ptr != endofbuf) && (gl_console->cursor_ptr->symbol != c)) + glConsoleMoveCursorForward(gl_console); + + return PROJECTM_SUCCESS; + +} + +int glConsoleMoveCursorUp(gl_console_t * gl_console) { + + /* Null argument check */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + /* The screen buffer is at the top and so is the screen cursor */ + if ((gl_console->screen_start_y == 0) && (gl_console->screen_y == 0)) { + + /* Wrap up flag specified, move cursor to bottom of screen */ + if (gl_console->flags & CONSOLE_FLAG_SCROLL_WRAP_UP) { + glConsoleAlignCursorDown(gl_console); + } + + + /* Do nothing instead */ + + } + /* The screen cursor is at the top but not the screen buffer */ + else if (gl_console->screen_y == 0){ + + /* screen_y stays the same, since it scrolls up one */ + + /* Decrement the cursor_ptr by one line */ + gl_console->cursor_ptr -= gl_console->scroll_width; + + /* Decrement starting 'y' position of the screen buffer */ + gl_console->screen_start_y--; + + /* Decrement the screen buffer by one line */ + gl_console->screen_buffer -= gl_console->scroll_width; + + + } + /* General case, not at top or bottoom */ + else { + gl_console->screen_y--; + gl_console->cursor_ptr -= gl_console->scroll_width; + } + + return PROJECTM_SUCCESS; +} + + +int glConsoleMoveCursorDown(gl_console_t * gl_console) { + + /* Null argument check */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + /* The screen buffer is at the bottom and so is the screen cursor, this may not ever + happen */ + if (gl_console->screen_start_y == (gl_console->scroll_height - gl_console->screen_height)) { + if (gl_console->screen_y == (gl_console->screen_height - 1)) { + // printf("BOTTOM AND END\n"); + /* Wrap down to up enabled */ + if (gl_console->flags & CONSOLE_FLAG_SCROLL_WRAP_DOWN) { + glConsoleAlignCursorUp(gl_console); + } + + /* Otherwise, do nothing */ + } + } + + /* The screen cursor is at the bottom but not the end of the scroll buffer */ + else if (gl_console->screen_y == (gl_console->screen_height - 1)) { + + // printf("BOTTOM BUT NOT END\n"); + /* screen_y stays the same, since it scrolls down one */ + + /* Increment the cursor_ptr by one line */ + gl_console->cursor_ptr += gl_console->scroll_width; + + /* Increment starting 'y' position of the screen buffer */ + gl_console->screen_start_y++; + + /* Increment the screen buffer by one line */ + gl_console->screen_buffer += gl_console->scroll_width; + + + } + + /* General case, not at top or bottoom */ + else { + // printf("GENERAL CASE\n"); + gl_console->screen_y++; + gl_console->cursor_ptr += gl_console->scroll_width; + } + + return PROJECTM_SUCCESS; +} + +/* Move the console forward one character, wrap around is the current behavior */ +int glConsoleMoveCursorForward(gl_console_t * gl_console) { + + /* Null argument check */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + + /* The case where the end of the screen is reached and the end of the scroll buffer */ + if ((gl_console->screen_start_x + gl_console->screen_width) == (gl_console->scroll_width)) { + if ((gl_console->screen_x) == (gl_console->screen_width - 1)) { + + /* Wrap around to next line if this flag is enabled */ + if (gl_console->flags & CONSOLE_FLAG_SCROLL_WRAP_RIGHT) { + /* Down one and to the left */ + glConsoleMoveCursorDown(gl_console); + glConsoleAlignCursorLeft(gl_console); + } + + /* Otherwise do nothing */ + } + } + + /* The case where the end of the screen is reach, but the not end of the scroll buffer */ + else if (gl_console->screen_x == (gl_console->screen_width - 1)) { + + /* screen_x doesn't change because the whole console is shifted left */ + /* screen_y doesn't change because we haven't reached the end of the scroll buffer */ + + gl_console->cursor_ptr++; /* increment cursor pointer */ + gl_console->screen_buffer++; /* move the screen buffer right one */ + gl_console->screen_start_x++; /* incrementing the start of the screen 'x' variable */ + } + + /* The most common case, no scrolling required. In other words, the cursor is at some + arbitrary non end point position */ + else { + gl_console->screen_x++; /* increment x variable */ + gl_console->cursor_ptr++; /* increment cursor pointer */ + } + + return PROJECTM_SUCCESS; +} + + +/* Moves the cursor backward one space */ +int glConsoleMoveCursorBackward(gl_console_t * gl_console) { + + /* Null argument check */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + /* The case where the beginning of the screen is reached and the beginning of the scroll buffer */ + if ((gl_console->screen_start_x == 0) && (gl_console->screen_x == 0)) { + if (gl_console->flags & CONSOLE_FLAG_SCROLL_WRAP_LEFT) { + glConsoleMoveCursorUp(gl_console); + glConsoleAlignCursorRight(gl_console); + } + + } + + /* The case where the beginning of the screen is reach, but the not beginning of the scroll buffer */ + else if (gl_console->screen_x == 0) { + gl_console->cursor_ptr--; /* decrement cursor pointer */ + gl_console->screen_buffer--; /* move the screen buffer left one */ + gl_console->screen_start_x--; /* decrement the start of the screen 'x' variable */ + } + + /* The most common case, no scrolling required. In other words, the cursor is at some + arbitrary non end point position */ + else { + gl_console->screen_x--; /* increment x variable */ + gl_console->cursor_ptr--; /* increment cursor pointer */ + } + + /* Finised, return success */ + return PROJECTM_SUCCESS; +} + +/* Sets the cursor position to (x,y) of the passed console */ +int glConsoleSetCursorPos(int x, int y, gl_console_t * gl_console) { + + /* Null argument check */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + /* Bound checks */ + if ((x < 0) || (x > (gl_console->scroll_width-1))) + return PROJECTM_FAILURE; + + if ((y < 0) || (y > (gl_console->scroll_height-1))) + return PROJECTM_FAILURE; + + + /* Set cursor ptr to new screen location. This variable does not depend on if the + screen needs to be scrolled */ + gl_console->cursor_ptr = gl_console->scroll_buffer + (y * gl_console->scroll_width) + x; + + /* Goal 1: Determine what needs to be changed on the X axis */ + + + /* Case (i): x coordinate is less than the starting screen buffer x coordinate. Must + shift the screen buffer left by difference of the two coordinates */ + if (x < gl_console->screen_start_x) { + // printf("X: case (i)\n"); + + /* Align x offset to new x corodinate */ + gl_console->screen_start_x = x; + + /* Set screen_x to zero because we are left edge aligned in the screen buffer */ + gl_console->screen_x = 0; + + } + + /* Case (ii): x coordinate is greater than farthest screen buffer x coordinate. Must + shift the screen buffer right by difference of the two coordinates */ + else if (x > (gl_console->screen_start_x+gl_console->screen_width-1)) { + // printf("X: case (ii)\n"); + + /* Align end of screen buffer X coordinate space to new x coordinate */ + gl_console->screen_start_x = x - (gl_console->screen_width - 1); + + /* Set screen_x to right edge of screen buffer because we are right aligned to the new x coordinate */ + gl_console->screen_x = gl_console->screen_width - 1; + } + + /* CASE (iii): x coordinate must lie within the current screen buffer rectangle. No need to + shift the screen buffer on the X axis */ + else { + // printf("X: case (iii)\n"); + + /* Set the new screen coordinate to the passed in x coordinate minus the starting screen buffer distance */ + gl_console->screen_x = x - gl_console->screen_start_x; + + } + + + /* Goal 2: Determine what needs to be changed on the Y axis */ + + /* Case (i): y coordinate is less than the starting screen buffer y coordinate. Must + shift the screen buffer up by difference of the two coordinates */ + if (y < gl_console->screen_start_y) { + // printf("Y: case (i) y = %d, start_y = %d\n", y, gl_console->screen_start_y); + + /* Align y offset to new y corodinate */ + gl_console->screen_start_y = y; + + /* Set screen_y to zero because we are top aligned in the screen buffer */ + gl_console->screen_y = 0; + + } + + /* Case (ii): y coordinate is greater than loweest screen buffer y coordinate. Must + shift the screen buffer down by difference of the two coordinates */ + else if (y > (gl_console->screen_start_y+gl_console->screen_height-1)) { + // printf("Y: case (ii)\n"); + + /* Align end of screen buffer Y coordinate space to new y coordinate */ + gl_console->screen_start_y = y - (gl_console->screen_height-1); + + /* Set screen_y to bottom edge of screen buffer because we are bottom aligned to the new y coordinate */ + gl_console->screen_y = gl_console->screen_height - 1; + } + + /* CASE (iii): y coordinate must lie within the current screen buffer rectangle. No need to + shift the screen buffer on the Y axis */ + + else { + // printf("Y: case (iii)\n"); + /* Set the new screen coordinate to the passed in y coordinate minus the starting screen buffer distance */ + gl_console->screen_y = y - gl_console->screen_start_y; + + } + + + /* Re-adjust screen buffer ptr based on computed screen starting coordinates */ + gl_console->screen_buffer = gl_console->scroll_buffer + (gl_console->screen_start_y*gl_console->screen_width) + + gl_console->screen_start_x; + + + return PROJECTM_SUCCESS; +} + +/* Sets 'x' and 'y' to the console coordinates of the current cursor position */ +int glConsoleGetCursorPos(int * x, int * y, gl_console_t * gl_console) { + + /* Null argument check */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + /* Null arguments passed, bail */ + if ((x == NULL) || (y == NULL)) + return PROJECTM_FAILURE; + + /* Set coordinates with appropiate offset */ + *x = gl_console->screen_x + gl_console->screen_start_x; + *y = gl_console->screen_y + gl_console->screen_start_y; + + return PROJECTM_SUCCESS; +} + +/* Helper function that changes the current color */ +static int gl_console_set_color(color_t color) { + + switch (color) { + + case CONSOLE_BLACK: + glColor4f(0, 0, 0, 1); + break; + case CONSOLE_RED: + glColor4f(1, 0, 0, 1); + break; + case CONSOLE_GREEN: + glColor4f(0, 1, 0, 1); + break; + case CONSOLE_WHITE: + glColor4f(1, 1, 1, 1); + break; + case CONSOLE_BLUE: + glColor4f(0, 0, 1, 1); + break; + case CONSOLE_TRANS: + glColor4f(0, 0, 0, 0); + break; + default: /* hmm, use white I guess */ + glColor4f(1, 1, 1, 1); + } + + return PROJECTM_SUCCESS; +} + +/* Sets the passed console to a new foreground */ +int glConsoleSetFGColor(color_t color, gl_console_t * gl_console) { + + if (gl_console == NULL) + return PROJECTM_FAILURE; + + gl_console->current_fg = color; + + return PROJECTM_SUCCESS; +} + +/* Sets the passed console to a new background */ +int glConsoleSetBGColor(color_t color, gl_console_t * gl_console) { + + if (gl_console == NULL) + return PROJECTM_FAILURE; + + gl_console->current_bg = color; + + return PROJECTM_SUCCESS; +} + +/* Sets the cursor color */ +int glConsoleSetCursorColor(color_t color, gl_console_t * gl_console) { + + if (gl_console == NULL) + return PROJECTM_FAILURE; + + gl_console->cursor_color = color; + + return PROJECTM_SUCCESS; +} + +/* Prints a string starting from the current cursor position */ +int glConsolePrintString(char * s, gl_console_t * gl_console) { + + int len; + int i; + console_char_t console_char; + char symbol; + + /* Null argument checks */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + if (s == NULL) + return PROJECTM_FAILURE; + + /* Set the console struct to correct fg and bg values. + The character value will change in the for loop */ + console_char.fg_color = gl_console->current_fg; + console_char.bg_color = gl_console->current_bg; + console_char.symbol = 0; + + /* Calculate length of the string */ + len = strlen(s); + + + for (i = 0; i < len; i++) { + + /* Case on the type of character */ + + switch (symbol = *(s+i)) { + + case '\r': + case '\n': + console_char.symbol = symbol; + *gl_console->cursor_ptr = console_char; + glConsoleMoveCursorDown(gl_console); + glConsoleAlignCursorLeft(gl_console); + break; + case '\b': + glConsoleMoveCursorBackward(gl_console); + break; + default: + /* Change the screen_buffer value */ + console_char.symbol = symbol; + *gl_console->cursor_ptr = console_char; + glConsoleMoveCursorForward(gl_console); + + } + } + + return PROJECTM_SUCCESS; +} + + +/* Clears the console screen_buffer, using current fg and bg values */ +int clear_console_screen_buffer(gl_console_t * gl_console) { + + int i, console_size; + console_char_t console_char; + + /* Set console struct to current fg and bg values */ + console_char.fg_color = gl_console->current_fg; + console_char.bg_color = gl_console->current_bg; + console_char.symbol = 0; /* empty symbol */ + + if (gl_console == NULL) + return PROJECTM_FAILURE; + + console_size = gl_console->scroll_width * gl_console->scroll_height; + + for (i = 0; i < console_size; i++) + *(gl_console->screen_buffer + i) = console_char; + + return PROJECTM_SUCCESS; +} + +/* Clears the entire buffer */ +int clear_console_scroll_buffer(gl_console_t * gl_console) { + + int i, console_size; + console_char_t console_char; + + /* Set console struct to current fg and bg values */ + console_char.fg_color = gl_console->current_fg; + console_char.bg_color = gl_console->current_bg; + console_char.symbol = 0; /* empty symbol */ + + if (gl_console == NULL) + return PROJECTM_FAILURE; + + console_size = gl_console->scroll_width * gl_console->scroll_height; + + for (i = 0; i < console_size; i++) + *(gl_console->scroll_buffer + i) = console_char; + + return PROJECTM_SUCCESS; +} + +/* Align the cursor all the way to the right of the passed console */ +int glConsoleAlignCursorRight(gl_console_t * gl_console) { + + /* Null argument check */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + /* Set the cursor pointer to the rightmost end of the scroll buffer */ + gl_console->cursor_ptr += gl_console->scroll_width - (gl_console->screen_start_x + gl_console->screen_x) - 1; + + /* Move the screen buffer to the farthest right as possible */ + gl_console->screen_buffer += gl_console->scroll_width - gl_console->screen_start_x - gl_console->screen_width; + + /* Set the screen start 'x' value to length of the scroll buffer minus the length + of the screen buffer with a -1 offset to access the array correctly */ + gl_console->screen_start_x = gl_console->scroll_width - gl_console->screen_width; + + /* Set the screen_x cursor value to the screen width length minus an array adjustment offset */ + gl_console->screen_x = gl_console->screen_width - 1; + + + return PROJECTM_SUCCESS; +} + +/* Align the cursor all the way to the right of the passed console */ +int glConsoleAlignCursorLeft(gl_console_t * gl_console) { + + /* Null argument check */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + /* Set the cursor pointer to the left most end of the scroll buffer */ + gl_console->cursor_ptr -= (gl_console->screen_start_x + gl_console->screen_x); + + /* Set the screen buffer all the way to left */ + gl_console->screen_buffer -= gl_console->screen_start_x; + + /* Set the screen start x to the leftmost end of the scroll buffer */ + gl_console->screen_start_x = 0; + + /* Set the screen_x cursor value to the leftmost end of the screne buffer */ + gl_console->screen_x = 0; + + + /* Finished, return success */ + return PROJECTM_SUCCESS; +} + +/* Align the cursor to the top of the screen of the passed console */ +int glConsoleAlignCursorUp(gl_console_t * gl_console) { + + /* Null argument check */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + /* Set the cursor pointer to the top of the buffer plus the x offset */ + gl_console->cursor_ptr = gl_console->scroll_buffer + gl_console->screen_start_x + gl_console->screen_x; + + /* Set the screen start y to the top of the scroll buffer */ + gl_console->screen_start_y = 0; + + /* Set the screen_y cursor value to the top of the screen buffer */ + gl_console->screen_y = 0; + + /* Set screen buffer to the top shifted lefted by the screen start value */ + gl_console->screen_buffer = gl_console->scroll_buffer + gl_console->screen_start_x; + + /* Finished, return success */ + return PROJECTM_SUCCESS; +} + + +/* Align the cursor to the top of the screen of the passed console */ +int glConsoleAlignCursorDown(gl_console_t * gl_console) { + + /* Null argument check */ + if (gl_console == NULL) + return PROJECTM_FAILURE; + + /* Set the cursor pointer to the bottom of the buffer plus the x offset */ + gl_console->cursor_ptr = gl_console->scroll_buffer + + ((gl_console->scroll_height-1)*gl_console->scroll_width) + + gl_console->screen_start_x + gl_console->screen_x; + + /* Set the screen start y to the bottom of the scroll buffer mi screen_height */ + gl_console->screen_start_y = gl_console->scroll_height - gl_console->screen_height; + + /* Set the screen_y cursor value to the bottom of the screen buffer */ + gl_console->screen_y = gl_console->screen_height - 1; + + /* Set screen buffer to the bottom minus the height of the screen + shifted left by the screen start value */ + + gl_console->screen_buffer = gl_console->scroll_buffer + + ((gl_console->scroll_height - gl_console->screen_height) + *gl_console->scroll_width) + gl_console->screen_start_x; + + /* Finished, return success */ + return PROJECTM_SUCCESS; +} + + + +int glConsoleDraw( gl_console_t * console) { + +#ifdef USE_FTGL + int vw = 512; + int vh=512; + int x,y; + //float minx, miny, maxx, maxy; + char * symbol; + console_char_t * console_char; + float start_x, start_y; + + //REMOVE SOON + //int width=800,height=600; + + + // console->start_x=0; + // console->start_y=1; + + + int width=1; + int height=1; + + + + start_y = -(console->start_y - 1.0); + start_x = console->start_x; + + /* Null argument check */ + if (console == NULL) + return PROJECTM_FAILURE; + + symbol = (char*)wipemalloc(sizeof(char)+1); + *symbol = *(symbol+1) = 0; + + /* First, push the gl matrix to save data */ + glPushMatrix(); + + + /* Start rendering at the console's start position */ + glTranslatef(start_x,start_y,-1); + //glTranslatef(0,0.5,-1); + /* Assign a pointer to the start of the console buffer */ + console_char = console->screen_buffer; + + /* Iterate through entire console buffer, drawing each + character one at a time with appropiate foreground and + background values. May not be the most efficient. */ + + // glScalef(8.0,8.0,0); + + + + float llx; // The bottom left near most ?? in the x axis + float lly; // The bottom left near most ?? in the y axis + float llz; // The bottom left near most ?? in the z axis + float urx; // The top right far most ?? in the x axis + float ury; // The top right far most ?? in the y axis + float urz; // The top right far most ?? in the z axis + float advance; + + + //Figure out size of one console unit + PM->renderer->other_font->FaceSize((unsigned)(16*(vh/512.0))); + + /// @bug commented out to get projectM working + //advance=PM->renderer->other_font->Advance("W"); + PM->renderer->other_font->BBox("qpg_XT[",llx,lly,llx,urx,ury,urz); + + + float invfix=1.0/512; + llx*=invfix;lly*=invfix;llz*=invfix; + urx*=invfix;ury*=invfix;urz*=invfix; + advance=advance/vw; + + glTranslatef(advance*0.5,lly-ury,0); + + for (y = 0; y < console->screen_height; y++) { + + glPushMatrix(); + char buffer[console->screen_width+1]; + memset( buffer, '\0',sizeof(char) * (console->screen_width+1)); + + + + for (x = 0; x < console->screen_width; x++) { + + console_char = console->screen_buffer + (y*console->scroll_width) + x; + *symbol = console_char->symbol; + + + /* Draw the background color */ + if ((console->flags & CONSOLE_FLAG_ALWAYS_DRAW_BACKGROUND) || (*symbol != 0)) { + + /* Draw the background by drawing a rectangle */ + gl_console_set_color(console_char->bg_color); + glRectf(llx, lly ,llx+advance, ury); + + } + + /* We are at the cursor position. See if the cursor is hidden or not and act accordingly */ + if ((console_char == console->cursor_ptr) && (!(console->flags & CONSOLE_FLAG_CURSOR_HIDDEN))) { + + /* Cursor is not hidden and blinking */ + if (console->flags & CONSOLE_FLAG_CURSOR_BLINKING) { + if (refresh_count % CURSOR_REFRESH_RATE) + gl_console_set_color(console->cursor_color); + else + gl_console_set_color(console_char->bg_color); + } + + /* Cursor is not hidden, and not blinking */ + else { + gl_console_set_color(console->cursor_color); + } + + /* Draw the cursor according to the set style */ + if (console->cursor_style == BAR_STYLE) + glRectf(llx, lly, llx+advance, ury); + else if (console->cursor_style == UNDERLINE_STYLE) { + glRectf(llx, lly, llx+advance, ury); + } + } + + /* The cursor is not here or hidden, draw regular background (OLD COMMENT) */ + + /* Instead of the above, do nothing because we always draw the background before + printing the cursor to the screen */ + else { + +// if ((console->flags & CONSOLE_FLAG_ALWAYS_DRAW_BACKGROUND) || (*symbol != 0)) { + + /* Draw the background by drawing a rectangle */ +// gl_console_set_color(console_char->bg_color); +// glRectf(-0.5, 1.0 ,1.0, -1.0); + + //} + } + + /* If the symbol is nonzero draw it */ + if (*symbol != 0 && *symbol != '\n') { + buffer[x]=*symbol; + //gl_console_set_color(console_char->fg_color); + } + /* Now shift to the right by the size of the character space */ + glTranslatef(advance,0,0); + + // console_char++; + } + + + // glColor4f(0.0,1.0,1.0,1.0); + //glTranslatef(((lly-ury)*console->screen_width),0,0); + //glRasterPos2f(50,-50); + + glPopMatrix(); + + console_char = console->screen_buffer + (y*console->scroll_width + 1); + gl_console_set_color(console_char->fg_color); + glRasterPos2f(0,0); + + PM->renderer->other_font->Render(buffer); + + + /* New line, shift down the size of the symbol plus some extra space */ + + + glTranslatef(0,(lly-ury), 0); + } + //glColor4f(1,1,1,1); + + /* Finished, pop the gl matrix and return success */ + glPopMatrix(); + + + free(symbol); + refresh_count++; +#endif /** USE_FTGL */ + + return PROJECTM_SUCCESS; +} + + + +int glConsoleSetFlags(int flags, gl_console_t * gl_console) { + + if (gl_console == NULL) + return PROJECTM_FAILURE; + + gl_console->flags = gl_console->flags | flags; + + return PROJECTM_SUCCESS; +} + +#ifdef NOGOOD +int glConsoleStartShell(gl_console_t * gl_console) { + + int pid1, pid2; + char * s; + char c; + FILE * fs; + + if (gl_console == NULL) + return PROJECTM_FAILURE; + + if ((s = wipemalloc(sizeof(char) + 512)) == NULL) + return PROJECTM_FAILURE; + + memset(s, 0, 512); + +#if !defined(MACOS) && !defined(WIN32) + if ((pid1 = fork()) == 0) { + printf("bash starting\n"); + execve("/bin/bash", NULL, NULL); + printf("bash exiting..\n"); + exit(0); + } + + if ((pid2 = fork()) == 0) { + //fs = fopen("tempfile", "r"); + printf("about to loop on stdout\n"); + while (1) { + //printf("^");//fflush(stdout); + //ungetc(c, stdin); + fread(s, 1, 1, stdout); + *s = 'a'; + //printf("%c", *s);fflush(stdout); + glConsolePrintString(s, gl_console); + } + //fclose(fs); + printf("waiting for pid1 to exit\n"); + waitpid(pid1, NULL, 0); + free(s); + printf("pid1 exited\n"); + return PROJECTM_SUCCESS; + } + + printf("bash should have started\n"); +#endif /** !MACOS */ + return PROJECTM_SUCCESS; +} +#endif +/* Copies the console buffer into a character array */ +int glConsoleCopyBuffer(char * src, int len, gl_console_t * gl_console) { + + int i; + int j = 0; + int size; + char c; + if (src == NULL) + return PROJECTM_FAILURE; + if (len < 0) + return PROJECTM_FAILURE; + if (gl_console == NULL) + return PROJECTM_FAILURE; + + /* Clear the character space */ + memset(src, 0, len); + + size = gl_console->scroll_width*gl_console->scroll_height; + + for (i=0; ((i - j) < len) && (i < size); i++) { + c = (gl_console->scroll_buffer + i)->symbol; + + /* We don't want to accidentally null terminate the string...*/ + if (c != 0) + src[i - j] = c; + else + j++; + + // if (c != 0) + // src[i] = c; + // else + // src[i] = '\n'; + } + + /* Ensure the string actually ends */ + src[len - 1] = 0; + + return PROJECTM_SUCCESS; +} + +/* Sets the cursor draw style */ +int glConsoleSetCursorStyle(int style_num, gl_console_t * gl_console) { + + if (gl_console == NULL) + return PROJECTM_FAILURE; + + gl_console->cursor_style = style_num; + + return PROJECTM_SUCCESS; +} + diff --git a/src/projectM-engine-backup/glConsole.h b/src/projectM-engine-backup/glConsole.h new file mode 100755 index 000000000..ecded4c00 --- /dev/null +++ b/src/projectM-engine-backup/glConsole.h @@ -0,0 +1,114 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * + * $Log$ + */ + +#ifndef _GLCONSOLE_H +#define _GLCONSOLE_H + +#define GL_CONSOLE_DEBUG 0 +#define MAX_CONSOLE_HEIGHT 500 +#define MAX_CONSOLE_WIDTH 500 + +#define CONSOLE_FLAG_NONE 0 +#define CONSOLE_FLAG_CURSOR_HIDDEN 1 +#define CONSOLE_FLAG_CURSOR_BLINKING (1 << 1) +#define CONSOLE_FLAG_SCROLL_WRAP_RIGHT (1 << 3) +#define CONSOLE_FLAG_SCROLL_WRAP_LEFT (1 << 4) +#define CONSOLE_FLAG_SCROLL_WRAP_UP (1 << 5) +#define CONSOLE_FLAG_SCROLL_WRAP_DOWN (1 << 6) +#define CONSOLE_FLAG_ALWAYS_DRAW_BACKGROUND (1 << 7) + +#define BAR_STYLE 0 +#define UNDERLINE_STYLE 1 + +typedef enum { + CONSOLE_RED, + CONSOLE_BLACK, + CONSOLE_BLUE, + CONSOLE_WHITE, + CONSOLE_GREEN, + CONSOLE_TRANS +} color_t; + +typedef struct CONSOLE_CHAR_T { + char symbol; + color_t fg_color; + color_t bg_color; +} console_char_t; + + +typedef struct GL_CONSOLE_T { + float start_x; + float start_y; + int screen_width; + int screen_height; + int scroll_width; + int scroll_height; + console_char_t * screen_buffer; /* start of current screen buffer */ + console_char_t * scroll_buffer; /* pointer to very top of buffer */ + int font_descriptor; + int screen_x; + int screen_y; + int screen_start_x; + int screen_start_y; + int cursor_style; + color_t current_fg; + color_t current_bg; + color_t cursor_color; + console_char_t * cursor_ptr; /* pointer to position in console buffer */ + short int flags; +} gl_console_t; + +int glConsoleSetFGColor(color_t color, gl_console_t * gl_console); +int glConsoleSetBGColor(color_t color, gl_console_t * gl_console); +int glConsoleSetCursorColor(color_t color, gl_console_t * gl_console); +int glConsoleSetCursorPos(int x, int y, gl_console_t * gl_console); +int glConsoleGetCursorPos(int * x, int * y, gl_console_t * gl_console); +int glConsoleShowCursor(gl_console_t * console); +int glConsoleHideCursor(gl_console_t * console); +int glConsoleDraw( gl_console_t * console); +int glConsoleClearScreen(gl_console_t * console); +int glConsoleClearBuffer(gl_console_t * console); +int glConsolePrintString(char * s, gl_console_t * console); +int glConsoleSetFlags(int flags, gl_console_t * console); +int glConsoleSetCursorStyle(int style_num, gl_console_t * console); +int glConsoleAlignCursorRight(gl_console_t * gl_console); +int glConsoleAlignCursorLeft(gl_console_t * gl_console); +int glConsoleAlignCursorUp(gl_console_t * gl_console); +int glConsoleAlignCursorDown(gl_console_t * gl_console); + +int glConsoleMoveCursorForward(gl_console_t * gl_console); +int glConsoleMoveCursorBackward(gl_console_t * gl_console); +int glConsoleMoveCursorUp(gl_console_t * gl_console); +int glConsoleMoveCursorDown(gl_console_t * gl_console); +int glConsoleStartShell(gl_console_t * gl_console); +int glConsoleCopyBuffer(char * src, int len, gl_console_t * gl_console); +int glConsoleCursorToNextChar(char c, gl_console_t * gl_console); +gl_console_t * glConsoleCreate(int screen_width, int screen_height, int scroll_width, int scroll_height, + float start_x, float start_y, int font_descriptor); +int glConsoleDestroy(gl_console_t * console); + +#endif /** !_GLCONSOLE_H */ diff --git a/src/projectM-engine-backup/libprojectM.dsp b/src/projectM-engine-backup/libprojectM.dsp new file mode 100755 index 000000000..a7ffbd35f --- /dev/null +++ b/src/projectM-engine-backup/libprojectM.dsp @@ -0,0 +1,348 @@ +# Microsoft Developer Studio Project File - Name="libprojectM" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=libprojectM - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "libprojectM.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "libprojectM.mak" CFG="libprojectM - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "libprojectM - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "libprojectM - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "libprojectM - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "libprojectM - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "DEBUG" /YX /FD /GZ /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "libprojectM - Win32 Release" +# Name "libprojectM - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\BeatDetect.cpp +# End Source File +# Begin Source File + +SOURCE=.\browser.cpp +# End Source File +# Begin Source File + +SOURCE=.\builtin_funcs.cpp +# End Source File +# Begin Source File + +SOURCE=.\console_interface.cpp +# End Source File +# Begin Source File + +SOURCE=.\CustomShape.cpp +# End Source File +# Begin Source File + +SOURCE=.\CustomWave.cpp +# End Source File +# Begin Source File + +SOURCE=.\editor.cpp +# End Source File +# Begin Source File + +SOURCE=.\Eval.cpp +# End Source File +# Begin Source File + +SOURCE=.\Expr.cpp +# End Source File +# Begin Source File + +SOURCE=.\fftsg.cpp +# End Source File +# Begin Source File + +SOURCE=.\Func.cpp +# End Source File +# Begin Source File + +SOURCE=.\glConsole.cpp +# End Source File +# Begin Source File + +SOURCE=.\InitCond.cpp +# End Source File +# Begin Source File + +SOURCE=.\menu.cpp +# End Source File +# Begin Source File + +SOURCE=.\Param.cpp +# End Source File +# Begin Source File + +SOURCE=.\Parser.cpp +# End Source File +# Begin Source File + +SOURCE=.\pbuffer.cpp +# End Source File +# Begin Source File + +SOURCE=.\PCM.cpp +# End Source File +# Begin Source File + +SOURCE=.\PerFrameEqn.cpp +# End Source File +# Begin Source File + +SOURCE=.\PerPixelEqn.cpp +# End Source File +# Begin Source File + +SOURCE=.\PerPointEqn.cpp +# End Source File +# Begin Source File + +SOURCE=.\Preset.cpp +# End Source File +# Begin Source File + +SOURCE=.\projectM.cpp +# End Source File +# Begin Source File + +SOURCE=.\SplayTree.cpp +# End Source File +# Begin Source File + +SOURCE=.\timer.cpp +# End Source File +# Begin Source File + +SOURCE=".\win32-dirent.cpp" +# End Source File +# Begin Source File + +SOURCE=.\wipemalloc.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\BeatDetect.h +# End Source File +# Begin Source File + +SOURCE=.\browser.h +# End Source File +# Begin Source File + +SOURCE=.\builtin_funcs.h +# End Source File +# Begin Source File + +SOURCE=.\carbontoprojectM.h +# End Source File +# Begin Source File + +SOURCE=.\common.h +# End Source File +# Begin Source File + +SOURCE=.\compare.h +# End Source File +# Begin Source File + +SOURCE=.\console_interface.h +# End Source File +# Begin Source File + +SOURCE=.\CustomShape.h +# End Source File +# Begin Source File + +SOURCE=.\CustomWave.h +# End Source File +# Begin Source File + +SOURCE=.\CValue.h +# End Source File +# Begin Source File + +SOURCE=.\dlldefs.h +# End Source File +# Begin Source File + +SOURCE=.\editor.h +# End Source File +# Begin Source File + +SOURCE=.\Eval.h +# End Source File +# Begin Source File + +SOURCE=.\event.h +# End Source File +# Begin Source File + +SOURCE=.\Expr.h +# End Source File +# Begin Source File + +SOURCE=.\fatal.h +# End Source File +# Begin Source File + +SOURCE=.\fftsg.h +# End Source File +# Begin Source File + +SOURCE=.\Func.h +# End Source File +# Begin Source File + +SOURCE=.\glConsole.h +# End Source File +# Begin Source File + +SOURCE=.\glf.h +# End Source File +# Begin Source File + +SOURCE=.\InitCond.h +# End Source File +# Begin Source File + +SOURCE=.\lvtoprojectM.h +# End Source File +# Begin Source File + +SOURCE=.\menu.h +# End Source File +# Begin Source File + +SOURCE=.\Param.h +# End Source File +# Begin Source File + +SOURCE=.\Parser.h +# End Source File +# Begin Source File + +SOURCE=.\pbuffer.h +# End Source File +# Begin Source File + +SOURCE=.\PCM.h +# End Source File +# Begin Source File + +SOURCE=.\PerFrameEqn.h +# End Source File +# Begin Source File + +SOURCE=.\PerPixelEqn.h +# End Source File +# Begin Source File + +SOURCE=.\PerPointEqn.h +# End Source File +# Begin Source File + +SOURCE=.\Preset.h +# End Source File +# Begin Source File + +SOURCE=.\projectM.h +# End Source File +# Begin Source File + +SOURCE=.\sdltoprojectM.h +# End Source File +# Begin Source File + +SOURCE=.\SplayTree.h +# End Source File +# Begin Source File + +SOURCE=.\timer.h +# End Source File +# Begin Source File + +SOURCE=".\win32-dirent.h" +# End Source File +# Begin Source File + +SOURCE=.\wipemalloc.h +# End Source File +# End Group +# End Target +# End Project diff --git a/src/projectM-engine-backup/libprojectM.ncb b/src/projectM-engine-backup/libprojectM.ncb new file mode 100755 index 000000000..eed9399a5 Binary files /dev/null and b/src/projectM-engine-backup/libprojectM.ncb differ diff --git a/src/projectM-engine-backup/libprojectM.opt b/src/projectM-engine-backup/libprojectM.opt new file mode 100755 index 000000000..1327d4034 Binary files /dev/null and b/src/projectM-engine-backup/libprojectM.opt differ diff --git a/src/projectM-engine-backup/libprojectM.plg b/src/projectM-engine-backup/libprojectM.plg new file mode 100755 index 000000000..a3e36679c --- /dev/null +++ b/src/projectM-engine-backup/libprojectM.plg @@ -0,0 +1,78 @@ + + +
+

Build Log

+

+--------------------Configuration: libprojectM - Win32 Debug-------------------- +

+

Command Lines

+Creating temporary file "C:\DOCUME~1\descarte\LOCALS~1\Temp\RSP2E1.tmp" with contents +[ +/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "DEBUG" /Fp"Debug/libprojectM.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c +"C:\tmp\projectM-1.00\src\libprojectM\browser.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\builtin_funcs.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\console_interface.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\CustomShape.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\CustomWave.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\editor.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\Eval.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\Expr.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\Func.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\glConsole.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\InitCond.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\menu.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\Param.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\Parser.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\PerFrameEqn.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\PerPixelEqn.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\PerPointEqn.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\Preset.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\projectM.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\SplayTree.cpp" +"C:\tmp\projectM-1.00\src\libprojectM\win32-dirent.cpp" +] +Creating command line "cl.exe @C:\DOCUME~1\descarte\LOCALS~1\Temp\RSP2E1.tmp" +Creating temporary file "C:\DOCUME~1\descarte\LOCALS~1\Temp\RSP2E2.tmp" with contents +[ +/nologo /out:"Debug\libprojectM.lib" +".\Debug\BeatDetect.obj" +".\Debug\browser.obj" +".\Debug\builtin_funcs.obj" +".\Debug\console_interface.obj" +".\Debug\CustomShape.obj" +".\Debug\CustomWave.obj" +".\Debug\editor.obj" +".\Debug\Eval.obj" +".\Debug\Expr.obj" +".\Debug\fftsg.obj" +".\Debug\Func.obj" +".\Debug\glConsole.obj" +".\Debug\InitCond.obj" +".\Debug\menu.obj" +".\Debug\Param.obj" +".\Debug\Parser.obj" +".\Debug\pbuffer.obj" +".\Debug\PCM.obj" +".\Debug\PerFrameEqn.obj" +".\Debug\PerPixelEqn.obj" +".\Debug\PerPointEqn.obj" +".\Debug\Preset.obj" +".\Debug\projectM.obj" +".\Debug\SplayTree.obj" +".\Debug\timer.obj" +".\Debug\win32-dirent.obj" +".\Debug\wipemalloc.obj" +] +Creating command line "link.exe -lib @C:\DOCUME~1\descarte\LOCALS~1\Temp\RSP2E2.tmp" +

Output Window

+Compiling... +browser.cpp +builtin_funcs.cpp +console_interface.cpp +CustomShape.cpp +CustomWave.cpp +cl.exe terminated at user request. + +
+ + diff --git a/src/projectM-engine-backup/libprojectM/Debug/libprojectM.pch b/src/projectM-engine-backup/libprojectM/Debug/libprojectM.pch new file mode 100755 index 000000000..e8c8d9c27 Binary files /dev/null and b/src/projectM-engine-backup/libprojectM/Debug/libprojectM.pch differ diff --git a/src/projectM-engine-backup/libprojectM/Debug/vc60.idb b/src/projectM-engine-backup/libprojectM/Debug/vc60.idb new file mode 100755 index 000000000..0f48fc1bb Binary files /dev/null and b/src/projectM-engine-backup/libprojectM/Debug/vc60.idb differ diff --git a/src/projectM-engine-backup/libprojectM/Debug/vc60.pdb b/src/projectM-engine-backup/libprojectM/Debug/vc60.pdb new file mode 100755 index 000000000..6e47e71d2 Binary files /dev/null and b/src/projectM-engine-backup/libprojectM/Debug/vc60.pdb differ diff --git a/src/projectM-engine-backup/libprojectM/libprojectM.plg b/src/projectM-engine-backup/libprojectM/libprojectM.plg new file mode 100755 index 000000000..1f8cd9f10 --- /dev/null +++ b/src/projectM-engine-backup/libprojectM/libprojectM.plg @@ -0,0 +1,16 @@ + + +
+

Build Log

+

+--------------------Configuration: libprojectM - Win32 Debug-------------------- +

+

Command Lines

+ + + +

Results

+libprojectM.lib - 0 error(s), 0 warning(s) +
+ + diff --git a/src/projectM-engine-backup/lvtoprojectM.h b/src/projectM-engine-backup/lvtoprojectM.h new file mode 100755 index 000000000..4215b8abe --- /dev/null +++ b/src/projectM-engine-backup/lvtoprojectM.h @@ -0,0 +1,156 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: sdltoprojectM.hpp,v 1.1 2004/10/08 00:35:28 cvs Exp $ + * + * Translates SDL -> projectM variables + * + * $Log: sdltoprojectM.hpp,v $ + * Revision 1.1 2004/10/08 00:35:28 cvs + * Moved and imported + * + * Revision 1.1.1.1 2004/10/04 12:56:00 cvs + * Imported + * + */ + +#include + +projectMEvent lv2pmEvent( VisEventType event ) { + + switch ( event ) { + case VISUAL_EVENT_RESIZE: + return PROJECTM_VIDEORESIZE; + case VISUAL_EVENT_KEYUP: + return PROJECTM_KEYUP; + case VISUAL_EVENT_KEYDOWN: + return PROJECTM_KEYDOWN; + default: + return PROJECTM_KEYUP; + } + } +projectMKeycode lv2pmKeycode( VisKey keysym ) +{ + switch ( keysym ) + { + case VKEY_F1: + return PROJECTM_K_F1; + case VKEY_F2: + return PROJECTM_K_F2; + case VKEY_F3: + return PROJECTM_K_F3; + case VKEY_F4: + return PROJECTM_K_F4; + case VKEY_F5: + return PROJECTM_K_F5; + case VKEY_F6: + return PROJECTM_K_F6; + case VKEY_F7: + return PROJECTM_K_F7; + case VKEY_F8: + return PROJECTM_K_F8; + case VKEY_F9: + return PROJECTM_K_F9; + case VKEY_F10: + return PROJECTM_K_F10; + case VKEY_F11: + return PROJECTM_K_F11; + case VKEY_F12: + return PROJECTM_K_F12; + case VKEY_ESCAPE: + return PROJECTM_K_ESCAPE; + case VKEY_a: + return PROJECTM_K_a; + case VKEY_b: + return PROJECTM_K_b; + case VKEY_c: + return PROJECTM_K_c; + case VKEY_d: + return PROJECTM_K_d; + case VKEY_e: + return PROJECTM_K_e; + case VKEY_f: + return PROJECTM_K_f; + case VKEY_g: + return PROJECTM_K_g; + case VKEY_h: + return PROJECTM_K_h; + case VKEY_i: + return PROJECTM_K_i; + case VKEY_j: + return PROJECTM_K_j; + case VKEY_k: + return PROJECTM_K_k; + case VKEY_l: + return PROJECTM_K_l; + case VKEY_m: + return PROJECTM_K_m; + case VKEY_n: + return PROJECTM_K_n; + case VKEY_o: + return PROJECTM_K_o; + case VKEY_p: + return PROJECTM_K_p; + case VKEY_q: + return PROJECTM_K_q; + case VKEY_r: + return PROJECTM_K_r; + case VKEY_s: + return PROJECTM_K_s; + case VKEY_t: + return PROJECTM_K_t; + case VKEY_u: + return PROJECTM_K_u; + case VKEY_v: + return PROJECTM_K_v; + case VKEY_w: + return PROJECTM_K_w; + case VKEY_x: + return PROJECTM_K_x; + case VKEY_y: + return PROJECTM_K_y; + case VKEY_z: + return PROJECTM_K_z; + case VKEY_UP: + return PROJECTM_K_UP; + case VKEY_RETURN: + return PROJECTM_K_RETURN; + case VKEY_RIGHT: + return PROJECTM_K_RIGHT; + case VKEY_LEFT: + return PROJECTM_K_LEFT; + case VKEY_DOWN: + return PROJECTM_K_DOWN; + case VKEY_PAGEUP: + return PROJECTM_K_PAGEUP; + case VKEY_PAGEDOWN: + return PROJECTM_K_PAGEDOWN; + + + default: + return PROJECTM_K_NONE; + break; + } + } + +projectMModifier lv2pmModifier( int mod ) { + return mod && VKMOD_LSHIFT; + } diff --git a/src/projectM-engine-backup/menu.cpp b/src/projectM-engine-backup/menu.cpp new file mode 100755 index 000000000..26c3f7930 --- /dev/null +++ b/src/projectM-engine-backup/menu.cpp @@ -0,0 +1,1033 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#include +#include +#include + +#include "projectM.hpp" + +#ifdef MACOS +#include +#else +#include +#endif /** MACOS */ +#include "Common.hpp" +#include "fatal.h" +#include "Param.hpp" +#include + +#include "InitCond.hpp" + +#include "glConsole.h" + +#include "Preset.hpp" +#include "editor.h" +#include "menu.h" +#include "wipemalloc.h" + +#define HIGHLIGHT_COLOR 1 +#define DEFAULT_COLOR 0 +#define LOCKED_COLOR 2 +#if 0 +extern Preset *activePreset; +extern interface_t current_interface; + +menu_t * load_waveform_menu(); +menu_t * load_augmentations_menu(); +menu_t * load_postprocessing_menu(); +menu_t * load_motion_menu(); +int load_main_menu(); + +int edit_per_frame_init(); +int edit_per_frame_eqn(); +int edit_per_pixel_eqn(); +int run_bash_shell(); + + +int print_menu_item(menu_item_t * menu_item); +int switch_bool_param(Param * param); +int adj_float_param(Param * param, adj_t adj); +int adj_int_param(Param * param, adj_t adj); +int pursue_menu_link(menu_link_t * menu_link); + +int append_menu_item(menu_t * menu, menu_item_t * new_menu_item); + +menu_t * new_menu(menu_t * top_menu); +menu_item_t * new_menu_item(int menu_entry_type, menu_entry_t * menu_entry); +menu_entry_t * new_menu_link(char * print_string, menu_t * menu_ptr); + + +menu_entry_t * new_param_adj(char * print_string, Param * param); + +menu_entry_t * new_function_mode(char * print_string, int (*func_ptr)()); + +int free_menu_entry(menu_entry_t * menu_entry); +int free_menu_item(menu_item_t * menu_item); +int free_menu(menu_t * menu); + +int menu_lprint(char * string, int col); +int init_main_menu(); +int destroy_main_menu(); + +int width, height; + +float xmin,ymin,xmax,ymax; + + +CValue saved_init_val; /* backups the value of an initial condition */ + +menu_t * main_menu = NULL; /* Global menu structure */ + +menu_t * active_menu = NULL; /* the currently loaded menu */ + +gl_console_t * menu_console = NULL; + + +display_state menu_display_state = HIDE; + +int initMenu() { + if (MENU_DEBUG) { + printf("initMenu: loading menu:"); + fflush(stdout); + } + + load_main_menu(); + if (MENU_DEBUG) printf(" [done]\n"); + active_menu = main_menu; + return PROJECTM_SUCCESS; +} + +int showMenu() { + + if ((menu_console = glConsoleCreate(80,24, 81, 25, width*.05, height * .90,0)) == NULL) + return PROJECTM_FAILURE; + + glConsoleSetFlags(CONSOLE_FLAG_CURSOR_HIDDEN|CONSOLE_FLAG_SCROLL_WRAP_DOWN|CONSOLE_FLAG_SCROLL_WRAP_RIGHT, menu_console); + + active_menu = main_menu; + main_menu->start_item = main_menu->selected_item; + menu_display_state = SHOW; + return PROJECTM_SUCCESS; +} + +int hideMenu() { + menu_display_state = HIDE; + active_menu = main_menu; + active_menu->selected_item = active_menu->start_item; + + if (active_menu->locked_item != NULL) { + // if (active_menu->locked_item->menu_entry_type == PARAM_ADJ_TYPE) + // active_menu->locked_item->menu_entry->param_adj.param->init_val = saved_init_val; + active_menu->locked_item = NULL; + } + + glConsoleDestroy(menu_console); + menu_console = NULL; + + return PROJECTM_SUCCESS; +} + +int load_main_menu() { + + menu_t * waveform_menu; + menu_t * augmentations_menu; + menu_t * motion_menu; + menu_t * postprocessing_menu; + + if ((main_menu = new_menu(NULL)) == NULL) + return PROJECTM_OUTOFMEM_ERROR; + + if (MENU_DEBUG) { printf(" [waveform:"); fflush(stdout); } + waveform_menu = load_waveform_menu(); + + if (waveform_menu == NULL) { + free_menu(main_menu); + if (MENU_DEBUG) { printf(" failure]\n"); fflush(stdout); } + return PROJECTM_FAILURE; + } + + if (MENU_DEBUG) { printf(" success]"); fflush(stdout); } + + if (MENU_DEBUG) { printf(" [augmentations:"); fflush(stdout); } + augmentations_menu = load_augmentations_menu(); + + if (augmentations_menu == NULL) { + free_menu(main_menu); + free_menu(waveform_menu); + if (MENU_DEBUG) { printf(" failure]\n"); fflush(stdout); } + return PROJECTM_FAILURE; + } + + if (MENU_DEBUG) { printf(" success]"); fflush(stdout); } + + if (MENU_DEBUG) { printf(" [postprocessing:"); fflush(stdout); } + postprocessing_menu = load_postprocessing_menu(); + + if (postprocessing_menu == NULL) { + free_menu(main_menu); + free_menu(waveform_menu); + free_menu(augmentations_menu); + if (MENU_DEBUG) { printf(" failure]\n"); fflush(stdout); } + return PROJECTM_FAILURE; + } + + if (MENU_DEBUG) { printf(" success]"); fflush(stdout); } + + if (MENU_DEBUG) { printf(" [motion:"); fflush(stdout); } + motion_menu = load_motion_menu(); + + if (motion_menu == NULL) { + free_menu(main_menu); + free_menu(waveform_menu); + free_menu(augmentations_menu); + free_menu(postprocessing_menu); + if (MENU_DEBUG) { printf(" failure]\n"); fflush(stdout); } + return PROJECTM_FAILURE; + } + + if (MENU_DEBUG) { printf(" success]"); fflush(stdout); } + + append_menu_item(main_menu, new_menu_item(MENU_LINK_TYPE, new_menu_link("--waveform", waveform_menu))); + append_menu_item(main_menu, new_menu_item(MENU_LINK_TYPE, new_menu_link("--augmentations", augmentations_menu))); + append_menu_item(main_menu, new_menu_item(MENU_LINK_TYPE, new_menu_link("--motion", motion_menu))); + append_menu_item(main_menu, new_menu_item(MENU_LINK_TYPE, new_menu_link("--post processing, global effects", postprocessing_menu))); + + append_menu_item(main_menu, new_menu_item(FUNCTION_MODE_TYPE, new_function_mode("edit per_frame equations", edit_per_frame_eqn))); + append_menu_item(main_menu, new_menu_item(FUNCTION_MODE_TYPE, new_function_mode("edit per_pixel equations", edit_per_pixel_eqn))); + append_menu_item(main_menu, new_menu_item(FUNCTION_MODE_TYPE, new_function_mode("edit preset initialization code", edit_per_frame_init))); + //append_menu_item(main_menu, new_menu_item(FUNCTION_MODE_TYPE, new_function_mode("bash shell", run_bash_shell))); + + main_menu->selected_item = main_menu->start_item; + + return PROJECTM_SUCCESS; +} + + +menu_t * load_waveform_menu() { + menu_t * waveform_menu; + + if ((waveform_menu = new_menu(main_menu)) == NULL) + return NULL; + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("wave type", ParamUtils::find("nWaveMode", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("size", ParamUtils::find("fWaveScale", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("smoothing", ParamUtils::find("fWaveSmoothing", activePreset, P_CREATE)))); + + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("mystery parameter", ParamUtils::find("wave_mystery", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("opacity", ParamUtils::find("fWaveAlpha", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("position (x)", ParamUtils::find("wave_x", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("position (y)", ParamUtils::find("wave_y", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("color (red)", ParamUtils::find("wave_r", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("color (green)", ParamUtils::find("wave_g", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("color (blue)", ParamUtils::find("wave_b", activePreset, P_CREATE)))); + + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("use dots", ParamUtils::find("bWaveDots", activePreset, P_CREATE)))); + + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("draw thick", ParamUtils::find("bWaveThick", activePreset, P_CREATE)))); + + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("modulate opacity by volume", ParamUtils::find("bModWaveAlphaByVolume", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("mod. lower threshold", ParamUtils::find("fModWaveAlphaStart", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("mod. uppper threshold", ParamUtils::find("fModWaveAlphaEnd", activePreset, P_CREATE)))); + + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("additive drawing", ParamUtils::find("bAdditiveWaves", activePreset, P_CREATE)))); + append_menu_item(waveform_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("color brightening", ParamUtils::find("bMaximizeWaveColor", activePreset, P_CREATE)))); + waveform_menu->selected_item = waveform_menu->start_item; + + return waveform_menu; +} + + +menu_t * load_augmentations_menu() { + menu_t * augmentations_menu; + + if ((augmentations_menu = new_menu(main_menu)) == NULL) + return NULL; + + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("outer border thickness", ParamUtils::find("ob_size", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj(" color (red)", ParamUtils::find("ob_r", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj(" color (green)", ParamUtils::find("ob_g", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj(" color (blue)", ParamUtils::find("ob_b", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj(" opacity", ParamUtils::find("ob_a", activePreset, P_CREATE)))); + + + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("inner border thickness", ParamUtils::find("ib_size", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj(" color (red)", ParamUtils::find("ib_r", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj(" color (green)", ParamUtils::find("ib_g", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj(" color (blue)", ParamUtils::find("ib_b", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj(" opacity", ParamUtils::find("ib_a", activePreset, P_CREATE)))); + + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("motion vector opacity", ParamUtils::find("mv_a", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("num. mot. vector (X)", ParamUtils::find("mv_x", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("num. mot. vector (Y)", ParamUtils::find("mv_y", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("offset (X)", ParamUtils::find("mv_dx", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("offset (Y)", ParamUtils::find("mv_dy", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("trail length", ParamUtils::find("mv_l", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("color (red)", ParamUtils::find("mv_r", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("color (green)", ParamUtils::find("mv_g", activePreset, P_CREATE)))); + append_menu_item(augmentations_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("color (blue)", ParamUtils::find("mv_b", activePreset, P_CREATE)))); + + + augmentations_menu->selected_item = augmentations_menu->start_item; + + return augmentations_menu; +} + +/* Loads the motion menu, a sub menu of the main menu */ +menu_t * load_motion_menu() { + menu_t * motion_menu; + + if ((motion_menu = new_menu(main_menu)) == NULL) + return NULL; + + + append_menu_item(motion_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("zoom amount", ParamUtils::find("zoom", activePreset, P_CREATE)))); + append_menu_item(motion_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("zoom exponent", ParamUtils::find("zoomexp", activePreset, P_CREATE)))); + append_menu_item(motion_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("rotation amount", ParamUtils::find("rot", activePreset, P_CREATE)))); + append_menu_item(motion_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("rot., center of (X)", ParamUtils::find("cx", activePreset, P_CREATE)))); + append_menu_item(motion_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("rot., center of (Y)", ParamUtils::find("cy", activePreset, P_CREATE)))); + append_menu_item(motion_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("translation (X)", ParamUtils::find("dx", activePreset, P_CREATE)))); + append_menu_item(motion_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("translation (Y)", ParamUtils::find("dy", activePreset, P_CREATE)))); + append_menu_item(motion_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("scaling (X)", ParamUtils::find("sx", activePreset, P_CREATE)))); + append_menu_item(motion_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("scaling (Y)", ParamUtils::find("sy", activePreset, P_CREATE)))); + + motion_menu->selected_item = motion_menu->start_item; + + return motion_menu; +} + +/* Loads the post processing menu, a sub menu of the main, menu */ +menu_t * load_postprocessing_menu() { + menu_t * postprocessing_menu; + if ((postprocessing_menu = new_menu(main_menu)) == NULL) + return NULL; + + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("sustain level", ParamUtils::find("fDecay", activePreset, P_CREATE)))); + + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("darken center", ParamUtils::find("bDarkenCenter", activePreset, P_CREATE)))); + + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("gamma adjustment", ParamUtils::find("fDecay", activePreset, P_CREATE)))); + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("video echo: alpha", ParamUtils::find("fVideoEchoAlpha", activePreset, P_CREATE)))); + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("video echo: scale", ParamUtils::find("fVideoEchoZoom", activePreset, P_CREATE)))); + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("video echo: orientation", ParamUtils::find("nVideoEchoOrientation", activePreset, P_CREATE)))); + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("texture wrapping", ParamUtils::find("bTexWrap", activePreset, P_CREATE)))); + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("darken filter", ParamUtils::find("bDarken", activePreset, P_CREATE)))); + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("brighten filter", ParamUtils::find("bBrighten", activePreset, P_CREATE)))); + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("solarize filter", ParamUtils::find("bSolarize", activePreset, P_CREATE)))); + append_menu_item(postprocessing_menu, new_menu_item(PARAM_ADJ_TYPE, new_param_adj("invert filter", ParamUtils::find("bInvert", activePreset, P_CREATE)))); + + + postprocessing_menu->selected_item = postprocessing_menu->start_item; + + return postprocessing_menu; +} + +int refreshMenu() { + + menu_item_t * menu_item; + + if (menu_display_state == HIDE) { + return PROJECTM_SUCCESS; + } + + if (menu_display_state == SPECIAL) { + glConsoleDraw(menu_console); + glConsoleClearBuffer(menu_console); + return PROJECTM_SUCCESS; + } + + menu_item = active_menu->start_item; + + glConsoleClearBuffer(menu_console); + + while (menu_item) { + print_menu_item(menu_item); + menu_item = menu_item->down; + } + + glConsoleDraw(menu_console); + return PROJECTM_SUCCESS; +} + +int destroyMenu() { + + if (main_menu != NULL) + free_menu(main_menu); + + main_menu = NULL; + return PROJECTM_SUCCESS; +} + +/* Prints a line to the opengl screen, second entry is the color, work in progress */ +int menu_lprint(char * string, int col) { + + if (active_menu == NULL) + return PROJECTM_FAILURE; + + if (string == NULL) + return PROJECTM_FAILURE; + + if (col == HIGHLIGHT_COLOR) { + glConsoleSetBGColor(CONSOLE_WHITE, menu_console); + glConsoleSetFGColor(CONSOLE_BLUE, menu_console); + } + else if (col == LOCKED_COLOR) { + glConsoleSetBGColor(CONSOLE_WHITE, menu_console); + glConsoleSetFGColor(CONSOLE_RED, menu_console); + } + else { + glConsoleSetBGColor(CONSOLE_BLACK, menu_console); + glConsoleSetFGColor(CONSOLE_WHITE, menu_console); + } + + glConsolePrintString(string, menu_console); + glConsolePrintString("\n", menu_console); + return PROJECTM_SUCCESS; +} + + + +int print_menu_item(menu_item_t * menu_item) { + + param_adj_t param_adj; + char string[MAX_TOKEN_SIZE]; + int col; + InitCond * init_cond; + + if (menu_item == NULL) + return PROJECTM_FAILURE; + if (active_menu == NULL) + return PROJECTM_FAILURE; + + if (active_menu->locked_item == menu_item) + col = LOCKED_COLOR; + else if (active_menu->selected_item == menu_item) + col = HIGHLIGHT_COLOR; + else + col = DEFAULT_COLOR; + switch (menu_item->menu_entry_type) { + + case PARAM_ADJ_TYPE: + param_adj = menu_item->menu_entry->param_adj; + + switch(param_adj.param->type) { + + case P_TYPE_BOOL: + + if ((init_cond = projectM::activePreset->get_init_cond(param_adj.param)) == NULL) + sprintf(string, "%s ?", param_adj.print_string); + else if (init_cond->init_val.bool_val) + sprintf(string, "%s [ON]", param_adj.print_string); + else + sprintf(string, "%s [OFF]", param_adj.print_string); + break; + case P_TYPE_INT: + if ((init_cond = projectM::activePreset->get_init_cond(param_adj.param)) == NULL) + sprintf(string, "%s ?", param_adj.print_string); + else + sprintf(string, "%s %d", param_adj.print_string, init_cond->init_val.int_val); + break; + case P_TYPE_DOUBLE: + if ((init_cond = projectM::activePreset->get_init_cond(param_adj.param)) == NULL) + sprintf(string, "%s ?", param_adj.print_string); + else + sprintf(string, "%s %f", param_adj.print_string, init_cond->init_val.float_val); + break; + + default: /* unknown paramater type */ + return PROJECTM_FAILURE; + } + return menu_lprint(string, col); + case FUNCTION_MODE_TYPE: + return menu_lprint(menu_item->menu_entry->function_mode.print_string, col); + case MENU_LINK_TYPE: + return menu_lprint(menu_item->menu_entry->menu_link.print_string, col); + default: + if (MENU_DEBUG) printf("print_menu_item: invalid menu entry type, val = %d\n", + menu_item->menu_entry_type); + return PROJECTM_FAILURE; + } + + return PROJECTM_SUCCESS; +} + +/* switchMenuState: changes to another menu item according to the passed direction */ +int switchMenuState(dir_t dir) { + + menu_item_t * new_menu_item; + param_adj_t param_adj; + InitCond * init_cond; + + if (active_menu == NULL) + return PROJECTM_FAILURE; + + /* Case on the direction of the key press */ + switch (dir) { + + case PAGEUP: + if(active_menu->locked_item != NULL) { + if (active_menu->locked_item->menu_entry_type == PARAM_ADJ_TYPE) + return adj_float_param(active_menu->locked_item->menu_entry->param_adj.param, BIG_INC); + } + + /* Force to top of menu */ + active_menu->selected_item = active_menu->start_item; + return PROJECTM_SUCCESS; + case PAGEDOWN: + if(active_menu->locked_item != NULL) { + if (active_menu->locked_item->menu_entry_type == PARAM_ADJ_TYPE) + return adj_float_param(active_menu->locked_item->menu_entry->param_adj.param, BIG_DEC); + } + + /* Force to bottom of menu */ + while((new_menu_item = active_menu->selected_item->down) != NULL) + active_menu->selected_item = new_menu_item; + return PROJECTM_SUCCESS; + + case UP: + if(active_menu->locked_item != NULL) { + if (active_menu->locked_item->menu_entry_type == PARAM_ADJ_TYPE) + return adj_float_param(active_menu->locked_item->menu_entry->param_adj.param, SMALL_INC); + } + + /* Is this the first item of the menu ? */ + if ((new_menu_item = active_menu->selected_item->up) == NULL) + return PROJECTM_SUCCESS; + active_menu->selected_item = new_menu_item; + return PROJECTM_SUCCESS; + case DOWN: + if(active_menu->locked_item != NULL) { + if (active_menu->locked_item->menu_entry_type == PARAM_ADJ_TYPE) + return adj_float_param(active_menu->locked_item->menu_entry->param_adj.param, SMALL_DEC); + } + + /* Is this the last item of the menu ? */ + if ((new_menu_item = active_menu->selected_item->down) == NULL) + return PROJECTM_SUCCESS; + active_menu->selected_item = new_menu_item; + return PROJECTM_SUCCESS; + case LEFT: + /* Left key unlocks the highlighted item */ + if (active_menu->locked_item != NULL) { + /* The left arrow cancels the initial condition adjustment */ + if (active_menu->locked_item->menu_entry_type == PARAM_ADJ_TYPE) { + //active_menu->locked_item->menu_entry->param_adj.param->init_val = saved_init_val; + } + active_menu->locked_item = NULL; + return PROJECTM_SUCCESS; + } + /* Otherwise go up a menu if it isn't the top menu */ + if (active_menu->top_menu == NULL) + return PROJECTM_SUCCESS; + active_menu = active_menu->top_menu; + return PROJECTM_SUCCESS; + case RIGHT: + switch (active_menu->selected_item->menu_entry_type) { + case MENU_LINK_TYPE: + return pursue_menu_link(&active_menu->selected_item->menu_entry->menu_link); + case PARAM_ADJ_TYPE: + param_adj = active_menu->selected_item->menu_entry->param_adj; + + + + if (active_menu->locked_item == NULL) { + + if ((init_cond = projectM::activePreset->get_init_cond(param_adj.param)) == NULL) + return PROJECTM_FAILURE; + + + /* Save previous initial condition value */ + //saved_init_val = init_cond->init_val; + + /* If a bool parameter, just switch its value and quit */ + if (param_adj.param->type == P_TYPE_BOOL) { + init_cond->init_val.bool_val = !init_cond->init_val.bool_val; + return PROJECTM_SUCCESS; + } + + /* Otherwise, lock this parameter so the user can adjust it */ + active_menu->locked_item = active_menu->selected_item; + + } + + /* Unlock the item, but keep the changed initial value intact */ + else { + active_menu->locked_item = NULL; + } + + break; + case FUNCTION_MODE_TYPE: + return active_menu->selected_item->menu_entry->function_mode.func_ptr(); + default: + return PROJECTM_FAILURE; + } + default: + return PROJECTM_FAILURE; +} + +return PROJECTM_SUCCESS; +} + +/* Creates a new menu */ +menu_t * new_menu(menu_t * top_menu) { + + menu_t * menu; + + if ((menu = (menu_t*)wipemalloc(sizeof(menu_t))) == NULL) + return NULL; + + menu->top_menu = top_menu; + menu->start_item = menu->selected_item = NULL; + menu->locked_item = NULL; + return menu; +} + +/* Frees a menu */ +int free_menu(menu_t * menu) { + menu_item_t * menu_item, * backup; + + if (menu == NULL) + return PROJECTM_SUCCESS; + + menu_item = menu->start_item; + + /* Now we free every entry in this menu */ + while (menu_item) { + backup = menu_item->down; + + /* If a menu link, free the sub menu it points to */ + if (menu_item->menu_entry_type == MENU_LINK_TYPE) { + free_menu(menu_item->menu_entry->menu_link.sub_menu); + } + + /* Now free the menu item */ + free_menu_item(menu_item); + + /* Set menu item to the next item in the list */ + menu_item = backup; + } + + /* Finally, we free the menu struct itself */ + free(menu); + menu = NULL; + + /* Finished, return success */ + return PROJECTM_SUCCESS; +} + +/* Creates a new menu link type */ +menu_entry_t * new_menu_link(char * print_string, menu_t * menu_ptr) { + + menu_entry_t * menu_entry; + menu_link_t menu_link; + + /* Argument Checks */ + if (print_string == NULL) + return NULL; + if (menu_ptr == NULL) + return NULL; + + + /* Allocate memory for the menu entry */ + if ((menu_entry = (menu_entry_t*)wipemalloc(sizeof(menu_entry_t))) == NULL) + return NULL; + + + /* Copy the string parameter */ + memset(menu_link.print_string, 0, MAX_TOKEN_SIZE); + strncpy(menu_link.print_string, print_string, MAX_TOKEN_SIZE); + + menu_link.sub_menu = menu_ptr; + + menu_entry->menu_link = menu_link; + + return menu_entry; +} + + +/* Creates a new parameter adjustment entry */ +menu_entry_t * new_param_adj(char * print_string, Param * param) { + + menu_entry_t * menu_entry; + param_adj_t param_adj; + + /* Argument Checks */ + if (print_string == NULL) + return NULL; + + if (param == NULL) { + if (MENU_DEBUG) printf("new_param_adj: passed a null parameter!\n"); + return NULL; + } + + /* Allocate memory for the menu entry */ + if ((menu_entry = (menu_entry_t*)wipemalloc(sizeof(menu_entry_t))) == NULL) + return NULL; + + /* Copy the string parameter */ + memset(param_adj.print_string, 0, MAX_TOKEN_SIZE); + strncpy(param_adj.print_string, print_string, MAX_TOKEN_SIZE); + + param_adj.param = param; + menu_entry->param_adj = param_adj; + + return menu_entry; +} + +/* Appends a menu item */ +int append_menu_item(menu_t * menu, menu_item_t * new_menu_item) { + + menu_item_t * menu_item; + + /* Argument checks */ + if (menu == NULL) + return PROJECTM_FAILURE; + + if (new_menu_item == NULL) + return PROJECTM_FAILURE; + + + /* Menu is empty, insert here */ + if (menu->start_item == NULL) { + menu->start_item = new_menu_item; + new_menu_item->up = NULL; + return PROJECTM_SUCCESS; + } + + menu_item = menu->start_item; + + /* Traverse down the menu */ + while (menu_item->down) { + menu_item = menu_item->down; + } + + /* Insert the item at the end */ + menu_item->down = new_menu_item; + new_menu_item->up = menu_item; + + return PROJECTM_SUCCESS; + +} + +/* Creates a new menu item, up and down entries are null by default */ +menu_item_t * new_menu_item(int menu_entry_type, menu_entry_t * menu_entry) { + + menu_item_t * menu_item; + + /* Argument check */ + if (menu_entry == NULL) + return NULL; + + /* Out of memory check */ + if ((menu_item = (menu_item_t*)wipemalloc(sizeof(menu_item_t))) == NULL) { + return NULL; + } + + menu_item->menu_entry_type = menu_entry_type; + menu_item->menu_entry = menu_entry; + menu_item->up = NULL; + menu_item->down = NULL; + + return menu_item; +} + +/* Frees a menu item */ +int free_menu_item(menu_item_t * menu_item) { + + if (menu_item == NULL) + return PROJECTM_OK; + + free(menu_item->menu_entry); + free(menu_item); + + menu_item = NULL; + + return PROJECTM_SUCCESS; +} + + +/* Creates a new editor mode */ +menu_entry_t * new_function_mode(char * print_string, int (*func_ptr)()) { + + menu_entry_t * menu_entry; + function_mode_t function_mode; + + /* Argument Checks */ + if (print_string == NULL) + return NULL; + + /* Allocate memory for the menu entry */ + if ((menu_entry = (menu_entry_t*)wipemalloc(sizeof(menu_entry_t))) == NULL) + return NULL; + + + /* Copy the string parameter */ + memset(function_mode.print_string, 0, MAX_TOKEN_SIZE); + strncpy(function_mode.print_string, print_string, MAX_TOKEN_SIZE); + + function_mode.func_ptr = func_ptr; + menu_entry->function_mode = function_mode; + + return menu_entry; +} + + +/* Pursues a link in a menu */ +int pursue_menu_link(menu_link_t * menu_link) { + + if (menu_link == NULL) + return PROJECTM_FAILURE; + + active_menu = menu_link->sub_menu; + + return PROJECTM_SUCCESS; +} + + +int edit_per_pixel_eqn() { + hideMenu(); + current_interface = EDITOR_INTERFACE; +// loadEditor(activePreset->per_pixel_eqn_string_buffer,(void (*)()) reloadPerPixel, 80, 24, 140, 60, 0, 0); + return PROJECTM_SUCCESS; +} + +int edit_per_frame_eqn() { + hideMenu(); + current_interface = EDITOR_INTERFACE; +// loadEditor(activePreset->per_frame_eqn_string_buffer, (void (*)())reloadPerFrame,80,24,140,60,0,0); + return PROJECTM_SUCCESS; +} + +int edit_per_frame_init() { + hideMenu(); + current_interface = EDITOR_INTERFACE; +// loadEditor(activePreset->per_frame_init_eqn_string_buffer,(void (*)()) reloadPerFrameInit,80,24,140,60,0,0); + return PROJECTM_SUCCESS; +} + + +int run_bash_shell() { + + printf("setting menu state to special\n"); + menu_display_state = SPECIAL; + // glConsoleStartShell(menu_console); + + //menu_display_state = SHOW; + + return PROJECTM_SUCCESS; +} + + + +/* Adjust a float parameter */ +int adj_float_param(Param * param, adj_t adj) { + + float inc_val; + InitCond * init_cond = NULL; + + if (param == NULL) + return PROJECTM_FAILURE; + + if (param->type == P_TYPE_INT) + return (adj_int_param(param, adj)); + + if ((init_cond = (InitCond*)projectM::activePreset->init_cond_tree->splay_find(param->name)) == NULL) + return PROJECTM_FAILURE; + + switch (adj) { + + case VERY_SMALL_INC: + inc_val = .001; + break; + case SMALL_INC: + inc_val = .01; + break; + case BIG_INC: + inc_val = .1; + break; + case VERY_BIG_INC: + inc_val = 1.0; + break; + case VERY_SMALL_DEC: + inc_val = -.001; + break; + case SMALL_DEC: + inc_val = -.01; + break; + case BIG_DEC: + inc_val = -0.1; + break; + case VERY_BIG_DEC: + inc_val = -1.0; + break; + + default: + return PROJECTM_FAILURE; + } + + /* Beyond upper bounds, normalize to maximum value */ + if ((init_cond->init_val.float_val + inc_val) > param->upper_bound.float_val) + init_cond->init_val.float_val = param->upper_bound.float_val; + + else if ((init_cond->init_val.float_val + inc_val) < param->lower_bound.float_val) + init_cond->init_val.float_val = param->lower_bound.float_val; + + else + init_cond->init_val.float_val += inc_val; + + return PROJECTM_SUCCESS; +} + +/* Adjust an integer parameter */ +int adj_int_param(Param * param, adj_t adj) { + + int inc_val; + InitCond * init_cond = NULL; + + if (param == NULL) + return PROJECTM_FAILURE; + + if ((init_cond = (InitCond*)activePreset->init_cond_tree->splay_find(param->name)) == NULL) + return PROJECTM_FAILURE; + + switch (adj) { + + + case VERY_SMALL_INC: + inc_val = 1; + break; + case SMALL_INC: + inc_val = 1; + break; + case BIG_INC: + inc_val = 1; + break; + case VERY_BIG_INC: + inc_val = 5; + break; + + case VERY_SMALL_DEC: + inc_val = -1; + break; + case SMALL_DEC: + inc_val = -1; + break; + case BIG_DEC: + inc_val = -1; + break; + case VERY_BIG_DEC: + inc_val = -5; + break; + + default: + return PROJECTM_FAILURE; + } + + /* Beyond upper bounds, normalize to maximum value */ + if ((init_cond->init_val.int_val + inc_val) > param->upper_bound.int_val) + init_cond->init_val.int_val = param->upper_bound.int_val; + + /* Below lower bounds, normalize to lowest value */ + else if ((init_cond->init_val.int_val + inc_val) < param->lower_bound.int_val) + init_cond->init_val.int_val = param->lower_bound.int_val; + + else + init_cond->init_val.int_val += inc_val; + + return PROJECTM_SUCCESS; +} + +void menu_key_handler( projectMEvent event, projectMKeycode key ) { + + switch( event ) { + case PROJECTM_KEYDOWN: + switch(key) + { + case PROJECTM_K_f: + + if (projectM::currentEngine->fullscreen==1) + {projectM::currentEngine->renderer->reset(projectM::currentEngine->wvw,projectM::currentEngine->wvh); +projectM::currentEngine->fullscreen=0;} + else{projectM::currentEngine->renderer->reset(projectM::currentEngine->fvw,projectM::currentEngine->fvh); +projectM::currentEngine->fullscreen=1; +} + +// init_display(projectM::currentEngine->vw,projectM::currentEngine->vh,projectM::currentEngine->fullscreen); + + + break; + case PROJECTM_K_n: + //projectM::currentEngine->switchPreset(ALPHA_NEXT, HARD_CUT); + break; + case PROJECTM_K_r: + //projectM::currentEngine->switchPreset(RANDOM_NEXT, HARD_CUT); + break; + case PROJECTM_K_p: + //projectM::currentEngine->switchPreset(ALPHA_PREVIOUS, HARD_CUT); + break; + case PROJECTM_K_a: + break; + case PROJECTM_K_z: + break; + case PROJECTM_K_0: + //nWaveMode=0; + break; + case PROJECTM_K_6: + //nWaveMode=6; + break; + case PROJECTM_K_7: + //nWaveMode=7; + break; + case PROJECTM_K_UP: + switchMenuState(UP); + break; + case PROJECTM_K_RETURN: + case PROJECTM_K_RIGHT: + switchMenuState(RIGHT); + break; + case PROJECTM_K_LEFT: + switchMenuState(LEFT); + break; + case PROJECTM_K_DOWN: + switchMenuState(DOWN); + break; + case PROJECTM_K_PAGEUP: + switchMenuState(PAGEUP); + break; + case PROJECTM_K_PAGEDOWN: + switchMenuState(PAGEDOWN); + break; + case PROJECTM_K_ESCAPE: + case PROJECTM_K_m: + hideMenu(); + current_interface = DEFAULT_INTERFACE; + break; + case PROJECTM_K_t: + break; + default: + break; + } + } + + + + +} +#endif diff --git a/src/projectM-engine-backup/menu.h b/src/projectM-engine-backup/menu.h new file mode 100755 index 000000000..22f020e69 --- /dev/null +++ b/src/projectM-engine-backup/menu.h @@ -0,0 +1,118 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id$ + * + * + * + * $Log$ + */ + +#ifndef _MENU_H +#define _MENU_H + +#include "event.h" +#include "Common.hpp" +#include "Param.hpp" + +#define MENU_DEBUG 0 + +#define PARAM_ADJ_TYPE 0 +#define MENU_LINK_TYPE 1 +#define FUNCTION_MODE_TYPE 2 + +typedef struct MENU_LINK_T { + char print_string[MAX_TOKEN_SIZE]; + struct MENU_T * sub_menu; +} menu_link_t; + +typedef struct PARAM_ADJ_T { + char print_string[MAX_TOKEN_SIZE]; + Param * param; +} param_adj_t; + +typedef struct FUNCTION_MODE_T { + char print_string[MAX_TOKEN_SIZE]; + int (*func_ptr)(); +} function_mode_t; + +typedef union MENU_ENTRY_T { + menu_link_t menu_link; + param_adj_t param_adj; + function_mode_t function_mode; +} menu_entry_t; + + +typedef struct MENU_ITEM_T { + int menu_entry_type; + menu_entry_t * menu_entry; + struct MENU_ITEM_T * up; + struct MENU_ITEM_T * down; +} menu_item_t; + + +typedef struct MENU_T { + menu_item_t * selected_item; + menu_item_t * start_item; + menu_item_t * locked_item; + struct MENU_T * top_menu; +} menu_t; + +/* Direction types */ +typedef enum { + UP, + DOWN, + LEFT, + RIGHT, + PAGEUP, + PAGEDOWN +} dir_t; + +/* Adjustment types */ +typedef enum { + BIG_INC, + BIG_DEC, + SMALL_INC, + SMALL_DEC, + VERY_BIG_INC, + VERY_BIG_DEC, + VERY_SMALL_INC, + VERY_SMALL_DEC +} adj_t; + +typedef enum { + SHOW, + HIDE, + SPECIAL +} display_state; + + + +int switchMenuState(dir_t dir); + +int initMenu(); +int refreshMenu(); +int clearMenu(); +int showMenu(); +int hideMenu(); +void menu_key_handler( projectM *PM, projectMEvent event, projectMKeycode key ); + +#endif /** !_MENU_H */ diff --git a/src/projectM-engine-backup/presets b/src/projectM-engine-backup/presets new file mode 120000 index 000000000..840871fb9 --- /dev/null +++ b/src/projectM-engine-backup/presets @@ -0,0 +1 @@ +../../presets \ No newline at end of file diff --git a/src/projectM-engine-backup/projectM.cpp b/src/projectM-engine-backup/projectM.cpp new file mode 100755 index 000000000..ef74c2a15 --- /dev/null +++ b/src/projectM-engine-backup/projectM.cpp @@ -0,0 +1,705 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +#include "wipemalloc.h" +#include "BuiltinFuncs.hpp" +#include "fatal.h" +#include "Common.hpp" +#include "compare.h" +#ifdef WIN32 +#include "win32-dirent.h" +#endif + +#include "timer.h" +#include +#ifdef LINUX +#include "time.h" +#endif + +//#include +#include "projectM.hpp" +#include "BeatDetect.hpp" +#include "Eval.hpp" +#include "Param.hpp" +#include "Parser.hpp" +#include "Preset.hpp" +#include "PerPixelEqn.hpp" +//#include "menu.h" +#include "PCM.hpp" //Sound data handler (buffering, FFT, etc.) +#include "CustomWave.hpp" +#include "CustomShape.hpp" +#include +#include "Renderer.hpp" +#include "PresetChooser.hpp" + +#ifdef LINUX +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/"); +#endif + + +#ifdef WIN32 +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. */ +/// @bug These probably shouldn't be static! +RenderTarget * projectM::renderTarget = NULL; +Renderer * projectM::renderer = NULL; + + +DLLEXPORT projectM::projectM() { + beatDetect = NULL; +} + + +DLLEXPORT void projectM::renderFrame() { + +#ifdef DEBUG + 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 + + +#ifndef WIN32 + presetInputs.time = getTicks( &startTime ) * 0.001; +#else + 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; + +// 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(); + + +// 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 ); + + 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; + } + } + + count++; + + 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); + } + + 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); +#endif /** !WIN32 */ + + DWRITE( "exiting renderFrame()\n" ); +} + +DLLEXPORT void projectM::projectM_reset() { + + DWRITE( "projectM_reset(): in\n" ); + + /// @bug it's very possible this is a hack + m_activePreset = std::auto_ptr(0); + + this->presetURL = NULL; + this->fontURL = NULL; + + /** 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; + + /** Frames per preset */ + this->avgtime = 500; + + + + /** More other stuff */ + this->mspf = 0; + this->timed = 0; + this->timestart = 0; + this->nohard = 0; + this->count = 0; + + this->fpsstart = 0; + + projectM_resetengine(); +} + +DLLEXPORT void projectM::projectM_init(int gx, int gy, int fps, int texsize, int width, int height) { + + + + /** Initialise engine variables */ + + + projectM_initengine(); + presetInputs.Initialize(gx, gy); + presetOutputs.Initialize(gx, gy); + + DWRITE("projectM plugin: Initializing\n"); + + /** Initialise start time */ +#ifndef WIN32 + gettimeofday(&this->startTime, NULL); +#else + startTime = GetTickCount(); +#endif /** !WIN32 */ + + /** Nullify frame stash */ + fbuffer = NULL; + + /** Initialise per-pixel matrix calculations */ + + + presetInputs.fps = fps; + + /** 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(); + + /* 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" ); + } + + 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 ); + + /** Stash the short preset name */ + + } 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; + } + } + + /** 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'; +// loadPresetDir( "../../presets/" ); +// loadPresetDir( "/Users/descarte/tmp/projectM-1.00/presets_projectM" ); + } 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 ); +#ifdef WIN32 + strcpy( this->fontURL, "c:\\tmp\\projectM\\fonts" ); + fontURL[24] = '\0'; +#else + strcpy( this->fontURL, "/Users/descarte/tmp/projectM/fonts" ); + fontURL[34] = '\0'; +#endif + DWRITE( "loading font URL directly: %s\n", this->fontURL ); +#ifdef WIN32 + // loadPresetDir( "c:\\tmp\\projectM\\presets_projectM" ); +#else + // loadPresetDir( "/Users/descarte/tmp/projectM-1.00/presets_projectM" ); +#endif + } else { + printf( "PresetDir: %s\n", this->presetURL ); + //loadPresetDir( presetURL ); + } + +#endif + + + mspf=(int)(1000.0/(float)presetInputs.fps); + + +// initMenu(); +//DWRITE( "post initMenu()\n" ); + + printf("mesh: %d %d\n", gx,gy ); + +#ifdef PANTS + printf( "maxsamples: %d\n", this->maxsamples ); + initPCM(this->maxsamples); + DWRITE( "post PCM init\n" ); +#endif + + this->avgtime=this->presetInputs.fps*20; + + this->hasInit = 1; + + 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); + + printf( "exiting projectM_init()\n" ); +} + + + + +//calculate matrices for per_pixel + + + + +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; + + 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.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.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->presetInputs.meshx = 0; +//this->presetInputs.meshy = 0; + + + this->presetInputs.progress = 0; + this->presetInputs.frame = 0; + + 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; + + 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; + + + /* 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 */ + + + /* 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; + + + /* 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.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; +*/ + +//custom wave per point meshes +} + +/* Reinitializes the engine variables to a default (conservative and sane) value */ +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.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.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.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; + + + 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; + + 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; + + + /* 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 */ + + + /* 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; + + + /* Q VARIABLES END */ + + /** Stash the current engine */ + currentEngine = this; +} + +/** Resets OpenGL state */ +DLLEXPORT void projectM::projectM_resetGL( int w, int h ) { + + + int mindim, origtexsize; + + DWRITE( "projectM_resetGL(): in: %d x %d\n", w, h ); + + /** Stash the new dimensions */ + + + + 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 ); + + } + */ +} + + +int projectM::initPresetTools() { + + /* Initializes the builtin function database */ + BuiltinFuncs::init_builtin_func_db(); + + /* Initializes all infix operators */ + Eval::init_infix_ops(); + + /* Set the seed to the current time in seconds */ +#ifdef WIN32 + 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_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 + printf("initPresetLoader: finished\n"); +#endif + return PROJECTM_SUCCESS; +} + +void projectM::destroyPresetTools() { + + if (m_presetChooser) + delete(m_presetChooser); + + if (m_presetLoader) + delete(m_presetLoader); + + Eval::destroy_infix_ops(); + BuiltinFuncs::destroy_builtin_func_db(); + +} diff --git a/src/projectM-engine-backup/projectM.dsp b/src/projectM-engine-backup/projectM.dsp new file mode 100755 index 000000000..06efa3d37 --- /dev/null +++ b/src/projectM-engine-backup/projectM.dsp @@ -0,0 +1,381 @@ +# Microsoft Developer Studio Project File - Name="projectM" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=projectM - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "projectM.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "projectM.mak" CFG="projectM - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "projectM - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "projectM - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "projectM - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "projectM - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "projectM - Win32 Release" +# Name "projectM - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\beat_detect.c +# End Source File +# Begin Source File + +SOURCE=.\browser.c +# End Source File +# Begin Source File + +SOURCE=.\builtin_funcs.c +# End Source File +# Begin Source File + +SOURCE=.\console_interface.c +# End Source File +# Begin Source File + +SOURCE=.\custom_shape.c +# End Source File +# Begin Source File + +SOURCE=.\custom_wave.c +# End Source File +# Begin Source File + +SOURCE=.\editor.c +# End Source File +# Begin Source File + +SOURCE=.\eval.c +# End Source File +# Begin Source File + +SOURCE=.\fftsg.c +# End Source File +# Begin Source File + +SOURCE=.\func.c +# End Source File +# Begin Source File + +SOURCE=.\glConsole.c +# End Source File +# Begin Source File + +SOURCE=.\glf.c +# End Source File +# Begin Source File + +SOURCE=.\init_cond.c +# End Source File +# Begin Source File + +SOURCE=.\menu.c +# End Source File +# Begin Source File + +SOURCE=.\param.c +# End Source File +# Begin Source File + +SOURCE=.\parser.c +# End Source File +# Begin Source File + +SOURCE=.\PCM.c +# End Source File +# Begin Source File + +SOURCE=.\per_frame_eqn.c +# End Source File +# Begin Source File + +SOURCE=.\per_pixel_eqn.c +# End Source File +# Begin Source File + +SOURCE=.\preset.c +# End Source File +# Begin Source File + +SOURCE=.\projectm.c +# End Source File +# Begin Source File + +SOURCE=.\pbuffer.c +# End Source File +# Begin Source File + +SOURCE=.\splaytree.c +# End Source File +# Begin Source File + +SOURCE=.\timer.c +# End Source File +# Begin Source File + +SOURCE=.\tree_types.c +# End Source File +# Begin Source File + +SOURCE=".\win32-dirent.c" +# End Source File +# Begin Source File + +SOURCE=.\wipemalloc.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\beat_detect.h +# End Source File +# Begin Source File + +SOURCE=.\browser.h +# End Source File +# Begin Source File + +SOURCE=.\builtin_funcs.h +# End Source File +# Begin Source File + +SOURCE=.\common.h +# End Source File +# Begin Source File + +SOURCE=.\compare.h +# End Source File +# Begin Source File + +SOURCE=.\config.h +# End Source File +# Begin Source File + +SOURCE=.\console_interface.h +# End Source File +# Begin Source File + +SOURCE=.\custom_shape.h +# End Source File +# Begin Source File + +SOURCE=.\custom_shape_types.h +# End Source File +# Begin Source File + +SOURCE=.\custom_wave.h +# End Source File +# Begin Source File + +SOURCE=.\custom_wave_types.h +# End Source File +# Begin Source File + +SOURCE=.\editor.h +# End Source File +# Begin Source File + +SOURCE=.\eval.h +# End Source File +# Begin Source File + +SOURCE=.\event.h +# End Source File +# Begin Source File + +SOURCE=.\expr_types.h +# End Source File +# Begin Source File + +SOURCE=.\fatal.h +# End Source File +# Begin Source File + +SOURCE=.\fftsg.h +# End Source File +# Begin Source File + +SOURCE=.\func.h +# End Source File +# Begin Source File + +SOURCE=.\func_types.h +# End Source File +# Begin Source File + +SOURCE=.\glConsole.h +# End Source File +# Begin Source File + +SOURCE=.\glf.h +# End Source File +# Begin Source File + +SOURCE=.\idle_preset.h +# End Source File +# Begin Source File + +SOURCE=.\init_cond.h +# End Source File +# Begin Source File + +SOURCE=.\init_cond_types.h +# End Source File +# Begin Source File + +SOURCE=.\interface_types.h +# End Source File +# Begin Source File + +SOURCE=.\menu.h +# End Source File +# Begin Source File + +SOURCE=.\param.h +# End Source File +# Begin Source File + +SOURCE=.\param_types.h +# End Source File +# Begin Source File + +SOURCE=.\parser.h +# End Source File +# Begin Source File + +SOURCE=.\PCM.h +# End Source File +# Begin Source File + +SOURCE=.\per_frame_eqn.h +# End Source File +# Begin Source File + +SOURCE=.\per_frame_eqn_types.h +# End Source File +# Begin Source File + +SOURCE=.\per_pixel_eqn.h +# End Source File +# Begin Source File + +SOURCE=.\per_pixel_eqn_types.h +# End Source File +# Begin Source File + +SOURCE=.\per_point_types.h +# End Source File +# Begin Source File + +SOURCE=.\preset.h +# End Source File +# Begin Source File + +SOURCE=.\preset_types.h +# End Source File +# Begin Source File + +SOURCE=.\projectM.h +# End Source File +# Begin Source File + +SOURCE=.\pbuffer.h +# End Source File +# Begin Source File + +SOURCE=.\splaytree.h +# End Source File +# Begin Source File + +SOURCE=.\splaytree_types.h +# End Source File +# Begin Source File + +SOURCE=.\timer.h +# End Source File +# Begin Source File + +SOURCE=.\tree_types.h +# End Source File +# Begin Source File + +SOURCE=".\win32-dirent.h" +# End Source File +# Begin Source File + +SOURCE=.\wipemalloc.h +# End Source File +# End Group +# End Target +# End Project diff --git a/src/projectM-engine-backup/projectM.hpp b/src/projectM-engine-backup/projectM.hpp new file mode 100755 index 000000000..843674dfc --- /dev/null +++ b/src/projectM-engine-backup/projectM.hpp @@ -0,0 +1,242 @@ +/* + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: projectM.hpp,v 1.1.1.1 2005/12/23 18:05:11 psperl Exp $ + * + * Encapsulation of ProjectM engine + * + * $Log$ + */ + +#ifndef _PROJECTM_H +#define _PROJECTM_H + +#include "PBuffer.hpp" + +#ifdef WIN32 +#include "win32-dirent.h" +#else +#include +#endif /** WIN32 */ +#include +#include +#include +#include +#ifndef WIN32 +#include +#endif +#include + +#ifdef MACOS +#include +#include +#include +#else +#ifdef WIN32 +#include +#endif /** WIN32 */ +#include +#include +#endif /** MACOS */ +#ifdef WIN322 +#define inline +#endif /** WIN32 */ +#ifndef WIN32 +#include +#else +#endif /** !WIN32 */ + +#include "dlldefs.h" +#include "event.h" +#include "fatal.h" +#include "PresetFrameIO.hpp" +#include "Renderer.hpp" +//#include "PresetChooser.hpp" + +#include + +class BeatDetect; +class Func; +class Renderer; +class Preset; +class PresetIterator; +class PresetChooser; +class PresetLoader; + +#include +#ifdef WIN32 +#pragma warning (disable:4244) +#pragma warning (disable:4305) +#endif /** WIN32 */ + +#ifdef MACOS2 +#define inline +#endif + +/** KEEP THIS UP TO DATE! */ +#define PROJECTM_VERSION "1.02.00" +#define PROJECTM_TITLE "projectM 1.02.00" + +/** Per-platform path separators */ +#define WIN32_PATH_SEPARATOR '\\' +#define UNIX_PATH_SEPARATOR '/' +#ifdef WIN32 +#define PATH_SEPARATOR WIN32_PATH_SEPARATOR +#else +#define PATH_SEPARATOR UNIX_PATH_SEPARATOR +#endif /** WIN32 */ + +/** Thread state */ +typedef enum { GO, STOP } PMThreadState; + +/** Interface types */ +typedef enum { + MENU_INTERFACE, + SHELL_INTERFACE, + EDITOR_INTERFACE, + DEFAULT_INTERFACE, + BROWSER_INTERFACE + } interface_t; + + +class projectM { +public: + static const std::string PROJECTM_PRESET_PATH; + + static projectM *currentEngine; + static Renderer *renderer; + static RenderTarget *renderTarget; + + char *presetURL; + + char *fontURL; + + int hasInit; + + int pcmframes; + int freqframes; + + + GLubyte *fbuffer; + +#ifndef WIN32 + /* The first ticks value of the application */ + struct timeval startTime; +#else + long startTime; +#endif /** !WIN32 */ + + /** Render target texture ID */ + + char disp[80]; + + float wave_o; + + //int texsize=1024; //size of texture to do actual graphics + int fvw; //fullscreen dimensions + int fvh; + int wvw; //windowed dimensions + int wvh; + + int fullscreen; + + int avgtime; //# frames per preset + + /** Timing information */ + int mspf; + int timed; + int timestart; + int nohard; + int count; + float fpsstart; + + /** Various toggles */ + /* PER_FRAME CONSTANTS END */ + + /** Beat detection engine */ + 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(); + + DLLEXPORT void projectM_init(int gx, int gy, int fps, int texsize, int width, int height); + DLLEXPORT void projectM_reset(); + DLLEXPORT void projectM_resetGL( int width, int height ); + DLLEXPORT void projectM_setTitle( char *title ); + DLLEXPORT void renderFrame(); + + DLLEXPORT void projectM_initengine(); + DLLEXPORT void projectM_resetengine(); + void draw_help(); + void draw_fps(float fps); + void draw_preset(); + void draw_title(); + void draw_stats(); + + void do_per_pixel_math(); + void do_per_frame(); + + void render_interpolation(); + void render_texture_to_screen(); + void render_texture_to_studio(); + + void get_title(); + + void reset_per_pixel_matrices(); + void init_per_pixel_matrices(); + void rescale_per_pixel_matrices(); + void free_per_pixel_matrices(); + + void key_handler( projectMEvent event, + projectMKeycode keycode, projectMModifier modifier ); + void default_key_handler( projectMEvent event, projectMKeycode keycode ); + + /// Initializes preset loading / management libraries + int initPresetTools(); + + /// Deinitialize all preset related tools. Usually done before projectM cleanup + void destroyPresetTools(); + + private: + + // The current position of the directory iterator + PresetIterator * m_presetPos; + + // Required by the preset chooser. Manages a loaded preset directory + PresetLoader * m_presetLoader; + + // Provides accessor functions to choose presets + PresetChooser * m_presetChooser; + + // Currently loaded preset- will be fancier when smooth preset switching + std::auto_ptr m_activePreset; + }; + +#endif /** !_PROJECTM_H */ diff --git a/src/projectM-engine-backup/sdltoprojectM.h b/src/projectM-engine-backup/sdltoprojectM.h new file mode 100755 index 000000000..d2a974db0 --- /dev/null +++ b/src/projectM-engine-backup/sdltoprojectM.h @@ -0,0 +1,165 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: sdltoprojectM.hpp,v 1.1 2004/10/08 00:35:28 cvs Exp $ + * + * Translates SDL -> projectM variables + * + * $Log: sdltoprojectM.hpp,v $ + * Revision 1.1 2004/10/08 00:35:28 cvs + * Moved and imported + * + * Revision 1.1.1.1 2004/10/04 12:56:00 cvs + * Imported + * + */ + +#ifndef _SDLTOPROJECTM_H +#define _SDLTOPROJECTM_H + +#include "event.h" + + //#include "projectM/projectM.hpp" +#ifdef WIN32 +#include +#else +#include +#endif + +inline projectMEvent sdl2pmEvent( SDL_Event event ) { \ + + switch ( event.type ) { \ + case SDL_VIDEORESIZE: + return PROJECTM_VIDEORESIZE; \ + case SDL_KEYUP: \ + return PROJECTM_KEYUP; \ + case SDL_KEYDOWN: \ + return PROJECTM_KEYDOWN; \ + default: + return PROJECTM_KEYUP; \ + } \ + } \ + +inline projectMKeycode sdl2pmKeycode( SDLKey keysym ) { \ + switch ( keysym ) { \ + case SDLK_F1: \ + return PROJECTM_K_F1; \ + case SDLK_F2: \ + return PROJECTM_K_F2; \ + case SDLK_F3: \ + return PROJECTM_K_F3; \ + case SDLK_F4: \ + return PROJECTM_K_F4; \ + case SDLK_F5: \ + return PROJECTM_K_F5; \ + case SDLK_F6: \ + return PROJECTM_K_F6; \ + case SDLK_F7: \ + return PROJECTM_K_F7; \ + case SDLK_F8: \ + return PROJECTM_K_F8; \ + case SDLK_F9: \ + return PROJECTM_K_F9; \ + case SDLK_F10: \ + return PROJECTM_K_F10; \ + case SDLK_F11: \ + return PROJECTM_K_F11; \ + case SDLK_F12: \ + return PROJECTM_K_F12; \ + case SDLK_ESCAPE: \ + return PROJECTM_K_ESCAPE; + case SDLK_a: + return PROJECTM_K_a; + case SDLK_b: + return PROJECTM_K_b; + case SDLK_c: + return PROJECTM_K_c; + case SDLK_d: + return PROJECTM_K_d; + case SDLK_e: + return PROJECTM_K_e; + case SDLK_f: + return PROJECTM_K_f; + case SDLK_g: + return PROJECTM_K_g; + case SDLK_h: + return PROJECTM_K_h; + case SDLK_i: + return PROJECTM_K_i; + case SDLK_j: + return PROJECTM_K_j; + case SDLK_k: + return PROJECTM_K_k; + case SDLK_l: + return PROJECTM_K_l; + case SDLK_m: + return PROJECTM_K_m; + case SDLK_n: + return PROJECTM_K_n; + case SDLK_o: + return PROJECTM_K_o; + case SDLK_p: + return PROJECTM_K_p; + case SDLK_q: + return PROJECTM_K_q; + case SDLK_r: + return PROJECTM_K_r; + case SDLK_s: + return PROJECTM_K_s; + case SDLK_t: + return PROJECTM_K_t; + case SDLK_u: + return PROJECTM_K_u; + case SDLK_v: + return PROJECTM_K_v; + case SDLK_w: + return PROJECTM_K_w; + case SDLK_x: + return PROJECTM_K_x; + case SDLK_y: + return PROJECTM_K_y; + case SDLK_z: + return PROJECTM_K_z; + case SDLK_UP: + return PROJECTM_K_UP; + case SDLK_RETURN: + return PROJECTM_K_RETURN; + case SDLK_RIGHT: + return PROJECTM_K_RIGHT; + case SDLK_LEFT: + return PROJECTM_K_LEFT; + case SDLK_DOWN: + return PROJECTM_K_DOWN; + case SDLK_PAGEUP: + return PROJECTM_K_PAGEUP; + case SDLK_PAGEDOWN: + return PROJECTM_K_PAGEDOWN; + + default: \ + return PROJECTM_K_NONE; \ + } \ + } \ + +inline projectMModifier sdl2pmModifier( SDLMod mod ) { \ + return PROJECTM_KMOD_LSHIFT; \ + } \ + +#endif /** _SDLTOPROJECTM_H */ diff --git a/src/projectM-engine-backup/timer.cpp b/src/projectM-engine-backup/timer.cpp new file mode 100755 index 000000000..e9e1dafc7 --- /dev/null +++ b/src/projectM-engine-backup/timer.cpp @@ -0,0 +1,44 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: timer.c,v 1.1.1.1 2005/12/23 18:05:05 psperl Exp $ + * + * Platform-independent timer + */ + +#include "timer.h" +#include + +#ifndef WIN32 +/** Get number of ticks since the given timestamp */ +unsigned int getTicks( struct timeval *start ) { + struct timeval now; + unsigned int ticks; + + gettimeofday(&now, NULL); + ticks=(now.tv_sec-start->tv_sec)*1000+(now.tv_usec-start->tv_usec)/1000; + return(ticks); + } +#else +unsigned int getTicks( long start ) { + return GetTickCount() - start; + } +#endif /** !WIN32 */ diff --git a/src/projectM-engine-backup/timer.h b/src/projectM-engine-backup/timer.h new file mode 100755 index 000000000..2c797593f --- /dev/null +++ b/src/projectM-engine-backup/timer.h @@ -0,0 +1,49 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: timer.h,v 1.1.1.1 2005/12/23 18:05:00 psperl Exp $ + * + * Platform-independent timer + * + * $Log: timer.h,v $ + * Revision 1.1.1.1 2005/12/23 18:05:00 psperl + * Imported + * + * Revision 1.2 2004/10/05 09:19:40 cvs + * Fixed header include defines + * + * Revision 1.1.1.1 2004/10/04 12:56:00 cvs + * Imported + * + */ + +#ifndef _TIMER_H +#define _TIMER_H + +#ifndef WIN32 +#include +unsigned int getTicks( struct timeval *start ); +#else +#include +unsigned int getTicks( long start ); +#endif /** !WIN32 */ + +#endif /** _TIMER_H */ diff --git a/src/projectM-engine-backup/win32-dirent.cpp b/src/projectM-engine-backup/win32-dirent.cpp new file mode 100755 index 000000000..a5397603e --- /dev/null +++ b/src/projectM-engine-backup/win32-dirent.cpp @@ -0,0 +1,231 @@ +/* + + Implementation of POSIX directory browsing functions and types for Win32. + + Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com) + History: Created March 1997. Updated June 2003. + Rights: See end of file. + +*/ + +#include "win32-dirent.h" +#include +#include /* _findfirst and _findnext set errno iff they return -1 */ +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct DIR +{ + long handle; /* -1 for failed rewind */ + struct _finddata_t info; + struct dirent result; /* d_name null iff first time */ + char *name; /* null-terminated char string */ +}; + +DIR *opendir(const char *name) +{ + DIR *dir = 0; + + if(name && name[0]) + { + size_t base_length = strlen(name); + const char *all = /* search pattern must end with suitable wildcard */ + strchr("/\\", name[base_length - 1]) ? "*" : "/*"; + + if((dir = (DIR *) malloc(sizeof *dir)) != 0 && + (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0) + { + strcat(strcpy(dir->name, name), all); + + if((dir->handle = (long) _findfirst(dir->name, &dir->info)) != -1) + { + dir->result.d_name = 0; + } + else /* rollback */ + { + free(dir->name); + free(dir); + dir = 0; + } + } + else /* rollback */ + { + free(dir); + dir = 0; + errno = ENOMEM; + } + } + else + { + errno = EINVAL; + } + + return dir; +} + +int closedir(DIR *dir) +{ + int result = -1; + + if(dir) + { + if(dir->handle != -1) + { + result = _findclose(dir->handle); + } + + free(dir->name); + free(dir); + } + + if(result == -1) /* map all errors to EBADF */ + { + errno = EBADF; + } + + return result; +} + +struct dirent *readdir(DIR *dir) +{ + struct dirent *result = 0; + + if(dir && dir->handle != -1) + { + if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) + { + result = &dir->result; + result->d_name = dir->info.name; + } + } + else + { + errno = EBADF; + } + + return result; +} + +void rewinddir(DIR *dir) +{ + if(dir && dir->handle != -1) + { + _findclose(dir->handle); + dir->handle = (long) _findfirst(dir->name, &dir->info); + dir->result.d_name = 0; + } + else + { + errno = EBADF; + } +} + +// helper for scandir below +static void scandir_free_dir_entries(struct dirent*** namelist, int entries) { + int i; + if (!*namelist) return; + for (i = 0; i < entries; ++i) { + free((*namelist)[i]); + } + free(*namelist); + *namelist = 0; +} + +// returns the number of directory entries select or -1 if an error occurs +int scandir( + const char* dir, + struct dirent*** namelist, + int(*filter)(const struct dirent*), + int(*compar)(const void*, const void*) +) { + int entries = 0; + int max_entries = 512; // assume 2*512 = 1024 entries (used for allocation) + DIR* d; + + *namelist = 0; + + // open directory + d = opendir(dir); + if (!d) return -1; + + // iterate + while (1) { + struct dirent* ent = readdir(d); + if (!ent) break; + + // add if no filter or filter returns non-zero + if (filter && (0 == filter(ent))) continue; + + // resize our buffer if there is not enough room + if (!*namelist || entries >= max_entries) { + struct dirent** new_entries; + + max_entries *= 2; + new_entries = (struct dirent **)realloc(*namelist, max_entries); + if (!new_entries) { + scandir_free_dir_entries(namelist, entries); + closedir(d); + errno = ENOMEM; + return -1; + } + + *namelist = new_entries; + } + + // allocate new entry + (*namelist)[entries] = (struct dirent *)malloc(sizeof(struct dirent) + strlen(ent->d_name) + 1); + if (!(*namelist)[entries]) { + scandir_free_dir_entries(namelist, entries); + closedir(d); + errno = ENOMEM; + return -1; + } + + // copy entry info + *(*namelist)[entries] = *ent; + + // and then we tack the string onto the end + { + char* dest = (char*)((*namelist)[entries]) + sizeof(struct dirent); + strcpy(dest, ent->d_name); + (*namelist)[entries]->d_name = dest; + } + + ++entries; + } + + // sort + if (*namelist && compar) qsort(*namelist, entries, sizeof((*namelist)[0]), compar); + + return entries; +} + +int alphasort(const void* lhs, const void* rhs) { + const struct dirent* lhs_ent = *(struct dirent**)lhs; + const struct dirent* rhs_ent = *(struct dirent**)rhs; + return _strcmpi(lhs_ent->d_name, rhs_ent->d_name); +} + +#ifdef __cplusplus +} +#endif + +/* + + Copyright Kevlin Henney, 1997, 2003. All rights reserved. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose is hereby granted without fee, provided + that this copyright and permissions notice appear in all copies and + derivatives. + + This software is supplied "as is" without express or implied warranty. + + But that said, if there are any problems please get in touch. + +*/ diff --git a/src/projectM-engine-backup/win32-dirent.h b/src/projectM-engine-backup/win32-dirent.h new file mode 100755 index 000000000..7893d0bc4 --- /dev/null +++ b/src/projectM-engine-backup/win32-dirent.h @@ -0,0 +1,59 @@ + +#ifndef DIRENT_INCLUDED +#define DIRENT_INCLUDED + +/* + + Declaration of POSIX directory browsing functions and types for Win32. + + Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com) + History: Created March 1997. Updated June 2003. + Rights: See end of file. + +*/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct DIR DIR; + +static int errno; + +struct dirent +{ + char *d_name; +}; + +DIR *opendir(const char *); +int closedir(DIR *); +struct dirent *readdir(DIR *); +void rewinddir(DIR *); +int scandir( + const char* dir, + struct dirent*** namelist, + int(*filter)(const struct dirent*), + int(*compar)(const void*, const void*) ); +int alphasort(const void* lhs, const void* rhs); + +/* + + Copyright Kevlin Henney, 1997, 2003. All rights reserved. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose is hereby granted without fee, provided + that this copyright and permissions notice appear in all copies and + derivatives. + + This software is supplied "as is" without express or implied warranty. + + But that said, if there are any problems please get in touch. + +*/ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/projectM-engine-backup/wipemalloc.cpp b/src/projectM-engine-backup/wipemalloc.cpp new file mode 100755 index 000000000..14bcf7816 --- /dev/null +++ b/src/projectM-engine-backup/wipemalloc.cpp @@ -0,0 +1,44 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2004 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: wipemalloc.c,v 1.1.1.1 2005/12/23 18:05:05 psperl Exp $ + * + * Clean memory allocator + */ + +#include "wipemalloc.h" + + void *wipemalloc( size_t count ) { + void *mem = malloc( count ); + if ( mem != NULL ) { + memset( mem, 0, count ); + } else { + printf( "wipemalloc() failed to allocate %d bytes\n", (int)count ); + } + return mem; + } + +/** Safe memory deallocator */ + void wipefree( void *ptr ) { + if ( ptr != NULL ) { + free( ptr ); + } + } diff --git a/src/projectM-engine-backup/wipemalloc.h b/src/projectM-engine-backup/wipemalloc.h new file mode 100755 index 000000000..6ff625d36 --- /dev/null +++ b/src/projectM-engine-backup/wipemalloc.h @@ -0,0 +1,60 @@ +/** + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2007 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ +/** + * $Id: wipemalloc.h,v 1.1.1.1 2005/12/23 18:05:03 psperl Exp $ + * + * Contains an inline function which can replace malloc() that also + * call memset( ..., 0, sizeof( ... ) ) on the allocated block for + * safe initialization + * + * $Log$ + */ + +#ifndef _WIPEMALLOC_H +#define _WIPEMALLOC_H + +#ifndef MACOS +#ifndef HAVE_AIX /** AIX has malloc() defined in a strange place... */ +#ifdef WIN32 +#include +#endif +#include +#include +#else +#include +#endif /** !HAVE_AIX */ +#else +#include +#include +#endif /** !MACOS */ +#include + +#ifdef PANTS +#if defined(WIN32) && !defined(inline) +#define inline +#endif +#endif + +/** Safe memory allocator */ + void *wipemalloc( size_t count ); + void wipefree( void *ptr ); + +#endif /** !_WIPEMALLOC_H */ diff --git a/src/projectM-xmms/main.cpp b/src/projectM-xmms/main.cpp index d0fc27b61..242041257 100755 --- a/src/projectM-xmms/main.cpp +++ b/src/projectM-xmms/main.cpp @@ -210,11 +210,14 @@ int worker_func(void*) while ( SDL_PollEvent( &event ) ) { /** Translate into projectM codes and process */ evt = sdl2pmEvent( event ); + if (!((event.type == SDL_KEYDOWN) || (event.type == SDL_KEYUP))) + continue; + key = sdl2pmKeycode( event.key.keysym.sym ); mod = sdl2pmModifier( event.key.keysym.mod ); if ( evt == PROJECTM_KEYDOWN ) { - + printf("menu-imp\n"); if(key == PROJECTM_K_f) {