Human readable debug

Leverage the code that writes a preset to XML so that messages
can be displayed in a human readable format.

E.g.,

(6, 2432, 1280)  Distortion: Dist Type: Screamer

The 3-tuple is position, id, value, which is followed by the
colon separated decode of the position, id, and the mapped value.
This commit is contained in:
Tim LaBerge
2012-04-06 08:57:08 -07:00
parent 1205a1639d
commit ea80320531
7 changed files with 177 additions and 36 deletions

View File

@@ -3970,7 +3970,7 @@ XmlSettings xml_settings[] = {
{WAH_ON_OFF, WAH_POSITION, "Wah Enable", &values_on_off, xml_on_off_labels, G_N_ELEMENTS(xml_on_off_labels)},
{WAH_PEDAL_POSITION, WAH_POSITION, "Wah Position", &values_0_to_99,},
{WAH_VOLUME_BOOST, WAH_POSITION, "Wah Vol. Boost", &values_db_boost,},
{MOD_TYPE, MOD_POSITION, "Mod Type", &values_0_to_99,}, // ???
//{MOD_TYPE, MOD_POSITION, "Mod Type", &values_0_to_99,}, // ???
{PRESET_LEVEL, PRESET_POSITION, "Preset Level", &values_0_to_99,},
@@ -4034,8 +4034,51 @@ XmlSettings xml_settings[] = {
{STOMP_MODE, GLOBAL_POSITION, "Stomp Mode", &values_0_to_99,},
};
guint n_xml_settings = G_N_ELEMENTS(xml_settings);
gchar *Positions[] = {
[ GLOBAL_POSITION ] = "Global",
[ PICKUP_POSITION ] = "Pickup",
[ WAH_POSITION ] = "Wah",
[ COMP_POSITION ] = "Compressor",
[ GNX3K_WHAM_POSITION ] = "Gnx3K Wham",
[ DIST_POSITION ] = "Distortion",
[ AMP_CHANNEL_POSITION ] = "Amp Channel",
[ GNX_CHANNEL_POSITION ] = "Gnx Channel",
[ AMP_A_POSITION ] = "Amp A",
[ AMP_CAB_POSITION ] = "Amp Cab A",
[ AMP_B_POSITION ] = "Amp B",
[ AMP_CAB_B_POSITION ] = "Amp Cab B",
[ NOISEGATE_POSITION ] = "Noise Gate",
[ VOLUME_PRE_FX_POSITION ] = "Volume Pre Fx",
[ CHORUSFX_POSITION ] = "Chorus Fx",
[ DELAY_POSITION ] = "Delay",
[ REVERB_POSITION ] = "Reverb",
[ VOLUME_POST_FX_POSITION ] = "Volume Post Fx",
[ PRESET_POSITION ] = "Preset",
[ EXP_POSITION ] = "Expression",
[ WAH_POSITION_MIN_MAX ] = "Wah Min Max",
[ VSWITCH_ASSIGN_POSITION ] = "Vswitch",
[ LFO1_POSITION ] = "LFO 1",
[ LFO2_POSITION ] = "LFO 2",
[ EQ_A_POSITION ] = "EQ A",
[ EQ_B_POSITION ] = "EQ B",
[ LIB_POSITION ] = "Library",
[ AMP_LOOP_POSITION ] = "Amp Loop",
};
guint max_position = G_N_ELEMENTS(Positions);
gchar *
get_position (guint position)
{
if (position > max_position) {
return "";
}
return Positions[position];
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
/**

View File

@@ -116,6 +116,7 @@ typedef struct {
gint n_banks;
} Device;
gchar *get_position(guint position);
ModifierGroup *modifier_linkable_list();
void modifier_group_free(ModifierGroup *modifier_group);
void get_values_info(EffectValues *values,

129
gdigi.c
View File

@@ -21,6 +21,7 @@
#include <alsa/asoundlib.h>
#include <alloca.h>
#include "gdigi.h"
#include "gdigi_xml.h"
#include "gui.h"
static unsigned char device_id = 0x7F;
@@ -55,6 +56,9 @@ gboolean set_debug_flags (const gchar *option_name, const gchar *value,
if (strchr(value, 'h')) {
DebugFlags |= DEBUG_MSG2HOST;
}
if (strchr(value, 'm')) {
DebugFlags |= DEBUG_MSG2DEV|DEBUG_MSG2HOST|DEBUG_GROUP;
}
if (strchr(value, 's')) {
DebugFlags |= DEBUG_STARTUP;
}
@@ -88,10 +92,105 @@ debug_msg (debug_flags_t flags, char *fmt, ...)
vsnprintf(buf, 1024, fmt, ap);
va_end(ap);
g_message("%s", buf);
fprintf(stderr, "%s\n", buf);
}
}
/*
* Format a value according to the xml setting.
* Returns an allocated buffer that must be freed by the caller.
*/
GString *
format_value (XmlSettings *xml, guint value)
{
GString *buf = g_string_sized_new(1);
EffectValues *values = NULL;
ValueType vtype;
gchar *suffix = "";
gdouble step = 1.0;
gint offset = 0;
gboolean decimal = FALSE;
values = xml->values;
vtype = values->type;
while ((vtype & VALUE_TYPE_EXTRA) && value_is_extra(values, value)) {
values = values->extra;
vtype = values->type;
}
vtype &= ~VALUE_TYPE_EXTRA;
if (vtype & VALUE_TYPE_OFFSET) {
offset = values->offset;
vtype &= ~VALUE_TYPE_OFFSET;
}
if (vtype & VALUE_TYPE_STEP) {
step = values->step;
vtype &= ~VALUE_TYPE_STEP;
}
if (vtype & VALUE_TYPE_SUFFIX) {
suffix = values->suffix;
vtype &= ~VALUE_TYPE_SUFFIX;
}
if (vtype & VALUE_TYPE_DECIMAL) {
decimal = TRUE;
vtype &= ~VALUE_TYPE_DECIMAL;
}
switch (vtype) {
case VALUE_TYPE_LABEL:
{
char *textp = map_xml_value(xml, value);
if (!textp) {
g_warning("Unable to map %s value %d for id %d position %d",
xml->label, value, xml->id, xml->position);
textp = "";
}
g_string_printf(buf, "%s", textp);
break;
}
case VALUE_TYPE_PLAIN:
{
if (decimal) {
double dvalue = (value + offset) * step;
g_string_printf(buf, "%0.2f%s", dvalue, suffix);
} else {
gint ivalue = (value + offset) * step;
g_string_printf(buf, "%d%s", ivalue, suffix);
}
break;
}
case VALUE_TYPE_NONE:
g_string_printf(buf, "%s", "");
break;
default:
g_warning("Unhandled value type %d", vtype);
break;
}
return buf;
}
GString *
format_ipv (guint id, guint pos, guint val)
{
GString *buf = g_string_sized_new(1);
GString *vec_buf = g_string_sized_new(1);
XmlSettings *xml = get_xml_settings(id, pos);
GString *val_buf = format_value(xml, val);
g_string_printf(vec_buf, "(%d, %d, %d)", pos, id, val);
g_string_printf(buf, "%-16s %s: %s: %s",
vec_buf->str,
get_position(pos), xml->label, val_buf->str);
g_string_free(vec_buf, TRUE);
g_string_free(val_buf, TRUE);
return buf;
}
/**
* Registers an error quark for gdigi if necessary.
*
@@ -275,9 +374,6 @@ MessageID get_message_id(GString *msg)
return -1;
}
#include "gdigi_xml.h"
extern XmlSettings *get_xml_settings (guint id, guint position);
void push_message (GString *msg)
{
MessageID msgid = get_message_id(msg);
@@ -315,13 +411,14 @@ void push_message(GString *msg)
{
unpack_message(msg);
param = setting_param_new_from_data(&msg->str[8], NULL);
XmlSettings *xml = get_xml_settings(param->id, param->position);
char *label = xml ? xml->label : "NULL";
debug_msg(DEBUG_MSG2HOST,
"RECEIVE_PARAMETER_VALUE: ID: %5d Position: %2d "
"Value: %6.1d: %s",
param->id, param->position,
param->value, label);
if (debug_flag_is_set(DEBUG_MSG2HOST)) {
GString *ipv = format_ipv(param->id,
param->position,
param->value);
debug_msg(DEBUG_MSG2HOST, "RECEIVE_PARAMETER_VALUE\n%s",
ipv->str);
g_string_free(ipv, TRUE);
}
GDK_THREADS_ENTER();
apply_setting_param_to_gui(param);
@@ -545,8 +642,9 @@ void send_message(gint procedure, gchar *data, gint len)
g_string_append_printf(msg, "%c\xF7",
calculate_checksum(&msg->str[1], msg->len - 1));
debug_msg(DEBUG_VERBOSE, "Sending message %s len %d",
debug_msg(DEBUG_VERBOSE, "Sending %s len %d",
get_message_name(procedure), len);
send_data(msg->str, msg->len);
g_string_free(msg, TRUE);
@@ -805,8 +903,11 @@ void set_option(guint id, guint position, guint value)
((id & 0xFF00) >> 8), (id & 0xFF),
position);
append_value(msg, value);
debug_msg(DEBUG_MSG2DEV, "Sending id %d position %d value %d",
id, position, value);
if (debug_flag_is_set(DEBUG_MSG2DEV)) {
GString *ipv = format_ipv(id, position, value);
debug_msg(DEBUG_MSG2DEV, "RECEIVE_PARAMETER_VALUE\n%s", ipv->str);
g_string_free(ipv, TRUE);
}
send_message(RECEIVE_PARAMETER_VALUE, msg->str, msg->len);
g_string_free(msg, TRUE);
}

View File

@@ -530,7 +530,6 @@ enum {
};
#define MOD_TYPE 768
#define MOD_POSITION 768
#define MOD_PRE_POST 1798
#define CHORUSFX_TYPE 768
@@ -893,7 +892,6 @@ enum {
#define LIBRARY_EFFECTS 8705
#define EFFECTS_LEVEL 8706
#define LIBRARY_POSITION 25
#define LIB_POSITION 26
#define TONE_LIB_TYPE 8704
@@ -1145,5 +1143,6 @@ void set_preset_level(int level);
GStrv query_preset_names(gchar bank);
void message_list_free(GList *list);
GList *get_current_preset();
GString *format_ipv(guint id, guint pos, guint val);
#endif /* GDIGI_H */

View File

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

View File

@@ -330,10 +330,11 @@ Preset *create_preset_from_data(GList *list)
SettingParam *param = setting_param_new_from_data(&data->str[x], &x);
n++;
preset->params = g_list_prepend(preset->params, param);
debug_msg(DEBUG_MSG2HOST, "%3d ID %4d Position %2d "
"Value %6.1d",
n, param->id, param->position,
param->value);
if (debug_flag_is_set(DEBUG_MSG2HOST)) {
GString *ipv = format_ipv(param->id, param->position, param->value);
debug_msg(DEBUG_MSG2HOST, "%3d %s", n, ipv->str);
g_string_free(ipv, TRUE);
}
} while ((x < data->len) && n<total);
debug_msg(DEBUG_MSG2HOST, "TOTAL %d", total);
preset->params = g_list_sort(preset->params, params_cmp);

View File

@@ -84,10 +84,9 @@ map_xml_value(XmlSettings *xml, gint value)
return NULL;
}
gboolean value_is_extra (EffectValues *val, SettingParam *param)
gboolean value_is_extra (EffectValues *val, int value)
{
if ((param->value < val->min) || (param->value > val->max)) {
if ((value < val->min) || (value > val->max)) {
return TRUE;
}
return FALSE;
@@ -97,7 +96,6 @@ gboolean value_is_extra (EffectValues *val, SettingParam *param)
void
write_preset_to_xml(Preset *preset, gchar *filename)
{
int rc;
xmlTextWriterPtr writer;
GList *iter_params = preset->params;
@@ -178,7 +176,7 @@ write_preset_to_xml(Preset *preset, gchar *filename)
BAD_CAST xml->label);
values = xml->values;
type = values->type;
while ((type & VALUE_TYPE_EXTRA) && value_is_extra(values, param)) {
while ((type & VALUE_TYPE_EXTRA) && value_is_extra(values, param->value)) {
values = values->extra;
type = values->type;
}
@@ -249,10 +247,6 @@ write_preset_to_xml(Preset *preset, gchar *filename)
iter_params = iter_params->next;
}
/* Here we could close the elements ORDER and EXAMPLE using the
* function xmlTextWriterEndElement, but since we do not want to
* write any other elements, we simply call xmlTextWriterEndDocument,
* which will do all the work. */
rc = xmlTextWriterEndDocument(writer);
if (rc < 0) {
printf("testXmlwriterFilename: Error at xmlTextWriterEndDocument\n");