+static void InitGameModeMusicInfo()
+{
+ struct PropertyMapping *property_mapping = getMusicListPropertyMapping();
+ int num_property_mappings = getMusicListPropertyMappingSize();
+ int default_levelset_music = -1;
+ int i;
+
+ /* set values to -1 to identify later as "uninitialized" values */
+ for (i = 0; i < MAX_LEVELS; i++)
+ levelset.music[i] = -1;
+ for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
+ menu.music[i] = -1;
+
+ /* initialize gamemode/music mapping from static configuration */
+ for (i = 0; gamemode_to_music[i].music > -1; i++)
+ {
+ int gamemode = gamemode_to_music[i].gamemode;
+ int music = gamemode_to_music[i].music;
+
+#if 0
+ printf("::: gamemode == %d, music == %d\n", gamemode, music);
+#endif
+
+ if (gamemode < 0)
+ gamemode = GAME_MODE_DEFAULT;
+
+ menu.music[gamemode] = music;
+ }
+
+ /* initialize gamemode/music mapping from dynamic configuration */
+ for (i = 0; i < num_property_mappings; i++)
+ {
+ int prefix = property_mapping[i].base_index;
+ int gamemode = property_mapping[i].ext1_index;
+ int level = property_mapping[i].ext2_index;
+ int music = property_mapping[i].artwork_index;
+
+#if 0
+ printf("::: prefix == %d, gamemode == %d, level == %d, music == %d\n",
+ prefix, gamemode, level, music);
+#endif
+
+ if (prefix < 0 || prefix >= NUM_MUSIC_PREFIXES)
+ continue;
+
+ if (gamemode < 0)
+ gamemode = GAME_MODE_DEFAULT;
+
+ /* level specific music only allowed for in-game music */
+ if (level != -1 && gamemode == GAME_MODE_DEFAULT)
+ gamemode = GAME_MODE_PLAYING;
+
+ if (level == -1)
+ {
+ level = 0;
+ default_levelset_music = music;
+ }
+
+ if (gamemode == GAME_MODE_PLAYING || gamemode == GAME_MODE_DEFAULT)
+ levelset.music[level] = music;
+ if (gamemode != GAME_MODE_PLAYING)
+ menu.music[gamemode] = music;
+ }
+
+ /* now set all '-1' values to menu specific default values */
+ /* (undefined values of "levelset.music[]" might stay at "-1" to
+ allow dynamic selection of music files from music directory!) */
+ for (i = 0; i < MAX_LEVELS; i++)
+ if (levelset.music[i] == -1)
+ levelset.music[i] = default_levelset_music;
+ for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
+ if (menu.music[i] == -1)
+ menu.music[i] = menu.music[GAME_MODE_DEFAULT];
+
+#if 0
+ /* TEST ONLY */
+ for (i = 0; i < MAX_LEVELS; i++)
+ if (levelset.music[i] != -1)
+ printf("::: levelset.music[%d] == %d\n", i, levelset.music[i]);
+ for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
+ if (menu.music[i] != -1)
+ printf("::: menu.music[%d] == %d\n", i, menu.music[i]);
+#endif
+}
+
+static void set_music_parameters(int music, char **parameter_raw)
+{
+ int parameter[NUM_MUS_ARGS];
+ int i;
+
+ /* get integer values from string parameters */
+ for (i = 0; i < NUM_MUS_ARGS; i++)
+ parameter[i] =
+ get_parameter_value(music_config_suffix[i].token, parameter_raw[i],
+ music_config_suffix[i].type);
+
+ /* explicit loop mode setting in configuration overrides default value */
+ if (parameter[MUS_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
+ music_info[music].loop = parameter[MUS_ARG_MODE_LOOP];
+}
+
+static void InitMusicInfo()
+{
+ int num_music = getMusicListSize();
+ int i, j;
+
+ if (music_info != NULL)
+ free(music_info);
+
+ music_info = checked_calloc(num_music * sizeof(struct MusicInfo));
+
+ for (i = 0; i < num_music; i++)
+ {
+ struct FileInfo *music = getMusicListEntry(i);
+ int len_music_text = strlen(music->token);
+
+ music_info[i].loop = TRUE; /* default: play music in loop mode */
+
+ /* determine all loop music */
+
+ for (j = 0; music_prefix_info[j].prefix; j++)
+ {
+ int len_prefix_text = strlen(music_prefix_info[j].prefix);
+
+ if (len_prefix_text < len_music_text &&
+ strncmp(music->token,
+ music_prefix_info[j].prefix, len_prefix_text) == 0)
+ {
+ music_info[i].loop = music_prefix_info[j].is_loop_music;
+
+ break;
+ }
+ }
+
+ set_music_parameters(i, music->parameter);
+ }
+}
+