#include #include #include #include #define PPQN_TEMPO_FACTOR 10 unsigned char Phrase[] = {0, 0x90, 60, 127, 50, 0x90, 60, 00, 0, 0x91, 62, 127, 50, 0x91, 62, 00, 0, 0x92, 64, 127, 50, 0x92, 64, 00, 0, 0x93, 65, 127, 50, 0x93, 65, 00, 0, 0x94, 67, 127, 50, 0x94, 67, 00, 0, 0x95, 69, 127, 50, 0x95, 69, 00, 0, 0x96, 71, 127, 50, 0x96, 71, 00, 0, 0x97, 72, 127, 50, 0x97, 72, 00, 0, 0x98, 74, 127, 50, 0x98, 74, 00, 0, 0x99, 76, 127, 50, 0x99, 76, 00, 0, 0x9A, 77, 127, 50, 0x9A, 77, 00, 0, 0x9B, 79, 127, 50, 0x9B, 79, 00, 0, 0x9C, 81, 127, 50, 0x9C, 81, 00, 0, 0x9D, 83, 127, 50, 0x9D, 83, 00, 0, 0x9E, 84, 127, 50, 0x9E, 84, 00, 0, 0x9F, 86, 127, 50, 0x9F, 86, 00, 0, 0x00}; /*********************** PrintMidiOutErrorMsg() ************************** * Retrieves and displays an error message for the passed MIDI Out error * number. It does this using midiOutGetErrorText(). *************************************************************************/ void PrintMidiOutErrorMsg(unsigned long err) { #define BUFFERSIZE 120 char buffer[BUFFERSIZE]; if (!(err = midiOutGetErrorText(err, &buffer[0], BUFFERSIZE))) { printf("%s\r\n", &buffer[0]); } else if (err == MMSYSERR_BADERRNUM) { printf("Strange error number returned!\r\n"); } else { printf("Specified pointer is invalid!\r\n"); } } /* ******************************** main() ******************************** */ int main(int argc, char **argv) { HMIDIOUT handle; unsigned char * ptr; unsigned long err; union { DWORD dwData; UCHAR bData[4]; } u; printf("M.I.D.I. Output test\n"); printf("Les 16 notes seront jouee de do a re sur plus de 2 octaves,\n"); printf("une note par canal MIDI\n\n"); /* Open whichever MIDI Out device he has specified in Control Panel's "Multimedia"*/ if (!(err = midiOutOpen(&handle, (UINT)-1, 0, 0, CALLBACK_NULL))) { /* Get pointer to first event */ ptr = &Phrase[0]; /* Play the phrase. Note that we always assume at least one event, so I put the while test at the end of the loop */ do { /* Insert a delay here according the time byte. Factor in the tempo. */ if (*ptr) { // printf("%x %02d\n", u.bData[0], u.bData[1]); printf("%d %02d\n", ((UCHAR)*(ptr+1)-0x90)+1, (UCHAR)*(ptr+2)); Sleep(*ptr * PPQN_TEMPO_FACTOR); } ptr++; /* Construct the MIDI message */ u.bData[0] = (UCHAR)*(ptr)++; /* MIDI status byte */ u.bData[1] = (UCHAR)*(ptr)++; /* first MIDI data byte */ u.bData[2] = (UCHAR)*(ptr)++; /* second MIDI data byte */ u.bData[3] = 0; // if (!*ptr) printf("%x %02d\n", u.bData[0], u.bData[1]); /* Output the note event */ if ((err = midiOutShortMsg(handle, u.dwData))) { PrintMidiOutErrorMsg(err); } /* Another note? */ } while (*(ptr + 1)); /* Close the MIDI device */ midiOutClose(handle); } else { // printf("Error opening the default MIDI Out device!\r\n"); printf("Quelle galere pour ouvrir le MIDI Out device!\r\n"); PrintMidiOutErrorMsg(err); } printf("Tapez (pas trop fort) sur une touche pour continuer\n"); getch(); return(0); }