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(); } } } }
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); }
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; }
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; }
bool RationalNumber::is_Like (const RationalNumber &other) { if(other.getDenominator()==Denominator && other.getNumerator() ==Numerator){ return true; } return false; //numerator == op2.getNumerator && denominator == op2.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; }
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; } }
//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); }