home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / msdos / midi / mpusr2 / delaytst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-24  |  1.5 KB  |  78 lines

  1. /*
  2.  
  3.     TEST MIDI.C Midi Read and Write 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 "DELAYTST"
  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. #pragma argsused
  26. int main(int argc, char**argv) {
  27.     int i;
  28.     long t;
  29.     int result;
  30.     MidiChannelT *channel;
  31.     MidiMessageT *msg;
  32.  
  33.     directvideo = 1;
  34.     fprintf(stderr,"DELAYTST v1.0 - Echo incoming events with delay\n"
  35.                         "by Larry Troxler" CR
  36.                         CR
  37.     );
  38.     channel = CreateMidiChannel(
  39.                 0,         // base_address
  40.                 0,        // int #
  41.                 8192,  // buffer size
  42.                 RECORDPLAY_MODE,   // Operating mode
  43.                 MPU_INTERNAL_CLOCK, // internal clock
  44.                 120,            // Beats per minute
  45.                 MPU_TIMEBASE_192, // Timebase
  46.                 0,                 // Metronome beats per measure
  47.                 MPU_RX_ALL | MPU_DEFAULT_THRU, // rx/thru messages
  48.                 -1,            // midi_channel_mask (rx all midi channels)
  49.                 1,            // Playback tracks
  50.                 &result
  51.             );
  52.  
  53.     if (channel == NULL) {
  54.         midiError(result);
  55.     }
  56.  
  57.     while (YES) {
  58.         msg = ReceiveMidiMessage(channel);
  59.         if ((result = MidiStatus(channel)) != 0) {
  60.             midiError(result);
  61.         }
  62.         if (msg != NULL  && msg != ((MidiMessageT*)(-1))) {
  63.             ScheduleMidiMessage(
  64.               channel,
  65.               0,
  66.               GetMidiMessageReceiveTime(msg) + 1024,
  67.               msg
  68.             );
  69.         } else {
  70.             if (kbhit())
  71.                 break;
  72.         }
  73.     }
  74.     DestroyMidiChannel(channel);
  75.     getch();
  76.     return 0;
  77. }
  78.