Commit 96b76306 authored by Max Kellermann's avatar Max Kellermann

ape: convert to C++

parent dd5ba062
......@@ -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 += \
......
/*
* 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;
}
/*
* 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
/*
* 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;
}
/*
* 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
......
/*
* 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;
}
/*
* 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"
......
......@@ -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>
......
......@@ -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"
}
......
......@@ -27,7 +27,7 @@ extern "C" {
}
#include "tag_handler.h"
#include "tag_ape.h"
#include "ApeTag.hxx"
#include <wavpack/wavpack.h>
#include <glib.h>
......
......@@ -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>
......
......@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment