Skip to content

Commit

Permalink
Fix header validity in MEI basic export. Fixes #3529
Browse files Browse the repository at this point in the history
  • Loading branch information
lpugin committed Nov 14, 2023
1 parent 938ab77 commit 5d50ac4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,31 @@ bool Doc::GenerateMeasureNumbers()

void Doc::GenerateMEIHeader(bool meiBasic)
{
// Try to preserve titles if we have an existing header
std::list<std::string> titles;
pugi::xpath_node_set titlesNodeSet = m_header.select_nodes("//meiHead/fileDesc/titleStmt/title/text()");
for (pugi::xpath_node titleXpathNode : titlesNodeSet) {
pugi::xml_node titleNode = titleXpathNode.node();
if (!titleNode) continue;
titles.push_back(titleNode.text().as_string());
}

m_header.remove_children();
pugi::xml_node meiHead = m_header.append_child("meiHead");
pugi::xml_node fileDesc = meiHead.append_child("fileDesc");
pugi::xml_node titleStmt = fileDesc.append_child("titleStmt");
titleStmt.append_child("title");
// Re-add preserved titles
if (titles.size() > 0) {
for (auto &title : titles) {
pugi::xml_node titleNode = titleStmt.append_child("title");
pugi::xml_node textNode = titleNode.append_child(pugi::node_pcdata);
textNode.text() = title.c_str();
}
}
// Add an empty title for validity
else {
titleStmt.append_child("title");
}
pugi::xml_node pubStmt = fileDesc.append_child("pubStmt");
pugi::xml_node date = pubStmt.append_child("date");

Expand Down
4 changes: 2 additions & 2 deletions src/iomei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ bool MEIOutput::WriteDoc(Doc *doc)

// ---- header ----
if (!m_ignoreHeader) {
if (!m_doc->m_header.first_child()) m_doc->GenerateMEIHeader(this->GetBasic());
if (this->GetBasic() || !m_doc->m_header.first_child()) m_doc->GenerateMEIHeader(this->GetBasic());
m_mei.append_copy(m_doc->m_header.first_child());
// Add transposition in the revision list but not in mei-basic
if (!this->GetBasic() && !m_doc->GetOptions()->m_transpose.GetValue().empty()) {
Expand All @@ -1459,7 +1459,7 @@ bool MEIOutput::WriteDoc(Doc *doc)

pugi::xml_node music = m_mei.append_child("music");
Facsimile *facs = doc->GetFacsimile();
if ((facs != NULL) && (facs->GetChildCount() > 0)) {
if (!this->GetBasic() && (facs != NULL) && (facs->GetChildCount() > 0)) {
pugi::xml_node facsimile = music.append_child("facsimile");
this->WriteFacsimile(facsimile, facs);
m_nodeStack.push_back(facsimile);
Expand Down

0 comments on commit 5d50ac4

Please sign in to comment.