diff --git a/gdigi.c b/gdigi.c index c75d050..34af79a 100644 --- a/gdigi.c +++ b/gdigi.c @@ -202,35 +202,52 @@ void push_message(GString *msg) printf("%02x ", (unsigned char)msg->str[x]); printf("\n"); - if (get_message_id(msg) == ACK) { - g_message("Received ACK"); - g_string_free(msg, TRUE); - return; + switch (get_message_id(msg)) { + case ACK: + g_message("Received ACK"); + g_string_free(msg, TRUE); + return; + + case NACK: + g_message("Received NACK"); + g_string_free(msg, TRUE); + return; + + case RECEIVE_PARAMETER_VALUE: + unpack_message(msg); + SettingParam *param = setting_param_new_from_data(&msg->str[8], NULL); + g_message("Received parameter change ID: %d Position: %d Value: %d", param->id, param->position, param->value); + + GDK_THREADS_ENTER(); + apply_setting_param_to_gui(param); + GDK_THREADS_LEAVE(); + + setting_param_free(param); + g_string_free(msg, TRUE); + return; + + case RECEIVE_DEVICE_NOTIFICATION: + unpack_message(msg); + unsigned char *str = (unsigned char*)msg->str; + switch (str[8]) { + case NOTIFY_PRESET_MOVED: + if (str[11] == PRESETS_EDIT_BUFFER && str[12] == 0) { + g_message("Loaded preset %d from bank %d", str[10], str[9]); + + GDK_THREADS_ENTER(); + g_timeout_add(0, apply_current_preset_to_gui, NULL); + GDK_THREADS_LEAVE(); + } else + g_message("%d %d moved to %d %d", str[9], str[10], str[11], str[12]); + return; + default: + g_message("Received unhandled device notification"); + } + default: + g_mutex_lock(message_queue_mutex); + g_queue_push_tail(message_queue, msg); + g_mutex_unlock(message_queue_mutex); } - - if (get_message_id(msg) == NACK) { - g_message("Received NACK"); - g_string_free(msg, TRUE); - return; - } - - if (get_message_id(msg) == RECEIVE_PARAMETER_VALUE) { - unpack_message(msg); - SettingParam *param = setting_param_new_from_data(&msg->str[8], NULL); - g_message("Received parameter change ID: %d Position: %d Value: %d", param->id, param->position, param->value); - - GDK_THREADS_ENTER(); - apply_setting_param_to_gui(param); - GDK_THREADS_LEAVE(); - - setting_param_free(param); - g_string_free(msg, TRUE); - return; - } - - g_mutex_lock(message_queue_mutex); - g_queue_push_tail(message_queue, msg); - g_mutex_unlock(message_queue_mutex); } gpointer read_data_thread(gboolean *stop) diff --git a/gdigi.h b/gdigi.h index 550173c..91dc19b 100644 --- a/gdigi.h +++ b/gdigi.h @@ -637,6 +637,23 @@ typedef enum { PRESETS_EXTERNAL = 6 } PresetBank; +typedef enum { + /* Version 0 only */ + NOTIFY_PRESET_LOADED = 0, + NOTIFY_PRESET_STORED = 1, + + NOTIFY_MODIFIER_GROUP_CHANGED = 2, + + /* Version 1 */ + NOTIFY_PRESET_MOVED = 3, + NOTIFY_OBJECT_MOVED = 4, + NOTIFY_OBJECT_RENAMED = 5, + NOTIFY_MEDIA_CARD_PRESENT_CHANGED = 6, + NOTIFY_ALL_GLOBALS_CHANGED = 7, + NOTIFY_PRESET_INDEX_TABLE_CHANGED = 8, + NOTIFY_PRESET_RENAMED = 9 +} NotifyCode; + typedef enum { REQUEST_WHO_AM_I = 0x01, RECEIVE_WHO_AM_I = 0x02, diff --git a/gui.c b/gui.c index 1b552cf..a00f858 100644 --- a/gui.c +++ b/gui.c @@ -199,6 +199,12 @@ static void apply_current_preset() preset_free(preset); } +gboolean apply_current_preset_to_gui(gpointer data) +{ + apply_current_preset(); + return FALSE; +} + /** * \param settings effect parameters * \param amt amount of effect parameters diff --git a/gui.h b/gui.h index f7f6b69..42538fb 100644 --- a/gui.h +++ b/gui.h @@ -22,6 +22,7 @@ void show_error_message(GtkWidget *parent, gchar *message); void apply_setting_param_to_gui(SettingParam *param); +gboolean apply_current_preset_to_gui(gpointer data); void gui_create(Device *device); void gui_free(); gboolean unsupported_device_dialog(Device **device);