Skip to content

Commit

Permalink
ported #6891: Improves recognition of instrument when loading a pre-3…
Browse files Browse the repository at this point in the history
….6 score.
  • Loading branch information
igorkorsukov authored and vpereverzev committed Feb 4, 2021
1 parent b86e4a7 commit e4fb738
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/libmscore/instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1720,14 +1720,44 @@ void Instrument::updateInstrumentId()
return;
}

// When reading a score create with pre-3.6, instruments doesn't
// have an id define in the instrument. So try to find the instrumentId
// based on MusicXMLid.
// This requires a hack for instruments using MusicXMLid "strings.group"
// because there are multiple instrument using this same id.
// For these instruments, use the value of controller 32 of the "arco"
// channel to find the correct instrument.
const QString arco = QString("arco");
const bool groupHack = instrumentId() == QString("strings.group");
const int idxref = channelIdx(arco);
const int val32ref = (idxref < 0) ? -1 : channel(idxref)->bank();
QString fallback;

for (InstrumentGroup* g : qAsConst(instrumentGroups)) {
for (InstrumentTemplate* it : qAsConst(g->instrumentTemplates)) {
if (it->musicXMLid == instrumentId()) {
_id = it->id;
return;
if (groupHack) {
if (fallback.isEmpty()) {
// Instrument "Strings" doesn't have bank defined so
// if no "strings.group" instrument with requested bank
// is found, assume "Strings".
fallback = it->id;
}
for (const Channel& chan : it->channel) {
if ((chan.name() == arco) && (chan.bank() == val32ref)) {
_id = it->id;
return;
}
}
} else {
_id = it->id;
return;
}
}
}
}

_id = fallback.isEmpty() ? QString("piano") : fallback;
}

//---------------------------------------------------------
Expand Down

0 comments on commit e4fb738

Please sign in to comment.