// // Programmer: Craig Stuart Sapp // Creation Date: Wed Jan 12 14:12:54 PST 2005 // Last Modified: Wed Jan 12 15:09:07 PST 2005 // Last Modified: Tue Apr 7 21:05:20 PDT 2009 Added -F option // Last Modified: Sat Apr 6 22:23:29 PDT 2013 Enabled multiple segment input // Filename: ...sig/examples/all/scaletype.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/scaletype.cpp // Syntax: C++; museinfo // // Description: Identifies **kern data as pentatonic, sexatonic, // or heptatonic. // #include "humdrum.h" // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void analyzeFile (HumdrumFile& infile, Array& pc12, Array& pc40); void printAnalysis (HumdrumFile& infile, Array& pc12, Array& pc40, const string& filename); int countPitchClasses (Array& pc12); void printPitches (Array& pc40); // global variables Options options; // database for command-line arguments int debugQ = 0; // used with the --debug option int shortQ = 0; // used with the -s option int pitchesQ = 0; // used with the -p option int suppressQ = 0; // used with -F option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFileSet infiles; // process the command-line options checkOptions(options, argc, argv); string filename = ""; int i; Array pc12; // twelve-tone pitch-class note histogram Array pc40; // base-40 enharmonic pitch-class note histogram pc12.setSize(12); pc12.allowGrowth(0); pc12.setAll(0); pc40.setSize(40); pc40.allowGrowth(0); pc40.setAll(0); int numinputs = options.getArgCount(); if (numinputs < 1) { infiles.read(cin); } else { for (i=0; i& pc12, Array& pc40, const string& filename) { int setcount = countPitchClasses(pc12); if (filename[0] != '\0') { if (shortQ && (strrchr(filename.c_str(), '/') != NULL)) { cout << strrchr(filename.c_str(), '/')+1 << ":\t"; } else { cout << filename << ":\t"; } } if (setcount < 5) { cout << "toofew"; } else if (setcount == 5) { cout << "pentatonic"; } else if (setcount == 6) { cout << "hexatonic"; } else if (setcount == 7) { cout << "heptatonic"; } else if (setcount > 7) { cout << "chromatic"; } else { cout << "error"; } if (pitchesQ) { cout << "\t"; printPitches(pc40); } cout << endl; } /////////////////////////////// // // printPitches -- // void printPitches(Array& pc40) { int i; char buffer[128] = {0}; int upc = countPitchClasses(pc40); int count = 0; for (i=0; i 0) { cout << Convert::base40ToKern(buffer, i + 120); count++; if (count < upc) { cout << " "; } } } } ////////////////////////////// // // countPitchClasses -- // int countPitchClasses(Array& pc12) { int i; int sum = 0; for (i=0; i 0) { sum++; } } return sum; } ////////////////////////////// // // analyzeFile -- count the twelve-tone pitch classes in all **kern spines. // void analyzeFile(HumdrumFile& infile, Array& pc12, Array& pc40) { pc12.setAll(0); pc40.setAll(0); char buffer[1024] = {0}; int i, j, k; int tokencount = 0; int notenum; for (i=0; i