xref: /haiku/headers/os/midi/MidiStore.h (revision 815212800210a100d07c2c3d8dfea18360426319)
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 struct BMidiEvent;
14 
15 class BMidiStore : public BMidi {
16 public:
17 
18 	BMidiStore();
19 	virtual ~BMidiStore();
20 
21 	virtual void NoteOff(
22 		uchar channel, uchar note, uchar velocity, uint32 time = B_NOW);
23 
24 	virtual void NoteOn(
25 		uchar channel, uchar note, uchar velocity, uint32 time = B_NOW);
26 
27 	virtual void KeyPressure(
28 		uchar channel, uchar note, uchar pressure, uint32 time = B_NOW);
29 
30 	virtual void ControlChange(
31 		uchar channel, uchar controlNumber, uchar controlValue,
32 		uint32 time = B_NOW);
33 
34 	virtual void ProgramChange(
35 		uchar channel, uchar programNumber, uint32 time = B_NOW);
36 
37 	virtual void ChannelPressure(
38 		uchar channel, uchar pressure, uint32 time = B_NOW);
39 
40 	virtual void PitchBend(
41 		uchar channel, uchar lsb, uchar msb, uint32 time = B_NOW);
42 
43 	virtual void SystemExclusive(
44 		void* data, size_t length, uint32 time = B_NOW);
45 
46 	virtual void SystemCommon(
47 		uchar status, uchar data1, uchar data2, uint32 time = B_NOW);
48 
49 	virtual void SystemRealTime(uchar status, uint32 time = B_NOW);
50 
51 	virtual void TempoChange(int32 beatsPerMinute, uint32 time = B_NOW);
52 
53 	status_t Import(const entry_ref* ref);
54 	status_t Export(const entry_ref* ref, int32 format);
55 
56 	void SortEvents(bool force = false);
57 	uint32 CountEvents() const;
58 
59 	uint32 CurrentEvent() const;
60 	void SetCurrentEvent(uint32 eventNumber);
61 
62 	uint32 DeltaOfEvent(uint32 eventNumber) const;
63 	uint32 EventAtDelta(uint32 time) const;
64 
65 	uint32 BeginTime() const;
66 
67 	void SetTempo(int32 beatsPerMinute);
68 	int32 Tempo() const;
69 
70 private:
71 
72 	friend class BMidiSynthFile;
73 
74 	virtual void _ReservedMidiStore1();
75 	virtual void _ReservedMidiStore2();
76 	virtual void _ReservedMidiStore3();
77 
78 	virtual void Run();
79 
80 	void AddEvent(BMidiEvent* event);
81 	void SprayEvent(const BMidiEvent* event, uint32 time);
82 	BMidiEvent* EventAt(int32 index) const;
83 	uint32 GetEventTime(const BMidiEvent* event) const;
84 	uint32 TicksToMilliseconds(uint32 ticks) const;
85 	uint32 MillisecondsToTicks(uint32 ms) const;
86 
87 	BList* fEvents;
88 	int32 fCurrentEvent;
89 	uint32 fStartTime;
90 	int32 fBeatsPerMinute;
91 	int16 fTicksPerBeat;
92 	bool fNeedsSorting;
93 
94 	void ReadFourCC(char* fourcc);
95 	uint32 Read32Bit();
96 	uint16 Read16Bit();
97 	uint8 PeekByte();
98 	uint8 NextByte();
99 	void SkipBytes(uint32 length);
100 	uint32 ReadVarLength();
101 	void ReadChunk();
102 	void ReadTrack();
103 	void ReadSystemExclusive();
104 	void ReadMetaEvent();
105 
106 	void WriteFourCC(char a, char b, char c, char d);
107 	void Write32Bit(uint32 val);
108 	void Write16Bit(uint16 val);
109 	void WriteByte(uint8 val);
110 	void WriteVarLength(uint32 val);
111 	void WriteTrack();
112 	void WriteMetaEvent(BMidiEvent* event);
113 
114 	BFile* fFile;
115 	uint32 fByteCount;
116 	uint32 fTotalTicks;
117 	uint16 fNumTracks;
118 	uint16 fCurrTrack;
119 	uint16 fFormat;
120 
121 	uint16 _reserved1[1];
122 
123 	bool* fInstruments;
124 	synth_file_hook fHookFunc;
125 	int32 fHookArg;
126 	bool fLooping;
127 	bool fPaused;
128 	bool fFinished;
129 
130 	uint32 _reserved2[12];
131 };
132 
133 #endif // _MIDI_STORE_H
134