void getAlternateFactor(HumdrumFile& infile, RationalNumber& factor) { PerlRegularExpression pre; int i; int top; int bot; RationalNumber value; RationalNumber orig(1,1); getOriginalFactor(infile, orig); for (i=0; i<infile.getNumLines(); i++) { if (!infile[i].isBibliographic()) { continue; } if (!pre.search(infile[i][0], "^!!!rscale-alt\\s*:\\s*(\\d+)(/?)(\\d*)", "")) { continue; } top = atoi(pre.getSubmatch(1)); bot = 1; if (strlen(pre.getSubmatch(2)) != 0) { if (strlen(pre.getSubmatch(3)) != 0) { bot = atoi(pre.getSubmatch()); } } if (top == 0) { top = 1; } if (bot == 0) { bot = 1; } value.setValue(top, bot); factor = value * orig; return; } }
void printReferenceRecord(ostream& out, HumdrumFile& infile, int line) { int& i = line; PerlRegularExpression pre; if (!pre.search(infile[line][0], "^!!!([^:]+):(.*)$", "")) { out << "<tr valign=baseline><td colspan=" << infile.getMaxTracks() << ">"; out << "<font color=green>" << infile[i] << "</font></td></tr>"; return; } Array<char> description; char buffer[128] = {0}; infile[line].getBibliographicMeaning(description, pre.getSubmatch(1)); PerlRegularExpression pre2; pre2.sar(description, "\"", "", "g"); out << "<tr valign=baseline><td colspan=" << infile.getMaxTracks() << ">"; out << "<font color=green>"; out << "<span title=\""; out << infile[line].getBibKey(buffer); out << ": "; out << description; out << "\">"; out << "!!!"; out << pre.getSubmatch(1); out << ":"; out << pre.getSubmatch(2); out << "</span>"; out << "</font></td></tr>"; }
void printSingleKernSubtoken(const char* buff, RationalNumber& factor) { PerlRegularExpression pre; RationalNumber value; int level = 0; if (factor == 2) { level = 1; } else if (factor == 4) { level = 2; } if (!rebeamQ) { level = 0; } char prebuffer[1024] = {0}; char postbuffer[1024] = {0}; if (pre.search(buff, "([^\\d]*)(\\d+)(%?)(\\d*)(.*)", "")) { int top = atoi(pre.getSubmatch(2)); int bot; if (strlen(pre.getSubmatch(4)) != 0) { bot = atoi(pre.getSubmatch()); if (bot == 0) { bot = 1; } } else { bot = 1; } if (top == 0) { // handle cases where breve=0; long=00; maxima=000 int tcount = 0; int i; int len = strlen(buff); for (i=0; i<len; i++) { if (buff[i] == '0') { tcount++; } } top = 1; bot = int(pow(2.0,tcount)); } value.setValue(top, bot); value /= factor; // factor is duration so inverse strcpy(prebuffer, pre.getSubmatch(1)); strcpy(postbuffer, pre.getSubmatch(5)); cleanUpBeams(prebuffer, postbuffer, level); cout << prebuffer; printSpecialRational(value); // print stuff after numeric part of rhythm cout << postbuffer; } else { cout << buff; } }
int MuseData::getInitialTPQ(void) { int output = 0; if (data.getSize() == 0) { return output; } PerlRegularExpression pre; int i; if (data[0]->getType() == E_muserec_unknown) { // search for first line which starts with '$': for (i=0; i<data.getSize(); i++) { if (data[i]->getLength() <= 0) { continue; } if ((*data[i])[0] == '$') { if (pre.search(data[i]->getLine(), "Q:(\\d+)", "")) { output = atoi(pre.getSubmatch(1)); } break; } } } else { for (i=0; i<data.getSize(); i++) { if (data[i]->getType() == E_muserec_musical_attributes) { if (pre.search(data[i]->getLine(), "Q:(\\d+)", "")) { output = atoi(pre.getSubmatch(1)); } break; } } } return output; }
void addLabelHyperlinks(Array<char>& strang) { PerlRegularExpression pre; if (!pre.search(strang, "^\\*>(.*)\\[(.*)\\]", "")) { return; } char buffer[10123] = {0}; strcpy(buffer, "*>"); strcat(buffer, pre.getSubmatch(1)); strcat(buffer, "["); PerlRegularExpression pre2; Array<Array<char> > tokens; pre2.getTokens(tokens, ",", pre.getSubmatch(2)); int i; for (i=0; i<tokens.getSize(); i++) { strcat(buffer, "<a href=\"#"); strcat(buffer, tokens[i].getBase()); strcat(buffer, "\">"); strcat(buffer, tokens[i].getBase()); strcat(buffer, "</a>"); if (i < tokens.getSize() - 1) { strcat(buffer, ","); } } strcat(buffer, "]"); strang.setSize(strlen(buffer) + 1); strcpy(strang.getBase(), buffer); }
void getPartNames(HumdrumFile& infile, Array<Array<char> >& PartNames) { int i, j; PartNames.setSize(infile.getMaxTracks()+1); // 0 = unused for (i=0; i<PartNames.getSize(); i++) { PartNames[i].setSize(1); PartNames[i][0]= '\0'; } int abbreviationQ = 0; Array<int> ignore; ignore.setSize(infile.getMaxTracks()+1); ignore.setAll(0); PerlRegularExpression pre; int track; for (i=0; i<infile.getNumLines(); i++) { if (infile[i].isData()) { // stop looking when the first data line is found break; } if (!infile[i].isInterpretation()) { continue; } for (j=0; j<infile[i].getFieldCount(); j++) { if (strcmp(infile[i][j], "*^") == 0) { // don't search for names after spine splits (there might // be two names, and one of them will be ignored). ignore[infile[i].getPrimaryTrack(j)] = 1; } if (ignore[infile[i].getPrimaryTrack(j)]) { continue; } if (!abbreviationQ) { if (pre.search(infile[i][j], "^\\*I\"\\s*(.*)\\s*$", "")) { track = infile[i].getPrimaryTrack(j); PartNames[track].setSize(strlen(pre.getSubmatch(1))+1); strcpy(PartNames[track].getBase(), pre.getSubmatch()); } } else { if (pre.search(infile[i][j], "^\\*I\'\\s*(.*)\\s*$", "")) { track = infile[i].getPrimaryTrack(j); PartNames[track].setSize(strlen(pre.getSubmatch(1))+1); strcpy(PartNames[track].getBase(), pre.getSubmatch()); } } } } // if no part name, set to "part name" (for debugging purposes): //for (i=1; i<=infile.getMaxTracks(); i++) { // if (strcmp(PartNames[i].getBase(), "") == 0) { // PartNames[i].setSize(strlen("part name")+1); // strcpy(PartNames[i].getBase(), "part name"); // } // } }
void printMensuration(ostream& out, HumdrumFile& infile, int index) { int i; PerlRegularExpression pre; for (i=index; i<infile.getNumLines(); i++) { if (infile[i].isData()) { break; } if (!infile[i].isGlobalComment()) { continue; } if (pre.search(infile[i][0], "^!!primary-mensuration:\\s*met\\(([^)]+)\\)")) { out << ", \"mensuration\":\"" << pre.getSubmatch(1) << "\""; return; } } for (i=index; i<infile.getNumLines(); i++) { if (infile[i].isData()) { break; } if (!infile[i].isInterpretation()) { continue; } if (pre.search(infile[i][0], "^\\*met\\(([^)]+)\\)")) { out << ", \"mensuration\":\"" << pre.getSubmatch(1) << "\""; return; } } for (i=index-1; i>=0; i--) { if (infile[i].isData()) { break; } if (!infile[i].isGlobalComment()) { continue; } if (pre.search(infile[i][0], "^!!primary-mensuration:\\s*met\\(([^)]+)\\)")) { out << ", \"mensuration\":\"" << pre.getSubmatch(1) << "\""; return; } } for (i=index-1; i>=0; i--) { if (infile[i].isData()) { break; } if (!infile[i].isInterpretation()) { continue; } if (pre.search(infile[i][0], "^\\*met\\(([^)]+)\\)")) { out << ", \"mensuration\":\"" << pre.getSubmatch(1) << "\""; return; } } }
void addStem(char* output, const string& input, const string& piece) { PerlRegularExpression pre; if (pre.search(input, "(.*[ABCDEFG][n#-]*)(.*)$", "i")) { strcpy(output, pre.getSubmatch(1)); strcat(output, piece.c_str()); strcat(output, pre.getSubmatch(2)); } else { strcpy(output, input.c_str()); strcat(output, piece.c_str()); } }
void MuseData::analyzeRhythm(void) { RationalNumber cumulative(0,1); RationalNumber linedur(0,1); int tpq = 1; PerlRegularExpression pre; char buffer[128] = {0}; RationalNumber primarychordnoteduration(0,1); // needed for chord notes int i; for (i=0; i<data.getSize(); i++) { if (data[i]->getType() == E_muserec_musical_attributes) { if (pre.search(data[i]->getLine(), "Q:(\\d+)", "")) { tpq = atoi(pre.getSubmatch(1)); } } if (data[i]->getType() == E_muserec_note_chord) { // insert an automatic back command for chord tones // also deal with cue-size note chords? data[i]->setAbsBeat(cumulative - primarychordnoteduration); // Check to see if the secondary chord note has a duration. // If so, then set the note duration to that value; otherwise, // set the note duration to the duration of the primary chord // note (first note before the current note which is not a chord // note). data[i]->getTickDurationField(buffer); if (pre.search(buffer, "\\d", "")) { data[i]->setNoteDuration(data[i]->getNoteTickDuration(), tpq); } else { data[i]->setNoteDuration(primarychordnoteduration); } data[i]->setLineDuration(0); } else { data[i]->setAbsBeat(cumulative); data[i]->setNoteDuration(data[i]->getNoteTickDuration(), tpq); data[i]->setLineDuration(data[i]->getNoteDurationR()); } linedur.setValue(data[i]->getLineTickDuration(), tpq); cumulative += linedur; switch (data[i]->getType()) { case E_muserec_note_regular: // should also worry about cue and grace note chords? primarychordnoteduration = linedur; } } // adjust Sound and Print records so that they occur at the same // absolute time as the note they affect. for (i=1; i<data.getSize(); i++) { switch (data[i]->getType()) { case E_muserec_print_suggestion: case E_muserec_sound_directives: data[i]->setAbsBeat(data[i-1]->getAbsBeatR()); } } }
int isValidFile(HumdrumFile& infile) { int actual; PerlRegularExpression pre; Array<int> ktracks; infile.getTracksByExInterp(ktracks, "**kern"); actual = ktracks.getSize(); int i; int target = -1; for (i=0; i<infile.getNumLines(); i++) { if (pre.search(infile[i][0], "!!+voices\\s*:\\s*(\\d+)")) { target = atoi(pre.getSubmatch(1)); break; } } if (target < 0) { // no !!voices: line, so presum valid return 1; } if (target == actual) { return 1; } else { return 0; } }
void printOutput(HumdrumFile& infile, RationalNumber& rnum) { int i, j; PerlRegularExpression pre; for (i=0; i<infile.getNumLines(); i++) { if (autoQ) { if (pre.search(infile[i][0], "^!+RSCALE:\\s*(\\d+)/(\\d+)")) { rnum = atoi(pre.getSubmatch(1)); rnum /= atoi(pre.getSubmatch(2)); continue; } else if (pre.search(infile[i][0], "^!+RSCALE:\\s*(\\d+)")) { rnum = atoi(pre.getSubmatch(1)); continue; } } if (infile[i].isBibliographic()) { handleBibliographic(infile, i, rnum); continue; } if (!infile[i].isData()) { if (meterQ && infile[i].isInterpretation()) { processTimeSignature(infile, i, rnum); } else { cout << infile[i] << "\n"; } continue; } for (j=0; j<infile[i].getFieldCount(); j++) { if (!(infile[i].isExInterp(j, "**kern") || infile[i].isExInterp(j, "**recip"))) { cout << infile[i][j]; if (j < infile[i].getFieldCount() - 1) { cout << "\t"; } continue; } printKernToken(infile, i, j, rnum); if (j < infile[i].getFieldCount() - 1) { cout << "\t"; } } cout << "\n"; } }
void printErrorMarker(HumdrumFile& infile, int best40, const char* mode) { PerlRegularExpression pre; int foundQ = 0; int i, j; for (i=0; i<infile.getNumLines(); i++) { if (infile[i].isData()) { break; } if (!infile[i].isInterpretation()) { continue; } for (j=0; j<infile[i].getFieldCount(); j++) { if (pre.search(infile[i][j], "^\\*([A-Ga-g#-]+):")) { foundQ = 1; break; } } if (foundQ) { break; } } if (!foundQ) { cout << "?"; return; } PerlRegularExpression pre2; const char* testmode = "major"; if (std::islower(pre.getSubmatch(1)[0])) { testmode = "minor"; } int testbase40 = Convert::kernToBase40(pre.getSubmatch()); if ((testbase40 % 40) == (best40 % 40)) { if (strcmp(mode, testmode) == 0) { // the answer is correct return; } } // the answer was not correct, so print the correct answer char buffer[1024] = {0}; Convert::base40ToKern(buffer, (testbase40 % 40) + 3 * 40); cout << " X:" << buffer << " " << testmode; }
void checkMarks(HumdrumFile& infile, Array<char>& marks, Array<Array<char> >& markcolors) { int markQ = 1; if (!markQ) { marks.setSize(0); markline.setSize(0); markcolors.setSize(0); return; } marks.setSize(0); markline.setSize(0); markcolors.setSize(0); int i; char target; PerlRegularExpression pre; for (i=0; i<infile.getNumLines(); i++) { if (!infile[i].isBibliographic()) { continue; } if (pre.search(infile[i][0], "!!!RDF\\*\\*kern\\s*:\\s*([^=])\\s*=\\s*match", "i")) { target = pre.getSubmatch(1)[0]; marks.append(target); markline.append(i); markcolors.setSize(markcolors.getSize()+1); markcolors.last() = "red"; } else if (pre.search(infile[i][0], "!!!RDF\\*\\*kern\\s*:\\s*([^=])\\s*=\\s*mark", "i")) { target = pre.getSubmatch(1)[0]; marks.append(target); markline.append(i); markcolors.setSize(markcolors.getSize()+1); markcolors.last() = "red"; } } if (debugQ) { for (i=0; i<marks.getSize(); i++) { cerr << "MARK " << marks[i] << "\t" << markcolors[i] << endl; } } }
void addLabelHyperlinkName(Array<char>& strang) { PerlRegularExpression pre; if (!pre.search(strang, "^\\*>([^\\[]+)$", "")) { return; } char buffer[1024] = {0}; strcpy(buffer, "<a name=\""); strcat(buffer, pre.getSubmatch(1)); strcat(buffer, "\"></a>"); strcat(buffer, strang.getBase()); strang.setSize(strlen(buffer)+1); strcpy(strang.getBase(), buffer); }
void processFile(HumdrumFile& infile) { PerlRegularExpression pre; int measure = getStartingMeasure(infile); int i; for (i=0; i<infile.getNumLines(); i++) { if (appendQ) { cout << infile[i]; } if (infile[i].isData()) { if (appendQ) { cout << '\t'; } printLocation(infile, i, measure); if (prependQ) { cout << '\t'; } if (appendQ) { cout << '\n'; } } else if (infile[i].isInterpretation()) { if (appendQ) { cout << '\t'; } if (strcmp(infile[i][0], "*-") == 0) { cout << "*-"; } else if (strncmp(infile[i][0], "**", 2) == 0) { printExclusiveInterpretation(); } else { cout << "*"; } if (prependQ) { cout << '\t'; } if (appendQ) { cout << '\n'; } } else if (infile[i].isBarline()) { if (pre.search(infile[i][0], "=([\\d.]+)")) { measure = atoi(pre.getSubmatch(1)); } if (appendQ) { cout << '\t'; } cout << infile[i][0]; if (prependQ) { cout << '\t'; } if (appendQ) { cout << '\n'; } } else if (infile[i].isLocalComment()) { if (appendQ) { cout << '\t'; } cout << "!"; if (prependQ) { cout << '\t'; } if (appendQ) { cout << '\n'; } } else { if (!(appendQ || prependQ)) { cout << infile[i]; } if (appendQ) { cout << '\n'; } } if (prependQ) { cout << infile[i]; } if (!appendQ) { cout << '\n'; } } }
int getStartingMeasure(HumdrumFile& infile) { int i; int measure = -1; int datafound = 0; int measurefound = 0; PerlRegularExpression pre; for (i=0; i<infile.getNumLines(); i++) { if (infile[i].isData()) { datafound = 1; break; } if (infile[i].isMeasure()) { measurefound = 1; if (pre.search(infile[i][0], "=([\\d]+)")) { measure = atoi(pre.getSubmatch(1)); } } if (measurefound) { break; } } if (datafound) { // data has a pickup measure, so subtract one from measure // number if not already negative. if (measure < 0) { return 0; } else { return measure - 1; } } else { // data not found before barline, so use the measure number if (measure < 0) { return 1; } else { return measure; } } // shouldn't get here, but return 1 if it happens. return 1; }
void getMarkChars(Array<char>& marks, HumdrumFile& infile) { PerlRegularExpression pre; Array<char>& colorchar = marks; colorchar.setSize(0); char value; int i; for (i=0; i<infile.getNumLines(); i++) { if (!infile[i].isBibliographic()) { continue; } // !!!RDF**kern: N= mark color="#ff0000", root if (pre.search(infile[i].getLine(), "^!!!RDF\\*\\*kern:\\s*([^\\s])\\s*=\\s*match", "i") || pre.search(infile[i].getLine(), "^!!!RDF\\*\\*kern:\\s*([^\\s])\\s*=\\s*mark", "i") ) { value = pre.getSubmatch(1)[0]; colorchar.append(value); } } }
void handleBibliographic(HumdrumFile& infile, int row, RationalNumber& num) { char buffer[1024] = {0}; infile[row].getBibKey(buffer, 1000); if (strcmp(buffer, "rscale") != 0) { cout << infile[row] << endl; return; } RationalNumber onum; PerlRegularExpression pre; if (!pre.search(infile[row][0], "!!!rscale([^\\d]*)(\\d+)(/?)(\\d*)(.*)", "")) { cout << infile[row] << endl; return; } int top = atoi(pre.getSubmatch(2)); int bot = 1; if (strlen(pre.getSubmatch(3)) != 0) { if (strlen(pre.getSubmatch(4)) != 0) { bot = atoi(pre.getSubmatch()); } } if (bot == 0) { bot = 1; } onum.setValue(top, bot); onum *= num; FoundRef = 1; if (onum == 1) { // don't print !!!rscale: entry if scaling is 1. return; } if (originalQ) { // original rhythmic values are being generated, don't print ref rec. return; } cout << "!!!rscale"; cout << pre.getSubmatch(1); cout << onum; cout << pre.getSubmatch(5); cout << "\n"; }
int MuseData::getMembershipPartNumber(const char* mstring) { char *searchstring = new char[strlen(mstring+100)]; strcpy(searchstring, "^"); strcat(searchstring, mstring); strcat(searchstring, ":"); PerlRegularExpression pre; int i; for (i=0; i<data.getSize(); i++) { if (data[i]->getType() == E_muserec_header_12) { if (pre.search(data[i]->getLine(), searchstring, "")) { if (pre.search(data[i]->getLine(), "part\\s*(\\d+)\\s*of\\s*(\\d+)", "")) { const char* partnum = pre.getSubmatch(1); return atoi(partnum); } } } if (data[i]->getType() == E_muserec_musical_attributes) { break; } } return 0; }
void processFileConvert(HumdrumFile& infile) { infile.analyzeRhythm("4"); PerlRegularExpression pre; RationalNumber absbeat; int fieldcount = 0; int i, j; char buffer[1024] = {0}; int trackline = 0; int dashQ = 0; for (i=0; i<infile.getNumLines(); i++) { if (infile[i].isData()) { fieldcount = infile[i].getFieldCount(); trackline = i; continue; } if (infile[i].isInterpretation()) { fieldcount = infile[i].getFieldCount(); for (j=0; j<infile[i].getFieldCount(); j++) { if (strcmp(infile[i][j], "*") == 0) { continue; } else if (strcmp(infile[i][j], "*^") == 0) { fieldcount++; trackline = i; } else if ((j > 0) && (strcmp(infile[i][j], "*v") == 0)) { if (strcmp(infile[i][j-1], "*v") == 0) { fieldcount--; trackline = i; } } // should check for *+, but not very common. } continue; } if (!infile[i].isGlobalComment()) { continue; } if (pre.search(infile[i][0], "^!!barline:.*absbeat\\s*=\\s*(\\d+)/(\\d+)")) { absbeat = atoi(pre.getSubmatch(1)); absbeat /= atoi(pre.getSubmatch(2)); if (pre.search(infile[i][0], "dash", "i")) { dashQ = 1; } else { dashQ = 0; } } else if (pre.search(infile[i][0], "^!!barline:.*absbeat\\s*=\\s*(\\d+)")) { absbeat = atoi(pre.getSubmatch(1)); if (pre.search(infile[i][0], "dash", "i")) { dashQ = 1; } else { dashQ = 0; } } else { continue; } buffer[0] = '\0'; for (j=0; j<fieldcount; j++) { strcat(buffer, "="); if (dashQ) { strcat(buffer, "."); } if (j < fieldcount - 1) { strcat(buffer, "\t"); } } infile[i].setLine(buffer); infile[i].setAbsBeatR(absbeat); cutNotesAcrossBarline(infile, i, trackline, fieldcount, absbeat); } cout << infile; }
void printTimeSignature(ostream& out, HumdrumFile& infile, int spine, int line) { Coordinate timesig; timesig.i = -1; timesig.j = -1; int track; PerlRegularExpression pre; int i, j; // first search backwards for time signature for (i=line; i>0; i--) { if (infile[i].isData()) { // quit loop when a data line is found. break; } for (j=0; j<infile[i].getFieldCount(); j++) { track = infile[i].getPrimaryTrack(j); if (track != spine) { continue; }; if (!infile[i].isInterpretation()) { continue; } if (pre.search(infile[i][j], "^\\*M\\d.*/\\d")) { timesig.i = i; timesig.j = j; break; } } } // now search forwards for time signature for (i=line+1; i<infile.getNumLines(); i++) { if (infile[i].isData()) { // quit loop when a data line is found. break; } for (j=0; j<infile[i].getFieldCount(); j++) { track = infile[i].getPrimaryTrack(j); if (track != spine) { continue; }; if (!infile[i].isInterpretation()) { continue; } if (pre.search(infile[i][j], "^\\*M\\d.*/\\d")) { timesig.i = i; timesig.j = j; break; } } } if (timesig.i < 0) { // nothing to do return; } // for the moment, do not allow % within time signature pre.search(infile[timesig.i][timesig.j], "^\\*M(\\d+)\\/(\\d+)"); int topnum = atoi(pre.getSubmatch(1)); int botnum = atoi(pre.getSubmatch(2)); indent(out, LEVEL); out << ":time-signature (" << topnum << " " << botnum; if (line == 0) { // printing initial time signature // check to see if the first measure is a pickup beat RationalNumber pickupdur; pickupdur = infile.getPickupDurationR(); if (pickupdur > 0) { out << " :kind :pickup"; } } out << ")" << endl; }
void processFileAuto(HumdrumFile& infile) { infile.analyzeRhythm("4"); PerlRegularExpression pre; RationalNumber fraction = 1; int barcounter = 0; RationalNumber barstarttime; RationalNumber barduration; RationalNumber nextbarmessage; int dashQ = 0; for (int i=0; i<infile.getNumLines(); i++) { if ((nextbarmessage > 0) && (infile[i].getAbsBeatR() >= nextbarmessage)) { cout << "!!barline: absbeat=" << nextbarmessage; if (dashQ) { cout << " dash"; } cout << endl; if (infile[i].getAbsBeatR() > nextbarmessage) { cout << "!!barline: dataline" << endl; } barcounter++; if (barcounter+1 == fraction.getDenominator()) { nextbarmessage = -1; } else { nextbarmessage = barstarttime + barduration * fraction * (barcounter + 1); } } if (infile[i].isGlobalComment()) { if (pre.search(infile[i][0], "!!BARLINES:\\s*(\\d+)/(\\d+)")) { fraction = atoi(pre.getSubmatch(1)); fraction /= atoi(pre.getSubmatch(2)); if (pre.search(infile[i][0], "dash", "i")) { dashQ = 1; } else { dashQ = 0; } continue; } } if (fraction == 1) { cout << infile[i] << endl; continue; } if (infile[i].isBarline()) { barcounter = 0; barstarttime = infile[i].getAbsBeatR(); barduration = infile[i].getMeasureDuration(); if (barduration <= 0) { nextbarmessage = -1; } else { nextbarmessage = barstarttime + barduration * fraction; } cout << infile[i] << endl; continue; } cout << infile[i] << endl; } }
void printBarlines(ostream& out, HumdrumFile& infile, int indent) { int i; pi(out, indent); out << "\t\"barlines\"\t:\n"; pi(out, indent); out << "\t\t[\n"; indent++; indent++; int barinit = 0; int number; int terminal; int invisible; PerlRegularExpression pre; RationalNumber timeval; RationalNumber measuredur; for (i=0; i<infile.getNumLines(); i++) { if (!infile[i].isBarline()) { continue; } if (pre.search(infile[i][0], "=(\\d+)")) { number = atoi(pre.getSubmatch(1)); } else { number = -1; } terminal = 0; if (strstr(infile[i][0], "||") != NULL) { terminal = 1; } else if (strstr(infile[i][0], "==") != NULL) { terminal = 1; } invisible = 0; if (strchr(infile[i][0], '-') != NULL) { invisible = 1; } if ((invisible) && (number < 0)) { continue; } if (barinit) { out << ",\n"; } else { barinit = 1; } pi(out, indent); out << "{\"time\":"; timeval = infile[i].getAbsBeatR(); printRationalNumber(out, timeval); if (number >= 0) { out << ", \"label\":\"" << number << "\""; } if (terminal) { out << ", \"terminal\":\"" << "true" << "\""; } printSectionLabel(out, infile, i); printMensuration(out, infile, i); out << "}"; } out << "\n\t\t],\n"; }
void checkOptions(Options& opts, int argc, char* argv[]) { opts.define("d|f|factor=s:1/1", "Factor to multiply durations by"); opts.define("F=b", "Read rscale factors from !!!RSCALE: lines"); opts.define("M|T|nometer=b", "Do not alter time signatures"); opts.define("o|original=b", "Revert to original rhythms"); opts.define("a|alternate=b", "Change to alternate rhythm set"); opts.define("r|long=b", "Do not use short form for breve,long,maxima"); opts.define("B|adjust-beams=b", "Adjust beaming for powers of 2 rscaling"); opts.define("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, " << "[email protected], Jan 2011" << endl; exit(0); } else if (opts.getBoolean("version")) { cout << argv[0] << ", version: 6 Jan 2011" << endl; cout << "compiled: " << __DATE__ << endl; cout << MUSEINFO_VERSION << endl; exit(0); } else if (opts.getBoolean("help")) { usage(opts.getCommand().data()); exit(0); } else if (opts.getBoolean("example")) { example(); exit(0); } PerlRegularExpression pre; if (pre.search(opts.getString("factor").data(), "(\\d+)\\/?(\\d*)", "")) { int top = 1; int bot = 1; top = atoi(pre.getSubmatch(1)); if (strlen(pre.getSubmatch(2)) != 0) { bot = atoi(pre.getSubmatch()); if (bot == 0) { bot = 1; } } else { bot = 1; } factor.setValue(top, bot); } else { factor.setValue(1,1); cerr << "Scaling factor set to " << factor << endl; } debugQ = opts.getBoolean("debug"); if (debugQ) { cerr << "Scaling factor set to " << factor << endl; } autoQ = opts.getBoolean("F"); meterQ = !opts.getBoolean("nometer"); originalQ = opts.getBoolean("original"); alternateQ = opts.getBoolean("alternate"); longQ = opts.getBoolean("long"); rebeamQ = opts.getBoolean("adjust-beams"); }
void readEditWeights(const char* filename) { #ifndef OLDCPP ifstream weightfile(filename, ios::in); #else ifstream weightfile(filename, ios::in | ios::nocreate); #endif if (weightfile.eof()) { cerr << "Error opening weightfile file: " << filename << endl; exit(1); } PerlRegularExpression pre; PerlRegularExpression pre2; Array<char> storage; char buffer[1024] = {0}; int strsize; weightfile.getline(buffer, 1024); while (!weightfile.eof()) { strsize = strlen(buffer); storage.setSize(strsize+1); strcpy(storage.getBase(), buffer); weightfile.getline(buffer, 1024); pre.sar(storage, "\\s*#.*", "", ""); if (pre.search(storage, "^\\s*(d1|d2|r1|r2|s0|s1|s2|s3)\\s+([\\d.+\\-]+)", "i")) { if (pre2.search(pre.getSubmatch(1), "D1", "i")) { weight_D1 = atof(pre.getSubmatch(2)); } else if (pre2.search(pre.getSubmatch(1), "D2", "i")) { weight_D2 = atof(pre.getSubmatch(2)); } else if (pre2.search(pre.getSubmatch(1), "R1", "i")) { weight_R1 = atof(pre.getSubmatch(2)); } else if (pre2.search(pre.getSubmatch(1), "R2", "i")) { weight_R2 = atof(pre.getSubmatch(2)); } else if (pre2.search(pre.getSubmatch(1), "S0", "i")) { weight_S0 = atof(pre.getSubmatch(2)); } else if (pre2.search(pre.getSubmatch(1), "S1", "i")) { weight_S1 = atof(pre.getSubmatch(2)); } else if (pre2.search(pre.getSubmatch(1), "S2", "i")) { weight_S2 = atof(pre.getSubmatch(2)); } else if (pre2.search(pre.getSubmatch(1), "S3", "i")) { weight_S3 = atof(pre.getSubmatch(2)); } } } weightfile.close(); }
void processTimeSignature(HumdrumFile& infile, int row, RationalNumber& factor) { int j; RationalNumber beat; int mtop; int top; int bot; PerlRegularExpression pre; for (j=0; j<infile[row].getFieldCount(); j++) { if (pre.search(infile[row][j], "^\\*tb(\\d+)(%?)(\\d*)$", "")) { // process a timebase interpretation top = atoi(pre.getSubmatch(1)); bot = 1; if (strlen(pre.getSubmatch(2)) != 0) { if (strlen(pre.getSubmatch(3)) != 0) { bot = atoi(pre.getSubmatch()); if (bot == 0) { bot = 1; } } } beat.setValue(top, bot); beat /= factor; cout << "*tb"; printSpecialRational(beat); if (j < infile[row].getFieldCount() - 1) { cout << "\t"; } continue; } if ((!meterQ) || (!pre.search(infile[row][j], "^\\*M(\\d+)/(\\d+)(%?)(\\d*)(.*)", ""))) { cout << infile[row][j]; if (j < infile[row].getFieldCount() - 1) { cout << "\t"; } continue; } mtop = atoi(pre.getSubmatch(1)); top = atoi(pre.getSubmatch(2)); bot = 1; if (strlen(pre.getSubmatch(3)) != 0) { if (strlen(pre.getSubmatch(4)) != 0) { bot = atoi(pre.getSubmatch()); if (bot == 0) { bot = 1; } } } beat.setValue(top, bot); beat /= factor; cout << "*M"; cout << mtop; cout << "/"; printSpecialRational(beat); cout << pre.getSubmatch(5); if (j < infile[row].getFieldCount() - 1) { cout << "\t"; } } cout << "\n"; }