diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2013-05-03 21:08:42 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2013-05-03 21:08:42 +0400 |
commit | 1058def8e7827e56ce4a70afb4aeacb5dc44148f (patch) | |
tree | 4495d23e7b54ab5700e3839081e797c1eafe0db9 /tutorials/sndkit/samples/midiin.c | |
download | oss4-1058def8e7827e56ce4a70afb4aeacb5dc44148f.tar.gz |
Imported Upstream version 4.2-build2006upstream/4.2-build2006upstream
Diffstat (limited to 'tutorials/sndkit/samples/midiin.c')
-rw-r--r-- | tutorials/sndkit/samples/midiin.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tutorials/sndkit/samples/midiin.c b/tutorials/sndkit/samples/midiin.c new file mode 100644 index 0000000..ab6ca26 --- /dev/null +++ b/tutorials/sndkit/samples/midiin.c @@ -0,0 +1,55 @@ +/* + * Purpose: A minimalistic MIDI input programming sample. + * Copyright (C) 4Front Technologies, 2002-2004. Released under GPLv2/CDDL. + * + * Description: + * This simple program opens a MIDI device file and displays everything + * it receives in hexadecimal format. + * + * Please look at the "{!link MIDI}" section of the OSS Developer's + * manual for more info about MIDI programming. + */ + +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <fcntl.h> +#include <soundcard.h> + +#define DEVICE "/dev/midi" + +int +main () +{ + int fd; + unsigned char buf[128]; + int l; + + if ((fd = open (DEVICE, O_RDONLY, 0)) == -1) + { + perror ("open " DEVICE); + exit (-1); + } + +/* + * Note that read may return any number of bytes between 0 and sizeof(buf). + * -1 means that some error has occurred. + */ + + while ((l = read (fd, buf, sizeof (buf))) != -1) + { + int i; + + for (i = 0; i < l; i++) + { + if (buf[i] & 0x80) /* Status byte */ + printf ("\n"); + printf ("%02x ", buf[i]); + } + + fflush (stdout); + } + + close (fd); + exit (0); +} |