home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / msdos / midi / mpusr2 / readtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-26  |  1.6 KB  |  79 lines

  1. /*
  2.  
  3.     TEST MIDI.C Midi Read functionality.
  4.  
  5.  
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "std.h"
  11. #include "midi.h"
  12. #include <conio.h>
  13.  
  14.  
  15. #define PROGNAME "READTEST"
  16.  
  17. #define printf cprintf
  18. #define CR "\r\n"
  19.  
  20. void midiError(int midi_error_code) {
  21.     printf(PROGNAME ": %s\n",MidiErrorString(midi_error_code));
  22.     exit(9);
  23. }
  24.  
  25. void PrintMidiMessage(MidiMessageT *msg) {
  26.     UCHAR midi_msg[3];
  27.  
  28.     GetMidiMessageData(msg,&midi_msg[0],&midi_msg[1],&midi_msg[2]);
  29.     printf("%s" CR,MidiName(midi_msg));
  30. }
  31. #pragma argsused
  32. int main(int argc, char**argv) {
  33.     int result;
  34.     MidiChannelT *channel;
  35.     MidiMessageT *msg;
  36.  
  37.     directvideo = 1;
  38.     fprintf(stderr,"MIDIDBG v1.1 - Trace all MIDI commands on the screen" CR
  39.                        "Copyright (c) 1990, Robin Davies" CR
  40.                        CR
  41.     );
  42.     channel = CreateMidiChannel(
  43.                 0,         // base_address
  44.                 0,        // int #
  45.                 32760,  // buffer size
  46.                 STOP_MODE,   // Operating mode
  47.                 MPU_INTERNAL_CLOCK, // internal clock
  48.                 60,            // Beats per minute
  49.                 MPU_TIMEBASE_192, // Timebase
  50.                 0,                 // Metronome beats per measure
  51.                 MPU_RX_ALL | MPU_DEFAULT_THRU, // rx/thru messages
  52.                 -1,            // midi_channel_mask (rx all midi channels)
  53.                 1,            // Record tracks
  54.                 &result
  55.             );
  56.  
  57.     if (channel == NULL) {
  58.         midiError(result);
  59.     }
  60.  
  61.     SetMidiOperatingMode(channel,RECORD_MODE);
  62.     while (YES) {
  63.         msg = ReceiveMidiMessage(channel);
  64.         if ((result = MidiStatus(channel)) != 0) {
  65.             midiError(result);
  66.         }
  67.         if (msg != NULL) {
  68.             PrintMidiMessage(msg);
  69.             FreeMidiMessage(msg);
  70.         } else {
  71.             if (kbhit())
  72.                 break;
  73.         }
  74.     }
  75.     DestroyMidiChannel(channel);
  76.     getch();
  77.     return 0;
  78. }
  79.