Timestamp in the output of aseqdump

I'm currently working on an Arduino based MIDI controler. So I use an USB interface for receiving bytes for debug. Classic. But at some time, I was thinking about a nano-sequencer in the Arduino. Writing code, with interleaved pooling, and some bad tricks. Remember : there was no scheduler in standard Arduino. Shit happen. Precise timing was broken by a sort of RDF.

One of my favorite tools can't help. It was a time problem, and aseqdump know nothing about the time. So we're gonna explain to him how to do it.

First patch

--- aseqdump.c.original	2017-11-29 21:31:36.797372286 +0100
+++ aseqdump.c	2017-11-29 22:22:12.875416088 +0100
@@ -24,6 +24,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <signal.h>
+#include <sys/time.h>
 #include <getopt.h>
 #include <sys/poll.h>
 #include <alsa/asoundlib.h>
@@ -34,7 +35,7 @@
 static int port_count;
 static snd_seq_addr_t *ports;
 static volatile sig_atomic_t stop = 0;
-
+static double start_time;
 
 /* prints an error message to stderr, and dies */
 static void fatal(const char *msg, ...)
@@ -128,8 +129,16 @@
 	}
 }
 
+static double dtime(void)
+{
+struct timeval tv;
+(void)gettimeofday(&tv, NULL);
+return (double)tv.tv_sec + ((double)tv.tv_usec)/1e6;
+}
+
 static void dump_event(const snd_seq_event_t *ev)
 {
+	printf("%9.3f ", dtime()-start_time);
 	printf("%3d:%-3d ", ev->source.client, ev->source.port);
 	switch (ev->type) {
 	case SND_SEQ_EVENT_NOTEON:
@@ -366,6 +375,7 @@
 	int c, err;
 
 	init_seq();
+	start_time = dtime();
 
 	while ((c = getopt_long(argc, argv, short_options,
 				long_options, NULL)) != -1) {

I think (at this time) that this patch was pretty efficient.
Next step : adding the arguments parsing for this friture, updating the man page, and the hard part : sending the patch upstream.

screenshot

xterm, need more xterm

First milestone reached

This kluge is hardcoded in the original version. Breaking the user experience is bad. Undocumenting this break is worse. So I added boilerplate in getopt, help and manpage.

~/Essais/MIDI/Tools $ ./sqdmp -h
Usage: ./sqdmp [options]

Available options:
  -h,--help                  this help
  -V,--version               show version
  -l,--list                  list input ports
  -p,--port=client:port,...  source port(s)
  -t,--timestamp             show timestamp
~/Essais/MIDI/Tools $ 

Event filter

When you work on a combo controler/sequencer, the MIDI output is a mix of note on/off, control/program changes, and more. Event overflow, hard to manage. So I need a filter in aseqdump.

  -f 'comma separated list of filters'
  -f cc,pc     mute control change & program change
  -f !,on      everithing except note-on

First step : coding the string parser. After that, plug it in the Makefile. In third, write the manpage with some usecase.

Ce code et la documentation qui va avec ont été écrites avec klangstube dans les oreilles.