Skip to content

Commit

Permalink
ENG-27: Apply MusicXML import options and styles for conversion job
Browse files Browse the repository at this point in the history
  • Loading branch information
iveshenry18 authored and vpereverzev committed May 18, 2021
1 parent 3224f34 commit 3bb7eb9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
1 change: 1 addition & 0 deletions global/settings/types/preferencekeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#define PREF_IMPORT_GUITARPRO_CHARSET "import/guitarpro/charset"
#define PREF_IMPORT_MUSICXML_IMPORTBREAKS "import/musicXML/importBreaks"
#define PREF_IMPORT_MUSICXML_IMPORTLAYOUT "import/musicXML/importLayout"
#define PREF_IMPORT_MUSICXML_REMOVEINSTRUMENTNAMES "import/musicXML/removeInstrumentNames"
#define PREF_IMPORT_OVERTURE_CHARSET "import/overture/charset"
#define PREF_IMPORT_STYLE_STYLEFILE "import/style/styleFile"
#define PREF_MIGRATION_DO_NOT_ASK_ME_AGAIN "import/compatibility/do_not_ask_me_again"
Expand Down
47 changes: 46 additions & 1 deletion importexport/musicxml/importmxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "libmscore/page.h"
#include "libmscore/part.h"
#include "libmscore/staff.h"
#include "libmscore/style.h"
#include "libmscore/sym.h"
#include "libmscore/symbol.h"

Expand All @@ -34,6 +35,43 @@

namespace Ms {

Score::FileError removeInstrumentNames(Score* score, MxmlLogger* logger)
{
for (Part* part : score->parts()) {
logger->logDebugInfo(QString("Removing instrument names from '%1')")
.arg(part->instrumentName()));
part->setPlainLongName(QString(""));
part->setPlainShortName(QString(""));
}

return Score::FileError::FILE_NO_ERROR;
}

Score::FileError applyMusicXMLStyles(Score* score, MxmlLogger* logger)
{

// Reset styles to default
auto ignoreStyles = pageStyles();
ignoreStyles.insert(Sid::concertPitch);
ignoreStyles.insert(Sid::createMultiMeasureRests);
score->style().resetAllStyles(score, ignoreStyles);
score->update();

// Apply PVG MusicXML Style Sheet
bool styleLoadResult = score->loadStyle(":/styles/PVGMusicXML.mss", /*ign*/false, /*overlap*/true);
if (!styleLoadResult) {
logger->logError(QString("importMusicXMLfromBuffer could not load :/styles/PVGMusicXML.mss"));
return Score::FileError::FILE_NOT_FOUND;
}

// Remove instrument names
if (preferences.getBool(PREF_IMPORT_MUSICXML_REMOVEINSTRUMENTNAMES))
removeInstrumentNames(score, logger);

return Score::FileError::FILE_NO_ERROR;
}


Score::FileError importMusicXMLfromBuffer(Score* score, const QString& /*name*/, QIODevice* dev)
{
//qDebug("importMusicXMLfromBuffer(score %p, name '%s', dev %p)",
Expand All @@ -54,7 +92,14 @@ Score::FileError importMusicXMLfromBuffer(Score* score, const QString& /*name*/,
// pass 2
dev->seek(0);
MusicXMLParserPass2 pass2(score, pass1, &logger);
return pass2.parse(dev);
Score::FileError res2 = pass2.parse(dev);

// Apply Styles (possibly unique to Faber/Hal Leonard Conversion Job)
Score::FileError styleRes = applyMusicXMLStyles(score, &logger);
if (styleRes != Score::FileError::FILE_NO_ERROR)
return styleRes;

return res2;
}

} // namespace Ms
1 change: 1 addition & 0 deletions mscore/musescore.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<file>data/icons/edit.svg</file>
<file alias="styles/Leland.mss">../share/styles/Leland.mss</file>
<file alias="styles/Edwin.mss">../share/styles/Edwin.mss</file>
<file alias="styles/PVGMusicXML.mss">../share/styles/PVGMusicXML.mss</file>
<file alias="styles/legacy-style-defaults-v3.mss">../share/styles/legacy-style-defaults-v3.mss</file>
<file alias="styles/legacy-style-defaults-v2.mss">../share/styles/legacy-style-defaults-v2.mss</file>
<file alias="styles/legacy-style-defaults-v1.mss">../share/styles/legacy-style-defaults-v1.mss</file>
Expand Down
3 changes: 2 additions & 1 deletion mscore/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void Preferences::init(bool storeInMemoryOnly)
{PREF_MIGRATION_APPLY_LELAND_STYLE, new BoolPreference(false, false)},
{PREF_MIGRATION_APPLY_EDWIN_STYLE, new BoolPreference(false, false)},
{PREF_MIGRATION_RESET_ELEMENT_POSITIONS, new BoolPreference(false, false)},
{PREF_MIGRATION_APPLY_EDWIN_FOR_XML_FILES, new BoolPreference(false, false)},
{PREF_MIGRATION_APPLY_EDWIN_FOR_XML_FILES, new BoolPreference(true, false)}, // TODO: this default does not appear to be honored
{PREF_MIGRATION_DO_NOT_ASK_ME_AGAIN_XML, new BoolPreference(false, false)},
{PREF_APP_BACKUP_GENERATE_BACKUP, new BoolPreference(true)},
{PREF_APP_BACKUP_SUBFOLDER, new StringPreference(".mscbackup")},
Expand All @@ -172,6 +172,7 @@ void Preferences::init(bool storeInMemoryOnly)
{PREF_IMPORT_GUITARPRO_CHARSET, new StringPreference("UTF-8", false)},
{PREF_IMPORT_MUSICXML_IMPORTBREAKS, new BoolPreference(true, false)},
{PREF_IMPORT_MUSICXML_IMPORTLAYOUT, new BoolPreference(true, false)},
{PREF_IMPORT_MUSICXML_REMOVEINSTRUMENTNAMES, new BoolPreference(true, false)}, // TODO: add to preferences menu
{PREF_IMPORT_OVERTURE_CHARSET, new StringPreference("GBK", false)},
{PREF_IMPORT_STYLE_STYLEFILE, new StringPreference("", false)},
{PREF_IO_ALSA_DEVICE, new StringPreference("default", false)},
Expand Down
1 change: 1 addition & 0 deletions share/styles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
install(FILES
Leland.mss
MuseJazz.mss
PVGMusicXML.mss
legacy-style-defaults-v3.mss
legacy-style-defaults-v2.mss
legacy-style-defaults-v1.mss
Expand Down
8 changes: 8 additions & 0 deletions share/styles/PVGMusicXML.mss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<museScore version="3.02">
<Style>
<hideEmptyStaves>1</hideEmptyStaves>
<dontHidStavesInFirstSystm>0</dontHidStavesInFirstSystm>
<defaultsVersion>302</defaultsVersion>
</Style>
</museScore>

0 comments on commit 3bb7eb9

Please sign in to comment.