// // Programmer: Craig Stuart Sapp // Creation Date: Mon Dec 21 18:00:42 PST 1998 // Last Modified: Mon Dec 21 18:00:42 PST 1998 // Filename: ...linuxmidi/output/method1.c // Syntax: C // $Smake: gcc -O -o %b %f && strip %b // // Description: This program sends out a single MIDI note (middle C) // and then exits. The MIDI driver usually turns the // note off automatically when the program is exited. // #include #include #include #include int main(void) { char* device = "/dev/sequencer"; unsigned char devnum = 0; unsigned char packet[4] = {SEQ_MIDIPUTC, 0, devnum, 0}; // step 1: open the OSS device for writing int fd = open(device, O_WRONLY); if (fd < 0) { printf("Error: cannot open %s\n", device); exit(1); } // step 2: write the note-on message to MIDI output packet[1] = 0x90; // note-on MIDI command write(fd, packet, sizeof(packet)); packet[1] = 60; // kenumber: 60 = middle c write(fd, packet, sizeof(packet)); packet[1] = 127; // attack velocity: 127 = loud write(fd, packet, sizeof(packet)); // step 3: (optional) close the device close(fd); return 0; }