diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2013-05-28 00:08:14 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2013-05-28 00:11:27 +0200 |
commit | 1feb244dce282abfa7838ec7a7d7acb977487338 (patch) | |
tree | d97406f83d7e7a9bd7cd08eb212cb7e2dd334043 /src/tags.cpp | |
parent | 4db97e55025e3eb33746aa9afdf2f2f4da132f9b (diff) |
song info: show replay gain info if available (flac/ogg only)
Diffstat (limited to 'src/tags.cpp')
-rw-r--r-- | src/tags.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/tags.cpp b/src/tags.cpp index 4fa866d0..8042ca95 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -187,6 +187,24 @@ void writeXiphComments(const MPD::MutableSong &s, TagLib::Ogg::XiphComment *tag) writeXiph("COMMENT", tagList(s, &MPD::Song::getComment)); } +Tags::ReplayGainInfo getReplayGain(TagLib::Ogg::XiphComment *tag) +{ + auto first_or_empty = [](const TagLib::StringList &list) { + std::string result; + if (!list.isEmpty()) + result = list.front().to8Bit(true); + return result; + }; + auto &fields = tag->fieldListMap(); + return Tags::ReplayGainInfo( + first_or_empty(fields["REPLAYGAIN_REFERENCE_LOUDNESS"]), + first_or_empty(fields["REPLAYGAIN_TRACK_GAIN"]), + first_or_empty(fields["REPLAYGAIN_TRACK_PEAK"]), + first_or_empty(fields["REPLAYGAIN_ALBUM_GAIN"]), + first_or_empty(fields["REPLAYGAIN_ALBUM_PEAK"]) + ); +} + } namespace Tags {// @@ -198,6 +216,22 @@ bool extendedSetSupported(const TagLib::File *f) || dynamic_cast<const TagLib::FLAC::File *>(f); } +ReplayGainInfo readReplayGain(TagLib::File *f) +{ + ReplayGainInfo result; + if (auto ogg_file = dynamic_cast<TagLib::Ogg::Vorbis::File *>(f)) + { + if (auto xiph = ogg_file->tag()) + result = getReplayGain(xiph); + } + else if (auto flac_file = dynamic_cast<TagLib::FLAC::File *>(f)) + { + if (auto xiph = flac_file->xiphComment()) + result = getReplayGain(xiph); + } + return result; +} + void read(MPD::MutableSong &s) { TagLib::FileRef f(s.getURI().c_str()); |