Exemple #1
0
int doTickAnalysis(Array<int>& tickanalysis, HumdrumFile& infile) {
   int i;
   tickanalysis.setSize(infile.getNumLines());

   Array<RationalNumber> pretick(tickanalysis.getSize());

   int minrhy = infile.getMinTimeBase();
   if (minrhy <= 0.0) {
      return 1;
   }
   RationalNumber value;
   int monitor = 0;
   for (i=0; i<infile.getNumLines()-1; i++) {
      value = ((infile[i+1].getAbsBeatR()-infile[i].getAbsBeatR())/4)*minrhy;
      pretick[i] = value;
      if (value.getDenominator() != 1) {
         monitor = 1;
      }
   }

   if (monitor == 0) {
      for (i=0; i<pretick.getSize(); i++) {
         tickanalysis[i] = pretick[i].getNumerator();
      }
      return 1;
   }

   for (i=0; i<pretick.getSize(); i++) {
      // estimate a multiplication of 4 to remove fractional part.
      tickanalysis[i] = pretick[i].getNumerator() * 4;
   }

   return 4;
}
RationalNumber RationalNumber::operator*(const RationalNumber &r) const {
   RationalNumber temp;

   if (r.getNumerator() == 0) {
      temp.setValue(0,1);
      return temp;
   }
   if (getNumerator() == 0) {
      temp.setValue(0,1);
      return temp;
   }


   int a = this->_num;
   int b = this->_den;
   int c = r._num;
   int d = r._den;
   int gcd_val = gcd( a, d );
   int gcd_val2 = gcd( b, c );
   a /= gcd_val;
   d /= gcd_val;
   b /= gcd_val2;
   c /= gcd_val2;
   temp._num = a * c;
   temp._den = b * d;
   return temp;
}
Exemple #3
0
int ScorePage::getSystemLCMRhythm(int systemindex) {
   if (!analysis_info.systemsIsValid()) {
      analyzeSystems();
   }
   if (!analysis_info.durationIsValid()) {
      analyzeStaffDurations();
   }


   set<int> numbers;
   RationalNumber rn;
   RationalNumber rd;
   vectorSIp& sysitems = this->getSystemItems(systemindex);
   for (auto& it : sysitems) {
      if (!it->hasDuration()) {
         continue;
      }
      rn = it->getDurationIncludingDots();

      if (rn <= 0) {
         continue;
      }
      numbers.insert(rn.getDenominator());
   }

   int output = ScoreUtility::lcm(numbers);
   return output;
}
Exemple #4
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;
   }

}
Exemple #5
0
bool RationalNumber::is_Like (const RationalNumber &other) {
    if(other.getDenominator()==Denominator && other.getNumerator() ==Numerator){
        return true;
    }
    return false;
   //numerator == op2.getNumerator && denominator == op2.getDenominator;
}
Exemple #6
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;
   }
}
	RationalNumber operator ^ (const RationalNumber& B) const throw(std::invalid_argument)
	{
		if (!isFraction() || !B.isInteger())
		{
			return RationalNumber(powl(getRealNumber(), B.getRealNumber()));
		}
		RationalNumber S(1, 1);
		RationalNumber A = *this;
		long long n = B.numerator;
		if (n < 0)
		{
			A = RationalNumber(1, 1) / A;
			n = -n;
		}
		while (n)
		{
			if (n & 1)
			{
				S = S * A;
			}
			A = A * A;
			n >>= 1;
		}
		return S;
	}
	RationalNumber operator * (const RationalNumber& B) const
	{
		if (!isFraction() || !B.isFraction())
		{
			return RationalNumber(getRealNumber() * B.getRealNumber());
		}
		return RationalNumber(numerator * B.numerator, denominator * B.denominator);
	}
int RationalNumber::operator ==(const RationalNumber &r) const {
   if ((this->getNumerator() == 0) && (r.getNumerator() == 0)) {
      return 1;
   } else {
      return ((this->getNumerator() == r.getNumerator()) && 
            (this->getDenominator() == r.getDenominator() ));
   }
}
Exemple #10
0
RationalNumber RationalNumber::subtract (const RationalNumber &other){
    int commonDenominator = Denominator * other.getDenominator();
    int numerator1 = Numerator * other.getDenominator();
    int numerator2 = other.getNumerator() * Denominator;
    int difference = numerator1 - numerator2;
    
    return RationalNumber (difference, commonDenominator);
}
Exemple #11
0
RationalNumber RationalNumber::add(const RationalNumber &other){
    int commonDenominator = Denominator * other.getDenominator();
    int numerator1 = Numerator * other.getDenominator();
    int numerator2 = other.getNumerator() * Denominator;
    int sum = numerator1 + numerator2;
    
    return RationalNumber (sum, commonDenominator);
}
Exemple #12
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 #13
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 << "]";
}
	RationalNumber operator / (const RationalNumber& B) const throw(std::domain_error)
	{
		if (!isFraction() || !B.isFraction())
		{
			return RationalNumber(getRealNumber() / B.getRealNumber());
		}
		if (B.numerator == 0)
		{
			throw std::domain_error("Division by zero!");
		}
		return RationalNumber(numerator * B.denominator, denominator * B.numerator);
	}
bool RationalNumber::operator==(const RationalNumber& other) const {
	if (other.isNaN())
		return false;

	signed short int a1 = nomi() * other.deno();
	signed short int b1 = deno() * other.deno();

	signed short int a2 = other.nomi() * deno();
	signed short int b2 = other.deno() * deno();

	return (a1 == a2 && b1 == b2);
}
Exemple #16
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; }
   }

}
Exemple #17
0
ostream& RationalDuration::printHumdrum(ostream& out) {
   if (primaryvalue <= 0) {
      out << 'g';
      return out;
   }
   RationalNumber rn = primaryvalue / 4;
   out << rn.getDenominator();
   if (rn.getNumerator() != 1) {
      out << '%' << rn.getNumerator();
   }
   for (int i=0; i<dotcount; i++) {
      out << '.';
   }
   return out;
}
// call by value - non-member function
RationalNumber operator-(const RationalNumber& one, const RationalNumber& two) {
	if (one.isNaN() || two.isNaN()) {
		RationalNumber r;
		return r;
	}
	RationalNumber r(one.nomi() * two.deno() - two.nomi() * one.deno(),
			one.deno() * two.deno());
	r.normalize();
	return r;
}
Exemple #19
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";

}
// call by value
RationalNumber RationalNumber::operator-(const RationalNumber& other) const {
	if (other.isNaN())
		return RationalNumber(*this);

	RationalNumber r(*this);
	r -= other;
	r.normalize();
	return r;
}
void MuseRecordBasic::append(const char* format, ...) {
   va_list valist;
   int     i;

   va_start(valist, format);

   union Format_t {
      int   i;
      char *s;
      int  *r;  // array of two integers for rational number
   } FormatData;

   RationalNumber rn;

   for (i=0; format[i] != '\0'; i++) {
      switch (format[i]) {   // Type to expect.
         case 'i':
            FormatData.i = va_arg(valist, int);
            appendInteger(FormatData.i);
            break;

         case 's':
            FormatData.s = va_arg(valist, char *);
            if (strlen(FormatData.s) > 0) {
               appendString(FormatData.s);
            }
            break;

         case 'r':
             FormatData.r = va_arg(valist, int *);
             rn.setValue(FormatData.r[0], FormatData.r[1]);
             appendRational(rn);
            break;

         default:
            // don't put any character other than "i", "r" or "s" 
            // in the format string
            break;
      }
   }

   va_end(valist);
}
Exemple #22
0
RationalNumber getSmallestRhythm(HumdrumFile& infile, Array<Coordinate>& items,
     Array<int>&  notes, int noteindex, int groupcount) {
   int i;
   RationalNumber minrhy;
   RationalNumber testrhy;
   minrhy.setValue(1,1);
   int ii, jj;
   for (i=noteindex; i<noteindex+groupcount; i++) { 
      ii = items[notes[i]].i;
      jj = items[notes[i]].j;
      testrhy = Convert::kernToDurationR(infile[ii][jj]);
      if (testrhy.getNumerator() == 0) {
         cerr << "ERROR: grace notes are not yet handled by program" << endl;
         exit(1);
      }
      if (minrhy > testrhy) {
         minrhy = testrhy;
      }
   }
   return minrhy;
}
Exemple #23
0
int getBeatGroupCount(HumdrumFile& infile, Array<Coordinate>& items, 
      Array<int>& notes, int noteindex) {
   int output = 0;
   int i;
   RationalNumber dursum;
   dursum.setValue(0,1);
   int ii, jj;
   for (i=noteindex; i<notes.getSize(); i++) {
      ii = items[notes[i]].i;
      jj = items[notes[i]].j;
      dursum += Convert::kernToDurationR(infile[ii][jj]);
      output++;
      if (dursum.isInteger()) {
         return output;
      }
   }
   cerr << "ERROR: measure does not sum to an integer amount of beats." << endl;
   cerr << "Instead the group duration is: " << dursum << endl;
   exit(1);
   return -1;
}
Exemple #24
0
void printSpecialRational(RationalNumber& value) {
   static RationalNumber half(1,2);      // breve
   static RationalNumber quarter(1,4);   // long
   static RationalNumber eighth(1,8);    // maxima

   if (longQ) {
      // don't print 0 for breve, 00 for long or 000 for maxima.
      cout << value.getNumerator();
      if (value.getDenominator() != 1) {
         cout << '%' << value.getDenominator();
      }

   } else {

      if (value == half) {               // breve alternate
         cout << "0";
      } else if (value == quarter) {     // long alternate
         cout << "00";
      } else if (value == eighth) {      // maxima alternate
         cout << "000";
      } else {
         cout << value.getNumerator();
         if (value.getDenominator() != 1) {
            cout << '%' << value.getDenominator();
         }
      }

   }

}
// call by value
RationalNumber RationalNumber::operator+(const RationalNumber& other) const {
	if (other.isNaN())
		return RationalNumber(*this);
	/*
	 RationalNumber result(nomi() * other.deno() + other.nomi() * deno(),
	 deno() * other.deno());
	 return result;
	 */
	RationalNumber r(*this);
	r += other;
	r.normalize();
	return r;
}
Exemple #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;
}
Exemple #27
0
void printChord(ostream& out, HumdrumFile& infile, int line, int field, 
      RationalNumber& dur, int keysig, int defaultclef, int currentclef) {
   int& ii = line;
   int& jj = field;

   int tdur = dur.getNumerator();
   if (tdur == 0) {
      // grace notes are stored with duration of 1 (and :class :grace-beat)
      tdur = 1;
   }

   // simple case where the note is an integer number of beats.
   indent(out, LEVEL);

   if (strchr(infile[ii][jj], 'r') != NULL) {
      printRest(out, infile, line, field, dur);
   } else {
      out << "(" << tdur << " ((" << 1;

      printTieDot(out, infile, ii, jj);
      out << " :notes (";
      printMidiNotes(out, infile, ii, jj, keysig);
      out << ")";  // end of notes list
      
      printChordArticulations(out, infile, ii, jj);

      printStem(out, infile, ii, jj);
 
      if (defaultclef != currentclef) {
         printClefAttribute(out, currentclef);
      }

      out << ")"; // end of chord parentheses 
      out << ")"; // end of beat list 
      if (dur == 0) {
         out << " :class :grace-beat";
      }
      out << ")";  // end of beat group
   }

   if (humdrumQ) {
      out << "\t; " << infile[ii][jj];
   }
   out << endl;
}
Exemple #28
0
RationalNumber RationalNumber::operator+(const RationalNumber &r) const {
   if (r.getNumerator() == 0) {
      return *this;
   }
   if (this->getNumerator() == 0) {
      return r;
   }

   RationalNumber temp;
   int lcm_val = lcm( this->_den, r._den );
   int a = this->_num * ( lcm_val / this->_den );
   int c = r._num * ( lcm_val / r._den );
   // int b = lcm_val; 
   // int d = b;
   temp._num = a + c;
   temp._den = lcm_val;
   simplify(temp);
   return temp;
}
Exemple #29
0
void printRest(ostream& out, HumdrumFile& infile, int line, int field, 
      RationalNumber& dur) {
   int& ii = line;
   int& jj = field;

   int tdur = dur.getNumerator();
   if (tdur == 0) {
      // grace notes are stored with duration of 1 (and :class :grace-beat)
      tdur = 1;
   }

   // this rest has no attributes so not adding an extra paren set
   // otherwise it would be "((-".
   out << "(" << tdur << " (-" << 1;
   printTieDot(out, infile, ii, jj);
   out << ")"; // paren for inner units
   if (dur == 0) {
      out << " :class :grace-beat";
   }
   out << ")"; // paren for outer unit
}
Exemple #30
0
bool RationalNumber::operator >(const RationalNumber &another) const {
    return another.lessThan(*this);
}