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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 // Music class
24 
25 #ifndef SAGA_MUSIC_H
26 #define SAGA_MUSIC_H
27 
28 #include "audio/mididrv.h"
29 #include "audio/midiplayer.h"
30 #include "audio/midiparser.h"
31 #include "audio/mixer.h"
32 
33 namespace Saga {
34 
35 enum MusicFlags {
36 	MUSIC_NORMAL = 0,
37 	MUSIC_LOOP = 0x0001
38 };
39 
40 class MusicDriver : public Audio::MidiPlayer {
41 public:
42 	MusicDriver();
43 
44 	void play(SagaEngine *vm, ByteArray *buffer, bool loop);
45 	void playQuickTime(const Common::String &musicName, bool loop);
46 	virtual void pause();
47 	virtual void resume();
48 
isAdlib()49 	bool isAdlib() const { return _driverType == MT_ADLIB; }
50 
51 	// FIXME
isPlaying()52 	bool isPlaying() const { return _parser && _parser->isPlaying(); }
53 
54 	// MidiDriver_BASE interface implementation
55 	virtual void send(uint32 b);
56 	virtual void metaEvent(byte type, byte *data, uint16 length);
57 
58 protected:
59 	MusicType _driverType;
60 	bool _isGM;
61 	bool _milesAudioMode;
62 };
63 
64 class Music {
65 public:
66 
67 	Music(SagaEngine *vm, Audio::Mixer *mixer);
68 	~Music();
69 	bool isPlaying();
hasDigitalMusic()70 	bool hasDigitalMusic() { return _digitalMusic; }
71 
72 	void play(uint32 resourceId, MusicFlags flags = MUSIC_NORMAL);
73 	void pause();
74 	void resume();
75 	void stop();
76 
77 	void setVolume(int volume, int time = 1);
getVolume()78 	int getVolume() { return _currentVolume; }
79 
isAdlib()80 	bool isAdlib() const { return _player->isAdlib(); }
81 
82 	Common::Array<int32> _songTable;
83 
84 private:
85 	SagaEngine *_vm;
86 	Audio::Mixer *_mixer;
87 
88 	MusicDriver *_player;
89 	Audio::SoundHandle _musicHandle;
90 	uint32 _trackNumber;
91 
92 	int _targetVolume;
93 	int _currentVolume;
94 	int _currentVolumePercent;
95 	bool _digitalMusic;
96 
97 	ResourceContext *_musicContext;
98 	ResourceContext *_digitalMusicContext;
99 
100 
101 	static void musicVolumeGaugeCallback(void *refCon);
102 	static void onTimer(void *refCon);
103 	void musicVolumeGauge();
104 	ByteArray *_currentMusicBuffer;
105 	ByteArray _musicBuffer[2];
106 };
107 
108 } // End of namespace Saga
109 
110 #endif
111