00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __UT_MidiFile__
00022 #define __UT_MidiFile__
00023
00024 #include "UT_API.h"
00025 #include <stdio.h>
00026
00027 #include "UT_Midi.h"
00028 #include "UT_Endian.h"
00029 #include "UT_PtrArray.h"
00030 #include "UT_IntArray.h"
00031 #include "UT_RefArray.h"
00032
00033 class UT_MidiFile;
00034
00035
00036
00037
00038 class UT_API utMidiFileEvent
00039 {
00040 public:
00041 utMidiFileEvent();
00042 ~utMidiFileEvent();
00043
00044 void read(FILE *,UT_MidiFile *from);
00045 void write(FILE *,UT_MidiFile *from);
00046
00047 int isARealEvent();
00048 int isEnd();
00049 int isTempoChange();
00050
00051 int getChannel();
00052 uint64 getTime();
00053
00054 void toMidiEvent(midiEvent &, UT_Midi *);
00055 void toMidiFileEvent(midiEvent &, UT_Midi *);
00056 long getTempo();
00057
00058 static long readVariableLength(FILE *);
00059 static void writeVariableLength(FILE *,long);
00060
00061 friend class UT_MidiFile;
00062 private:
00063 unsigned char myStatus;
00064 unsigned char myByte1;
00065 unsigned char myByte2;
00066 int myTempo;
00067
00068
00069 long myMaxSysLength;
00070 long mySysLength;
00071 unsigned char *mySys;
00072 int myBarPending;
00073 float myBarValue;
00074
00075 uint64 myTime;
00076 };
00077
00078
00079 class UT_API UT_MidiFile
00080 {
00081 public:
00082 UT_MidiFile(UT_Midi *myMidi);
00083 ~UT_MidiFile();
00084
00085 void rewind();
00086 uint64 getLastTime();
00087
00088 int open(const char *name,int read,fpreal st=0,fpreal end=0);
00089 int openWrite(const char *, UT_RefArray<midiEvent> &events);
00090
00091 int hasMidiInput(uint64 up_to_time,
00092 UT_IntArray &channel);
00093
00094 void getMidiInput(uint64 up_to_time,
00095 UT_RefArray<midiEvent> &midi_input,
00096 UT_IntArray &channel);
00097
00098 int sendMidiOutput(UT_RefArray<midiEvent> &midi_output,
00099 int channel);
00100
00101 void clearQueue();
00102
00103
00104 uint64 currentTime();
00105 void setCurrentTime(uint64);
00106 unsigned char lastCommand();
00107 void setLastCommand(unsigned char);
00108 uint64 convertFromDeltaTicks(unsigned long delta);
00109 long convertToDeltaTicks(uint64 ticks);
00110
00111
00112 private:
00113 int openRead(const char *,fpreal start,fpreal end);
00114
00115 int readHeader(FILE *);
00116 void readTrack(FILE *,int tindex,fpreal start,fpreal end);
00117 void sequenceEvents();
00118
00119 void writeHeader(FILE *);
00120 void writeTrack(FILE *, UT_RefArray<midiEvent> &events);
00121
00122 unsigned short myFormat;
00123 unsigned char myValidFlag;
00124 unsigned long myTicksPerSec;
00125 int myResolution;
00126 uint64 myCurrentTime;
00127 long myLastEvent;
00128 unsigned char myLastCommand;
00129 fpreal64 myCumulativeError;
00130 UT_Midi *myMidi;
00131
00132 UT_PtrArray<utMidiFileEvent*> myEvents;
00133 UT_PtrArray< UT_PtrArray<utMidiFileEvent *> *> myTrackEvents;
00134 };
00135
00136 #endif