decoder/sidplay: use class SidDatabase

Remove our own songlength database parser.
This commit is contained in:
Max Kellermann 2014-12-04 21:29:49 +01:00
parent a547d2aaba
commit 9f878b77e9
2 changed files with 11 additions and 53 deletions

View File

@ -542,8 +542,6 @@ AC_ARG_ENABLE(sidplay,
AS_HELP_STRING([--enable-sidplay], AS_HELP_STRING([--enable-sidplay],
[enable C64 SID support via libsidplay2]),, [enable C64 SID support via libsidplay2]),,
enable_sidplay=auto) enable_sidplay=auto)
MPD_DEPENDS([enable_sidplay], [enable_glib],
[Cannot use --enable-sidplay with --disable-glib])
AC_ARG_ENABLE(shine-encoder, AC_ARG_ENABLE(shine-encoder,
AS_HELP_STRING([--enable-shine-encoder], AS_HELP_STRING([--enable-shine-encoder],

View File

@ -33,57 +33,35 @@
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <glib.h>
#include <sidplay/sidplay2.h> #include <sidplay/sidplay2.h>
#include <sidplay/builders/resid.h> #include <sidplay/builders/resid.h>
#include <sidplay/utils/SidTuneMod.h> #include <sidplay/utils/SidTuneMod.h>
#include <sidplay/utils/SidDatabase.h>
#define SUBTUNE_PREFIX "tune_" #define SUBTUNE_PREFIX "tune_"
static constexpr Domain sidplay_domain("sidplay"); static constexpr Domain sidplay_domain("sidplay");
static GKeyFile *songlength_database; static SidDatabase *songlength_database;
static bool all_files_are_containers; static bool all_files_are_containers;
static unsigned default_songlength; static unsigned default_songlength;
static bool filter_setting; static bool filter_setting;
static GKeyFile * static SidDatabase *
sidplay_load_songlength_db(const Path path) sidplay_load_songlength_db(const Path path)
{ {
GError *error = nullptr; SidDatabase *db = new SidDatabase();
gchar *data; if (db->open(path.c_str()) < 0) {
gsize size;
if (!g_file_get_contents(path.c_str(), &data, &size, &error)) {
FormatError(sidplay_domain, FormatError(sidplay_domain,
"unable to read songlengths file %s: %s", "unable to read songlengths file %s: %s",
path.c_str(), error->message); path.c_str(), db->error());
g_error_free(error); delete db;
return nullptr; return nullptr;
} }
/* replace any ; comment characters with # */
for (gsize i = 0; i < size; i++)
if (data[i] == ';')
data[i] = '#';
GKeyFile *db = g_key_file_new();
bool success = g_key_file_load_from_data(db, data, size,
G_KEY_FILE_NONE, &error);
g_free(data);
if (!success) {
FormatError(sidplay_domain,
"unable to parse songlengths file %s: %s",
path.c_str(), error->message);
g_error_free(error);
g_key_file_free(db);
return nullptr;
}
g_key_file_set_list_separator(db, ' ');
return db; return db;
} }
@ -111,8 +89,7 @@ sidplay_init(const config_param &param)
static void static void
sidplay_finish() sidplay_finish()
{ {
if(songlength_database) delete songlength_database;
g_key_file_free(songlength_database);
} }
struct SidplayContainerPath { struct SidplayContainerPath {
@ -171,28 +148,11 @@ get_song_length(const SidplayContainerPath &container)
const unsigned song_num = container.track; const unsigned song_num = container.track;
gsize num_items; const auto length = songlength_database->length(md5sum, song_num);
gchar **values=g_key_file_get_string_list(songlength_database, if (length < 0)
"Database", md5sum, &num_items, nullptr);
if(!values || song_num>num_items) {
g_strfreev(values);
return SignedSongTime::Negative(); return SignedSongTime::Negative();
}
int minutes=strtol(values[song_num-1], nullptr, 10); return SignedSongTime::FromS(length);
if(errno==EINVAL) minutes=0;
int seconds;
char *ptr=strchr(values[song_num-1], ':');
if(ptr) {
seconds=strtol(ptr+1, nullptr, 10);
if(errno==EINVAL) seconds=0;
} else
seconds=0;
g_strfreev(values);
return SignedSongTime::FromS((minutes * 60) + seconds);
} }
static void static void