diff --git a/src/test/keyutilstest.cpp b/src/test/keyutilstest.cpp index d8fb1481073..02adce28a25 100644 --- a/src/test/keyutilstest.cpp +++ b/src/test/keyutilstest.cpp @@ -53,7 +53,7 @@ TEST_F(KeyUtilsTest, LancelotNotation) { TEST_F(KeyUtilsTest, KeyNameNotation) { // Invalid letter - // (actually valid in traditional german notation where B is H and Bb is B - + // (actually valid in traditional German notation where B is H and Bb is B - // everyone confused?) EXPECT_EQ(mixxx::track::io::key::INVALID, KeyUtils::guessKeyFromText("H")); @@ -142,6 +142,47 @@ TEST_F(KeyUtilsTest, KeyNameNotation) { KeyUtils::guessKeyFromText("cb")); EXPECT_EQ(mixxx::track::io::key::C_MINOR, KeyUtils::guessKeyFromText("b#")); + + // Rapid Evolution test cases + EXPECT_EQ(mixxx::track::io::key::A_MINOR, + KeyUtils::guessKeyFromText("Am")); + EXPECT_EQ(mixxx::track::io::key::A_MINOR, + KeyUtils::guessKeyFromText("08A")); + EXPECT_EQ(mixxx::track::io::key::B_FLAT_MINOR, + KeyUtils::guessKeyFromText("A#m")); + EXPECT_EQ(mixxx::track::io::key::B_FLAT_MINOR, + KeyUtils::guessKeyFromText("Bbm")); + EXPECT_EQ(mixxx::track::io::key::A_MAJOR, + KeyUtils::guessKeyFromText("11B")); + EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + KeyUtils::guessKeyFromText("G#+50")); + EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + KeyUtils::guessKeyFromText("Ab +50")); + EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + KeyUtils::guessKeyFromText("Ab +50cents")); + EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + KeyUtils::guessKeyFromText("04B +50cents")); + EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + KeyUtils::guessKeyFromText("G#-50")); + EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + KeyUtils::guessKeyFromText("Ab -50")); + EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + KeyUtils::guessKeyFromText("Ab -50cents")); + EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + KeyUtils::guessKeyFromText("04B -50cents")); + EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + KeyUtils::guessKeyFromText(" 4b -50 cents ")); + // Mixxx does not allow this but Rapid Evolution + // EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + // KeyUtils::guessKeyFromText(" g # - 50 cents ")); + // EXPECT_EQ(mixxx::track::io::key::A_FLAT_MAJOR, // ionian + // KeyUtils::guessKeyFromText(" g # + 50 cents ")); + EXPECT_EQ(mixxx::track::io::key::INVALID, // ionian + KeyUtils::guessKeyFromText(" ")); + EXPECT_EQ(mixxx::track::io::key::INVALID, // ionian + KeyUtils::guessKeyFromText("")); + EXPECT_EQ(mixxx::track::io::key::INVALID, // ionian + KeyUtils::guessKeyFromText("xyz")); } mixxx::track::io::key::ChromaticKey incrementKey( diff --git a/src/track/keyutils.cpp b/src/track/keyutils.cpp index 595ed75c18e..47083e625fe 100644 --- a/src/track/keyutils.cpp +++ b/src/track/keyutils.cpp @@ -17,7 +17,8 @@ using mixxx::track::io::key::ChromaticKey_IsValid; static const QString s_openKeyPattern("^\\s*(1[0-2]|[1-9])([dm])\\s*$"); // Lancelot notation, the numbers 1-12 followed by a (minor) or b (major). -static const QString s_lancelotKeyPattern("^\\s*(1[0-2]|[1-9])([ab])\\s*$"); +// This is also used to detect RapidEvolution Key Code format using a padding "0" +static const QString s_lancelotKeyPattern("^\\s*0*(1[0-2]|[1-9])([ab])\\s*$"); // a-g followed by any number of sharps or flats, optionally followed by // a scale spec (m = minor, min, maj) @@ -248,7 +249,14 @@ QString KeyUtils::getGlobalKeyText(const Keys& keys, KeyNotation notation) { // static ChromaticKey KeyUtils::guessKeyFromText(const QString& text) { - QString trimmed = text.trimmed(); + // Remove Shift (Tuning) Information used by Rapid Evolution like: "A#m +50"; + int shiftStart = text.indexOf('+'); + if (shiftStart < 0) { + shiftStart = text.indexOf('-'); + } + const QString trimmed = + shiftStart >= 0 ? text.left(shiftStart).trimmed() : text.trimmed(); + if (trimmed.isEmpty()) { return mixxx::track::io::key::INVALID; } diff --git a/src/track/track.cpp b/src/track/track.cpp index f4acaaa54ff..68c30e805e1 100644 --- a/src/track/track.cpp +++ b/src/track/track.cpp @@ -151,9 +151,9 @@ void Track::importMetadata( // overwriting with an inconsistent value. The bpm must always be // set together with the beat grid and the key text must be parsed // and validated. - const auto importedBpm = importedMetadata.getTrackInfo().getBpm(); + const mixxx::Bpm importedBpm = importedMetadata.getTrackInfo().getBpm(); importedMetadata.refTrackInfo().setBpm(getBpmWhileLocked()); - const auto importedKeyText = importedMetadata.getTrackInfo().getKey(); + const QString importedKeyText = importedMetadata.getTrackInfo().getKey(); importedMetadata.refTrackInfo().setKey(m_record.getMetadata().getTrackInfo().getKey()); bool modified = false;