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 {
|
||||
ReplayGainTuple tuples[2];
|
||||
ReplayGainTuple track, album;
|
||||
|
||||
constexpr bool IsDefined() const {
|
||||
return tuples[REPLAY_GAIN_ALBUM].IsDefined() ||
|
||||
tuples[REPLAY_GAIN_TRACK].IsDefined();
|
||||
return track.IsDefined() || album.IsDefined();
|
||||
}
|
||||
|
||||
const ReplayGainTuple &Get(ReplayGainMode mode) const {
|
||||
return mode == REPLAY_GAIN_ALBUM
|
||||
? (tuples[REPLAY_GAIN_ALBUM].IsDefined()
|
||||
? tuples[REPLAY_GAIN_ALBUM]
|
||||
: tuples[REPLAY_GAIN_TRACK])
|
||||
: (tuples[REPLAY_GAIN_TRACK].IsDefined()
|
||||
? tuples[REPLAY_GAIN_TRACK]
|
||||
: tuples[REPLAY_GAIN_ALBUM]);
|
||||
? (album.IsDefined() ? album : track)
|
||||
: (track.IsDefined() ? track : album);
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
tuples[REPLAY_GAIN_ALBUM].Clear();
|
||||
tuples[REPLAY_GAIN_TRACK].Clear();
|
||||
track.Clear();
|
||||
album.Clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -805,8 +805,8 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
|
|||
lame.track_gain) {
|
||||
ReplayGainInfo rgi;
|
||||
rgi.Clear();
|
||||
rgi.tuples[REPLAY_GAIN_TRACK].gain = lame.track_gain;
|
||||
rgi.tuples[REPLAY_GAIN_TRACK].peak = lame.peak;
|
||||
rgi.track.gain = lame.track_gain;
|
||||
rgi.track.peak = lame.peak;
|
||||
client->SubmitReplayGain(&rgi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,10 +170,10 @@ mpcdec_decode(DecoderClient &client, InputStream &is)
|
|||
|
||||
ReplayGainInfo rgi;
|
||||
rgi.Clear();
|
||||
rgi.tuples[REPLAY_GAIN_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.tuples[REPLAY_GAIN_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.album.gain = MPC_OLD_GAIN_REF - (info.gain_album / 256.);
|
||||
rgi.album.peak = pow(10, info.peak_album / 256. / 20) / 32767;
|
||||
rgi.track.gain = MPC_OLD_GAIN_REF - (info.gain_title / 256.);
|
||||
rgi.track.peak = pow(10, info.peak_title / 256. / 20) / 32767;
|
||||
|
||||
client.SubmitReplayGain(&rgi);
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ ScanOneOpusTag(const char *name, const char *value,
|
|||
char *endptr;
|
||||
long l = strtol(value, &endptr, 10);
|
||||
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);
|
||||
|
|
|
@ -225,13 +225,13 @@ wavpack_replaygain(ReplayGainInfo &rgi,
|
|||
|
||||
bool found = false;
|
||||
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",
|
||||
&rgi.tuples[REPLAY_GAIN_TRACK].peak);
|
||||
&rgi.track.peak);
|
||||
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",
|
||||
&rgi.tuples[REPLAY_GAIN_ALBUM].peak);
|
||||
&rgi.album.peak);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
|
|
@ -33,16 +33,16 @@ ParseReplayGainTagTemplate(ReplayGainInfo &info, const T t)
|
|||
const char *value;
|
||||
|
||||
if ((value = t["replaygain_track_gain"]) != nullptr) {
|
||||
info.tuples[REPLAY_GAIN_TRACK].gain = atof(value);
|
||||
info.track.gain = atof(value);
|
||||
return true;
|
||||
} else if ((value = t["replaygain_album_gain"]) != nullptr) {
|
||||
info.tuples[REPLAY_GAIN_ALBUM].gain = atof(value);
|
||||
info.album.gain = atof(value);
|
||||
return true;
|
||||
} else if ((value = t["replaygain_track_peak"]) != nullptr) {
|
||||
info.tuples[REPLAY_GAIN_TRACK].peak = atof(value);
|
||||
info.track.peak = atof(value);
|
||||
return true;
|
||||
} else if ((value = t["replaygain_album_peak"]) != nullptr) {
|
||||
info.tuples[REPLAY_GAIN_ALBUM].peak = atof(value);
|
||||
info.album.peak = atof(value);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
|
|
|
@ -82,12 +82,12 @@ rva2_apply_data(ReplayGainInfo &rgi,
|
|||
float volume_adjustment = rva2_float_volume_adjustment(data);
|
||||
|
||||
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) {
|
||||
rgi.tuples[REPLAY_GAIN_TRACK].gain = volume_adjustment;
|
||||
rgi.track.gain = volume_adjustment;
|
||||
} else {
|
||||
rgi.tuples[REPLAY_GAIN_ALBUM].gain = volume_adjustment;
|
||||
rgi.tuples[REPLAY_GAIN_TRACK].gain = volume_adjustment;
|
||||
rgi.album.gain = volume_adjustment;
|
||||
rgi.track.gain = volume_adjustment;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -132,8 +132,8 @@ DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple)
|
|||
static void
|
||||
DumpReplayGainInfo(const ReplayGainInfo &info)
|
||||
{
|
||||
DumpReplayGainTuple("album", info.tuples[REPLAY_GAIN_ALBUM]);
|
||||
DumpReplayGainTuple("track", info.tuples[REPLAY_GAIN_TRACK]);
|
||||
DumpReplayGainTuple("album", info.album);
|
||||
DumpReplayGainTuple("track", info.track);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -56,8 +56,8 @@ DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple)
|
|||
static void
|
||||
DumpReplayGainInfo(const ReplayGainInfo &info)
|
||||
{
|
||||
DumpReplayGainTuple("album", info.tuples[REPLAY_GAIN_ALBUM]);
|
||||
DumpReplayGainTuple("track", info.tuples[REPLAY_GAIN_TRACK]);
|
||||
DumpReplayGainTuple("album", info.album);
|
||||
DumpReplayGainTuple("track", info.track);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
Loading…
Reference in New Issue