00001
00002
00003 #ifndef MIDI_H
00004 #define MIDI_H
00005
00006 #include <G3D/G3DAll.h>
00007 #include <iostream>
00008 using namespace std;
00009
00010 #ifdef WIN32
00011 #include <windows.h>
00012 #include <mmsystem.h>
00013 #endif
00014
00015 namespace VRG3D {
00016
00017 #define MIDI_IN_BUFFER_SIZE 1024
00018 #define MIDI_IN_DATA_BUFFER_SIZE 256
00019
00020 class MidiInDevice
00021 {
00022 public:
00023 static MidiInDevice* fromMidiDeviceName(const char *name);
00024 static MidiInDevice* fromMidiDeviceNumber(int number);
00025 static int getNumAvailableDevices();
00026 static void getAvailableDeviceName(int number, char *name);
00027
00028 MidiInDevice(int number);
00029 virtual ~MidiInDevice();
00030
00031
00034 bool hasMessageWaiting();
00035
00045 bool readMessage(unsigned char **msgPtr, int *size);
00046
00047
00049 bool hasDataWaiting();
00050
00052 int readData(unsigned char* &statusBytes, unsigned char* &data1Bytes, unsigned char* &data2Bytes);
00053
00054
00055
00057 void poll();
00058
00060 void setMessage(unsigned char *msg, int size);
00061 void addData(unsigned char status, unsigned char data1, unsigned char data2);
00062
00063 void shutdown();
00064
00065 #ifdef WIN32
00066 bool continueCallback;
00067 #endif
00068
00069 private:
00070
00071 #ifdef WIN32
00072 HMIDIIN _handle;
00073 MIDIHDR _header;
00074 #else
00075
00076 int _handle;
00077 int _sysExMsgSize;
00078 #endif
00079
00080
00081
00082 unsigned char _sysExBuffer[MIDI_IN_BUFFER_SIZE];
00083
00084
00085
00086 unsigned char _msg[MIDI_IN_BUFFER_SIZE];
00087 int _msgSize;
00088 bool _newMsgFlag;
00089
00090 unsigned char _dataStatus[MIDI_IN_DATA_BUFFER_SIZE];
00091 unsigned char _data1[MIDI_IN_DATA_BUFFER_SIZE];
00092 unsigned char _data2[MIDI_IN_DATA_BUFFER_SIZE];
00093 int _dataSize;
00094 bool _newDataFlag;
00095 };
00096
00097
00098
00099
00100 class MidiOutDevice
00101 {
00102 public:
00103 static MidiOutDevice* fromMidiDeviceName(const char *name);
00104 static MidiOutDevice* fromMidiDeviceNumber(int number);
00105 static int getNumAvailableDevices();
00106 static void getAvailableDeviceName(int number, char *name);
00107
00108 MidiOutDevice(int number);
00109 virtual ~MidiOutDevice();
00110
00111 void sendMessage(unsigned char* message, int size);
00112
00113 private:
00114
00115 #ifdef WIN32
00116 HMIDIOUT _handle;
00117 #else
00118 int _handle;
00119 #endif
00120 };
00121
00122 }
00123
00124 #endif
00125
00126