diff --git a/src/doc.cpp b/src/doc.cpp index 0220bc69469..e79a92b74b0 100644 --- a/src/doc.cpp +++ b/src/doc.cpp @@ -289,11 +289,31 @@ bool Doc::GenerateMeasureNumbers() void Doc::GenerateMEIHeader(bool meiBasic) { + // Try to preserve titles if we have an existing header + std::list 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"); diff --git a/src/iomei.cpp b/src/iomei.cpp index 0b450b2ebc0..385764c9b59 100644 --- a/src/iomei.cpp +++ b/src/iomei.cpp @@ -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()) { @@ -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);