Module Name:    src
Committed By:   mrg
Date:           Wed Sep 23 05:31:01 UTC 2015

Modified Files:
        src/usr.bin/midirecord: midirecord.1 midirecord.c

Log Message:
add "-R <roundbeats>" option, to round beat counts to be aligned to
<roundbeats>, which defaults to 1.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/midirecord/midirecord.1
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/midirecord/midirecord.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/midirecord/midirecord.1
diff -u src/usr.bin/midirecord/midirecord.1:1.4 src/usr.bin/midirecord/midirecord.1:1.5
--- src/usr.bin/midirecord/midirecord.1:1.4	Mon Jun  8 06:33:35 2015
+++ src/usr.bin/midirecord/midirecord.1	Wed Sep 23 05:31:01 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: midirecord.1,v 1.4 2015/06/08 06:33:35 mrg Exp $
+.\"	$NetBSD: midirecord.1,v 1.5 2015/09/23 05:31:01 mrg Exp $
 .\"
 .\" Copyright (c) 1998, 1999, 2001, 2002, 2010 Matthew R. Green
 .\" All rights reserved.
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd December 30, 2014
+.Dd July 22, 2015
 .Dt MIDIRECORD 1
 .Os
 .Sh NAME
@@ -38,6 +38,7 @@
 .Op Fl d Ar devices
 .Op Fl f Ar sequencerdev
 .Op Fl n Ar notesperbeat
+.Op Fl R Ar roundbeats
 .Op Fl r Ar raw_output
 .Op Fl T Ar tempo
 .Op Fl t Ar time
@@ -87,6 +88,11 @@ Start the relative timer at process star
 the first event.
 .It Fl q
 Be quiet.
+.It Fl R Ar roundbeats
+Round timings to
+.Ar roundbeats
+of a note.
+Output will always be aligned to this many beats.
 .It Fl r Ar raw_output
 Create the raw output of the sequencer device in
 .Ar raw_output .

Index: src/usr.bin/midirecord/midirecord.c
diff -u src/usr.bin/midirecord/midirecord.c:1.9 src/usr.bin/midirecord/midirecord.c:1.10
--- src/usr.bin/midirecord/midirecord.c:1.9	Sun Jun 21 06:04:45 2015
+++ src/usr.bin/midirecord/midirecord.c	Wed Sep 23 05:31:01 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: midirecord.c,v 1.9 2015/06/21 06:04:45 mrg Exp $	*/
+/*	$NetBSD: midirecord.c,v 1.10 2015/09/23 05:31:01 mrg Exp $	*/
 
 /*
  * Copyright (c) 2014 Matthew R. Green
@@ -33,7 +33,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: midirecord.c,v 1.9 2015/06/21 06:04:45 mrg Exp $");
+__RCSID("$NetBSD: midirecord.c,v 1.10 2015/09/23 05:31:01 mrg Exp $");
 #endif
 
 #include <sys/param.h>
@@ -72,6 +72,7 @@ static ssize_t	data_size;
 static struct timeval record_time;
 static struct timeval start_time;
 static int	tempo = 120;
+static unsigned	round_beats = 1;
 static unsigned	notes_per_beat = 24;
 static bool ignore_timer_fail = false;
 static bool stdout_mode = false;
@@ -144,6 +145,11 @@ main(int argc, char *argv[])
 		case 'r':
 			raw_output = optarg;
 			break;
+		case 'R':
+			decode_uint(optarg, &round_beats);
+			if (round_beats == 0)
+				errx(1, "-R <round_beats> must be a positive integer");
+			break;
 		case 't':
 			no_time_limit = 0;
 			decode_time(optarg, &record_time);
@@ -316,6 +322,7 @@ midi_event_timer_wait_abs_to_output(
 	size_t bufsize)
 {
 	static unsigned prev_div;
+	static int prev_leftover;
 	unsigned cur_div;
 	unsigned val = 0, xdiv;
 	int vallen = 0, i;
@@ -324,7 +331,15 @@ midi_event_timer_wait_abs_to_output(
 		prev_div = e.t_WAIT_ABS.divisions;
 	cur_div = e.t_WAIT_ABS.divisions;
 
-	xdiv = cur_div - prev_div;
+	xdiv = cur_div - prev_div + prev_leftover;
+	if (round_beats != 1) {
+		// round to closest
+		prev_leftover = xdiv % round_beats;
+		xdiv -= prev_leftover;
+		if (verbose)
+			fprintf(stderr, "adjusted beat value to %x (leftover = %d)\n",
+			    xdiv, prev_leftover);
+	}
 	if (xdiv) {
 		while (xdiv) {
 			uint32_t extra = val ? 0x80 : 0;

Reply via email to