1 #ifndef _MIDI_STORE_H 2 #define _MIDI_STORE_H 3 4 #ifndef _BE_BUILD_H 5 #include <BeBuild.h> 6 #endif 7 #include <Midi.h> 8 9 struct entry_ref; 10 11 class BMidiEvent; 12 class BFile; 13 14 /*------------------------------------------------------------*/ 15 16 class BMidiStore : public BMidi { 17 public: 18 BMidiStore(); 19 virtual ~BMidiStore(); 20 21 virtual void NoteOff(uchar channel, 22 uchar note, 23 uchar velocity, 24 uint32 time = B_NOW); 25 26 virtual void NoteOn(uchar channel, 27 uchar note, 28 uchar velocity, 29 uint32 time = B_NOW); 30 31 virtual void KeyPressure(uchar channel, 32 uchar note, 33 uchar pressure, 34 uint32 time = B_NOW); 35 36 virtual void ControlChange(uchar channel, 37 uchar controlNumber, 38 uchar controlValue, 39 uint32 time = B_NOW); 40 41 virtual void ProgramChange(uchar channel, 42 uchar programNumber, 43 uint32 time = B_NOW); 44 45 virtual void ChannelPressure(uchar channel, 46 uchar pressure, 47 uint32 time = B_NOW); 48 49 virtual void PitchBend(uchar channel, 50 uchar lsb, 51 uchar msb, 52 uint32 time = B_NOW); 53 54 virtual void SystemExclusive(void* data, 55 size_t dataLength, 56 uint32 time = B_NOW); 57 58 virtual void SystemCommon(uchar statusByte, 59 uchar data1, 60 uchar data2, 61 uint32 time = B_NOW); 62 63 virtual void SystemRealTime(uchar statusByte, uint32 time = B_NOW); 64 65 virtual void TempoChange(int32 bpm, uint32 time = B_NOW); 66 67 status_t Import(const entry_ref *ref); 68 status_t Export(const entry_ref *ref, int32 format); 69 70 void SortEvents(bool force=false); 71 uint32 CountEvents() const; 72 73 uint32 CurrentEvent() const; 74 void SetCurrentEvent(uint32 eventNumber); 75 76 uint32 DeltaOfEvent(uint32 eventNumber) const; 77 uint32 EventAtDelta(uint32 time) const; 78 79 uint32 BeginTime() const; 80 81 void SetTempo(int32 bpm); 82 int32 Tempo() const; 83 84 private: 85 86 virtual void _ReservedMidiStore1(); 87 virtual void _ReservedMidiStore2(); 88 virtual void _ReservedMidiStore3(); 89 90 virtual void Run(); 91 92 void AddEvent(uint32 time, 93 bool inMS, 94 uchar type, 95 uchar data1 = 0, 96 uchar data2 = 0, 97 uchar data3 = 0, 98 uchar data4 = 0); 99 100 void AddSystemExclusive(void* data, size_t dataLength); 101 102 status_t ReadHeader(); 103 bool ReadMT(char*); 104 int32 Read32Bit(); 105 int32 EGetC(); 106 int32 To32Bit(int32, int32, int32, int32); 107 int32 Read16Bit(); 108 int32 To16Bit(int32, int32); 109 bool ReadTrack(); 110 int32 ReadVariNum(); 111 void ChannelMessage(int32, int32, int32); 112 void MsgInit(); 113 void MsgAdd(int32); 114 void BiggerMsg(); 115 void MetaEvent(int32); 116 int32 MsgLength(); 117 uchar* Msg(); 118 void BadByte(int32); 119 120 int32 PutC(int32 c); 121 bool WriteTrack(int32 track); 122 void WriteTempoTrack(); 123 bool WriteTrackChunk(int32 whichTrack); 124 void WriteHeaderChunk(int32 format); 125 bool WriteMidiEvent(uint32 deltaTime, 126 uint32 type, 127 uint32 channel, 128 uchar* data, 129 uint32 size); 130 bool WriteMetaEvent(uint32 deltaTime, 131 uint32 type, 132 uchar* data, 133 uint32 size); 134 bool WriteSystemExclusiveEvent(uint32 deltaTime, 135 uchar* data, 136 uint32 size); 137 void WriteTempo(uint32 deltaTime, int32 tempo); 138 void WriteVarLen(uint32 value); 139 void Write32Bit(uint32 data); 140 void Write16Bit(ushort data); 141 int32 EPutC(uchar c); 142 143 uint32 TicksToMilliseconds(uint32 ticks) const; 144 uint32 MillisecondsToTicks(uint32 ms) const; 145 146 BList *events; 147 // uint32 fNumEvents; 148 // uint32 fEventsSize; 149 uint32 fCurrEvent; 150 bool fNeedsSorting; 151 // bool fResetTimer; 152 uint32 fStartTime; 153 BFile* fFile; 154 short fDivision; 155 float fDivisionFactor; 156 int32 fTempo; 157 int32 fCurrTime; 158 int32 fCurrTrack; 159 int32 fNumTracks; 160 161 // int32 fToBeRead; 162 // int32 fMsgIndex; 163 // int32 fMsgSize; 164 // uchar* fMsgBuff; 165 166 int32 fNumBytesWritten; 167 168 uchar* fFileBuffer; 169 int32 fFileBufferMax; 170 int32 fFileBufferSize; 171 int32 fFileBufferIndex; 172 uint32 _reserved[4]; 173 }; 174 175 176 /*------------------------------------------------------------*/ 177 178 #endif 179