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  utMidiFileEvent(const utMidiFileEvent &) = delete;
37  utMidiFileEvent &operator=(const utMidiFileEvent &) = delete;
38 
39  void read(FILE *,UT_MidiFile *from);
40  void write(FILE *,UT_MidiFile *from);
41 
42  int isARealEvent();
43  int isEnd();
44  int isTempoChange();
45 
46  int getChannel();
47  uint64 getTime();
48 
49  void toMidiEvent(midiEvent &, UT_Midi *);
50  void toMidiFileEvent(midiEvent &, UT_Midi *);
51  long getTempo();
52 
53  static long readVariableLength(FILE *);
54  static void writeVariableLength(FILE *,long);
55 
56  friend class UT_MidiFile;
57 private:
58  unsigned char myStatus;
59  unsigned char myByte1;
60  unsigned char myByte2;
61  int myTempo;
62 
63  // system exclusives
64  long myMaxSysLength;
65  long mySysLength;
66  unsigned char *mySys;
67  int myBarPending;
68  float myBarValue;
69 
70  uint64 myTime;
71 };
72 
73 
75 {
76 public:
77  UT_MidiFile(UT_Midi *myMidi);
78  ~UT_MidiFile();
79 
80  UT_MidiFile(const UT_MidiFile &) = delete;
81  UT_MidiFile &operator=(const UT_MidiFile &) = delete;
82 
83  void rewind();
84  uint64 getLastTime();
85 
86  int open(const char *name,int read,fpreal st=0,fpreal end=0);
87  int openWrite(const char *, UT_Array<midiEvent> &events);
88 
89  int hasMidiInput(uint64 up_to_time,
90  UT_IntArray &channel);
91 
92  void getMidiInput(uint64 up_to_time,
93  UT_Array<midiEvent> &midi_input,
94  UT_IntArray &channel);
95 
96  int sendMidiOutput(UT_Array<midiEvent> &midi_output,
97  int channel);
98 
99  void clearQueue();
100 
101  // called by utMidiEvent-----
102  uint64 currentTime();
103  void setCurrentTime(uint64);
104  unsigned char lastCommand();
105  void setLastCommand(unsigned char);
106  uint64 convertFromDeltaTicks(unsigned long delta);
107  long convertToDeltaTicks(uint64 ticks);
108  // -----
109 
110 private:
111  int openRead(const char *,fpreal start,fpreal end);
112 
113  int readHeader(FILE *);
114  void readTrack(FILE *,int tindex,fpreal start,fpreal end);
115  void sequenceEvents();
116 
117  void writeHeader(FILE *);
118  void writeTrack(FILE *, UT_Array<midiEvent> &events);
119 
120  unsigned short myFormat;
121  unsigned long myTicksPerSec;
122  int myResolution;
123  uint64 myCurrentTime;
124  long myLastEvent;
125  unsigned char myLastCommand;
126  fpreal64 myCumulativeError;
127  UT_Midi *myMidi;
128 
131 };
132 
133 #endif
GLuint start
Definition: glcorearb.h:475
#define UT_API
Definition: UT_API.h:14
unsigned long long uint64
Definition: SYS_Types.h:117
double fpreal64
Definition: SYS_Types.h:201
int open(float queuesize) override
GLuint GLuint end
Definition: glcorearb.h:475
GLuint const GLchar * name
Definition: glcorearb.h:786
GT_API const UT_StringHolder st
fpreal64 fpreal
Definition: SYS_Types.h:277
LeafData & operator=(const LeafData &)=delete