ScummVM API documentation
midiparser_qt.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef AUDIO_MIDIPARSER_QT_H
23 #define AUDIO_MIDIPARSER_QT_H
24 
25 #include "audio/midiparser.h"
26 #include "common/array.h"
27 #include "common/hashmap.h"
28 #include "common/queue.h"
29 #include "common/formats/quicktime.h"
30 
56 public:
57  MidiParser_QT(int8 source = -1) : _source(source) {}
58  ~MidiParser_QT() {}
59 
60  // MidiParser
61  bool loadMusic(byte *data, uint32 size) override;
62  void unloadMusic() override;
63 
67  bool loadFromTune(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
68 
72  bool loadFromContainerStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
73 
77  bool loadFromContainerFile(const Common::Path &fileName);
78 
79 protected:
80  // MidiParser
81  void parseNextEvent(EventInfo &info) override;
82  void resetTracking() override;
83 
84  void sendToDriver(uint32 b) override;
85  void sendMetaEventToDriver(byte type, byte *data, uint16 length) override;
86 
87  // QuickTimeParser
88  SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize) override;
89 
97  int8 _source;
98 
99 private:
100  struct MIDITrackInfo {
101  byte *data;
102  uint32 size;
103  uint32 timeScale;
104  };
105 
106  struct PartStatus {
107  uint32 instrument;
108  byte volume;
109  byte pan;
110  uint16 pitchBend;
111  };
112 
113  class MIDISampleDesc : public SampleDesc {
114  public:
115  MIDISampleDesc(Common::QuickTimeParser::Track *parentTrack, uint32 codecTag);
116  ~MIDISampleDesc() {}
117 
118  byte *_requestData;
119  uint32 _requestSize;
120  };
121 
122  uint32 readNextEvent();
123  void handleGeneralEvent(uint32 control);
124  void handleControllerEvent(uint32 control, uint32 part, byte intPart, byte fracPart);
125  void handleNoteEvent(uint32 part, byte pitch, byte velocity, uint32 length);
126 
127  void definePart(uint32 part, uint32 instrument);
128  void setupPart(uint32 part);
129 
130  byte getChannel(uint32 part);
131  bool isChannelAllocated(byte channel) const;
132  byte findFreeChannel(uint32 part);
133  void deallocateFreeChannel();
134  void deallocateChannel(byte channel);
135  bool allChannelsAllocated() const;
136 
137  byte *readWholeTrack(Common::QuickTimeParser::Track *track, uint32 &trackSize);
138 
139  Common::Array<MIDITrackInfo> _trackInfo;
140  Common::Queue<EventInfo> _queuedEvents;
141 
143  PartMap _partMap;
144 
146  ChannelMap _channelMap;
147 
148  void initFromContainerTracks();
149  void initCommon();
150  uint32 readUint32();
151 };
153 #endif
Definition: midiparser_qt.h:55
int8 _source
Definition: midiparser_qt.h:97
Definition: quicktime.h:132
Definition: path.h:52
Definition: stream.h:745
Definition: midiparser.h:84
Definition: quicktime.h:58
Definition: quicktime.h:276
bool loadFromTune(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse=DisposeAfterUse::YES)
bool loadFromContainerStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse=DisposeAfterUse::YES)
bool loadFromContainerFile(const Common::Path &fileName)
Definition: midiparser.h:289