/* * File: beet.c * * Summary: Simple MIDI Note Player (C version) * * Author: Tobias Kunze * E-Mail: tkunze@ccrma.stanford.edu * Org: * * Orig-Date: 5-Apr-97 at 22:05:37 * Last-Mod: 23-Feb-98 at 23:36:32 by Tobias Kunze * * Description: cc -o beet beet.c -lmi_d * * "$Revision: 1.2.1 $" */ #include #include "../../include/mi_d.h" void main(int argc, char* argv[]) { int res, i; int qtr = 350; /* quarter note tempo (in ms) */ unsigned long time = 0; /* note time stamp */ int dur; /* note duration */ short notes[] /* the melody */ = {64, 64, 65, 67, 67, 65, 64, 62, 60, 60, 62, 64, 64, 62, 62}; /* make sure we've got exactly one argument */ if (argc != 2) { fprintf(stderr, "Usage: %s interface\n", argv[0]); return; } /* Open MIDI for 16 channels, 1 route and connection, 16+1 */ /* mapping cells and allocate a small queue of 100 or so events */ res = mi_dOpen("Hello Mi_D", 16, 1, 1, 17, 100); if (res != mi_dNoErr) { fprintf(stderr, "Can't open MIDI (%d)\n", res); } else { /* use standard channel and route maps */ mi_dStandardMaps(); /* connect to the given interface */ res = mi_dConnect(0, argv[1], mi_dOutput); if (res != mi_dNoErr) { fprintf(stderr, "Can't connect to \"%s\" (%d)\n", argv[1], res); } else { /* reset timer */ mi_dSetTime(0UL); /* play the melody */ for (i = 0; i < 15; i++) { dur = qtr * (i == 12 ? 1.5 : i == 13 ? .5 : i == 14 ? 2 : 1); mi_dWriteNote_3c(0, notes[i], 64, 64, dur, time); time += dur; } } } mi_dClose(); return; } /* * -*- EOF -*- */