Skip to content

Commit

Permalink
fix #281007: MusicXML export: allow exporting scores without invisibl…
Browse files Browse the repository at this point in the history
…e elements
  • Loading branch information
dmitrio95 authored and vpereverzev committed Jul 5, 2021
1 parent 69866a7 commit 250fd0c
Show file tree
Hide file tree
Showing 8 changed files with 2,934 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/importexport/musicxml/imusicxmlconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class IMusicXmlConfiguration : MODULE_EXPORT_INTERFACE
virtual MusicxmlExportBreaksType musicxmlExportBreaksType() const = 0;
virtual void setMusicxmlExportBreaksType(MusicxmlExportBreaksType breaksType) = 0;

virtual bool musicxmlExportInvisibleElements() const = 0;
virtual void setMusicxmlExportInvisibleElements(bool value) = 0;

virtual bool needUseDefaultFont() const = 0;
virtual void setNeedUseDefaultFont(bool value) = 0;

Expand Down
30 changes: 30 additions & 0 deletions src/importexport/musicxml/internal/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ class ExportMusicXml
double getTenthsFromDots(double) const;
Fraction tick() const { return _tick; }
void writeInstrumentDetails(const Instrument* instrument);
bool canWriteDirection(const Element* e) const;
};

//---------------------------------------------------------
Expand Down Expand Up @@ -5340,6 +5341,10 @@ static void annotations(ExportMusicXml* exp, int strack, int etrack, int track,
// if (fd) qDebug("annotations seg %p found fretboard diagram %p", seg, fd);

for (const Element* e : seg->annotations()) {
if (!exp->canWriteDirection(e)) {
continue;
}

int wtrack = -1; // track to write annotation

if (strack <= e->track() && e->track() < etrack) {
Expand Down Expand Up @@ -5455,6 +5460,10 @@ static void spannerStart(ExportMusicXml* exp, int strack, int etrack, int track,
for (auto it = exp->score()->spanner().lower_bound(stick.ticks()); it != exp->score()->spanner().upper_bound(stick.ticks()); ++it) {
Spanner* e = it->second;

if (!exp->canWriteDirection(e)) {
continue;
}

int wtrack = -1; // track to write spanner
if (strack <= e->track() && e->track() < etrack) {
wtrack = findTrackForAnnotations(e->track(), seg);
Expand Down Expand Up @@ -5510,6 +5519,10 @@ static void spannerStop(ExportMusicXml* exp, int strack, int etrack, const Fract
for (auto it : exp->score()->spanner()) {
Spanner* e = it.second;

if (!exp->canWriteDirection(e)) {
continue;
}

if (e->tick2() != tick2 || e->track() < strack || e->track() >= etrack) {
continue;
}
Expand Down Expand Up @@ -6410,6 +6423,9 @@ static void annotationsWithoutNote(ExportMusicXml* exp, const int strack, const
if (segment->segmentType() == SegmentType::ChordRest) {
for (const auto element : segment->annotations()) {
if (!element->isFiguredBass() && !element->isHarmony()) { // handled elsewhere
if (!exp->canWriteDirection(element)) {
continue;
}
const auto wtrack = findTrackForAnnotations(element->track(), segment); // track to write annotation
if (strack <= element->track() && element->track() < (strack + VOICES * staves) && wtrack < 0) {
commonAnnotations(exp, element, staves > 1 ? 1 : 0);
Expand Down Expand Up @@ -7275,4 +7291,18 @@ void ExportMusicXml::harmony(Harmony const* const h, FretDiagram const* const fd
}
#endif
}

//---------------------------------------------------------
// canWriteDirection
//---------------------------------------------------------

/**
Whether \b <direction> tag corresponding to the given element \p e
should be included to the exported MusicXML file.
*/

bool ExportMusicXml::canWriteDirection(const Element* e) const
{
return e->visible() || configuration()->musicxmlExportInvisibleElements();
}
}
12 changes: 12 additions & 0 deletions src/importexport/musicxml/internal/musicxmlconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static const Settings::Key MUSICXML_IMPORT_BREAKS_KEY(module_name, "import/music
static const Settings::Key MUSICXML_IMPORT_LAYOUT_KEY(module_name, "import/musicXML/importLayout");
static const Settings::Key MUSICXML_EXPORT_LAYOUT_KEY(module_name, "export/musicXML/exportLayout");
static const Settings::Key MUSICXML_EXPORT_BREAKS_TYPE_KEY(module_name, "export/musicXML/exportBreaks");
static const Settings::Key MUSICXML_EXPORT_INVISIBLE_ELEMENTS_KEY(module_name, "export/musicXML/exportInvisibleElements");
static const Settings::Key MIGRATION_APPLY_EDWIN_FOR_XML(module_name, "import/compatibility/apply_edwin_for_xml");
static const Settings::Key MIGRATION_NOT_ASK_AGAING_KEY(module_name, "import/compatibility/do_not_ask_me_again");
static const Settings::Key STYLE_FILE_IMPORT_PATH_KEY(module_name, "import/style/styleFile");
Expand All @@ -42,6 +43,7 @@ void MusicXmlConfiguration::init()
settings()->setDefaultValue(MUSICXML_IMPORT_LAYOUT_KEY, Val(true));
settings()->setDefaultValue(MUSICXML_EXPORT_LAYOUT_KEY, Val(true));
settings()->setDefaultValue(MUSICXML_EXPORT_BREAKS_TYPE_KEY, Val(static_cast<int>(MusicxmlExportBreaksType::All)));
settings()->setDefaultValue(MUSICXML_EXPORT_INVISIBLE_ELEMENTS_KEY, Val(false));
settings()->setDefaultValue(MIGRATION_NOT_ASK_AGAING_KEY, Val(false));
}

Expand Down Expand Up @@ -85,6 +87,16 @@ void MusicXmlConfiguration::setMusicxmlExportBreaksType(MusicxmlExportBreaksType
settings()->setSharedValue(MUSICXML_EXPORT_BREAKS_TYPE_KEY, Val(static_cast<int>(breaksType)));
}

bool MusicXmlConfiguration::musicxmlExportInvisibleElements() const
{
return settings()->value(MUSICXML_EXPORT_INVISIBLE_ELEMENTS_KEY).toBool();
}

void MusicXmlConfiguration::setMusicxmlExportInvisibleElements(bool value)
{
settings()->setValue(MUSICXML_EXPORT_INVISIBLE_ELEMENTS_KEY, Val(value));
}

bool MusicXmlConfiguration::needUseDefaultFont() const
{
return settings()->value(MIGRATION_APPLY_EDWIN_FOR_XML).toBool();
Expand Down
3 changes: 3 additions & 0 deletions src/importexport/musicxml/internal/musicxmlconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class MusicXmlConfiguration : public IMusicXmlConfiguration
MusicxmlExportBreaksType musicxmlExportBreaksType() const override;
void setMusicxmlExportBreaksType(MusicxmlExportBreaksType breaksType) override;

bool musicxmlExportInvisibleElements() const override;
void setMusicxmlExportInvisibleElements(bool value) override;

bool needUseDefaultFont() const override;
void setNeedUseDefaultFont(bool value) override;

Expand Down
Loading

0 comments on commit 250fd0c

Please sign in to comment.