tag/ReplayGain: move code to template function
This commit is contained in:
parent
d1e31261fe
commit
9f4fc8ad33
@ -25,24 +25,46 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static bool
|
||||||
|
ParseReplayGainTagTemplate(ReplayGainInfo &info, const T t)
|
||||||
|
{
|
||||||
|
const char *value;
|
||||||
|
|
||||||
|
if ((value = t["replaygain_track_gain"]) != nullptr) {
|
||||||
|
info.tuples[REPLAY_GAIN_TRACK].gain = atof(value);
|
||||||
|
return true;
|
||||||
|
} else if ((value = t["replaygain_album_gain"]) != nullptr) {
|
||||||
|
info.tuples[REPLAY_GAIN_ALBUM].gain = atof(value);
|
||||||
|
return true;
|
||||||
|
} else if ((value = t["replaygain_track_peak"]) != nullptr) {
|
||||||
|
info.tuples[REPLAY_GAIN_TRACK].peak = atof(value);
|
||||||
|
return true;
|
||||||
|
} else if ((value = t["replaygain_album_peak"]) != nullptr) {
|
||||||
|
info.tuples[REPLAY_GAIN_ALBUM].peak = atof(value);
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ParseReplayGainTag(ReplayGainInfo &info, const char *name, const char *value)
|
ParseReplayGainTag(ReplayGainInfo &info, const char *name, const char *value)
|
||||||
{
|
{
|
||||||
assert(name != nullptr);
|
assert(name != nullptr);
|
||||||
assert(value != nullptr);
|
assert(value != nullptr);
|
||||||
|
|
||||||
if (StringEqualsCaseASCII(name, "replaygain_track_gain")) {
|
struct NameValue {
|
||||||
info.tuples[REPLAY_GAIN_TRACK].gain = atof(value);
|
const char *name;
|
||||||
return true;
|
const char *value;
|
||||||
} else if (StringEqualsCaseASCII(name, "replaygain_album_gain")) {
|
|
||||||
info.tuples[REPLAY_GAIN_ALBUM].gain = atof(value);
|
gcc_pure
|
||||||
return true;
|
const char *operator[](const char *n) const {
|
||||||
} else if (StringEqualsCaseASCII(name, "replaygain_track_peak")) {
|
return StringEqualsCaseASCII(name, n)
|
||||||
info.tuples[REPLAY_GAIN_TRACK].peak = atof(value);
|
? value
|
||||||
return true;
|
: nullptr;
|
||||||
} else if (StringEqualsCaseASCII(name, "replaygain_album_peak")) {
|
}
|
||||||
info.tuples[REPLAY_GAIN_ALBUM].peak = atof(value);
|
};
|
||||||
return true;
|
|
||||||
} else
|
return ParseReplayGainTagTemplate(info, NameValue{name, value});
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user