ReplayGainInfo: implement fallback in Get()

Eliminates Complete().
This commit is contained in:
Max Kellermann 2016-11-24 16:52:31 +01:00
parent 09c3cc58e4
commit 1261327fa6
3 changed files with 9 additions and 17 deletions

View File

@ -41,10 +41,3 @@ ReplayGainTuple::CalculateScale(float preamp, float missing_preamp,
return scale; return scale;
} }
void
ReplayGainInfo::Complete()
{
if (!tuples[REPLAY_GAIN_ALBUM].IsDefined())
tuples[REPLAY_GAIN_ALBUM] = tuples[REPLAY_GAIN_TRACK];
}

View File

@ -57,19 +57,19 @@ struct ReplayGainInfo {
} }
const ReplayGainTuple &Get(ReplayGainMode mode) const { 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() { void Clear() {
tuples[REPLAY_GAIN_ALBUM].Clear(); tuples[REPLAY_GAIN_ALBUM].Clear();
tuples[REPLAY_GAIN_TRACK].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 #endif

View File

@ -79,10 +79,9 @@ public:
} }
void SetInfo(const ReplayGainInfo *_info) { void SetInfo(const ReplayGainInfo *_info) {
if (_info != nullptr) { if (_info != nullptr)
info = *_info; info = *_info;
info.Complete(); else
} else
info.Clear(); info.Clear();
Update(); Update();