From 25e58df5e07c3eb878d48ac58780d56f2ecdd565 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 24 Nov 2016 16:45:56 +0100 Subject: [PATCH] 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. --- src/ReplayGainInfo.hxx | 17 ++++++----------- src/decoder/plugins/MadDecoderPlugin.cxx | 4 ++-- src/decoder/plugins/MpcdecDecoderPlugin.cxx | 8 ++++---- src/decoder/plugins/OpusTags.cxx | 2 +- src/decoder/plugins/WavpackDecoderPlugin.cxx | 8 ++++---- src/tag/ReplayGain.cxx | 8 ++++---- src/tag/TagRva2.cxx | 8 ++++---- test/FakeDecoderAPI.cxx | 4 ++-- test/dump_rva2.cxx | 4 ++-- 9 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/ReplayGainInfo.hxx b/src/ReplayGainInfo.hxx index 432171b3f..18e21604d 100644 --- a/src/ReplayGainInfo.hxx +++ b/src/ReplayGainInfo.hxx @@ -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(); } }; diff --git a/src/decoder/plugins/MadDecoderPlugin.cxx b/src/decoder/plugins/MadDecoderPlugin.cxx index 729decb37..bc61efb2b 100644 --- a/src/decoder/plugins/MadDecoderPlugin.cxx +++ b/src/decoder/plugins/MadDecoderPlugin.cxx @@ -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); } } diff --git a/src/decoder/plugins/MpcdecDecoderPlugin.cxx b/src/decoder/plugins/MpcdecDecoderPlugin.cxx index a5f58c288..3a73d4d56 100644 --- a/src/decoder/plugins/MpcdecDecoderPlugin.cxx +++ b/src/decoder/plugins/MpcdecDecoderPlugin.cxx @@ -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); diff --git a/src/decoder/plugins/OpusTags.cxx b/src/decoder/plugins/OpusTags.cxx index db7fa571a..f924d27b7 100644 --- a/src/decoder/plugins/OpusTags.cxx +++ b/src/decoder/plugins/OpusTags.cxx @@ -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); diff --git a/src/decoder/plugins/WavpackDecoderPlugin.cxx b/src/decoder/plugins/WavpackDecoderPlugin.cxx index fb4ed7a16..16fcf4d60 100644 --- a/src/decoder/plugins/WavpackDecoderPlugin.cxx +++ b/src/decoder/plugins/WavpackDecoderPlugin.cxx @@ -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; } diff --git a/src/tag/ReplayGain.cxx b/src/tag/ReplayGain.cxx index 1de9c3d1d..38ab13e3d 100644 --- a/src/tag/ReplayGain.cxx +++ b/src/tag/ReplayGain.cxx @@ -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; diff --git a/src/tag/TagRva2.cxx b/src/tag/TagRva2.cxx index 5f68f7e3a..d8d510104 100644 --- a/src/tag/TagRva2.cxx +++ b/src/tag/TagRva2.cxx @@ -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; diff --git a/test/FakeDecoderAPI.cxx b/test/FakeDecoderAPI.cxx index f443c5d42..c92d9be9c 100644 --- a/test/FakeDecoderAPI.cxx +++ b/test/FakeDecoderAPI.cxx @@ -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 diff --git a/test/dump_rva2.cxx b/test/dump_rva2.cxx index 603d96e7b..3a5aada64 100644 --- a/test/dump_rva2.cxx +++ b/test/dump_rva2.cxx @@ -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)