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 ULTIMA4_SOUND_MUSIC_H
24 #define ULTIMA4_SOUND_MUSIC_H
25 
26 #include "ultima/shared/std/containers.h"
27 #include "audio/audiostream.h"
28 #include "audio/midiplayer.h"
29 #include "audio/mixer.h"
30 
31 namespace Ultima {
32 namespace Ultima4 {
33 
34 #define CAMP_FADE_OUT_TIME          1000
35 #define CAMP_FADE_IN_TIME           0
36 #define INN_FADE_OUT_TIME           1000
37 #define INN_FADE_IN_TIME            5000
38 #define NLOOPS -1
39 
40 
41 class Music : public Audio::MidiPlayer {
42 public:
43 	enum Type {
44 		NONE,
45 		OUTSIDE,
46 		TOWNS,
47 		SHRINES,
48 		SHOPPING,
49 		RULEBRIT,
50 		FANFARE,
51 		DUNGEON,
52 		COMBAT,
53 		CASTLES,
54 		MAX
55 	};
56 
57 	Type _introMid;
58 private:
59 	Audio::Mixer *_mixer;
60 	Audio::SoundHandle _soundHandle;
61 	Std::vector<Common::String> _filenames;
62 
63 	/**
64 	 * Play a given music file if is exists
65 	 */
66 	bool startMusic(const Common::String &filename);
67 protected:
68 	// Overload Audio::MidiPlayer method
69 	void sendToChannel(byte channel, uint32 b) override;
70 public:
71 	Music(Audio::Mixer *mixer);
72 	~Music() override;
73 
74 	/**
75 	 * Play music
76 	 */
77 	void playMusic(const Common::String &filename);
78 
79 	/**
80 	 * Play music of a given type
81 	 */
82 	void playMusic(Type music);
83 
84 	/**
85 	 * Play the designated music for the current map
86 	 */
87 	void playMapMusic();
88 
89 	void stop() override;
90 
91 
92 	/**
93 	 * Fade out the music
94 	 */
fadeOut(int msecs)95 	void fadeOut(int msecs) {
96 		// TODO
97 	}
98 
99 	/**
100 	 * Fade in the music
101 	 */
fadeIn(int msecs,bool loadFromMap)102 	void fadeIn(int msecs, bool loadFromMap) {
103 		// TODO
104 	}
105 
106 	/**
107 	 * Music when you talk to Lord British
108 	 */
lordBritish()109 	void lordBritish() {
110 		playMusic(RULEBRIT);
111 	}
112 
113 	/**
114 	 * Music when you talk to Hawkwind
115 	 */
hawkwind()116 	void hawkwind() {
117 		playMusic(SHOPPING);
118 	}
119 
120 	/**
121 	 * Music that plays while camping
122 	 */
camp()123 	void camp() {
124 		fadeOut(1000);
125 	}
126 
127 	/**
128 	 * Music when talking to a vendor
129 	 */
shopping()130 	void shopping() {
131 		playMusic(SHOPPING);
132 	}
133 
intro()134 	void intro() {
135 #ifdef IOS_ULTIMA4
136 		_on = true; // Force iOS to turn this back on from going in the background.
137 #endif
138 		playMusic(_introMid);
139 	}
140 
141 	/**
142 	 * Cycle through the introduction music
143 	 */
144 	void introSwitch(int n);
145 };
146 
147 extern Music *g_music;
148 
149 } // End of namespace Ultima4
150 } // End of namespace Ultima
151 
152 #endif
153