// // Programmer: Craig Stuart Sapp // Creation Date: Sun Feb 6 14:33:36 PST 2011 // Last Modified: Sun Feb 6 14:33:39 PST 2011 // Filename: ...sig/examples/all/satb2gs.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/satb2gs.cpp // Syntax: C++; museinfo // // Description: Converts Soprano/Alto/Tenor/Bass staves into // Grand-staff style. // #include #include #include #include /* for current time/date */ #include #include "humdrum.h" #include "PerlRegularExpression.h" using namespace std; ////////////////////////////////////////////////////////////////////////// // function declarations: void checkOptions (Options& opts, int argc, char** argv); void example (void); void usage (const char* command); void convertData (HumdrumFile& infile); int getSatbTracks (vector& tracks, HumdrumFile& infile); void printSpine (HumdrumFile& infile, int row, int col, vector& satbtracks); void printExInterp (HumdrumFile& infile, int line, vector& tracks); void printLastLine (HumdrumFile& infile, int line, vector& tracks); // User interface variables: Options options; int debugQ = 0; // used with --debug option ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { checkOptions(options, argc, argv); HumdrumStream streamer(options); HumdrumFile infile; while (streamer.read(infile)) { convertData(infile); } return 0; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // convertData -- data is assumed to be in the order from // bass, tenor, alto, soprano, with non-**kern data found // in any order. Only the first four **kern spines in the file // will be considered. // void convertData(HumdrumFile& infile) { vector satbtracks(4); int exinterpline = getSatbTracks(satbtracks, infile); int i, j; int lastline = -1; for (i=0; i& tracks) { int track; stringstream output; for (int j=0; j& tracks) { stringstream output; int j; int track; // first print exclusive interpretations for (j=0; j& satbtracks) { int track = infile[row].getPrimaryTrack(col); int j, k; int target = -1; for (k=0; k<(int)satbtracks.size(); k++) { if (track == satbtracks[k]) { if (k % 2 == 0) { target = satbtracks[k+1]; } else { target = satbtracks[k-1]; } break; } } if (target < 0) { // does not need to be switched cout << infile[row][col]; return; } // print the SAT or B token(s) (there should be only one token for each) // // If a tenor has a fermata and a bass has a fermata and both are // the same duration, then hide the tenor's fermata. // // If an alto has a fermata and a soprano has a fermata and both are // the same duration, then hide the alto's fermata. // // first identify the column for each voice, considering only the first // layer, if there are multiple layers. vector cols(4, -1); for (j=0; j= 0) { continue; } if (track == satbtracks[k]) { cols[k] = j; } } } PerlRegularExpression pre; string strang; int count = 0; for (j=0; j 0) { cout << '\t'; } strang = infile[row][j]; pre.sar(strang, "^\\*clef", "!*clef", ""); if (infile[row].isData()) { if ((cols[0] == col) && (strchr(infile[row][col], ';') != NULL)) { RationalNumber tenordur; RationalNumber bassdur; tenordur = Convert::kernToDurationR(infile[row][cols[0]]); bassdur = Convert::kernToDurationR(infile[row][cols[1]]); if (tenordur == bassdur) { pre.sar(strang, ";", ";y", "g"); // hide fermata } } if ((cols[3] == col) && (strchr(infile[row][col], ';') != NULL)) { RationalNumber altodur; RationalNumber sopranodur; altodur = Convert::kernToDurationR(infile[row][cols[3]]); sopranodur = Convert::kernToDurationR(infile[row][cols[2]]); if (altodur == sopranodur) { pre.sar(strang, ";", ";y", "g"); // hide fermata } } } cout << strang; count++; } } } /////////////////////////////// // // getSatbTracks -- return the primary track numbers of the satb spines. // // int getSatbTracks(vector& tracks, HumdrumFile& infile) { int i, j; int output = -1; tracks.resize(0); int track; for (i=0; i