diff options
Diffstat (limited to 'scripts/midi.c')
-rw-r--r-- | scripts/midi.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/midi.c b/scripts/midi.c new file mode 100644 index 0000000..97c66dc --- /dev/null +++ b/scripts/midi.c | |||
@@ -0,0 +1,40 @@ | |||
1 | // | ||
2 | // Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu> | ||
3 | // Creation Date: Tue Dec 22 20:12:18 PST 1998 | ||
4 | // Last Modified: Tue Dec 22 20:12:23 PST 1998 | ||
5 | // Filename: insimple.c | ||
6 | // Syntax: C; pthread | ||
7 | // $Smake: gcc -O3 -Wall -o %b %f -static -lpthread && strip %b | ||
8 | // | ||
9 | |||
10 | #include <sys/soundcard.h> | ||
11 | #include <fcntl.h> | ||
12 | #include <unistd.h> | ||
13 | #include <stdio.h> | ||
14 | |||
15 | #define MIDI_DEVICE "/dev/sequencer" | ||
16 | |||
17 | |||
18 | int main(void) { | ||
19 | unsigned char inpacket[4]; | ||
20 | |||
21 | // first open the sequencer device for reading. | ||
22 | int seqfd = open(MIDI_DEVICE, O_RDONLY); | ||
23 | if (seqfd == -1) { | ||
24 | printf("Error: cannot open %s\n", MIDI_DEVICE); | ||
25 | exit(1); | ||
26 | } | ||
27 | |||
28 | // now just wait around for MIDI bytes to arrive and print them to screen. | ||
29 | while (1) { | ||
30 | read(seqfd, &inpacket, sizeof(inpacket)); | ||
31 | |||
32 | // print the MIDI byte if this input packet contains one | ||
33 | if (inpacket[0] == SEQ_MIDIPUTC) { | ||
34 | printf("received MIDI byte: %d\n", inpacket[1]); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | return 0; | ||
39 | } | ||
40 | |||