amidi: ignore not only Active Sensing but also Clock bytes

Active Sensing messages are sent by many devices in the background and
would only interfere with the actual messages that amidi is supposed to
capture.  Therefore, amidi ignores them by default.  However, there are
also devices that send Clock messages with the same problem, so it is
a better idea to filter them out, too.

Reported-by: Martin Tarenskeen <m.tarenskeen@gmail.com>
Reviewd-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Clemens Ladisch 2016-08-13 16:41:23 +02:00 committed by Takashi Iwai
parent 675619eb29
commit 04322ca749
2 changed files with 26 additions and 8 deletions

View file

@ -1,4 +1,4 @@
.TH AMIDI 1 "26 Jun 2006" .TH AMIDI 1 "16 Apr 2016"
.SH NAME .SH NAME
amidi \- read from and write to ALSA RawMIDI ports amidi \- read from and write to ALSA RawMIDI ports
@ -80,9 +80,11 @@ to record a Standard MIDI (.mid) file, use
.B arecordmidi(1). .B arecordmidi(1).
.B amidi .B amidi
will filter out any Active Sensing bytes (FEh), unless the will filter out any Active Sensing and Clock bytes (FEh, F8h), unless the
.I \-a .I \-a
option has been given. or
.I \-c
options have been given.
.TP .TP
.I \-S, \-\-send\-hex="..." .I \-S, \-\-send\-hex="..."
@ -91,9 +93,11 @@ Sends the bytes specified as hexadecimal numbers to the MIDI port.
.TP .TP
.I \-d, \-\-dump .I \-d, \-\-dump
Prints data received from the MIDI port as hexadecimal bytes. Prints data received from the MIDI port as hexadecimal bytes.
Active Sensing bytes (FEh) will not be shown, unless the Active Sensing and Clock bytes (FEh, F8h) will not be shown, unless the
.I \-a .I \-a
option has been given. or
.I \-c
options have been given.
This option is useful for debugging. This option is useful for debugging.
@ -111,6 +115,11 @@ to stop receiving data.
Does not ignore Active Sensing bytes (FEh) when saving or printing Does not ignore Active Sensing bytes (FEh) when saving or printing
received MIDI commands. received MIDI commands.
.TP
.I \-c, \-\-clock
Does not ignore Clock bytes (F8h) when saving or printing received
MIDI commands.
.SH EXAMPLES .SH EXAMPLES
.TP .TP

View file

@ -77,7 +77,8 @@ static void usage(void)
"-d, --dump print received data as hexadecimal bytes\n" "-d, --dump print received data as hexadecimal bytes\n"
"-t, --timeout=seconds exits when no data has been received\n" "-t, --timeout=seconds exits when no data has been received\n"
" for the specified duration\n" " for the specified duration\n"
"-a, --active-sensing don't ignore active sensing bytes\n"); "-a, --active-sensing include active sensing bytes\n"
"-c, --clock include clock bytes\n");
} }
static void version(void) static void version(void)
@ -406,7 +407,7 @@ static void add_send_hex_data(const char *str)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
static const char short_options[] = "hVlLp:s:r:S::dt:a"; static const char short_options[] = "hVlLp:s:r:S::dt:ac";
static const struct option long_options[] = { static const struct option long_options[] = {
{"help", 0, NULL, 'h'}, {"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'}, {"version", 0, NULL, 'V'},
@ -419,10 +420,12 @@ int main(int argc, char *argv[])
{"dump", 0, NULL, 'd'}, {"dump", 0, NULL, 'd'},
{"timeout", 1, NULL, 't'}, {"timeout", 1, NULL, 't'},
{"active-sensing", 0, NULL, 'a'}, {"active-sensing", 0, NULL, 'a'},
{"clock", 0, NULL, 'c'},
{ } { }
}; };
int c, err, ok = 0; int c, err, ok = 0;
int ignore_active_sensing = 1; int ignore_active_sensing = 1;
int ignore_clock = 1;
int do_send_hex = 0; int do_send_hex = 0;
while ((c = getopt_long(argc, argv, short_options, while ((c = getopt_long(argc, argv, short_options,
@ -463,6 +466,9 @@ int main(int argc, char *argv[])
case 'a': case 'a':
ignore_active_sensing = 0; ignore_active_sensing = 0;
break; break;
case 'c':
ignore_clock = 0;
break;
default: default:
error("Try `amidi --help' for more information."); error("Try `amidi --help' for more information.");
return 1; return 1;
@ -589,7 +595,10 @@ int main(int argc, char *argv[])
} }
length = 0; length = 0;
for (i = 0; i < err; ++i) for (i = 0; i < err; ++i)
if (!ignore_active_sensing || buf[i] != 0xfe) if ((buf[i] != MIDI_CMD_COMMON_CLOCK &&
buf[i] != MIDI_CMD_COMMON_SENSING) ||
(buf[i] == MIDI_CMD_COMMON_CLOCK && !ignore_clock) ||
(buf[i] == MIDI_CMD_COMMON_SENSING && !ignore_active_sensing))
buf[length++] = buf[i]; buf[length++] = buf[i];
if (length == 0) if (length == 0)
continue; continue;