1 2 #ifndef _MIDI_STORE_H 3 #define _MIDI_STORE_H 4 5 #include <BeBuild.h> 6 #include <Midi.h> 7 #include <MidiSynthFile.h> 8 9 struct entry_ref; 10 11 class BFile; 12 class BList; 13 class BMidiEvent; 14 15 class BMidiStore : public BMidi 16 { 17 public: 18 19 BMidiStore(); 20 virtual ~BMidiStore(); 21 22 virtual void NoteOff( 23 uchar channel, uchar note, uchar velocity, uint32 time = B_NOW); 24 25 virtual void NoteOn( 26 uchar channel, uchar note, uchar velocity, uint32 time = B_NOW); 27 28 virtual void KeyPressure( 29 uchar channel, uchar note, uchar pressure, uint32 time = B_NOW); 30 31 virtual void ControlChange( 32 uchar channel, uchar controlNumber, uchar controlValue, 33 uint32 time = B_NOW); 34 35 virtual void ProgramChange( 36 uchar channel, uchar programNumber, uint32 time = B_NOW); 37 38 virtual void ChannelPressure( 39 uchar channel, uchar pressure, uint32 time = B_NOW); 40 41 virtual void PitchBend( 42 uchar channel, uchar lsb, uchar msb, uint32 time = B_NOW); 43 44 virtual void SystemExclusive( 45 void* data, size_t length, uint32 time = B_NOW); 46 47 virtual void SystemCommon( 48 uchar status, uchar data1, uchar data2, uint32 time = B_NOW); 49 50 virtual void SystemRealTime(uchar status, uint32 time = B_NOW); 51 52 virtual void TempoChange(int32 beatsPerMinute, uint32 time = B_NOW); 53 54 status_t Import(const entry_ref* ref); 55 status_t Export(const entry_ref* ref, int32 format); 56 57 void SortEvents(bool force = false); 58 uint32 CountEvents() const; 59 60 uint32 CurrentEvent() const; 61 void SetCurrentEvent(uint32 eventNumber); 62 63 uint32 DeltaOfEvent(uint32 eventNumber) const; 64 uint32 EventAtDelta(uint32 time) const; 65 66 uint32 BeginTime() const; 67 68 void SetTempo(int32 beatsPerMinute); 69 int32 Tempo() const; 70 71 private: 72 73 friend class BMidiSynthFile; 74 75 virtual void _ReservedMidiStore1(); 76 virtual void _ReservedMidiStore2(); 77 virtual void _ReservedMidiStore3(); 78 79 virtual void Run(); 80 81 void AddEvent(BMidiEvent* event); 82 void SprayEvent(const BMidiEvent* event, uint32 time); 83 BMidiEvent* EventAt(int32 index) const; 84 uint32 GetEventTime(const BMidiEvent* event) const; 85 uint32 TicksToMilliseconds(uint32 ticks) const; 86 uint32 MillisecondsToTicks(uint32 ms) const; 87 88 BList* events; 89 int32 currentEvent; 90 uint32 startTime; 91 int32 beatsPerMinute; 92 int16 ticksPerBeat; 93 bool needsSorting; 94 95 void ReadFourCC(char* fourcc); 96 uint32 Read32Bit(); 97 uint16 Read16Bit(); 98 uint8 PeekByte(); 99 uint8 NextByte(); 100 void SkipBytes(uint32 length); 101 uint32 ReadVarLength(); 102 void ReadChunk(); 103 void ReadTrack(); 104 void ReadSystemExclusive(); 105 void ReadMetaEvent(); 106 107 void WriteFourCC(char a, char b, char c, char d); 108 void Write32Bit(uint32 val); 109 void Write16Bit(uint16 val); 110 void WriteByte(uint8 val); 111 void WriteVarLength(uint32 val); 112 void WriteTrack(); 113 void WriteMetaEvent(BMidiEvent* event); 114 115 BFile* file; 116 uint32 byteCount; 117 uint32 totalTicks; 118 uint16 numTracks; 119 uint16 currTrack; 120 uint16 format; 121 122 uint16 _reserved1[1]; 123 124 bool* instruments; 125 synth_file_hook hookFunc; 126 int32 hookArg; 127 bool looping; 128 bool paused; 129 bool finished; 130 131 uint32 _reserved2[12]; 132 }; 133 134 #endif // _MIDI_STORE_H 135