File: midiin.c

package info (click to toggle)
oss4 4.2-build2020-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,320 kB
  • sloc: ansic: 239,151; cpp: 18,981; sh: 4,590; pascal: 3,863; asm: 1,189; makefile: 574; php: 53; xml: 46
file content (55 lines) | stat: -rw-r--r-- 1,069 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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);
}