From 1261327fa61fbf01adaab639bb012dae58ddab1a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 24 Nov 2016 16:52:31 +0100 Subject: [PATCH] ReplayGainInfo: implement fallback in Get() Eliminates Complete(). --- src/ReplayGainInfo.cxx | 7 ------- src/ReplayGainInfo.hxx | 14 +++++++------- src/filter/plugins/ReplayGainFilterPlugin.cxx | 5 ++--- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/ReplayGainInfo.cxx b/src/ReplayGainInfo.cxx index a87ae551f..3524811a0 100644 --- a/src/ReplayGainInfo.cxx +++ b/src/ReplayGainInfo.cxx @@ -41,10 +41,3 @@ ReplayGainTuple::CalculateScale(float preamp, float missing_preamp, return scale; } - -void -ReplayGainInfo::Complete() -{ - if (!tuples[REPLAY_GAIN_ALBUM].IsDefined()) - tuples[REPLAY_GAIN_ALBUM] = tuples[REPLAY_GAIN_TRACK]; -} diff --git a/src/ReplayGainInfo.hxx b/src/ReplayGainInfo.hxx index baa041bf7..432171b3f 100644 --- a/src/ReplayGainInfo.hxx +++ b/src/ReplayGainInfo.hxx @@ -57,19 +57,19 @@ struct ReplayGainInfo { } const ReplayGainTuple &Get(ReplayGainMode mode) const { - return tuples[mode]; + 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]); } void Clear() { tuples[REPLAY_GAIN_ALBUM].Clear(); tuples[REPLAY_GAIN_TRACK].Clear(); } - - /** - * Attempt to auto-complete missing data. In particular, if - * album information is missing, track gain is used. - */ - void Complete(); }; #endif diff --git a/src/filter/plugins/ReplayGainFilterPlugin.cxx b/src/filter/plugins/ReplayGainFilterPlugin.cxx index 1f72a12ae..da4a3bca2 100644 --- a/src/filter/plugins/ReplayGainFilterPlugin.cxx +++ b/src/filter/plugins/ReplayGainFilterPlugin.cxx @@ -79,10 +79,9 @@ public: } void SetInfo(const ReplayGainInfo *_info) { - if (_info != nullptr) { + if (_info != nullptr) info = *_info; - info.Complete(); - } else + else info.Clear(); Update();