Ejemplo n.º 1
0
void MeasureProperties::apply()
      {
      Score* score = m->score();

      for (int staffIdx = 0; staffIdx < score->nstaves(); ++staffIdx) {
            MStaff* ms = m->mstaff(staffIdx);
            bool v = visible(staffIdx);
            bool s = slashStyle(staffIdx);
            if (ms->visible() != v || ms->slashStyle() != s)
                  score->undo(new ChangeMStaffProperties(ms, v, s));
            }
      if (isIrregular() != m->irregular()
         || breakMultiMeasureRest->isChecked() != m->breakMultiMeasureRest()
         || repeatCount() != m->repeatCount()
         || layoutStretch->value() != m->userStretch()
         || measureNumberOffset->value() != m->noOffset()
         || m->len() != len()
         ) {
            score->undo(new ChangeMeasureProperties(
               m,
               breakMultiMeasureRest->isChecked(),
               repeatCount(),
               layoutStretch->value(),
               measureNumberOffset->value(),
               isIrregular())
               );
            if (m->len() != len()) {
                  m->adjustToLen(len());
                  score->select(m, SELECT_RANGE, 0);
                  }
            }
      score->select(0, SELECT_SINGLE, 0);
      score->end();
      }
Ejemplo n.º 2
0
void MeasureProperties::apply()
      {
      Score* score = m->score();

      for (int staffIdx = 0; staffIdx < score->nstaves(); ++staffIdx) {
            MStaff* ms = m->mstaff(staffIdx);
            bool v = visible(staffIdx);
            bool s = slashStyle(staffIdx);
            if (ms->visible() != v || ms->slashStyle() != s)
                  score->undo(new ChangeMStaffProperties(ms, v, s));
            }

      m->undoChangeProperty(P_ID::REPEAT_COUNT, repeatCount());
      m->undoChangeProperty(P_ID::BREAK_MMR, breakMultiMeasureRest->isChecked());
      m->undoChangeProperty(P_ID::USER_STRETCH, layoutStretch->value());
      m->undoChangeProperty(P_ID::MEASURE_NUMBER_MODE, measureNumberMode->currentIndex());
      m->undoChangeProperty(P_ID::NO_OFFSET, measureNumberOffset->value());
      m->undoChangeProperty(P_ID::IRREGULAR, isIrregular());

      if (m->len() != len()) {
            ScoreRange range;
            range.read(m->first(), m->last());
            if (range.canWrite(len()))
                  m->adjustToLen(len());
            else if (!MScore::noGui) {
                  QMessageBox::warning(0,
                     QT_TRANSLATE_NOOP("MeasureProperties", "MuseScore"),
                     QT_TRANSLATE_NOOP("MeasureProperties", "cannot change measure length:\n"
                     "tuplet would cross measure")
                     );
                  }
            }
      score->update();
      }
Ejemplo n.º 3
0
 int getMaxRepetitions(string s1, int n1, string s2, int n2) {
     vector<int> repeatCount(n1 + 1, 0);
     vector<int> nextIndex(n1 + 1, 0);
     int j = 0, cnt = 0;
     for (int k = 1; k <= n1; ++k) {
         for (int i = 0; i < s1.size(); ++i) {
             if (s1[i] == s2[j]) {
                 ++j;
                 if (j == s2.size()) {
                     j = 0;
                     ++cnt;
                 }
             }
         }
         repeatCount[k] = cnt;
         nextIndex[k] = j;
         for (int start = 0; start < k; ++start) {
             if (nextIndex[start] == j) {
                 int prefixCount = repeatCount[start];
                 int patternCount = (n1 - start) / (k - start) * (repeatCount[k] - prefixCount);
                 int suffixCount = repeatCount[start + (n1 - start) % (k - start)] - prefixCount;
                 return (prefixCount + patternCount + suffixCount) / n2;
             }
         }
     }
     return repeatCount[n1] / n2;
 }
Ejemplo n.º 4
0
Result RacingKingsBoard::result()
{
	QString str;
	bool blackFinished = finished(Side::Black);
	bool whiteFinished = finished(Side::White);

	// Finishing on eighth rank
	if (blackFinished && whiteFinished)
	{
		str = tr("Drawn race");
		return Result(Result::Draw, Side::NoSide, str);
	}

	if (blackFinished)
	{
		str = tr("Black wins the race");
		return Result(Result::Win, Side::Black, str);
	}

	Side side = sideToMove();
	bool mobile = canMove();

	// White finished but Black cannot finish or forfeited the chance
	if (whiteFinished
	&& ((mobile && !canFinish(Side::Black)) || side == Side::White))
	{
		str = tr("White wins the race");
		return Result(Result::Win, Side::White, str);
	}

	// Stalemate
	if (!mobile)
	{
		str = tr("Draw by stalemate");
		return Result(Result::Draw, Side::NoSide, str);
	}

	// 50 move rule
	if (reversibleMoveCount() >= 100)
	{
		str = tr("Draw by fifty moves rule");
		return Result(Result::Draw, Side::NoSide, str);
	}

	// 3-fold repetition
	if (repeatCount() >= 2)
	{
		str = tr("Draw by 3-fold repetition");
		return Result(Result::Draw, Side::NoSide, str);
	}

	return Result();
}
Ejemplo n.º 5
0
Result LosersBoard::result()
{
	Side winner;
	QString str;

	// Checkmate/Stalemate
	if (!canMove())
	{
		winner = sideToMove();
		str = tr("%1 gets mated").arg(winner.toString());
		return Result(Result::Win, winner, str);
	}

	// Lost all pieces
	int pieceCount = 0;
	for (int i = 0; i < arraySize(); i++)
	{
		if (pieceAt(i).side() == sideToMove()
		&&  ++pieceCount > 1)
			break;
	}
	if (pieceCount <= 1)
	{
		winner = sideToMove();
		str = tr("%1 lost all pieces").arg(winner.toString());
		return Result(Result::Win, winner, str);
	}

	// 50 move rule
	if (reversibleMoveCount() >= 100)
	{
		str = tr("Draw by fifty moves rule");
		return Result(Result::Draw, Side::NoSide, str);
	}

	// 3-fold repetition
	if (repeatCount() >= 2)
	{
		str = tr("Draw by 3-fold repetition");
		return Result(Result::Draw, Side::NoSide, str);
	}

	return Result();
}
Ejemplo n.º 6
0
 int getMaxRepetitions(string s1, int n1, string s2, int n2) {
     vector<int> repeatCount(s2.size() + 1, 0);
     unordered_map<int, int> lookup;
     int j = 0, count = 0;
     for (int k = 1; k <= n1; ++k) {
         for (int i = 0; i < s1.size(); ++i) {
             if (s1[i] == s2[j]) {
                 j = (j + 1) % s2.size();
                 count += (j == 0);
             }
         }
         
         if (lookup.find(j) != lookup.end()) {  // cyclic
             int i = lookup[j];
             int prefixCount = repeatCount[i];
             int patternCount = (count - repeatCount[i]) * ((n1 - i) / (k - i));
             int suffixCount = repeatCount[i + (n1 - i) % (k - i)] - repeatCount[i];
             return (prefixCount + patternCount + suffixCount) / n2;
         }
         lookup[j] = k;
         repeatCount[k] = count;
     }
     return repeatCount[n1] / n2;  // not cyclic iff n1 <= s2
 }