Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

custom_wave.c

00001 /*****************************************************************************
00002  * custom_wave.c:
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: custom_wave.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Cyril Deguet <[email protected]>
00008  *          code from projectM http://xmms-projectm.sourceforge.net
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 
00026 
00027 #include <stdio.h>
00028 #include <string.h>
00029 #include <stdlib.h>
00030 
00031 #include "common.h"
00032 #include "fatal.h"
00033 
00034 #include "param_types.h"
00035 #include "param.h"
00036 
00037 #include "expr_types.h"
00038 #include "eval.h"
00039 
00040 #include "splaytree_types.h"
00041 #include "splaytree.h"
00042 #include "tree_types.h"
00043 
00044 #include "per_frame_eqn_types.h"
00045 #include "per_frame_eqn.h"
00046 
00047 #include "init_cond_types.h"
00048 #include "init_cond.h"
00049 
00050 #include "preset_types.h"
00051 
00052 #include "custom_wave_types.h"
00053 #include "custom_wave.h"
00054 
00055 #include "init_cond_types.h"
00056 #include "init_cond.h"
00057 
00058 #include "engine_vars.h"
00059 #define MAX_SAMPLE_SIZE 4096
00060 
00061 extern int mesh_i;
00062 
00063 custom_wave_t * interface_wave = NULL;
00064 int interface_id = 0;
00065 extern preset_t * active_preset;
00066 inline void eval_custom_wave_init_conds(custom_wave_t * custom_wave);
00067 void load_unspec_init_cond(param_t * param);
00068 void destroy_per_point_eqn_tree(splaytree_t * tree);
00069 void destroy_param_db_tree(splaytree_t * tree);
00070 void destroy_per_frame_eqn_tree(splaytree_t * tree);
00071 void destroy_per_frame_init_eqn_tree(splaytree_t * tree);
00072 void destroy_init_cond_tree(splaytree_t * tree);
00073 inline void evalPerPointEqn(per_point_eqn_t * per_point_eqn);
00074 
00075 custom_wave_t * new_custom_wave(int id) {
00076 
00077   custom_wave_t * custom_wave;
00078   param_t * param;
00079   
00080   if ((custom_wave = (custom_wave_t*)malloc(sizeof(custom_wave_t))) == NULL)
00081     return NULL;
00082 
00083   custom_wave->id = id;
00084   custom_wave->per_frame_count = 0;
00085 
00086   custom_wave->samples = 512;
00087   custom_wave->bSpectrum = 0;
00088   custom_wave->enabled = 1;
00089   custom_wave->sep = 1;
00090   custom_wave->smoothing = 0.0;
00091   custom_wave->bUseDots = 0;
00092   custom_wave->bAdditive = 0;
00093   custom_wave->r = custom_wave->g = custom_wave->b = custom_wave->a = 0.0;
00094   custom_wave->scaling = 1.0;
00095   custom_wave->per_frame_eqn_string_index = 0;
00096   custom_wave->per_frame_init_eqn_string_index = 0;
00097   custom_wave->per_point_eqn_string_index = 0;
00098 
00099   custom_wave->r_mesh = malloc(MAX_SAMPLE_SIZE*sizeof(double));
00100   custom_wave->g_mesh = malloc(MAX_SAMPLE_SIZE*sizeof(double));
00101   custom_wave->b_mesh = malloc(MAX_SAMPLE_SIZE*sizeof(double));
00102   custom_wave->a_mesh = malloc(MAX_SAMPLE_SIZE*sizeof(double));
00103   custom_wave->x_mesh = malloc(MAX_SAMPLE_SIZE*sizeof(double));
00104   custom_wave->y_mesh = malloc(MAX_SAMPLE_SIZE*sizeof(double));
00105   custom_wave->value1 = malloc(MAX_SAMPLE_SIZE*sizeof(double));
00106   custom_wave->value2 = malloc(MAX_SAMPLE_SIZE*sizeof(double));
00107   custom_wave->sample_mesh = malloc(MAX_SAMPLE_SIZE*sizeof(double));
00108 
00109   /* Initialize tree data structures */
00110   
00111   if ((custom_wave->param_tree = 
00112        create_splaytree(compare_string, copy_string, free_string)) == NULL) {
00113     free_custom_wave(custom_wave);
00114     return NULL;
00115   }
00116 
00117   if ((custom_wave->per_point_eqn_tree = 
00118        create_splaytree(compare_int, copy_int, free_int)) == NULL) {
00119     free_custom_wave(custom_wave);
00120     return NULL;
00121   }
00122 
00123   if ((custom_wave->per_frame_eqn_tree = 
00124        create_splaytree(compare_int, copy_int, free_int)) == NULL) {
00125     free_custom_wave(custom_wave);
00126     return NULL;
00127   }
00128 
00129   if ((custom_wave->init_cond_tree = 
00130        create_splaytree(compare_string, copy_string, free_string)) == NULL) {
00131     free_custom_wave(custom_wave);
00132     return NULL;
00133   }
00134   
00135   if ((custom_wave->per_frame_init_eqn_tree = 
00136        create_splaytree(compare_string, copy_string, free_string)) == NULL) {
00137     free_custom_wave(custom_wave);
00138     return NULL;
00139   }
00140 
00141   
00142   /* Start: Load custom wave parameters */
00143 
00144   if ((param = new_param_double("r", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &custom_wave->r, custom_wave->r_mesh, 1.0, 0.0, .5)) == NULL) {
00145     free_custom_wave(custom_wave);
00146     return NULL;
00147   }
00148 
00149   if (insert_param(param, custom_wave->param_tree) < 0) {
00150     free_custom_wave(custom_wave);
00151     return NULL;
00152   }
00153  
00154   if ((param = new_param_double("g", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &custom_wave->g,  custom_wave->g_mesh, 1.0, 0.0, .5)) == NULL){
00155     free_custom_wave(custom_wave);
00156     return NULL;
00157   }
00158 
00159   if (insert_param(param, custom_wave->param_tree) < 0) {
00160     free_custom_wave(custom_wave);
00161     return NULL;
00162   }
00163 
00164   if ((param = new_param_double("b", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &custom_wave->b,  custom_wave->b_mesh, 1.0, 0.0, .5)) == NULL){
00165     free_custom_wave(custom_wave);
00166     return NULL;                                       
00167   }
00168 
00169   if (insert_param(param, custom_wave->param_tree) < 0) {
00170     free_custom_wave(custom_wave);
00171     return NULL;
00172   }
00173 
00174   if ((param = new_param_double("a", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &custom_wave->a,  custom_wave->a_mesh, 1.0, 0.0, .5)) == NULL){
00175     free_custom_wave(custom_wave);
00176     return NULL;
00177   }
00178   
00179   if (insert_param(param, custom_wave->param_tree) < 0) {
00180     free_custom_wave(custom_wave);
00181     return NULL;
00182   }
00183 
00184   if ((param = new_param_double("x", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &custom_wave->x,  custom_wave->x_mesh, 1.0, 0.0, .5)) == NULL) {
00185     free_custom_wave(custom_wave);
00186     return NULL;
00187   }
00188 
00189   if (insert_param(param, custom_wave->param_tree) < 0) {
00190     free_custom_wave(custom_wave);
00191     return NULL;
00192   }
00193 
00194   if ((param = new_param_double("y", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &custom_wave->y,  custom_wave->y_mesh, 1.0, 0.0, .5)) == NULL) {
00195     free_custom_wave(custom_wave);
00196     return NULL;
00197   }
00198 
00199   if (insert_param(param, custom_wave->param_tree) < 0) {
00200     free_custom_wave(custom_wave);
00201     return NULL;
00202   }
00203 
00204   if ((param = new_param_bool("enabled", P_FLAG_NONE, &custom_wave->enabled, 1, 0, 0)) == NULL) {
00205     free_custom_wave(custom_wave);
00206     return NULL;
00207   }
00208 
00209   if (insert_param(param, custom_wave->param_tree) < 0) {
00210     free_custom_wave(custom_wave);
00211     return NULL;
00212   }
00213 
00214   if ((param = new_param_int("sep", P_FLAG_NONE, &custom_wave->sep, 100, -100, 0)) == NULL) {
00215     free_custom_wave(custom_wave);
00216     return NULL;
00217   }
00218 
00219   if (insert_param(param, custom_wave->param_tree) < 0) {
00220     free_custom_wave(custom_wave);
00221     return NULL;
00222   }
00223 
00224   if ((param = new_param_bool("bSpectrum", P_FLAG_NONE, &custom_wave->bSpectrum, 1, 0, 0)) == NULL) {
00225     free_custom_wave(custom_wave);
00226     return NULL;
00227   }
00228 
00229   if (insert_param(param, custom_wave->param_tree) < 0) {
00230     free_custom_wave(custom_wave);
00231     return NULL;
00232   }
00233 
00234   if ((param = new_param_bool("bDrawThick", P_FLAG_NONE, &custom_wave->bDrawThick, 1, 0, 0)) == NULL) {
00235     free_custom_wave(custom_wave);
00236     return NULL;
00237   }
00238 
00239   if (insert_param(param, custom_wave->param_tree) < 0) {
00240     free_custom_wave(custom_wave);
00241     return NULL;
00242   }
00243 
00244   if ((param = new_param_bool("bUseDots", P_FLAG_NONE, &custom_wave->bUseDots, 1, 0, 0)) == NULL) {
00245     free_custom_wave(custom_wave);
00246     return NULL;
00247   }
00248 
00249   if (insert_param(param, custom_wave->param_tree) < 0) {
00250     free_custom_wave(custom_wave);
00251     return NULL;
00252   }
00253  
00254   if ((param = new_param_bool("bAdditive", P_FLAG_NONE, &custom_wave->bAdditive, 1, 0, 0)) == NULL) {
00255     free_custom_wave(custom_wave);
00256     return NULL;
00257   }
00258 
00259   if (insert_param(param, custom_wave->param_tree) < 0) {
00260     free_custom_wave(custom_wave);
00261     return NULL;
00262   }
00263 
00264   if ((param = new_param_int("samples", P_FLAG_NONE, &custom_wave->samples, 2048, 1, 512)) == NULL) {
00265     free_custom_wave(custom_wave);
00266     return NULL;
00267   }
00268  
00269   if (insert_param(param, custom_wave->param_tree) < 0) {
00270     free_custom_wave(custom_wave);
00271     return NULL;
00272   }
00273 
00274   if ((param = new_param_double("sample", P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT,
00275                                 &custom_wave->sample, custom_wave->sample_mesh, 1.0, 0.0, 0.0)) == NULL) {
00276     free_custom_wave(custom_wave);
00277     return NULL;
00278   }
00279  
00280  if (insert_param(param, custom_wave->param_tree) < 0) {
00281     printf("failed to insert sample\n");
00282     free_custom_wave(custom_wave);
00283     return NULL;
00284   }
00285 
00286   if ((param = new_param_double("value1", P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT, &custom_wave->v1, custom_wave->value1, 1.0, -1.0, 0.0)) == NULL) {
00287     free_custom_wave(custom_wave);
00288     return NULL;
00289   }
00290 
00291   if (insert_param(param, custom_wave->param_tree) < 0) {
00292     free_custom_wave(custom_wave);
00293     return NULL;
00294   }
00295 
00296   if ((param = new_param_double("value2", P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT, &custom_wave->v2, custom_wave->value2, 1.0, -1.0, 0.0)) == NULL) {
00297     free_custom_wave(custom_wave);
00298     return NULL;
00299   }
00300 
00301   if (insert_param(param, custom_wave->param_tree) < 0) {
00302     free_custom_wave(custom_wave);
00303     return NULL;
00304   }
00305 
00306   if ((param = new_param_double("smoothing", P_FLAG_NONE, &custom_wave->smoothing, NULL, 1.0, 0.0, 0.0)) == NULL) {
00307     free_custom_wave(custom_wave);
00308     return NULL;
00309   }
00310 
00311   if (insert_param(param, custom_wave->param_tree) < 0) {
00312     free_custom_wave(custom_wave);
00313     return NULL;
00314   }
00315 
00316   if ((param = new_param_double("scaling", P_FLAG_NONE, &custom_wave->scaling, NULL, MAX_DOUBLE_SIZE, 0.0, 1.0)) == NULL) {
00317     free_custom_wave(custom_wave);
00318     return NULL;
00319   }
00320 
00321   if (insert_param(param, custom_wave->param_tree) < 0) {
00322     free_custom_wave(custom_wave);
00323     return NULL;
00324   }
00325  
00326   if ((param = new_param_double("t1", P_FLAG_PER_POINT | P_FLAG_TVAR, &custom_wave->t1, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) {
00327     free_custom_wave(custom_wave);
00328     return NULL;
00329   }
00330 
00331   if (insert_param(param, custom_wave->param_tree) < 0) {
00332     free_custom_wave(custom_wave);
00333     return NULL;
00334   }
00335 
00336   if ((param = new_param_double("t2",  P_FLAG_PER_POINT |P_FLAG_TVAR, &custom_wave->t2, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) {
00337     free_custom_wave(custom_wave);
00338     return NULL;
00339   }
00340 
00341   if (insert_param(param, custom_wave->param_tree) < 0) {
00342     free_custom_wave(custom_wave);
00343     return NULL;
00344   }
00345 
00346   if ((param = new_param_double("t3",  P_FLAG_PER_POINT |P_FLAG_TVAR, &custom_wave->t3, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) {
00347     free_custom_wave(custom_wave);
00348     return NULL;
00349   }
00350 
00351   if (insert_param(param, custom_wave->param_tree) < 0) {
00352     free_custom_wave(custom_wave);
00353     return NULL;
00354   }
00355   if ((param = new_param_double("t4",  P_FLAG_PER_POINT |P_FLAG_TVAR, &custom_wave->t4, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) {
00356     free_custom_wave(custom_wave);
00357     return NULL;
00358   }
00359 
00360   if (insert_param(param, custom_wave->param_tree) < 0) {
00361     free_custom_wave(custom_wave);
00362     return NULL;
00363   }
00364   if ((param = new_param_double("t5", P_FLAG_TVAR, &custom_wave->t5, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) {
00365     free_custom_wave(custom_wave);
00366     return NULL;
00367   }
00368  
00369   if (insert_param(param, custom_wave->param_tree) < 0) {
00370     free_custom_wave(custom_wave);
00371     return NULL;
00372   }
00373   if ((param = new_param_double("t6", P_FLAG_TVAR | P_FLAG_PER_POINT, &custom_wave->t6, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) {
00374     free_custom_wave(custom_wave);
00375     return NULL;
00376   }
00377 
00378   if (insert_param(param, custom_wave->param_tree) < 0) {
00379     free_custom_wave(custom_wave);
00380     return NULL;
00381   }
00382   if ((param = new_param_double("t7", P_FLAG_TVAR | P_FLAG_PER_POINT, &custom_wave->t7, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) {
00383     free_custom_wave(custom_wave);
00384     return NULL;
00385   }
00386 
00387   if (insert_param(param, custom_wave->param_tree) < 0) {
00388     free_custom_wave(custom_wave);
00389     return NULL;
00390   }
00391 
00392   if ((param = new_param_double("t8", P_FLAG_TVAR | P_FLAG_PER_POINT, &custom_wave->t8, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) {
00393     free_custom_wave(custom_wave);
00394     return NULL;
00395   }
00396 
00397   if (insert_param(param, custom_wave->param_tree) < 0) {
00398     free_custom_wave(custom_wave);
00399     return NULL;
00400   }
00401   
00402   /* End of parameter loading. Note that the read only parameters associated
00403      with custom waves (ie, sample) are global variables, and not specific to 
00404      the custom wave datastructure. */
00405 
00406 
00407   return custom_wave;
00408 
00409 }
00410 
00411 void destroy_per_frame_init_eqn_tree(splaytree_t * tree) {
00412 
00413   if (!tree)
00414     return;
00415 
00416   splay_traverse(free_init_cond, tree);
00417   destroy_splaytree(tree);
00418 
00419 }
00420 
00421 
00422 void destroy_per_point_eqn_tree(splaytree_t * tree) {
00423 
00424   if (!tree)
00425     return;
00426 
00427   splay_traverse(free_per_point_eqn, tree);
00428   destroy_splaytree(tree);
00429 
00430 }
00431 
00432 void destroy_init_cond_tree(splaytree_t * tree) {
00433 
00434   if (!tree)
00435     return;
00436 
00437   splay_traverse(free_init_cond, tree);
00438   destroy_splaytree(tree);
00439 
00440 }
00441 
00442 void destroy_per_frame_eqn_tree(splaytree_t * tree) {
00443 
00444 
00445   if (!tree)
00446     return;
00447 
00448   splay_traverse(free_per_frame_eqn, tree);
00449   destroy_splaytree(tree);
00450 
00451 }
00452 
00453 
00454 void destroy_param_db_tree(splaytree_t * tree) {
00455 
00456   if (!tree)
00457     return;
00458 
00459   splay_traverse(free_param, tree);
00460   destroy_splaytree(tree);
00461 
00462 }
00463 
00464 /* Frees a custom wave form object */
00465 void free_custom_wave(custom_wave_t * custom_wave) {
00466 
00467   if (custom_wave == NULL)
00468     return;
00469 
00470   if (custom_wave->param_tree == NULL)
00471     return;
00472 
00473   destroy_per_point_eqn_tree(custom_wave->per_point_eqn_tree);
00474   destroy_per_frame_eqn_tree(custom_wave->per_frame_eqn_tree);
00475   destroy_init_cond_tree(custom_wave->init_cond_tree);
00476   destroy_param_db_tree(custom_wave->param_tree);
00477   destroy_per_frame_init_eqn_tree(custom_wave->per_frame_init_eqn_tree);
00478 
00479   free(custom_wave->r_mesh);
00480   free(custom_wave->g_mesh);
00481   free(custom_wave->b_mesh);
00482   free(custom_wave->a_mesh);
00483   free(custom_wave->x_mesh);
00484   free(custom_wave->y_mesh);
00485   free(custom_wave->value1);
00486   free(custom_wave->value2);
00487   free(custom_wave->sample_mesh);
00488 
00489   free(custom_wave);
00490 
00491   return;
00492 
00493 }
00494 
00495 
00496 
00497 int add_per_point_eqn(char * name, gen_expr_t * gen_expr, custom_wave_t * custom_wave) {
00498 
00499   per_point_eqn_t * per_point_eqn;
00500   int index;
00501   param_t * param = NULL;
00502 
00503   /* Argument checks */
00504   if (custom_wave == NULL)
00505           return FAILURE;
00506   if (gen_expr == NULL)
00507           return FAILURE;
00508   if (name == NULL)
00509           return FAILURE;
00510   
00511  if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: per pixel equation (name = \"%s\")\n", name);
00512 
00513  /* Search for the parameter so we know what matrix the per pixel equation is referencing */
00514 
00515  if ((param = find_param_db(name, custom_wave->param_tree, TRUE)) == NULL) {
00516    if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: failed to allocate a new parameter!\n");
00517    return FAILURE;
00518  
00519  }       
00520 
00521  /* Find most largest index in the splaytree */
00522  if ((per_point_eqn = splay_find_max(custom_wave->per_point_eqn_tree)) == NULL)
00523    index = 0;
00524  else
00525    index = per_point_eqn->index+1;
00526 
00527  /* Create the per pixel equation given the index, parameter, and general expression */
00528  if ((per_point_eqn = new_per_point_eqn(index, param, gen_expr)) == NULL)
00529          return FAILURE;
00530  if (CUSTOM_WAVE_DEBUG) 
00531    printf("add_per_point_eqn: created new equation (index = %d) (name = \"%s\")\n", per_point_eqn->index, per_point_eqn->param->name);
00532  /* Insert the per pixel equation into the preset per pixel database */
00533  if (splay_insert(per_point_eqn, &per_point_eqn->index, custom_wave->per_point_eqn_tree) < 0) {
00534         free_per_point_eqn(per_point_eqn);
00535         return FAILURE;  
00536  }
00537          
00538  /* Done */ 
00539  return SUCCESS;
00540 }
00541 
00542 per_point_eqn_t * new_per_point_eqn(int index, param_t * param, gen_expr_t * gen_expr) {
00543 
00544         per_point_eqn_t * per_point_eqn;
00545         
00546         if (param == NULL)
00547                 return NULL;
00548         if (gen_expr == NULL)
00549                 return NULL;
00550 
00551         if ((per_point_eqn = (per_point_eqn_t*)malloc(sizeof(per_point_eqn_t))) == NULL)
00552                 return NULL;
00553 
00554       
00555         per_point_eqn->index = index;
00556         per_point_eqn->gen_expr = gen_expr;
00557         per_point_eqn->param = param;
00558         return per_point_eqn;   
00559 }
00560 
00561 
00562 void free_per_point_eqn(per_point_eqn_t * per_point_eqn) {
00563 
00564         if (per_point_eqn == NULL)
00565                 return;
00566         
00567         free_gen_expr(per_point_eqn->gen_expr);
00568         
00569         free(per_point_eqn);
00570         
00571         return;
00572 }
00573 
00574 custom_wave_t * find_custom_wave(int id, preset_t * preset, int create_flag) {
00575 
00576   custom_wave_t * custom_wave = NULL;
00577 
00578   if (preset == NULL)
00579     return NULL;
00580   
00581   if ((custom_wave = splay_find(&id, preset->custom_wave_tree)) == NULL) {
00582 
00583     if (CUSTOM_WAVE_DEBUG) { printf("find_custom_wave: creating custom wave (id = %d)...", id);fflush(stdout);}
00584 
00585     if (create_flag == FALSE) {
00586       if (CUSTOM_WAVE_DEBUG) printf("you specified not to (create flag = false), returning null\n");
00587        return NULL;
00588     }
00589 
00590     if ((custom_wave = new_custom_wave(id)) == NULL) {
00591       if (CUSTOM_WAVE_DEBUG) printf("failed...out of memory?\n");
00592       return NULL;
00593     }
00594 
00595     if  (CUSTOM_WAVE_DEBUG) {printf("success.Inserting..."); fflush(stdout);}
00596 
00597    if (splay_insert(custom_wave, &custom_wave->id, preset->custom_wave_tree) < 0) {
00598      if (CUSTOM_WAVE_DEBUG) printf("failed!\n");
00599      free_custom_wave(custom_wave);
00600      return NULL;
00601     }
00602  
00603    if (CUSTOM_WAVE_DEBUG) printf("done.\n");
00604   }
00605  
00606   return custom_wave;
00607 }
00608 
00609 inline void evalCustomWaveInitConditions() {
00610   splay_traverse(eval_custom_wave_init_conds, active_preset->custom_wave_tree);
00611 }
00612 
00613 inline void eval_custom_wave_init_conds(custom_wave_t * custom_wave) {
00614   splay_traverse(eval_init_cond, custom_wave->init_cond_tree);
00615   splay_traverse(eval_init_cond, custom_wave->per_frame_init_eqn_tree);
00616 }
00617 
00618 /* Interface function. Makes another custom wave the current
00619    concern for per frame / point equations */
00620 inline custom_wave_t * nextCustomWave() {
00621 
00622   if ((interface_wave = splay_find(&interface_id, active_preset->custom_wave_tree)) == NULL) {
00623     interface_id = 0;
00624     return NULL;
00625   }
00626 
00627   interface_id++;
00628 
00629   /* Evaluate all per frame equations associated with this wave */
00630   splay_traverse(eval_per_frame_eqn, interface_wave->per_frame_eqn_tree);
00631   return interface_wave;
00632 }
00633 
00634 
00635 inline void evalPerPointEqns() { 
00636 
00637   int x;
00638 
00639   for (x = 0; x < interface_wave->samples; x++)
00640     interface_wave->r_mesh[x] = interface_wave->r;
00641   for (x = 0; x < interface_wave->samples; x++)
00642     interface_wave->g_mesh[x] = interface_wave->g;
00643   for (x = 0; x < interface_wave->samples; x++)
00644     interface_wave->b_mesh[x] = interface_wave->b;
00645   for (x = 0; x < interface_wave->samples; x++)
00646     interface_wave->a_mesh[x] = interface_wave->a;
00647   for (x = 0; x < interface_wave->samples; x++)
00648     interface_wave->x_mesh[x] = interface_wave->x;
00649   for (x = 0; x < interface_wave->samples; x++)
00650     interface_wave->y_mesh[x] = interface_wave->y;
00651 
00652  
00653   /* Evaluate per pixel equations */
00654   splay_traverse(evalPerPointEqn, interface_wave->per_point_eqn_tree);
00655 
00656   /* Reset index */
00657   mesh_i = -1;
00658 }
00659 
00660 /* Evaluates a per point equation for the current custom wave given by interface_wave ptr */
00661 inline void evalPerPointEqn(per_point_eqn_t * per_point_eqn) {
00662   
00663   
00664   int samples, size;
00665   double * param_matrix;
00666   gen_expr_t * eqn_ptr;
00667 
00668   samples = interface_wave->samples;
00669   eqn_ptr = per_point_eqn->gen_expr;
00670  
00671   if (per_point_eqn->param->matrix == NULL) {
00672     if ((param_matrix = per_point_eqn->param->matrix = malloc(size = samples*sizeof(double))) == NULL)
00673       return;
00674     memset(param_matrix, 0, size);
00675   }
00676   else 
00677     param_matrix = (double*)per_point_eqn->param->matrix;
00678   
00679   for (mesh_i = 0; mesh_i < samples; mesh_i++) {    
00680       param_matrix[mesh_i] = eval_gen_expr(eqn_ptr);
00681   }
00682   
00683   /* Now that this parameter has been referenced with a per
00684      point equation, we let the evaluator know by setting
00685      this flag */
00686   per_point_eqn->param->matrix_flag = 1; 
00687 
00688 }
00689 
00690 
00691 void load_unspecified_init_conds(custom_wave_t * custom_wave) {
00692 
00693   interface_wave = custom_wave;
00694   splay_traverse(load_unspec_init_cond, interface_wave->param_tree);
00695   interface_wave = NULL;
00696  
00697 }
00698 
00699 void load_unspec_init_cond(param_t * param) {
00700 
00701   init_cond_t * init_cond;
00702   value_t init_val;
00703 
00704   /* Don't count these parameters as initial conditions */
00705   if (param->flags & P_FLAG_READONLY)
00706     return;
00707   if (param->flags & P_FLAG_QVAR)
00708     return;
00709   if (param->flags & P_FLAG_TVAR)
00710     return;
00711   if (param->flags & P_FLAG_USERDEF)
00712     return;
00713 
00714   /* If initial condition was not defined by the preset file, force a default one
00715      with the following code */
00716   if ((init_cond = splay_find(param->name, interface_wave->init_cond_tree)) == NULL) {
00717     
00718     /* Make sure initial condition does not exist in the set of per frame initial equations */
00719     if ((init_cond = splay_find(param->name, interface_wave->per_frame_init_eqn_tree)) != NULL)
00720       return;
00721     
00722     if (param->type == P_TYPE_BOOL)
00723       init_val.bool_val = 0;
00724     
00725     else if (param->type == P_TYPE_INT)
00726       init_val.int_val = *(int*)param->engine_val;
00727 
00728     else if (param->type == P_TYPE_DOUBLE)
00729       init_val.double_val = *(double*)param->engine_val;
00730 
00731     //printf("%s\n", param->name);
00732     /* Create new initial condition */
00733     if ((init_cond = new_init_cond(param, init_val)) == NULL)
00734       return;
00735     
00736     /* Insert the initial condition into this presets tree */
00737     if (splay_insert(init_cond, init_cond->param->name, interface_wave->init_cond_tree) < 0) {
00738       free_init_cond(init_cond);
00739       return;
00740     }
00741     
00742   }
00743  
00744 }

Generated on Tue Dec 20 10:14:56 2005 for vlc-0.8.4a by  doxygen 1.4.2