Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/midirecord add "-R <roundbeats>" option, to round be...



details:   https://anonhg.NetBSD.org/src/rev/264479a01c3d
branches:  trunk
changeset: 340656:264479a01c3d
user:      mrg <mrg%NetBSD.org@localhost>
date:      Wed Sep 23 05:31:01 2015 +0000

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

diffstat:

 usr.bin/midirecord/midirecord.1 |  10 ++++++++--
 usr.bin/midirecord/midirecord.c |  21 ++++++++++++++++++---
 2 files changed, 26 insertions(+), 5 deletions(-)

diffs (101 lines):

diff -r 9b24b38d4238 -r 264479a01c3d usr.bin/midirecord/midirecord.1
--- a/usr.bin/midirecord/midirecord.1   Wed Sep 23 05:28:14 2015 +0000
+++ b/usr.bin/midirecord/midirecord.1   Wed Sep 23 05:31:01 2015 +0000
@@ -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 @@
 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 .
diff -r 9b24b38d4238 -r 264479a01c3d usr.bin/midirecord/midirecord.c
--- a/usr.bin/midirecord/midirecord.c   Wed Sep 23 05:28:14 2015 +0000
+++ b/usr.bin/midirecord/midirecord.c   Wed Sep 23 05:31:01 2015 +0000
@@ -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 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 @@
                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 @@
        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 @@
                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;



Home | Main Index | Thread Index | Old Index