Skip to content

Commit

Permalink
Merge pull request #5260 from IsaacWeiss/instrument-name-numbers
Browse files Browse the repository at this point in the history
Fix #293113: Number instruments when using New Score Wizard
  • Loading branch information
dmitrio95 committed Mar 20, 2020
2 parents 5f97528 + d9618fb commit 0d0db01
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions mscore/instrwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ void InstrumentsWidget::createInstruments(Score* cs)
m->cmdAddStaves(sidx, eidx, true);
staffIdx += rstaff;
}
numberInstrumentNames(cs);
#if 0 // TODO
//
// check for bar lines
Expand All @@ -1066,6 +1067,44 @@ void InstrumentsWidget::createInstruments(Score* cs)
cs->setLayoutAll();
}

//---------------------------------------------------------
// numberInstrumentNames
//---------------------------------------------------------

void InstrumentsWidget::numberInstrumentNames(Score* cs)
{
vector<QString> names;
vector<QString> 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
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions mscore/instrwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class InstrumentsWidget : public QWidget, public Ui::InstrumentsWidget {
void genPartList(Score*);
void init();
void createInstruments(Score*);
void numberInstrumentNames(Score*);
QTreeWidget* getPartiturList();
};

Expand Down

0 comments on commit 0d0db01

Please sign in to comment.