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 #ifndef ULTIMA8_AUDIO_CRUMUSICPROCESS_H
24 #define ULTIMA8_AUDIO_CRUMUSICPROCESS_H
25 
26 #include "ultima/ultima8/audio/music_process.h"
27 #include "ultima/ultima8/misc/classtype.h"
28 #include "audio/audiostream.h"
29 #include "audio/mixer.h"
30 
31 namespace Ultima {
32 namespace Ultima8 {
33 
34 class Debugger;
35 class MidiPlayer;
36 
37 class CruMusicProcess : public MusicProcess {
38 	friend class Debugger;
39 
40 protected:
41 	//! Play a music track
42 	//! \param track The track number to play. Pass 0 to stop music
43 	void playMusic_internal(int track) override;
44 
45 private:
46 	int _currentTrack;      //! Currently playing track (don't save)
47 
48 	int _savedTrack;
49 
50 	uint8 _m16offset;
51 
52 	Audio::SoundHandle _soundHandle;
53 
54 	// These are both initialized in constructor and do not need to be saved.
55 	int _maxTrack;
56 	const char **_trackNames;
57 
58 public:
59 	CruMusicProcess();
60 	~CruMusicProcess() override;
61 
62 	ENABLE_RUNTIME_CLASSTYPE()
63 
64 	//! Play some background music. Does not change the current track if combat music is active.  If another track is currently queued, just queues this track for play.
65 	void playMusic(int track) override;
66 	//! Play some combat music - the last played track will be remembered
67 	void playCombatMusic(int track) override;
68 	//! Queue a track to start once the current one finishes
69 	void queueMusic(int track) override;
70 	//! Clear any queued track (does not affect currently playing track)
71 	void unqueueMusic() override;
72 	//! Restore the last requested non-combat track (eg, at the end of combat)
73 	void restoreMusic() override;
74 
75 	//! Fading is not used, so this does nothing
fadeMusic(uint16 length)76 	void fadeMusic(uint16 length) override { };
77 	//! Fading is not used, so this returns false
isFading()78 	bool isFading() override { return false; };
79 
80 	//! Save the current track state - used when the menu is opened
81 	void saveTrackState() override;
82 	//! Bring back the track state from before it was put on hold
83 	void restoreTrackState() override;
84 
85 	//! Is a track currently playing?
86 	bool isPlaying() override;
87 
88 	//! Pause the currently playing track
89 	void pauseMusic() override;
90 	//! Resume the current track after pausing
91 	void unpauseMusic() override;
92 
93 	void run() override;
94 
95 	bool loadData(Common::ReadStream *rs, uint32 version);
96 	void saveData(Common::WriteStream *ws) override;
97 };
98 
99 } // End of namespace Ultima8
100 } // End of namespace Ultima
101 
102 #endif
103