00001
00002
00003
00004
00005
00006
00007 #ifndef CSL_MIDIIO_H
00008 #define CSL_MIDIIO_H
00009
00010 #include "CSL_Types.h"
00011 #include "CGestalt.h"
00012
00013 #include "math.h"
00014 #include "portmidi.h"
00015 #include "porttime.h"
00016
00017
00018
00019 #define OUTPUT_BUFFER_SIZE 0
00020 #define DRIVER_INFO NULL
00021 #define TIME_PROC Pt_Time
00022 #define TIME_INFO NULL
00023 #define TIME_START Pt_Start(1, 0, 0)
00024 #define MIDI_THRU NULL
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 namespace csl {
00045
00047
00048 typedef enum {
00049 kNone = 0,
00050 kNoteOff = 8,
00051 kNoteOn = 9,
00052 kPolyTouch = 10,
00053 kControlChange = 11,
00054 kProgramChange = 12,
00055 kAftertouch = 13,
00056 kPitchWheel = 14,
00057 kSysEX = 15
00058 } CSL_MIDIMessageType;
00059
00061
00062 class CSL_MIDIMessage {
00063
00064 public:
00065 CSL_MIDIMessageType message;
00066 unsigned channel;
00067 unsigned data1;
00068 unsigned data2;
00069 long time;
00070
00071 CSL_MIDIMessage();
00072
00073 };
00074
00076
00077 void copy_CSL_MIDIMessage(CSL_MIDIMessage* source, CSL_MIDIMessage* dest );
00078
00080
00081 void CSL_MIDIMessageToPmEvent(CSL_MIDIMessage* cslMIDI, PmEvent* event );
00082
00084
00085 void PmEventToCSL_MIDIMessage( PmEvent* event, CSL_MIDIMessage* cslMIDI );
00086
00088
00089 unsigned Message_ChannelToStatus(CSL_MIDIMessageType message, unsigned channel );
00090
00094
00095 class MIDIIO {
00096 public:
00097 MIDIIO();
00098 virtual ~MIDIIO();
00099
00100 virtual void open() { };
00101 bool is_open();
00102 void close();
00103 void dump_device_info();
00104 void dump_count_devices();
00105
00107 int count_devices();
00108 int get_default_input_id();
00109 int get_default_output_id();
00110 const PmDeviceInfo* get_device_info(int deviceID );
00111
00112 protected:
00113 PmStream * mMIDIStream;
00114 PmDeviceID mDeviceID;
00115
00117 static bool mIsInitialized;
00118 static unsigned mNumInstantiated;
00119 static bool mIsPortTimeStarted;
00120
00122 bool mIsInput;
00123 bool mIsOutput;
00124 bool mIsOpen;
00125
00126 void handle_error(PmError err);
00127 };
00128
00132
00133 class MIDIIn : public MIDIIO {
00134 public:
00135 MIDIIn();
00136
00137 unsigned buffer_size();
00138 void set_buffer_size(unsigned bufferSize );
00139 void open();
00140 void open(int deviceID);
00141 bool poll();
00142 void read();
00143 void read_interpret();
00144
00145 PmEvent buffer() { return mBuffer[0]; }
00146 void dump_buffer();
00147
00148 CSL_MIDIMessage message() { return mMsg; }
00149 void dump_CSL_MIDIMessage();
00150
00151 bool is_NoteOn_received();
00152 bool is_NoteOff_received();
00153 bool is_PolyTouch_received();
00154 bool is_ControlChange_received();
00155 bool is_ProgramChange_received();
00156 bool is_Aftertouch_received();
00157 bool is_PitchWheel_received();
00158 bool is_SysEX_received();
00159
00160 unsigned get_note();
00161 unsigned get_velocity();
00162 unsigned get_PolyAftertouch();
00163 unsigned get_ControlChange_function();
00164 unsigned get_ControlChange_value();
00165 unsigned get_ProgramNumber();
00166 unsigned get_Aftertouch();
00167 unsigned get_PitchWheel();
00168 float get_frequency();
00169 float get_velocity_float();
00170
00171 void setFilter();
00172 void filter_active_sensing(bool flag );
00173 void filter_sysex(bool flag );
00174 void filter_clock_msg(bool flag );
00175
00176
00177 protected:
00179 long mBufferSize;
00180 long mFilterFlag;
00181
00182 CSL_MIDIMessage mMsg;
00183
00184 PmEvent mBuffer[1];
00185 PmError mLength;
00186
00187 };
00188
00192
00193 class MIDIOut : public MIDIIO {
00194 public:
00195 MIDIOut();
00196 ~MIDIOut();
00197
00198 unsigned buffer_size();
00199 void set_buffer_size(unsigned bufferSize );
00200 long latency();
00201 void set_latency(long latency );
00202
00203 void open();
00204 void open(int deviceID );
00205 void set_message(CSL_MIDIMessage msg, long when );
00206 void write();
00207 void write(CSL_MIDIMessage* msg, long length );
00208 void write_short(CSL_MIDIMessage msg );
00209 void write_SysEX(long when, unsigned char *msg );
00210
00213 void write_NoteOn(unsigned channel, unsigned pitch, unsigned velocity );
00214 void write_NoteOn(unsigned channel, float frequency, float amplitude );
00215 void write_NoteOff(unsigned channel, unsigned pitch, unsigned velocity );
00216 void write_NoteOff(unsigned channel, float frequency, float amplitude );
00217 void write_PolyTouch(unsigned channel, unsigned pitch, unsigned amount );
00218 void write_ControlChange(unsigned channel, unsigned function, unsigned value );
00219 void write_ProgramChange(unsigned channel, unsigned programNum );
00220 void write_Aftertouch(unsigned channel, unsigned amount );
00221 void write_PitchWheel(unsigned channel, unsigned amount );
00222
00223 protected:
00224 long mBufferSize;
00225 long mLatency;
00226
00227 CSL_MIDIMessage mMsg;
00228 };
00229
00230 }
00231
00232 #endif