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 type detection of AIFF files #4364

Merged
merged 2 commits into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions res/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,12 @@ reapplying those migrations.
UPDATE library SET source_synchronized_ms=NULL WHERE source_synchronized_ms=0;
</sql>
</revision>
<revision version="39" min_compatible="3">
<description>
Replace file type "aif" with "aiff".
</description>
<sql>
UPDATE library SET filetype='aiff' WHERE filetype='aif';
</sql>
</revision>
</schema>
2 changes: 1 addition & 1 deletion src/database/mixxxdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
const QString MixxxDb::kDefaultSchemaFile(":/schema.xml");

//static
const int MixxxDb::kRequiredSchemaVersion = 38;
const int MixxxDb::kRequiredSchemaVersion = 39;

namespace {

Expand Down
4 changes: 4 additions & 0 deletions src/sources/soundsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inline QString fileTypeFromSuffix(const QString& suffix) {
// of an empty string which might either be null or "".
return QString{};
}
// Map shortened suffix "aif" to "aiff" for disambiguation
if (fileType == QStringLiteral("aif")) {
return QStringLiteral("aiff");
}
return fileType;
}

Expand Down
23 changes: 22 additions & 1 deletion src/test/soundproxy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,12 +752,33 @@ TEST_F(SoundSourceProxyTest, getTypeFromFile) {
}

TEST_F(SoundSourceProxyTest, getTypeFromMissingFile) {
// Also verify that the shortened suffix ".aif" (case-insensitive) is
// mapped to file type "aiff", independent of whether the file exists or not!
const QFileInfo missingFileWithUppercaseSuffixAndLeadingTrailingWhitespaceSuffix =
kTestDir.absoluteFilePath(QStringLiteral("missing_file. AIFF "));
kTestDir.absoluteFilePath(QStringLiteral("missing_file. AIF "));

ASSERT_FALSE(missingFileWithUppercaseSuffixAndLeadingTrailingWhitespaceSuffix.exists());

EXPECT_STREQ(qPrintable("aiff"),
qPrintable(mixxx::SoundSource::getTypeFromFile(
missingFileWithUppercaseSuffixAndLeadingTrailingWhitespaceSuffix)));
}

TEST_F(SoundSourceProxyTest, getTypeFromAiffFile) {
const QString aiffFilePath =
kTestDir.absoluteFilePath(QStringLiteral("cover-test.aiff"));

ASSERT_TRUE(QFileInfo::exists(aiffFilePath));
ASSERT_STREQ(qPrintable("aiff"),
qPrintable(mixxx::SoundSource::getTypeFromFile(
aiffFilePath)));

const QString aiffFilePathWithShortenedSuffix =
mixxxtest::generateTemporaryFileName(QStringLiteral("cover-test.aif"));
mixxxtest::copyFile(aiffFilePath, aiffFilePathWithShortenedSuffix);
ASSERT_TRUE(QFileInfo::exists(aiffFilePathWithShortenedSuffix));

EXPECT_STREQ(qPrintable("aiff"),
qPrintable(mixxx::SoundSource::getTypeFromFile(
aiffFilePathWithShortenedSuffix)));
}