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 a program to record midi files from /...



details:   https://anonhg.NetBSD.org/src/rev/7ce8366fb1cd
branches:  trunk
changeset: 805352:7ce8366fb1cd
user:      mrg <mrg%NetBSD.org@localhost>
date:      Tue Dec 30 04:14:25 2014 +0000

description:
add a program to record midi files from /dev/music.

this doesn't process several potential result that netbsd does
not output on /dev/music, and should be largely complete for
our current sequencer(4).

diffstat:

 usr.bin/midirecord/Makefile     |   15 +
 usr.bin/midirecord/midirecord.1 |  116 +++++
 usr.bin/midirecord/midirecord.c |  800 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 931 insertions(+), 0 deletions(-)

diffs (truncated from 943 to 300 lines):

diff -r 4bff979510ce -r 7ce8366fb1cd usr.bin/midirecord/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/midirecord/Makefile       Tue Dec 30 04:14:25 2014 +0000
@@ -0,0 +1,15 @@
+#      $NetBSD: Makefile,v 1.1 2014/12/30 04:14:25 mrg Exp $
+
+PROG=  midirecord
+
+.include <bsd.own.mk>
+
+LIBAUDIO != cd ${.CURDIR}/../audio/common && ${PRINTOBJDIR}
+CPPFLAGS+=-I${.CURDIR}/../audio/common
+DPADD+=        ${LIBAUDIO}/libaudio.a
+LDADD+=        -L${LIBAUDIO} -laudio
+
+DPADD+=        ${LIBUTIL}
+LDADD+=        -lutil
+
+.include <bsd.prog.mk>
diff -r 4bff979510ce -r 7ce8366fb1cd usr.bin/midirecord/midirecord.1
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/midirecord/midirecord.1   Tue Dec 30 04:14:25 2014 +0000
@@ -0,0 +1,116 @@
+.\"    $NetBSD: midirecord.1,v 1.1 2014/12/30 04:14:25 mrg Exp $
+.\"
+.\" Copyright (c) 1998, 1999, 2001, 2002, 2010 Matthew R. Green
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd December 29, 2014
+.Dt MIDIRECORD 1
+.Os
+.Sh NAME
+.Nm midiorecord
+.Nd record midi files
+.Sh SYNOPSIS
+.Nm
+.Op Fl afhoqV
+.Op Fl B Ar buffersize
+.Op Fl c Ar channels
+.Op Fl d Ar devices
+.Op Fl f Ar sequencerdev
+.Op Fl n Ar notesperbeat
+.Op Fl r Ar raw_output
+.Op Fl t Ar time
+.Op Fl T Ar tempo
+.Ar file
+.Sh DESCRIPTION
+The
+.Nm
+program converts the sequencer events read on
+.Ar sequencerdev
+to the named MIDI SMF output.
+If the file name is \-, output will go to the standard output.
+.Pp
+.Sh OPTIONS
+The following options are available:
+.Bl -tag -width XnXnotesperbeatX
+.It Fl a
+Append to the specified file, rather than overwriting.
+.It Fl B Ar buffersize
+Set the sequencer device read buffer size to
+.Ar buffersize .
+The default value is 32768 bytes.
+.It Fl c Ar channels
+Sets the filter list of channels to
+.Ar channels ,
+which is a comma separated list of channels to filter in.
+.It Fl D
+Enable debug log.
+.It Fl d Ar devices
+Sets the filter list of devices to
+.Ar devices ,
+which is a comma separated list of devices to filter in.
+.It Fl f Ar sequencerdev
+Sets the sequencer device to use to
+.Ar sequencerdev .
+The default is
+.Pa /dev/music .
+.It Fl h
+Print a help message.
+.It Fl n Ar notesperbeat
+Sets the MIDI notes (clocks) per beat to
+.Ar notesperbeat .
+.It Fl r Ar raw_output
+Create the raw output of the sequencer device in
+.Ar raw_output .
+.It Fl q
+Be quiet.
+.It Fl t Ar time
+Sets the maximum amount of time to record.
+Format is [hh:]mm:ss[.dddddd].
+.It Fl V
+Be verbose.
+.El
+.Sh ENVIRONMENT
+.Bl -tag -width MIDIDEVICE
+.It MIDIDEVICE
+the midi device to be used.
+.El
+.Sh SEE ALSO
+.Xr midiplay 1 ,
+.Xr midi 4 ,
+.Xr sequencer 4 .
+.Sh HISTORY
+The
+.Nm
+program was first seen in 
+.Nx 8 .
+.Sh AUTHORS
+The
+.Nm
+program was written by
+.An Matthew R. Green Aq Mt mrg%eterna.com.au@localhost .
+.Sh BUGS
+SYSEX, LOCAL and FULLSIZE messages are not currently handled, but the
+.Nx
+.Xr sequencer 4
+device does not generate them.
diff -r 4bff979510ce -r 7ce8366fb1cd usr.bin/midirecord/midirecord.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/midirecord/midirecord.c   Tue Dec 30 04:14:25 2014 +0000
@@ -0,0 +1,800 @@
+/*     $NetBSD: midirecord.c,v 1.1 2014/12/30 04:14:25 mrg Exp $       */
+
+/*
+ * Copyright (c) 2014 Matthew R. Green
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * midirecord(1), similar to audiorecord(1).
+ */
+
+#include <sys/cdefs.h>
+
+#ifndef lint
+__RCSID("$NetBSD: midirecord.c,v 1.1 2014/12/30 04:14:25 mrg Exp $");
+#endif
+
+#include <sys/param.h>
+#include <sys/midiio.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/uio.h>
+
+#include <err.h>
+#include <errno.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <util.h>
+#include <assert.h>
+#include <stdbool.h>
+
+#include "libaudio.h"
+
+static const char *midi_device;
+static unsigned        *filt_devnos = NULL;
+static unsigned        *filt_chans = NULL;
+static unsigned num_filt_devnos, num_filt_chans;
+static char    *raw_output;
+static int     midifd;
+static int     aflag, qflag, oflag;
+static bool debug = false;
+int    verbose;
+static int     outfd, rawfd = -1;
+static ssize_t data_size;
+static struct timeval record_time;
+static struct timeval start_time;
+static int     tempo = 120;
+static unsigned        notes_per_beat = 24;
+static bool ignore_timer_fail = false;
+
+static void debug_log(const char *, size_t, const char *, ...);
+static size_t midi_event_local_to_output(seq_event_t, u_char *, size_t);
+static size_t midi_event_timer_wait_abs_to_output(seq_event_t, u_char *,
+                                                 size_t);
+static size_t midi_event_timer_to_output(seq_event_t, u_char *, size_t);
+static size_t midi_event_chn_common_to_output(seq_event_t, u_char *, size_t);
+static size_t midi_event_chn_voice_to_output(seq_event_t, u_char *, size_t);
+static size_t midi_event_sysex_to_output(seq_event_t, u_char *, size_t);
+static size_t midi_event_fullsize_to_output(seq_event_t, u_char *, size_t);
+static size_t midi_event_to_output(seq_event_t, u_char *, size_t);
+static int timeleft(struct timeval *, struct timeval *);
+static bool filter_array(unsigned, unsigned *, size_t);
+static bool filter_dev(unsigned);
+static bool filter_chan(unsigned);
+static bool filter_devchan(unsigned, unsigned);
+static void parse_ints(const char *, unsigned **, unsigned *, const char *);
+static void cleanup(int) __dead;
+static void rewrite_header(void);
+static void write_midi_header(void);
+static void write_midi_trailer(void);
+static void usage(void) __dead;
+
+#define PATH_DEV_MUSIC "/dev/music"
+
+int
+main(int argc, char *argv[])
+{
+       u_char  *buffer;
+       size_t  bufsize = 0;
+       int     ch, no_time_limit = 1;
+
+       while ((ch = getopt(argc, argv, "aB:c:Dd:f:hn:qr:t:T:V")) != -1) {
+               switch (ch) {
+               case 'a':
+                       aflag++;
+                       break;
+               case 'B':
+                       bufsize = strsuftoll("read buffer size", optarg,
+                                            1, UINT_MAX);
+                       break;
+               case 'c':
+                       parse_ints(optarg, &filt_chans, &num_filt_chans,
+                           "channels");
+                       break;
+               case 'D':
+                       debug++;
+                       break;
+               case 'd':
+                       parse_ints(optarg, &filt_devnos, &num_filt_devnos,
+                           "devices");
+                       break;
+               case 'f':
+                       midi_device = optarg;
+                       ignore_timer_fail = true;
+                       break;
+               case 'n':
+                       decode_uint(optarg, &notes_per_beat);
+                       break;
+               case 'o':
+                       oflag++;        /* time stamp starts at proc start */
+                       break;
+               case 'q':
+                       qflag++;
+                       break;
+               case 'r':
+                       raw_output = optarg;
+                       break;
+               case 't':
+                       no_time_limit = 0;
+                       decode_time(optarg, &record_time);
+                       break;
+               case 'T':
+                       decode_int(optarg, &tempo);
+                       break;
+               case 'V':
+                       verbose++;
+                       break;
+               /* case 'h': */
+               default:
+                       usage();



Home | Main Index | Thread Index | Old Index