2
* Purpose: A minimalistic MIDI output programming sample.
3
* Copyright (C) 4Front Technologies, 2002-2004. Released under GPLv2/CDDL.
6
* This program does nothing but plays a note on MIDI channel 1
7
* after sending a program change message.
9
* This program demonstrates how simple it's to write programs that play
10
* MIDI. All you need to do is assembling the MIDI message and writing
11
* it to the device. The MIDI format is defined in "MIDI 1.0 Detailed
12
* Specification" which is available from MIDI Manufacturs Association (MMA)
13
* (see {!hlink http://www.midi.org}).
15
* This program does timing by calling the sleep(3) system call. In some
16
* systems like Linux there may be better sleep routines like usleep(3)
17
* that provide better timing resolution.
19
* However application based timing may not be as precise as required in
20
* musical applications. For this reason the MIDI interface of OSS will
21
* provide a driver based timing approach in the near future.
23
* Please look at the "{!link MIDI}" section of the OSS Developer's
24
* manual for more info about MIDI programming.
31
#include <soundcard.h>
33
#define DEVICE "/dev/midi"
40
unsigned char note_on[] = { 0xc0, 0, /* Program change */
43
unsigned char note_off[] = { 0x80, 60, 60 }; /* Note off */
45
if ((fd = open (DEVICE, O_WRONLY, 0)) == -1)
47
perror ("open " DEVICE);
51
if (write (fd, note_on, sizeof (note_on)) == -1)
53
perror ("write " DEVICE);
57
sleep (1); /* Delay one second */
59
if (write (fd, note_off, sizeof (note_off)) == -1)
61
perror ("write " DEVICE);