HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  UT_Midi(const UT_Midi &) = delete;
170  UT_Midi &operator=(const UT_Midi &) = delete;
171 
172  virtual int numInterfaces(int indevices);
173  virtual const char *interfaceName(int n, int indevices);
174 
175  virtual int openPort(const char *portname, int read);
176  virtual int openFile(const char *filename, int read,
178  virtual int openFile(const char *filename,
179  UT_Array<midiEvent> &events);
180 
181  // these five methods have both a file and a device version.
182  // the device versions are implemented in $MIDI/MIDI_Interface.
183  // the file versions are implemented in this file.
184  //
185  void closePort(int port);
186 
187  int hasMidiInput(int port, uint64 up_to_time,
188  UT_IntArray &channel);
189 
190  void getMidiInput(int port,
191  uint64 up_to_time,
192  UT_Array<midiEvent> &midi_input,
193  UT_IntArray &channel);
194 
195  int sendMidiOutput(int port,
196  UT_Array<midiEvent> &midi_output,
197  int channel);
198 
199  void clearQueue(int port);
200  ////
201 
202  uint64 getLastFileTime(int port);
203 
204  virtual uint64 getTime(int port);
205  virtual void setTimerCallback(void (*callback)(void *));
206 
207  virtual void startRecordTimer(void *, int time);
208  virtual void stopRecordTimer(void *);
209  void setPrintMessage(int);
210 
211  virtual uint64 markOffsetTime(int port);
212 
213  int identifySysex(const char *, int len, float *value=0);
214 
215  void printMessage(midiEvent *);
216  int printMessages() { return myPrintMessageFlag; }
217 
218  void setBarMarkerMessage(const int *a)
219  { myBarMarkerMessage = a; }
220 
221 protected:
222  // All Device methods are empty at this level. Implemented in
223  // MIDI_Interface.{C,h}
224  //
225  virtual int hasDeviceInput(int port,uint64 up_to_time,
226  UT_IntArray &channel);
227  int hasFileInput(int port,uint64 up_to_time,
228  UT_IntArray &channel);
229 
230  virtual void getDeviceInput(int port,
231  uint64 up_to_time,
232  UT_Array<midiEvent> &midi_input,
233  UT_IntArray &channel);
234  void getFileInput(int port,
235  uint64 up_to_time,
236  UT_Array<midiEvent> &midi_input,
237  UT_IntArray &channel);
238  virtual int sendDeviceOutput(int port,
239  UT_Array<midiEvent> &midi_output,
240  int channel);
241 
242  int sendFileOutput(int port,
243  UT_Array<midiEvent> &midi_output,
244  int channel);
245 
246  virtual void clearDeviceQueue(int port);
247  void clearFileQueue(int port);
248 
249  virtual void closeDevice(int port);
250  void closeFile(int port);
251 
253 
255 private:
256 
257  UT_ValArray<UT_MidiFile *> myInputFiles;
258  UT_ValArray<UT_MidiFile *> myOutputFiles;
259  const int *myBarMarkerMessage;
260  void printSysexMessage(int *array);
261 
262 
263 };
264 
265 UT_API extern UT_Midi *UTgetMidi(); // Get the app interrupt ptr
266 UT_API extern void UTsetMidi(UT_Midi *);
267 
268 
269 #endif
270 
midiEvent(const int)
Definition: UT_Midi.h:108
int operator==(const midiEvent &mdv)
Definition: UT_Midi.h:144
GT_API const UT_StringHolder filename
#define MAX_SYSEXMSG_LEN
Definition: UT_Midi.h:83
char sysexmsg[MAX_SYSEXMSG_LEN]
Definition: UT_Midi.h:103
GT_API const UT_StringHolder time
GLuint start
Definition: glcorearb.h:475
char bar
Definition: UT_Midi.h:100
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define UT_API
Definition: UT_API.h:14
unsigned long long uint64
Definition: SYS_Types.h:117
int sysexlen
Definition: UT_Midi.h:104
~midiEvent()
Definition: UT_Midi.h:124
int myPrintMessageFlag
Definition: UT_Midi.h:252
GLdouble n
Definition: glcorearb.h:2008
UT_API UT_Midi * UTgetMidi()
midiEvent()
Definition: UT_Midi.h:107
GLuint GLuint end
Definition: glcorearb.h:475
uint64 time
Definition: UT_Midi.h:99
void setBarMarkerMessage(const int *a)
Definition: UT_Midi.h:218
float barvalue
Definition: UT_Midi.h:101
UT_API void UTsetMidi(UT_Midi *)
midiEvent(const midiEvent &mdv)
Definition: UT_Midi.h:110
uint64 myLastTime
Definition: UT_Midi.h:254
fpreal64 fpreal
Definition: SYS_Types.h:277
LeafData & operator=(const LeafData &)=delete
int trackNum
Definition: UT_Midi.h:102
Definition: core.h:1131
int printMessages()
Definition: UT_Midi.h:216
char msg[3]
Definition: UT_Midi.h:98
that also have some descendant prim *whose name begins with bar
midiEvent & operator=(const midiEvent &mdv)
Definition: UT_Midi.h:127