HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_Midi.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Midi.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * This is a generic midi class to contain midi
11  * methods without creating link dependencies
12  */
13 
14 #ifndef __UT_Midi__
15 #define __UT_Midi__
16 
17 #include "UT_API.h"
18 #include <string.h>
19 
20 #include "UT_Endian.h"
21 #include "UT_Array.h"
22 #include "UT_ValArray.h"
23 #include "UT_IntArray.h"
24 
25 class UT_MidiFile;
26 
27 #ifdef WIN32
28  #define MIDI_IN_DEVICE_BASE 128
29  #define MIDI_OUT_DEVICE_BASE 256
30 #else
31  #define MIDI_IN_DEVICE_BASE 4096
32  #define MIDI_OUT_DEVICE_BASE 8192
33 #endif
34 #define MIDI_IN_FILE_BASE 12288
35 #define MIDI_OUT_FILE_BASE 16384
36 #define MIDI_NUM_DEVICES 4095
37 
38 /* timing modes */
39 #define MD_NOSTAMP 1
40 #define MD_DELTASTAMP 2
41 #define MD_RELATIVESTAMP 3
42 #define MD_DELTATICKS 4 /* delta ticks, as in SMF 1.0 */
43 #define MD_RELATIVETICKS 5 /* relative ticks */
44 
45 #define MD_STAMPING_MASK 0xf
46 
47 #define MD_CHANNELMASK 0x0F
48 #define MD_STATUSMASK 0xF0
49 
50 #define MD_CHANNELVOICE 0x80
51 #define MD_NOTEOFF 0x80
52 #define MD_NOTEON 0x90 /* note-off is also note-on w/velocity=0 */
53 #define MD_POLYKEYPRESSURE 0xA0 /* polyphonic key pressure or aftertouch */
54 #define MD_CONTROLCHANGE 0xB0
55 #define MD_CHANNELMODESELECT 0xB0
56 #define MD_PROGRAMCHANGE 0xC0
57 #define MD_CHANNELPRESSURE 0xD0 /* aftertouch is the Yamaha term */
58 #define MD_PITCHBENDCHANGE 0xE0
59 
60 #ifdef MD_SYSEX
61 #undef MD_SYSEX
62 #endif
63 #define MD_SYSEX 0xF0 /* System Exclusive */
64 #define MD_SYSTEMREALTIME 0xF8
65 #define MD_TIMINGCLOCK 0xF8
66 #define MD_UNDEFINED3 0xF9
67 #define MD_START 0xFA
68 #define MD_CONTINUE 0xFB
69 #define MD_STOP 0xFC
70 #define MD_UNDEFINED4 0xFD
71 #define MD_ACTIVESENSING 0xFE
72 #define MD_SYSTEMRESET 0xFF
73 #define MD_META 0xFF /* MIDI Files only */
74 #define MD_SYSTEMCOMMON 0xF1
75 #define MD_TIMECODEQUARTERFRAME 0xF1
76 #define MD_SONGPOSITIONPOINTER 0xF2
77 #define MD_SONGSELECT 0xF3
78 #define MD_UNDEFINED1 0xF4
79 #define MD_UNDEFINED2 0xF5
80 #define MD_TUNEREQUEST 0xF6
81 #define MD_EOX 0xF7 /* End of System Exclusive */
82 
83 #define MAX_SYSEXMSG_LEN 128
84 
85 #define SYSEX_TYPE_NONE (0)
86 #define SYSEX_TYPE_BARMARKER (1)
87 
88 #define MESSAGE_VALUE_RAW (-1)
89 #define MESSAGE_VALUE_NORM (-2)
90 #define MESSAGE_DONTCARE (-3)
91 #define MESSAGE_STOP (-4)
92 
93 
95 {
96 public:
97 
98  char msg[3];
100  char bar;
101  float barvalue;
102  int trackNum;
103  char sysexmsg[MAX_SYSEXMSG_LEN];
104  int sysexlen;
105 
106 
107  midiEvent() { sysexlen = 0; trackNum=-1; }
108  explicit midiEvent(const int) { sysexlen = 0; trackNum=-1; }
109 
110  midiEvent(const midiEvent &mdv)
111  {
112  msg[0] = mdv.msg[0];
113  msg[1] = mdv.msg[1];
114  msg[2] = mdv.msg[2];
115  time = mdv.time;
116  bar = mdv.bar;
117  barvalue = mdv.barvalue;
118  trackNum = -1;
119 
120  memcpy(sysexmsg, mdv.sysexmsg, mdv.sysexlen);
121  sysexlen = mdv.sysexlen;
122  }
123 
125  { };
126 
128  {
129  msg[0] = mdv.msg[0];
130  msg[1] = mdv.msg[1];
131  msg[2] = mdv.msg[2];
132 
133  time = mdv.time;
134  bar = mdv.bar;
135  barvalue = mdv.barvalue;
136  trackNum = mdv.trackNum;
137 
138  memcpy(sysexmsg, mdv.sysexmsg, mdv.sysexlen);
139  sysexlen = mdv.sysexlen;
140 
141  return *this;
142  }
143 
144  int operator==(const midiEvent &mdv)
145  {
146  if (msg[0] == mdv.msg[0] &&
147  msg[1] == mdv.msg[1] &&
148  msg[2] == mdv.msg[2] &&
149  time == mdv.time &&
150  sysexlen == mdv.sysexlen)
151  {
152  return 1;
153  }
154  else
155  {
156  return 0;
157  }
158  }
159 };
160 
162 {
163 
164 public:
165 
166  UT_Midi();
167  virtual ~UT_Midi();
168 
169  virtual int numInterfaces(int indevices);
170  virtual const char *interfaceName(int n, int indevices);
171 
172  virtual int openPort(const char *portname, int read);
173  virtual int openFile(const char *filename, int read,
175  virtual int openFile(const char *filename,
176  UT_Array<midiEvent> &events);
177 
178  // these five methods have both a file and a device version.
179  // the device versions are implemented in $MIDI/MIDI_Interface.
180  // the file versions are implemented in this file.
181  //
182  void closePort(int port);
183 
184  int hasMidiInput(int port, uint64 up_to_time,
185  UT_IntArray &channel);
186 
187  void getMidiInput(int port,
188  uint64 up_to_time,
189  UT_Array<midiEvent> &midi_input,
190  UT_IntArray &channel);
191 
192  int sendMidiOutput(int port,
193  UT_Array<midiEvent> &midi_output,
194  int channel);
195 
196  void clearQueue(int port);
197  ////
198 
199  uint64 getLastFileTime(int port);
200 
201  virtual uint64 getTime(int port);
202  virtual void setTimerCallback(void (*callback)(void *));
203 
204  virtual void startRecordTimer(void *, int time);
205  virtual void stopRecordTimer(void *);
206  void setPrintMessage(int);
207 
208  virtual uint64 markOffsetTime(int port);
209 
210  int identifySysex(const char *, int len, float *value=0);
211 
212  void printMessage(midiEvent *);
213  int printMessages() { return myPrintMessageFlag; }
214 
215  void setBarMarkerMessage(const int *a)
216  { myBarMarkerMessage = a; }
217 
218 protected:
219  // All Device methods are empty at this level. Implemented in
220  // MIDI_Interface.{C,h}
221  //
222  virtual int hasDeviceInput(int port,uint64 up_to_time,
223  UT_IntArray &channel);
224  int hasFileInput(int port,uint64 up_to_time,
225  UT_IntArray &channel);
226 
227  virtual void getDeviceInput(int port,
228  uint64 up_to_time,
229  UT_Array<midiEvent> &midi_input,
230  UT_IntArray &channel);
231  void getFileInput(int port,
232  uint64 up_to_time,
233  UT_Array<midiEvent> &midi_input,
234  UT_IntArray &channel);
235  virtual int sendDeviceOutput(int port,
236  UT_Array<midiEvent> &midi_output,
237  int channel);
238 
239  int sendFileOutput(int port,
240  UT_Array<midiEvent> &midi_output,
241  int channel);
242 
243  virtual void clearDeviceQueue(int port);
244  void clearFileQueue(int port);
245 
246  virtual void closeDevice(int port);
247  void closeFile(int port);
248 
250 
252 private:
253 
254  UT_ValArray<UT_MidiFile *> myInputFiles;
255  UT_ValArray<UT_MidiFile *> myOutputFiles;
256  const int *myBarMarkerMessage;
257  void printSysexMessage(int *array);
258 
259 
260 };
261 
262 UT_API extern UT_Midi *UTgetMidi(); // Get the app interrupt ptr
263 UT_API extern void UTsetMidi(UT_Midi *);
264 
265 
266 #endif
267 
midiEvent(const int)
Definition: UT_Midi.h:108
int operator==(const midiEvent &mdv)
Definition: UT_Midi.h:144
#define MAX_SYSEXMSG_LEN
Definition: UT_Midi.h:83
char sysexmsg[MAX_SYSEXMSG_LEN]
Definition: UT_Midi.h:103
GLuint start
Definition: glcorearb.h:474
char bar
Definition: UT_Midi.h:100
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
#define UT_API
Definition: UT_API.h:12
void read(T &in, bool &v)
Definition: ImfXdr.h:611
int sysexlen
Definition: UT_Midi.h:104
~midiEvent()
Definition: UT_Midi.h:124
int myPrintMessageFlag
Definition: UT_Midi.h:249
GLdouble n
Definition: glcorearb.h:2007
unsigned long long uint64
Definition: SYS_Types.h:101
UT_API UT_Midi * UTgetMidi()
midiEvent()
Definition: UT_Midi.h:107
GLuint GLuint end
Definition: glcorearb.h:474
uint64 time
Definition: UT_Midi.h:99
void setBarMarkerMessage(const int *a)
Definition: UT_Midi.h:215
float barvalue
Definition: UT_Midi.h:101
UT_API void UTsetMidi(UT_Midi *)
midiEvent(const midiEvent &mdv)
Definition: UT_Midi.h:110
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:263
uint64 myLastTime
Definition: UT_Midi.h:251
int trackNum
Definition: UT_Midi.h:102
int printMessages()
Definition: UT_Midi.h:213
char msg[3]
Definition: UT_Midi.h:98
midiEvent & operator=(const midiEvent &mdv)
Definition: UT_Midi.h:127