ScummVM API documentation
music.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 GROOVIE_MUSIC_H
23 #define GROOVIE_MUSIC_H
24 
25 #include "common/array.h"
26 #include "common/mutex.h"
27 #include "common/file.h"
28 #include "audio/mididrv.h"
29 #include "audio/mididrv_ms.h"
30 #include "audio/mixer.h"
31 #include "audio/miles.h"
32 
33 class MidiParser;
34 
35 namespace Groovie {
36 
37 class GroovieEngine;
38 class TlcGame;
39 
40 class MusicPlayer {
41 public:
43  virtual ~MusicPlayer();
44 
45  void playSong(uint32 fileref);
46  // Stops all music playback. Clears the current
47  // background song.
48  void stop();
49  void setBackgroundSong(uint32 fileref);
50  void playCD(uint8 track);
51  void startBackground();
52  bool isPlaying() { return _isPlaying; }
53  // Pause or resume the music. Note that digital music
54  // already pauses when the ScummVM menu is open, so
55  // it does not seem to need an implementation.
56  virtual void pause(bool pause) { }
57 
58  // Set the MIDI initialization state
59  void setMidiInit(bool midiInit) { _midiInit = midiInit; }
60  // Returns true if MIDI has been fully initialized
61  bool isMidiInit() { return _midiInit; }
62 
63  void frameTick();
64  void setBackgroundDelay(uint16 delay);
65 
66  // Volume
67  virtual void setUserVolume(uint16 volume);
68  void setGameVolume(uint16 volume, uint16 time);
69 
70 private:
71  // Song playback
72  bool play(uint32 fileref, bool loop);
73  bool _isPlaying;
74  uint32 _backgroundFileRef;
75  uint8 _prevCDtrack;
76 
77  uint16 _backgroundDelay;
78 
79  // T7G iOS credits mp3 stream
80  void playCreditsIOS();
81  void stopCreditsIOS();
82  Audio::SoundHandle _handleCreditsIOS;
83 
84  // Volume fading
85  uint32 _fadingStartTime;
86  uint16 _fadingStartVolume;
87  uint16 _fadingEndVolume;
88  uint16 _fadingDuration;
89  void applyFading();
90 
91 protected:
92  GroovieEngine *_vm;
93 
94  // True if the MIDI initialization has completed
95  bool _midiInit;
96 
97  // Callback
98  static void onTimer(void *data);
99  virtual void onTimerInternal() {}
100  Common::Mutex _mutex;
101 
102  // User volume
103  uint16 _userVolume;
104  // Game volume
105  uint16 _gameVolume;
106 
107  // These are specific for each type of music
108  virtual void updateVolume() = 0;
109  virtual bool load(uint32 fileref, bool loop) = 0;
110  virtual void unload(bool updateState = true);
111 };
112 
114 public:
116  ~MusicPlayerMidi() override;
117 
118  // MidiDriver_BASE interface
119  void send(uint32 b) override;
120  void sysEx(const byte* msg, uint16 length) override;
121  uint16 sysExNoDelay(const byte *msg, uint16 length) override;
122  void metaEvent(byte type, byte *data, uint16 length) override;
123 
124  void pause(bool pause) override;
125 
126 private:
127  // Channel volumes
128  byte _chanVolumes[0x10];
129  void updateChanVolume(byte channel);
130 
131 protected:
132  byte *_data;
133  MidiParser *_midiParser;
134  MidiDriver *_driver;
135 
136  void onTimerInternal() override;
137  void updateVolume() override;
138  void unload(bool updateState = true) override;
139  void endTrack();
140 
141  bool loadParser(Common::SeekableReadStream *stream, bool loop);
142 };
143 
145 public:
146  MusicPlayerXMI(GroovieEngine *vm, const Common::String &gtlName);
147  ~MusicPlayerXMI();
148 
149  using MusicPlayerMidi::send;
150  void send(int8 source, uint32 b) override;
151  using MusicPlayerMidi::metaEvent;
152  void metaEvent(int8 source, byte type, byte *data, uint16 length) override;
153  void stopAllNotes(bool stopSustainedNotes) override;
154  void processXMIDITimbreChunk(const byte *timbreListPtr, uint32 timbreListSize) override {
155  if (_milesXmidiTimbres)
156  _milesXmidiTimbres->processXMIDITimbreChunk(timbreListPtr, timbreListSize);
157  };
158  bool isReady(int8 source = -1) override;
159 
160  void setUserVolume(uint16 volume) override;
161 
162 protected:
163  void updateVolume() override;
164  bool load(uint32 fileref, bool loop) override;
165  void unload(bool updateState = true) override;
166 
167 private:
168  // Output music type
169  uint8 _musicType;
170 
171  MidiDriver_Multisource *_multisourceDriver;
172  MidiDriver_Miles_Xmidi_Timbres *_milesXmidiTimbres;
173 };
174 
176 public:
178 
179 protected:
180  bool load(uint32 fileref, bool loop) override;
181 
182 private:
184 };
185 
187 public:
189 
190 protected:
191  bool load(uint32 fileref, bool loop) override;
192 };
193 
194 class MusicPlayerIOS : public MusicPlayer {
195 public:
197  ~MusicPlayerIOS() override;
198 
199 protected:
200  void updateVolume() override;
201  bool load(uint32 fileref, bool loop) override;
202  void unload(bool updateState = true) override;
203 
204 private:
205  Audio::SoundHandle _handle;
206 };
207 
208 class MusicPlayerTlc : public MusicPlayer {
209 public:
211  ~MusicPlayerTlc();
212 
213 protected:
214  virtual Common::String getFilename(uint32 fileref);
215  void updateVolume() override;
216  bool load(uint32 fileref, bool loop) override;
217  void unload(bool updateState = true) override;
218 
219 private:
220  Audio::SoundHandle _handle;
221  Common::File *_file;
222 };
223 
225 public:
227 
228 protected:
229  Common::String getFilename(uint32 fileref) override;
230 };
231 
232 } // End of Groovie namespace
233 
234 #endif // GROOVIE_MUSIC_H
Definition: str.h:59
void processXMIDITimbreChunk(const byte *timbreListPtr, uint32 timbreListSize) override
Definition: music.h:154
Definition: groovie.h:113
Definition: mididrv_ms.h:86
Definition: music.h:113
Definition: stream.h:745
Definition: music.h:40
Definition: mididrv.h:299
void send(uint32 b) override
Definition: mixer.h:49
Definition: music.h:144
Definition: music.h:208
Definition: file.h:47
Definition: mididrv.h:102
Definition: music.h:224
Definition: mutex.h:67
Definition: music.h:194
Definition: music.h:175
Definition: cursor.h:32
Definition: midiparser.h:289
Definition: music.h:186