decoder/flac: move code to tag/MixRamp.cxx
This commit is contained in:
parent
6c48aa5fae
commit
8a7ff6a6fd
@ -27,32 +27,11 @@
|
|||||||
#include "tag/Tag.hxx"
|
#include "tag/Tag.hxx"
|
||||||
#include "tag/VorbisComment.hxx"
|
#include "tag/VorbisComment.hxx"
|
||||||
#include "tag/ReplayGain.hxx"
|
#include "tag/ReplayGain.hxx"
|
||||||
|
#include "tag/MixRamp.hxx"
|
||||||
#include "ReplayGainInfo.hxx"
|
#include "ReplayGainInfo.hxx"
|
||||||
#include "util/ASCII.hxx"
|
#include "util/ASCII.hxx"
|
||||||
#include "util/SplitString.hxx"
|
#include "util/SplitString.hxx"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
static const char *
|
|
||||||
vorbis_comment_value(const FLAC__StreamMetadata *block,
|
|
||||||
const char *name)
|
|
||||||
{
|
|
||||||
int offset =
|
|
||||||
FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0,
|
|
||||||
name);
|
|
||||||
if (offset < 0)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
size_t name_length = strlen(name);
|
|
||||||
|
|
||||||
const FLAC__StreamMetadata_VorbisComment_Entry &vc =
|
|
||||||
block->data.vorbis_comment.comments[offset];
|
|
||||||
const char *comment = (const char *)vc.entry;
|
|
||||||
|
|
||||||
/* 1 is for '=' */
|
|
||||||
return comment + name_length + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
flac_parse_replay_gain(ReplayGainInfo &rgi,
|
flac_parse_replay_gain(ReplayGainInfo &rgi,
|
||||||
const FLAC__StreamMetadata_VorbisComment &vc)
|
const FLAC__StreamMetadata_VorbisComment &vc)
|
||||||
@ -70,23 +49,19 @@ flac_parse_replay_gain(ReplayGainInfo &rgi,
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_pure
|
|
||||||
static std::string
|
|
||||||
flac_find_string_comment(const FLAC__StreamMetadata *block, const char *cmnt)
|
|
||||||
{
|
|
||||||
const char *value = vorbis_comment_value(block, cmnt);
|
|
||||||
if (value == nullptr)
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
return std::string(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
MixRampInfo
|
MixRampInfo
|
||||||
flac_parse_mixramp(const FLAC__StreamMetadata *block)
|
flac_parse_mixramp(const FLAC__StreamMetadata *block)
|
||||||
{
|
{
|
||||||
|
const FLAC__StreamMetadata_VorbisComment &vc =
|
||||||
|
block->data.vorbis_comment;
|
||||||
|
|
||||||
MixRampInfo mix_ramp;
|
MixRampInfo mix_ramp;
|
||||||
mix_ramp.SetStart(flac_find_string_comment(block, "mixramp_start"));
|
|
||||||
mix_ramp.SetEnd(flac_find_string_comment(block, "mixramp_end"));
|
const auto *comments = vc.comments;
|
||||||
|
for (FLAC__uint32 i = 0, n = vc.num_comments; i < n; ++i)
|
||||||
|
ParseMixRampVorbis(mix_ramp,
|
||||||
|
(const char *)comments[i].entry);
|
||||||
|
|
||||||
return mix_ramp;
|
return mix_ramp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "MixRamp.hxx"
|
#include "MixRamp.hxx"
|
||||||
|
#include "VorbisComment.hxx"
|
||||||
#include "MixRampInfo.hxx"
|
#include "MixRampInfo.hxx"
|
||||||
#include "util/ASCII.hxx"
|
#include "util/ASCII.hxx"
|
||||||
|
|
||||||
@ -61,3 +62,18 @@ ParseMixRampTag(MixRampInfo &info, const char *name, const char *value)
|
|||||||
|
|
||||||
return ParseMixRampTagTemplate(info, NameValue{name, value});
|
return ParseMixRampTagTemplate(info, NameValue{name, value});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ParseMixRampVorbis(MixRampInfo &info, const char *entry)
|
||||||
|
{
|
||||||
|
struct VorbisCommentEntry {
|
||||||
|
const char *entry;
|
||||||
|
|
||||||
|
gcc_pure
|
||||||
|
const char *operator[](const char *n) const {
|
||||||
|
return vorbis_comment_value(entry, n);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return ParseMixRampTagTemplate(info, VorbisCommentEntry{entry});
|
||||||
|
}
|
||||||
|
@ -27,4 +27,7 @@ class MixRampInfo;
|
|||||||
bool
|
bool
|
||||||
ParseMixRampTag(MixRampInfo &info, const char *name, const char *value);
|
ParseMixRampTag(MixRampInfo &info, const char *name, const char *value);
|
||||||
|
|
||||||
|
bool
|
||||||
|
ParseMixRampVorbis(MixRampInfo &info, const char *entry);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user