// // Programmer: Craig Stuart Sapp // Creation Date: Wed Jan 10 12:32:52 PST 2001 // Last Modified: Wed Jan 10 12:32:54 PST 2001 // Filename: ...sig/examples/all/ccheck.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/ccheck.cpp // Syntax: C++; museinfo // // Description: determine the chord information for the given region // #include "humdrum.h" #include #include // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void printAnalysis (HumdrumFile& infile, Array& rhylev); void usage (const char* command); int findMinimum (Array& values); int findBestMode (Array& values, int majorbest, int minorbest); int findBestTonic (Array& values, Array& tonicscores); // global variables Options options; // database for command-line arguments int debugQ = 0; // used with the --debug option int appendQ = 0; // used with the -a option int compoundQ = 1; // used with the -c option double neighbornorm[40] = { 0.0000000000000, // C C 0 0 0 1.4142135623731, // C C# 1 1 -1 2.8284271247462, // C C## 2 2 -2 100000.0, // invalid 3 3.0000000000000, // C D-- 4 -3 0 2.2360679774998, // C D- 5 -2 -1 2.2360679774998, // C D 6 -1 -2 3.0000000000000, // C D# 7 0 -3 4.0000000000000, // C D## 8 4 0 100000.0, // invalid 9 2.2360679774998, // C E-- 10 -1 2 1.0000000000000, // C E- 11 0 1 1.0000000000000, // C E 12 1 0 2.2360679774998, // C E# 13 2 -1 3.6055512754640, // C E## 14 3 -2 3.1622776601684, // C F-- 15 -3 1 2.0000000000000, // C F- 16 -2 0 1.4142135623731, // C F 17 -1 -1 2.0000000000000, // C F# 18 0 -2 3.1622776601684, // C F## 19 1 -3 100000.0, // invalid 20 3.1622776601684, // C G-- 21 -1 3 2.0000000000000, // C G- 22 0 2 1.4142135623731, // C G 23 1 1 2.0000000000000, // C G# 24 2 0 3.1622776601684, // C G## 25 3 -1 100000.0, // invalid 26 2.2360679774998, // C A-- 27 -2 1 1.0000000000000, // C A- 28 -1 0 1.0000000000000, // C A 29 0 -1 2.2360679774998, // C A# 30 1 -2 3.6055512754640, // C A## 31 2 -3 100000.0, // invalid 32 3.0000000000000, // C B-- 33 0 3 2.2360679774998, // C B- 34 1 2 2.2360679774998, // C B 35 2 1 3.0000000000000, // C B# 36 3 0 4.1231056256176, // C B## 37 4 -1 2.8284271247462, // C C-- -2 -2 2 1.4142135623731, // C C- -1 -1 1 }; /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile; Array rhylev; // process the command-line options checkOptions(options, argc, argv); // figure out the number of input files to process int numinputs = options.getArgCount(); int most = 0; Array values; values.setSize(0); char buffer[128] = {0}; char buffer2[128] = {0}; Array tonicscores; for (int i=0; i& values, int majorbest, int minorbest) { int majorscore = 0; int minorscore = 0; double tscore1, tscore2; int majindexnatu, majindexflat; int minindexnatu, minindexflat; majindexnatu = (12 + majorbest) % 40; majindexflat = (11 + majorbest - 1 + 40) % 40; tscore1 = neighbornorm[majindexnatu] * values[majindexnatu]; tscore2 = neighbornorm[majindexflat] * values[majindexflat]; if (tscore1 < tscore2) { majorscore += 1; } else { majorscore += -1; } minindexnatu = (12 + minorbest) % 40; minindexflat = (11 + minorbest - 1 + 40) % 40; tscore1 = neighbornorm[minindexnatu] * values[minindexnatu]; tscore2 = neighbornorm[minindexflat] * values[minindexflat]; if (tscore1 > tscore2) { minorscore += 1; } else { minorscore += -1; } majindexnatu = (29 + majorbest) % 40; majindexflat = (29 + majorbest - 1 + 40) % 40; tscore1 = neighbornorm[majindexnatu] * values[majindexnatu]; tscore2 = neighbornorm[majindexflat] * values[majindexflat]; if (tscore1 < tscore2) { majorscore += 1; } else { majorscore += -1; } minindexnatu = (29 + minorbest) % 40; minindexflat = (29 + minorbest - 1 + 40) % 40; tscore1 = neighbornorm[minindexnatu] * values[minindexnatu]; tscore2 = neighbornorm[minindexflat] * values[minindexflat]; if (tscore1 > tscore2) { minorscore += 1; } else { minorscore += -1; } majindexnatu = (35 + majorbest) % 40; majindexflat = (35 + majorbest - 1 + 40) % 40; tscore1 = neighbornorm[majindexnatu] * values[majindexnatu]; tscore2 = neighbornorm[majindexflat] * values[majindexflat]; if (tscore1 < tscore2) { majorscore += 1; } else { majorscore += -1; } minindexnatu = (35 + minorbest) % 40; minindexflat = (35 + minorbest - 1 + 40) % 40; tscore1 = neighbornorm[minindexnatu] * values[minindexnatu]; tscore2 = neighbornorm[minindexflat] * values[minindexflat]; if (tscore1 > tscore2) { minorscore += 1; } else { minorscore += -1; } if (majorscore > minorscore) { return 0; } else { return 1; } } ////////////////////////////// // // findMinimum -- // int findMinimum(Array& values) { int i; int min = 0; for (i=1; i& values, Array& tonicscores) { int i, j; tonicscores.setSize(values.getSize()); tonicscores.zero(); int maj[7] = {0, 6, 12, 17, 23, 29, 35}; for (i=0; i& rhylev) { int i; if (appendQ) { for (i=0; i