implement reading of the replaygain tags
ClosedPublic

Authored by astippich on Jun 23 2018, 4:47 PM.

Details

Summary

add the ability to read the replaygain_{album/track}_{gain/peak} tags
the implementation can succesfully read the tags generated by MediaMonkey
mp4 files are not supported

Test Plan

tests pass

Diff Detail

Repository
R286 KFileMetaData
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
astippich created this revision.Jun 23 2018, 4:47 PM
Restricted Application added projects: Frameworks, Baloo. · View Herald TranscriptJun 23 2018, 4:47 PM
Restricted Application added subscribers: Baloo, kde-frameworks-devel. · View Herald Transcript
astippich requested review of this revision.Jun 23 2018, 4:47 PM

I decided to store the values as string, including the "dB" unit. Another possibility would be to store them as floats, but this would require adjustments to baloo first.

astippich retitled this revision from implement the replaygain tags to implement reading of the replaygain tags.Jun 23 2018, 5:24 PM
bruns added a comment.Jun 23 2018, 5:46 PM

"dB" is nothing more than deci-Bel, i.e. 0.1 Bel. You can convert the value to e.g. mB or uB. This looks unfamiliar, but is e.g. also used by the CRDA WiFi compliance tool.

"dB" is nothing more than deci-Bel, i.e. 0.1 Bel. You can convert the value to e.g. mB or uB. This looks unfamiliar, but is e.g. also used by the CRDA WiFi compliance tool.

I know what dB is :)
The question here is actually if we want to store the unit within the string as it is stored in the metadata, e.g. "-9.90 dB" or if we go to floats and drop the unit from the property in KFileMetaData

"dB" is nothing more than deci-Bel, i.e. 0.1 Bel. You can convert the value to e.g. mB or uB. This looks unfamiliar, but is e.g. also used by the CRDA WiFi compliance tool.

I know what dB is :)
The question here is actually if we want to store the unit within the string as it is stored in the metadata, e.g. "-9.90 dB" or if we go to floats and drop the unit from the property in KFileMetaData

I would just store the value, and document the unit. Then, the formatting can be made typographically correct, e.g. <value><THIN SPACE><unit>.

astippich updated this revision to Diff 36901.Jun 29 2018, 7:15 PM
  • use floats to store the replaygain tags

baloo handles floats actually just fine

mgallien requested changes to this revision.Aug 29 2018, 6:23 AM

Some inline comments

src/extractors/taglibextractor.cpp
254–263

I am not a fan of the strcmp usage here. Is it not possible to do without them ?

468

This change is unrelated to the patch. Please remove it.

662

same comment

986

Can you remove it ?

996

Could you check if it is not faster to use QLatin1String here ?

src/properties.h
333–340

Please document each entry separately otherwise only the first one will have documentation (as seen on api.kde.org).

This revision now requires changes to proceed.Aug 29 2018, 6:23 AM
astippich updated this revision to Diff 40824.Sep 1 2018, 3:01 PM
astippich marked 5 inline comments as done.
  • add documentation, remove unrelated changes and debug info
  • get rid of string comparisons for id3v2
astippich added inline comments.Sep 1 2018, 3:01 PM
src/extractors/taglibextractor.cpp
996

At least if my interpretations of callgrind are correct, it's exactly the same.

bruns added inline comments.Sep 1 2018, 6:01 PM
src/extractors/taglibextractor.cpp
252

You can use a typedef in this scope, makes the long lines easier to read
https://en.cppreference.com/w/cpp/language/namespace_alias

typedef TagLib::ID3v2::UserTextIdentificationFrame IdFrame;
auto trackGainFrame = IdFrame::find(mpegFile.ID3v2Tag(), "replaygain_track_gain");
if (trackGainFrame) { ...

Using a distinct name for each instance makes it clearer these are independent frames.

254

Remove the extra space inside the parentheses.

255

you can use TStringToQString
data.replayGainTrackGain = TStringToQString(userTextFrame->fieldList().back());

255

fieldList() may return an empty list, please add a check

astippich updated this revision to Diff 40851.Sep 2 2018, 11:26 AM
astippich marked 4 inline comments as done.
  • improve readability and add check
astippich added inline comments.Sep 2 2018, 11:27 AM
src/extractors/taglibextractor.cpp
255

toCString() was actually completely unnecessary. I removed it since convertWChartsToQString() avoids the UTF16->UTF8->UTF16 conversion of TStringToQString

bruns added inline comments.Sep 2 2018, 6:26 PM
src/extractors/taglibextractor.cpp
50

This is definitely broken:
http://taglib.org/api/classTagLib_1_1String.html#a0ef8ad270d710863e0bb1c1b18cdb95d

const wchar_t* TagLib::String::toCWString () const

Returns a standard C-style (null-terminated) wide character version of this String. The returned string is encoded in UTF-16 (without BOM/CPU byte order), not UTF-32 even if wchar_t is 32-bit wide.

https://github.com/qt/qtbase/blob/c5307203f5c0b0e588cc93e70764c090dd4c2ce0/src/corelib/tools/qstring.h#L1027

inline QString QString::fromWCharArray(const wchar_t *string, int size)
{
    return sizeof(wchar_t) == sizeof(QChar) ? fromUtf16(reinterpret_cast<const ushort *>(string), size)
                                            : fromUcs4(reinterpret_cast<const uint *>(string), size);
}

Fortunately, platforms with wchar_t == wchar32_t are uncommon ...

249

Maybe better // Check if there are any User Text Identification Frames (TXXX) at all
Technically, the UserTextIdentificationFrame::find(...) below would be sufficient to lookup the tags.

255

Stray space in if (...isEmpty() )

astippich updated this revision to Diff 41119.Sep 6 2018, 6:58 PM
astippich marked 2 inline comments as done.
  • remove space and adjust comment
astippich added inline comments.Sep 6 2018, 6:58 PM
src/extractors/taglibextractor.cpp
50

This is used throughout the taglibextractor and should then be corrected everywhere in a different patch imho.

249

You're right, the idea was to skip the calls to the replaygain tags if there aren't any TXXX tags

bruns added inline comments.Sep 8 2018, 2:08 AM
src/extractors/taglibextractor.cpp
943

You should check if the value can be converted to double, and probably also if it is in a sane range.

bruns added inline comments.Sep 8 2018, 2:17 AM
src/extractors/taglibextractor.cpp
50

Can you do a followup-patch to fix this?

Thanks for your hard work. This is a really nice addition to audio tags.
I no longer have objections. Please finish to take into account feedback from @bruns.

mgallien accepted this revision.Sep 8 2018, 7:22 AM
This revision is now accepted and ready to land.Sep 8 2018, 7:22 AM
astippich updated this revision to Diff 41429.Sep 11 2018, 6:30 PM
  • add checks for conversion to double
astippich added inline comments.Sep 11 2018, 6:31 PM
src/extractors/taglibextractor.cpp
50

Yes, will do after this patch landed

943

I added the checks for a successful conversion, but in my opinion kfilemetadata should not judge if the result is within a reasonable range. This should be up to the application.

@bruns any further comments/objections?

This revision was automatically updated to reflect the committed changes.