ReducedFraction toMuseScoreTicks(int tick, int oldDivision, bool isDivisionInTps)
      {
      if (isDivisionInTps)
            return ReducedFraction::fromTicks(tick);

      Q_ASSERT_X(!isDivisionOverflow(tick, oldDivision),
                 "ReducedFraction::toMuseScoreTicks", "Division overflow");
      Q_ASSERT_X(!isRemainderOverflow(tick, oldDivision),
                 "ReducedFraction::toMuseScoreTicks", "Remainder overflow");

      const int integral = tick / oldDivision;
      const int remainder = tick % oldDivision;

      Q_ASSERT_X(!isMultiplicationOverflow(remainder, MScore::division),
                 "ReducedFraction::toMuseScoreTicks", "Multiplication overflow");
      Q_ASSERT_X(!isAdditionOverflow(remainder * MScore::division, oldDivision / 2),
                 "ReducedFraction::toMuseScoreTicks", "Addition overflow");

      const int tmp = remainder * MScore::division + oldDivision / 2;

      Q_ASSERT_X(!isDivisionOverflow(tmp, oldDivision),
                 "ReducedFraction::toMuseScoreTicks", "Division overflow");
      Q_ASSERT_X(!isMultiplicationOverflow(integral, MScore::division),
                 "ReducedFraction::toMuseScoreTicks", "Multiplication overflow");
      Q_ASSERT_X(!isAdditionOverflow(tmp / oldDivision, integral *  MScore::division),
                 "ReducedFraction::toMuseScoreTicks", "Addition overflow");

      return ReducedFraction::fromTicks(tmp / oldDivision + integral * MScore::division);
      }
ReducedFraction ReducedFraction::reduced() const
      {
      const int tmp = gcd(numerator_, denominator_);

      Q_ASSERT_X(!isDivisionOverflow(numerator_, tmp),
                 "ReducedFraction::reduced", "Division overflow");
      Q_ASSERT_X(!isDivisionOverflow(denominator_, tmp),
                 "ReducedFraction::reduced", "Division overflow");

      return ReducedFraction(numerator_ / tmp, denominator_ / tmp);
      }
Exemplo n.º 3
0
void ReducedFraction::reduce()
      {
      const int tmp = gcd(numerator_, denominator_);

      Q_ASSERT_X(!isDivisionOverflow(numerator_, tmp),
                 "ReducedFraction::reduce", "Division overflow");
      Q_ASSERT_X(!isDivisionOverflow(denominator_, tmp),
                 "ReducedFraction::reduce", "Division overflow");

      numerator_ /= tmp;
      denominator_ /= tmp;
      }
int fractionPart(int lcmPart, int numerator, int denominator)
      {

      Q_ASSERT_X(!isDivisionOverflow(lcmPart, denominator),
                 "ReducedFraction::fractionPart", "Division overflow");

      const int part = lcmPart / denominator;

      Q_ASSERT_X(!isMultiplicationOverflow(numerator, part),
                 "ReducedFraction::fractionPart", "Multiplication overflow");

      return numerator * part;
      }
Exemplo n.º 5
0
ReducedFraction toMuseScoreTicks(int tick, int oldDivision)
      {

      Q_ASSERT_X(!isMultiplicationOverflow(tick, MScore::division),
                 "ReducedFraction::toMuseScoreTicks", "Multiplication overflow");
      Q_ASSERT_X(!isAdditionOverflow(tick * MScore::division, oldDivision / 2),
                 "ReducedFraction::toMuseScoreTicks", "Addition overflow");

      const int tmp = tick * MScore::division + oldDivision / 2;

      Q_ASSERT_X(!isDivisionOverflow(tmp, oldDivision),
                 "ReducedFraction::toMuseScoreTicks", "Division overflow");

      return ReducedFraction::fromTicks(tmp / oldDivision);
      }
int ReducedFraction::ticks() const
      {
      int integral = numerator_ / denominator_;
      int newNumerator = numerator_ % denominator_;
      int division = MScore::division * 4;

      Q_ASSERT_X(!isMultiplicationOverflow(newNumerator, division),
                 "ReducedFraction::ticks", "Multiplication overflow");
      Q_ASSERT_X(!isAdditionOverflow(newNumerator * division, denominator_ / 2),
                 "ReducedFraction::ticks", "Addition overflow");

      const int tmp = newNumerator * division + denominator_ / 2;

      Q_ASSERT_X(!isDivisionOverflow(tmp, denominator_),
                 "ReducedFraction::ticks", "Division overflow");
      Q_ASSERT_X(!isMultiplicationOverflow(integral, division),
                 "ReducedFraction::ticks", "Multiplication overflow");
      Q_ASSERT_X(!isAdditionOverflow(tmp / denominator_, integral * division),
                 "ReducedFraction::ticks", "Addition overflow");

      return tmp / denominator_ + integral * division;
      }