HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_MidiFile.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_MidiFile.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * This class reads a MIDI file. The events
11  * are stored until the object is destroyed.
12  */
13 #ifndef __UT_MidiFile__
14 #define __UT_MidiFile__
15 
16 #include "UT_API.h"
17 #include <stdio.h>
18 
19 #include "UT_Midi.h"
20 #include "UT_Endian.h"
21 #include "UT_ValArray.h"
22 #include "UT_IntArray.h"
23 #include "UT_Array.h"
24 
25 class UT_MidiFile;
26 
27 // event class (different from UT_Midi's midiEvent because of file
28 // meta-events)
29 //
31 {
32 public:
34  ~utMidiFileEvent();
35 
36  void read(FILE *,UT_MidiFile *from);
37  void write(FILE *,UT_MidiFile *from);
38 
39  int isARealEvent();
40  int isEnd();
41  int isTempoChange();
42 
43  int getChannel();
44  uint64 getTime();
45 
46  void toMidiEvent(midiEvent &, UT_Midi *);
47  void toMidiFileEvent(midiEvent &, UT_Midi *);
48  long getTempo();
49 
50  static long readVariableLength(FILE *);
51  static void writeVariableLength(FILE *,long);
52 
53  friend class UT_MidiFile;
54 private:
55  unsigned char myStatus;
56  unsigned char myByte1;
57  unsigned char myByte2;
58  int myTempo;
59 
60  // system exclusives
61  long myMaxSysLength;
62  long mySysLength;
63  unsigned char *mySys;
64  int myBarPending;
65  float myBarValue;
66 
67  uint64 myTime;
68 };
69 
70 
72 {
73 public:
74  UT_MidiFile(UT_Midi *myMidi);
75  ~UT_MidiFile();
76 
77  void rewind();
78  uint64 getLastTime();
79 
80  int open(const char *name,int read,fpreal st=0,fpreal end=0);
81  int openWrite(const char *, UT_Array<midiEvent> &events);
82 
83  int hasMidiInput(uint64 up_to_time,
84  UT_IntArray &channel);
85 
86  void getMidiInput(uint64 up_to_time,
87  UT_Array<midiEvent> &midi_input,
88  UT_IntArray &channel);
89 
90  int sendMidiOutput(UT_Array<midiEvent> &midi_output,
91  int channel);
92 
93  void clearQueue();
94 
95  // called by utMidiEvent-----
96  uint64 currentTime();
97  void setCurrentTime(uint64);
98  unsigned char lastCommand();
99  void setLastCommand(unsigned char);
100  uint64 convertFromDeltaTicks(unsigned long delta);
101  long convertToDeltaTicks(uint64 ticks);
102  // -----
103 
104 private:
105  int openRead(const char *,fpreal start,fpreal end);
106 
107  int readHeader(FILE *);
108  void readTrack(FILE *,int tindex,fpreal start,fpreal end);
109  void sequenceEvents();
110 
111  void writeHeader(FILE *);
112  void writeTrack(FILE *, UT_Array<midiEvent> &events);
113 
114  unsigned short myFormat;
115  unsigned long myTicksPerSec;
116  int myResolution;
117  uint64 myCurrentTime;
118  long myLastEvent;
119  unsigned char myLastCommand;
120  fpreal64 myCumulativeError;
121  UT_Midi *myMidi;
122 
125 };
126 
127 #endif
GLuint start
Definition: glcorearb.h:474
#define UT_API
Definition: UT_API.h:13
void read(T &in, bool &v)
Definition: ImfXdr.h:611
unsigned long long uint64
Definition: SYS_Types.h:108
double fpreal64
Definition: SYS_Types.h:192
GLuint GLuint end
Definition: glcorearb.h:474
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual int open(float queuesize)
double fpreal
Definition: SYS_Types.h:270
void write(T &out, bool v)
Definition: ImfXdr.h:332