diff --git a/src/linux/projectmDev10.kdevses b/src/linux/projectmDev10.kdevses index 734a9572a..5e8445788 100644 --- a/src/linux/projectmDev10.kdevses +++ b/src/linux/projectmDev10.kdevses @@ -1,106 +1,52 @@ - - - + + + - - + + - - + + - - + + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -114,13 +60,6 @@ - - - - - - - diff --git a/src/projectM-engine/CMakeLists.txt b/src/projectM-engine/CMakeLists.txt index 72e0a0d29..e12cb16f5 100644 --- a/src/projectM-engine/CMakeLists.txt +++ b/src/projectM-engine/CMakeLists.txt @@ -2,9 +2,9 @@ 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 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 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 PresetMerge.cpp PresetMerge.hpp) +Func.hpp Func.cpp Eval.cpp wipemalloc.h PerFrameEqn.cpp PerPointEqn.cpp fftsg.cpp glConsole.cpp console_interface.cpp +CValue.hpp Expr.hpp timer.cpp wipemalloc.cpp PerFrameEqn.hpp PerPixelEqn.hpp PerPointEqn.hpp BuiltinFuncs.hpp +BuiltinFuncs.cpp compare.h event.h fatal.h fftsg.h glConsole.h timer.h BuiltinParams.hpp BuiltinParams.cpp Preset.hpp Renderer.cpp Renderer.hpp ParamUtils.hpp PresetLoader.cpp PresetLoader.hpp PresetChooser.hpp PresetChooser.cpp PresetFrameIO.cpp PresetFrameIO.hpp PresetMerge.cpp PresetMerge.hpp) OPTION(USE_FTGL "Use FTGL for on-screen fonts" ON) @@ -35,4 +35,4 @@ INSTALL(FILES ${fonts} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/projectM/fonts) INSTALL(FILES "${CMAKE_BINARY_DIR}/libprojectM.pc" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) INSTALL(FILES config.1.00 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/projectM) 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(TARGETS projectM DESTINATION lib) \ No newline at end of file +INSTALL(TARGETS projectM DESTINATION lib) diff --git a/src/projectM-engine/CustomShape.cpp b/src/projectM-engine/CustomShape.cpp index 009361c7b..690abdb44 100755 --- a/src/projectM-engine/CustomShape.cpp +++ b/src/projectM-engine/CustomShape.cpp @@ -42,9 +42,6 @@ using namespace Algorithms; -void eval_custom_shape_init_conds ( CustomShape * custom_shape ); -void load_unspec_init_cond_shape ( Param * param ); - CustomShape::CustomShape ( int id ) { diff --git a/src/projectM-engine/CustomWave.cpp b/src/projectM-engine/CustomWave.cpp index af9886303..a9cfe3bdf 100755 --- a/src/projectM-engine/CustomWave.cpp +++ b/src/projectM-engine/CustomWave.cpp @@ -40,34 +40,31 @@ #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) + 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 + + /// @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)); @@ -80,324 +77,377 @@ CustomWave::CustomWave(int _id): /* Start: Load custom wave parameters */ - if ((param = Param::new_param_float("r", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &this->r, this->r_mesh, 1.0, 0.0, .5)) == NULL) { + if ((param = Param::new_param_float("r", P_FLAG_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, ¶m_tree) < 0) { + if (ParamUtils::insert(param, ¶m_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) { + + 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 + /// @bug make exception abort(); } - if (ParamUtils::insert(param, ¶m_tree) < 0) { + if (ParamUtils::insert(param, ¶m_tree) < 0) + { delete(this); -/// @bug make exception + /// @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){ + 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 + /// @bug make exception abort(); } - if (ParamUtils::insert(param, &this->param_tree) < 0) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); -/// @bug make exception + /// @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){ + 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 + /// @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) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); -/// @bug make exception + /// @bug make exception abort(); } - if (ParamUtils::insert(param, &this->param_tree) < 0) { + 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 + /// @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) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); -/// @bug make exception + /// @bug make exception abort(); } - if (ParamUtils::insert(param, &this->param_tree) < 0) { + 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 + /// @bug make exception abort(); } - if ((param = Param::new_param_bool("enabled", P_FLAG_NONE, &this->enabled, 1, 0, 0)) == NULL) { + if ((param = Param::new_param_bool("enabled", P_FLAG_NONE, &this->enabled, 1, 0, 0)) == NULL) + { delete(this); -/// @bug make exception + /// @bug make exception abort(); } - if (ParamUtils::insert(param, &this->param_tree) < 0) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); -/// @bug make exception + /// @bug make exception abort(); } - if ((param = Param::new_param_int("sep", P_FLAG_NONE, &this->sep, 100, -100, 0)) == NULL) { + if ((param = Param::new_param_int("sep", P_FLAG_NONE, &this->sep, 100, -100, 0)) == NULL) + { delete(this); -/// @bug make exception + /// @bug make exception abort(); } - if (ParamUtils::insert(param, &this->param_tree) < 0) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); -/// @bug make exception + /// @bug make exception abort(); } - if ((param = Param::new_param_bool("bSpectrum", P_FLAG_NONE, &this->bSpectrum, 1, 0, 0)) == NULL) { + if ((param = Param::new_param_bool("bSpectrum", P_FLAG_NONE, &this->bSpectrum, 1, 0, 0)) == NULL) + { delete(this); -/// @bug make exception + /// @bug make exception abort(); } - if (ParamUtils::insert(param, &this->param_tree) < 0) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); -/// @bug make exception + /// @bug make exception abort(); } - if ((param = Param::new_param_bool("bDrawThick", P_FLAG_NONE, &this->bDrawThick, 1, 0, 0)) == NULL) { + if ((param = Param::new_param_bool("bDrawThick", P_FLAG_NONE, &this->bDrawThick, 1, 0, 0)) == NULL) + { delete(this); -/// @bug make exception + /// @bug make exception abort(); } - if (ParamUtils::insert(param, &this->param_tree) < 0) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); -/// @bug make exception + /// @bug make exception abort(); } - if ((param = Param::new_param_bool("bUseDots", P_FLAG_NONE, &this->bUseDots, 1, 0, 0)) == NULL) { + if ((param = Param::new_param_bool("bUseDots", P_FLAG_NONE, &this->bUseDots, 1, 0, 0)) == NULL) + { delete(this); -/// @bug make exception + /// @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) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); abort(); } - if (ParamUtils::insert(param, &this->param_tree) < 0) { + if ((param = Param::new_param_bool("bAdditive", P_FLAG_NONE, &this->bAdditive, 1, 0, 0)) == NULL) + { delete(this); abort(); } - if ((param = Param::new_param_int("samples", P_FLAG_NONE, &this->samples, 2048, 1, 512)) == NULL) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); abort(); } - - if (ParamUtils::insert(param, &this->param_tree) < 0) { + + 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) { + &this->sample, this->sample_mesh, 1.0, 0.0, 0.0)) == NULL) + { delete(this); abort(); } - - if (ParamUtils::insert(param, &this->param_tree) < 0) { + + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); abort(); } - if (ParamUtils::insert(param, &this->param_tree) < 0) { + 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 ((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) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { delete(this); abort(); } - if (ParamUtils::insert(param, &this->param_tree) < 0) { + 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 ((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) { + if (ParamUtils::insert(param, &this->param_tree) < 0) + { 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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 ((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) { + 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) { + 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() { +CustomWave::~CustomWave() +{ - - 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_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); + delete(pos->second); for (std::map::iterator pos = init_cond_tree.begin(); pos != init_cond_tree.end(); ++pos) - delete(pos->second); + 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); + delete(pos->second); for (std::map::iterator pos = param_tree.begin(); pos != param_tree.end(); ++pos) - delete(pos->second); + delete(pos->second); free(r_mesh); free(g_mesh); @@ -409,14 +459,14 @@ CustomWave::~CustomWave() { free(value2); free(sample_mesh); - } // Comments: index is not passed, so we assume monotic increment by 1 is ok here -int CustomWave::add_per_point_eqn(char * name, GenExpr * gen_expr) { +int CustomWave::add_per_point_eqn(char * name, GenExpr * gen_expr) +{ PerPointEqn * per_point_eqn; int index; @@ -424,60 +474,68 @@ int CustomWave::add_per_point_eqn(char * name, GenExpr * gen_expr) { /* Argument checks */ if (gen_expr == NULL) - return PROJECTM_FAILURE; + 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); + return PROJECTM_FAILURE; - /* Search for the parameter so we know what matrix the per pixel equation is referencing */ + if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: per pixel equation (name = \"%s\")\n", name); - if ((param = ParamUtils::find(name,¶m_tree)) == NULL) { - if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: failed to allocate a new parameter!\n"); - return PROJECTM_FAILURE; - - } + /* Search for the parameter so we know what matrix the per pixel equation is referencing */ - /* Find most largest index in the splaytree */ - index = per_point_eqn_tree.size(); + if ((param = ParamUtils::find(name,¶m_tree)) == NULL) + { + if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: failed to allocate a new parameter!\n"); + return PROJECTM_FAILURE; - /* 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)); + /* Get largest index in the tree */ + index = per_point_eqn_tree.size(); - /* Done */ - return PROJECTM_SUCCESS; + /* Create the per point 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() { +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(); + { + assert(pos->second); + 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(); + { + assert(pos->second); + pos->second->evaluate(); + } } /** Evaluate per-point equations */ -void CustomWave::evalPerPointEqns() { +void CustomWave::evalPerPointEqns() +{ int x; assert(samples > 0); assert(r_mesh); -assert(g_mesh); -assert(b_mesh); -assert(a_mesh); -assert(x_mesh); -assert(y_mesh); + assert(g_mesh); + assert(b_mesh); + assert(a_mesh); + assert(x_mesh); + assert(y_mesh); for (x = 0; x < samples; x++) r_mesh[x] = r; @@ -493,17 +551,15 @@ assert(y_mesh); 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(); + 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() { +void CustomWave::load_unspecified_init_conds() +{ - InitCondUtils::LoadUnspecInitCond fun(this->init_cond_tree, this->per_frame_init_eqn_tree); - Algorithms::traverse(param_tree, fun); + InitCondUtils::LoadUnspecInitCond fun(this->init_cond_tree, this->per_frame_init_eqn_tree); + Algorithms::traverse(param_tree, fun); } - - - diff --git a/src/projectM-engine/CustomWave.hpp b/src/projectM-engine/CustomWave.hpp index d504da755..973078d01 100755 --- a/src/projectM-engine/CustomWave.hpp +++ b/src/projectM-engine/CustomWave.hpp @@ -125,11 +125,6 @@ public: 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(); diff --git a/src/projectM-engine/InitCond.cpp b/src/projectM-engine/InitCond.cpp index 5102c6c54..5dc9e3cee 100755 --- a/src/projectM-engine/InitCond.cpp +++ b/src/projectM-engine/InitCond.cpp @@ -58,18 +58,20 @@ void InitCond::evaluate() { assert(this); + assert(param); /* 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) { // printf( "init_cond: %s = %d (TYPE BOOL)\n", param->name.c_str(), init_val.bool_val); - - + std::cerr << "[InitCond] param is a boolean of with name " + << param->name << std::endl; + assert(param->engine_val); *((int*)param->engine_val) = init_val.bool_val; diff --git a/src/projectM-engine/InitCondUtils.hpp b/src/projectM-engine/InitCondUtils.hpp index 2dcb6045a..a2da08702 100644 --- a/src/projectM-engine/InitCondUtils.hpp +++ b/src/projectM-engine/InitCondUtils.hpp @@ -2,6 +2,7 @@ #define _INIT_COND_UTILS_HPP #include #include "InitCond.hpp" +#include namespace InitCondUtils { class LoadUnspecInitCond { @@ -57,12 +58,14 @@ inline void LoadUnspecInitCond::operator() (Param * param) { //printf("%s\n", param->name); /* Create new initial condition */ + std::cerr << "[InitCondUtils] creating an unspecified initial condition of name " << param->name << std::endl; if ((init_cond = new InitCond(param, init_val)) == NULL) return; /* Insert the initial condition into this presets tree */ - /// @bug check the result status of insert - m_initCondTree.insert(std::make_pair(init_cond->param->name, init_cond)); + std::pair::iterator, bool> inserteePair = + m_initCondTree.insert(std::make_pair(init_cond->param->name, init_cond)); + assert(inserteePair.second); } diff --git a/src/projectM-engine/Param.cpp b/src/projectM-engine/Param.cpp index 64023a56e..ad33cba41 100755 --- a/src/projectM-engine/Param.cpp +++ b/src/projectM-engine/Param.cpp @@ -89,6 +89,8 @@ Param::Param(std::string _name) : Param::~Param() { int x; + + // I hate this, but will let it be for now if (flags & P_FLAG_USERDEF) { delete((double*)engine_val); } @@ -98,12 +100,13 @@ Param::~Param() { if (flags & P_FLAG_PER_POINT) { free(matrix); + matrix = 0; } //FIX THIS NOW XMAS05 else if (flags & P_FLAG_PER_PIXEL) { for (x = 0; x < gx; x++) free(((float**)matrix)[x]); free(matrix); - matrix = NULL; + matrix = 0; } } @@ -112,28 +115,28 @@ Param::~Param() { /* Returns nonzero if the string is valid parameter name */ -int Param::is_valid_param_string( const char * string ) { +bool Param::is_valid_param_string( const char * string ) { if (string == NULL) - return FALSE; + return false; /* This ensures the first character is non numeric */ if ( ((*string) >= 48) && ((*string) <= 57)) - return FALSE; + return false; /* These probably should never happen */ if (*string == '.') - return FALSE; + return false; if (*string == '+') - return FALSE; + return false; if (*string == '-') - return FALSE; + return false; /* Could also add checks for other symbols. May do later */ - return TRUE; + return true; } diff --git a/src/projectM-engine/Param.hpp b/src/projectM-engine/Param.hpp index 535c16343..6ea841fe8 100755 --- a/src/projectM-engine/Param.hpp +++ b/src/projectM-engine/Param.hpp @@ -72,7 +72,7 @@ public: CValue lower_bound; /* this parameter's lower bound */ int gx, gy; - /* Function prototypes */ + /// Create a new parameter Param(std::string name, short int type, short int flags, void * eqn_val, void *matrix, CValue default_init_val, CValue upper_bound, @@ -80,16 +80,11 @@ public: ~Param(); - /** Create a user defined parameter **/ + /// Create a user defined floating point 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 ); + static bool 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, diff --git a/src/projectM-engine/ParamUtils.hpp b/src/projectM-engine/ParamUtils.hpp index 5da3470a3..d02a47c36 100644 --- a/src/projectM-engine/ParamUtils.hpp +++ b/src/projectM-engine/ParamUtils.hpp @@ -37,7 +37,7 @@ public: Param * param; - /* First look in the builtin database */ + /* First look in the suggested database */ std::map::iterator pos = paramTree->find(name); @@ -55,8 +55,7 @@ public: std::pair::iterator, bool> insertRetPair = paramTree->insert(std::make_pair(param->name, param)); - if (insertRetPair.second) - param = insertRetPair.first->second; + assert(insertRetPair.second); } else if (pos != paramTree->end()) param = pos->second; @@ -69,7 +68,7 @@ public: } - /// Checks attempt + static Param * find(const std::string & name, BuiltinParams * builtinParams, std::map * insertionTree) { @@ -84,56 +83,6 @@ public: } - class LoadInitCondFunctor - { - public: - LoadInitCondFunctor(Preset * preset) :m_preset(preset) {assert(preset);} - - void operator() (Param * param) - { - - InitCond * init_cond; - CValue init_val; - assert(param); - /* 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/Parser.cpp b/src/projectM-engine/Parser.cpp index a22dcdd0b..3dfafd9e4 100755 --- a/src/projectM-engine/Parser.cpp +++ b/src/projectM-engine/Parser.cpp @@ -1391,13 +1391,9 @@ int Parser::parse_wavecode(char * token, FILE * fs, Preset * preset) { 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; + assert(preset); + assert(fs); + assert(token); /* token should be in the form wavecode_N_var, such as wavecode_1_samples */ @@ -1407,12 +1403,14 @@ int Parser::parse_wavecode(char * token, FILE * fs, Preset * preset) { //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 */ + /* Retrieve custom wave information from preset, allocating new one if necessary */ if ((custom_wave = Preset::find_custom_object(id, true, *preset->customWaves)) == NULL) { - //if (PARSE_DEBUG) printf("parse_wavecode: failed to load (or create) custom wave (id = %d)!\n", id); + std::cerr << "parse_wavecode: failed to load (or create) custom wave (id = " + << id << ")!\n" << std::endl; + 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 */ @@ -1442,15 +1440,18 @@ int Parser::parse_wavecode(char * token, FILE * fs, Preset * preset) { //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)); - + + std::pair::iterator, bool> inserteePair = + custom_wave->init_cond_tree.insert(std::make_pair(init_cond->param->name, init_cond)); + + assert(inserteePair.second); + line_mode = CUSTOM_WAVE_WAVECODE_LINE_MODE; //if (PARSE_DEBUG) printf("parse_wavecode: [success]\n"); diff --git a/src/projectM-engine/Preset.cpp b/src/projectM-engine/Preset.cpp index 50ca1ecb9..ddd116ecc 100755 --- a/src/projectM-engine/Preset.cpp +++ b/src/projectM-engine/Preset.cpp @@ -263,14 +263,14 @@ void Preset::initialize(const std::string & pathname) memset(this->per_frame_init_eqn_string_buffer, 0, STRING_BUFFER_SIZE); int retval; - if ((retval = load_preset_file(pathname.c_str())) < 0) + if ((retval = loadPresetFile(pathname)) < 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; } @@ -279,13 +279,13 @@ void Preset::initialize(const std::string & pathname) this->per_frame_eqn_count = 0; this->per_frame_init_eqn_count = 0; - this->loadUnspecInitConds(); - this->load_custom_wave_init_conditions(); - this->load_custom_shape_init_conditions(); + this->loadBuiltinParamsUnspecInitConds(); + this->loadCustomWaveUnspecInitConds(); + this->loadCustomShapeUnspecInitConds(); } -void Preset::loadUnspecInitConds() { +void Preset::loadBuiltinParamsUnspecInitConds() { InitCondUtils::LoadUnspecInitCond loadUnspecInitCond(this->init_cond_tree, this->per_frame_init_eqn_tree); @@ -293,7 +293,8 @@ void Preset::loadUnspecInitConds() { this->builtinParams.traverse(loadUnspecInitCond); } -void Preset::load_custom_wave_init_conditions() + +void Preset::loadCustomWaveUnspecInitConds() { for (PresetOutputs::cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos) @@ -304,7 +305,7 @@ void Preset::load_custom_wave_init_conditions() } -void Preset::load_custom_shape_init_conditions() +void Preset::loadCustomShapeUnspecInitConds() { for (PresetOutputs::cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos) @@ -315,8 +316,6 @@ void Preset::load_custom_shape_init_conditions() } - - void Preset::evaluateFrame() { @@ -332,7 +331,7 @@ void Preset::evaluateFrame() } -/** Evaluates all per-pixel equations */ +// Evaluates all per-pixel equations void Preset::evalPerPixelEqns() { @@ -343,53 +342,9 @@ void Preset::evalPerPixelEqns() } -/** 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; - -} - -/* preset_file: private function that loads a specific preset denoted +/* loadPresetFile: private function that loads a specific preset denoted by the given pathname */ -int Preset::load_preset_file(const char * pathname) +int Preset::loadPresetFile(std::string pathname) { FILE * fs; @@ -397,27 +352,24 @@ int Preset::load_preset_file(const char * pathname) 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 ((fs = fopen(pathname.c_str(), "rb")) == 0) { #if defined(PRESET_DEBUG) && defined(DEBUG) - DWRITE( "load_preset_file: loading of file %s failed!\n", pathname); + DWRITE( "loadPresetFile: 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); + DWRITE( "loadPresetFile: 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"); + DWRITE( "loadPresetFile: no left bracket found...\n"); #endif fclose(fs); return PROJECTM_FAILURE; @@ -429,7 +381,7 @@ int Preset::load_preset_file(const char * pathname) 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); + DWRITE( "loadPresetFile: loading of preset name in file \"%s\" failed\n", pathname); #endif fclose(fs); return PROJECTM_ERROR; @@ -437,13 +389,13 @@ int Preset::load_preset_file(const char * pathname) name = std::string(tmp_name); #if defined(PRESET_DEBUG) && defined(DEBUG) - DWRITE( "load_preset_file: preset \"%s\" parsed\n", this->name); + DWRITE( "loadPresetFile: 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"); + DWRITE( "loadPresetFile: beginning line parsing...\n"); #endif while ((retval = Parser::parse_line(fs, this)) != EOF) { @@ -451,7 +403,7 @@ int Preset::load_preset_file(const char * pathname) { 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); + DWRITE( "loadPresetFile: parse error in file \"%s\": line %d\n", pathname,lineno); #endif } @@ -459,7 +411,7 @@ int Preset::load_preset_file(const char * pathname) } #if defined(PRESET_DEBUG) && defined(DEBUG) - DWRITE("load_preset_file: finished line parsing successfully\n"); + DWRITE("loadPresetFile: finished line parsing successfully\n"); #endif /* Now the preset has been loaded. @@ -468,81 +420,8 @@ int Preset::load_preset_file(const char * pathname) fclose(fs); #if defined(PRESET_DEBUG) && defined(DEBUG) - DWRITE("load_preset_file: file \"%s\" closed, preset ready\n", pathname); + DWRITE("loadPresetFile: file \"%s\" closed, preset ready\n", pathname); #endif return PROJECTM_SUCCESS; } - -void Preset::load_init_conditions() -{ - - ParamUtils::LoadInitCondFunctor functor(this); - builtinParams.traverse(functor); - -} - - - - - - -/* 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/Preset.hpp b/src/projectM-engine/Preset.hpp index 331e9e7c3..6175ef9ba 100644 --- a/src/projectM-engine/Preset.hpp +++ b/src/projectM-engine/Preset.hpp @@ -1,3 +1,4 @@ + /** * projectM -- Milkdrop-esque visualisation SDK * Copyright (C)2003-2007 projectM Team @@ -32,6 +33,7 @@ #include "Common.hpp" #include #include +#include #define PRESET_DEBUG 0 /* 0 for no debugging, 1 for normal, 2 for insane */ @@ -42,108 +44,116 @@ #include "PerFrameEqn.hpp" #include "BuiltinParams.hpp" #include "PresetFrameIO.hpp" -#include #include "InitCond.hpp" - - class CustomWave; class CustomShape; class InitCond; - - -class Preset { +class Preset +{ protected: public: - PresetOutputs & m_presetOutputs; - /// Load a preset by filename with input and output buffers specified. - /// This is the only proper way to allocate a new preset. - /// \param filename the absolute file path of a preset to load from the file system - /// \param presetInputs a const reference to read only projectM engine variables - /// \param presetOutputs initialized and filled with data parsed from a preset - Preset(const std::string & filename, const PresetInputs & presetInputs, PresetOutputs & presetOutputs); - - /// A special preset destructor. Very important: the preset destructor is currently responsible - /// for clearing out all heap memory it allocated in presetOutputs. This might change in future. - /// Conclusion: It does NOT necessarily reset or clear any values. It only deallocates. - ~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(); - template - static CustomObject * find_custom_object(int id, bool create_flag, std::map & customObjects); + /// Load a preset by filename with input and output buffers specified. + /// This is the only proper way to allocate a new preset. + /// \param filename the absolute file path of a preset to load from the file system + /// \param presetInputs a const reference to read only projectM engine variables + /// \param presetOutputs initialized and filled with data parsed from a preset + Preset(const std::string & filename, const PresetInputs & presetInputs, PresetOutputs & presetOutputs); - int per_pixel_eqn_string_index; - int per_frame_eqn_string_index; - int per_frame_init_eqn_string_index; + /// A special preset destructor. Very important: the preset destructor is currently responsible + /// for clearing out all heap memory it allocated in presetOutputs. This might change in future. + /// Conclusion: It does NOT necessarily reset or clear any values. It only deallocates. + ~Preset(); - int per_frame_eqn_count, - per_frame_init_eqn_count; + /// Evaluates the preset for a frame given the current values of preset inputs / outputs + /// All calculated values are stored in the associated preset outputs instance + void evaluateFrame(); - 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]; + /// All "builtin" parameters for this preset. Anything *but* user defined parameters and + /// custom waves / shapes objects go here. + /// @bug encapsulate + BuiltinParams builtinParams; - /* 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 */ - GenExpr * per_pixel_eqn_array[NUM_OPS]; /* per pixel equation array */ - 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 */ + /// Preset name, very boring, like [preset00] + std::string name; - int add_per_pixel_eqn( char *name, GenExpr *gen_expr ); + /// Used by parser to find/create custom waves and shapes. May be refactored + template + static CustomObject * find_custom_object(int id, bool create_flag, std::map & customObjects); - int resetPerPixelEqns(); - int resetPerPixelEqnFlags(); + int per_pixel_eqn_string_index; + int per_frame_eqn_string_index; + int per_frame_init_eqn_string_index; - InitCond *get_init_cond( Param *param ); + int per_frame_eqn_count, + per_frame_init_eqn_count; - void load_custom_wave_init_conditions(); - void load_custom_shape_init_conditions(); - + 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]; - int load_preset_file(const char * pathname); - static Preset *load_preset( const char *pathname ); - Param * find(char * name, int flags) ; + /// Used by parser + /// @bug refactor + int add_per_pixel_eqn( char *name, GenExpr *gen_expr ); - void load_init_cond(char *name, int flags); - inline void clearMeshChecks(); + /// Accessor method to retrieve the absolute file path of the loaded preset + /// \returns a file path string + std::string absoluteFilePath() const + { + return file_path; + } + + /// Accessor method for the preset outputs instance associated with this preset + /// \returns A preset output instance with values computed from most recent evaluateFrame() + PresetOutputs & presetOutputs() const + { + return m_presetOutputs; + } + + /// @bug encapsulate + PresetOutputs::cwave_container * customWaves; + PresetOutputs::cshape_container * customShapes; + + /// @bug encapsulate + /* 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 */ - std::string absoluteFilePath() const - { - return file_path; - } - - PresetOutputs::cwave_container * customWaves; - PresetOutputs::cshape_container * customShapes; - private: - void evalCustomWavePerFrameEquations(); - void evalCustomShapePerFrameEquations(); - void evalPerFrameInitEquations(); - void evalCustomWaveInitConditions(); - void evalCustomShapeInitConditions(); - void evalPerPixelEqns(); - void evalPerFrameEquations(); - void initialize(const std::string & pathname); - void loadUnspecInitConds(); + // The absolute file path of the preset + std::string file_path; + + void initialize(const std::string & pathname); + int loadPresetFile(std::string pathname); + + void loadBuiltinParamsUnspecInitConds(); + void loadCustomWaveUnspecInitConds(); + void loadCustomShapeUnspecInitConds(); + + void evalCustomWavePerFrameEquations(); + void evalCustomShapePerFrameEquations(); + void evalPerFrameInitEquations(); + void evalCustomWaveInitConditions(); + void evalCustomShapeInitConditions(); + void evalPerPixelEqns(); + void evalPerFrameEquations(); + + + inline void clearMeshChecks(); + + PresetOutputs & m_presetOutputs; - }; template @@ -151,13 +161,13 @@ CustomObject * Preset::find_custom_object(int id, bool create_flag, std::map::iterator pos = customObjects.find(id); if (pos == customObjects.end()) { - if (create_flag == FALSE) + if (create_flag == false) { return NULL; } @@ -167,32 +177,34 @@ CustomObject * Preset::find_custom_object(int id, bool create_flag, std::map::iterator, bool> inserteePair = - customObjects.insert(std::make_pair(custom_object->id, custom_object)); + std::pair::iterator, bool> inserteePair = + customObjects.insert(std::make_pair(custom_object->id, custom_object)); assert(inserteePair.second); custom_object = inserteePair.first->second; - } else - custom_object = pos->second; - + } + else + custom_object = pos->second; + assert(custom_object); return custom_object; } -inline void Preset::clearMeshChecks() { - m_presetOutputs.zoom_is_mesh = false; - m_presetOutputs.zoomexp_is_mesh = false; - m_presetOutputs.rot_is_mesh =false; - m_presetOutputs.sx_is_mesh =false; - m_presetOutputs.sy_is_mesh = false; - m_presetOutputs.dx_is_mesh = false; - m_presetOutputs.dy_is_mesh =false; - m_presetOutputs.cx_is_mesh = false; - m_presetOutputs.cy_is_mesh = false; +inline void Preset::clearMeshChecks() +{ + m_presetOutputs.zoom_is_mesh = false; + m_presetOutputs.zoomexp_is_mesh = false; + m_presetOutputs.rot_is_mesh = false; + m_presetOutputs.sx_is_mesh = false; + m_presetOutputs.sy_is_mesh = false; + m_presetOutputs.dx_is_mesh = false; + m_presetOutputs.dy_is_mesh = false; + m_presetOutputs.cx_is_mesh = false; + m_presetOutputs.cy_is_mesh = false; } diff --git a/src/projectM-engine/PresetFilters.hpp b/src/projectM-engine/PresetFilters.hpp deleted file mode 100644 index 0a7b98c6c..000000000 --- a/src/projectM-engine/PresetFilters.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#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/SplayNode.hpp b/src/projectM-engine/SplayNode.hpp deleted file mode 100644 index 09fb19ce0..000000000 --- a/src/projectM-engine/SplayNode.hpp +++ /dev/null @@ -1,91 +0,0 @@ -/** - * 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/browser.cpp b/src/projectM-engine/browser.cpp deleted file mode 100755 index e8a76a5bd..000000000 --- a/src/projectM-engine/browser.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/** - * 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/browser.h b/src/projectM-engine/browser.h deleted file mode 100755 index 958719b6f..000000000 --- a/src/projectM-engine/browser.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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/console_interface.cpp b/src/projectM-engine/console_interface.cpp index 907c58bd7..0aad8fa90 100755 --- a/src/projectM-engine/console_interface.cpp +++ b/src/projectM-engine/console_interface.cpp @@ -24,16 +24,14 @@ #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" #include +class Preset; + interface_t current_interface = DEFAULT_INTERFACE; void refreshConsole() { @@ -41,17 +39,18 @@ void refreshConsole() { switch (current_interface) { case MENU_INTERFACE: -// refreshMenu(); + // unimplemented break; case SHELL_INTERFACE: + // unimplemented break; case EDITOR_INTERFACE: - refreshEditor(); + // unimplemented break; case DEFAULT_INTERFACE: break; case BROWSER_INTERFACE: - refreshBrowser(); + // unimplemented break; default: break; @@ -78,10 +77,10 @@ void projectM::key_handler( projectMEvent event, //shell_key_handler(); break; case EDITOR_INTERFACE: - editor_key_handler(event,keycode); +// editor_key_handler(event,keycode); break; case BROWSER_INTERFACE: - browser_key_handler(event,keycode,modifier); +// browser_key_handler(event,keycode,modifier); break; case DEFAULT_INTERFACE: default_key_handler(event,keycode); diff --git a/src/projectM-engine/editor.cpp b/src/projectM-engine/editor.cpp deleted file mode 100755 index fbc97dfce..000000000 --- a/src/projectM-engine/editor.cpp +++ /dev/null @@ -1,870 +0,0 @@ -/** - * 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/editor.h b/src/projectM-engine/editor.h deleted file mode 100755 index 697b872df..000000000 --- a/src/projectM-engine/editor.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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/projectM.cpp b/src/projectM-engine/projectM.cpp index e0a97bc21..365d71c43 100755 --- a/src/projectM-engine/projectM.cpp +++ b/src/projectM-engine/projectM.cpp @@ -142,7 +142,9 @@ DLLEXPORT void projectM::renderFrame() presetInputs.frame = 0; m_activePreset2 = m_presetChooser->weightedRandom - (presetInputs, &m_activePreset->m_presetOutputs == &presetOutputs ? presetOutputs2 : presetOutputs); + (presetInputs, &m_activePreset->presetOutputs() == &presetOutputs ? presetOutputs2 : presetOutputs); + assert(m_activePreset2.get()); + nohard=(int)(presetInputs.fps*3.5); smoothFrame = (int)(presetInputs.fps * smoothTime); @@ -154,6 +156,7 @@ DLLEXPORT void projectM::renderFrame() printf("HARD CUT"); m_activePreset = m_presetChooser->weightedRandom (presetInputs, presetOutputs); + assert(m_activePreset.get()); nohard=presetInputs.fps*5; smoothFrame=0; } @@ -167,17 +170,19 @@ DLLEXPORT void projectM::renderFrame() int frame = presetInputs.frame++; presetInputs.frame = oldFrame; presetInputs.progress= 1.0; + assert(m_activePreset.get()); m_activePreset->evaluateFrame(); - renderer->PerPixelMath(&m_activePreset->m_presetOutputs, &presetInputs); + renderer->PerPixelMath(&m_activePreset->presetOutputs(), &presetInputs); presetInputs.frame = frame; presetInputs.progress= frame /(float) avgtime; - m_activePreset2->evaluateFrame(); - renderer->PerPixelMath(&m_activePreset2->m_presetOutputs, &presetInputs); + assert(m_activePreset2.get()); + m_activePreset2->evaluateFrame(); + renderer->PerPixelMath(&m_activePreset2->presetOutputs(), &presetInputs); double ratio = smoothFrame / (presetInputs.fps * smoothTime); - PresetMerger::MergePresets(m_activePreset->m_presetOutputs,m_activePreset2->m_presetOutputs,ratio,presetInputs.gx, presetInputs.gy); + PresetMerger::MergePresets(m_activePreset->presetOutputs(),m_activePreset2->presetOutputs(),ratio,presetInputs.gx, presetInputs.gy); //printf("Smooth:%d\n",smoothFrame); @@ -196,13 +201,13 @@ DLLEXPORT void projectM::renderFrame() presetInputs.frame++; //number of frames for current preset presetInputs.progress= presetInputs.frame/ ( float ) avgtime; m_activePreset->evaluateFrame(); - renderer->PerPixelMath(&m_activePreset->m_presetOutputs, &presetInputs); + renderer->PerPixelMath(&m_activePreset->presetOutputs(), &presetInputs); } // std::cout<< m_activePreset->absoluteFilePath()<presetName = m_activePreset->absoluteFilePath(); - renderer->RenderFrame ( &m_activePreset->m_presetOutputs, &presetInputs ); + renderer->RenderFrame ( &m_activePreset->presetOutputs(), &presetInputs ); count++; #ifndef WIN32