ape: convert to C++
This commit is contained in:
parent
dd5ba062cc
commit
96b763067e
@ -51,7 +51,6 @@ src_mpd_LDADD = \
|
|||||||
mpd_headers = \
|
mpd_headers = \
|
||||||
src/check.h \
|
src/check.h \
|
||||||
src/ack.h \
|
src/ack.h \
|
||||||
src/ape.h \
|
|
||||||
src/audio_format.h \
|
src/audio_format.h \
|
||||||
src/audio_check.h \
|
src/audio_check.h \
|
||||||
src/output_api.h \
|
src/output_api.h \
|
||||||
@ -79,13 +78,11 @@ mpd_headers = \
|
|||||||
src/aiff.h \
|
src/aiff.h \
|
||||||
src/replay_gain_config.h \
|
src/replay_gain_config.h \
|
||||||
src/replay_gain_info.h \
|
src/replay_gain_info.h \
|
||||||
src/replay_gain_ape.h \
|
|
||||||
src/TimePrint.cxx src/TimePrint.hxx \
|
src/TimePrint.cxx src/TimePrint.hxx \
|
||||||
src/stats.h \
|
src/stats.h \
|
||||||
src/tag.h \
|
src/tag.h \
|
||||||
src/tag_internal.h \
|
src/tag_internal.h \
|
||||||
src/tag_table.h \
|
src/tag_table.h \
|
||||||
src/tag_ape.h \
|
|
||||||
src/Timer.hxx \
|
src/Timer.hxx \
|
||||||
src/mpd_error.h
|
src/mpd_error.h
|
||||||
|
|
||||||
@ -428,9 +425,9 @@ TAG_LIBS = \
|
|||||||
$(ID3TAG_LIBS)
|
$(ID3TAG_LIBS)
|
||||||
|
|
||||||
libtag_a_SOURCES =\
|
libtag_a_SOURCES =\
|
||||||
src/ape.c \
|
src/ApeLoader.cxx src/ApeLoader.hxx \
|
||||||
src/replay_gain_ape.c \
|
src/ApeReplayGain.cxx src/ApeReplayGain.hxx \
|
||||||
src/tag_ape.c
|
src/ApeTag.cxx src/ApeTag.hxx
|
||||||
|
|
||||||
if HAVE_ID3TAG
|
if HAVE_ID3TAG
|
||||||
libtag_a_SOURCES += \
|
libtag_a_SOURCES += \
|
||||||
|
@ -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
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ape.h"
|
#include "ApeLoader.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ struct ape_footer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static bool
|
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 */
|
/* determine if file has an apeV2 tag */
|
||||||
struct ape_footer footer;
|
struct ape_footer footer;
|
||||||
@ -59,7 +59,7 @@ ape_scan_internal(FILE *fp, tag_ape_callback_t callback, void *ctx)
|
|||||||
remaining -= sizeof(footer);
|
remaining -= sizeof(footer);
|
||||||
assert(remaining > 10);
|
assert(remaining > 10);
|
||||||
|
|
||||||
char *buffer = g_malloc(remaining);
|
char *buffer = (char *)g_malloc(remaining);
|
||||||
if (fread(buffer, 1, remaining, fp) != remaining) {
|
if (fread(buffer, 1, remaining, fp) != remaining) {
|
||||||
g_free(buffer);
|
g_free(buffer);
|
||||||
return false;
|
return false;
|
||||||
@ -89,7 +89,7 @@ ape_scan_internal(FILE *fp, tag_ape_callback_t callback, void *ctx)
|
|||||||
if (remaining < size)
|
if (remaining < size)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!callback(flags, key, p, size, ctx))
|
if (!callback(flags, key, p, size))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
p += size;
|
p += size;
|
||||||
@ -101,15 +101,15 @@ ape_scan_internal(FILE *fp, tag_ape_callback_t callback, void *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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;
|
FILE *fp;
|
||||||
|
|
||||||
fp = fopen(path_fs, "rb");
|
fp = fopen(path_fs, "rb");
|
||||||
if (fp == NULL)
|
if (fp == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool success = ape_scan_internal(fp, callback, ctx);
|
bool success = ape_scan_internal(fp, callback);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
@ -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
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MPD_APE_H
|
#ifndef MPD_APE_LOADER_HXX
|
||||||
#define MPD_APE_H
|
#define MPD_APE_LOADER_HXX
|
||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <functional>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef bool (*tag_ape_callback_t)(unsigned long flags, const char *key,
|
typedef std::function<bool(unsigned long flags, const char *key,
|
||||||
const char *value, size_t value_length,
|
const char *value,
|
||||||
void *ctx);
|
size_t value_length)> ApeTagCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scans the APE tag values from a file.
|
* 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
|
* present
|
||||||
*/
|
*/
|
||||||
bool
|
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
|
#endif
|
@ -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
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -18,61 +18,61 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "replay_gain_ape.h"
|
#include "ApeReplayGain.hxx"
|
||||||
|
#include "ApeLoader.hxx"
|
||||||
#include "replay_gain_info.h"
|
#include "replay_gain_info.h"
|
||||||
#include "ape.h"
|
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
struct rg_ape_ctx {
|
|
||||||
struct replay_gain_info *info;
|
|
||||||
bool found;
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
replay_gain_ape_callback(unsigned long flags, const char *key,
|
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 */
|
/* we only care about utf-8 text tags */
|
||||||
if ((flags & (0x3 << 1)) != 0)
|
if ((flags & (0x3 << 1)) != 0)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
char value[16];
|
char value[16];
|
||||||
if (value_length >= sizeof(value))
|
if (value_length >= sizeof(value))
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
memcpy(value, _value, value_length);
|
memcpy(value, _value, value_length);
|
||||||
value[value_length] = 0;
|
value[value_length] = 0;
|
||||||
|
|
||||||
if (g_ascii_strcasecmp(key, "replaygain_track_gain") == 0) {
|
if (g_ascii_strcasecmp(key, "replaygain_track_gain") == 0) {
|
||||||
ctx->info->tuples[REPLAY_GAIN_TRACK].gain = atof(value);
|
info->tuples[REPLAY_GAIN_TRACK].gain = atof(value);
|
||||||
ctx->found = true;
|
return true;
|
||||||
} else if (g_ascii_strcasecmp(key, "replaygain_album_gain") == 0) {
|
} else if (g_ascii_strcasecmp(key, "replaygain_album_gain") == 0) {
|
||||||
ctx->info->tuples[REPLAY_GAIN_ALBUM].gain = atof(value);
|
info->tuples[REPLAY_GAIN_ALBUM].gain = atof(value);
|
||||||
ctx->found = true;
|
return true;
|
||||||
} else if (g_ascii_strcasecmp(key, "replaygain_track_peak") == 0) {
|
} else if (g_ascii_strcasecmp(key, "replaygain_track_peak") == 0) {
|
||||||
ctx->info->tuples[REPLAY_GAIN_TRACK].peak = atof(value);
|
info->tuples[REPLAY_GAIN_TRACK].peak = atof(value);
|
||||||
ctx->found = true;
|
return true;
|
||||||
} else if (g_ascii_strcasecmp(key, "replaygain_album_peak") == 0) {
|
} else if (g_ascii_strcasecmp(key, "replaygain_album_peak") == 0) {
|
||||||
ctx->info->tuples[REPLAY_GAIN_ALBUM].peak = atof(value);
|
info->tuples[REPLAY_GAIN_ALBUM].peak = atof(value);
|
||||||
ctx->found = true;
|
return true;
|
||||||
}
|
} else
|
||||||
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
replay_gain_ape_read(const char *path_fs, struct replay_gain_info *info)
|
replay_gain_ape_read(const char *path_fs, struct replay_gain_info *info)
|
||||||
{
|
{
|
||||||
struct rg_ape_ctx ctx = {
|
bool found = false;
|
||||||
.info = info,
|
|
||||||
.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) &&
|
return tag_ape_scan(path_fs, callback) && found;
|
||||||
ctx.found;
|
|
||||||
}
|
}
|
@ -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
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MPD_REPLAY_GAIN_APE_H
|
#ifndef MPD_APE_REPLAY_GAIN_HXX
|
||||||
#define MPD_REPLAY_GAIN_APE_H
|
#define MPD_APE_REPLAY_GAIN_HXX
|
||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
struct replay_gain_info;
|
struct replay_gain_info;
|
||||||
|
|
||||||
bool
|
bool
|
@ -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
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -18,16 +18,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "tag_ape.h"
|
#include "ApeTag.hxx"
|
||||||
|
#include "ApeLoader.hxx"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "tag_table.h"
|
#include "tag_table.h"
|
||||||
#include "tag_handler.h"
|
#include "tag_handler.h"
|
||||||
#include "ape.h"
|
|
||||||
|
|
||||||
const struct tag_table ape_tags[] = {
|
const struct tag_table ape_tags[] = {
|
||||||
{ "album artist", TAG_ALBUM_ARTIST },
|
{ "album artist", TAG_ALBUM_ARTIST },
|
||||||
{ "year", TAG_DATE },
|
{ "year", TAG_DATE },
|
||||||
{ NULL, TAG_NUM_OF_ITEM_TYPES }
|
{ nullptr, TAG_NUM_OF_ITEM_TYPES }
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum tag_type
|
static enum tag_type
|
||||||
@ -62,8 +62,8 @@ tag_ape_import_item(unsigned long flags,
|
|||||||
const char *end = value + value_length;
|
const char *end = value + value_length;
|
||||||
while (true) {
|
while (true) {
|
||||||
/* multiple values are separated by null bytes */
|
/* multiple values are separated by null bytes */
|
||||||
const char *n = memchr(value, 0, end - value);
|
const char *n = (const char *)memchr(value, 0, end - value);
|
||||||
if (n != NULL) {
|
if (n != nullptr) {
|
||||||
if (n > value) {
|
if (n > value) {
|
||||||
tag_handler_invoke_tag(handler, handler_ctx,
|
tag_handler_invoke_tag(handler, handler_ctx,
|
||||||
type, value);
|
type, value);
|
||||||
@ -84,34 +84,21 @@ tag_ape_import_item(unsigned long flags,
|
|||||||
return recognized;
|
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
|
bool
|
||||||
tag_ape_scan2(const char *path_fs,
|
tag_ape_scan2(const char *path_fs,
|
||||||
const struct tag_handler *handler, void *handler_ctx)
|
const struct tag_handler *handler, void *handler_ctx)
|
||||||
{
|
{
|
||||||
struct tag_ape_ctx ctx = {
|
bool recognized = false;
|
||||||
.handler = handler,
|
|
||||||
.handler_ctx = handler_ctx,
|
auto callback = [handler, handler_ctx, &recognized]
|
||||||
.recognized = false,
|
(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) &&
|
return tag_ape_scan(path_fs, callback) && recognized;
|
||||||
ctx.recognized;
|
|
||||||
}
|
}
|
@ -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
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MPD_TAG_APE_H
|
#ifndef MPD_APE_TAG_HXX
|
||||||
#define MPD_TAG_APE_H
|
#define MPD_APE_TAG_HXX
|
||||||
|
|
||||||
#include "tag_table.h"
|
#include "tag_table.h"
|
||||||
|
|
@ -32,10 +32,7 @@
|
|||||||
#include "InputStream.hxx"
|
#include "InputStream.hxx"
|
||||||
#include "DecoderList.hxx"
|
#include "DecoderList.hxx"
|
||||||
#include "util/UriUtil.hxx"
|
#include "util/UriUtil.hxx"
|
||||||
|
#include "ApeReplayGain.hxx"
|
||||||
extern "C" {
|
|
||||||
#include "replay_gain_ape.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@
|
|||||||
#include "DecoderPlugin.hxx"
|
#include "DecoderPlugin.hxx"
|
||||||
#include "DecoderList.hxx"
|
#include "DecoderList.hxx"
|
||||||
#include "TagId3.hxx"
|
#include "TagId3.hxx"
|
||||||
|
#include "ApeTag.hxx"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "tag_ape.h"
|
|
||||||
#include "tag_handler.h"
|
#include "tag_handler.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include "tag_handler.h"
|
#include "tag_handler.h"
|
||||||
#include "tag_ape.h"
|
#include "ApeTag.hxx"
|
||||||
|
|
||||||
#include <wavpack/wavpack.h>
|
#include <wavpack/wavpack.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
@ -29,14 +29,11 @@
|
|||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "tag_handler.h"
|
#include "tag_handler.h"
|
||||||
#include "TagId3.hxx"
|
#include "TagId3.hxx"
|
||||||
|
#include "ApeTag.hxx"
|
||||||
#include "Song.hxx"
|
#include "Song.hxx"
|
||||||
#include "TagFile.hxx"
|
#include "TagFile.hxx"
|
||||||
#include "cue/CueParser.hxx"
|
#include "cue/CueParser.hxx"
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "tag_ape.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -24,11 +24,9 @@
|
|||||||
#include "InputInit.hxx"
|
#include "InputInit.hxx"
|
||||||
#include "InputStream.hxx"
|
#include "InputStream.hxx"
|
||||||
#include "audio_format.h"
|
#include "audio_format.h"
|
||||||
extern "C" {
|
|
||||||
#include "tag_ape.h"
|
|
||||||
}
|
|
||||||
#include "tag_handler.h"
|
#include "tag_handler.h"
|
||||||
#include "TagId3.hxx"
|
#include "TagId3.hxx"
|
||||||
|
#include "ApeTag.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user