// // Programmer: Craig Stuart Sapp // Creation Date: Sat Apr 26 21:29:20 PDT 2014 // Last Modified: Sat Apr 26 22:05:49 PDT 2014 // Filename: ...museinfo/examples/all/dimuth.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/dimuth.cpp // Syntax: C++; museinfo // // Description: Calculate triadic scores for sonorities. // #include "humdrum.h" #include #include #include #include #include "PerlRegularExpression.h" using namespace std; class AnalysisData { public: AnalysisData(void) { clear(); measure = 0; harm = "."; key = "."; } int line; double beat; double duration; double cumulative; int measure; map pitches; vector scores; string harm; string key; void clear(void) { duration = cumulative = beat = 0.0; pitches.clear(); scores.clear(); line = 0; scores.resize(7); fill(scores.begin(), scores.end(), 0.0); } }; /////////////////////////////////////////////////////////////////////////// // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void processFile (HumdrumFile& infile, const string& filename); void extractData (HumdrumFile& infile, int line, AnalysisData& data); void printAnalysisData (vector& data, HumdrumFile& infile); int getChordRootInterval (const char* harmdata, const char* keyinfo); void calculateScores (AnalysisData& data); // global variables Options options; // database for command-line arguments int debugQ = 0; // used with --debug option /////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { checkOptions(options, argc, argv); HumdrumStream streamer(options); HumdrumFile infile; while (streamer.read(infile)) { processFile(infile, infile.getFileName()); } return 0; } /////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // processFile -- Do requested analysis on a given file. // void processFile(HumdrumFile& infile, const string& filename) { infile.analyzeRhythm(); AnalysisData current; PerlRegularExpression pre; vector data; data.reserve(infile.getNumLines()); for (int i=0; i 0) { data.push_back(current); } } for (unsigned int i=0; i dpcs(28); int dpc; int count; fill(dpcs.begin(), dpcs.end(), 0); for (auto& it : data.pitches) { count = it.second; dpc = Convert::base40ToDiatonic(it.first + 40 * 3) % 7; dpcs[dpc] += count; dpcs[dpc + 7] += count; dpcs[dpc + 14] += count; dpcs[dpc + 21] += count; } // char buffer[1024] = {0}; // for (auto& it : data.pitches) { // cout << it.second << Convert::base40ToKern(buffer, it.first + 40 * 3) << " "; // } // cout << "\t"; // for (auto& it : dpcs) { // cout << it << " "; // } int sum; // cout << "\tScores: "; for (int i=0; i<7; i++) { sum = 0; for (int j=0; j<7; j++) { sum += j * dpcs[i+j*2]; } data.scores[i] = sum; // cout << sum << " "; } // cout << endl; } ////////////////////////////// // // printAnalysisData -- // void printAnalysisData(vector& data, HumdrumFile& infile) { double minrhy = 1.0 / infile.getMinTimeBase() * 4.0; char buffer[1024] = {0}; int counter = 0; int chordint; cout << "#bar\t#beat\t#offset\t#dur\t#count\t#S0\t#S1\t#S2\t#S3\t#S4\t#S5\t#S6\t#root\t#key\t#harm\t#pitches\n"; for (unsigned int i=0; i= 1) { const char* ptr = strchr(harmdata, '/') + 1; offset = getChordRootInterval(ptr, keyinfo); } if (keymode) { // minor mode (harmonic minor) if (strstr(abuffer, "-vii") != 0) { output = E_base40_min7; } else if (strstr(abuffer, "vii") != 0) { output = E_base40_maj7; } else if (strstr(abuffer, "-VII") != 0) { output = E_base40_min7; } else if (strstr(abuffer, "VII") != 0) { output = E_base40_maj7; } else if (strstr(abuffer, "#vi") != 0) { output = E_base40_maj6; } else if (strstr(abuffer, "vi") != 0) { output = E_base40_min6; } else if (strstr(abuffer, "#VI") != 0) { output = E_base40_maj6; } else if (strstr(abuffer, "VI") != 0) { output = E_base40_min6; } else if (strstr(abuffer, "iv") != 0) { output = E_base40_per4; } else if (strstr(abuffer, "IV") != 0) { output = E_base40_per4; } else if (strstr(abuffer, "#iii") != 0) { output = E_base40_maj3; } else if (strstr(abuffer, "#III") != 0) { output = E_base40_maj3; } else if (strstr(abuffer, "iii") != 0) { output = E_base40_min3; } else if (strstr(abuffer, "III") != 0) { output = E_base40_min3; } else if (strstr(abuffer, "-ii") != 0) { output = E_base40_min2; } else if (strstr(abuffer, "-II") != 0) { output = E_base40_min2; } else if (strstr(abuffer, "ii") != 0) { output = E_base40_maj2; } else if (strstr(abuffer, "II") != 0) { output = E_base40_maj2; } else if (strstr(abuffer, "N") != 0) { output = E_base40_min2; } else if (strstr(abuffer, "v") != 0) { output = E_base40_per5; } else if (strstr(abuffer, "V") != 0) { output = E_base40_per5; } else if (strstr(abuffer, "i") != 0) { output = E_base40_per1; } else if (strstr(abuffer, "I") != 0) { output = E_base40_per1; } else if (strstr(abuffer, "Lt") != 0) { output = E_base40_aug4; } else if (strstr(abuffer, "Gn") != 0) { output = E_base40_aug4; } else if (strstr(abuffer, "Fr") != 0) { output = E_base40_aug4; } else { output = E_base40_rest; } } else { // major mode if (strstr(abuffer, "-vii") != 0) { output = E_base40_min7; } else if (strstr(abuffer, "vii") != 0) { output = E_base40_maj7; } else if (strstr(abuffer, "-VII") != 0) { output = E_base40_min7; } else if (strstr(abuffer, "VII") != 0) { output = E_base40_maj7; } else if (strstr(abuffer, "-vi") != 0) { output = E_base40_min6; } else if (strstr(abuffer, "vi") != 0) { output = E_base40_maj6; } else if (strstr(abuffer, "-VI") != 0) { output = E_base40_min6; } else if (strstr(abuffer, "VI") != 0) { output = E_base40_maj6; } else if (strstr(abuffer, "iv") != 0) { output = E_base40_per4; } else if (strstr(abuffer, "IV") != 0) { output = E_base40_per4; } else if (strstr(abuffer, "-iii") != 0) { output = E_base40_min3; } else if (strstr(abuffer, "-III") != 0) { output = E_base40_min3; } else if (strstr(abuffer, "iii") != 0) { output = E_base40_maj3; } else if (strstr(abuffer, "III") != 0) { output = E_base40_maj3; } else if (strstr(abuffer, "-ii") != 0) { output = E_base40_min2; } else if (strstr(abuffer, "-II") != 0) { output = E_base40_min2; } else if (strstr(abuffer, "ii") != 0) { output = E_base40_maj2; } else if (strstr(abuffer, "II") != 0) { output = E_base40_maj2; } else if (strstr(abuffer, "N") != 0) { output = E_base40_min2; } else if (strstr(abuffer, "v") != 0) { output = E_base40_per5; } else if (strstr(abuffer, "V") != 0) { output = E_base40_per5; } else if (strstr(abuffer, "i") != 0) { output = E_base40_per1; } else if (strstr(abuffer, "I") != 0) { output = E_base40_per1; } else if (strstr(abuffer, "Lt") != 0) { output = E_base40_aug4; } else if (strstr(abuffer, "Gn") != 0) { output = E_base40_aug4; } else if (strstr(abuffer, "Fr") != 0) { output = E_base40_aug4; } else { output = E_base40_rest; } } if (output < 0) { return output; } else { return (output + offset) % 40; } } ////////////////////////////// // // checkOptions -- validate and process command-line options. // void checkOptions(Options& opts, int argc, char* argv[]) { opts.define("debug=b"); // determine bad input line num opts.define("author=b"); // author of program opts.define("version=b"); // compilation info opts.define("example=b"); // example usages opts.define("help=b"); // short description opts.process(argc, argv); // handle basic options: if (opts.getBoolean("author")) { cout << "Written by Craig Stuart Sapp, " << "craig@ccrma.stanford.edu, September 2013" << endl; exit(0); } else if (opts.getBoolean("version")) { cout << argv[0] << ", version: 23 September 2013" << endl; cout << "compiled: " << __DATE__ << endl; cout << MUSEINFO_VERSION << endl; exit(0); } else if (opts.getBoolean("help")) { usage(opts.getCommand().c_str()); exit(0); } else if (opts.getBoolean("example")) { example(); exit(0); } } ////////////////////////////// // // example -- example usage of the quality program // void example(void) { cout << " \n" << endl; } ////////////////////////////// // // usage -- gives the usage statement for the meter program // void usage(const char* command) { cout << " \n" << endl; } // md5sum: 4602c199c13791b9e66a4e02bdf59184 dimuth.cpp [20170605]