ScummVM API documentation
midi.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 AGOS_MIDI_H
23 #define AGOS_MIDI_H
24 
25 #include "agos/sfxparser_accolade.h"
26 
27 #include "audio/mididrv.h"
28 #include "audio/mididrv_ms.h"
29 #include "audio/midiparser.h"
30 #include "common/mutex.h"
31 
32 namespace Common {
33 class File;
34 }
35 
36 namespace AGOS {
37 
38 class MidiPlayer {
39 protected:
40  // Instrument map specifically for remapping the instruments of the GM
41  // version of Simon 2 track 10 subtracks 2 and 3 to MT-32.
42  static const byte SIMON2_TRACK10_GM_MT32_INSTRUMENT_REMAPPING[];
43 
44  AGOSEngine *_vm;
45 
46  Common::Mutex _mutex;
47  // Driver used for music. This points to the same object as _driverMsMusic,
48  // except if a PC-98 driver is used (these do not implement the Multisource
49  // interface).
50  MidiDriver *_driver;
51  // Multisource driver used for music. Provides access to multisource
52  // methods without casting. If this is not nullptr, it points to the same
53  // object as _driver.
54  MidiDriver_Multisource *_driverMsMusic;
55  // Multisource driver used for sound effects. Only used for Elvira 2,
56  // Waxworks and Simon The Sorcerer DOS floppy AdLib sound effects.
57  // If AdLib is also used for music, this points to the same object as
58  // _driverMsMusic and _driver.
59  MidiDriver_Multisource *_driverMsSfx;
60 
61  // MIDI parser and data used for music.
62  MidiParser *_parserMusic;
63  byte *_musicData;
64  // MIDI parser and data used for SFX (Simon 1 DOS floppy).
65  MidiParser *_parserSfx;
66  byte *_sfxData;
67  // Parser used for SFX (Elvira 2 and Waxworks DOS).
68  SfxParser_Accolade *_parserSfxAccolade;
69 
70  bool _paused;
71 
72  // Queued music track data (Simon 2).
73  byte _queuedTrack;
74  bool _loopQueuedTrack;
75 
76 protected:
77  static void onTimer(void *data);
78 
79 public:
81  ~MidiPlayer();
82 
83  // Creates and opens the relevant parsers and drivers for the game version
84  // and selected sound device.
85  int open();
86 
87  // Loads music or SFX data supported by the MidiParser or SfxParser used
88  // for the detected version of the game. Specify sfx to indicate that this
89  // is a synthesized sound effect.
90  void load(Common::SeekableReadStream *in, int32 size = -1, bool sfx = false);
91 
104  void play(int track = 0, bool sfx = false, bool sfxUsesRhythm = false, bool queued = false);
105 
106  // Returns true if the playback device uses MT-32 MIDI data; false it it
107  // uses a different data type.
108  bool usesMT32Data() const;
109  // Returns true if the game version and selected sound device can use MIDI
110  // (or synthesized) sound effects.
111  bool hasMidiSfx() const;
112  void setLoop(bool loop);
113  // Activates or deactivates remapping GM to MT-32 instruments for
114  // Simon 2 track 10.
115  void setSimon2Remapping(bool remap);
116  void queueTrack(int track, bool loop);
117  bool isPlaying(bool checkQueued = false);
118 
119  void stop(bool sfx = false);
120  void pause(bool b);
121  void fadeOut();
122 
123  void syncSoundSettings();
124 
125 private:
126  bool _pc98;
127  // The type of the music device selected for playback.
128  MusicType _deviceType;
129  // The type of the MIDI data of the game (MT-32 or GM).
130  MusicType _dataType;
131 
132 private:
133  Common::SeekableReadStream *simon2SetupExtractFile(const Common::String &requestedFileName);
134 };
135 
136 } // End of namespace AGOS
137 
138 #endif
Definition: str.h:59
Definition: mididrv_ms.h:86
MusicType
Definition: mididrv.h:44
Definition: midi.h:38
Definition: stream.h:745
Definition: agos.h:200
Definition: mididrv.h:299
Definition: agos.h:63
Definition: algorithm.h:29
Definition: mutex.h:67
Definition: sfxparser_accolade.h:33
Definition: midiparser.h:289