// // Programmer: Craig Stuart Sapp // Creation Date: Tue Jan 16 11:25:31 PST 2001 // Last Modified: Mon Jan 29 14:02:45 PST 2001 // Last Modified: Fri Feb 2 12:05:51 PST 2001 (added weights display) // Last Modified: Tue Feb 6 19:13:51 PST 2001 (fixed -r option for large dur) // Filename: ...sig/examples/all/croot.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/croot.cpp // Syntax: C++; museinfo // // Description: determine the root of a chord in a given timespan. // #include "humdrum.h" #include #include // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); int findMinimum (Array& values); // 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 rval = 1.0; // used with the -r option double rlevel = 1.0; // used with the -r option int srhythm = 4; // used with the -r option double empirical1 = -4; // used with the --e1 option double empirical2 = -3; // used with the --e2 option double sx = 0.578; // used with the --sx option double sy = 1.0; // used with the --sx option int octave = -1; // used with the -o option int weightsQ = 0; // used with the -w option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile; Array rhylev; Array tonicscores; // 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}; for (int i=0; i= rhylev[line]) { // find ending point: int endline = line+1; while (endline < infile.getNumLines()) { if (infile[endline].getType() != E_humrec_data) { endline++; continue; } if (fabs(rval * infile[endline].getAbsBeat() - (int)(rval * infile[endline].getAbsBeat())) < 0.001) { break; } endline++; } if (endline >= infile.getNumLines()) { endline = infile.getNumLines() - 1; } most = infile.analyzeChordProbability(values, line, endline - 1, rhylev, empirical1, empirical2, sx, sy); if (most >= 0) { if (octave < 0) { nextroot = (most + 2) % 40 + 80; if (abs(nextroot + 40 - lastroot) < 13) { nextroot += 40; } else if (abs(nextroot - 40 - lastroot) < 13) { nextroot -= 40; } } else { nextroot = (most + 2) % 40 + 40 * octave; } Convert::base40ToKern(buffer, nextroot); lastroot = nextroot; } else { // handle rests strcpy(buffer, "r"); } cout << "\t"; if (infile[line].getDuration() > 1.0/rval) { cout << Convert::durationToKernRhythm(buffer2, infile[line].getDuration()); } else { cout << srhythm; } if (values[most] == 0) { cout << "r"; } else { cout << buffer; if (weightsQ) { cout << "\t" << values[most]; } } // cout << " [" << line << ", " << endline-1 << "]"; cout << "\n"; } else { if (weightsQ) { cout << "\t.\t." << "\n"; } else { cout << "\t." << "\n"; } } } } return 0; } /////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // findMinimum -- // int findMinimum(Array& values) { int i; int min = 0; for (i=1; i