00001 /***************************************************************************** 00002 * per_frame_eqn.c: 00003 ***************************************************************************** 00004 * Copyright (C) 2004 the VideoLAN team 00005 * $Id: per_frame_eqn.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 <stdlib.h> 00029 #include <string.h> 00030 00031 #include "fatal.h" 00032 #include "common.h" 00033 #include "per_frame_eqn_types.h" 00034 #include "per_frame_eqn.h" 00035 00036 #include "expr_types.h" 00037 #include "eval.h" 00038 00039 /* Evaluate an equation */ 00040 void eval_per_frame_eqn(per_frame_eqn_t * per_frame_eqn) { 00041 00042 if (per_frame_eqn == NULL) 00043 return; 00044 00045 if (PER_FRAME_EQN_DEBUG) { 00046 printf("per_frame_%d=%s= ", per_frame_eqn->index, per_frame_eqn->param->name); 00047 fflush(stdout); 00048 } 00049 00050 //*((double*)per_frame_eqn->param->engine_val) = eval_gen_expr(per_frame_eqn->gen_expr); 00051 set_param(per_frame_eqn->param, eval_gen_expr(per_frame_eqn->gen_expr)); 00052 if (PER_FRAME_EQN_DEBUG) printf(" = %.4f\n", *((double*)per_frame_eqn->param->engine_val)); 00053 00054 } 00055 00056 /* 00057 void eval_per_frame_init_eqn(per_frame_eqn_t * per_frame_eqn) { 00058 00059 double val; 00060 init_cond_t * init_cond; 00061 if (per_frame_eqn == NULL) 00062 return; 00063 00064 if (PER_FRAME_EQN_DEBUG) { 00065 printf("per_frame_init: %s = ", per_frame_eqn->param->name); 00066 fflush(stdout); 00067 } 00068 00069 00070 val = *((double*)per_frame_eqn->param->engine_val) = eval_gen_expr(per_frame_eqn->gen_expr); 00071 if (PER_FRAME_EQN_DEBUG) printf(" = %f\n", *((double*)per_frame_eqn->param->engine_val)); 00072 00073 if (per_frame_eqn->param->flags & P_FLAG_QVAR) { 00074 00075 per_frame_eqn->param->init_val.double_val = val; 00076 if ((init_cond = new_init_cond(per_frame_eqn->param)) == NULL) 00077 return; 00078 00079 if ((list_append(init_cond_list, init_cond)) < 0) { 00080 free_init_cond(init_cond); 00081 return; 00082 } 00083 } 00084 } 00085 */ 00086 00087 /* Frees perframe equation structure */ 00088 void free_per_frame_eqn(per_frame_eqn_t * per_frame_eqn) { 00089 00090 if (per_frame_eqn == NULL) 00091 return; 00092 00093 free_gen_expr(per_frame_eqn->gen_expr); 00094 free(per_frame_eqn); 00095 } 00096 00097 /* Create a new per frame equation */ 00098 per_frame_eqn_t * new_per_frame_eqn(int index, param_t * param, gen_expr_t * gen_expr) { 00099 00100 per_frame_eqn_t * per_frame_eqn; 00101 00102 per_frame_eqn = (per_frame_eqn_t*)malloc(sizeof(per_frame_eqn_t)); 00103 00104 if (per_frame_eqn == NULL) 00105 return NULL; 00106 00107 per_frame_eqn->param = param; 00108 per_frame_eqn->gen_expr = gen_expr; 00109 per_frame_eqn->index = index; 00110 /* Set per frame eqn name */ 00111 // memset(per_frame_eqn->name, 0, MAX_TOKEN_SIZE); 00112 //strncpy(per_frame_eqn->name, name, MAX_TOKEN_SIZE-1); 00113 return per_frame_eqn; 00114 00115 }