Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading metadata for some file extensions #13218

Open
wants to merge 7 commits into
base: 2.4
Choose a base branch
from

Conversation

daschuer
Copy link
Member

@daschuer daschuer commented May 6, 2024

This replaces all file type guessing code form the file extension, by using the normalized file type stored in the Track object.
This makes sure all parts are using the same file type, even if the extension is wrong.

This fixes #13205

…ough the call stack to avoid guessing it from the file extension.
Copy link
Contributor

@acolombier acolombier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be worth adding one or few test case to ensure the behaviour and prevent potential regression?

src/track/taglib/trackmetadata_file.cpp Outdated Show resolved Hide resolved
Co-authored-by: Antoine Colombier <7086688+acolombier@users.noreply.github.com>
@@ -1086,3 +1087,14 @@ TEST_F(SoundSourceProxyTest, freeModeGarbage) {
break;
}
}

TEST_F(SoundSourceProxyTest, taglibStringToEnumFileType) {
for (const auto& fileType : SoundSourceProxy::getSupportedFileTypes()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clazy here

@daschuer
Copy link
Member Author

All green now.

@@ -82,7 +83,7 @@ double SeratoTags::guessTimingOffsetMillis(
// PR for more detailed information:
// https://github.com/mixxxdj/mixxx/pull/2119
double timingOffset = 0;
if (taglib::getFileTypeFromFileName(filePath) == taglib::FileType::MP3) {
if (fileType == "mp3") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QStringLiteral, otherwise implicitly converts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qt has explicit an operator for it and it is faster than using a QStringLiteral:
https://github.com/qt/qtbase/blob/5686af295c98a5ed4b0793ad0098cef76f39a2d7/src/corelib/text/qstring.h#L1376

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

src/track/taglib/trackmetadata_file.cpp Outdated Show resolved Hide resolved
Comment on lines -17 to +14
taglib::FileType fileType)
const QString& fileType)
: m_fileName(fileName),
m_fileType(fileType) {
m_fileType(taglib::stringToEnumFileType(fileType)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the advantage of taking a string here instead of shifting the conversion duty to the caller? This smells stringly-typed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, two of the other three comments were redundant if this would avoid strings better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the duality of a string typed fileType used in Soundsource classes outside of Taglib and the enum inside Taglib. We still need the "fileType" as string, because it holds the file extension in case the type has not been normalized. This is a left over from the legacy when Mixxx uses just the file extension.

I have moved the conversion here, to hide all implementation details of MetadataSourceTagLib and keep the taglib includes in its cpp file.
Else it would be here:

SoundSource::SoundSource(const QUrl& url, const QString& type)
: AudioSource(validateLocalFileUrl(url)),
MetadataSourceTagLib(getLocalFileName(), type),
m_type(type) {
}

Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com>
@daschuer
Copy link
Member Author

daschuer commented Jun 9, 2024

Done

TypePair{"dff"_L1, FileType::DSDIFF},
TypePair{"dsdiff"_L1, FileType::DSDIFF}};

const auto it = std::find_if(lookupTable.cbegin(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy

Suggested change
const auto it = std::find_if(lookupTable.cbegin(),
const auto *const it = std::find_if(lookupTable.cbegin(),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants