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

Add case-insensitive parsing for Lancelot key notation #14318

Merged
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
6 changes: 6 additions & 0 deletions src/test/keyutilstest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ TEST_F(KeyUtilsTest, LancelotNotation) {
EXPECT_EQ(mixxx::track::io::key::C_SHARP_MINOR,
KeyUtils::guessKeyFromText("12A"));

// Allow lower-case to be more flexible when parsing search queries
EXPECT_EQ(mixxx::track::io::key::C_MAJOR,
KeyUtils::guessKeyFromText("8b"));
EXPECT_EQ(mixxx::track::io::key::C_SHARP_MINOR,
KeyUtils::guessKeyFromText("12a"));

// whitespace is ok
EXPECT_EQ(mixxx::track::io::key::B_MINOR,
KeyUtils::guessKeyFromText("\t10A "));
Expand Down
8 changes: 5 additions & 3 deletions src/track/keyutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const QRegularExpression s_openKeyRegex(QStringLiteral(
// Lancelot notation, the numbers 1-12 followed by A (minor) or B(I) (major).
// or "I", "L", "M", "D", "P", "C" for the advanced modes
const QRegularExpression s_lancelotKeyRegex(
QStringLiteral("\\A(?:^\\s*0*(1[0-2]|[1-9])([ABILMDPC])\\s*$)\\z"));
QStringLiteral("\\A(?:^\\s*0*(1[0-2]|[1-9])([ABILMDPC])\\s*$)\\z"),
QRegularExpression::CaseInsensitiveOption);
constexpr std::string_view s_lancelotMajorModes = "BILM";

// a-g followed by any number of sharps or flats, optionally followed by
Expand Down Expand Up @@ -460,8 +461,9 @@ ChromaticKey KeyUtils::guessKeyFromText(const QString& text) {
int openKeyNumber = lancelotNumberToOpenKeyNumber(lancelotNumber);

const QChar lancelotScaleMode = lancelotMatch.captured(2).at(0);
bool major = (s_lancelotMajorModes.find(lancelotScaleMode.toLatin1()) != std::string::npos);

bool major = (s_lancelotMajorModes.find(
lancelotScaleMode.toUpper().toLatin1()) !=
std::string::npos);
return openKeyNumberToKey(openKeyNumber, major);
}

Expand Down
Loading