Cleanups on the Logging branch.

1) Add a more reasonable max value for the the pedal/vswitch assign values.
2) Minor format change in format_ipv().
3) Formatting cleanup in push_message(). Also change debug messages to
   emphasize message direction.
4) Cleanup startup messages and add one that emits device name.
5) Cleanup the option message so that it's complete and readable.
This commit is contained in:
Tim LaBerge
2012-04-08 09:41:04 -07:00
parent baa5fdff85
commit 2b1c74ac30
4 changed files with 95 additions and 58 deletions

View File

@@ -634,18 +634,19 @@ static EffectValues values_wah_type = {
.type = VALUE_TYPE_LABEL, .type = VALUE_TYPE_LABEL,
}; };
// 4259839 is 0x40 FFFF, i.e. 0x<pos> <val>.
static EffectValues values_exp_assign = { static EffectValues values_exp_assign = {
.min = 0.0, .max = 1.0, .min = 0.0, .max = 4259839.0,
.type = VALUE_TYPE_LABEL, .type = VALUE_TYPE_LABEL,
}; };
static EffectValues values_vswitch_pedal_assign = { static EffectValues values_vswitch_pedal_assign = {
.min = 0.0, .max = 1.0, .min = 0.0, .max = 4259839.0,
.type = VALUE_TYPE_LABEL, .type = VALUE_TYPE_LABEL,
}; };
static EffectValues values_vswitch_assign = { static EffectValues values_vswitch_assign = {
.min = 0.0, .max = 1.0, .min = 0.0, .max = 4259839.0,
.type = VALUE_TYPE_LABEL, .type = VALUE_TYPE_LABEL,
}; };
@@ -3952,8 +3953,6 @@ XmlSettings xml_settings[] = {
{SYNTH_TALK_VOX, CHORUSFX_POSITION, "Synth Talk Vox", &values_0_to_99,}, {SYNTH_TALK_VOX, CHORUSFX_POSITION, "Synth Talk Vox", &values_0_to_99,},
{SYNTH_TALK_BALANCE, CHORUSFX_POSITION, "Synth Talk Balance", &values_0_to_99,}, {SYNTH_TALK_BALANCE, CHORUSFX_POSITION, "Synth Talk Balance", &values_0_to_99,},
{DELAY_TYPE, DELAY_POSITION, "Delay Type", &values_delay_type, xml_delay_labels, G_N_ELEMENTS(xml_delay_labels)}, {DELAY_TYPE, DELAY_POSITION, "Delay Type", &values_delay_type, xml_delay_labels, G_N_ELEMENTS(xml_delay_labels)},
{DELAY_ON_OFF, DELAY_POSITION, "Delay Enable", &values_on_off, xml_on_off_labels, G_N_ELEMENTS(xml_on_off_labels)}, {DELAY_ON_OFF, DELAY_POSITION, "Delay Enable", &values_on_off, xml_on_off_labels, G_N_ELEMENTS(xml_on_off_labels)},
{DELAY_TIME, DELAY_POSITION, "Delay Time", &values_delay_time,}, {DELAY_TIME, DELAY_POSITION, "Delay Time", &values_delay_time,},
@@ -4265,6 +4264,7 @@ gboolean get_device_info(unsigned char device_id, unsigned char family_id,
for (x = 0; x < G_N_ELEMENTS(supported_devices); x++) { for (x = 0; x < G_N_ELEMENTS(supported_devices); x++) {
if (supported_devices[x]->product_id == product_id && supported_devices[x]->family_id == family_id) { if (supported_devices[x]->product_id == product_id && supported_devices[x]->family_id == family_id) {
*device = supported_devices[x]; *device = supported_devices[x];
debug_msg(DEBUG_STARTUP, "Device name %s.", (*device)->name);
return TRUE; return TRUE;
} }
} }

84
gdigi.c
View File

@@ -190,7 +190,7 @@ format_ipv (guint id, guint pos, guint val)
} }
val_buf = format_value(xml, val); val_buf = format_value(xml, val);
g_string_printf(vec_buf, "(%d, %d, %d)", pos, id, val); g_string_printf(vec_buf, "(%2d, %4d, %d)", pos, id, val);
g_string_printf(buf, "%-16s %s: %s: %s", g_string_printf(buf, "%-16s %s: %s: %s",
vec_buf->str, vec_buf->str,
get_position(pos), xml->label, val_buf->str); get_position(pos), xml->label, val_buf->str);
@@ -382,23 +382,27 @@ MessageID get_message_id(GString *msg)
return -1; return -1;
} }
void push_message (GString *msg) #define HEX_WIDTH 26
void push_message(GString *msg)
{ {
MessageID msgid = get_message_id(msg); MessageID msgid = get_message_id(msg);
if (((unsigned char)msg->str[0] == 0xF0) && ((unsigned char)msg->str[msg->len-1] == 0xF7)) if (((unsigned char)msg->str[0] == 0xF0) &&
((unsigned char)msg->str[msg->len-1] == 0xF7)) {
debug_msg(DEBUG_VERBOSE, "Pushing correct message!"); debug_msg(DEBUG_VERBOSE, "Pushing correct message!");
else } else {
g_warning("Pushing incorrect message!"); g_warning("Pushing incorrect message!");
}
int x; int x;
if (debug_flag_is_set(DEBUG_HEX)) { if (debug_flag_is_set(DEBUG_HEX)) {
for (x = 0; x<msg->len; x++) { for (x = 0; x<msg->len; x++) {
if (x && (x % 26) == 0) { if (x && (x % HEX_WIDTH) == 0) {
printf("\n"); printf("\n");
} }
printf("%02x ", (unsigned char)msg->str[x]); printf("%02x ", (unsigned char)msg->str[x]);
} }
if (x % 26) { if (x % HEX_WIDTH) {
printf("\n"); printf("\n");
} }
} }
@@ -423,7 +427,7 @@ void push_message (GString *msg)
GString *ipv = format_ipv(param->id, GString *ipv = format_ipv(param->id,
param->position, param->position,
param->value); param->value);
debug_msg(DEBUG_MSG2HOST, "RECEIVE_PARAMETER_VALUE\n%s", debug_msg(DEBUG_MSG2HOST, "Receive RECEIVE_PARAMETER_VALUE: %s",
ipv->str); ipv->str);
g_string_free(ipv, TRUE); g_string_free(ipv, TRUE);
} }
@@ -438,8 +442,10 @@ void push_message (GString *msg)
} }
case RECEIVE_DEVICE_NOTIFICATION: case RECEIVE_DEVICE_NOTIFICATION:
unpack_message(msg); {
unsigned char *str = (unsigned char*)msg->str; unsigned char *str = (unsigned char*)msg->str;
unpack_message(msg);
switch (str[8]) { switch (str[8]) {
case NOTIFY_PRESET_MOVED: case NOTIFY_PRESET_MOVED:
if (str[11] == PRESETS_EDIT_BUFFER && str[12] == 0) { if (str[11] == PRESETS_EDIT_BUFFER && str[12] == 0) {
@@ -448,16 +454,18 @@ void push_message (GString *msg)
g_timeout_add(0, apply_current_preset_to_gui, NULL); g_timeout_add(0, apply_current_preset_to_gui, NULL);
GDK_THREADS_LEAVE(); GDK_THREADS_LEAVE();
debug_msg(DEBUG_MSG2HOST, debug_msg(DEBUG_MSG2HOST,
"RECEIVE_DEVICE_NOTIFICATION: Loaded preset " "Receive RECEIVE_DEVICE_NOTIFICATION: Loaded preset "
"%d from bank %d", "%d from bank %d",
str[10], str[9]); str[10], str[9]);
} else { } else {
debug_msg(DEBUG_MSG2HOST, debug_msg(DEBUG_MSG2HOST,
"RECEIVE_DEVICE_NOTIFICATION: %d %d moved to " "Receive RECEIVE_DEVICE_NOTIFICATION: %d %d moved to "
"%d %d", "%d %d",
str[9], str[10], str[9], str[10],
str[11], str[12]); str[11], str[12]);
} }
break;
case NOTIFY_MODIFIER_GROUP_CHANGED: case NOTIFY_MODIFIER_GROUP_CHANGED:
{ {
int i; int i;
@@ -469,20 +477,25 @@ void push_message (GString *msg)
printf("\n"); printf("\n");
} }
debug_msg(DEBUG_MSG2HOST, debug_msg(DEBUG_MSG2HOST,
"NOTIFY_MODIFIER_GROUP_CHANGED: Modifier group " "Receive NOTIFY_MODIFIER_GROUP_CHANGED: Modifier group "
"id %d changed", "id %d changed",
(str[9] << 8) | (str[10])); (str[9] << 8) | (str[10]));
break; break;
} }
default: default:
g_warning("Received unhandled device notification 0x%x", g_warning("Received unhandled device notification 0x%x", str[11]);
str[11]); break;
} }
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
return; return;
}
case RECEIVE_GLOBAL_PARAMETERS: case RECEIVE_GLOBAL_PARAMETERS:
unpack_message(msg); {
gint tot, n, x; gint tot, n, x;
unpack_message(msg);
tot = (unsigned char)msg->str[9]; tot = (unsigned char)msg->str[9];
if (debug_flag_is_set(DEBUG_HEX)) { if (debug_flag_is_set(DEBUG_HEX)) {
for (n = 0; n < msg->len; n++) { for (n = 0; n < msg->len; n++) {
@@ -496,7 +509,7 @@ void push_message (GString *msg)
do { do {
param = setting_param_new_from_data(&msg->str[x], &x); param = setting_param_new_from_data(&msg->str[x], &x);
debug_msg(DEBUG_MSG2HOST, debug_msg(DEBUG_MSG2HOST,
"RECEIVE_GLOBAL_PARAMETERS ID: %5d " "Receive RECEIVE_GLOBAL_PARAMETERS ID: %5d "
"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");
@@ -505,9 +518,12 @@ void push_message (GString *msg)
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
return; return;
}
case RECEIVE_MODIFIER_LINKABLE_LIST: case RECEIVE_MODIFIER_LINKABLE_LIST:
{
gint tot, n;
unpack_message(msg); unpack_message(msg);
tot = (unsigned char)msg->str[9]; tot = (unsigned char)msg->str[9];
@@ -522,13 +538,14 @@ void push_message (GString *msg)
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
return; return;
}
default: default:
g_mutex_lock(message_queue_mutex); g_mutex_lock(message_queue_mutex);
g_queue_push_tail(message_queue, msg); g_queue_push_tail(message_queue, msg);
g_cond_signal(message_queue_cond); g_cond_signal(message_queue_cond);
g_mutex_unlock(message_queue_mutex); g_mutex_unlock(message_queue_mutex);
break;
} }
} }
@@ -551,7 +568,8 @@ gpointer read_data_thread(gboolean *stop)
unsigned short revents; unsigned short revents;
/* SysEx messages can't contain bytes with 8th bit set. /* SysEx messages can't contain bytes with 8th bit set.
memset our buffer to 0xFF, so if for some reason we'll get out of reply bounds, we'll catch it */ memset our buffer to 0xFF, so if for some reason we'll
get out of reply bounds, we'll catch it */
memset(buf, '\0', sizeof(buf)); memset(buf, '\0', sizeof(buf));
err = poll(pfds, npfds, 200); err = poll(pfds, npfds, 200);
@@ -913,7 +931,7 @@ void set_option(guint id, guint position, guint value)
append_value(msg, value); append_value(msg, value);
if (debug_flag_is_set(DEBUG_MSG2DEV)) { if (debug_flag_is_set(DEBUG_MSG2DEV)) {
GString *ipv = format_ipv(id, position, value); GString *ipv = format_ipv(id, position, value);
debug_msg(DEBUG_MSG2DEV, "RECEIVE_PARAMETER_VALUE\n%s", ipv->str); debug_msg(DEBUG_MSG2DEV, "Send RECEIVE_PARAMETER_VALUE: %s", ipv->str);
g_string_free(ipv, TRUE); g_string_free(ipv, TRUE);
} }
send_message(RECEIVE_PARAMETER_VALUE, msg->str, msg->len); send_message(RECEIVE_PARAMETER_VALUE, msg->str, msg->len);
@@ -1334,6 +1352,10 @@ static gboolean request_who_am_i(unsigned char *device_id, unsigned char *family
*device_id = data->str[8]; *device_id = data->str[8];
*family_id = data->str[9]; *family_id = data->str[9];
*product_id = data->str[10]; *product_id = data->str[10];
debug_msg(DEBUG_STARTUP, "Found device id %d family %d product id %d.",
*device_id,
*family_id,
*product_id);
g_string_free(data, TRUE); g_string_free(data, TRUE);
return TRUE; return TRUE;
} }
@@ -1381,8 +1403,24 @@ static void request_device_configuration()
static GOptionEntry options[] = { static GOptionEntry options[] = {
{"device", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &device_port, "MIDI device port to use", NULL}, {"device", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &device_port, "MIDI device port to use", NULL},
{"debug-flags", 'D', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_CALLBACK, set_debug_flags, {"debug-flags <flags>", 'D', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_CALLBACK, set_debug_flags,
"Set debug flags: any combination of a, d, h, s:\n", "<flags> any of a, d, g, h, m, s, x, v:\n"
" "
"a: Everything.\n"
" "
"d: Messages to the device.\n"
" "
"g: Group messages.\n"
" "
"h: Dump message contents in hex.\n"
" "
"m: All messages.\n"
" "
"s: Startup.\n"
" "
"x: Debug xml parsing/writing.\n"
" "
"v: Additional verbosity.\n" ,
NULL}, NULL},
{NULL} {NULL}
}; };
@@ -1455,9 +1493,9 @@ int main(int argc, char *argv[]) {
device_port = g_strdup_printf("hw:%d,0,0", device_port = g_strdup_printf("hw:%d,0,0",
GPOINTER_TO_INT(device->data)); GPOINTER_TO_INT(device->data));
g_list_free(devices); g_list_free(devices);
debug_msg(DEBUG_STARTUP, "Found device %s\n", device_port); debug_msg(DEBUG_STARTUP, "Found device %s.", device_port);
} else { } else {
debug_msg(DEBUG_STARTUP, "Using device %s\n", device_port); debug_msg(DEBUG_STARTUP, "Using device %s.", device_port);
} }
g_option_context_free(context); g_option_context_free(context);

View File

@@ -36,6 +36,5 @@ typedef struct {
XmlSettings *get_xml_settings(guint id, guint position); XmlSettings *get_xml_settings(guint id, guint position);
gboolean value_is_extra(EffectValues *val, int value); gboolean value_is_extra(EffectValues *val, int value);
gchar * map_xml_value(XmlSettings *xml, gint value); gchar * map_xml_value(XmlSettings *xml, gint value);
// gchar *get_xml_label(guint id, guint position, gint type);
#endif /* GDIGI_XML_H */ #endif /* GDIGI_XML_H */