custom_wave_t * find_custom_wave(int id, preset_t * preset, int create_flag) { custom_wave_t * custom_wave = NULL; if (preset == NULL) return NULL; if ((custom_wave = splay_find(&id, preset->custom_wave_tree)) == NULL) { if (CUSTOM_WAVE_DEBUG) { printf("find_custom_wave: creating custom wave (id = %d)...", id);fflush(stdout);} if (create_flag == FALSE) { if (CUSTOM_WAVE_DEBUG) printf("you specified not to (create flag = false), returning null\n"); return NULL; } if ((custom_wave = new_custom_wave(id)) == NULL) { if (CUSTOM_WAVE_DEBUG) printf("failed...out of memory?\n"); return NULL; } if (CUSTOM_WAVE_DEBUG) {printf("success.Inserting..."); fflush(stdout);} if (splay_insert(custom_wave, &custom_wave->id, preset->custom_wave_tree) < 0) { if (CUSTOM_WAVE_DEBUG) printf("failed!\n"); free_custom_wave(custom_wave); return NULL; } if (CUSTOM_WAVE_DEBUG) printf("done.\n"); } return custom_wave; }
void load_unspec_init_cond(param_t * param) { init_cond_t * init_cond; value_t init_val; /* Don't count these parameters as initial conditions */ if (param->flags & P_FLAG_READONLY) return; if (param->flags & P_FLAG_QVAR) return; if (param->flags & P_FLAG_TVAR) return; if (param->flags & P_FLAG_USERDEF) return; /* If initial condition was not defined by the preset file, force a default one with the following code */ if ((init_cond = splay_find(param->name, interface_wave->init_cond_tree)) == NULL) { /* Make sure initial condition does not exist in the set of per frame initial equations */ if ((init_cond = splay_find(param->name, interface_wave->per_frame_init_eqn_tree)) != NULL) 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.double_val = *(double*)param->engine_val; //printf("%s\n", param->name); /* Create new initial condition */ if ((init_cond = new_init_cond(param, init_val)) == NULL) return; /* Insert the initial condition into this presets tree */ if (splay_insert(init_cond, init_cond->param->name, interface_wave->init_cond_tree) < 0) { free_init_cond(init_cond); return; } } }
/* Find a parameter given its name, will create one if not found */ param_t * find_param(char * name, preset_t * preset, int flags) { param_t * param = NULL; /* Null argument checks */ if (name == NULL) return NULL; if (preset == NULL) return NULL; /* First look in the builtin database */ param = (param_t *)splay_find(name, builtin_param_tree); /* If the search failed, check the user database */ if (param == NULL) { param = (param_t*)splay_find(name, preset->user_param_tree); } /* 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 (!is_valid_param_string(name)) { if (PARAM_DEBUG) printf("find_param: invalid parameter name:\"%s\"\n", name); return NULL; } /* Now, create the user defined parameter given the passed name */ if ((param = create_user_param(name)) == NULL) { if (PARAM_DEBUG) printf("find_param: failed to create a new user parameter!\n"); return NULL; } /* Finally, insert the new parameter into this preset's proper splaytree */ if (splay_insert(param, param->name, preset->user_param_tree) < 0) { if (PARAM_DEBUG) printf("PARAM \"%s\" already exists in user parameter tree!\n", param->name); free_param(param); return NULL; } } /* Return the found (or created) parameter. Note that if P_CREATE is not set, this could be null */ return param; }
param_t * find_builtin_param(char * name) { /* Null argument checks */ if (name == NULL) return NULL; return splay_find(name, builtin_param_tree); }
/* Interface function. Makes another custom wave the current concern for per frame / point equations */ custom_wave_t * nextCustomWave() { if ((interface_wave = splay_find(&interface_id, active_preset->custom_wave_tree)) == NULL) { interface_id = 0; return NULL; } interface_id++; /* Evaluate all per frame equations associated with this wave */ splay_traverse(eval_per_frame_eqn, interface_wave->per_frame_eqn_tree); return interface_wave; }
/* Search for parameter 'name' in 'database', if create_flag is true, then generate the parameter and insert it into 'database' */ param_t * find_param_db(char * name, splaytree_t * database, int create_flag) { param_t * param = NULL; /* Null argument checks */ if (name == NULL) return NULL; if (database == NULL) return NULL; /* First look in the builtin database */ param = (param_t *)splay_find(name, database); if (((param = (param_t *)splay_find(name, database)) == NULL) && (create_flag == TRUE)) { /* Check if string is valid */ if (!is_valid_param_string(name)) return NULL; /* Now, create the user defined parameter given the passed name */ if ((param = create_user_param(name)) == NULL) return NULL; /* Finally, insert the new parameter into this preset's proper splaytree */ if (splay_insert(param, param->name, database) < 0) { free_param(param); return NULL; } } /* Return the found (or created) parameter. Note that this could be null */ return param; }
/* Returns the 'maximum' key that is less than the given key in the splaytree */ inline void * splay_find_below_max(void * key, splaytree_t * splaytree) { void * closest_key; if (splaytree == NULL) return NULL; if (splaytree->root == NULL) return NULL; if (key == NULL) return NULL; closest_key = NULL; splay_find_below_max_helper(key, &closest_key, splaytree->root, splaytree->compare); if (closest_key == NULL) return NULL; return splay_find(closest_key, splaytree); }
/* Returns the 'minimum' key that is greater than the given key in the splaytree */ inline void * splay_find_above_min(void * key, splaytree_t * splaytree) { void * closest_key; if (splaytree == NULL) return NULL; if (splaytree->root == NULL) return NULL; if (key == NULL) return NULL; closest_key = NULL; splay_find_above_min_helper(key, &closest_key, splaytree->root, splaytree->compare); if (closest_key == NULL) { return NULL; } return splay_find(closest_key, splaytree); }
int switchPreset(switch_mode_t switch_mode, int cut_type) { preset_t * new_preset; int switch_index; /* Make sure a preset directory list is in the buffer */ if (chrono_order_preset_name_tree == NULL) { if (PRESET_DEBUG) printf("switchPreset: it helps if you open a directory first with a loadPresetDir() call\n"); return ERROR; } switch (switch_mode) { case ALPHA_NEXT: /* An index variable that iterates through the directory buffer, doing wrap around when it reaches the end of the buffer */ if (preset_index == (preset_name_buffer_size - 1)) switch_index = preset_index = 0; else switch_index = ++preset_index; break; case ALPHA_PREVIOUS: if (preset_index == 0) switch_index = preset_index = preset_name_buffer_size - 1; else switch_index = --preset_index; break; case RANDOM_NEXT: switch_index = (int) (preset_name_buffer_size*(rand()/(RAND_MAX+1.0))); break; case RESTART_ACTIVE: switch_index = preset_index; break; default: return FAILURE; } /* Finally, load the preset using its actual path */ if ((new_preset = load_preset((char*)splay_find(&switch_index, chrono_order_preset_name_tree))) == NULL) { if (PRESET_DEBUG) printf("switchPreset: failed to load preset\n"); return ERROR; } /* Closes a preset currently loaded, if any */ if ((active_preset != NULL) && (active_preset != idle_preset)) close_preset(active_preset); /* Sets global active_preset pointer */ active_preset = new_preset; /* Reinitialize the engine variables to sane defaults */ reset_engine_vars(); /* Add any missing initial conditions */ load_init_conditions(); /* Add any missing initial conditions for each wave */ load_custom_wave_init_conditions(); /* Add any missing initial conditions for each shape */ load_custom_shape_init_conditions(); /* Need to evaluate the initial conditions once */ evalInitConditions(); // evalInitPerFrameEquations(); return SUCCESS; }