Instantly share code, notes, and snippets.
Created
June 5, 2018 10:15
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save hotwatermorning/ffbd526b2605b437ade402721b467115 to your computer and use it in GitHub Desktop.
show related keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
struct RootName | |
{ | |
explicit | |
RootName(std::string name) | |
: name1_(name) | |
, name2_(name) | |
{} | |
RootName(std::string name1, std::string name2) | |
: name1_(name1) | |
, name2_(name2) | |
{} | |
std::string const & GetSharpName() const { return name1_; } | |
std::string const & GetFlatName() const { return name2_; } | |
private: | |
std::string name1_; | |
std::string name2_; | |
}; | |
std::vector<RootName> const root_names = { | |
RootName("C"), | |
RootName("C#", "Db"), | |
RootName("D"), | |
RootName("D#", "Eb"), | |
RootName("E"), | |
RootName("F"), | |
RootName("F#", "Gb"), | |
RootName("G"), | |
RootName("G#", "Ab"), | |
RootName("A"), | |
RootName("A#", "Bb"), | |
RootName("B"), | |
}; | |
std::vector<RootName> const interval_names = { | |
RootName("Ⅰ"), | |
RootName("Ⅰ#", "Ⅱb"), | |
RootName("Ⅱ"), | |
RootName("Ⅱ#", "Ⅲb"), | |
RootName("Ⅲ"), | |
RootName("Ⅳ"), | |
RootName("Ⅳ#", "Ⅴb"), | |
RootName("Ⅴ"), | |
RootName("Ⅴ#", "Ⅵb"), | |
RootName("Ⅵ"), | |
RootName("Ⅶ#", "Ⅶb"), | |
RootName("Ⅷ"), | |
}; | |
struct ScaleChord | |
{ | |
ScaleChord(int index, std::string const type) | |
: index_(index) | |
, type_(type) | |
{} | |
std::string GetSharpIntervalName() const | |
{ | |
return interval_names[index_].GetSharpName() + type_; | |
} | |
std::string GetFlatIntervalName() const | |
{ | |
return interval_names[index_].GetFlatName() + type_; | |
} | |
std::string GetSharpChordName(int root_index) const | |
{ | |
return root_names[(root_index + index_) % 12].GetSharpName() + type_; | |
} | |
std::string GetFlatChordName(int root_index) const | |
{ | |
return root_names[(root_index + index_) % 12].GetFlatName() + type_; | |
} | |
private: | |
int index_; | |
std::string type_; | |
}; | |
std::vector<ScaleChord> const major_scale = { | |
ScaleChord(0, "M7"), | |
ScaleChord(2, "m7"), | |
ScaleChord(4, "m7"), | |
ScaleChord(5, "M7"), | |
ScaleChord(7, "7"), | |
ScaleChord(9, "m7"), | |
ScaleChord(11, "m7-5"), | |
}; | |
std::vector<ScaleChord> const natural_minor_scale = { | |
ScaleChord(0, "m7"), | |
ScaleChord(2, "m7-5"), | |
ScaleChord(3, "M7"), | |
ScaleChord(5, "m7"), | |
ScaleChord(7, "m7"), | |
ScaleChord(8, "M7"), | |
ScaleChord(10, "7"), | |
}; | |
int main(int argc, char **argv) | |
{ | |
int const root = 4; | |
std::cout << "Key = " << root_names[root].GetSharpName() << std::endl; | |
std::cout << "主調" << std::endl; | |
std::for_each(major_scale.begin(), major_scale.end(), [root](auto const &chord) { | |
std::cout << chord.GetSharpIntervalName() << " = " << chord.GetSharpChordName(root) << std::endl; | |
}); | |
std::cout << "---------------------" << std::endl; | |
std::cout << "平行調" << std::endl; | |
std::for_each(natural_minor_scale.begin(), natural_minor_scale.end(), [root](auto const &chord) { | |
std::cout << chord.GetSharpIntervalName() << " = " << chord.GetSharpChordName((root + 9) % 12) << std::endl; | |
}); | |
std::cout << "---------------------" << std::endl; | |
std::cout << "同主短調" << std::endl; | |
std::for_each(natural_minor_scale.begin(), natural_minor_scale.end(), [root](auto const &chord) { | |
std::cout << chord.GetSharpIntervalName() << " = " << chord.GetSharpChordName(root) << std::endl; | |
}); | |
std::cout << "---------------------" << std::endl; | |
std::cout << "属調" << std::endl; | |
std::for_each(natural_minor_scale.begin(), natural_minor_scale.end(), [root](auto const &chord) { | |
std::cout << chord.GetSharpIntervalName() << " = " << chord.GetSharpChordName((root + 7) % 12) << std::endl; | |
}); | |
std::cout << "---------------------" << std::endl; | |
std::cout << "下属調" << std::endl; | |
std::for_each(natural_minor_scale.begin(), natural_minor_scale.end(), [root](auto const &chord) { | |
std::cout << chord.GetSharpIntervalName() << " = " << chord.GetSharpChordName((root + 5) % 12) << std::endl; | |
}); | |
std::cout << "---------------------" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment