Fix review comments for pull request.

1) Don't expose gui mode to the causual user. Hide under the DEVELOPMENT_MODE
   #define.

2) Add accessors for the ModifierLinkableList's interesting fields.

3) Free the ModifierLinkableList from modifier_linkable_list(). This allows
   us to make the free function static.

4) Rename modifier_linkable_list() to update_modifier_linkable_list().

5) In effects.h, reflect the renaming of update_modifier_linkable_list() and
   correct it's signature.

6) Whitespace fixups in gdigi.c.

7) In the handler for RECEIVE_GLOBAL_PARAMETERS, apply the parameter to the gui.

8) Fixup some merge damage ;-(

9) UnCamelCaseIze some variables.

10) When we create the gui, issue a single call to REQUEST_GLOBAL_PARAMETERS to
    retrieve the globals from the device, instead of polling each parameter
    individually.
This commit is contained in:
Tim LaBerge
2012-12-17 21:21:17 -08:00
parent 22aeaf8ffa
commit 0cd6727d45
4 changed files with 85 additions and 61 deletions

View File

@@ -723,7 +723,9 @@ static EffectValues values_rp_mix = {
static EffectSettings global_settings[] = { static EffectSettings global_settings[] = {
{"USB/RP Mix", USB_AUDIO_PLAYBACK_MIX, GLOBAL_POSITION, &values_rp_mix}, {"USB/RP Mix", USB_AUDIO_PLAYBACK_MIX, GLOBAL_POSITION, &values_rp_mix},
{"USB Level", USB_AUDIO_LEVEL, GLOBAL_POSITION, &values_m12_to_24}, {"USB Level", USB_AUDIO_LEVEL, GLOBAL_POSITION, &values_m12_to_24},
#if defined(DEVELOPMENT_MODE)
{"GUI Mode", GUI_MODE_ON_OFF, GLOBAL_POSITION, &values_on_off}, {"GUI Mode", GUI_MODE_ON_OFF, GLOBAL_POSITION, &values_on_off},
#endif /* DEVELOPMENT_MODE */
{"Tuning Reference", TUNING_REFERENCE, GLOBAL_POSITION, &values_0_to_29}, {"Tuning Reference", TUNING_REFERENCE, GLOBAL_POSITION, &values_0_to_29},
{"Pedal Position", EXP_PEDAL_LEVEL, GLOBAL_POSITION, &values_0_to_255}, {"Pedal Position", EXP_PEDAL_LEVEL, GLOBAL_POSITION, &values_0_to_255},
{"Stomp", STOMP_MODE, GLOBAL_POSITION, &values_on_off}, {"Stomp", STOMP_MODE, GLOBAL_POSITION, &values_on_off},
@@ -4308,12 +4310,52 @@ static void effect_settings_free(EffectSettings *settings)
* Used for Pedal Assignment and the LFO's. * Used for Pedal Assignment and the LFO's.
*/ */
ModifierGroup *ModifierLinkableList; ModifierGroup *ModifierLinkableList;
EffectGroup *get_modifier_group(void)
{
EffectGroup *group = NULL;
if (ModifierLinkableList) {
group = ModifierLinkableList->group;
}
return group;
}
guint get_modifier_amt(void)
{
guint amt = 0;
if (ModifierLinkableList) {
amt = ModifierLinkableList->group_amt;
}
return amt;
}
/** /**
* Retrieves modifier linkable group from device. * \param modifier_group group to be freed
* *
* \return ModifierGroup which must be freed using modifier_group_free. * Frees all memory used by ModifierGroup.
**/ **/
ModifierGroup *modifier_linkable_list(GString *msg) static void modifier_group_free(ModifierGroup *modifier_group)
{
g_return_if_fail(modifier_group != NULL);
int x;
for (x=0; x<modifier_group->group_amt; x++) {
if (modifier_group->group[x].settings)
effect_settings_free(modifier_group->group[x].settings);
}
g_slice_free1(modifier_group->group_amt * sizeof(EffectGroup),
modifier_group->group);
g_slice_free(ModifierGroup, modifier_group);
}
/**
* Retrieves modifier linkable group from device and updates the
* global list of linkable parameters. The old list is freed.
*
* \param msg A buffer containing the message with the list of
* linkable parameters.
*
**/
void update_modifier_linkable_list(GString *msg)
{ {
guint group_id; guint group_id;
guint count; guint count;
@@ -4362,29 +4404,13 @@ ModifierGroup *modifier_linkable_list(GString *msg)
modifier_group->group = group; modifier_group->group = group;
modifier_group->group_amt = count; modifier_group->group_amt = count;
if (ModifierLinkableList) {
modifier_group_free(ModifierLinkableList);
ModifierLinkableList = NULL;
}
ModifierLinkableList = modifier_group; ModifierLinkableList = modifier_group;
return modifier_group;
} }
/**
* \param modifier_group group to be freed
*
* Frees all memory used by ModifierGroup.
**/
void modifier_group_free(ModifierGroup *modifier_group)
{
g_return_if_fail(modifier_group != NULL);
int x;
for (x=0; x<modifier_group->group_amt; x++) {
if (modifier_group->group[x].settings)
effect_settings_free(modifier_group->group[x].settings);
}
g_slice_free1(modifier_group->group_amt * sizeof(EffectGroup),
modifier_group->group);
g_slice_free(ModifierGroup, modifier_group);
}
/** /**
* \param values EffectValues to examine * \param values EffectValues to examine

View File

@@ -118,9 +118,10 @@ typedef struct {
} Device; } Device;
gchar *get_position(guint position); gchar *get_position(guint position);
ModifierGroup *modifier_linkable_list(); void update_modifier_linkable_list(GString* msg);
extern ModifierGroup *ModifierLinkableList; extern ModifierGroup *ModifierLinkableList;
void modifier_group_free(ModifierGroup *modifier_group); EffectGroup *get_modifier_group(void);
guint get_modifier_amt(void);
void get_values_info(EffectValues *values, void get_values_info(EffectValues *values,
gdouble *min, gdouble *max, gboolean *custom); gdouble *min, gdouble *max, gboolean *custom);
gboolean get_device_info(unsigned char device_id, unsigned char family_id, gboolean get_device_info(unsigned char device_id, unsigned char family_id,

18
gdigi.c
View File

@@ -484,11 +484,6 @@ void push_message(GString *msg)
"id %d changed", "id %d changed",
(str[9] << 8) | (str[10])); (str[9] << 8) | (str[10]));
if (ModifierLinkableList) {
modifier_group_free(ModifierLinkableList);
ModifierLinkableList = NULL;
}
send_message(REQUEST_MODIFIER_LINKABLE_LIST, "\x00\x01", 2); send_message(REQUEST_MODIFIER_LINKABLE_LIST, "\x00\x01", 2);
break; break;
} }
@@ -518,6 +513,11 @@ void push_message(GString *msg)
"Position: %2.1d Value: %6.1d: %s", "Position: %2.1d Value: %6.1d: %s",
param->id, param->id,
param->position, param->value, "XXX"); param->position, param->value, "XXX");
GDK_THREADS_ENTER();
apply_setting_param_to_gui(param);
GDK_THREADS_LEAVE();
setting_param_free(param); setting_param_free(param);
} while ( (x < msg->len) && n < tot); } while ( (x < msg->len) && n < tot);
@@ -536,7 +536,7 @@ void push_message(GString *msg)
printf("\n"); printf("\n");
} }
modifier_linkable_list(msg); update_modifier_linkable_list(msg);
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
@@ -1365,6 +1365,10 @@ static gboolean request_who_am_i(unsigned char *device_id, unsigned char *family
*family_id = data->str[9]; *family_id = data->str[9];
*product_id = data->str[10]; *product_id = data->str[10];
g_string_free(data, TRUE); g_string_free(data, TRUE);
debug_msg(DEBUG_STARTUP, "Found device id %d family %d product id %d.",
*device_id,
*family_id,
*product_id);
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@@ -1487,7 +1491,7 @@ int main(int argc, char *argv[]) {
GList *device = NULL; GList *device = NULL;
int num_devices = 0; int num_devices = 0;
int chosen_device = 0; int chosen_device = 0;
if (get_digitech_devices(&devices) <= 0) { if ((num_devices = get_digitech_devices(&devices)) <= 0) {
g_warning("Couldn't find DigiTech devices!"); g_warning("Couldn't find DigiTech devices!");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

37
gui.c
View File

@@ -683,10 +683,12 @@ GtkWidget *create_widget_container(EffectGroup *group, gint amt, gint id, gint p
/** /**
* Populate a combo box with text entries from the modifier group. * Populate a combo box with text entries from the modifier group.
*/ */
void update_modifier_combo_box(GObject *combo_box, EffectGroup *group, gint amt, gint id, gint position) void update_modifier_combo_box(GObject *combo_box, gint id, gint position)
{ {
gint x; gint x;
EffectSettingsGroup *settings = NULL; EffectSettingsGroup *settings = NULL;
EffectGroup *group = get_modifier_group();
guint amt = get_modifier_amt();
for (x = 0; x<amt; x++) { for (x = 0; x<amt; x++) {
gchar *name; gchar *name;
@@ -711,7 +713,7 @@ void update_modifier_combo_box(GObject *combo_box, EffectGroup *group, gint amt,
static void widget_tree_elem_free(GList *); static void widget_tree_elem_free(GList *);
static void clean_modifier_combo_box (GObject *ComboBox, GList *list) static void clean_modifier_combo_box (GObject *combo_box, GList *list)
{ {
EffectSettingsGroup *settings = NULL; EffectSettingsGroup *settings = NULL;
WidgetTreeElem *el; WidgetTreeElem *el;
@@ -727,9 +729,9 @@ static void clean_modifier_combo_box (GObject *ComboBox, GList *list)
/* Useless assignment, but silences compiler warning. */ /* Useless assignment, but silences compiler warning. */
link = g_list_remove_link(list, link); link = g_list_remove_link(list, link);
g_assert(ComboBox == el->widget); g_assert(combo_box == el->widget);
name = g_strdup_printf("SettingsGroup%d", el->x); name = g_strdup_printf("SettingsGroup%d", el->x);
settings = g_object_steal_data(G_OBJECT(ComboBox), name); settings = g_object_steal_data(G_OBJECT(combo_box), name);
g_free(name); g_free(name);
g_slice_free(EffectSettingsGroup, settings); g_slice_free(EffectSettingsGroup, settings);
@@ -737,7 +739,7 @@ static void clean_modifier_combo_box (GObject *ComboBox, GList *list)
} }
link = next; link = next;
} }
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(ComboBox)); gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(combo_box));
} }
/** /**
@@ -754,7 +756,7 @@ create_modifier_group (guint pos, guint id)
gpointer key; gpointer key;
WidgetTreeElem *el; WidgetTreeElem *el;
GList *list; GList *list;
GObject *AssignComboBox; GObject *modifier_combo_box;
debug_msg(DEBUG_GROUP, "Building modifier group for position %d id %d \"%s\"", debug_msg(DEBUG_GROUP, "Building modifier group for position %d id %d \"%s\"",
pos, id, get_xml_settings(id, pos)->label); pos, id, get_xml_settings(id, pos)->label);
@@ -780,18 +782,15 @@ create_modifier_group (guint pos, guint id)
return; return;
} }
AssignComboBox = el->widget; modifier_combo_box = el->widget;
g_assert(AssignComboBox != NULL); g_assert(modifier_combo_box != NULL);
vbox = g_object_get_data(AssignComboBox, "vbox"); vbox = g_object_get_data(modifier_combo_box, "vbox");
g_assert(vbox != NULL); g_assert(vbox != NULL);
clean_modifier_combo_box(AssignComboBox, list); clean_modifier_combo_box(modifier_combo_box, list);
update_modifier_combo_box(AssignComboBox, update_modifier_combo_box(modifier_combo_box, id, pos);
ModifierLinkableList->group,
ModifierLinkableList->group_amt,
id, pos);
get_option(id, pos); get_option(id, pos);
} }
@@ -1508,15 +1507,9 @@ void gui_create(Device *device)
g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL);
/* Not part of the preset, but update from the device. */ /* Get the initial values for the linkable parameters and the globals. */
get_option(TUNING_REFERENCE, GLOBAL_POSITION);
get_option(USB_AUDIO_PLAYBACK_MIX, GLOBAL_POSITION);
get_option(GUI_MODE_ON_OFF, GLOBAL_POSITION);
get_option(USB_AUDIO_LEVEL, GLOBAL_POSITION);
get_option(EXP_PEDAL_LEVEL, GLOBAL_POSITION);
get_option(STOMP_MODE, GLOBAL_POSITION);
send_message(REQUEST_MODIFIER_LINKABLE_LIST, "\x00\x01", 2); send_message(REQUEST_MODIFIER_LINKABLE_LIST, "\x00\x01", 2);
send_message(REQUEST_GLOBAL_PARAMETERS, "\x00\x01", 2);
} }
/** /**