+static void *Load_MOD(char *filename)
+{
+#if defined(TARGET_SDL)
+ MusicInfo *mod_info;
+
+ if (!audio.sound_available)
+ return NULL;
+
+ mod_info = checked_calloc(sizeof(MusicInfo));
+
+ if ((mod_info->data_ptr = Mix_LoadMUS(filename)) == NULL)
+ {
+ Error(ERR_WARN, "cannot read music file '%s'", filename);
+ free(mod_info);
+ return NULL;
+ }
+
+ mod_info->type = MUS_TYPE_MOD;
+ mod_info->source_filename = getStringCopy(filename);
+
+ return mod_info;
+#else
+ return NULL;
+#endif
+}
+
+static void *Load_WAV_or_MOD(char *filename)
+{
+ if (FileIsSound(filename))
+ return Load_WAV(filename);
+ else if (FileIsMusic(filename))
+ return Load_MOD(filename);
+ else
+ return NULL;
+}
+
+void LoadCustomMusic_NoConf(void)
+{
+ static boolean draw_init_text = TRUE; /* only draw at startup */
+ static char *last_music_directory = NULL;
+ char *music_directory = getCustomMusicDirectory();
+ DIR *dir;
+ struct dirent *dir_entry;
+ int num_music = getMusicListSize();
+
+ if (!audio.sound_available)
+ return;
+
+ if (last_music_directory != NULL &&
+ strEqual(last_music_directory, music_directory))
+ return; /* old and new music directory are the same */
+
+ if (last_music_directory != NULL)
+ free(last_music_directory);
+ last_music_directory = getStringCopy(music_directory);
+
+ FreeAllMusic_NoConf();
+
+ if ((dir = opendir(music_directory)) == NULL)
+ {
+ Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
+ audio.music_available = FALSE;
+ return;
+ }
+
+ if (draw_init_text)
+ DrawInitText("Loading music", 120, FC_GREEN);
+
+ while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */
+ {
+ char *basename = dir_entry->d_name;
+ char *filename = NULL;
+ MusicInfo *mus_info = NULL;
+ boolean music_already_used = FALSE;
+ int i;
+
+ /* skip all music files that are configured in music config file */
+ for (i = 0; i < num_music; i++)
+ {
+ struct FileInfo *music = getMusicListEntry(i);
+
+ if (strEqual(basename, music->filename))
+ {
+ music_already_used = TRUE;
+ break;
+ }
+ }
+
+ if (music_already_used)
+ continue;
+
+ if (draw_init_text)
+ DrawInitText(basename, 150, FC_YELLOW);
+
+ filename = getPath2(music_directory, basename);
+
+ if (FileIsMusic(basename))
+ mus_info = Load_WAV_or_MOD(filename);
+
+ free(filename);
+
+ if (mus_info)
+ {
+ num_music_noconf++;
+ Music_NoConf = checked_realloc(Music_NoConf,
+ num_music_noconf * sizeof(MusicInfo *));
+ Music_NoConf[num_music_noconf - 1] = mus_info;
+ }
+ }
+
+ closedir(dir);
+
+ draw_init_text = FALSE;
+}
+
+int getSoundListSize()
+{
+ return (sound_info->num_file_list_entries +
+ sound_info->num_dynamic_file_list_entries);
+}
+
+int getMusicListSize()
+{
+ return (music_info->num_file_list_entries +
+ music_info->num_dynamic_file_list_entries);
+}
+
+struct FileInfo *getSoundListEntry(int pos)
+{
+ int num_list_entries = sound_info->num_file_list_entries;
+ int list_pos = (pos < num_list_entries ? pos : pos - num_list_entries);
+
+ return (pos < num_list_entries ? &sound_info->file_list[list_pos] :
+ &sound_info->dynamic_file_list[list_pos]);
+}
+
+struct FileInfo *getMusicListEntry(int pos)
+{
+ int num_list_entries = music_info->num_file_list_entries;
+ int list_pos = (pos < num_list_entries ? pos : pos - num_list_entries);
+
+ return (pos < num_list_entries ? &music_info->file_list[list_pos] :
+ &music_info->dynamic_file_list[list_pos]);
+}
+
+static SoundInfo *getSoundInfoEntryFromSoundID(int pos)
+{
+ int num_list_entries = sound_info->num_file_list_entries;
+ int list_pos = (pos < num_list_entries ? pos : pos - num_list_entries);
+ SoundInfo **snd_info =
+ (SoundInfo **)(pos < num_list_entries ? sound_info->artwork_list :
+ sound_info->dynamic_artwork_list);
+
+ return snd_info[list_pos];
+}
+
+static MusicInfo *getMusicInfoEntryFromMusicID(int pos)
+{
+ int num_list_entries = music_info->num_file_list_entries;
+ int list_pos = (pos < num_list_entries ? pos : pos - num_list_entries);
+ MusicInfo **mus_info =
+ (MusicInfo **)(pos < num_list_entries ? music_info->artwork_list :
+ music_info->dynamic_artwork_list);
+
+ return mus_info[list_pos];
+}
+
+int getSoundListPropertyMappingSize()
+{
+ return sound_info->num_property_mapping_entries;
+}
+
+int getMusicListPropertyMappingSize()
+{
+ return music_info->num_property_mapping_entries;
+}
+
+struct PropertyMapping *getSoundListPropertyMapping()