Exemple #1
0
int RationalDuration::isPowerOfTwo(void) {
   RationalNumber rn = getDurationPrimary();
   double pow2 = log(rn.getFloat())/log(2.0);
   if (pow2 < 0) {
      pow2 = -pow2;
   }
   if (fabs(pow2 - int(pow2+0.0001)) < 0.0001) {
      return 1;
   }
   return 0;
}
Exemple #2
0
void printRationalNumber(ostream& out, RationalNumber& rat) {
   double floatpart = rat.getFloat();
   int intpart = (int)floatpart;
   RationalNumber fraction;
   fraction = rat - intpart;
   out << "[" << floatpart;
   if (fraction.getNumerator() != 0) {
      out << ", " << fraction.getNumerator();
      out << ", " << fraction.getDenominator();
   }
   out << "]";
}
Exemple #3
0
void printLocation(HumdrumFile& infile, int line, int measure) {
   RationalNumber rat;
   int startQ = 0;
   if (fileQ) {
      if (startQ && spaceQ) { cout << ' '; } startQ++;
      if (quotesQ) {
         if (labelQ) { cout << '"'; }
      }
      cout << infile.getFilename();
      if (quotesQ) {
         if (labelQ) { cout << '"'; }
      }
   }
   if (lineQ) {
      if (startQ && spaceQ) { cout << ' '; } startQ++;
      if (labelQ) { cout << 'L'; }
      cout << line  + 1;
      if (labelQ && doubleQ) { cout << 'L'; }
   }
   if (measureQ) {
      if (startQ && spaceQ) { cout << ' '; } startQ++;
      if (labelQ) { cout << 'M'; }
      cout << measure;
      if (labelQ && doubleQ) { cout << 'M'; }
   }

   if (beatQ) {
      if (startQ && spaceQ) { cout << ' '; } startQ++;
      if (labelQ) { cout << 'B'; }
      if (rationalQ) {
         rat = infile[line].getBeatR(); 
         rat *= absFactor;
         rat.printTwoPart(cout);
      } else {
         cout << infile[line].getBeat();
      }
      if (labelQ && doubleQ) { cout << 'B'; }
   }

   if (absQ) {
      if (startQ && spaceQ) { cout << ' '; } startQ++;
      if (labelQ) { cout << absChar; }
      if (rationalQ) {
         rat = infile[line].getAbsBeatR(); 
         rat *= absFactor;
         rat.printTwoPart(cout);
      } else {
         cout << infile[line].getAbsBeat() * absFactor.getFloat();
      }
      if (labelQ && doubleQ) { cout << absChar; }
   }

}
int RationalNumber::operator<=(const RationalNumber &r) const {
   return this->getFloat() <= r.getFloat();
}
Exemple #5
0
void printKernTokenLineDuration(HumdrumFile& infile, int line, int field) {
	RationalNumber notestartabsbeat; // starting absbeat of note
	RationalNumber noteendabsbeat;   // ending absbeat of note
	RationalNumber linedur;          // absbeat of current line
	RationalNumber notedur;          // duration of note
	int ii, jj;
	linedur = infile[line].getDurationR();
	string notebuffer;
	if (linedur == 0) {
		// don't bother with grace notes for now:
		cout << infile[line][field];
	}
	ii = line;
	jj = field;
	if (infile[line].isNullToken(field)) {
		ii = infile[line].getDotLine(field);
		jj = infile[line].getDotField(field);
	}
	PerlRegularExpression pre;
	RationalNumber linestartabsbeat = infile[line].getAbsBeatR();
	notestartabsbeat = infile[ii].getAbsBeatR();
	RationalNumber lineendabsbeat;
	char newdur[1024] = {0};
	lineendabsbeat = linestartabsbeat + linedur;
	notedur = Convert::kernToDurationR(infile[ii][jj]);
	if (notedur == linedur) {
		cout << infile[ii][jj];
		return;
	}
	noteendabsbeat = notestartabsbeat + notedur;
	Convert::durationToKernRhythm(newdur, linedur.getFloat());
	notebuffer = infile[ii][jj];
	pre.sar(notebuffer, "[\\d%.]+", newdur, "g");

	// handle tie structure:
	//   Chord notes are all presumed to be tied in the same way.  This
	//   may not be true, so to be fully generalized, keeping track
	//   of the tie states of notes in the chord should be done.

	// * If the original note duration is the same as the line duration
	//   just keep the original note (already taken care of above).

	// * If the note starts at this point, then add a "[" tie marker
	//   if there is not a "[" or "_" character already on the note(s)
	if ((notestartabsbeat == linestartabsbeat)
			&& (strchr(infile[ii][jj], '[') == NULL)
			&& (strchr(infile[ii][jj], '_') == NULL)) {
		pre.sar(notebuffer, " ", " [", "g");
		cout << "[" << notebuffer;
		return;
	}

	// * If the linenote ends on this line, add "]" unless the original
	//   note had "_".
	if (lineendabsbeat == noteendabsbeat) {
		if (strchr(infile[ii][jj], '_') != NULL) {
			cout << notebuffer;
		} else if (strchr(infile[ii][jj], '[') != NULL) {
			pre.sar(notebuffer, "\\[", "", "g");
			pre.sar(notebuffer, " ", "_ ", "g");
			cout << notebuffer << "_";
		} else {
			pre.sar(notebuffer, "\\[", "", "g");
			pre.sar(notebuffer, " ", "\\] ", "g");
			cout << notebuffer << "]";
		}
		return;
	}


	if (notebuffer.find('[') != std::string::npos) {
		cout << notebuffer;
	} else {
		pre.sar(notebuffer, " ", "_ ", "g");
		cout << notebuffer << "_";
	}
}