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(); } } } }
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() )); } }
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 << "]"; }
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; }
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; }
bool RationalNumber::is_Like (const RationalNumber &other) { if(other.getDenominator()==Denominator && other.getNumerator() ==Numerator){ return true; } return false; //numerator == op2.getNumerator && denominator == op2.getDenominator; }
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); }
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); }
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; }
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; }
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; }
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 }
//definition for overload method operator <= bool RationalNumber::operator<=(RationalNumber rn) { return(numerator*rn.getDenominator() <= denominator*rn.getNumerator()); }
RationalNumber RationalNumber::multiply(const RationalNumber &other){ int numer = Numerator * other.getNumerator(); int denom = Denominator * other.getDenominator(); return RationalNumber (numer, denom); }