diff --git a/music.h b/music.h new file mode 100644 index 0000000000..5d968404a2 --- /dev/null +++ b/music.h @@ -0,0 +1,16 @@ +/* $Id */ + +#ifndef MUSIC_H +#define MUSIC_H + +#define NUM_SONGS_PLAYLIST 33 +#define NUM_SONGS_AVAILABLE 22 + +typedef struct SongSpecs { + char filename[256]; + char song_name[64]; +} SongSpecs; + +extern const SongSpecs origin_songs_specs[NUM_SONGS_AVAILABLE]; + +#endif //MUSIC_H diff --git a/music_gui.c b/music_gui.c index 4da6c64d5a..57cbad32c6 100644 --- a/music_gui.c +++ b/music_gui.c @@ -10,12 +10,12 @@ #include "hal.h" #include "macros.h" #include "variables.h" +#include "music.h" static byte _music_wnd_cursong; static bool _song_is_active; -static byte _cur_playlist[33]; +static byte _cur_playlist[NUM_SONGS_PLAYLIST]; -#define NUM_SONGS_AVAILABLE 22 static byte _playlist_all[] = { @@ -43,33 +43,31 @@ static byte * const _playlists[] = { msf.custom_2, }; -// Map the order of the song names to the numbers of the midi filenames -static const byte midi_idx[] = { - 0, // Tycoon DELUXE Theme - 2, // Easy Driver - 3, // Little Red Diesel - 17, // Cruise Control - 7, // Don't Walk! - 9, // Fell Apart On Me - 4, // City Groove - 19, // Funk Central - 6, // Stoke It - 12, // Road Hog - 5, // Aliens Ate My Railway - 1, // Snarl Up - 18, // Stroll On - 10, // Can't Get There From Here - 8, // Sawyer's Tune - 13, // Hold That Train! - 21, // Movin' On - 15, // Goss Groove - 16, // Small Town - 14, // Broomer's Oil Rag - 20, // Jammit - 11 // Hard Drivin' +const SongSpecs origin_songs_specs[NUM_SONGS_AVAILABLE] = { + {"gm_tt00.gm", "Tycoon DELUXE Theme"}, + {"gm_tt02.gm", "Easy Driver"}, + {"gm_tt03.gm", "Little Red Diesel"}, + {"gm_tt17.gm", "Cruise Control"}, + {"gm_tt07.gm", "Don't Walk!"}, + {"gm_tt09.gm", "Fell Apart On Me"}, + {"gm_tt04.gm", "City Groove"}, + {"gm_tt19.gm", "Funk Central"}, + {"gm_tt06.gm", "Stoke It"}, + {"gm_tt12.gm", "Road Hog"}, + {"gm_tt05.gm", "Aliens Ate My Railway"}, + {"gm_tt01.gm", "Snarl Up"}, + {"gm_tt18.gm", "Stroll On"}, + {"gm_tt10.gm", "Can't Get There From Here"}, + {"gm_tt08.gm", "Sawyer's Tune"}, + {"gm_tt13.gm", "Hold That Train!"}, + {"gm_tt21.gm", "Movin' On"}, + {"gm_tt15.gm", "Goss Groove"}, + {"gm_tt16.gm", "Small Town"}, + {"gm_tt14.gm", "Broomer's Oil Rag"}, + {"gm_tt20.gm", "Jammit"}, + {"gm_tt11.gm", "Hard Drivin'"}, }; - static void SkipToPrevSong(void) { byte *b = _cur_playlist; @@ -118,8 +116,8 @@ static void MusicVolumeChanged(byte new_vol) static void DoPlaySong(void) { char filename[256]; - snprintf(filename, sizeof(filename), "%sgm_tt%.2d.gm", - _path.gm_dir, midi_idx[_music_wnd_cursong - 1]); + snprintf(filename, sizeof(filename), "%s%s", + _path.gm_dir, origin_songs_specs[_music_wnd_cursong - 1].filename); _music_driver->play_song(filename); } @@ -131,10 +129,19 @@ static void DoStopMusic(void) static void SelectSongToPlay(void) { uint i = 0; + uint j = 0; + char filename[256]; memset(_cur_playlist, 0, sizeof(_cur_playlist)); do { - _cur_playlist[i] = _playlists[msf.playlist][i]; + snprintf(filename, sizeof(filename), "%s%s", + _path.gm_dir, origin_songs_specs[_playlists[msf.playlist][i]].filename); + //we are now checking for the existence of that file prior + //to add it to the list of available songs + if (FileExists(filename)) { + _cur_playlist[j] = _playlists[msf.playlist][i]; + j++; + } } while (_playlists[msf.playlist][i++] != 0 && i < lengthof(_cur_playlist) - 1); if (msf.shuffle) { @@ -165,7 +172,15 @@ static void PlayPlaylistSong(void) { if (_cur_playlist[0] == 0) { SelectSongToPlay(); - if (_cur_playlist[0] == 0) return; + //if there is not songs in the playlist, it may indicate + //no file on the gm folder, or even no gm folder. + //Stop the playback, then + if (_cur_playlist[0] == 0) { + _song_is_active = false; + _music_wnd_cursong = 0; + msf.playing = false; + return; + } } _music_wnd_cursong = _cur_playlist[0]; DoPlaySong(); @@ -182,13 +197,13 @@ void ResetMusic(void) void MusicLoop(void) { - if (!msf.btn_down && _song_is_active) { + if (!msf.playing && _song_is_active) { StopMusic(); - } else if (msf.btn_down && !_song_is_active) { + } else if (msf.playing && !_song_is_active) { PlayPlaylistSong(); } - if (_song_is_active == false) return; + if (!_song_is_active) return; if (!_music_driver->is_song_playing()) { if (_game_mode != GM_MENU) { @@ -257,7 +272,7 @@ static void MusicTrackSelectionWndProc(Window *w, WindowEvent *e) if (!IS_INT_INSIDE(y, 0, NUM_SONGS_AVAILABLE)) return; p = _playlists[msf.playlist]; - for (i = 0; i != 32; i++) { + for (i = 0; i != NUM_SONGS_PLAYLIST - 1; i++) { if (p[i] == 0) { p[i] = y + 1; p[i + 1] = 0; @@ -339,7 +354,7 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e) color = 0xB8; } } - GfxFillRect(187, 33 - i * 2, 200, 33 - i * 2, color); + GfxFillRect(187, NUM_SONGS_PLAYLIST - i * 2, 200, NUM_SONGS_PLAYLIST - i * 2, color); } GfxFillRect(60, 46, 239, 52, 0); @@ -405,10 +420,10 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e) SkipToNextSong(); break; case 4: // stop playing - msf.btn_down = false; + msf.playing = false; break; case 5: // start playing - msf.btn_down = true; + msf.playing = true; break; case 6:{ // volume sliders byte *vol,new_vol; diff --git a/settings.c b/settings.c index 41c6903bf0..e0aeae551f 100644 --- a/settings.c +++ b/settings.c @@ -742,7 +742,7 @@ static const SettingDesc music_settings[] = { {"effect_vol",SDT_UINT8, (void*)128, &msf.effect_vol, NULL}, {"custom_1", SDT_INTLIST | SDT_UINT8 | lengthof(msf.custom_1) << 16, NULL, &msf.custom_1, NULL}, {"custom_2", SDT_INTLIST | SDT_UINT8 | lengthof(msf.custom_2) << 16, NULL, &msf.custom_2, NULL}, - {"playing", SDT_BOOL, (void*)true, &msf.btn_down, NULL}, + {"playing", SDT_BOOL, (void*)true, &msf.playing, NULL}, {"shuffle", SDT_BOOL, (void*)false, &msf.shuffle, NULL}, {"extmidi", SDT_STRINGBUF | (lengthof(msf.extmidi)<<16), EXTERNAL_PLAYER, &msf.extmidi, NULL}, {NULL, 0, NULL, NULL, NULL} diff --git a/sound.h b/sound.h index f129d36123..9f9edaddc3 100644 --- a/sound.h +++ b/sound.h @@ -9,7 +9,7 @@ typedef struct MusicFileSettings { byte effect_vol; byte custom_1[33]; byte custom_2[33]; - bool btn_down; + bool playing; bool shuffle; char extmidi[80]; } MusicFileSettings; diff --git a/strings.c b/strings.c index 608464be53..db2d044c79 100644 --- a/strings.c +++ b/strings.c @@ -16,6 +16,7 @@ #include "waypoint.h" #include "industry.h" #include "variables.h" +#include "music.h" char _userstring[128]; @@ -899,31 +900,6 @@ static char *GenPresidentName(char *buff, uint32 x) return buff; } -static const char * const _song_names[] = { - "Tycoon DELUXE Theme", - "Easy Driver", - "Little Red Diesel", - "Cruise Control", - "Don't Walk!", - "Fell Apart On Me", - "City Groove", - "Funk Central", - "Stoke It", - "Road Hog", - "Aliens Ate My Railway", - "Snarl Up", - "Stroll On", - "Can't Get There From Here", - "Sawyer's Tune", - "Hold That Train!", - "Movin' On", - "Goss Groove", - "Small Town", - "Broomer's Oil Rag", - "Jammit", - "Hard Drivin'" -}; - static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv) { switch (ind) { @@ -937,7 +913,7 @@ static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv) return GenPresidentName(buff, GetInt32(&argv)); case 4: // song names - return strecpy(buff, _song_names[GetInt32(&argv) - 1], NULL); + return strecpy(buff, origin_songs_specs[GetInt32(&argv) - 1].song_name, NULL); } // town name?