Skip to content

Commit

Permalink
Use correct MusicXML ID for unknown percussion instruments
Browse files Browse the repository at this point in the history
Backport of musescore#26176
  • Loading branch information
shoogle authored and Jojo-Schmitz committed Jan 21, 2025
1 parent d875209 commit 8ff1173
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions libmscore/instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,28 @@ void Instrument::write(XmlWriter& xml, const Part* part) const

QString Instrument::recognizeInstrumentId() const
{
static QString defaultInstrumentId("keyboard.piano");
// Return a MusicXML "Sound ID", which is essentially an instrument ID.
// See https://github.com/w3c/musicxml/blob/gh-pages/schema/sounds.xml
static const QString defaultInstrumentId("keyboard.piano");
static const QString defaultMusicXmlPercussionId("drum.group.set");

QList<QString> nameList;

nameList << _trackName;
nameList << _longNames.toStringList();
nameList << _shortNames.toStringList();

InstrumentTemplate* tmplByName = Ms::searchTemplateForInstrNameList(nameList);
const InstrumentTemplate* tmplByName = Ms::searchTemplateForInstrNameList(nameList/*, _useDrumset*/);

if (tmplByName && !tmplByName->musicXMLid.isEmpty())
return tmplByName->musicXMLid;

if (!channel(0))
const Channel* channel = this->channel(0);

if (!channel)
return defaultInstrumentId;

InstrumentTemplate* tmplMidiProgram = Ms::searchTemplateForMidiProgram(channel(0)->program(), useDrumset());
InstrumentTemplate* tmplMidiProgram = Ms::searchTemplateForMidiProgram(channel->program(), _useDrumset);

if (tmplMidiProgram && !tmplMidiProgram->musicXMLid.isEmpty())
return tmplMidiProgram->musicXMLid;
Expand All @@ -314,6 +319,8 @@ QString Instrument::recognizeInstrumentId() const
if (guessedTmpl && !guessedTmpl->musicXMLid.isEmpty())
return guessedTmpl->musicXMLid;

if (_useDrumset)
return defaultMusicXmlPercussionId;
return defaultInstrumentId;
}

Expand Down Expand Up @@ -1633,7 +1640,7 @@ void Instrument::updateInstrumentId()
}
}

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

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

0 comments on commit 8ff1173

Please sign in to comment.