aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile.am9
-rw-r--r--src/ApeLoader.cxx (renamed from src/ape.c)16
-rw-r--r--src/ApeLoader.hxx (renamed from src/ape.h)17
-rw-r--r--src/ApeReplayGain.cxx (renamed from src/replay_gain_ape.c)58
-rw-r--r--src/ApeReplayGain.hxx (renamed from src/replay_gain_ape.h)8
-rw-r--r--src/ApeTag.cxx (renamed from src/tag_ape.c)47
-rw-r--r--src/ApeTag.hxx (renamed from src/tag_ape.h)6
-rw-r--r--src/DecoderThread.cxx5
-rw-r--r--src/SongUpdate.cxx2
-rw-r--r--src/decoder/WavpackDecoderPlugin.cxx2
-rw-r--r--src/playlist/EmbeddedCuePlaylistPlugin.cxx5
-rw-r--r--test/read_tags.cxx4
12 files changed, 77 insertions, 102 deletions
diff --git a/Makefile.am b/Makefile.am
index 464fa8b92..3ae2545dd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,7 +51,6 @@ src_mpd_LDADD = \
mpd_headers = \
src/check.h \
src/ack.h \
- src/ape.h \
src/audio_format.h \
src/audio_check.h \
src/output_api.h \
@@ -79,13 +78,11 @@ mpd_headers = \
src/aiff.h \
src/replay_gain_config.h \
src/replay_gain_info.h \
- src/replay_gain_ape.h \
src/TimePrint.cxx src/TimePrint.hxx \
src/stats.h \
src/tag.h \
src/tag_internal.h \
src/tag_table.h \
- src/tag_ape.h \
src/Timer.hxx \
src/mpd_error.h
@@ -428,9 +425,9 @@ TAG_LIBS = \
$(ID3TAG_LIBS)
libtag_a_SOURCES =\
- src/ape.c \
- src/replay_gain_ape.c \
- src/tag_ape.c
+ src/ApeLoader.cxx src/ApeLoader.hxx \
+ src/ApeReplayGain.cxx src/ApeReplayGain.hxx \
+ src/ApeTag.cxx src/ApeTag.hxx
if HAVE_ID3TAG
libtag_a_SOURCES += \
diff --git a/src/ape.c b/src/ApeLoader.cxx
index 6257fe6b3..dfbdb4ef3 100644
--- a/src/ape.c
+++ b/src/ApeLoader.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,7 @@
*/
#include "config.h"
-#include "ape.h"
+#include "ApeLoader.hxx"
#include <glib.h>
@@ -37,7 +37,7 @@ struct ape_footer {
};
static bool
-ape_scan_internal(FILE *fp, tag_ape_callback_t callback, void *ctx)
+ape_scan_internal(FILE *fp, ApeTagCallback callback)
{
/* determine if file has an apeV2 tag */
struct ape_footer footer;
@@ -59,7 +59,7 @@ ape_scan_internal(FILE *fp, tag_ape_callback_t callback, void *ctx)
remaining -= sizeof(footer);
assert(remaining > 10);
- char *buffer = g_malloc(remaining);
+ char *buffer = (char *)g_malloc(remaining);
if (fread(buffer, 1, remaining, fp) != remaining) {
g_free(buffer);
return false;
@@ -89,7 +89,7 @@ ape_scan_internal(FILE *fp, tag_ape_callback_t callback, void *ctx)
if (remaining < size)
break;
- if (!callback(flags, key, p, size, ctx))
+ if (!callback(flags, key, p, size))
break;
p += size;
@@ -101,15 +101,15 @@ ape_scan_internal(FILE *fp, tag_ape_callback_t callback, void *ctx)
}
bool
-tag_ape_scan(const char *path_fs, tag_ape_callback_t callback, void *ctx)
+tag_ape_scan(const char *path_fs, ApeTagCallback callback)
{
FILE *fp;
fp = fopen(path_fs, "rb");
- if (fp == NULL)
+ if (fp == nullptr)
return false;
- bool success = ape_scan_internal(fp, callback, ctx);
+ bool success = ape_scan_internal(fp, callback);
fclose(fp);
return success;
}
diff --git a/src/ape.h b/src/ApeLoader.hxx
index c2b271b15..a32ab840c 100644
--- a/src/ape.h
+++ b/src/ApeLoader.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,17 +17,18 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef MPD_APE_H
-#define MPD_APE_H
+#ifndef MPD_APE_LOADER_HXX
+#define MPD_APE_LOADER_HXX
#include "check.h"
-#include <stdbool.h>
+#include <functional>
+
#include <stddef.h>
-typedef bool (*tag_ape_callback_t)(unsigned long flags, const char *key,
- const char *value, size_t value_length,
- void *ctx);
+typedef std::function<bool(unsigned long flags, const char *key,
+ const char *value,
+ size_t value_length)> ApeTagCallback;
/**
* Scans the APE tag values from a file.
@@ -37,6 +38,6 @@ typedef bool (*tag_ape_callback_t)(unsigned long flags, const char *key,
* present
*/
bool
-tag_ape_scan(const char *path_fs, tag_ape_callback_t callback, void *ctx);
+tag_ape_scan(const char *path_fs, ApeTagCallback callback);
#endif
diff --git a/src/replay_gain_ape.c b/src/ApeReplayGain.cxx
index 0b59e3c02..0135d1b61 100644
--- a/src/replay_gain_ape.c
+++ b/src/ApeReplayGain.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,61 +18,61 @@
*/
#include "config.h"
-#include "replay_gain_ape.h"
+#include "ApeReplayGain.hxx"
+#include "ApeLoader.hxx"
#include "replay_gain_info.h"
-#include "ape.h"
#include <glib.h>
#include <string.h>
#include <stdlib.h>
-struct rg_ape_ctx {
- struct replay_gain_info *info;
- bool found;
-};
-
static bool
replay_gain_ape_callback(unsigned long flags, const char *key,
- const char *_value, size_t value_length, void *_ctx)
+ const char *_value, size_t value_length,
+ struct replay_gain_info *info)
{
- struct rg_ape_ctx *ctx = _ctx;
-
/* we only care about utf-8 text tags */
if ((flags & (0x3 << 1)) != 0)
- return true;
+ return false;
char value[16];
if (value_length >= sizeof(value))
- return true;
+ return false;
+
memcpy(value, _value, value_length);
value[value_length] = 0;
if (g_ascii_strcasecmp(key, "replaygain_track_gain") == 0) {
- ctx->info->tuples[REPLAY_GAIN_TRACK].gain = atof(value);
- ctx->found = true;
+ info->tuples[REPLAY_GAIN_TRACK].gain = atof(value);
+ return true;
} else if (g_ascii_strcasecmp(key, "replaygain_album_gain") == 0) {
- ctx->info->tuples[REPLAY_GAIN_ALBUM].gain = atof(value);
- ctx->found = true;
+ info->tuples[REPLAY_GAIN_ALBUM].gain = atof(value);
+ return true;
} else if (g_ascii_strcasecmp(key, "replaygain_track_peak") == 0) {
- ctx->info->tuples[REPLAY_GAIN_TRACK].peak = atof(value);
- ctx->found = true;
+ info->tuples[REPLAY_GAIN_TRACK].peak = atof(value);
+ return true;
} else if (g_ascii_strcasecmp(key, "replaygain_album_peak") == 0) {
- ctx->info->tuples[REPLAY_GAIN_ALBUM].peak = atof(value);
- ctx->found = true;
- }
-
- return true;
+ info->tuples[REPLAY_GAIN_ALBUM].peak = atof(value);
+ return true;
+ } else
+ return false;
}
bool
replay_gain_ape_read(const char *path_fs, struct replay_gain_info *info)
{
- struct rg_ape_ctx ctx = {
- .info = info,
- .found = false,
+ bool found = false;
+
+ auto callback = [info, &found]
+ (unsigned long flags, const char *key,
+ const char *value,
+ size_t value_length) {
+ found |= replay_gain_ape_callback(flags, key,
+ value, value_length,
+ info);
+ return true;
};
- return tag_ape_scan(path_fs, replay_gain_ape_callback, &ctx) &&
- ctx.found;
+ return tag_ape_scan(path_fs, callback) && found;
}
diff --git a/src/replay_gain_ape.h b/src/ApeReplayGain.hxx
index 35760a0aa..4bc34a9d2 100644
--- a/src/replay_gain_ape.h
+++ b/src/ApeReplayGain.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,13 +17,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef MPD_REPLAY_GAIN_APE_H
-#define MPD_REPLAY_GAIN_APE_H
+#ifndef MPD_APE_REPLAY_GAIN_HXX
+#define MPD_APE_REPLAY_GAIN_HXX
#include "check.h"
-#include <stdbool.h>
-
struct replay_gain_info;
bool
diff --git a/src/tag_ape.c b/src/ApeTag.cxx
index 0adc43092..1195ffe5f 100644
--- a/src/tag_ape.c
+++ b/src/ApeTag.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,16 +18,16 @@
*/
#include "config.h"
-#include "tag_ape.h"
+#include "ApeTag.hxx"
+#include "ApeLoader.hxx"
#include "tag.h"
#include "tag_table.h"
#include "tag_handler.h"
-#include "ape.h"
const struct tag_table ape_tags[] = {
{ "album artist", TAG_ALBUM_ARTIST },
{ "year", TAG_DATE },
- { NULL, TAG_NUM_OF_ITEM_TYPES }
+ { nullptr, TAG_NUM_OF_ITEM_TYPES }
};
static enum tag_type
@@ -62,8 +62,8 @@ tag_ape_import_item(unsigned long flags,
const char *end = value + value_length;
while (true) {
/* multiple values are separated by null bytes */
- const char *n = memchr(value, 0, end - value);
- if (n != NULL) {
+ const char *n = (const char *)memchr(value, 0, end - value);
+ if (n != nullptr) {
if (n > value) {
tag_handler_invoke_tag(handler, handler_ctx,
type, value);
@@ -84,34 +84,21 @@ tag_ape_import_item(unsigned long flags,
return recognized;
}
-struct tag_ape_ctx {
- const struct tag_handler *handler;
- void *handler_ctx;
-
- bool recognized;
-};
-
-static bool
-tag_ape_callback(unsigned long flags, const char *key,
- const char *value, size_t value_length, void *_ctx)
-{
- struct tag_ape_ctx *ctx = _ctx;
-
- ctx->recognized |= tag_ape_import_item(flags, key, value, value_length,
- ctx->handler, ctx->handler_ctx);
- return true;
-}
-
bool
tag_ape_scan2(const char *path_fs,
const struct tag_handler *handler, void *handler_ctx)
{
- struct tag_ape_ctx ctx = {
- .handler = handler,
- .handler_ctx = handler_ctx,
- .recognized = false,
+ bool recognized = false;
+
+ auto callback = [handler, handler_ctx, &recognized]
+ (unsigned long flags, const char *key,
+ const char *value,
+ size_t value_length) {
+ recognized |= tag_ape_import_item(flags, key, value,
+ value_length,
+ handler, handler_ctx);
+ return true;
};
- return tag_ape_scan(path_fs, tag_ape_callback, &ctx) &&
- ctx.recognized;
+ return tag_ape_scan(path_fs, callback) && recognized;
}
diff --git a/src/tag_ape.h b/src/ApeTag.hxx
index e2daf088d..3e6655531 100644
--- a/src/tag_ape.h
+++ b/src/ApeTag.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef MPD_TAG_APE_H
-#define MPD_TAG_APE_H
+#ifndef MPD_APE_TAG_HXX
+#define MPD_APE_TAG_HXX
#include "tag_table.h"
diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx
index f69a5fb3c..747319463 100644
--- a/src/DecoderThread.cxx
+++ b/src/DecoderThread.cxx
@@ -32,10 +32,7 @@
#include "InputStream.hxx"
#include "DecoderList.hxx"
#include "util/UriUtil.hxx"
-
-extern "C" {
-#include "replay_gain_ape.h"
-}
+#include "ApeReplayGain.hxx"
#include <glib.h>
diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx
index cfe4741c9..8285cdd99 100644
--- a/src/SongUpdate.cxx
+++ b/src/SongUpdate.cxx
@@ -29,9 +29,9 @@
#include "DecoderPlugin.hxx"
#include "DecoderList.hxx"
#include "TagId3.hxx"
+#include "ApeTag.hxx"
extern "C" {
-#include "tag_ape.h"
#include "tag_handler.h"
}
diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx
index 6776f7193..a1512ee63 100644
--- a/src/decoder/WavpackDecoderPlugin.cxx
+++ b/src/decoder/WavpackDecoderPlugin.cxx
@@ -27,7 +27,7 @@ extern "C" {
}
#include "tag_handler.h"
-#include "tag_ape.h"
+#include "ApeTag.hxx"
#include <wavpack/wavpack.h>
#include <glib.h>
diff --git a/src/playlist/EmbeddedCuePlaylistPlugin.cxx b/src/playlist/EmbeddedCuePlaylistPlugin.cxx
index 8f8d87153..c45e1d718 100644
--- a/src/playlist/EmbeddedCuePlaylistPlugin.cxx
+++ b/src/playlist/EmbeddedCuePlaylistPlugin.cxx
@@ -29,14 +29,11 @@
#include "tag.h"
#include "tag_handler.h"
#include "TagId3.hxx"
+#include "ApeTag.hxx"
#include "Song.hxx"
#include "TagFile.hxx"
#include "cue/CueParser.hxx"
-extern "C" {
-#include "tag_ape.h"
-}
-
#include <glib.h>
#include <assert.h>
#include <string.h>
diff --git a/test/read_tags.cxx b/test/read_tags.cxx
index 5998bad21..eda2604f6 100644
--- a/test/read_tags.cxx
+++ b/test/read_tags.cxx
@@ -24,11 +24,9 @@
#include "InputInit.hxx"
#include "InputStream.hxx"
#include "audio_format.h"
-extern "C" {
-#include "tag_ape.h"
-}
#include "tag_handler.h"
#include "TagId3.hxx"
+#include "ApeTag.hxx"
#include <glib.h>