mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-01-31 13:40:35 +00:00
refactor fluid_settings API
consistently return either FLUID_OK or FLUID_FAILED for public fluid_settings_* functions
This commit is contained in:
parent
9735059946
commit
e797853b2b
4 changed files with 307 additions and 233 deletions
|
@ -123,7 +123,7 @@ FLUIDSYNTH_API
|
|||
int fluid_settings_get_type(fluid_settings_t* settings, const char *name);
|
||||
|
||||
FLUIDSYNTH_API
|
||||
int fluid_settings_get_hints(fluid_settings_t* settings, const char *name);
|
||||
int fluid_settings_get_hints(fluid_settings_t* settings, const char *name, int* val);
|
||||
|
||||
FLUIDSYNTH_API
|
||||
int fluid_settings_is_realtime(fluid_settings_t* settings, const char *name);
|
||||
|
@ -150,10 +150,10 @@ FLUIDSYNTH_API
|
|||
int fluid_settings_getnum(fluid_settings_t* settings, const char *name, double* val);
|
||||
|
||||
FLUIDSYNTH_API
|
||||
double fluid_settings_getnum_default(fluid_settings_t* settings, const char *name);
|
||||
int fluid_settings_getnum_default(fluid_settings_t* settings, const char *name, double* val);
|
||||
|
||||
FLUIDSYNTH_API
|
||||
void fluid_settings_getnum_range(fluid_settings_t* settings, const char *name,
|
||||
int fluid_settings_getnum_range(fluid_settings_t* settings, const char *name,
|
||||
double* min, double* max);
|
||||
|
||||
FLUIDSYNTH_API
|
||||
|
@ -163,10 +163,10 @@ FLUIDSYNTH_API
|
|||
int fluid_settings_getint(fluid_settings_t* settings, const char *name, int* val);
|
||||
|
||||
FLUIDSYNTH_API
|
||||
int fluid_settings_getint_default(fluid_settings_t* settings, const char *name);
|
||||
int fluid_settings_getint_default(fluid_settings_t* settings, const char *name, int* val);
|
||||
|
||||
FLUIDSYNTH_API
|
||||
void fluid_settings_getint_range(fluid_settings_t* settings, const char *name,
|
||||
int fluid_settings_getint_range(fluid_settings_t* settings, const char *name,
|
||||
int* min, int* max);
|
||||
|
||||
/**
|
||||
|
|
|
@ -1298,15 +1298,14 @@ fluid_handle_set(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out)
|
|||
fluid_ostream_printf (out, "set: Parameter '%s' not found.\n", av[0]);
|
||||
break;
|
||||
case FLUID_INT_TYPE:
|
||||
hints = fluid_settings_get_hints (synth->settings, av[0]);
|
||||
|
||||
if (hints & FLUID_HINT_TOGGLED)
|
||||
if (fluid_settings_get_hints (synth->settings, av[0], &hints) == FLUID_OK
|
||||
&& hints & FLUID_HINT_TOGGLED)
|
||||
{
|
||||
if (FLUID_STRCMP (av[1], "yes") == 0 || FLUID_STRCMP (av[1], "True") == 0
|
||||
|| FLUID_STRCMP (av[1], "TRUE") == 0 || FLUID_STRCMP (av[1], "true") == 0
|
||||
|| FLUID_STRCMP (av[1], "T") == 0)
|
||||
if (FLUID_STRCMP (av[1], "yes") == 0 || FLUID_STRCMP (av[1], "True") == 0
|
||||
|| FLUID_STRCMP (av[1], "TRUE") == 0 || FLUID_STRCMP (av[1], "true") == 0
|
||||
|| FLUID_STRCMP (av[1], "T") == 0)
|
||||
ival = 1;
|
||||
else ival = atoi (av[1]);
|
||||
else ival = atoi (av[1]);
|
||||
}
|
||||
else ival = atoi (av[1]);
|
||||
|
||||
|
@ -1407,11 +1406,13 @@ static void fluid_handle_settings_iter2(void* data, char* name, int type)
|
|||
case FLUID_INT_TYPE: {
|
||||
int value, hints;
|
||||
fluid_synth_getint(d->synth, name, &value);
|
||||
hints = fluid_settings_get_hints (d->synth->settings, name);
|
||||
|
||||
if (!(hints & FLUID_HINT_TOGGLED))
|
||||
fluid_ostream_printf(d->out, "%d\n", value);
|
||||
else fluid_ostream_printf(d->out, "%s\n", value ? "True" : "False");
|
||||
|
||||
if(fluid_settings_get_hints (d->synth->settings, name, &hints) == FLUID_OK)
|
||||
{
|
||||
if (!(hints & FLUID_HINT_TOGGLED))
|
||||
fluid_ostream_printf(d->out, "%d\n", value);
|
||||
else fluid_ostream_printf(d->out, "%s\n", value ? "True" : "False");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1474,48 +1475,59 @@ fluid_handle_info(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out)
|
|||
return -1;
|
||||
|
||||
case FLUID_NUM_TYPE: {
|
||||
double value, min, max;
|
||||
fluid_settings_getnum_range(settings, av[0], &min, &max);
|
||||
fluid_settings_getnum(settings, av[0], &value);
|
||||
fluid_ostream_printf(out, "%s:\n", av[0]);
|
||||
fluid_ostream_printf(out, "Type: number\n");
|
||||
fluid_ostream_printf(out, "Value: %.3f\n", value);
|
||||
fluid_ostream_printf(out, "Minimum value: %.3f\n", min);
|
||||
fluid_ostream_printf(out, "Maximum value: %.3f\n", max);
|
||||
fluid_ostream_printf(out, "Default value: %.3f\n",
|
||||
fluid_settings_getnum_default(settings, av[0]));
|
||||
fluid_ostream_printf(out, "Real-time: %s\n",
|
||||
fluid_settings_is_realtime(settings, av[0])? "yes" : "no");
|
||||
double value, min, max, def;
|
||||
if(fluid_settings_getnum_range(settings, av[0], &min, &max) == FLUID_OK
|
||||
&& fluid_settings_getnum(settings, av[0], &value) == FLUID_OK
|
||||
&& fluid_settings_getnum_default(settings, av[0], &def) == FLUID_OK)
|
||||
{
|
||||
fluid_ostream_printf(out, "%s:\n", av[0]);
|
||||
fluid_ostream_printf(out, "Type: number\n");
|
||||
fluid_ostream_printf(out, "Value: %.3f\n", value);
|
||||
fluid_ostream_printf(out, "Minimum value: %.3f\n", min);
|
||||
fluid_ostream_printf(out, "Maximum value: %.3f\n", max);
|
||||
fluid_ostream_printf(out, "Default value: %.3f\n", def);
|
||||
fluid_ostream_printf(out, "Real-time: %s\n",
|
||||
fluid_settings_is_realtime(settings, av[0])? "yes" : "no");
|
||||
}
|
||||
else
|
||||
{
|
||||
fluid_ostream_printf(out, "An error occurred when processing %s\n", av[0]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case FLUID_INT_TYPE: {
|
||||
int value, min, max, def, hints;
|
||||
|
||||
fluid_settings_getint_range(settings, av[0], &min, &max);
|
||||
fluid_settings_getint(settings, av[0], &value);
|
||||
hints = fluid_settings_get_hints(settings, av[0]);
|
||||
def = fluid_settings_getint_default (settings, av[0]);
|
||||
|
||||
fluid_ostream_printf(out, "%s:\n", av[0]);
|
||||
|
||||
if (!(hints & FLUID_HINT_TOGGLED))
|
||||
if(fluid_settings_getint_range(settings, av[0], &min, &max) == FLUID_OK
|
||||
&& fluid_settings_getint(settings, av[0], &value) == FLUID_OK
|
||||
&& fluid_settings_get_hints(settings, av[0], &hints) == FLUID_OK
|
||||
&& fluid_settings_getint_default (settings, av[0], &def) == FLUID_OK)
|
||||
{
|
||||
fluid_ostream_printf(out, "Type: integer\n");
|
||||
fluid_ostream_printf(out, "Value: %d\n", value);
|
||||
fluid_ostream_printf(out, "Minimum value: %d\n", min);
|
||||
fluid_ostream_printf(out, "Maximum value: %d\n", max);
|
||||
fluid_ostream_printf(out, "Default value: %d\n", def);
|
||||
fluid_ostream_printf(out, "%s:\n", av[0]);
|
||||
|
||||
if (!(hints & FLUID_HINT_TOGGLED))
|
||||
{
|
||||
fluid_ostream_printf(out, "Type: integer\n");
|
||||
fluid_ostream_printf(out, "Value: %d\n", value);
|
||||
fluid_ostream_printf(out, "Minimum value: %d\n", min);
|
||||
fluid_ostream_printf(out, "Maximum value: %d\n", max);
|
||||
fluid_ostream_printf(out, "Default value: %d\n", def);
|
||||
}
|
||||
else
|
||||
{
|
||||
fluid_ostream_printf(out, "Type: boolean\n");
|
||||
fluid_ostream_printf(out, "Value: %s\n", value ? "True" : "False");
|
||||
fluid_ostream_printf(out, "Default value: %s\n", def ? "True" : "False");
|
||||
}
|
||||
|
||||
fluid_ostream_printf(out, "Real-time: %s\n",
|
||||
fluid_settings_is_realtime(settings, av[0])? "yes" : "no");
|
||||
}
|
||||
else
|
||||
{
|
||||
fluid_ostream_printf(out, "Type: boolean\n");
|
||||
fluid_ostream_printf(out, "Value: %s\n", value ? "True" : "False");
|
||||
fluid_ostream_printf(out, "Default value: %s\n", def ? "True" : "False");
|
||||
fluid_ostream_printf(out, "An error occurred when processing %s\n", av[0]);
|
||||
}
|
||||
|
||||
fluid_ostream_printf(out, "Real-time: %s\n",
|
||||
fluid_settings_is_realtime(settings, av[0])? "yes" : "no");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,9 +111,8 @@ void process_o_cmd_line_option(fluid_settings_t* settings, char* optarg)
|
|||
}
|
||||
break;
|
||||
case FLUID_INT_TYPE:
|
||||
hints = fluid_settings_get_hints (settings, optarg);
|
||||
|
||||
if (hints & FLUID_HINT_TOGGLED)
|
||||
if (fluid_settings_get_hints (settings, optarg, &hints) == FLUID_OK
|
||||
&& hints & FLUID_HINT_TOGGLED)
|
||||
{
|
||||
if (FLUID_STRCMP (val, "yes") == 0 || FLUID_STRCMP (val, "True") == 0
|
||||
|| FLUID_STRCMP (val, "TRUE") == 0 || FLUID_STRCMP (val, "true") == 0
|
||||
|
@ -184,14 +183,14 @@ settings_foreach_func (void *data, char *name, int type)
|
|||
{
|
||||
case FLUID_NUM_TYPE:
|
||||
fluid_settings_getnum_range (settings, name, &dmin, &dmax);
|
||||
ddef = fluid_settings_getnum_default (settings, name);
|
||||
fluid_settings_getnum_default (settings, name, &ddef);
|
||||
printf ("%-24s FLOAT [min=%0.3f, max=%0.3f, def=%0.3f]\n",
|
||||
name, dmin, dmax, ddef);
|
||||
break;
|
||||
case FLUID_INT_TYPE:
|
||||
fluid_settings_getint_range (settings, name, &imin, &imax);
|
||||
idef = fluid_settings_getint_default (settings, name);
|
||||
hints = fluid_settings_get_hints (settings, name);
|
||||
fluid_settings_getint_default (settings, name, &idef);
|
||||
fluid_settings_get_hints (settings, name, &hints);
|
||||
|
||||
if (!(hints & FLUID_HINT_TOGGLED))
|
||||
{
|
||||
|
|
|
@ -337,7 +337,7 @@ fluid_settings_tokenize(const char *s, char *buf, char **ptr)
|
|||
* @param settings a settings object
|
||||
* @param name Settings name
|
||||
* @param value Location to store setting node if found
|
||||
* @return 1 if the node exists, 0 otherwise
|
||||
* @return #FLUID_OK if the node exists, #FLUID_FAILED otherwise
|
||||
*/
|
||||
static int
|
||||
fluid_settings_get(fluid_settings_t* settings, const char *name,
|
||||
|
@ -352,19 +352,19 @@ fluid_settings_get(fluid_settings_t* settings, const char *name,
|
|||
|
||||
ntokens = fluid_settings_tokenize (name, buf, tokens);
|
||||
|
||||
if (table == NULL || ntokens <= 0) return 0;
|
||||
if (table == NULL || ntokens <= 0) return FLUID_FAILED;
|
||||
|
||||
for (n = 0; n < ntokens; n++) {
|
||||
|
||||
node = fluid_hashtable_lookup(table, tokens[n]);
|
||||
if (!node) return 0;
|
||||
if (!node) return FLUID_FAILED;
|
||||
|
||||
table = (node->type == FLUID_SET_TYPE) ? ((fluid_set_setting_t *)node)->hashtable : NULL;
|
||||
}
|
||||
|
||||
if (value) *value = node;
|
||||
|
||||
return 1;
|
||||
return FLUID_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -373,7 +373,7 @@ fluid_settings_get(fluid_settings_t* settings, const char *name,
|
|||
* @param settings a settings object
|
||||
* @param name Settings name
|
||||
* @param value Node instance to assign (used directly)
|
||||
* @return 1 if the value has been set, zero otherwise
|
||||
* @return #FLUID_OK if the value has been set, #FLUID_FAILED otherwise
|
||||
*/
|
||||
static int
|
||||
fluid_settings_set(fluid_settings_t* settings, const char *name, void* value)
|
||||
|
@ -387,7 +387,7 @@ fluid_settings_set(fluid_settings_t* settings, const char *name, void* value)
|
|||
|
||||
num = fluid_settings_tokenize (name, buf, tokens) - 1;
|
||||
if (num == 0)
|
||||
return 0;
|
||||
return FLUID_FAILED;
|
||||
|
||||
for (n = 0; n < num; n++) {
|
||||
|
||||
|
@ -400,7 +400,7 @@ fluid_settings_set(fluid_settings_t* settings, const char *name, void* value)
|
|||
} else {
|
||||
/* path ends prematurely */
|
||||
FLUID_LOG(FLUID_WARN, "'%s' is not a node", name[n]);
|
||||
return 0;
|
||||
return FLUID_FAILED;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -417,7 +417,7 @@ fluid_settings_set(fluid_settings_t* settings, const char *name, void* value)
|
|||
|
||||
if (setnode) delete_fluid_set_setting (setnode);
|
||||
|
||||
return 0;
|
||||
return FLUID_FAILED;
|
||||
}
|
||||
|
||||
fluid_hashtable_insert(table, dupname, setnode);
|
||||
|
@ -430,34 +430,43 @@ fluid_settings_set(fluid_settings_t* settings, const char *name, void* value)
|
|||
if (!dupname)
|
||||
{
|
||||
FLUID_LOG(FLUID_ERR, "Out of memory");
|
||||
return 0;
|
||||
return FLUID_FAILED;
|
||||
}
|
||||
|
||||
fluid_hashtable_insert(table, dupname, value);
|
||||
|
||||
return 1;
|
||||
return FLUID_OK;
|
||||
}
|
||||
|
||||
/** returns 1 if the value has been registered correctly, 0
|
||||
otherwise */
|
||||
/**
|
||||
* Registers a new string value for the specified setting.
|
||||
*
|
||||
* @param settings a settings object
|
||||
* @param name the setting's name
|
||||
* @param def the default value for the setting
|
||||
* @param hints the hints for the setting
|
||||
* @param fun an update function for the setting
|
||||
* @param data user supplied data
|
||||
* @return #FLUID_OK if the value has been register correctly, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_register_str(fluid_settings_t* settings, const char* name, const char* def, int hints,
|
||||
fluid_str_update_t fun, void* data)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
fluid_str_setting_t* setting;
|
||||
int retval;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (!fluid_settings_get(settings, name, &node)) {
|
||||
setting = new_fluid_str_setting(def, def, hints, fun, data);
|
||||
retval = fluid_settings_set(settings, name, setting);
|
||||
if (retval != 1) delete_fluid_str_setting (setting);
|
||||
if (retval != FLUID_OK) delete_fluid_str_setting (setting);
|
||||
} else {
|
||||
/* if variable already exists, don't change its value. */
|
||||
if (node->type == FLUID_STR_TYPE) {
|
||||
|
@ -466,10 +475,9 @@ fluid_settings_register_str(fluid_settings_t* settings, const char* name, const
|
|||
setting->data = data;
|
||||
setting->def = def? FLUID_STRDUP(def) : NULL;
|
||||
setting->hints = hints;
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
} else {
|
||||
FLUID_LOG(FLUID_WARN, "Type mismatch on setting '%s'", name);
|
||||
retval = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -478,19 +486,30 @@ fluid_settings_register_str(fluid_settings_t* settings, const char* name, const
|
|||
return retval;
|
||||
}
|
||||
|
||||
/** returns 1 if the value has been register correctly, zero
|
||||
otherwise */
|
||||
/**
|
||||
* Registers a new float value for the specified setting.
|
||||
*
|
||||
* @param settings a settings object
|
||||
* @param name the setting's name
|
||||
* @param def the default value for the setting
|
||||
* @param min the smallest allowed value for the setting
|
||||
* @param max the largest allowed value for the setting
|
||||
* @param hints the hints for the setting
|
||||
* @param fun an update function for the setting
|
||||
* @param data user supplied data
|
||||
* @return #FLUID_OK if the value has been register correctly, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_register_num(fluid_settings_t* settings, const char* name, double def,
|
||||
double min, double max, int hints,
|
||||
fluid_num_update_t fun, void* data)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
|
||||
/* For now, all floating point settings are bounded below and above */
|
||||
hints |= FLUID_HINT_BOUNDED_BELOW | FLUID_HINT_BOUNDED_ABOVE;
|
||||
|
@ -502,7 +521,7 @@ fluid_settings_register_num(fluid_settings_t* settings, const char* name, double
|
|||
fluid_num_setting_t* setting;
|
||||
setting = new_fluid_num_setting(min, max, def, hints, fun, data);
|
||||
retval = fluid_settings_set(settings, name, setting);
|
||||
if (retval != 1) delete_fluid_num_setting (setting);
|
||||
if (retval != FLUID_OK) delete_fluid_num_setting (setting);
|
||||
} else {
|
||||
if (node->type == FLUID_NUM_TYPE) {
|
||||
/* update the existing setting but don't change its value */
|
||||
|
@ -513,11 +532,10 @@ fluid_settings_register_num(fluid_settings_t* settings, const char* name, double
|
|||
setting->max = max;
|
||||
setting->def = def;
|
||||
setting->hints = hints;
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
} else {
|
||||
/* type mismatch */
|
||||
FLUID_LOG(FLUID_WARN, "Type mismatch on setting '%s'", name);
|
||||
retval = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -526,19 +544,30 @@ fluid_settings_register_num(fluid_settings_t* settings, const char* name, double
|
|||
return retval;
|
||||
}
|
||||
|
||||
/** returns 1 if the value has been register correctly, zero
|
||||
otherwise. */
|
||||
/**
|
||||
* Registers a new integer value for the specified setting.
|
||||
*
|
||||
* @param settings a settings object
|
||||
* @param name the setting's name
|
||||
* @param def the default value for the setting
|
||||
* @param min the smallest allowed value for the setting
|
||||
* @param max the largest allowed value for the setting
|
||||
* @param hints the hints for the setting
|
||||
* @param fun an update function for the setting
|
||||
* @param data user supplied data
|
||||
* @return #FLUID_OK if the value has been register correctly, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_register_int(fluid_settings_t* settings, const char* name, int def,
|
||||
int min, int max, int hints,
|
||||
fluid_int_update_t fun, void* data)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
|
||||
/* For now, all integer settings are bounded below and above */
|
||||
hints |= FLUID_HINT_BOUNDED_BELOW | FLUID_HINT_BOUNDED_ABOVE;
|
||||
|
@ -550,7 +579,7 @@ fluid_settings_register_int(fluid_settings_t* settings, const char* name, int de
|
|||
fluid_int_setting_t* setting;
|
||||
setting = new_fluid_int_setting(min, max, def, hints, fun, data);
|
||||
retval = fluid_settings_set(settings, name, setting);
|
||||
if (retval != 1) delete_fluid_int_setting (setting);
|
||||
if (retval != FLUID_OK) delete_fluid_int_setting (setting);
|
||||
} else {
|
||||
if (node->type == FLUID_INT_TYPE) {
|
||||
/* update the existing setting but don't change its value */
|
||||
|
@ -561,11 +590,10 @@ fluid_settings_register_int(fluid_settings_t* settings, const char* name, int de
|
|||
setting->max = max;
|
||||
setting->def = def;
|
||||
setting->hints = hints;
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
} else {
|
||||
/* type mismatch */
|
||||
FLUID_LOG(FLUID_WARN, "Type mismatch on setting '%s'", name);
|
||||
retval = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -581,21 +609,23 @@ fluid_settings_register_int(fluid_settings_t* settings, const char* name, int de
|
|||
* @param name a setting's name
|
||||
* @return the type for the named setting, or #FLUID_NO_TYPE when it does not exist
|
||||
*/
|
||||
int
|
||||
enum fluid_types_enum
|
||||
fluid_settings_get_type(fluid_settings_t* settings, const char *name)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int type;
|
||||
enum fluid_types_enum type = FLUID_NO_TYPE;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, FLUID_NO_TYPE);
|
||||
fluid_return_val_if_fail (name != NULL, FLUID_NO_TYPE);
|
||||
fluid_return_val_if_fail (name[0] != '\0', FLUID_NO_TYPE);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
type = fluid_settings_get (settings, name, &node) ? node->type : FLUID_NO_TYPE;
|
||||
type = fluid_settings_get (settings, name, &node) == FLUID_OK
|
||||
? (enum fluid_types_enum)node->type
|
||||
: FLUID_NO_TYPE;
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
||||
return (type);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -603,36 +633,40 @@ fluid_settings_get_type(fluid_settings_t* settings, const char *name)
|
|||
*
|
||||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @return the hints associated to the named setting if it exists, zero otherwise
|
||||
* @param hints set to the hints associated to the setting if it exists
|
||||
* @return #FLUID_OK if hints associated to the named setting exist, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_get_hints(fluid_settings_t* settings, const char *name)
|
||||
fluid_settings_get_hints(fluid_settings_t* settings, const char *name, int* hints)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int hints = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)) {
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK) {
|
||||
if (node->type == FLUID_NUM_TYPE) {
|
||||
fluid_num_setting_t* setting = (fluid_num_setting_t*) node;
|
||||
hints = setting->hints;
|
||||
*hints = setting->hints;
|
||||
retval = FLUID_OK;
|
||||
} else if (node->type == FLUID_STR_TYPE) {
|
||||
fluid_str_setting_t* setting = (fluid_str_setting_t*) node;
|
||||
hints = setting->hints;
|
||||
*hints = setting->hints;
|
||||
retval = FLUID_OK;
|
||||
} else if (node->type == FLUID_INT_TYPE) {
|
||||
fluid_int_setting_t* setting = (fluid_int_setting_t*) node;
|
||||
hints = setting->hints;
|
||||
*hints = setting->hints;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
||||
return hints;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -640,7 +674,7 @@ fluid_settings_get_hints(fluid_settings_t* settings, const char *name)
|
|||
*
|
||||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @return non zero if the setting is changeable in real-time
|
||||
* @return TRUE if the setting is changeable in real-time, FALSE otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_is_realtime(fluid_settings_t* settings, const char *name)
|
||||
|
@ -654,7 +688,7 @@ fluid_settings_is_realtime(fluid_settings_t* settings, const char *name)
|
|||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)) {
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK) {
|
||||
if (node->type == FLUID_NUM_TYPE) {
|
||||
fluid_num_setting_t* setting = (fluid_num_setting_t*) node;
|
||||
isrealtime = setting->update != NULL;
|
||||
|
@ -678,21 +712,21 @@ fluid_settings_is_realtime(fluid_settings_t* settings, const char *name)
|
|||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @param str new string value
|
||||
* @return 1 if the value has been set, 0 otherwise
|
||||
* @return #FLUID_OK if the value has been set, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_setstr(fluid_settings_t* settings, const char *name, const char *str)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get (settings, name, &node)) {
|
||||
if (fluid_settings_get (settings, name, &node) == FLUID_OK) {
|
||||
if (node->type == FLUID_STR_TYPE) {
|
||||
fluid_str_setting_t *setting = (fluid_str_setting_t *)node;
|
||||
|
||||
|
@ -701,7 +735,7 @@ fluid_settings_setstr(fluid_settings_t* settings, const char *name, const char *
|
|||
|
||||
/* Call under lock to keep update() synchronized with the current value */
|
||||
if (setting->update) (*setting->update)(setting->data, name, str);
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
else if (node->type == FLUID_INT_TYPE) /* Handle yes/no for boolean values for backwards compatibility */
|
||||
{
|
||||
|
@ -713,11 +747,13 @@ fluid_settings_setstr(fluid_settings_t* settings, const char *name, const char *
|
|||
{
|
||||
setting->value = TRUE;
|
||||
if (setting->update) (*setting->update)(setting->data, name, TRUE);
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
else if (FLUID_STRCMP (str, "no") == 0)
|
||||
{
|
||||
setting->value = FALSE;
|
||||
if (setting->update) (*setting->update)(setting->data, name, FALSE);
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -726,7 +762,7 @@ fluid_settings_setstr(fluid_settings_t* settings, const char *name, const char *
|
|||
fluid_str_setting_t* setting;
|
||||
setting = new_fluid_str_setting(str, NULL, 0, NULL, NULL);
|
||||
retval = fluid_settings_set(settings, name, setting);
|
||||
if (retval != 1) delete_fluid_str_setting (setting);
|
||||
if (retval != FLUID_OK) delete_fluid_str_setting (setting);
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
@ -741,7 +777,7 @@ fluid_settings_setstr(fluid_settings_t* settings, const char *name, const char *
|
|||
* @param str Caller supplied buffer to copy string value to
|
||||
* @param len Size of 'str' buffer (no more than len bytes will be written, which
|
||||
* will always include a zero terminator)
|
||||
* @return 1 if the value exists, 0 otherwise
|
||||
* @return #FLUID_OK if the value exists, #FLUID_FAILED otherwise
|
||||
* @since 1.1.0
|
||||
*
|
||||
* @note A size of 256 should be more than sufficient for the string buffer.
|
||||
|
@ -751,19 +787,19 @@ fluid_settings_copystr(fluid_settings_t* settings, const char *name,
|
|||
char *str, int len)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (str != NULL, 0);
|
||||
fluid_return_val_if_fail (len > 0, 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (str != NULL, retval);
|
||||
fluid_return_val_if_fail (len > 0, retval);
|
||||
|
||||
str[0] = 0;
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get (settings, name, &node))
|
||||
if (fluid_settings_get (settings, name, &node) == FLUID_OK)
|
||||
{
|
||||
if (node->type == FLUID_STR_TYPE)
|
||||
{
|
||||
|
@ -775,7 +811,7 @@ fluid_settings_copystr(fluid_settings_t* settings, const char *name,
|
|||
str[len - 1] = 0; /* Force terminate, in case of truncation */
|
||||
}
|
||||
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
else if (node->type == FLUID_INT_TYPE) /* Handle boolean integers for backwards compatibility */
|
||||
{
|
||||
|
@ -786,7 +822,7 @@ fluid_settings_copystr(fluid_settings_t* settings, const char *name,
|
|||
FLUID_STRNCPY (str, setting->value ? "yes" : "no", len);
|
||||
str[len - 1] = 0; /* Force terminate, in case of truncation */
|
||||
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -801,7 +837,7 @@ fluid_settings_copystr(fluid_settings_t* settings, const char *name,
|
|||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @param str Location to store pointer to allocated duplicate string
|
||||
* @return 1 if the value exists and was successfully duplicated, 0 otherwise
|
||||
* @return #FLUID_OK if the value exists and was successfully duplicated, #FLUID_FAILED otherwise
|
||||
* @since 1.1.0
|
||||
*
|
||||
* Like fluid_settings_copystr() but allocates a new copy of the string. Caller
|
||||
|
@ -811,16 +847,16 @@ int
|
|||
fluid_settings_dupstr(fluid_settings_t* settings, const char *name, char** str)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (str != NULL, 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (str != NULL, retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node))
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK)
|
||||
{
|
||||
if (node->type == FLUID_STR_TYPE)
|
||||
{
|
||||
|
@ -832,7 +868,7 @@ fluid_settings_dupstr(fluid_settings_t* settings, const char *name, char** str)
|
|||
if (!*str) FLUID_LOG (FLUID_ERR, "Out of memory");
|
||||
}
|
||||
|
||||
if (!setting->value || *str) retval = 1; /* Don't set to 1 if out of memory */
|
||||
if (!setting->value || *str) retval = FLUID_OK; /* Don't set to FLUID_OK if out of memory */
|
||||
}
|
||||
else if (node->type == FLUID_INT_TYPE) /* Handle boolean integers for backwards compatibility */
|
||||
{
|
||||
|
@ -843,7 +879,7 @@ fluid_settings_dupstr(fluid_settings_t* settings, const char *name, char** str)
|
|||
*str = FLUID_STRDUP (setting->value ? "yes" : "no");
|
||||
if (!*str) FLUID_LOG (FLUID_ERR, "Out of memory");
|
||||
|
||||
if (!setting->value || *str) retval = 1; /* Don't set to 1 if out of memory */
|
||||
if (!setting->value || *str) retval = FLUID_OK; /* Don't set to FLUID_OK if out of memory */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -860,34 +896,43 @@ fluid_settings_dupstr(fluid_settings_t* settings, const char *name, char** str)
|
|||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @param s a string to be tested
|
||||
* @return 1 if the value exists and is equal to 's', 0 otherwise
|
||||
* @return #FLUID_OK if the value exists and is equal to 's', #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_str_equal (fluid_settings_t* settings, const char *name, const char *s)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (s != NULL, 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (s != NULL, retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get (settings, name, &node))
|
||||
if (fluid_settings_get (settings, name, &node) == FLUID_OK)
|
||||
{
|
||||
if (node->type == FLUID_STR_TYPE)
|
||||
{
|
||||
fluid_str_setting_t *setting = (fluid_str_setting_t *)node;
|
||||
if (setting->value) retval = FLUID_STRCMP (setting->value, s) == 0;
|
||||
if (setting->value)
|
||||
{
|
||||
retval = FLUID_STRCMP (setting->value, s) == 0
|
||||
? FLUID_OK
|
||||
: FLUID_FAILED;
|
||||
}
|
||||
}
|
||||
else if (node->type == FLUID_INT_TYPE) /* Handle boolean integers for backwards compatibility */
|
||||
{
|
||||
fluid_int_setting_t *setting = (fluid_int_setting_t *)node;
|
||||
|
||||
if (setting->hints & FLUID_HINT_TOGGLED)
|
||||
retval = FLUID_STRCMP (setting->value ? "yes" : "no", s) == 0;
|
||||
{
|
||||
retval = FLUID_STRCMP (setting->value ? "yes" : "no", s) == 0
|
||||
? FLUID_OK
|
||||
: FLUID_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -916,7 +961,7 @@ fluid_settings_getstr_default(fluid_settings_t* settings, const char *name)
|
|||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get (settings, name, &node))
|
||||
if (fluid_settings_get (settings, name, &node) == FLUID_OK)
|
||||
{
|
||||
if (node->type == FLUID_STR_TYPE)
|
||||
{
|
||||
|
@ -942,7 +987,7 @@ fluid_settings_getstr_default(fluid_settings_t* settings, const char *name)
|
|||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @param s option string to add
|
||||
* @return 1 if the setting exists and option was added, 0 otherwise
|
||||
* @return #FLUID_OK if the setting exists and option was added, #FLUID_FAILED otherwise
|
||||
*
|
||||
* Causes the setting's #FLUID_HINT_OPTIONLIST hint to be set.
|
||||
*/
|
||||
|
@ -950,22 +995,22 @@ int
|
|||
fluid_settings_add_option(fluid_settings_t* settings, const char *name, const char *s)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (s != NULL, 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (s != NULL, retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK
|
||||
&& (node->type == FLUID_STR_TYPE)) {
|
||||
fluid_str_setting_t* setting = (fluid_str_setting_t*) node;
|
||||
char* copy = FLUID_STRDUP(s);
|
||||
setting->options = fluid_list_append(setting->options, copy);
|
||||
setting->hints |= FLUID_HINT_OPTIONLIST;
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
@ -978,22 +1023,22 @@ fluid_settings_add_option(fluid_settings_t* settings, const char *name, const ch
|
|||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @param s option string to remove
|
||||
* @return 1 if the setting exists and option was removed, 0 otherwise
|
||||
* @return #FLUID_OK if the setting exists and option was removed, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_remove_option(fluid_settings_t* settings, const char *name, const char* s)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (s != NULL, 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (s != NULL, retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK
|
||||
&& (node->type == FLUID_STR_TYPE)) {
|
||||
|
||||
fluid_str_setting_t* setting = (fluid_str_setting_t*) node;
|
||||
|
@ -1002,9 +1047,9 @@ fluid_settings_remove_option(fluid_settings_t* settings, const char *name, const
|
|||
while (list) {
|
||||
char* option = (char*) fluid_list_get(list);
|
||||
if (FLUID_STRCMP(s, option) == 0) {
|
||||
FLUID_FREE (option);
|
||||
setting->options = fluid_list_remove_link(setting->options, list);
|
||||
retval = 1;
|
||||
FLUID_FREE (option);
|
||||
setting->options = fluid_list_remove_link(setting->options, list);
|
||||
retval = FLUID_OK;
|
||||
break;
|
||||
}
|
||||
list = fluid_list_next(list);
|
||||
|
@ -1022,22 +1067,22 @@ fluid_settings_remove_option(fluid_settings_t* settings, const char *name, const
|
|||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @param val new setting's value
|
||||
* @return 1 if the value has been set, 0 otherwise
|
||||
* @return #FLUID_OK if the value has been set, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_setnum(fluid_settings_t* settings, const char *name, double val)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
fluid_num_setting_t* setting;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)) {
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK) {
|
||||
if (node->type == FLUID_NUM_TYPE) {
|
||||
setting = (fluid_num_setting_t*) node;
|
||||
|
||||
|
@ -1048,7 +1093,7 @@ fluid_settings_setnum(fluid_settings_t* settings, const char *name, double val)
|
|||
|
||||
/* Call under lock to keep update() synchronized with the current value */
|
||||
if (setting->update) (*setting->update)(setting->data, name, val);
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
} else {
|
||||
/* insert a new setting */
|
||||
|
@ -1056,7 +1101,7 @@ fluid_settings_setnum(fluid_settings_t* settings, const char *name, double val)
|
|||
setting = new_fluid_num_setting(-1e10, 1e10, 0.0f, 0, NULL, NULL);
|
||||
setting->value = val;
|
||||
retval = fluid_settings_set(settings, name, setting);
|
||||
if (retval != 1) delete_fluid_num_setting (setting);
|
||||
if (retval != FLUID_OK) delete_fluid_num_setting (setting);
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
@ -1070,26 +1115,26 @@ fluid_settings_setnum(fluid_settings_t* settings, const char *name, double val)
|
|||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @param val variable pointer to receive the setting's numeric value
|
||||
* @return 1 if the value exists, 0 otherwise
|
||||
* @return #FLUID_OK if the value exists, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_getnum(fluid_settings_t* settings, const char *name, double* val)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (val != NULL, 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (val != NULL, retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK
|
||||
&& (node->type == FLUID_NUM_TYPE)) {
|
||||
fluid_num_setting_t* setting = (fluid_num_setting_t*) node;
|
||||
*val = setting->value;
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
@ -1104,29 +1149,34 @@ fluid_settings_getnum(fluid_settings_t* settings, const char *name, double* val)
|
|||
* @param name a setting's name
|
||||
* @param min setting's range lower limit
|
||||
* @param max setting's range upper limit
|
||||
* @return #FLUID_OK if the setting's range exists, #FLUID_FAILED otherwise
|
||||
*/
|
||||
void
|
||||
int
|
||||
fluid_settings_getnum_range(fluid_settings_t* settings, const char *name,
|
||||
double* min, double* max)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_if_fail (settings != NULL);
|
||||
fluid_return_if_fail (name != NULL);
|
||||
fluid_return_if_fail (name[0] != '\0');
|
||||
fluid_return_if_fail (min != NULL);
|
||||
fluid_return_if_fail (max != NULL);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (min != NULL, retval);
|
||||
fluid_return_val_if_fail (max != NULL, retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK
|
||||
&& (node->type == FLUID_NUM_TYPE)) {
|
||||
fluid_num_setting_t* setting = (fluid_num_setting_t*) node;
|
||||
*min = setting->min;
|
||||
*max = setting->max;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1134,24 +1184,27 @@ fluid_settings_getnum_range(fluid_settings_t* settings, const char *name,
|
|||
*
|
||||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @return the default value if the named setting exists, 0.0f otherwise
|
||||
* @param val set to the default value if the named setting exists
|
||||
* @return #FLUID_OK if the default value of the named setting exists, #FLUID_FAILED otherwise
|
||||
*/
|
||||
double
|
||||
fluid_settings_getnum_default(fluid_settings_t* settings, const char *name)
|
||||
int
|
||||
fluid_settings_getnum_default(fluid_settings_t* settings, const char *name, double* val)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
double retval = 0.0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0.0);
|
||||
fluid_return_val_if_fail (name != NULL, 0.0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0.0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (val != NULL, retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK
|
||||
&& (node->type == FLUID_NUM_TYPE)) {
|
||||
fluid_num_setting_t* setting = (fluid_num_setting_t*) node;
|
||||
retval = setting->def;
|
||||
*val = setting->def;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
@ -1165,22 +1218,22 @@ fluid_settings_getnum_default(fluid_settings_t* settings, const char *name)
|
|||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @param val new setting's integer value
|
||||
* @return 1 if the value has been set, 0 otherwise
|
||||
* @return #FLUID_OK if the value has been set, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_setint(fluid_settings_t* settings, const char *name, int val)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
fluid_int_setting_t* setting;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)) {
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK) {
|
||||
if (node->type == FLUID_INT_TYPE) {
|
||||
setting = (fluid_int_setting_t*) node;
|
||||
|
||||
|
@ -1191,7 +1244,7 @@ fluid_settings_setint(fluid_settings_t* settings, const char *name, int val)
|
|||
|
||||
/* Call under lock to keep update() synchronized with the current value */
|
||||
if (setting->update) (*setting->update)(setting->data, name, val);
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
} else {
|
||||
/* insert a new setting */
|
||||
|
@ -1199,7 +1252,7 @@ fluid_settings_setint(fluid_settings_t* settings, const char *name, int val)
|
|||
setting = new_fluid_int_setting(INT_MIN, INT_MAX, 0, 0, NULL, NULL);
|
||||
setting->value = val;
|
||||
retval = fluid_settings_set(settings, name, setting);
|
||||
if (retval != 1) delete_fluid_int_setting (setting);
|
||||
if (retval != FLUID_OK) delete_fluid_int_setting (setting);
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
@ -1213,26 +1266,26 @@ fluid_settings_setint(fluid_settings_t* settings, const char *name, int val)
|
|||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @param val pointer to a variable to receive the setting's integer value
|
||||
* @return 1 if the value exists, 0 otherwise
|
||||
* @return #FLUID_OK if the value exists, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_getint(fluid_settings_t* settings, const char *name, int* val)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (val != NULL, 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (val != NULL, retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK
|
||||
&& (node->type == FLUID_INT_TYPE)) {
|
||||
fluid_int_setting_t* setting = (fluid_int_setting_t*) node;
|
||||
*val = setting->value;
|
||||
retval = 1;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
@ -1246,29 +1299,34 @@ fluid_settings_getint(fluid_settings_t* settings, const char *name, int* val)
|
|||
* @param name a setting's name
|
||||
* @param min setting's range lower limit
|
||||
* @param max setting's range upper limit
|
||||
* @return #FLUID_OK if the setting's range exists, #FLUID_FAILED otherwise
|
||||
*/
|
||||
void
|
||||
int
|
||||
fluid_settings_getint_range(fluid_settings_t* settings, const char *name,
|
||||
int* min, int* max)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_if_fail (settings != NULL);
|
||||
fluid_return_if_fail (name != NULL);
|
||||
fluid_return_if_fail (name[0] != '\0');
|
||||
fluid_return_if_fail (min != NULL);
|
||||
fluid_return_if_fail (max != NULL);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (min != NULL, retval);
|
||||
fluid_return_val_if_fail (max != NULL, retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK
|
||||
&& (node->type == FLUID_INT_TYPE)) {
|
||||
fluid_int_setting_t* setting = (fluid_int_setting_t*) node;
|
||||
*min = setting->min;
|
||||
*max = setting->max;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1276,24 +1334,26 @@ fluid_settings_getint_range(fluid_settings_t* settings, const char *name,
|
|||
*
|
||||
* @param settings a settings object
|
||||
* @param name a setting's name
|
||||
* @return the setting's default integer value it it exists, zero otherwise
|
||||
* @param val set to the setting's default integer value if it exists
|
||||
* @return #FLUID_OK if the setting's default integer value exists, #FLUID_FAILED otherwise
|
||||
*/
|
||||
int
|
||||
fluid_settings_getint_default(fluid_settings_t* settings, const char *name)
|
||||
int fluid_settings_getint_default(fluid_settings_t* settings, const char *name, int* val)
|
||||
{
|
||||
fluid_setting_node_t *node;
|
||||
int retval = 0;
|
||||
int retval = FLUID_FAILED;
|
||||
|
||||
fluid_return_val_if_fail (settings != NULL, 0);
|
||||
fluid_return_val_if_fail (name != NULL, 0);
|
||||
fluid_return_val_if_fail (name[0] != '\0', 0);
|
||||
fluid_return_val_if_fail (settings != NULL, retval);
|
||||
fluid_return_val_if_fail (name != NULL, retval);
|
||||
fluid_return_val_if_fail (name[0] != '\0', retval);
|
||||
fluid_return_val_if_fail (val != NULL, retval);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
|
||||
if (fluid_settings_get(settings, name, &node)
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK
|
||||
&& (node->type == FLUID_INT_TYPE)) {
|
||||
fluid_int_setting_t* setting = (fluid_int_setting_t*) node;
|
||||
retval = setting->def;
|
||||
*val = setting->def;
|
||||
retval = FLUID_OK;
|
||||
}
|
||||
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
@ -1328,7 +1388,8 @@ fluid_settings_foreach_option (fluid_settings_t* settings, const char *name,
|
|||
|
||||
fluid_rec_mutex_lock (settings->mutex); /* ++ lock */
|
||||
|
||||
if (!fluid_settings_get (settings, name, &node) || node->type != FLUID_STR_TYPE)
|
||||
if (fluid_settings_get (settings, name, &node) != FLUID_OK
|
||||
|| node->type != FLUID_STR_TYPE)
|
||||
{
|
||||
fluid_rec_mutex_unlock (settings->mutex); /* -- unlock */
|
||||
return;
|
||||
|
@ -1370,7 +1431,8 @@ fluid_settings_option_count (fluid_settings_t *settings, const char *name)
|
|||
fluid_return_val_if_fail (name[0] != '\0', -1);
|
||||
|
||||
fluid_rec_mutex_lock (settings->mutex);
|
||||
if (fluid_settings_get(settings, name, &node) && node->type == FLUID_STR_TYPE)
|
||||
if (fluid_settings_get(settings, name, &node) == FLUID_OK
|
||||
&& node->type == FLUID_STR_TYPE)
|
||||
count = fluid_list_size (((fluid_str_setting_t *)node)->options);
|
||||
fluid_rec_mutex_unlock (settings->mutex);
|
||||
|
||||
|
@ -1404,7 +1466,8 @@ fluid_settings_option_concat (fluid_settings_t *settings, const char *name,
|
|||
|
||||
fluid_rec_mutex_lock (settings->mutex); /* ++ lock */
|
||||
|
||||
if (!fluid_settings_get (settings, name, &node) || node->type != FLUID_STR_TYPE)
|
||||
if (fluid_settings_get (settings, name, &node) != FLUID_OK
|
||||
|| node->type != FLUID_STR_TYPE)
|
||||
{
|
||||
fluid_rec_mutex_unlock (settings->mutex); /* -- unlock */
|
||||
return (NULL);
|
||||
|
@ -1514,7 +1577,6 @@ fluid_settings_foreach (fluid_settings_t* settings, void* data,
|
|||
fluid_settings_foreach_bag_t bag;
|
||||
fluid_setting_node_t *node;
|
||||
fluid_list_t *p;
|
||||
int r;
|
||||
|
||||
fluid_return_if_fail (settings != NULL);
|
||||
fluid_return_if_fail (func != NULL);
|
||||
|
@ -1533,8 +1595,9 @@ fluid_settings_foreach (fluid_settings_t* settings, void* data,
|
|||
/* Loop over names and call the callback */
|
||||
for (p = bag.names; p; p = p->next)
|
||||
{
|
||||
r = fluid_settings_get (settings, (char *)(p->data), &node);
|
||||
if (r && node) (*func) (data, (char *)(p->data), node->type);
|
||||
if (fluid_settings_get (settings, (char *)(p->data), &node) == FLUID_OK
|
||||
&& node)
|
||||
(*func) (data, (char *)(p->data), node->type);
|
||||
FLUID_FREE (p->data); /* -- Free name */
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue