diff --git a/example.midizaprc b/example.midizaprc index 638b586..132bae6 100644 --- a/example.midizaprc +++ b/example.midizaprc @@ -110,8 +110,15 @@ #DEBUG_KEYS +# Finally, the following option prints all MIDI input (with the input port +# number in the first, and the actual data value in the last column). This is +# useful as a simple MIDI monitor, especially if you want to figure out which +# tokens to use in your translations. + +#DEBUG_MIDI + # NOTE: The debugging options can also be specified on the command line -# using -d in conjunction with any of the letters r, s and k (or the +# using -d in conjunction with any of the letters r, s, k and m (or the # letter j if you also want debugging output from Jack). Just -d # without any option letter turns on all debugging options. diff --git a/midizap.c b/midizap.c index d117df2..e442348 100644 --- a/midizap.c +++ b/midizap.c @@ -251,6 +251,21 @@ static char *debug_key(translation *tr, char *name, return name; } +static void debug_input(translation *tr, int portno, + int status, int chan, int data, int data2) +{ + char name[100]; + if (status == 0xe0) + // translate LSB,MSB to a pitch bend value in the range -8192..8191 + data2 = ((data2 << 7) | data) - 8192; + if (status == 0xc0) + printf("[%d] %s\n", portno, + debug_key(tr, name, status, chan, data, 0)); + else + printf("[%d] %s value = %d\n", portno, + debug_key(tr, name, status, chan, data, 0), data2); +} + void send_strokes(translation *tr, uint8_t portno, int status, int chan, int data, int index, int dir) @@ -486,6 +501,7 @@ handle_event(uint8_t *msg, uint8_t portno) msg[0] = status | chan; msg[2] = 0; } + if (debug_midi) debug_input(tr, portno, status, chan, msg[1], msg[2]); switch (status) { case 0xc0: send_strokes(tr, portno, status, chan, msg[1], 0, 0); @@ -647,6 +663,9 @@ main(int argc, char **argv) case 'k': default_debug_keys = 1; break; + case 'm': + default_debug_midi = 1; + break; case 'j': debug_jack = 1; break; @@ -658,7 +677,8 @@ main(int argc, char **argv) ++a; } } else { - default_debug_regex = default_debug_strokes = default_debug_keys = 1; + default_debug_regex = default_debug_strokes = default_debug_keys = + default_debug_midi = 1; debug_jack = 1; } break; diff --git a/midizap.h b/midizap.h index 137c2c0..497bf3b 100644 --- a/midizap.h +++ b/midizap.h @@ -89,8 +89,9 @@ extern int read_config_file(void); extern translation *get_translation(char *win_title, char *win_class); extern void print_stroke_sequence(char *name, char *up_or_down, stroke *s); extern translation *default_translation, *default_midi_translation[2]; -extern int debug_regex, debug_strokes, debug_keys; -extern int default_debug_regex, default_debug_strokes, default_debug_keys; +extern int debug_regex, debug_strokes, debug_keys, debug_midi; +extern int default_debug_regex, default_debug_strokes, default_debug_keys, + default_debug_midi; extern char *config_file_name; extern int enable_jack_output; extern int midi_octave; diff --git a/readconfig.c b/readconfig.c index 5f809dc..2c430ab 100644 --- a/readconfig.c +++ b/readconfig.c @@ -190,10 +190,12 @@ int default_debug_regex = 0; int default_debug_strokes = 0; int default_debug_keys = 0; +int default_debug_midi = 0; int debug_regex = 0; int debug_strokes = 0; int debug_keys = 0; +int debug_midi = 0; int midi_octave = 0; @@ -1130,7 +1132,8 @@ read_config_file(void) } if (buf.st_mtime > config_file_modification_time) { config_file_modification_time = buf.st_mtime; - if (default_debug_regex || default_debug_strokes || default_debug_keys) { + if (default_debug_regex || default_debug_strokes || default_debug_keys || + default_debug_midi) { printf("Loading configuration: %s\n", config_file_name); } @@ -1148,6 +1151,7 @@ read_config_file(void) debug_regex = default_debug_regex; debug_strokes = default_debug_strokes; debug_keys = default_debug_keys; + debug_midi = default_debug_midi; midi_octave = 0; while ((line=read_line(f, config_file_name)) != NULL) { @@ -1203,6 +1207,10 @@ read_config_file(void) debug_keys = 1; continue; } + if (!strcmp(tok, "DEBUG_MIDI")) { + debug_midi = 1; + continue; + } if (!strncmp(tok, "MIDI_OCTAVE", 11)) { char *a = tok+11; int k, n;