From: pmalani@chromium.org
To: patch@alsa-project.org
Cc: Prashant Malani <pmalani@chromium.org>,
alsa-devel@alsa-project.org, derat@chromium.org
Subject: [PATCH 1/1] seq: arecordmidi: Add num-events option
Date: Mon, 28 Jan 2019 17:44:45 -0800 [thread overview]
Message-ID: <5c4fb010.1c69fb81.94ca0.01ae@mx.google.com> (raw)
From: Prashant Malani <pmalani@chromium.org>
Add a command line option to automatically exit after recording a fixed
number of MIDI events. This allows a program using arecordmidi to expect
a MIDI file to be written automatically when the specified number of
events have been received, instead of having to send a SIGINT or SIGTERM
programmatically.
It also avoids the need to have the arecordmidi process running in the
background, and then constantly stat the output file to check if any
bytes have been written to it (this makes for less predictable and
longer-running tests).
This functionality finds use in Chrome OS functional testing, since
having to send SIGTERM/SIGINT programmatically and then wait for the
output file adds unpredictability and delay to the tests.
The addition of this command-line option should (hopefully) not break
any existing usage.
Signed-off-by: Prashant Malani <pmalani@chromium.org>
diff --git a/seq/aplaymidi/arecordmidi.c b/seq/aplaymidi/arecordmidi.c
index 19dbb7d..ca25bfa 100644
--- a/seq/aplaymidi/arecordmidi.c
+++ b/seq/aplaymidi/arecordmidi.c
@@ -690,7 +690,8 @@ static void help(const char *argv0)
" -t,--ticks=ticks resolution in ticks per beat or frame\n"
" -s,--split-channels create a track for each channel\n"
" -m,--metronome=client:port play a metronome signal\n"
- " -i,--timesig=nn:dd time signature\n",
+ " -i,--timesig=nn:dd time signature\n"
+ " -n,--num-events=events fixed number of events to record, then exit\n",
argv0);
}
@@ -706,7 +707,7 @@ static void sighandler(int sig)
int main(int argc, char *argv[])
{
- static const char short_options[] = "hVlp:b:f:t:sdm:i:";
+ static const char short_options[] = "hVlp:b:f:t:sdm:i:n:";
static const struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
@@ -719,6 +720,7 @@ int main(int argc, char *argv[])
{"dump", 0, NULL, 'd'},
{"metronome", 1, NULL, 'm'},
{"timesig", 1, NULL, 'i'},
+ {"num-events", 1, NULL, 'n'},
{ }
};
@@ -727,6 +729,9 @@ int main(int argc, char *argv[])
struct pollfd *pfds;
int npfds;
int c, err;
+ /* If |num_events| isn't specified, leave it at 0. */
+ int num_events = 0;
+ int events_received = 0;
init_seq();
@@ -775,6 +780,11 @@ int main(int argc, char *argv[])
case 'i':
time_signature(optarg);
break;
+ case 'n':
+ num_events = atoi(optarg);
+ if (num_events <= 0)
+ fatal("num_events must be greater than 0");
+ break;
default:
help(argv[0]);
return 1;
@@ -864,13 +874,20 @@ int main(int argc, char *argv[])
err = snd_seq_event_input(seq, &event);
if (err < 0)
break;
- if (event)
+ if (event) {
record_event(event);
+ events_received++;
+ }
} while (err > 0);
if (stop)
break;
+ if (num_events && (events_received == num_events))
+ break;
}
+ if (num_events && events_received < num_events)
+ fputs("Warning: Received signal before num_events\n", stdout);
+
finish_tracks();
write_file();
--
2.20.1.495.gaa96b0ce6b-goog
next reply other threads:[~2019-01-29 1:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-29 1:44 pmalani [this message]
2019-01-29 3:36 ` [PATCH 1/1] seq: arecordmidi: Add num-events option Takashi Sakamoto
2019-01-29 5:34 ` Prashant Malani
2019-01-29 8:45 ` Takashi Sakamoto
2019-01-29 9:58 ` pmalani
2019-01-29 16:18 ` Clemens Ladisch
2019-01-29 23:42 ` Prashant Malani
2019-02-04 20:20 ` Prashant Malani
2019-02-11 4:23 ` Prashant Malani
2019-02-11 8:14 ` Takashi Iwai
2019-02-11 10:07 ` Prashant Malani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5c4fb010.1c69fb81.94ca0.01ae@mx.google.com \
--to=pmalani@chromium.org \
--cc=alsa-devel@alsa-project.org \
--cc=derat@chromium.org \
--cc=patch@alsa-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.