From d9618fbe0bd0d7e85e542329693aa6ff55a92864 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 8 Aug 2019 23:38:27 -0400 Subject: [PATCH] Fix #293113: Number instruments when using New Score Wizard --- mscore/instrwidget.cpp | 39 +++++++++++++++++++++++++++++++++++++++ mscore/instrwidget.h | 1 + 2 files changed, 40 insertions(+) diff --git a/mscore/instrwidget.cpp b/mscore/instrwidget.cpp index ac73c501fa3a..9987a193f663 100644 --- a/mscore/instrwidget.cpp +++ b/mscore/instrwidget.cpp @@ -1029,6 +1029,7 @@ void InstrumentsWidget::createInstruments(Score* cs) m->cmdAddStaves(sidx, eidx, true); staffIdx += rstaff; } + numberInstrumentNames(cs); #if 0 // TODO // // check for bar lines @@ -1052,6 +1053,44 @@ void InstrumentsWidget::createInstruments(Score* cs) cs->setLayoutAll(); } +//--------------------------------------------------------- +// numberInstrumentNames +//--------------------------------------------------------- + +void InstrumentsWidget::numberInstrumentNames(Score* cs) + { + vector names; + vector firsts; + + for (auto i = cs->parts().begin(); i != cs->parts().end(); ++i) { + auto p = *i; + + QString name = p->partName(); + + names.push_back(name); + int n = 1; + + for (auto j = i + 1; j != cs->parts().end(); ++j) { + auto part = *j; + // number 2nd and subsequent instances of instrument + if (std::find(names.begin(), names.end(), part->partName()) != names.end()) { + firsts.push_back(name); + n++; + part->setPartName((part->partName() + QStringLiteral(" %1").arg(n))); + part->setLongName((part->longName() + QStringLiteral(" %1").arg(n))); + part->setShortName((part->shortName() + QStringLiteral(" %1").arg(n))); + } + } + + // now finish by adding first instances + if (std::find(firsts.begin(), firsts.end(), p->partName()) != firsts.end()) { + p->setPartName(p->partName() + " 1"); + p->setLongName(p->longName() + " 1"); + p->setShortName(p->shortName() + " 1"); + } + } + } + //--------------------------------------------------------- // init //--------------------------------------------------------- diff --git a/mscore/instrwidget.h b/mscore/instrwidget.h index 4cc9392ee212..ad0c773d81df 100644 --- a/mscore/instrwidget.h +++ b/mscore/instrwidget.h @@ -154,6 +154,7 @@ class InstrumentsWidget : public QWidget, public Ui::InstrumentsWidget { void genPartList(Score*); void init(); void createInstruments(Score*); + void numberInstrumentNames(Score*); QTreeWidget* getPartiturList(); };