Skip to content

Commit

Permalink
Merge pull request #11001 from daschuer/gh10995
Browse files Browse the repository at this point in the history
Don't reject file metadata Keys values with non Minor/Major scales.
  • Loading branch information
Swiftb0y authored Aug 8, 2023
2 parents 46fd5bf + 92ea4e6 commit 1a9a62b
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 147 deletions.
57 changes: 42 additions & 15 deletions src/test/keyutilstest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class KeyUtilsTest : public testing::Test {
};

TEST_F(KeyUtilsTest, OpenKeyNotation) {
EXPECT_EQ(mixxx::track::io::key::C_MAJOR,
KeyUtils::guessKeyFromText("1D"));
EXPECT_EQ(mixxx::track::io::key::C_SHARP_MINOR,
KeyUtils::guessKeyFromText("5M"));

// Lower-case.
EXPECT_EQ(mixxx::track::io::key::B_MAJOR,
KeyUtils::guessKeyFromText("6d"));
Expand All @@ -37,18 +32,12 @@ TEST_F(KeyUtilsTest, LancelotNotation) {
EXPECT_EQ(mixxx::track::io::key::C_SHARP_MINOR,
KeyUtils::guessKeyFromText("12A"));

// Lower-case.
EXPECT_EQ(mixxx::track::io::key::B_MAJOR,
KeyUtils::guessKeyFromText("1b"));
EXPECT_EQ(mixxx::track::io::key::B_MINOR,
KeyUtils::guessKeyFromText("10a"));

// whitespace is ok
EXPECT_EQ(mixxx::track::io::key::B_MINOR,
KeyUtils::guessKeyFromText("\t10a "));
KeyUtils::guessKeyFromText("\t10A "));
// but other stuff is not
EXPECT_EQ(mixxx::track::io::key::INVALID,
KeyUtils::guessKeyFromText("\t10aa "));
KeyUtils::guessKeyFromText("\t10AA "));
}

TEST_F(KeyUtilsTest, KeyNameNotation) {
Expand Down Expand Up @@ -170,10 +159,10 @@ TEST_F(KeyUtilsTest, KeyNameNotation) {
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(" 4b -50 cents "));
// 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 "));
Expand All @@ -185,6 +174,44 @@ TEST_F(KeyUtilsTest, KeyNameNotation) {
KeyUtils::guessKeyFromText("xyz"));
}

TEST_F(KeyUtilsTest, ScaleModeNotation) {
EXPECT_EQ(mixxx::track::io::key::C_MAJOR,
KeyUtils::guessKeyFromText("C ionian"));
EXPECT_EQ(mixxx::track::io::key::A_MINOR,
KeyUtils::guessKeyFromText("A aeolian"));
EXPECT_EQ(mixxx::track::io::key::C_MAJOR,
KeyUtils::guessKeyFromText("F lydian"));
EXPECT_EQ(mixxx::track::io::key::C_MAJOR,
KeyUtils::guessKeyFromText("G mixolydian"));
EXPECT_EQ(mixxx::track::io::key::A_MINOR,
KeyUtils::guessKeyFromText("D dorian"));
EXPECT_EQ(mixxx::track::io::key::A_MINOR,
KeyUtils::guessKeyFromText("E phrygian"));
EXPECT_EQ(mixxx::track::io::key::A_MINOR,
KeyUtils::guessKeyFromText("B locrian"));

EXPECT_EQ(mixxx::track::io::key::F_SHARP_MINOR,
KeyUtils::guessKeyFromText("11A"));
EXPECT_EQ(mixxx::track::io::key::A_MAJOR,
KeyUtils::guessKeyFromText("11B"));
EXPECT_EQ(mixxx::track::io::key::A_MAJOR,
KeyUtils::guessKeyFromText("11I"));
EXPECT_EQ(mixxx::track::io::key::A_MAJOR,
KeyUtils::guessKeyFromText("11L"));
EXPECT_EQ(mixxx::track::io::key::A_MAJOR,
KeyUtils::guessKeyFromText("11M"));
EXPECT_EQ(mixxx::track::io::key::F_SHARP_MINOR,
KeyUtils::guessKeyFromText("11D"));
EXPECT_EQ(mixxx::track::io::key::F_SHARP_MINOR,
KeyUtils::guessKeyFromText("11P"));
EXPECT_EQ(mixxx::track::io::key::F_SHARP_MINOR,
KeyUtils::guessKeyFromText("11C"));

// Redundant Mode
EXPECT_EQ(mixxx::track::io::key::INVALID,
KeyUtils::guessKeyFromText("Cm ionian"));
}

mixxx::track::io::key::ChromaticKey incrementKey(
mixxx::track::io::key::ChromaticKey key, int steps=1) {
return static_cast<mixxx::track::io::key::ChromaticKey>(
Expand Down
Loading

0 comments on commit 1a9a62b

Please sign in to comment.