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

  1. /*
  2.  
  3.     MIDI.H  -- Midi function interface
  4.  
  5. */
  6.  
  7. #ifndef MIDI_H
  8.  
  9. #define MIDI_H
  10.  
  11. #ifndef STD_H
  12. #include "std.h"
  13. #endif
  14.  
  15. #ifndef MPU_H
  16. #include "mpu.h"
  17. #endif
  18.  
  19. #ifdef JUNK
  20.  
  21. // The following defines allow scheduled SYSEX messages to be reclaimed.
  22. // The problem is that the SYSEX data block can't be freed from an 
  23. // interrupt service routine. Once the block is sent, the 
  24. // sysex data block is placed in a temporary free chain which is then 
  25. // freed properly by ReclaimSysexMemory().
  26.  
  27. // Since SYSEX messages can't currently be scheduled, this code is 
  28. // disabled (for now).
  29.  
  30. // Warning: Nasty hack follows....
  31. // ANSI C specifically allows (encourages?) this kind of nastiness,
  32. // although it has a reputation for being rather difficult to implement
  33. // properly.
  34.  
  35. // See the PDOC's for ReclaimSysexMemory which explains what this
  36. // nasty little peice of goods is doing.
  37.  
  38. #define calloc(x,y) (ReclaimSysexMemory(),calloc(x,y))
  39. #define malloc(x)    (ReclaimSysexMemory(),malloc(x))
  40. #endif
  41.  
  42. // Midi error codes
  43. #define LOWEST_MIDI_ERROR 0x100
  44.  
  45. typedef enum MidiErrorT {
  46.     MIDI_ENOMEM = LOWEST_MIDI_ERROR, // Insufficient memory.
  47. } MidiErrorT;
  48.  
  49. #ifdef MIDI_PRIVATES  // Accessable through MidiErrorString
  50. PRIVATE char * MidiErrorStrings[] = {
  51.     "Insufficient memory"
  52. };
  53. #endif
  54.  
  55. // Message IDs
  56. #define NOTE_ON_MSG 0x90
  57. #define NOTE_OFF_MSG 0x80
  58. #define CONTROL_MSG 0xB0
  59. #define PROGRAM_MSG 0xC0
  60. #define AFTERTOUCH_MSG 0xD0
  61. #define BENDER_MSG 0xE0
  62. #define COMMON_MSG 0xF0
  63. #define SONG_POSITION_MSG 0xF2
  64. #define SONG_SELECT_MSG 0xF3
  65. #define EOX_MSG 0xF7
  66. #define TIMING_CLOCK_MSG 0xF8
  67. #define START_MSG 0xFA
  68. #define CONTINUE_MSG 0xFB
  69. #define STOP_MSG 0xFC
  70. #define ACTIVE_SENSE_MSG 0xFE
  71. #define SYSEX_MSG 0xF0
  72.  
  73. typedef long MidiTimeT;
  74.  
  75. // Midi Message Structure
  76. typedef struct MidiMessageT {
  77.     struct MidiMessageT *next;
  78.     MidiTimeT time;
  79.     BYTE midiCommand;
  80.     BYTE midiData[2];
  81.     unsigned int sysexLength;
  82.     BYTE *sysexData;
  83. } MidiMessageT;
  84.  
  85. // Midi channel control block
  86.  
  87. typedef struct MidiChannelT {
  88.     MpuPortT *mpu_port;    /* Warning: MpuPort must be first elelement of MidiChannelT -rd */
  89.     MidiErrorT errno;
  90.     int midiMessagesPending; /* Number of scheduled midi messages pending */
  91.     MidiMessageT *sendQ[MAX_MPU_TRACK];
  92.     MidiMessageT *sendQTail[MAX_MPU_TRACK];
  93.     MidiTimeT qTime[MAX_MPU_TRACK];
  94.     
  95. } MidiChannelT;
  96.  
  97.  
  98. // Function prototypes.
  99.  
  100. void ReclaimSysexMemory(void);
  101. MidiMessageT *AllocMidiMessage(void);
  102. MidiMessageT *ReceiveMidiMessage(MidiChannelT *channel);
  103.  
  104. void ScheduleMidiMessage(
  105.     MidiChannelT *channel,
  106.     int track,
  107.     MidiTimeT time,
  108.     MidiMessageT *msg
  109. );
  110.  
  111. BOOL SendMidiMessage(MidiChannelT *channel,MidiMessageT *msg);
  112.  
  113. BOOL SetMidiMessage(
  114.     MidiMessageT *msg,
  115.     UCHAR midi_command, 
  116.     UCHAR data1, 
  117.     UCHAR data2,
  118.     unsigned int sysex_length,    // Must be zero for non-SYSEX commands!
  119.     UCHAR *sysex_data            // May be NULL
  120. );
  121.  
  122. void GetMidiMessageData(
  123.     MidiMessageT *msg,
  124.     UCHAR *midi_cmd, // Receives midi command
  125.     UCHAR *data1,     // Receives data1 (if not NULL)
  126.     UCHAR *data2     // Receives data2 (if not NULL)
  127. );
  128.  
  129. void GetMidiMessageSysexData(
  130.     MidiMessageT *msg,
  131.     int *sysexLength,
  132.     UCHAR **sysexData    // Filled if not null
  133. );
  134.  
  135. MidiTimeT GetMidiMessageReceiveTime(
  136.     MidiMessageT *msg
  137. );
  138.     
  139.  
  140. MidiChannelT *CreateMidiChannel(
  141.     int mpu_base_address, // Mpu base address (default 0x330)
  142.     int mpu_interrupt,      // Mpu interrupt number (default 2)
  143.     int rx_buffersize,      // Size of receive buffer (default 1024)
  144.     enum MpuOperatingModeT operating_mode, // RECORD_MODE,PLAY_MODE,RECORDPLAY_MODE,STOP_MODE
  145.     enum MpuClockT mpu_clock_source, // MPU_INTERNAL_CLOCK, MPU_MIDI_CLOCK
  146.                                      // or MPU_FSK_CLOCK
  147.     int tempo,              // Beats per minute
  148.     enum MpuTimebaseT timebase,     // Ticks per beat (see MpuTimebaseT in MPU.H)
  149.     int metronome_measure_length, // beats per measure, 0 -> metronome off
  150.     int mode,              // See description 
  151.     int midi_channel_mask, // bit n controls midi channel n+1
  152.                            // bit = 0 -> pass trough without host intervention
  153.                            // bit = 1 -> record/filter this midi channel    
  154.     int tracks,               // number of tracks (0 to 7) for scheduled midi messages
  155.     int *result               // retcode placed here
  156. );
  157.  
  158. void SetMidiOperatingMode(
  159.     MidiChannelT *channel,
  160.     MpuOperatingModeT operating_mode
  161. );
  162.  
  163. int DestroyMidiChannel(MidiChannelT *channel);
  164.  
  165. int MidiStatus(MidiChannelT *channel);
  166.  
  167. char *MidiErrorString(int error_code);
  168. int MidiMessagesPending(MidiChannelT *channel);
  169. void FreeMidiMessage(MidiMessageT *msg);
  170.  
  171.  
  172. #endif //def MIDI_H
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.