~ubuntu-branches/ubuntu/oneiric/oss4/oneiric-proposed

« back to all changes in this revision

Viewing changes to tutorials/sndkit/samples/midiin.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2011-06-16 20:37:48 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110616203748-jbrxik6ql33z54co
Tags: 4.2-build2004-1ubuntu1
* Merge from Debian unstable.
  - Supports our current kernel (LP: #746048)
  Remaining changes:
  - debian/oss4-dkms.dkms.in: s/source/build/ in Kernel headers paths.
* ld-as-needed.patch: Re-order CC arguments to enable building with ld
  --as-needed (LP: #770972)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Purpose: A minimalistic MIDI input programming sample.
 
3
 * Copyright (C) 4Front Technologies, 2002-2004. Released under GPLv2/CDDL.
 
4
 *
 
5
 * Description:
 
6
 * This simple program opens a MIDI device file and displays everything
 
7
 * it receives in hexadecimal format.
 
8
 *
 
9
 * Please look at the "{!link MIDI}" section of the OSS Developer's
 
10
 * manual for more info about MIDI programming.
 
11
 */
 
12
 
 
13
#include <stdio.h>
 
14
#include <unistd.h>
 
15
#include <stdlib.h>
 
16
#include <fcntl.h>
 
17
#include <soundcard.h>
 
18
 
 
19
#define DEVICE "/dev/midi"
 
20
 
 
21
int
 
22
main ()
 
23
{
 
24
  int fd;
 
25
  unsigned char buf[128];
 
26
  int l;
 
27
 
 
28
  if ((fd = open (DEVICE, O_RDONLY, 0)) == -1)
 
29
    {
 
30
      perror ("open " DEVICE);
 
31
      exit (-1);
 
32
    }
 
33
 
 
34
/*
 
35
 * Note that read may return any number of bytes between 0 and sizeof(buf).
 
36
 * -1 means that some error has occurred.
 
37
 */
 
38
 
 
39
  while ((l = read (fd, buf, sizeof (buf))) != -1)
 
40
    {
 
41
      int i;
 
42
 
 
43
      for (i = 0; i < l; i++)
 
44
        {
 
45
          if (buf[i] & 0x80)    /* Status byte */
 
46
            printf ("\n");
 
47
          printf ("%02x ", buf[i]);
 
48
        }
 
49
 
 
50
      fflush (stdout);
 
51
    }
 
52
 
 
53
  close (fd);
 
54
  exit (0);
 
55
}