// // Programmer: Craig Stuart Sapp // Creation Date: Tue Feb 15 17:09:16 PST 2011 // Last Modified: Tue Feb 15 17:09:23 PST 2011 // Filename: ...sig/examples/all/fixdyna.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/lazydynam.cpp // Syntax: C++; museinfo // // Description: Fix crescendo and decrescendo symbols (wedges, hairpins). // #include "humdrum.h" #include "PerlRegularExpression.h" #ifndef OLDCPP using namespace std; #endif class Coord { public: int i, j; Coord(void) { } ~Coord() { } void clear(void) { i = j = -1; } }; /////////////////////////////////////////////////////////////////////////// // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void processFile (HumdrumFile& infile); void processDynamicSpine(HumdrumFile& infile, int track); void storeDynamSpine (Array >& data, HumdrumFile& infile, int track); // global variables Options options; // database for command-line arguments int debugQ = 0; // used with --debug option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile; // process the command-line options checkOptions(options, argc, argv); const char* filename; infile.clear(); // if no command-line arguments read data file from standard input int numinputs = options.getArgCount(); if (numinputs < 1) { infile.read(cin); } else { filename = options.getArg(1); infile.read(options.getArg(1)); } processFile(infile); cout << infile; return 0; } /////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // processFile -- // void processFile(HumdrumFile& infile) { int i, j; for (i=0; i > data; storeDynamSpine(data, infile, track); int i; int ii, jj; int crescX = 0; // interpreted crescendo (cresc. word) int decrescX = 0; // interpreted decrescendo (decresc. word) int crescy = 0; // hidden crescendo int decrescy = 0; // hidden decrescendo int crescState = 0; // active crescendo int decrescState = 0; // active decrescendo char buffer[1024] = {0}; Array buf; PerlRegularExpression pre; int xx, yy; if (debugQ) { cerr << "DATA SIZE = " << data.getSize() << endl; } for (i=0; i marker to initiate de/cresc. if (strchr(infile[ii][jj], '<') != NULL) { crescState = 1; } if (strchr(infile[ii][jj], '>') != NULL) { decrescState = 1; } if (strstr(infile[ii][jj], "X") != NULL) { decrescX = 1; } if (strstr(infile[ii][jj], "yy") != NULL) { decrescy = 1; } } // handle case where cresc/decresc ends data with nothing after it. if (crescState) { // end the crescendo xx = data.last()[0].i; yy = data.last()[0].j; if (debugQ) { cerr << "GOT HERE " << infile[xx][yy] << endl; } if ((xx < 0) || (yy < 0)) { return; } // this is a dynamic object of some sort so terminate // the crescendo on the previous item if (strchr(infile[xx][yy], '(') != NULL) { if (debugQ) { cerr << "GOT HERE " << infile[xx][yy] << endl; } // replace the '(' found on the previous data line buf.setSize(strlen(infile[xx][yy])+1); strcpy(buf.getBase(), infile[xx][yy]); pre.sar(buf, "\\(", "[", ""); // should only apply to last if (crescX) { pre.sar(buf, "\\[", "[", ""); crescX = 0; } if (crescy) { pre.sar(buf, "\\[", "[", ""); crescy = 0; } infile[xx].changeField(yy, buf.getBase()); crescState = 0; if (debugQ) { cerr << "DEACTIVATING CRESC 1" << endl; } } } else if (decrescState) { // end the decrescendo xx = data.last()[0].i; yy = data.last()[0].j; if (debugQ) { cerr << "GOT HERE " << infile[xx][yy] << endl; } if ((xx < 0) || (yy < 0)) { return; } // this is a dynamic object of some sort so terminate // the decrescendo on the previous item if (strchr(infile[xx][yy], ')') != NULL) { if (debugQ) { cerr << "GOT HERE " << infile[xx][yy] << endl; } // replace the '(' found on the previous data line buf.setSize(strlen(infile[xx][yy])+1); strcpy(buf.getBase(), infile[xx][yy]); pre.sar(buf, "\\)", "]", ""); // should only apply to last if (decrescX) { pre.sar(buf, "\\]", "]", ""); decrescX = 0; } if (decrescy) { pre.sar(buf, "\\]", "]", ""); decrescy = 0; } infile[xx].changeField(yy, buf.getBase()); decrescState = 0; if (debugQ) { cerr << "DEACTIVATING DECRESC 1" << endl; } } } } ////////////////////////////// // // storeDynamSpine -- make a list of the data spines for the given track // void storeDynamSpine(Array >& data, HumdrumFile& infile, int track) { data.setSize(infile.getNumLines()); data.setSize(0); Coord coord; int i, j; for (i=0; i