aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/plugins
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-12-04 21:29:49 +0100
committerMax Kellermann <max@duempel.org>2014-12-04 21:40:38 +0100
commit51f349d504df664740d3626a153904d6618c63ed (patch)
tree2bf213c34ad7fd96344cb8c4744979635f47cb83 /src/decoder/plugins
parent4f201d1e8515b336cb38905935baf52d0ee08d17 (diff)
downloadmpd-51f349d504df664740d3626a153904d6618c63ed.tar.gz
mpd-51f349d504df664740d3626a153904d6618c63ed.tar.xz
mpd-51f349d504df664740d3626a153904d6618c63ed.zip
decoder/sidplay: use class SidDatabase
Remove our own songlength database parser.
Diffstat (limited to 'src/decoder/plugins')
-rw-r--r--src/decoder/plugins/SidplayDecoderPlugin.cxx62
1 files changed, 11 insertions, 51 deletions
diff --git a/src/decoder/plugins/SidplayDecoderPlugin.cxx b/src/decoder/plugins/SidplayDecoderPlugin.cxx
index 4e92e17f6..b4dca3629 100644
--- a/src/decoder/plugins/SidplayDecoderPlugin.cxx
+++ b/src/decoder/plugins/SidplayDecoderPlugin.cxx
@@ -33,57 +33,35 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <glib.h>
#include <sidplay/sidplay2.h>
#include <sidplay/builders/resid.h>
#include <sidplay/utils/SidTuneMod.h>
+#include <sidplay/utils/SidDatabase.h>
#define SUBTUNE_PREFIX "tune_"
static constexpr Domain sidplay_domain("sidplay");
-static GKeyFile *songlength_database;
+static SidDatabase *songlength_database;
static bool all_files_are_containers;
static unsigned default_songlength;
static bool filter_setting;
-static GKeyFile *
+static SidDatabase *
sidplay_load_songlength_db(const Path path)
{
- GError *error = nullptr;
- gchar *data;
- gsize size;
-
- if (!g_file_get_contents(path.c_str(), &data, &size, &error)) {
+ SidDatabase *db = new SidDatabase();
+ if (db->open(path.c_str()) < 0) {
FormatError(sidplay_domain,
"unable to read songlengths file %s: %s",
- path.c_str(), error->message);
- g_error_free(error);
- 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);
+ path.c_str(), db->error());
+ delete db;
return nullptr;
}
- g_key_file_set_list_separator(db, ' ');
return db;
}
@@ -111,8 +89,7 @@ sidplay_init(const config_param &param)
static void
sidplay_finish()
{
- if(songlength_database)
- g_key_file_free(songlength_database);
+ delete songlength_database;
}
struct SidplayContainerPath {
@@ -171,28 +148,11 @@ get_song_length(const SidplayContainerPath &container)
const unsigned song_num = container.track;
- gsize num_items;
- gchar **values=g_key_file_get_string_list(songlength_database,
- "Database", md5sum, &num_items, nullptr);
- if(!values || song_num>num_items) {
- g_strfreev(values);
+ const auto length = songlength_database->length(md5sum, song_num);
+ if (length < 0)
return SignedSongTime::Negative();
- }
-
- int minutes=strtol(values[song_num-1], nullptr, 10);
- 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);
+ return SignedSongTime::FromS(length);
}
static void