decoder/sidplay: move global variables to struct SidplayGlobal
This commit is contained in:
parent
b8a64771c0
commit
bed8a0e040
@ -36,6 +36,7 @@
|
|||||||
#include "util/AllocatedString.hxx"
|
#include "util/AllocatedString.hxx"
|
||||||
#include "util/CharUtil.hxx"
|
#include "util/CharUtil.hxx"
|
||||||
#include "util/ByteOrder.hxx"
|
#include "util/ByteOrder.hxx"
|
||||||
|
#include "util/Manual.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#ifdef HAVE_SIDPLAYFP
|
#ifdef HAVE_SIDPLAYFP
|
||||||
@ -67,17 +68,35 @@
|
|||||||
|
|
||||||
static constexpr Domain sidplay_domain("sidplay");
|
static constexpr Domain sidplay_domain("sidplay");
|
||||||
|
|
||||||
static SidDatabase *songlength_database;
|
struct SidplayGlobal {
|
||||||
|
SidDatabase *songlength_database;
|
||||||
|
|
||||||
static bool all_files_are_containers;
|
bool all_files_are_containers;
|
||||||
static unsigned default_songlength;
|
unsigned default_songlength;
|
||||||
static std::string default_genre;
|
std::string default_genre;
|
||||||
|
|
||||||
static bool filter_setting;
|
bool filter_setting;
|
||||||
|
|
||||||
|
#ifdef HAVE_SIDPLAYFP
|
||||||
|
uint8_t *kernal = nullptr, *basic = nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
explicit SidplayGlobal(const ConfigBlock &block);
|
||||||
|
|
||||||
|
~SidplayGlobal() noexcept {
|
||||||
|
delete songlength_database;
|
||||||
|
|
||||||
|
#ifdef HAVE_SIDPLAYFP
|
||||||
|
delete[] basic;
|
||||||
|
delete[] kernal;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static SidplayGlobal *sidplay_global;
|
||||||
|
|
||||||
#ifdef HAVE_SIDPLAYFP
|
#ifdef HAVE_SIDPLAYFP
|
||||||
static constexpr unsigned rom_size = 8192;
|
static constexpr unsigned rom_size = 8192;
|
||||||
static uint8_t *kernal, *basic = nullptr;
|
|
||||||
|
|
||||||
static void loadRom(const Path rom_path, uint8_t *dump)
|
static void loadRom(const Path rom_path, uint8_t *dump)
|
||||||
{
|
{
|
||||||
@ -110,8 +129,8 @@ sidplay_load_songlength_db(const Path path) noexcept
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
inline
|
||||||
sidplay_init(const ConfigBlock &block)
|
SidplayGlobal::SidplayGlobal(const ConfigBlock &block)
|
||||||
{
|
{
|
||||||
/* read the songlengths database file */
|
/* read the songlengths database file */
|
||||||
const auto database_path = block.GetPath("songlength_database");
|
const auto database_path = block.GetPath("songlength_database");
|
||||||
@ -144,19 +163,19 @@ sidplay_init(const ConfigBlock &block)
|
|||||||
loadRom(basic_path, basic);
|
loadRom(basic_path, basic);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sidplay_init(const ConfigBlock &block)
|
||||||
|
{
|
||||||
|
sidplay_global = new SidplayGlobal(block);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sidplay_finish() noexcept
|
sidplay_finish() noexcept
|
||||||
{
|
{
|
||||||
delete songlength_database;
|
delete sidplay_global;
|
||||||
|
|
||||||
#ifdef HAVE_SIDPLAYFP
|
|
||||||
delete[] basic;
|
|
||||||
delete[] kernal;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SidplayContainerPath {
|
struct SidplayContainerPath {
|
||||||
@ -207,10 +226,10 @@ get_song_length(T &tune) noexcept
|
|||||||
{
|
{
|
||||||
assert(tune.getStatus());
|
assert(tune.getStatus());
|
||||||
|
|
||||||
if (songlength_database == nullptr)
|
if (sidplay_global->songlength_database == nullptr)
|
||||||
return SignedSongTime::Negative();
|
return SignedSongTime::Negative();
|
||||||
|
|
||||||
const auto length = songlength_database->length(tune);
|
const auto length = sidplay_global->songlength_database->length(tune);
|
||||||
if (length < 0)
|
if (length < 0)
|
||||||
return SignedSongTime::Negative();
|
return SignedSongTime::Negative();
|
||||||
|
|
||||||
@ -245,15 +264,15 @@ sidplay_file_decode(DecoderClient &client, Path path_fs)
|
|||||||
tune.selectSong(song_num);
|
tune.selectSong(song_num);
|
||||||
|
|
||||||
auto duration = get_song_length(tune);
|
auto duration = get_song_length(tune);
|
||||||
if (duration.IsNegative() && default_songlength > 0)
|
if (duration.IsNegative() && sidplay_global->default_songlength > 0)
|
||||||
duration = SongTime::FromS(default_songlength);
|
duration = SongTime::FromS(sidplay_global->default_songlength);
|
||||||
|
|
||||||
/* initialize the player */
|
/* initialize the player */
|
||||||
|
|
||||||
#ifdef HAVE_SIDPLAYFP
|
#ifdef HAVE_SIDPLAYFP
|
||||||
sidplayfp player;
|
sidplayfp player;
|
||||||
|
|
||||||
player.setRoms(kernal, basic, nullptr);
|
player.setRoms(sidplay_global->kernal, sidplay_global->basic, nullptr);
|
||||||
#else
|
#else
|
||||||
sidplay2 player;
|
sidplay2 player;
|
||||||
#endif
|
#endif
|
||||||
@ -296,7 +315,7 @@ sidplay_file_decode(DecoderClient &client, Path path_fs)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
builder.filter(filter_setting);
|
builder.filter(sidplay_global->filter_setting);
|
||||||
#ifdef HAVE_SIDPLAYFP
|
#ifdef HAVE_SIDPLAYFP
|
||||||
if (!builder.getStatus()) {
|
if (!builder.getStatus()) {
|
||||||
FormatWarning(sidplay_domain,
|
FormatWarning(sidplay_domain,
|
||||||
@ -529,8 +548,9 @@ ScanSidTuneInfo(const SidTuneInfo &info, unsigned track, unsigned n_tracks,
|
|||||||
handler.OnTag(TAG_ARTIST, artist.c_str());
|
handler.OnTag(TAG_ARTIST, artist.c_str());
|
||||||
|
|
||||||
/* genre */
|
/* genre */
|
||||||
if (!default_genre.empty())
|
if (!sidplay_global->default_genre.empty())
|
||||||
handler.OnTag(TAG_GENRE, default_genre.c_str());
|
handler.OnTag(TAG_GENRE,
|
||||||
|
sidplay_global->default_genre.c_str());
|
||||||
|
|
||||||
/* date */
|
/* date */
|
||||||
const auto date = GetDateString(info);
|
const auto date = GetDateString(info);
|
||||||
@ -598,7 +618,7 @@ sidplay_container_scan(Path path_fs)
|
|||||||
|
|
||||||
/* Don't treat sids containing a single tune
|
/* Don't treat sids containing a single tune
|
||||||
as containers */
|
as containers */
|
||||||
if(!all_files_are_containers && n_tracks < 2)
|
if (!sidplay_global->all_files_are_containers && n_tracks < 2)
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
TagBuilder tag_builder;
|
TagBuilder tag_builder;
|
||||||
|
Loading…
Reference in New Issue
Block a user