branch | 0.4 |
changeset 10065 | fc91a7eca19e |
parent 9959 | 984493ab6fff |
10064:c63f74223041 | 10065:fc91a7eca19e |
---|---|
8 #include "gfx.h" |
8 #include "gfx.h" |
9 #include "sound.h" |
9 #include "sound.h" |
10 #include "hal.h" |
10 #include "hal.h" |
11 #include "macros.h" |
11 #include "macros.h" |
12 #include "variables.h" |
12 #include "variables.h" |
13 #include "music.h" |
|
13 |
14 |
14 static byte _music_wnd_cursong; |
15 static byte _music_wnd_cursong; |
15 static bool _song_is_active; |
16 static bool _song_is_active; |
16 static byte _cur_playlist[33]; |
17 static byte _cur_playlist[NUM_SONGS_PLAYLIST]; |
17 |
18 |
18 #define NUM_SONGS_AVAILABLE 22 |
|
19 |
19 |
20 |
20 |
21 static byte _playlist_all[] = { |
21 static byte _playlist_all[] = { |
22 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 0 |
22 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 0 |
23 }; |
23 }; |
41 _playlist_ezy_street, |
41 _playlist_ezy_street, |
42 msf.custom_1, |
42 msf.custom_1, |
43 msf.custom_2, |
43 msf.custom_2, |
44 }; |
44 }; |
45 |
45 |
46 // Map the order of the song names to the numbers of the midi filenames |
46 const SongSpecs origin_songs_specs[NUM_SONGS_AVAILABLE] = { |
47 static const byte midi_idx[] = { |
47 {"gm_tt00.gm", "Tycoon DELUXE Theme"}, |
48 0, // Tycoon DELUXE Theme |
48 {"gm_tt02.gm", "Easy Driver"}, |
49 2, // Easy Driver |
49 {"gm_tt03.gm", "Little Red Diesel"}, |
50 3, // Little Red Diesel |
50 {"gm_tt17.gm", "Cruise Control"}, |
51 17, // Cruise Control |
51 {"gm_tt07.gm", "Don't Walk!"}, |
52 7, // Don't Walk! |
52 {"gm_tt09.gm", "Fell Apart On Me"}, |
53 9, // Fell Apart On Me |
53 {"gm_tt04.gm", "City Groove"}, |
54 4, // City Groove |
54 {"gm_tt19.gm", "Funk Central"}, |
55 19, // Funk Central |
55 {"gm_tt06.gm", "Stoke It"}, |
56 6, // Stoke It |
56 {"gm_tt12.gm", "Road Hog"}, |
57 12, // Road Hog |
57 {"gm_tt05.gm", "Aliens Ate My Railway"}, |
58 5, // Aliens Ate My Railway |
58 {"gm_tt01.gm", "Snarl Up"}, |
59 1, // Snarl Up |
59 {"gm_tt18.gm", "Stroll On"}, |
60 18, // Stroll On |
60 {"gm_tt10.gm", "Can't Get There From Here"}, |
61 10, // Can't Get There From Here |
61 {"gm_tt08.gm", "Sawyer's Tune"}, |
62 8, // Sawyer's Tune |
62 {"gm_tt13.gm", "Hold That Train!"}, |
63 13, // Hold That Train! |
63 {"gm_tt21.gm", "Movin' On"}, |
64 21, // Movin' On |
64 {"gm_tt15.gm", "Goss Groove"}, |
65 15, // Goss Groove |
65 {"gm_tt16.gm", "Small Town"}, |
66 16, // Small Town |
66 {"gm_tt14.gm", "Broomer's Oil Rag"}, |
67 14, // Broomer's Oil Rag |
67 {"gm_tt20.gm", "Jammit"}, |
68 20, // Jammit |
68 {"gm_tt11.gm", "Hard Drivin'"}, |
69 11 // Hard Drivin' |
69 }; |
70 }; |
|
71 |
|
72 |
70 |
73 static void SkipToPrevSong(void) |
71 static void SkipToPrevSong(void) |
74 { |
72 { |
75 byte *b = _cur_playlist; |
73 byte *b = _cur_playlist; |
76 byte *p = b; |
74 byte *p = b; |
116 } |
114 } |
117 |
115 |
118 static void DoPlaySong(void) |
116 static void DoPlaySong(void) |
119 { |
117 { |
120 char filename[256]; |
118 char filename[256]; |
121 snprintf(filename, sizeof(filename), "%sgm_tt%.2d.gm", |
119 snprintf(filename, sizeof(filename), "%s%s", |
122 _path.gm_dir, midi_idx[_music_wnd_cursong - 1]); |
120 _path.gm_dir, origin_songs_specs[_music_wnd_cursong - 1].filename); |
123 _music_driver->play_song(filename); |
121 _music_driver->play_song(filename); |
124 } |
122 } |
125 |
123 |
126 static void DoStopMusic(void) |
124 static void DoStopMusic(void) |
127 { |
125 { |
129 } |
127 } |
130 |
128 |
131 static void SelectSongToPlay(void) |
129 static void SelectSongToPlay(void) |
132 { |
130 { |
133 uint i = 0; |
131 uint i = 0; |
132 uint j = 0; |
|
133 char filename[256]; |
|
134 |
134 |
135 memset(_cur_playlist, 0, sizeof(_cur_playlist)); |
135 memset(_cur_playlist, 0, sizeof(_cur_playlist)); |
136 do { |
136 do { |
137 _cur_playlist[i] = _playlists[msf.playlist][i]; |
137 snprintf(filename, sizeof(filename), "%s%s", |
138 _path.gm_dir, origin_songs_specs[_playlists[msf.playlist][i]].filename); |
|
139 //we are now checking for the existence of that file prior |
|
140 //to add it to the list of available songs |
|
141 if (FileExists(filename)) { |
|
142 _cur_playlist[j] = _playlists[msf.playlist][i]; |
|
143 j++; |
|
144 } |
|
138 } while (_playlists[msf.playlist][i++] != 0 && i < lengthof(_cur_playlist) - 1); |
145 } while (_playlists[msf.playlist][i++] != 0 && i < lengthof(_cur_playlist) - 1); |
139 |
146 |
140 if (msf.shuffle) { |
147 if (msf.shuffle) { |
141 i = 500; |
148 i = 500; |
142 do { |
149 do { |
163 |
170 |
164 static void PlayPlaylistSong(void) |
171 static void PlayPlaylistSong(void) |
165 { |
172 { |
166 if (_cur_playlist[0] == 0) { |
173 if (_cur_playlist[0] == 0) { |
167 SelectSongToPlay(); |
174 SelectSongToPlay(); |
168 if (_cur_playlist[0] == 0) return; |
175 //if there is not songs in the playlist, it may indicate |
176 //no file on the gm folder, or even no gm folder. |
|
177 //Stop the playback, then |
|
178 if (_cur_playlist[0] == 0) { |
|
179 _song_is_active = false; |
|
180 _music_wnd_cursong = 0; |
|
181 msf.playing = false; |
|
182 return; |
|
183 } |
|
169 } |
184 } |
170 _music_wnd_cursong = _cur_playlist[0]; |
185 _music_wnd_cursong = _cur_playlist[0]; |
171 DoPlaySong(); |
186 DoPlaySong(); |
172 _song_is_active = true; |
187 _song_is_active = true; |
173 |
188 |
180 DoPlaySong(); |
195 DoPlaySong(); |
181 } |
196 } |
182 |
197 |
183 void MusicLoop(void) |
198 void MusicLoop(void) |
184 { |
199 { |
185 if (!msf.btn_down && _song_is_active) { |
200 if (!msf.playing && _song_is_active) { |
186 StopMusic(); |
201 StopMusic(); |
187 } else if (msf.btn_down && !_song_is_active) { |
202 } else if (msf.playing && !_song_is_active) { |
188 PlayPlaylistSong(); |
203 PlayPlaylistSong(); |
189 } |
204 } |
190 |
205 |
191 if (_song_is_active == false) return; |
206 if (!_song_is_active) return; |
192 |
207 |
193 if (!_music_driver->is_song_playing()) { |
208 if (!_music_driver->is_song_playing()) { |
194 if (_game_mode != GM_MENU) { |
209 if (_game_mode != GM_MENU) { |
195 StopMusic(); |
210 StopMusic(); |
196 SkipToNextSong(); |
211 SkipToNextSong(); |
255 |
270 |
256 if (msf.playlist < 4) return; |
271 if (msf.playlist < 4) return; |
257 if (!IS_INT_INSIDE(y, 0, NUM_SONGS_AVAILABLE)) return; |
272 if (!IS_INT_INSIDE(y, 0, NUM_SONGS_AVAILABLE)) return; |
258 |
273 |
259 p = _playlists[msf.playlist]; |
274 p = _playlists[msf.playlist]; |
260 for (i = 0; i != 32; i++) { |
275 for (i = 0; i != NUM_SONGS_PLAYLIST - 1; i++) { |
261 if (p[i] == 0) { |
276 if (p[i] == 0) { |
262 p[i] = y + 1; |
277 p[i] = y + 1; |
263 p[i + 1] = 0; |
278 p[i + 1] = 0; |
264 SetWindowDirty(w); |
279 SetWindowDirty(w); |
265 SelectSongToPlay(); |
280 SelectSongToPlay(); |
337 color = 0xBF; |
352 color = 0xBF; |
338 if (i > 6) { |
353 if (i > 6) { |
339 color = 0xB8; |
354 color = 0xB8; |
340 } |
355 } |
341 } |
356 } |
342 GfxFillRect(187, 33 - i * 2, 200, 33 - i * 2, color); |
357 GfxFillRect(187, NUM_SONGS_PLAYLIST - i * 2, 200, NUM_SONGS_PLAYLIST - i * 2, color); |
343 } |
358 } |
344 |
359 |
345 GfxFillRect(60, 46, 239, 52, 0); |
360 GfxFillRect(60, 46, 239, 52, 0); |
346 |
361 |
347 if (_song_is_active == 0 || _music_wnd_cursong == 0) { |
362 if (_song_is_active == 0 || _music_wnd_cursong == 0) { |
403 if (!_song_is_active) |
418 if (!_song_is_active) |
404 return; |
419 return; |
405 SkipToNextSong(); |
420 SkipToNextSong(); |
406 break; |
421 break; |
407 case 4: // stop playing |
422 case 4: // stop playing |
408 msf.btn_down = false; |
423 msf.playing = false; |
409 break; |
424 break; |
410 case 5: // start playing |
425 case 5: // start playing |
411 msf.btn_down = true; |
426 msf.playing = true; |
412 break; |
427 break; |
413 case 6:{ // volume sliders |
428 case 6:{ // volume sliders |
414 byte *vol,new_vol; |
429 byte *vol,new_vol; |
415 int x = e->click.pt.x - 88; |
430 int x = e->click.pt.x - 88; |
416 |
431 |