Example #1
0
void songs_uninit()
{
    songs_stop_all();
#ifdef USE_SDLMIXER
    jukebox_unload();
#endif
    if (BIMSongs != NULL)
        d_free(BIMSongs);
    Songs_initialized = 0;
}
Example #2
0
/* Loads music file names from a given directory or M3U playlist */
void jukebox_load()
{
	jukebox_unload();

	// Check if it's an M3U file
	auto &cfgpath = CGameCfg.CMLevelMusicPath;
	size_t musiclen = strlen(cfgpath.data());
	if (musiclen > 4 && !d_stricmp(&cfgpath[musiclen - 4], ".m3u"))
		read_m3u();
	else	// a directory
	{
		class PHYSFS_path_deleter
		{
		public:
			void operator()(const char *const p) const noexcept
			{
				PHYSFS_removeFromSearchPath(p);
			}
		};
		std::unique_ptr<const char, PHYSFS_path_deleter> new_path;
		const char *sep = PHYSFS_getDirSeparator();
		size_t seplen = strlen(sep);

		// stick a separator on the end if necessary.
		if (musiclen >= seplen)
		{
			auto p = &cfgpath[musiclen - seplen];
			if (strcmp(p, sep))
				cfgpath.copy_if(musiclen, sep, seplen);
		}

		const auto p = cfgpath.data();
		// Read directory using PhysicsFS
		if (PHYSFS_isDirectory(p))	// find files in relative directory
			JukeboxSongs.list.reset(PHYSFSX_findFiles(p, jukebox_exts));
		else
		{
			if (PHYSFSX_isNewPath(p))
				new_path.reset(p);
			PHYSFS_addToSearchPath(p, 0);

			// as mountpoints are no option (yet), make sure only files originating from GameCfg.CMLevelMusicPath are aded to the list.
			JukeboxSongs.list.reset(PHYSFSX_findabsoluteFiles("", p, jukebox_exts));
		}

		if (!JukeboxSongs.list)
		{
			return;
		}
		JukeboxSongs.num_songs = std::distance(JukeboxSongs.list.begin(), JukeboxSongs.list.end());
	}

	if (JukeboxSongs.num_songs)
	{
		con_printf(CON_DEBUG,"Jukebox: %d music file(s) found in %s", JukeboxSongs.num_songs, cfgpath.data());
		if (CGameCfg.CMLevelMusicTrack[1] != JukeboxSongs.num_songs)
		{
			CGameCfg.CMLevelMusicTrack[1] = JukeboxSongs.num_songs;
			CGameCfg.CMLevelMusicTrack[0] = 0; // number of songs changed so start from beginning.
		}
	}
	else
	{
		CGameCfg.CMLevelMusicTrack[0] = -1;
		CGameCfg.CMLevelMusicTrack[1] = -1;
		con_puts(CON_DEBUG,"Jukebox music could not be found!");
	}
}