home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / msdos / midi / mpusr2 / writetst.c < prev   
Encoding:
C/C++ Source or Header  |  1991-01-03  |  1.7 KB  |  83 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 "WRITETST"
  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 SendRandomNote(MidiChannelT *channel) {
  26.     MidiMessageT *msg;
  27.     static int send_time = 0;
  28.  
  29.     msg = AllocMidiMessage();
  30.     SetMidiMessage(msg,NOTE_ON_MSG,36+random(36),64,0,NULL);
  31. //    SendMidiMessage(channel,msg);
  32.     ScheduleMidiMessage(channel,0,send_time,msg);
  33.     send_time += random(64);
  34.  
  35. //    delay(random(1000));
  36. }
  37. #pragma argsused
  38. int main(int argc, char**argv) {
  39.     int result;
  40.     MidiChannelT *channel;
  41.     MidiMessageT *msg;
  42.  
  43.     directvideo = 1;
  44.     fprintf(stderr,"WRITETST v1.0 - Write random MIDI note events\n"
  45.                        "Copyright (c) 1990, Robin Davies" CR
  46.                        CR
  47.     );
  48.     channel = CreateMidiChannel(
  49.                 0,         // base_address
  50.                 0,        // int #
  51.                 32760,  // buffer size
  52.                 PLAY_MODE,   // Operating mode
  53.                 MPU_INTERNAL_CLOCK, // internal clock
  54.                 60,            // Beats per minute
  55.                 MPU_TIMEBASE_192, // Timebase
  56.                 0,                 // Metronome beats per measure
  57.                 MPU_RX_ALL | MPU_DEFAULT_THRU, // rx/thru messages
  58.                 -1,            // midi_channel_mask (rx all midi channels)
  59.                 1,            // Playback tracks
  60.                 &result
  61.             );
  62.  
  63.     if (channel == NULL) {
  64.         midiError(result);
  65.     }
  66.  
  67.     while (!kbhit()) {
  68.         if (MidiMessagesPending(channel) < 10) {
  69.             SendRandomNote(channel);
  70.             if ((result = MidiStatus(channel)) != 0) {
  71.                 midiError(result);
  72.             }
  73.         } else {
  74.             if (kbhit())
  75.                 break;
  76.         }
  77.  
  78.     }
  79.     DestroyMidiChannel(channel);
  80.     getch();
  81.     return 0;
  82. }
  83.