00001 00002 00003 #ifndef MIDI_H 00004 #define MIDI_H 00005 00006 #include "IS3DCommon.H" 00007 00008 #ifdef WIN32 00009 #include <windows.h> 00010 #include <mmsystem.h> 00011 #endif 00012 00013 namespace IS3D { 00014 00015 00016 #define MIDI_IN_BUFFER_SIZE 1024 00017 00018 class MidiInDevice 00019 { 00020 public: 00021 static MidiInDevice* fromMidiDeviceName(const char *name); 00022 static MidiInDevice* fromMidiDeviceNumber(int number); 00023 static int getNumAvailableDevices(); 00024 static void getAvailableDeviceName(int number, char *name); 00025 00026 MidiInDevice(int number); 00027 virtual ~MidiInDevice(); 00028 00038 bool readMessage(unsigned char **msgPtr, int *size); 00039 00042 bool hasMessageWaiting(); 00043 00045 void setMessage(unsigned char *msg, int size); 00046 00048 void poll(); 00049 00050 private: 00051 00052 #ifdef WIN32 00053 HMIDIIN _handle; 00054 MIDIHDR _header; 00055 #else 00056 // a file descriptor 00057 int _handle; 00058 int _sysExMsgSize; 00059 #endif 00060 00061 // buffer filled up by the midi callback in windows and the poll 00062 // routine in linux 00063 unsigned char _sysExBuffer[MIDI_IN_BUFFER_SIZE]; 00064 00065 // buffer filled up by this class with data extracted from the 00066 // bytes received from the device 00067 unsigned char _msg[MIDI_IN_BUFFER_SIZE]; 00068 int _msgSize; 00069 bool _newMsgFlag; 00070 }; 00071 00072 00073 00074 00075 class MidiOutDevice 00076 { 00077 public: 00078 static MidiOutDevice* fromMidiDeviceName(const char *name); 00079 static MidiOutDevice* fromMidiDeviceNumber(int number); 00080 static int getNumAvailableDevices(); 00081 static void getAvailableDeviceName(int number, char *name); 00082 00083 MidiOutDevice(int number); 00084 virtual ~MidiOutDevice(); 00085 00086 void sendMessage(unsigned char* message, int size); 00087 00088 private: 00089 00090 #ifdef WIN32 00091 HMIDIOUT _handle; 00092 #else 00093 int _handle; 00094 #endif 00095 }; 00096 00097 } // end namespace 00098 00099 #endif 00100 00101