// // Programmer: Craig Stuart Sapp // Creation Date: Mon Nov 12 22:57:24 PST 2012 // Last Modified: Mon Nov 12 22:57:30 PST 2012 // Filename: ...sig/examples/all/menchop.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/menchop.cpp // Syntax: C++; museinfo // // Description: Extract music with a specific mensurations from input. // // Limitations: Presumes no spine splits or subtracks. // #include "humdrum.h" #include "PerlRegularExpression.h" #include // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void processFile (const char* filename); void processTrack (HumdrumFile& infile, int track, const char* basename); char* getFileName (char* buffer, HumdrumFile& infile, int line, const char* basename, int track); char* buildFileName (char* buffer, const char* basename, int track, int line, const char* met); // global variables Options options; // database for command-line arguments int debugQ = 0; // used with the --debug option int jrpQ = 0; // used with --jrp option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile; // process the command-line options checkOptions(options, argc, argv); string filename = ""; int i; for (i=1; i<=options.getArgCount(); i++) { filename = options.getArg(i); processFile(filename.c_str()); } return 0; } /////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // processFile -- // void processFile(const char* filename) { Array basename; basename.setSize(strlen(filename)+1); strcpy(basename.getBase(), filename); PerlRegularExpression pre; pre.sar(basename, ".*/", ""); pre.sar(basename, "\\....$", ""); Array kerntracks; HumdrumFile infile(filename); infile.getTracksByExInterp(kerntracks, "**kern"); int i; for (i=0; i shortname; shortname.setSize(strlen(basename)+1); strcpy(shortname.getBase(), basename); PerlRegularExpression pre; if (jrpQ) { pre.sar(shortname, "-.*", ""); } for (i=0; i= 0)) { output << "*-" << endl; } if (output.is_open()) { output.close(); } cout << "!!FILENAME: " << buffer << endl; output.open(buffer, ios::out); if (!output.is_open()) { cerr << "ERROR: cannot write to " << buffer << endl; exit(1); } output << "!!original-filename:\t"<< basename << ".krn" << endl; if (exinterpline >= 0) { output << "**kern" << endl; if (notecount > 1) { // how to deal with tied notes starting a segement // will need to be considered. In this case the tied // note will (probably) be ignored. output << "!noff:" << track << ";" << notecount+1 << endl; } } } dataQ = 0; } } if (infile[i].isData()) { dataQ = 1; } if (strcmp(infile[i][0], "*-") == 0) { endQ = 1; } for (j=0; j