Skip to content

Commit

Permalink
Improve XML instrument import
Browse files Browse the repository at this point in the history
Backport of musescore#23366, only partial, not the 'other improvements'
  • Loading branch information
miiizen authored and Jojo-Schmitz committed Oct 4, 2024
1 parent 5ebac73 commit 48d567b
Show file tree
Hide file tree
Showing 7 changed files with 5,168 additions and 10 deletions.
22 changes: 15 additions & 7 deletions importexport/musicxml/importmxmlpass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1916,12 +1916,13 @@ void MusicXMLParserPass1::partList(MusicXmlPartGroupList& partGroupList)

int scoreParts = 0; // number of score-parts read sofar
MusicXmlPartGroupMap partGroups;
QString curPartGroupName;

while (_e.readNextStartElement()) {
if (_e.name() == "part-group")
partGroup(scoreParts, partGroupList, partGroups);
partGroup(scoreParts, partGroupList, partGroups, curPartGroupName);
else if (_e.name() == "score-part") {
scorePart();
scorePart(curPartGroupName);
scoreParts++;
}
else
Expand Down Expand Up @@ -2036,7 +2037,7 @@ static void partGroupStop(MusicXmlPartGroupMap& pgs, int n, int p,

void MusicXMLParserPass1::partGroup(const int scoreParts,
MusicXmlPartGroupList& partGroupList,
MusicXmlPartGroupMap& partGroups)
MusicXmlPartGroupMap& partGroups, QString& curPartGroupName)
{
_logger->logDebugTrace("MusicXMLParserPass1::partGroup", &_e);
bool barlineSpan = true;
Expand All @@ -2048,7 +2049,7 @@ void MusicXMLParserPass1::partGroup(const int scoreParts,

while (_e.readNextStartElement()) {
if (_e.name() == "group-name")
_e.skipCurrentElement(); // skip but don't log
curPartGroupName = _e.readElementText();
else if (_e.name() == "group-abbreviation")
symbol = _e.readElementText();
else if (_e.name() == "group-symbol")
Expand Down Expand Up @@ -2122,7 +2123,7 @@ void MusicXMLParserPass1::addInferredTranspose(const QString& partId)
which is invalid MusicXML but is (sometimes ?) generated by NWC2MusicXML.
*/

void MusicXMLParserPass1::scorePart()
void MusicXMLParserPass1::scorePart(const QString& curPartGroupName)
{
_logger->logDebugTrace("MusicXMLParserPass1::scorePart", &_e);
QString id = _e.attributes().value("id").toString().trimmed();
Expand Down Expand Up @@ -2186,7 +2187,7 @@ void MusicXMLParserPass1::scorePart()
else if (_e.name() == "group") // TODO
_e.skipCurrentElement(); // skip but don't log
else if (_e.name() == "score-instrument")
scoreInstrument(id);
scoreInstrument(id, curPartGroupName);
else if (_e.name() == "player") // unsupported
_e.skipCurrentElement(); // skip but don't log
else if (_e.name() == "midi-device") {
Expand Down Expand Up @@ -2222,7 +2223,7 @@ void MusicXMLParserPass1::scorePart()
Parse the /score-partwise/part-list/score-part/score-instrument node.
*/

void MusicXMLParserPass1::scoreInstrument(const QString& partId)
void MusicXMLParserPass1::scoreInstrument(const QString& partId, const QString& curPartGroupName)
{
_logger->logDebugTrace("MusicXMLParserPass1::scoreInstrument", &_e);
QString instrId = _e.attributes().value("id").toString();
Expand All @@ -2239,6 +2240,13 @@ void MusicXMLParserPass1::scoreInstrument(const QString& partId)
qPrintable(instrName)
);
*/

// Finale exports all instrument names as 'Grand Piano' - use part name
if (_exporterString.contains("finale")) {
instrName = _parts[partId].getName();
if (instrName.size() <= 1)
instrName = curPartGroupName;
}
_instruments[partId].insert(instrId, MusicXMLInstrument(instrName));
// Element instrument-name is typically not displayed in the score,
// but used only internally
Expand Down
6 changes: 3 additions & 3 deletions importexport/musicxml/importmxmlpass1.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ class MusicXMLParserPass1 {
void defaults();
void pageLayout(MxmlPageFormat& pf, const qreal conversion);
void partList(MusicXmlPartGroupList& partGroupList);
void partGroup(const int scoreParts, MusicXmlPartGroupList& partGroupList, MusicXmlPartGroupMap& partGroups);
void scorePart();
void partGroup(const int scoreParts, MusicXmlPartGroupList& partGroupList, MusicXmlPartGroupMap& partGroups, QString& curPartGroupName);
void scorePart(const QString& curPartGroupName);
void setStyle(const QString& type, const double val);
void scoreInstrument(const QString& partId);
void scoreInstrument(const QString& partId, const QString& curPartGroupName);
void midiInstrument(const QString& partId);
void part();
void measure(const QString& partId, const Fraction cTime, Fraction& mdur, VoiceOverlapDetector& vod, const int measureNr);
Expand Down
Loading

0 comments on commit 48d567b

Please sign in to comment.