Example #1
0
void removeStem2(HumdrumFile& infile, int row, int col) {
	PerlRegularExpression pre;
	string strin = infile[row][col];
	pre.sar(strin, "[\\\\/]x(?!x)", "", "g");
	pre.sar(strin, "[\\\\/](?!x)", "", "g");
	infile[row].setToken(col, strin.c_str());
}
Example #2
0
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>";

}
Example #3
0
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);
}
Example #4
0
void removeStems(ostream& out, HumdrumFile& infile) {
	int i, j;
	PerlRegularExpression pre;
	string buffer;
	buffer.resize(1024);

	for (i=0; i<infile.getNumLines(); i++) {
		if (!infile[i].isData()) {
			out << infile[i] << "\n";
			continue;
		}
		for (j=0; j<infile[i].getFieldCount(); j++) {
			if (!infile[i].isExInterp(j, "**kern")) {
				out << infile[i][j];
				if (j < infile[i].getFieldCount()-1) {
					out << "\t";
				}
				continue;
			}
			buffer = infile[i][j];
			if (removeallQ || overwriteallQ) {
				pre.sar(buffer, "[\\\\/]x(?!x)", "", "g");
				pre.sar(buffer, "[\\\\/](?!x)", "", "g");
			} else {
				pre.sar(buffer, "[\\\\/](?!x)", "", "g");
			}
			out << buffer;
	
			if (j < infile[i].getFieldCount()-1) {
				out << "\t";
			}
		}
		out << "\n";
	}
}
Example #5
0
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;
}
Example #6
0
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());
      }
   }

}
Example #7
0
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;
   }

}
Example #8
0
void removeStem2(HumdrumFile& infile, int row, int col) {
   Array<char> strin;
   int len = strlen(infile[row][col]);
   strin.setSize(len+1);
   strcpy(strin.getBase(), infile[row][col]);
   PerlRegularExpression pre;
   pre.sar(strin, "[\\\\/]x(?!x)", "", "g");
   pre.sar(strin, "[\\\\/](?!x)", "", "g");
   infile[row].setToken(col, strin.getBase());
}
Example #9
0
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;
      }
   }

}
Example #10
0
void cutNotesAcrossBarline(HumdrumFile& infile, int barline, int trackline,
      int fieldcount, RationalNumber& barabsbeat) {

   Array<int> tracknum;
   Array<int> subtracknum;
   int i;

   getTrackInfo(infile, trackline, tracknum, subtracknum);

   PerlRegularExpression pre;
   int dataline = -1;
   
   for (i=barline+1; i<infile.getNumLines(); i++) {
      if (infile[i].isData()) {
         dataline = i;
         break;
      } else if (infile[i].isGlobalComment()) {
         if (pre.search(infile[i][0], "!!barline:.*dataline")) {
            generateDataLine(infile, i, tracknum, subtracknum);
            infile[i].setAbsBeatR(barabsbeat);
            dataline = i;
            break;
         }
      }
   }
   
   RationalNumber nabsbeat; // absolute beat of starting note;
   RationalNumber dabsbeat; // absolute beat of data line;
   RationalNumber firstdur, seconddur;
   RationalNumber olddur;
   int ii, jj;
   int tiestate;
//   int track; 
   int j;
   for (j=0; j<infile[dataline].getFieldCount(); j++) {
      if (strcmp(infile.getTrackExInterp(tracknum[j]).c_str(), "**kern") != 0) {
         continue;
      }
      if (strcmp(infile[dataline][j], ".") != 0) {
         continue;
      }
      getAddress(ii, jj, infile, barline, tracknum[j], subtracknum[j]);
      
      nabsbeat = infile[ii].getAbsBeatR();
      dabsbeat = infile[dataline].getAbsBeatR();
      firstdur = dabsbeat - nabsbeat;
      olddur = Convert::kernToDurationR(infile[ii][jj]);
      seconddur = olddur - firstdur;

      infile[dataline].setToken(j, infile[ii][jj]);
      tiestate = setNewDuration(infile, ii, jj, firstdur, -1, 0);
      setNewDuration(infile, dataline, j, seconddur, +1, tiestate);
   }
}
Example #11
0
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());
	}
}
Example #12
0
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);
}
Example #13
0
void getNoteExpressions(stringstream& expressions, HumdrumFile& infile, int line, 
      int field, int subfield, const char* kernnote) {

   PerlRegularExpression pre;
   
   int i;
   for (i=0; i<marks.getSize(); i++) {
      if (strchr(kernnote, marks[i]) != NULL) {
         if (pre.search(infile[markline[i]][0], "circle")) {
            expressions << "(:score-expression/" << InstanceIdCounter++;
            expressions << " :kind :circled" << ")";
         }
      }
   }

}
Example #14
0
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;
   }
}
Example #15
0
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");
   //   }
   // }

}
Example #16
0
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;
}
Example #17
0
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'; }
   }
}
Example #18
0
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;
      }
   }
}
Example #19
0
void printFields(ostream& out, HumdrumFile& infile, int line) {
   out << "<tr class=\"hi\" valign=baseline>";
   int& i = line;
   int j;
   int track;
   int counter;
   int subtracks;
   PerlRegularExpression pre;
   Array<char> strang;

   for (track=1; track<=infile.getMaxTracks(); track++) {
      subtracks = getSubTracks(infile, line, track);
      out << "<td>";
      if (subtracks > 1) {
         out << "<table " << C0C0 << "><tr valign=top";
         if (infile[i].isMeasure()) {
            out << " bgcolor=#eeeeee ";
         }
         out << ">";
         counter = 0;
         for (j=0; j<infile[i].getFieldCount(); j++) {
            if (infile[i].getPrimaryTrack(j) == track) {
               strang.setSize(strlen(infile[i][j])+1);
               strcpy(strang.getBase(), infile[i][j]); 
               pre.sar(strang, " ", "&nbsp;", "g");
               if (pre.search(strang, "^\\*>.*\\[", "")) {
                  addLabelHyperlinks(strang);
               } else if (pre.search(strang, "^\\*>", "")) {
                  addLabelHyperlinkName(strang);
               }
               out << "<td width=" << TOKENWIDTH << ">" << strang << "</td>";
               counter++;
               if (counter < subtracks) {
                  out << "<td width=" << TDSEP << "></td>";
               }
            }
         }
         out << "</tr></table>\n";
      } else {
         for (j=0; j<infile[i].getFieldCount(); j++) {
            if (infile[i].getPrimaryTrack(j) == track) {
               strang.setSize(strlen(infile[i][j])+1);
               strcpy(strang.getBase(), infile[i][j]); 
               pre.sar(strang, " ", "&nbsp;", "g");
               if (pre.search(strang, "^\\*>.*\\[", "")) {
                  addLabelHyperlinks(strang);
               } else if (pre.search(strang, "^\\*>", "")) {
                  addLabelHyperlinkName(strang);
               }
               out << strang;
            }
         }
      }
      out << "</td>";
   }
   out << "</tr>\n";
}
Example #20
0
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;
}
Example #21
0
void printOutput(HumdrumFile& infile) {
	int i, j;
	string data;
	PerlRegularExpression pre;
	infile.printNonemptySegmentLabel(cout);
	for (i=0; i<infile.getNumLines(); i++) {
		if (infile[i].getType() && (E_humrec_data == 0)) {
			cout << infile[i].getLine() << "\n";
		} else {
			for (j=0; j<infile[i].getFieldCount(); j++) {
				if (strcmp(infile[i][j], ".") == 0) {
					if (parensQ) {
						cout << "(";
					}
					data = infile.getDotValue(i, j);

					if (charQ) {
						pre.sar(data, charString, "", "g");
					}

					if (xcharQ) {
						pre.sar(data, xcharString, "", "g");
					}

					if (data == "") {
						data = ".";
					}
					cout << data;
					if (parensQ) {
						cout << ")";
					}
				} else {
					cout << infile[i][j];
				}
				if (j < infile[i].getFieldCount() - 1) {
					cout << "\t";
				}
			}
			cout << "\n";
		}
	}
}
Example #22
0
void checkOptions(Options& opts, int argc, char* argv[]) {
	opts.define("p|parens=b", "print parentheses around dittox data");
	opts.define("r|rhythm=b", "print keeping kern data rhythm parseable");
	opts.define("c|char|chars=s:[rA-Ga-g#-]",
	                            "print only characters in list when dittoing");
	opts.define("C|xchar|xchars=s", "remove characters in list when dittoing");
	opts.define("k|kern|pitches=b", "print only pitch names in **kern data");

	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], Nov 2000" << endl;
		exit(0);
	} else if (opts.getBoolean("version")) {
		cout << argv[0] << ", version: 14 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);
	}

	parensQ  = opts.getBoolean("parens");
	rhythmQ  = opts.getBoolean("rhythm");

	PerlRegularExpression pre;
	charQ    = opts.getBoolean("char");
	if (charQ) {
		charString = opts.getString("char");
		if (!pre.search(charString, "^\\[")) {
			pre.sar(charString, "^", "[");
			pre.sar(charString, "$", "]");
		}
		pre.sar(charString, "^\\[", "[^");
	}

	xcharQ    = opts.getBoolean("xchar");
	if (xcharQ) {
		xcharString = opts.getString("xchar");
		if (!pre.search(xcharString, "^\\[")) {
			pre.sar(xcharString, "^", "[");
			pre.sar(xcharString, "$", "]");
		}
	}

	if (opts.getBoolean("kern")) {
		charString = "[^rA-Ga-g#-]";
		charQ = 1;
	}
}
Example #23
0
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;
   }

}
Example #24
0
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);
      }
   }
}
Example #25
0
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;
}
Example #26
0
void printMeasureData(Array<int>& analysis, HumdrumFile& infile, int line) {
   int i;
   PerlRegularExpression pre;
   RationalNumber startdur;
   RationalNumber enddur;

   if (mdurQ) {
      startdur = infile[line].getAbsBeatR();
      enddur   = infile[infile.getNumLines()-1].getAbsBeatR();
   }
   int sum = 0;
   for (i=line; i<infile.getNumLines(); i++) {
      if (infile[i].isMeasure()) {
         if (pre.search(infile[i][0], "\\d")) {
            if (mdurQ) {
               enddur = infile[i].getAbsBeatR();
            }
            break;
         }
      }
      if (!infile[i].isData()) { 
         continue;
      }
      if (nograceQ && (infile[i].getDuration() == 0)) {
         continue;
      }
      sum += analysis[i];
   }
   if (mdurQ) {
      RationalNumber duration;
      duration = enddur - startdur;
      duration.printTwoPart(cout);
      cout << ":";
   }
   cout << sum;
}
Example #27
0
const char* MuseData::getPartName(char* buffer, int maxx) {
   buffer[0] = '\0';
   Array<char> output;
   int line = getPartNameIndex();
   if (line < 0) {
      return buffer;
   }
   PerlRegularExpression pre;
   output.setSize(strlen(data[line]->getLine())+1);
   strcpy(output.getBase(), data[line]->getLine());
   pre.sar(output, "^\\s+", "", "");
   pre.sar(output, "\\s+$", "", "");
   strncpy(buffer, output.getBase(), maxx);


   Array<char> instrument;
   instrument.setSize(strlen(buffer)+1);
   strcpy(instrument.getBase(), buffer);
   pre.sar(instrument, "^\\s*", "", "");
   pre.sar(instrument, "\\s*$", "", "");
   strcpy(buffer, instrument.getBase());

   return buffer;
}
Example #28
0
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";

}
Example #29
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";
   }
}
Example #30
0
void printNotePositions(HumdrumFile& infile, 
		vector<vector<vector<int> > >& notepos) {

	PerlRegularExpression pre;
	string data;
	stringstream *pstream;


	int i, j, k;
	for (i=0; i<infile.getNumLines(); i++) {
		if (!(infile[i].isData() || infile[i].isLocalComment() ||
				infile[i].isMeasure() || infile[i].isInterpretation())) {
				cout << infile[i] << "\n";
				continue;
		}
		cout << infile[i] << "\t";
		if (infile[i].isMeasure()) {
				cout << infile[i][0] << "\n";
				continue;
		}
		if (infile[i].isLocalComment()) {
				cout << "!\n";
				continue;
		}
		if (infile[i].isInterpretation()) { 
				if (strncmp(infile[i][0], "**", 2) == 0) {
				cout << "**vpos";
				} else if (strcmp(infile[i][0], "*-") == 0) {
				cout << "*-";
				} else {
				cout << "*";
				}
				cout << "\n";
				continue;
		}
		pstream = new stringstream;
		for (j=0; j<infile[i].getFieldCount(); j++) {
				if (!infile[i].isExInterp(j, "**kern")) {
				continue;
				}
				if (strcmp(infile[i][j], ".") == 0) {
				// ignore null tokens
				continue;
				}
				if (strchr(infile[i][j], 'r') != NULL) {
				// ignore rests
				continue;
				}
				for (k=0; k<(int)notepos[i][j].size(); k++) {
				(*pstream) << notepos[i][j][k];
				if (k < (int)notepos[i][j].size()-1) {
					(*pstream) << " ";
				}
				}
				(*pstream) << " ";
		}
		(*pstream) << ends;
		data = pstream->str();
		pre.sar(data, "\\s+$", "", "");
		if (data.empty()) {
				pre.sar(data, "^\\s*$", ".");
		}
		cout << data;
		cout << "\n";
		delete pstream;
		pstream = NULL;
	}
}