ReplayGainInfo: don't use array in struct ReplayGainInfo
Declare two named elements. An enum should not be used as an array index, as this is error prone.
This commit is contained in:
parent
1261327fa6
commit
25e58df5e0
|
@ -49,26 +49,21 @@ struct ReplayGainTuple {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ReplayGainInfo {
|
struct ReplayGainInfo {
|
||||||
ReplayGainTuple tuples[2];
|
ReplayGainTuple track, album;
|
||||||
|
|
||||||
constexpr bool IsDefined() const {
|
constexpr bool IsDefined() const {
|
||||||
return tuples[REPLAY_GAIN_ALBUM].IsDefined() ||
|
return track.IsDefined() || album.IsDefined();
|
||||||
tuples[REPLAY_GAIN_TRACK].IsDefined();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReplayGainTuple &Get(ReplayGainMode mode) const {
|
const ReplayGainTuple &Get(ReplayGainMode mode) const {
|
||||||
return mode == REPLAY_GAIN_ALBUM
|
return mode == REPLAY_GAIN_ALBUM
|
||||||
? (tuples[REPLAY_GAIN_ALBUM].IsDefined()
|
? (album.IsDefined() ? album : track)
|
||||||
? tuples[REPLAY_GAIN_ALBUM]
|
: (track.IsDefined() ? track : album);
|
||||||
: tuples[REPLAY_GAIN_TRACK])
|
|
||||||
: (tuples[REPLAY_GAIN_TRACK].IsDefined()
|
|
||||||
? tuples[REPLAY_GAIN_TRACK]
|
|
||||||
: tuples[REPLAY_GAIN_ALBUM]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear() {
|
void Clear() {
|
||||||
tuples[REPLAY_GAIN_ALBUM].Clear();
|
track.Clear();
|
||||||
tuples[REPLAY_GAIN_TRACK].Clear();
|
album.Clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -805,8 +805,8 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
|
||||||
lame.track_gain) {
|
lame.track_gain) {
|
||||||
ReplayGainInfo rgi;
|
ReplayGainInfo rgi;
|
||||||
rgi.Clear();
|
rgi.Clear();
|
||||||
rgi.tuples[REPLAY_GAIN_TRACK].gain = lame.track_gain;
|
rgi.track.gain = lame.track_gain;
|
||||||
rgi.tuples[REPLAY_GAIN_TRACK].peak = lame.peak;
|
rgi.track.peak = lame.peak;
|
||||||
client->SubmitReplayGain(&rgi);
|
client->SubmitReplayGain(&rgi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,10 +170,10 @@ mpcdec_decode(DecoderClient &client, InputStream &is)
|
||||||
|
|
||||||
ReplayGainInfo rgi;
|
ReplayGainInfo rgi;
|
||||||
rgi.Clear();
|
rgi.Clear();
|
||||||
rgi.tuples[REPLAY_GAIN_ALBUM].gain = MPC_OLD_GAIN_REF - (info.gain_album / 256.);
|
rgi.album.gain = MPC_OLD_GAIN_REF - (info.gain_album / 256.);
|
||||||
rgi.tuples[REPLAY_GAIN_ALBUM].peak = pow(10, info.peak_album / 256. / 20) / 32767;
|
rgi.album.peak = pow(10, info.peak_album / 256. / 20) / 32767;
|
||||||
rgi.tuples[REPLAY_GAIN_TRACK].gain = MPC_OLD_GAIN_REF - (info.gain_title / 256.);
|
rgi.track.gain = MPC_OLD_GAIN_REF - (info.gain_title / 256.);
|
||||||
rgi.tuples[REPLAY_GAIN_TRACK].peak = pow(10, info.peak_title / 256. / 20) / 32767;
|
rgi.track.peak = pow(10, info.peak_title / 256. / 20) / 32767;
|
||||||
|
|
||||||
client.SubmitReplayGain(&rgi);
|
client.SubmitReplayGain(&rgi);
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ ScanOneOpusTag(const char *name, const char *value,
|
||||||
char *endptr;
|
char *endptr;
|
||||||
long l = strtol(value, &endptr, 10);
|
long l = strtol(value, &endptr, 10);
|
||||||
if (endptr > value && *endptr == 0)
|
if (endptr > value && *endptr == 0)
|
||||||
rgi->tuples[REPLAY_GAIN_TRACK].gain = double(l) / 256.;
|
rgi->track.gain = double(l) / 256.;
|
||||||
}
|
}
|
||||||
|
|
||||||
tag_handler_invoke_pair(handler, ctx, name, value);
|
tag_handler_invoke_pair(handler, ctx, name, value);
|
||||||
|
|
|
@ -225,13 +225,13 @@ wavpack_replaygain(ReplayGainInfo &rgi,
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
found |= wavpack_tag_float(wpc, "replaygain_track_gain",
|
found |= wavpack_tag_float(wpc, "replaygain_track_gain",
|
||||||
&rgi.tuples[REPLAY_GAIN_TRACK].gain);
|
&rgi.track.gain);
|
||||||
found |= wavpack_tag_float(wpc, "replaygain_track_peak",
|
found |= wavpack_tag_float(wpc, "replaygain_track_peak",
|
||||||
&rgi.tuples[REPLAY_GAIN_TRACK].peak);
|
&rgi.track.peak);
|
||||||
found |= wavpack_tag_float(wpc, "replaygain_album_gain",
|
found |= wavpack_tag_float(wpc, "replaygain_album_gain",
|
||||||
&rgi.tuples[REPLAY_GAIN_ALBUM].gain);
|
&rgi.album.gain);
|
||||||
found |= wavpack_tag_float(wpc, "replaygain_album_peak",
|
found |= wavpack_tag_float(wpc, "replaygain_album_peak",
|
||||||
&rgi.tuples[REPLAY_GAIN_ALBUM].peak);
|
&rgi.album.peak);
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,16 +33,16 @@ ParseReplayGainTagTemplate(ReplayGainInfo &info, const T t)
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
||||||
if ((value = t["replaygain_track_gain"]) != nullptr) {
|
if ((value = t["replaygain_track_gain"]) != nullptr) {
|
||||||
info.tuples[REPLAY_GAIN_TRACK].gain = atof(value);
|
info.track.gain = atof(value);
|
||||||
return true;
|
return true;
|
||||||
} else if ((value = t["replaygain_album_gain"]) != nullptr) {
|
} else if ((value = t["replaygain_album_gain"]) != nullptr) {
|
||||||
info.tuples[REPLAY_GAIN_ALBUM].gain = atof(value);
|
info.album.gain = atof(value);
|
||||||
return true;
|
return true;
|
||||||
} else if ((value = t["replaygain_track_peak"]) != nullptr) {
|
} else if ((value = t["replaygain_track_peak"]) != nullptr) {
|
||||||
info.tuples[REPLAY_GAIN_TRACK].peak = atof(value);
|
info.track.peak = atof(value);
|
||||||
return true;
|
return true;
|
||||||
} else if ((value = t["replaygain_album_peak"]) != nullptr) {
|
} else if ((value = t["replaygain_album_peak"]) != nullptr) {
|
||||||
info.tuples[REPLAY_GAIN_ALBUM].peak = atof(value);
|
info.album.peak = atof(value);
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -82,12 +82,12 @@ rva2_apply_data(ReplayGainInfo &rgi,
|
||||||
float volume_adjustment = rva2_float_volume_adjustment(data);
|
float volume_adjustment = rva2_float_volume_adjustment(data);
|
||||||
|
|
||||||
if (strcmp((const char *)id, "album") == 0) {
|
if (strcmp((const char *)id, "album") == 0) {
|
||||||
rgi.tuples[REPLAY_GAIN_ALBUM].gain = volume_adjustment;
|
rgi.album.gain = volume_adjustment;
|
||||||
} else if (strcmp((const char *)id, "track") == 0) {
|
} else if (strcmp((const char *)id, "track") == 0) {
|
||||||
rgi.tuples[REPLAY_GAIN_TRACK].gain = volume_adjustment;
|
rgi.track.gain = volume_adjustment;
|
||||||
} else {
|
} else {
|
||||||
rgi.tuples[REPLAY_GAIN_ALBUM].gain = volume_adjustment;
|
rgi.album.gain = volume_adjustment;
|
||||||
rgi.tuples[REPLAY_GAIN_TRACK].gain = volume_adjustment;
|
rgi.track.gain = volume_adjustment;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -132,8 +132,8 @@ DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple)
|
||||||
static void
|
static void
|
||||||
DumpReplayGainInfo(const ReplayGainInfo &info)
|
DumpReplayGainInfo(const ReplayGainInfo &info)
|
||||||
{
|
{
|
||||||
DumpReplayGainTuple("album", info.tuples[REPLAY_GAIN_ALBUM]);
|
DumpReplayGainTuple("album", info.album);
|
||||||
DumpReplayGainTuple("track", info.tuples[REPLAY_GAIN_TRACK]);
|
DumpReplayGainTuple("track", info.track);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -56,8 +56,8 @@ DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple)
|
||||||
static void
|
static void
|
||||||
DumpReplayGainInfo(const ReplayGainInfo &info)
|
DumpReplayGainInfo(const ReplayGainInfo &info)
|
||||||
{
|
{
|
||||||
DumpReplayGainTuple("album", info.tuples[REPLAY_GAIN_ALBUM]);
|
DumpReplayGainTuple("album", info.album);
|
||||||
DumpReplayGainTuple("track", info.tuples[REPLAY_GAIN_TRACK]);
|
DumpReplayGainTuple("track", info.track);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
|
Loading…
Reference in New Issue