// // Programmer: Craig Stuart Sapp // Creation Date: Fri Mar 4 07:02:41 PST 2011 // Last Modified: Fri Mar 4 07:02:43 PST 2011 // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/hexa.cpp // Syntax: C++; museinfo // // Description: Describe the hexachord position of notes. // #include #include /* for current time/date */ #ifndef OLDCPP #include #include #include #define SSTREAM stringstream #define CSTRING str().c_str() using namespace std; #else #include #include #ifdef VISUAL #include #else #include #endif #define SSTREAM strstream #define CSTRING str() #endif #include "string.h" #include "humdrum.h" #include "PerlRegularExpression.h" #include "MuseData.h" #include "MuseDataSet.h" #include "CheckSum.h" #include "SigString.h" ////////////////////////////////////////////////////////////////////////// // function declarations: void checkOptions (Options& opts, int argc, char** argv); void example (void); void usage (const char* command); void extractPitches (Array > >& pitches, HumdrumFile& infile); void printData (Array > >& pitches, HumdrumFile& infile); void printLine (HumdrumFile& infile, int line, Array > >& pitches, int offset); void printDataToken (Array > >& pitches, int line, int col, char prefix, int interval); void printKernTokenAndData (HumdrumFile& infile, int line, int col, Array > >& pitches, int offset); char hexPos (int interval); void printSingleColumnLine (HumdrumRecord& arecord, int offset); // User interface variables: Options options; int debugQ = 0; // used with --debug option ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { HumdrumFile infile; // initial processing of the command-line options checkOptions(options, argc, argv); if (options.getArgCount() < 1) { infile.read(cin); } else { infile.read(options.getArg(1)); } infile.analyzeRhythm("4"); Array > > pitches; extractPitches(pitches, infile); printData(pitches, infile); return 0; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // printData -- // void printData(Array > >& pitches, HumdrumFile& infile) { int i; int offset = 75; for (i=0; i pos; pos.setSize(strlen(pre.getSubmatch(2))+1); strcpy(pos.getBase(), pre.getSubmatch()); Array > tokens; PerlRegularExpression pre2; pre2.getTokens(tokens, "[v,\\s]+", pre.getSubmatch()); int value; cout << pre.getSubmatch(1); cout << "v"; int i; for (i=0; i > >& pitches, int offset) { int& i = line; int j; int started = 0; for (j=0; j > >& pitches, int offset) { int& i = line; int& j = col; int m; PerlRegularExpression pre; Array strang; strang.setSize(strlen(infile[i][j])+1); strcpy(strang.getBase(), infile[i][j]); if (pre.search(strang, "^(!LO:TX.*Y=)(\\d+)(.*)")) { // text printed below the staff, but need to drop it so that // it does not collide with the text (which cannot be adjsted // in muse2ps). cout << pre.getSubmatch(1); int value = atoi(pre.getSubmatch(2)); // value = -50; cout << value; cout << ":hide"; // just hide text so that it is not displayed cout << pre.getSubmatch(3); } else { cout << strang; } if (infile[i].isLocalComment()) { for (m=0; m<3; m++) { cout << "\t!"; } return; } if (infile[i].isMeasure()) { for (m=0; m<3; m++) { cout << "\t" << infile[i][j]; } return; } if (infile[i].isInterpretation()) { if (strncmp(infile[i][j], "**", 2) == 0) { for (m=0; m<3; m++) { cout << "\t**hexa"; } return; } if (strcmp(infile[i][j], "*-") == 0) { for (m=0; m<3; m++) { cout << "\t*-"; } return; } for (m=0; m<3; m++) { cout << "\t*"; } return; } char prefix[3] = {'f', 'c', 'g'}; int interval[3] = {17, 0, 23}; for (m=0; m<3; m++) { cout << "\t"; printDataToken(pitches, line, col, prefix[m], interval[m]); } } ////////////////////////////// // // printDataToken -- // void printDataToken(Array > >& pitches, int line, int col, char prefix, int interval) { int& i = line; int& j = col; int k; char pos; if (pitches[i][j].getSize() == 0) { cout << "."; return; } for (k=0; k 0) { cout << " "; } pos = hexPos((pitches[line][col][k] - (2 + interval)) % 40); cout << prefix << pos; } } ////////////////////////////// // // hexPos -- // char hexPos(int interval) { switch (interval) { case 0: return '1'; case 6: return '2'; case 12: return '3'; case 17: return '4'; case 23: return '5'; case 29: return '6'; } return 'X'; } ////////////////////////////// // // extractPitches -- // void extractPitches(Array > >& pitches, HumdrumFile& infile) { pitches.setSize(infile.getNumLines()); PerlRegularExpression pre; int i, j, k; int value; int tokencount; char buffer[1024] = {0}; for (i=0; i