// // Programmer: Craig Stuart Sapp // Creation Date: Fri May 10 12:40:06 PDT 2002 // Last Modified: Fri May 10 12:40:09 PDT 2002 // Last Modified: Tue Aug 26 01:37:37 PDT 2008 (allow multiple input files) // Filename: ...sig/examples/all/pitchhist.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/pitchhist.cpp // Syntax: C++; museinfo // // Description: Generate pitch histograms of **kern data in Humdrum files. // #include "humdrum.h" #include // function declarations void checkOptions(Options& opts, int argc, char* argv[]); void example(void); void usage(const char* command); void printHistogram(Array& histogram); void getHistogram(Array& histogram, HumdrumFile& infile, double starttime, double stoptime); // interface variables Options options; // database for command-line arguments double starttime = 0.0; double stoptime = -1.0; int verboseQ = 0; // used with -v option int pcQ = 1; // used with -o option int restQ = 0; // used with -r option int base40Q = 0; // used with -b option int fillQ = 0; // used with -f option int countQ = 0; // used with -c option int normalizeQ = 0; // used with -n option int fifthsQ = 0; // used with -5 option int cstyleQ = 0; // used with -C option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile; // process the command-line options checkOptions(options, argc, argv); // figure out the number of input files to process int numinputs = options.getArgCount(); Array histogram(1001); Array temphistogram(1001); histogram.zero(); temphistogram.zero(); for (int i=0; i 0.0) { for (i=0; i<1001; i++) { histogram[i] /= sum; } } } printHistogram(histogram); return 0; } /////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // printHistogram -- // void printHistogram(Array& histogram) { int i; char buffer[256] = {0}; int findex = 0; if (verboseQ) { for (i=0; i39 && i<1000) { continue; } if (!base40Q && pcQ && i >12 && i<1000) { continue; } if (!base40Q && i>127 && i<1000) { continue; } if (restQ == 0 && i >= 1000) { continue; } if (!fillQ && histogram[i] == 0.0) { continue; } if (base40Q) { if (i < 1000) { if (pcQ) { if (fifthsQ) { findex = (17 + i * 23) % 40; Convert::base40ToKern(buffer, findex+4*40); if (buffer[0] == '\0') { continue; } } else { Convert::base40ToKern(buffer, i+4*40); if (buffer[0] == '\0') { continue; } } } else { if (histogram[i] == 0.0) { continue; } Convert::base40ToKern(buffer, i); } } else { strcpy(buffer, "rest"); } if (base40Q && pcQ && fifthsQ) { cout << buffer << ":\t" << histogram[findex] << endl; } else { cout << buffer << ":\t" << histogram[i] << endl; } } else { cout << i << ":\t" << histogram[i] << endl; } } } else { if (base40Q) { } else { if (cstyleQ) cout << "{"; for (i=0; i<12; i++) { cout << histogram[i]; if (i < 11) { if (cstyleQ) cout << ","; cout << " "; } } if (restQ) { if (cstyleQ) cout << ","; cout << " " << histogram[1000]; } if (cstyleQ) cout << "};"; cout << endl; } } } ////////////////////////////// // // getHistogram -- // void getHistogram(Array& histogram, HumdrumFile& infile, double starttime, double stoptime) { if (stoptime <= starttime) { stoptime = infile.getTotalDuration(); } histogram.zero(); int i, j, k; double duration = 0.0; int tokencount = 0; int pitch = 0; char buffer[1024] = {0}; for (i=0; i stoptime) { break; } if (!infile[i].isData()) { continue; } for (j=0; j