void TestMidi::midi02() { MCursor c; c.setTimeSig(Fraction(3,4)); c.createScore("test2a"); c.addPart("voice"); c.move(0, 0); // move to track 0 tick 0 c.addKeySig(Key(2)); c.addTimeSig(Fraction(3,4)); c.addChord(60, TDuration(TDuration::DurationType::V_QUARTER)); c.addChord(61, TDuration(TDuration::DurationType::V_QUARTER)); c.addChord(62, TDuration(TDuration::DurationType::V_QUARTER)); Score* score = c.score(); score->doLayout(); score->rebuildMidiMapping(); c.saveScore(); saveMidi(score, "test2.mid"); Score* score2 = new Score(mscore->baseStyle()); score2->setName("test2b"); QCOMPARE(importMidi(score2, "test2.mid"), Score::FileError::FILE_NO_ERROR); score2->doLayout(); score2->rebuildMidiMapping(); MCursor c2(score2); c2.saveScore(); QVERIFY(compareScores(score, score2)); delete score; delete score2; }
void TestBarline::barline04() { Score* score = readScore(DIR + "barline04.mscx"); QVERIFY(score); score->doLayout(); score->startCmd(); // 'go' to 5th measure Measure* msr = score->firstMeasure(); for (int i=0; i < 4; i++) msr = msr->nextMeasure(); // check span data of measure-initial start-repeat bar line Segment* seg = msr->findSegment(SegmentType::StartRepeatBarLine, msr->tick()); QVERIFY2(seg != nullptr, "No SegStartRepeatBarLine segment in measure 5."); BarLine* bar = static_cast<BarLine*>(seg->element(0)); QVERIFY2(bar != nullptr, "No start-repeat barline in measure 5."); bar->undoChangeProperty(Pid::BARLINE_SPAN, 2); bar->undoChangeProperty(Pid::BARLINE_SPAN_FROM, 2); bar->undoChangeProperty(Pid::BARLINE_SPAN_TO, 6); score->endCmd(); QVERIFY2(bar->spanStaff() && bar->spanFrom() == 2 && bar->spanTo() == 6, "Wrong span data in start-repeat barline of measure 5."); // check start-repeat bar ine in second staff is gone QVERIFY2(seg->element(1) == nullptr, "Extra start-repeat barline in 2nd staff of measure 5."); // QVERIFY(saveCompareScore(score, "barline04.mscx", DIR + "barline04-ref.mscx")); delete score; }
EditStaff::EditStaff(Staff* s, QWidget* parent) : QDialog(parent) { staff = s; setupUi(this); setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); Part* part = staff->part(); instrument = *part->instr(); Score* score = part->score(); // hide string data controls if instrument has no strings stringDataFrame->setVisible(instrument.stringData() && instrument.stringData()->strings() > 0); fillStaffTypeCombo(); small->setChecked(staff->small()); invisible->setChecked(staff->invisible()); spinExtraDistance->setValue(s->userDist() / score->spatium()); color->setColor(s->color()); partName->setText(part->partName()); updateInstrument(); connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(bboxClicked(QAbstractButton*))); connect(changeInstrument, SIGNAL(clicked()), SLOT(showInstrumentDialog())); connect(editShortName, SIGNAL(clicked()), SLOT(editShortNameClicked())); connect(editLongName, SIGNAL(clicked()), SLOT(editLongNameClicked())); connect(minPitchASelect, SIGNAL(clicked()), SLOT(minPitchAClicked())); connect(maxPitchASelect, SIGNAL(clicked()), SLOT(maxPitchAClicked())); connect(minPitchPSelect, SIGNAL(clicked()), SLOT(minPitchPClicked())); connect(maxPitchPSelect, SIGNAL(clicked()), SLOT(maxPitchPClicked())); connect(editStringData, SIGNAL(clicked()), SLOT(editStringDataClicked())); }
void TestMidi::midi3() { MCursor c; c.createScore("test3a"); c.addPart("voice"); c.move(0, 0); // move to track 0 tick 0 c.addKeySig(1); c.addTimeSig(Fraction(4,4)); c.addChord(60, TDuration(TDuration::V_QUARTER)); c.addChord(61, TDuration(TDuration::V_QUARTER)); c.addChord(62, TDuration(TDuration::V_QUARTER)); c.addChord(63, TDuration(TDuration::V_QUARTER)); Score* score = c.score(); score->doLayout(); score->rebuildMidiMapping(); c.saveScore(); saveMidi(score, "test3.mid"); Score* score2 = new Score(mscore->baseStyle()); score2->setName("test3b"); QVERIFY(importMidi(score2, "test3.mid")); score2->doLayout(); score2->rebuildMidiMapping(); MCursor c2(score2); c2.saveScore(); QVERIFY(compareScores(score, score2)); delete score; delete score2; }
void unitTests() { HighScore scores; scores.addScore("Robert", 10); scores.addScore("Phillip", 30); scores.addScore("Michael", 20); Score* s = scores.getScores().at(0); assert(s->getName() == "Phillip"); scores.addScore("Rebecca", 5); s = scores.getScores().back(); assert(s->getName() == "Rebecca"); scores.save(); HighScore testScores; testScores.load(); testScores.addScore("Rhonda", 65); s = testScores.getScores().at(0); assert(s->getName() == "Rhonda"); assert(s->getScore() == 65); testScores.save(); remove ("highscores.txt"); //model test for starting a new game. Model::instance()->singleGameStart("easy", false); assert(Model::instance()->getById(0) != NULL); assert(Model::instance()->load()); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //populate highscores list HighScore* scores = new HighScore(); if(scores->load()){ for(unsigned int i = 0; i < scores->getScores().size(); ++i ) { Score *score = scores->getScores().at(i); QString QName = QString::fromStdString(score->getName()); QString QScore = QString::number(score->getScore()); ui->lstScores->addItem(QName + " -- " + QScore); } } else //no file exists scores->save(); //creates new highscores file file //connect(ui->btnNewGame, SIGNAL(click()), this, SLOT(openGameWindow())); //set the help and score screens to be invisible ui->brwHelp->hide(); ui->boxHighScores->hide(); }
double HyperGeoTotalCache::log2Tail (int x, int k, int n, int m, ScoreParameters** p) { XKNM xknm (x, k, n, m); Score* cachedScore = _cache->find (xknm); if (cachedScore == NULL) { // // double score = HyperGeometric::logTailhyge (x, m, k, n); // // change from ln to 2-base log static const double LN_2 = ::log (static_cast <double> (2)); double log2score = score / LN_2; cachedScore = new Score (xknm, log2score); _cache->add (cachedScore); } if (p != NULL) *p = cachedScore; return cachedScore->score (); }
void PowerTabOldImporter::load(const boost::filesystem::path &filename, Score &score) { PowerTabDocument::Document document; document.Load(filename); // TODO - handle font settings, etc. ScoreInfo info; convert(document.GetHeader(), info); score.setScoreInfo(info); score.setLineSpacing(document.GetTablatureStaffLineSpacing()); ScoreUtils::addStandardFilters(score); assert(document.GetNumberOfScores() == 2); // Convert the guitar score. Score guitarScore; convert(*document.GetScore(0), guitarScore); // Convert and then merge the bass score. Score bassScore; convert(*document.GetScore(1), bassScore); ScoreMerger::merge(score, guitarScore, bassScore); // Reformat the score, since the guitar and bass score from v1.7 may have // had different spacing. ScoreUtils::polishScore(score); }
bool FilterCriteria::Satisfy(const DNALength& alnLength, const float& pctSimilarity, const float& pctAccuracy, const Score& score) const { if (alnLength < _minAlnLength) { if (_verbose > 0) std::cout << "Alignment length " << alnLength << " is too short." << std::endl; return false; } if (pctSimilarity < _minPctSimilarity) { if (_verbose > 0) std::cout << "Percentage similarity " << pctSimilarity << " is too low." << std::endl; return false; } if (pctAccuracy < _minPctAccuracy) { if (_verbose > 0) std::cout << "Percentage accuracy " << pctAccuracy << " is too low." << std::endl; return false; } if (_useScore and not score.BetterThanOrEqual(_scoreCutoff)) { if (_verbose) std::cout << "Alignment score " << score.Value() << " worse than cut off." << std::endl; return false; } return true; }
void TestSpanners::spanners05() { MasterScore* score = readScore(DIR + "glissando-cloning02.mscx"); QVERIFY(score); score->doLayout(); // create parts // (copied and adapted from void TestParts::createParts() in mtest/libmscore/parts/tst_parts.cpp) QList<Part*> parts; parts.append(score->parts().at(0)); Score* nscore = new Score(score); Excerpt ex(score); ex.setPartScore(nscore); ex.setTitle(parts.front()->longName()); ex.setParts(parts); ::createExcerpt(&ex); QVERIFY(nscore); nscore->setName(parts.front()->partName()); score->undo(new AddExcerpt(nscore)); QVERIFY(saveCompareScore(score, "glissando-cloning02.mscx", DIR + "glissando-cloning02-ref.mscx")); delete score; }
void TestBarline::barline02() { char msg[256]; Score* score = readScore(DIR + "barline02.mscx"); QVERIFY(score); Measure* msr = score->firstMeasure()->nextMeasure(); TimeSig* ts = new TimeSig(score); ts->setSig(Fraction(3, 4), TimeSigType::NORMAL); score->cmdAddTimeSig(msr, 0, ts, false); score->doLayout(); msr = score->firstMeasure(); int msrNo = 1; while ((msr = msr->nextMeasure())) { ++msrNo; Segment* seg = msr->findSegment(SegmentType::EndBarLine, msr->tick()+msr->ticks()); sprintf(msg, "No SegEndBarLine in measure %d.", msrNo); QVERIFY2(seg != nullptr, msg); BarLine* bar = static_cast<BarLine*>(seg->element(0)); sprintf(msg, "No barline in measure %d.", msrNo); QVERIFY2(bar != nullptr, msg); // bar line should be generated if NORMAL, except the END one at the end sprintf(msg, "Barline in measure %d changed into 'non-generated'.", msrNo); // ws: end barline is also generated // bool test = (bar->barLineType() == BarLineType::NORMAL) ? bar->generated() : !bar->generated(); bool test = bar->generated(); QVERIFY2(test, msg); } // QVERIFY(saveCompareScore(score, "barline02.mscx", DIR + "barline02-ref.mscx")); delete score; }
void detectSwing(Staff *staff, MidiOperation::Swing swingType) { Score *score = staff->score(); const int strack = staff->idx() * VOICES; SwingDetector swingDetector(swingType); for (Segment *seg = score->firstSegment(Segment::SegChordRest); seg; seg = seg->next1(Segment::SegChordRest)) { for (int voice = 0; voice < VOICES; ++voice) { ChordRest *cr = static_cast<ChordRest *>(seg->element(strack + voice)); if (!cr) continue; swingDetector.add(cr); } } if (swingDetector.wasSwingApplied()) { // add swing label to the score StaffText* st = new StaffText(score); st->setTextStyleType(TEXT_STYLE_STAFF); st->setText(swingCaption(swingType)); Segment* seg = score->firstSegment(Segment::SegChordRest); st->setParent(seg); st->setTrack(strack); // voice == 0 score->addElement(st); } }
void createTupletNotes( Staff *staff, const std::multimap<ReducedFraction, TupletData> &tuplets) { Score* score = staff->score(); const int track = staff->idx() * VOICES; for (const auto &tupletEvent: tuplets) { const auto &tupletData = tupletEvent.second; if (tupletData.elements.empty()) continue; Tuplet* tuplet = new Tuplet(score); const auto &tupletRatio = tupletLimits(tupletData.tupletNumber).ratio; tuplet->setRatio(tupletRatio.fraction()); tuplet->setDuration(tupletData.len.fraction()); const TDuration baseLen = tupletData.len.fraction() / tupletRatio.denominator(); tuplet->setBaseLen(baseLen); tuplet->setTrack(track); tuplet->setTick(tupletData.onTime.ticks()); tuplet->setVoice(tupletData.voice); Measure* measure = score->tick2measure(tupletData.onTime.ticks()); tuplet->setParent(measure); for (DurationElement *el: tupletData.elements) { tuplet->add(el); el->setTuplet(tuplet); } } }
void Table::printTable() { printEmptyLine(); printHouseNamesLine(); for (int i = 0; i < n; i++) { string line(""); line += (algoNames[i].size() >= PLACE_FOR_ALGO) ? SEPRATE_CHAR + algoNames[i].substr(0, PLACE_FOR_ALGO) : SEPRATE_CHAR + algoNames[i] + string(PLACE_FOR_ALGO - algoNames[i].size(), ' '); int sum = 0; for (int j = 0; j < m; j++) { Score score = robots[j*n + i]->getScore(); int result = score.calcResult(); sum += result; string res = std::to_string(result); int placeForSpaces = PLACE_FOR_HOUSE - res.size(); line += SEPRATE_CHAR + string(placeForSpaces, ' ') +res; } double avg=sum/(double)m; string res = std::to_string(avg); int placeForSpace = PLACE_FOR_HOUSE - res.size() + 4; //because we want 2 digit and to_string is 6 digit line += SEPRATE_CHAR + string(placeForSpace, ' ') + res.substr(0,res.size() - 4) + SEPRATE_CHAR; printEmptyLine(); cout << line << endl; } printEmptyLine(); }
bool Snake::collision(Score& _hScore) { // Snake eats the bait if(Pixels[0]->getFrontDot() == food.getFrontDot()) { _hScore.addScore(); _hScore.levelControl(); addPixel(); feedRefresh(); } // If the snake hits the tail for(int i=1; i<numberOfPixel; i++) { if( Pixels[0]->getFrontDot() == Pixels[i]->getFrontDot() ) return true; } // If the snake hits the wall if( Pixels[0]->getFrontDot().getX() >= 0 && Pixels[0]->getFrontDot().getX() < 800 && Pixels[0]->getFrontDot().getY() >= 0 && Pixels[0]->getFrontDot().getY() < 540 ) { return false; } else return true; }
Score* TestInstrumentChange::test_pre(const char* p) { QString p1 = DIR + p + ".mscx"; Score* score = readScore(p1); score->doLayout(); return score; }
ScorePanel::ScorePanel() { sf::Vector2u const& windowSize = sGame->GetWindow()->getSize(); const float cellSize = (float)windowSize.x / 24; // Create scores const uint16 beginScore = (uint16)eScores::START + 1; const uint16 endScore = (uint16)eScores::END; for (uint16 i = beginScore; i < endScore; ++i) { Score* score = new Score((eScores)i, 0); // set basic position if (i == beginScore) { const float y = windowSize.y - (cellSize * 1.25f); score->GetText()->setPosition(cellSize, y); } else { // back text value position Score* prevScore = m_scores.back(); // set x to backscore + (cell size * 2) float posX = prevScore->GetValueText()->getPosition().x + (cellSize * 2); float posY = prevScore->GetValueText()->getPosition().y; score->GetText()->setPosition(sf::Vector2f(posX, posY)); } CorrectValuePosition(score); m_scores.push_back(score); } }
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(); }
QSplitter* ScoreTab::viewSplitter(int n) const { TabScoreView* tsv = static_cast<TabScoreView*>(tab->tabData(n).value<void*>()); if (tsv == 0) { // qDebug("ScoreTab::viewSplitter %d is zero", n); return 0; } Score* score = tsv->score; if (tsv->part) { QList<Excerpt*>& excerpts = score->excerpts(); if (!excerpts.isEmpty() && ((tsv->part - 1) < excerpts.size())) score = excerpts.at(tsv->part - 1)->partScore(); } int nn = stack->count(); for (int i = 0; i < nn; ++i) { QSplitter* sp = static_cast<QSplitter*>(stack->widget(i)); if (sp->count() == 0) return 0; ScoreView* v = static_cast<ScoreView*>(sp->widget(0)); if (v->score() == score) return sp; } return 0; }
bool Score::BetterThan(const Score& another) const { if (this->_value == another.Value()) return false; if (this->_sign == ScoreSign::POSITIVE) return (this->_value > another.Value()); else return (this->_value < another.Value()); }
void PowerTabOldImporter::convertGuitarIns( const PowerTabDocument::Score &oldScore, Score &score) { // For each guitar, keep track of its current staff. std::array<int, PowerTabDocument::Score::MAX_NUM_GUITARS> activePlayers; activePlayers.fill(-1); for (size_t i = 0; i < oldScore.GetSystemCount(); ++i) { std::vector<PowerTabDocument::Score::GuitarInPtr> guitarIns; oldScore.GetGuitarInsInSystem(guitarIns, oldScore.GetSystem(i)); if (guitarIns.empty()) continue; size_t currentPosition = guitarIns.front()->GetPosition(); // In v1.7, each staff has separate guitar ins. In the new format, // player changes occur at the system level so we need to combine // the guitar ins from several staves. for (auto &guitarIn : guitarIns) { // For now, ignore guitar ins that only affect rhythm slashes. if (!guitarIn->HasStaffGuitarsSet()) continue; // After combining all guitar in's at a position, write out a player // change. if (guitarIn->GetPosition() != currentPosition) { score.getSystems()[i].insertPlayerChange(getPlayerChange( activePlayers, static_cast<int>(currentPosition))); } // Clear out any players that are currently active for this staff. const int staff = guitarIn->GetStaff(); for (auto &activePlayer : activePlayers) { if (activePlayer == staff) activePlayer = -1; } // Set the active players for this staff. std::bitset<8> activeGuitars(guitarIn->GetStaffGuitars()); for (size_t k = 0; k < activePlayers.size(); ++k) { if (activeGuitars[k]) activePlayers[k] = staff; } currentPosition = guitarIn->GetPosition(); } // After processing all of the guitar ins in the system, write out a // final player change. score.getSystems()[i].insertPlayerChange( getPlayerChange(activePlayers, static_cast<int>(currentPosition))); } }
/// Tests the Alternate Ending Array Functions /// @return True if all tests were executed, false if not bool ScoreTestSuite::TestCaseAlternateEndingArray() { //------Last Checked------// // - Jan 6, 2005 Score score; TEST(wxT("IsValidAlternateEndingIndex - false"), !score.IsValidAlternateEndingIndex(0)); TEST(wxT("GetAlternateEnding - invalid index"), (score.GetAlternateEnding(0) == NULL)); return (true); }
/// Tests the System Array Functions /// @return True if all tests were executed, false if not bool ScoreTestSuite::TestCaseSystemArray() { //------Last Checked------// // - Jan 6, 2005 Score score; TEST(wxT("IsValidSystemIndex - false"), !score.IsValidSystemIndex(0)); TEST(wxT("GetSystem - invalid index"), (score.GetSystem(0) == NULL)); return (true); }
/// Tests the Dynamic Array Functions /// @return True if all tests were executed, false if not bool ScoreTestSuite::TestCaseDynamicArray() { //------Last Checked------// // - Jan 6, 2005 Score score; TEST(wxT("IsValidDynamicIndex - false"), !score.IsValidDynamicIndex(0)); TEST(wxT("GetDynamic - invalid index"), (score.GetDynamic(0) == NULL)); return (true); }
void InspectorTremoloBar::propertiesClicked() { TremoloBar* b = toTremoloBar(inspector->element()); Score* score = b->score(); score->startCmd(); mscore->currentScoreView()->editTremoloBarProperties(b); score->setLayoutAll(); score->endCmd(); }
EditViewFilters::EditViewFilters(Score &score, std::vector<ViewFilter> new_filters) : QUndoCommand(QObject::tr("Edit View Filters")), myScore(score), myOriginalFilters(score.getViewFilters().begin(), score.getViewFilters().end()), myNewFilters(std::move(new_filters)) { }
/// Tests the Guitar In Array Functions /// @return True if all tests were executed, false if not bool ScoreTestSuite::TestCaseGuitarInArray() { //------Last Checked------// // - Jan 6, 2005 Score score; TEST(wxT("IsValidGuitarInIndex - false"), !score.IsValidGuitarInIndex(0)); TEST(wxT("GetGuitarIn - invalid index"), (score.GetGuitarIn(0) == NULL)); return (true); }
void InspectorBend::propertiesClicked() { Bend* b = toBend(inspector->element()); Score* score = b->score(); score->startCmd(); mscore->currentScoreView()->editBendProperties(b); score->setLayoutAll(); score->endCmd(); }
/// Tests the Floating Text Array Functions /// @return True if all tests were executed, false if not bool ScoreTestSuite::TestCaseFloatingTextArray() { //------Last Checked------// // - Jan 6, 2005 Score score; TEST(wxT("IsValidFloatingTextIndex - false"), !score.IsValidFloatingTextIndex(0)); TEST(wxT("GetFloatingText - invalid index"), (score.GetFloatingText(0) == NULL)); return (true); }
/// Tests the Tempo Marker Array Functions /// @return True if all tests were executed, false if not bool ScoreTestSuite::TestCaseTempoMarkerArray() { //------Last Checked------// // - Jan 6, 2005 Score score; TEST(wxT("IsValidTempoMarkerIndex - false"), !score.IsValidTempoMarkerIndex(0)); TEST(wxT("GetTempoMarker - invalid index"), (score.GetTempoMarker(0) == NULL)); return (true); }