mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2024-12-03 09:32:02 +00:00
Add dedicated functions for registering update callbacks on settings
This avoids having to duplicate the default, min, max and hint values when setting a callback function for an existing setting.
This commit is contained in:
parent
c94f747c04
commit
5cd03e0171
3 changed files with 119 additions and 10 deletions
|
@ -612,18 +612,13 @@ new_fluid_synth(fluid_settings_t *settings)
|
||||||
fluid_settings_getint(settings, "synth.cpu-cores", &synth->cores);
|
fluid_settings_getint(settings, "synth.cpu-cores", &synth->cores);
|
||||||
|
|
||||||
/* register the callbacks */
|
/* register the callbacks */
|
||||||
fluid_settings_register_num(settings, "synth.sample-rate",
|
fluid_settings_callback_num(settings, "synth.sample-rate",
|
||||||
44100.0f, 8000.0f, 96000.0f, 0,
|
|
||||||
(fluid_num_update_t) fluid_synth_update_sample_rate, synth);
|
(fluid_num_update_t) fluid_synth_update_sample_rate, synth);
|
||||||
fluid_settings_register_num(settings, "synth.gain",
|
fluid_settings_callback_num(settings, "synth.gain",
|
||||||
0.2f, 0.0f, 10.0f, 0,
|
|
||||||
(fluid_num_update_t) fluid_synth_update_gain, synth);
|
(fluid_num_update_t) fluid_synth_update_gain, synth);
|
||||||
fluid_settings_register_int(settings, "synth.polyphony",
|
fluid_settings_callback_int(settings, "synth.polyphony",
|
||||||
synth->polyphony, 1, 65535, 0,
|
(fluid_int_update_t) fluid_synth_update_polyphony, synth);
|
||||||
(fluid_int_update_t) fluid_synth_update_polyphony,
|
fluid_settings_callback_int(settings, "synth.device-id",
|
||||||
synth);
|
|
||||||
fluid_settings_register_int(settings, "synth.device-id",
|
|
||||||
synth->device_id, 126, 0, 0,
|
|
||||||
(fluid_int_update_t) fluid_synth_update_device_id, synth);
|
(fluid_int_update_t) fluid_synth_update_device_id, synth);
|
||||||
|
|
||||||
fluid_synth_register_overflow(settings,
|
fluid_synth_register_overflow(settings,
|
||||||
|
|
|
@ -625,6 +625,114 @@ fluid_settings_register_int(fluid_settings_t* settings, const char* name, int de
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback for the specified string setting.
|
||||||
|
*
|
||||||
|
* @param settings a settings object
|
||||||
|
* @param name the setting's name
|
||||||
|
* @param callback an update function for the setting
|
||||||
|
* @param data user supplied data passed to the update function
|
||||||
|
* @return #FLUID_OK if the callback has been set, #FLUID_FAILED otherwise
|
||||||
|
*/
|
||||||
|
int fluid_settings_callback_str(fluid_settings_t* settings, const char* name,
|
||||||
|
fluid_str_update_t callback, void* data)
|
||||||
|
{
|
||||||
|
fluid_setting_node_t *node;
|
||||||
|
fluid_str_setting_t *setting;
|
||||||
|
|
||||||
|
fluid_return_val_if_fail (settings != NULL, FLUID_FAILED);
|
||||||
|
fluid_return_val_if_fail (name != NULL, FLUID_FAILED);
|
||||||
|
fluid_return_val_if_fail (name[0] != '\0', FLUID_FAILED);
|
||||||
|
|
||||||
|
fluid_rec_mutex_lock (settings->mutex);
|
||||||
|
|
||||||
|
if ((fluid_settings_get(settings, name, &node) != FLUID_OK)
|
||||||
|
|| node->type != FLUID_STR_TYPE)
|
||||||
|
{
|
||||||
|
fluid_rec_mutex_unlock(settings->mutex);
|
||||||
|
return FLUID_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
setting = &node->str;
|
||||||
|
setting->update = callback;
|
||||||
|
setting->data = data;
|
||||||
|
|
||||||
|
fluid_rec_mutex_unlock(settings->mutex);
|
||||||
|
return FLUID_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback for the specified numeric setting.
|
||||||
|
*
|
||||||
|
* @param settings a settings object
|
||||||
|
* @param name the setting's name
|
||||||
|
* @param callback an update function for the setting
|
||||||
|
* @param data user supplied data passed to the update function
|
||||||
|
* @return #FLUID_OK if the callback has been set, #FLUID_FAILED otherwise
|
||||||
|
*/
|
||||||
|
int fluid_settings_callback_num(fluid_settings_t* settings, const char* name,
|
||||||
|
fluid_num_update_t callback, void* data)
|
||||||
|
{
|
||||||
|
fluid_setting_node_t *node;
|
||||||
|
fluid_num_setting_t *setting;
|
||||||
|
|
||||||
|
fluid_return_val_if_fail (settings != NULL, FLUID_FAILED);
|
||||||
|
fluid_return_val_if_fail (name != NULL, FLUID_FAILED);
|
||||||
|
fluid_return_val_if_fail (name[0] != '\0', FLUID_FAILED);
|
||||||
|
|
||||||
|
fluid_rec_mutex_lock (settings->mutex);
|
||||||
|
|
||||||
|
if ((fluid_settings_get(settings, name, &node) != FLUID_OK)
|
||||||
|
|| node->type != FLUID_NUM_TYPE)
|
||||||
|
{
|
||||||
|
fluid_rec_mutex_unlock(settings->mutex);
|
||||||
|
return FLUID_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
setting = &node->num;
|
||||||
|
setting->update = callback;
|
||||||
|
setting->data = data;
|
||||||
|
|
||||||
|
fluid_rec_mutex_unlock(settings->mutex);
|
||||||
|
return FLUID_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback for the specified int setting.
|
||||||
|
*
|
||||||
|
* @param settings a settings object
|
||||||
|
* @param name the setting's name
|
||||||
|
* @param callback an update function for the setting
|
||||||
|
* @param data user supplied data passed to the update function
|
||||||
|
* @return #FLUID_OK if the callback has been set, #FLUID_FAILED otherwise
|
||||||
|
*/
|
||||||
|
int fluid_settings_callback_int(fluid_settings_t* settings, const char* name,
|
||||||
|
fluid_int_update_t callback, void* data)
|
||||||
|
{
|
||||||
|
fluid_setting_node_t *node;
|
||||||
|
fluid_int_setting_t *setting;
|
||||||
|
|
||||||
|
fluid_return_val_if_fail (settings != NULL, FLUID_FAILED);
|
||||||
|
fluid_return_val_if_fail (name != NULL, FLUID_FAILED);
|
||||||
|
fluid_return_val_if_fail (name[0] != '\0', FLUID_FAILED);
|
||||||
|
|
||||||
|
fluid_rec_mutex_lock (settings->mutex);
|
||||||
|
|
||||||
|
if ((fluid_settings_get(settings, name, &node) != FLUID_OK)
|
||||||
|
|| node->type != FLUID_INT_TYPE)
|
||||||
|
{
|
||||||
|
fluid_rec_mutex_unlock(settings->mutex);
|
||||||
|
return FLUID_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
setting = &node->i;
|
||||||
|
setting->update = callback;
|
||||||
|
setting->data = data;
|
||||||
|
|
||||||
|
fluid_rec_mutex_unlock(settings->mutex);
|
||||||
|
return FLUID_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of the setting with the given name
|
* Get the type of the setting with the given name
|
||||||
*
|
*
|
||||||
|
|
|
@ -30,6 +30,8 @@ typedef int (*fluid_str_update_t)(void* data, const char* name, const char* valu
|
||||||
|
|
||||||
int fluid_settings_register_str(fluid_settings_t* settings, const char* name, const char* def, int hints,
|
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_str_update_t fun, void* data);
|
||||||
|
int fluid_settings_callback_str(fluid_settings_t* settings, const char* name,
|
||||||
|
fluid_str_update_t fun, void* data);
|
||||||
|
|
||||||
|
|
||||||
typedef int (*fluid_num_update_t)(void* data, const char* name, double value);
|
typedef int (*fluid_num_update_t)(void* data, const char* name, double value);
|
||||||
|
@ -37,11 +39,15 @@ typedef int (*fluid_num_update_t)(void* data, const char* name, double value);
|
||||||
int fluid_settings_register_num(fluid_settings_t* settings, const char* name, double def,
|
int fluid_settings_register_num(fluid_settings_t* settings, const char* name, double def,
|
||||||
double min, double max, int hints,
|
double min, double max, int hints,
|
||||||
fluid_num_update_t fun, void* data);
|
fluid_num_update_t fun, void* data);
|
||||||
|
int fluid_settings_callback_num(fluid_settings_t* settings, const char* name,
|
||||||
|
fluid_num_update_t fun, void* data);
|
||||||
|
|
||||||
|
|
||||||
typedef int (*fluid_int_update_t)(void* data, const char* name, int value);
|
typedef int (*fluid_int_update_t)(void* data, const char* name, int value);
|
||||||
int fluid_settings_register_int(fluid_settings_t* settings, const char* name, int def,
|
int fluid_settings_register_int(fluid_settings_t* settings, const char* name, int def,
|
||||||
int min, int max, int hints,
|
int min, int max, int hints,
|
||||||
fluid_int_update_t fun, void* data);
|
fluid_int_update_t fun, void* data);
|
||||||
|
int fluid_settings_callback_int(fluid_settings_t* settings, const char* name,
|
||||||
|
fluid_int_update_t fun, void* data);
|
||||||
|
|
||||||
#endif /* _FLUID_SETTINGS_H */
|
#endif /* _FLUID_SETTINGS_H */
|
||||||
|
|
Loading…
Reference in a new issue