// // Programmer: Craig Stuart Sapp // Creation Date: Mon Jul 18 11:23:42 PDT 2005 // Last Modified: Mon Jul 18 11:23:46 PDT 2005 // Last Modified: Sun Mar 2 18:58:48 PST 2008 (added -l and -i options) // Last Modified: Mon Mar 3 13:46:34 PST 2008 (added -r option) // Filename: ...sig/examples/all/thrux.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/thrux.cpp // Syntax: C++; museinfo // // Description: C++ implementation of the Humdrum Toolkit thru command. // #include "humdrum.h" #include #include #ifndef OLDCPP #include #else #include #endif // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void processData (HumdrumFile& infile); void usage (const char* command); void getLabelSequence (Array >& labelsequence, const char* string); int getLabelIndex (Array >& labels, Array& key); void printLabelList (HumdrumFile& infile); void printLabelInfo (HumdrumFile& infile); int getBarline (HumdrumFile& infile, int line); int adjustFirstBarline (HumdrumFile& infile); // global variables Options options; // database for command-line arguments const char* variation = ""; // used with -v option int listQ = 0; // used with -l option int infoQ = 0; // used with -i option int keepQ = 0; // used with -k option const char* realization = ""; // used with -r option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile, outfile; // process the command-line options checkOptions(options, argc, argv); // figure out the number of input files to process int numinputs = options.getArgCount(); for (int i=0; i", 2) != 0) { continue; // ignore non-labels } //if (strchr(infile[i][0], '[') != NULL) { // continue; // ignore realizations //} length = strlen(infile[i][0]); for (j=2; j labellines; labellines.setSize(1000); labellines.setGrowth(1000); labellines.setSize(0); for (i=0; i", 2) != 0) { continue; // ignore non-labels } if (strchr(infile[i][0], '[') != NULL) { cout << "!!>"; length = strlen(infile[i][0]); for (j=2; j barlines; barlines.setSize(1000); barlines.allowGrowth(0); barlines.setAll(-1); for (i=0; i 0) { barlines[0] = adjustFirstBarline(infile); } int startline; int endline; double startbeat; double endbeat; double duration; cout << "**label\t**sline\t**eline\t**sbeat\t**ebeat\t**dur\t**bar\n"; for (i=0; i 0) { break; } sscanf(infile[i][0], "=%d", &number); break; } return number; } ////////////////////////////// // // getBarline -- // int getBarline(HumdrumFile& infile, int line) { if (infile[line].getAbsBeat() == 0) { return 0; } int i; int missingcount = 0; int number = -1; for (i=line; i>0; i--) { if (infile[i].getType() != E_humrec_data_measure) { continue; } if (sscanf(infile[i][0], "=%d", &number) == 1) { break; } else { missingcount++; } if (missingcount > 1) { break; } } return number; } ////////////////////////////// // // checkOptions -- validate and process command-line options. // void checkOptions(Options& opts, int argc, char* argv[]) { opts.define("v|variation=s:", "Choose the expansion variation"); opts.define("l|list=b:", "Print list of labels in file"); opts.define("k|keep=b:", "Keep variation interpretations"); opts.define("i|info=b:", "Print info list of labels in file"); opts.define("r|realization=s:", "alternate relaization label sequence"); opts.define("d|debug=b"); // determine bad input line num opts.define("author=b"); // author of program opts.define("version=b"); // compilation info opts.define("example=b"); // example usages opts.define("h|help=b"); // short description opts.process(argc, argv); // handle basic options: if (opts.getBoolean("author")) { cout << "Written by Craig Stuart Sapp, " << "craig@ccrma.stanford.edu, May 1998" << endl; exit(0); } else if (opts.getBoolean("version")) { cout << argv[0] << ", version: Nov 2000" << endl; cout << "compiled: " << __DATE__ << endl; cout << MUSEINFO_VERSION << endl; exit(0); } else if (opts.getBoolean("help")) { usage(opts.getCommand()); exit(0); } else if (opts.getBoolean("example")) { example(); exit(0); } variation = opts.getString("variation"); realization = opts.getString("realization"); listQ = opts.getBoolean("list"); infoQ = opts.getBoolean("info"); keepQ = opts.getBoolean("keep"); } ////////////////////////////// // // example -- example usage of the sonority program // void example(void) { cout << " \n" << endl; } ////////////////////////////// // // processData -- // void processData(HumdrumFile& infile) { Array > labelsequence; labelsequence.setSize(1000); labelsequence.setGrowth(1000); labelsequence.setSize(0); Array > labels; labels.setSize(1000); labels.setGrowth(1000); labels.setSize(0); Array startline; startline.setSize(1000); startline.setGrowth(1000); startline.setSize(0); Array stopline; stopline.setSize(1000); stopline.setGrowth(1000); stopline.setSize(0); int header = -1; int footer = -1; char labelsearch[1024] = {0}; strcpy(labelsearch, "*>"); strcat(labelsearch, variation); strcat(labelsearch, "["); int length = strlen(labelsearch); // check for label to expand int i; int foundlabel = 0; if (realization[0] == '\0') { for (i=0; i", infile[i][0], 2) != 0) { continue; } if (strchr(infile[i][0], '[') != NULL) { continue; } if (strchr(infile[i][0], ']') != NULL) { continue; } if (labels.getSize() == 0) { header = i-1; } label = &(infile[i][0][2]); llen = strlen(label); index = labels.getSize(); location = i-1; if (startline.getSize() > 0) { stopline.append(location); } labels.setSize(index+1); labels[index].setSize(llen+1); strcpy(labels[index].getBase(), label); startline.append(i); } // cout << "FOOTER = " << footer << endl; // cout << "HEADER = " << header << endl; // for (i=0; i", 2) == 0) { if (strchr(infile[i][0], '[') != NULL) { continue; } } } } cout << infile[i] << "\n"; if (strncmp(infile[i][0], "**", 2) == 0) { for (j=0; j", 2) == 0) { if (strchr(infile[j][0], '[') != NULL) { continue; } } } } cout << infile[j] << "\n"; } } // print footer: for (i=footer; i", 2) == 0) { if (strchr(infile[i][0], '[') != NULL) { continue; } } } } cout << infile[i] << "\n"; } } ////////////////////////////// // // getLabelIndex -- // int getLabelIndex(Array >& labels, Array& key) { int i; for (i=0; i >& labelsequence, const char* string) { int slength = strlen(string); char* sdata = new char[slength+1]; strcpy(sdata, string); const char* ignorecharacters = ", [] "; int length = 0; int index; char* strptr = strtok(sdata, ignorecharacters); while (strptr != NULL) { length = strlen(strptr); labelsequence.setSize(labelsequence.getSize() + 1); index = labelsequence.getSize() - 1; labelsequence[index].setSize(length+1); strcpy(labelsequence[index].getBase(), strptr); strptr = strtok(NULL, ignorecharacters); } delete [] sdata; } ////////////////////////////// // // usage -- gives the usage statement for the sonority program // void usage(const char* command) { cout << " \n" << endl; } // md5sum: d1a47ae31dbed6847227a405ca13f3c5 thrux.cpp [20090508]