Ejemplo n.º 1
0
Archivo: param.c Proyecto: Kafay/vlc
/* Inserts a parameter into the builtin database */
int insert_builtin_param(param_t * param) {

	if (param == NULL)
		return FAILURE;
	
	return splay_insert(param, param->name, builtin_param_tree);	
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
Archivo: param.c Proyecto: Kafay/vlc
/* Inserts a parameter into the builtin database */
int insert_param(param_t * param, splaytree_t * database) {

	if (param == NULL)
	  return FAILURE;
	if (database == NULL)
	  return FAILURE;

	return splay_insert(param, param->name, database);	
}
Ejemplo n.º 4
0
void reloadPerFrame(char * s, preset_t * preset) {

  FILE * fs;
  int slen;
  char c;
  int eqn_count = 1;
  per_frame_eqn_t * per_frame;

  if (s == NULL)
    return;

  if (preset == NULL)
    return;

  /* Clear previous per frame equations */
  splay_traverse(free_per_frame_eqn, preset->per_frame_eqn_tree);
  destroy_splaytree(preset->per_frame_eqn_tree);
  preset->per_frame_eqn_tree = create_splaytree(compare_int, copy_int, free_int);

  /* Convert string to a stream */
  fs = fmemopen (s, strlen(s), "r");

  while ((c = fgetc(fs)) != EOF) {
    ungetc(c, fs);
    if ((per_frame = parse_per_frame_eqn(fs, eqn_count, preset)) != NULL) {
      splay_insert(per_frame, &eqn_count, preset->per_frame_eqn_tree);
      eqn_count++;
    }
  }

  fclose(fs);

  /* Clear string space */
  memset(preset->per_frame_eqn_string_buffer, 0, STRING_BUFFER_SIZE);

  /* Compute length of string */
  slen = strlen(s);

  /* Copy new string into buffer */
  strncpy(preset->per_frame_eqn_string_buffer, s, slen);

  /* Yet again no bounds checking */
  preset->per_frame_eqn_string_index = slen;

  /* Finished */
  printf("reloadPerFrame: %d eqns parsed succesfully\n", eqn_count-1);
  return;

}
Ejemplo n.º 5
0
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;
    }
    
  }
 
}
Ejemplo n.º 6
0
Archivo: param.c Proyecto: Kafay/vlc
/* 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;
  
}
Ejemplo n.º 7
0
int add_per_point_eqn(char * name, gen_expr_t * gen_expr, custom_wave_t * custom_wave) {

  per_point_eqn_t * per_point_eqn;
  int index;
  param_t * param = NULL;

  /* Argument checks */
  if (custom_wave == NULL)
	  return FAILURE;
  if (gen_expr == NULL)
	  return FAILURE;
  if (name == NULL)
	  return FAILURE;
  
 if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: per pixel equation (name = \"%s\")\n", name);

 /* Search for the parameter so we know what matrix the per pixel equation is referencing */

 if ((param = find_param_db(name, custom_wave->param_tree, TRUE)) == NULL) {
   if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: failed to allocate a new parameter!\n");
   return FAILURE;
 
 } 	 

 /* Find most largest index in the splaytree */
 if ((per_point_eqn = splay_find_max(custom_wave->per_point_eqn_tree)) == NULL)
   index = 0;
 else
   index = per_point_eqn->index+1;

 /* Create the per pixel equation given the index, parameter, and general expression */
 if ((per_point_eqn = new_per_point_eqn(index, param, gen_expr)) == NULL)
	 return 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);
 /* Insert the per pixel equation into the preset per pixel database */
 if (splay_insert(per_point_eqn, &per_point_eqn->index, custom_wave->per_point_eqn_tree) < 0) {
	free_per_point_eqn(per_point_eqn);
	return FAILURE;	 
 }
	 
 /* Done */ 
 return SUCCESS;
}
Ejemplo n.º 8
0
Archivo: param.c Proyecto: Kafay/vlc
/* 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;

}
Ejemplo n.º 9
0
int add_per_pixel_eqn(char * name, gen_expr_t * gen_expr, preset_t * preset) {

    per_pixel_eqn_t * per_pixel_eqn;
    int index;
    param_t * param = NULL;

    /* Argument checks */
    if (preset == NULL)
        return FAILURE;
    if (gen_expr == NULL)
        return FAILURE;
    if (name == NULL)
        return FAILURE;

    if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: per pixel equation (name = \"%s\")\n", name);

    if (!strncmp(name, "dx", strlen("dx")))
        preset->per_pixel_flag[DX_OP] = TRUE;
    else if (!strncmp(name, "dy", strlen("dy")))
        preset->per_pixel_flag[DY_OP] = TRUE;
    else if (!strncmp(name, "cx", strlen("cx")))
        preset->per_pixel_flag[CX_OP] = TRUE;
    else if (!strncmp(name, "cy", strlen("cy")))
        preset->per_pixel_flag[CX_OP] = TRUE;
    else if (!strncmp(name, "zoom", strlen("zoom")))
        preset->per_pixel_flag[ZOOM_OP] = TRUE;
    else if (!strncmp(name, "zoomexp", strlen("zoomexp")))
        preset->per_pixel_flag[ZOOMEXP_OP] = TRUE;
    else if (!strncmp(name, "rot", strlen("rot")))
        preset->per_pixel_flag[ROT_OP] = TRUE;
    else if (!strncmp(name, "sx", strlen("sx")))
        preset->per_pixel_flag[SX_OP] = TRUE;
    else if (!strncmp(name, "sy", strlen("sy")))
        preset->per_pixel_flag[SY_OP] = TRUE;


    /* Search for the parameter so we know what matrix the per pixel equation is referencing */

    if ((param = find_param(name, preset, TRUE)) == NULL) {
        if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: failed to allocate a new parameter!\n");
        return FAILURE;

    }

    /* Find most largest index in the splaytree */
// if ((per_pixel_eqn = splay_find_max(active_preset->per_pixel_eqn_tree)) == NULL)
// index = 0;
// else
    index = splay_size(preset->per_pixel_eqn_tree);

    /* Create the per pixel equation given the index, parameter, and general expression */
    if ((per_pixel_eqn = new_per_pixel_eqn(index, param, gen_expr)) == NULL) {
        if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: failed to create new per pixel equation!\n");
        return FAILURE;

    }

    if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: new equation (index = %d) (param = \"%s\")\n",
                                        per_pixel_eqn->index, per_pixel_eqn->param->name);
    /* Insert the per pixel equation into the preset per pixel database */
    if (splay_insert(per_pixel_eqn, &per_pixel_eqn->index, preset->per_pixel_eqn_tree) < 0) {
        free_per_pixel_eqn(per_pixel_eqn);
        printf("failed to add per pixel eqn!\n");
        return FAILURE;
    }

    /* Done */
    return SUCCESS;
}
Ejemplo n.º 10
0
int loadPresetDir(char * dir) {

  struct dirent ** name_list;
  char * preset_name;
  int i, j, dir_size;
  
  if (dir == NULL)
	return ERROR;
 
  if (chrono_order_preset_name_tree != NULL) {
	if (PRESET_DEBUG) printf("loadPresetDir: previous directory doesn't appear to be closed!\n");
	/* Let this slide for now */
  }	
  
  /* Scan the entire directory, storing each entry in a dirent struct array that needs 
     to be freed later. For more information, consult scandir(3) in the man pages */
  if ((dir_size = scandir(dir, &name_list, 0, alphasort)) < 0) {
	if (PRESET_DEBUG) printf("loadPresetDir: failed to open directory \"%s\"\n", dir);
	return ERROR;
  }
  
  chrono_order_preset_name_tree = create_splaytree(compare_int, copy_int, free_int);
  
  /* Iterate through entire dirent name list, adding to the preset name list if it
     is valid */  
  for (i = 0; ((i < dir_size) && (i < MAX_PRESETS_IN_DIR));i++) {

	/* Only perform the next set of operations if the preset name 
	   contains a valid extension */
	if (is_valid_extension(name_list[i]->d_name)) {
		
		/* Handle the out of memory case. My guess is xmms would
		   crash before this program would, but whatever...*/
		if ((preset_name = (char*)malloc(MAX_PATH_SIZE)) == NULL) {
			if (PRESET_DEBUG) printf("loadPresetDir: out of memory! \n");
			
			/* Free the rest of the dirent name list */
			for (j = i; j < dir_size; j++) 
				free(name_list[j]);
			destroy_splaytree(chrono_order_preset_name_tree);
			return OUTOFMEM_ERROR;
		}
				
		/* Now create the full path */
	    if (get_preset_path(&preset_name, dir, name_list[i]->d_name) < 0) {
			if (PRESET_DEBUG) printf("loadPresetDir: failed to generate full preset path name!\n");
			
			/* Free the rest of the dirent name list */
			for (j = i; j < dir_size; j++) 
				free(name_list[j]);
			destroy_splaytree(chrono_order_preset_name_tree);
			return OUTOFMEM_ERROR;
			
		}
		
		/* Insert the character string into the splay tree, with the key being its sequence number */
		splay_insert(preset_name, &preset_name_buffer_size, chrono_order_preset_name_tree);
		preset_name_buffer_size++;
	}
	
	/* Free the dirent struct */
	free(name_list[i]);
	
  }	
  
  free(name_list);
  
  /* No valid files in directory! */
  if (chrono_order_preset_name_tree->root == NULL) {
	if (PRESET_DEBUG) printf("loadPresetDir: no valid files in directory \"%s\"\n", dir);
	destroy_splaytree(chrono_order_preset_name_tree);
	chrono_order_preset_name_tree = NULL;
	return FAILURE;	  
  }	
  	  
  /* Start the prefix index right before the first entry, so next preset
     starts at the top of the list */
  preset_index = -1;
  
  /* Start the first preset */

  switchPreset(ALPHA_NEXT, HARD_CUT);
  
  return SUCCESS;
}