aseqdump: White-space and slight code refactoring

Fix white spaces and applied a slight code refactoring to reduce the
indentation levels.  No code functionality changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2024-06-27 13:40:45 +02:00
parent be6356d847
commit 7e7a53f0c9

View file

@ -254,7 +254,7 @@ static void list_ports(void)
} }
} }
void send_midi_msg(snd_seq_event_type_t type, mbyte_t *data, int len) static void send_midi_msg(snd_seq_event_type_t type, mbyte_t *data, int len)
{ {
snd_seq_event_t ev; snd_seq_event_t ev;
@ -264,11 +264,8 @@ void send_midi_msg(snd_seq_event_type_t type, mbyte_t *data, int len)
snd_seq_ev_set_direct(&ev); snd_seq_ev_set_direct(&ev);
if (type == SND_SEQ_EVENT_SYSEX) { if (type == SND_SEQ_EVENT_SYSEX) {
snd_seq_ev_set_sysex(&ev, len, data); snd_seq_ev_set_sysex(&ev, len, data);
} else { } else {
mbyte_t ch = data[0] & 0xF; mbyte_t ch = data[0] & 0xF;
switch (type) { switch (type) {
@ -300,7 +297,6 @@ void send_midi_msg(snd_seq_event_type_t type, mbyte_t *data, int len)
snd_seq_event_output(seq, &ev); snd_seq_event_output(seq, &ev);
snd_seq_drain_output(seq); snd_seq_drain_output(seq);
} }
static int msg_byte_in_range(mbyte_t *data, mbyte_t len) static int msg_byte_in_range(mbyte_t *data, mbyte_t len)
@ -322,6 +318,8 @@ int main(int argc, char *argv[])
char do_port_list = 0; char do_port_list = 0;
char verbose = 0; char verbose = 0;
int sysex_interval = 1000; //us int sysex_interval = 1000; //us
int sent_data_c;
int k;
while ((c = getopt(argc, argv, "hi:Vvlp:s:")) != -1) { while ((c = getopt(argc, argv, "hi:Vvlp:s:")) != -1) {
switch (c) { switch (c) {
@ -375,28 +373,32 @@ int main(int argc, char *argv[])
for (; argv[optind]; ++optind) { for (; argv[optind]; ++optind) {
add_send_hex_data(argv[optind]); add_send_hex_data(argv[optind]);
} }
if (send_hex) parse_data(); if (send_hex)
parse_data();
} }
if (send_data) { if (!send_data)
exit(EXIT_SUCCESS);
init_seq(); init_seq();
create_port(); create_port();
if (snd_seq_parse_address(seq,&addr,port_name) == 0) { if (snd_seq_parse_address(seq, &addr, port_name) < 0) {
error("Unable to parse port name!");
exit(EXIT_FAILURE);
}
int sent_data_c = 0;//counter of actually sent bytes sent_data_c = 0; //counter of actually sent bytes
k = 0;
int k = 0;
while (k < send_data_length) { while (k < send_data_length) {
if (send_data[k] == 0xF0) { if (send_data[k] == 0xF0) {
int c1 = k; int c1 = k;
while (c1 < send_data_length) while (c1 < send_data_length) {
{ if (send_data[c1] == 0xF7)
if (send_data[c1] == 0xF7) break; break;
c1++; c1++;
} }
@ -421,58 +423,51 @@ int main(int argc, char *argv[])
send_midi_msg(SND_SEQ_EVENT_NOTEOFF, send_data+k, 3); send_midi_msg(SND_SEQ_EVENT_NOTEOFF, send_data+k, 3);
sent_data_c += 3; sent_data_c += 3;
} }
k = k+3; k += 3;
} else if (tp == 0x9) { } else if (tp == 0x9) {
if (msg_byte_in_range(send_data + k + 1, 2)) { if (msg_byte_in_range(send_data + k + 1, 2)) {
send_midi_msg(SND_SEQ_EVENT_NOTEON, send_data+k, 3); send_midi_msg(SND_SEQ_EVENT_NOTEON, send_data+k, 3);
sent_data_c += 3; sent_data_c += 3;
} }
k = k+3; k += 3;
} else if (tp == 0xA) { } else if (tp == 0xA) {
if (msg_byte_in_range(send_data + k + 1, 2)) { if (msg_byte_in_range(send_data + k + 1, 2)) {
send_midi_msg(SND_SEQ_EVENT_KEYPRESS, send_data+k, 3); send_midi_msg(SND_SEQ_EVENT_KEYPRESS, send_data+k, 3);
sent_data_c += 3; sent_data_c += 3;
} }
k = k+3; k += 3;
} else if (tp == 0xB) { } else if (tp == 0xB) {
if (msg_byte_in_range(send_data + k + 1, 2)) { if (msg_byte_in_range(send_data + k + 1, 2)) {
send_midi_msg(SND_SEQ_EVENT_CONTROLLER, send_data+k, 3); send_midi_msg(SND_SEQ_EVENT_CONTROLLER, send_data+k, 3);
sent_data_c += 3; sent_data_c += 3;
} }
k = k+3; k += 3;
} else if (tp == 0xC) { } else if (tp == 0xC) {
if (msg_byte_in_range(send_data + k + 1, 1)) { if (msg_byte_in_range(send_data + k + 1, 1)) {
send_midi_msg(SND_SEQ_EVENT_PGMCHANGE, send_data+k, 2); send_midi_msg(SND_SEQ_EVENT_PGMCHANGE, send_data+k, 2);
sent_data_c += 2; sent_data_c += 2;
} }
k = k+2; k += 2;
} else if (tp == 0xD) { } else if (tp == 0xD) {
if (msg_byte_in_range(send_data + k + 1, 1)) { if (msg_byte_in_range(send_data + k + 1, 1)) {
send_midi_msg(SND_SEQ_EVENT_CHANPRESS, send_data+k, 2); send_midi_msg(SND_SEQ_EVENT_CHANPRESS, send_data+k, 2);
sent_data_c += 2; sent_data_c += 2;
} }
k = k+2; k += 2;
} else if (tp == 0xE) { } else if (tp == 0xE) {
if (msg_byte_in_range(send_data + k + 1, 2)) { if (msg_byte_in_range(send_data + k + 1, 2)) {
send_midi_msg(SND_SEQ_EVENT_PITCHBEND, send_data+k, 3); send_midi_msg(SND_SEQ_EVENT_PITCHBEND, send_data+k, 3);
sent_data_c += 3; sent_data_c += 3;
} }
k = k+3; k += 3;
} else k++; } else
k++;
} }
} }
if (verbose) if (verbose)
printf("Sent : %u bytes\n", sent_data_c); printf("Sent : %u bytes\n", sent_data_c);
} else {
error("Unable to parse port name!");
exit(EXIT_FAILURE);
}
snd_seq_close(seq); snd_seq_close(seq);
}
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }