From cc9269df0bd0ba3f2d47e6698f92d237f90c57e1 Mon Sep 17 00:00:00 2001 From: Laurent Pugin Date: Thu, 28 Dec 2023 19:17:22 +0000 Subject: [PATCH] Add mei-facs output option in the command-line tool --- src/options.cpp | 2 +- src/toolkit.cpp | 17 +++++++++++++++-- tools/main.cpp | 14 +++++++++----- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/options.cpp b/src/options.cpp index 08aa84dad59..294837d2679 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -954,7 +954,7 @@ Options::Options() m_baseOptions.AddOption(&m_scale); m_outputTo.SetInfo("Output to", - "Select output format to: \"mei\", \"mei-pb\", \"mei-basic\", \"svg\", \"midi\", \"timemap\", " + "Select output format to: \"mei\", \"mei-pb\", \"mei-facs\", \"mei-basic\", \"svg\", \"midi\", \"timemap\", " "\"expansionmap\", \"humdrum\" or " "\"pae\""); m_outputTo.Init("svg"); diff --git a/src/toolkit.cpp b/src/toolkit.cpp index c946c020aca..b7a31251bd2 100644 --- a/src/toolkit.cpp +++ b/src/toolkit.cpp @@ -152,6 +152,9 @@ bool Toolkit::SetOutputTo(std::string const &outputTo) else if (outputTo == "mei-pb") { m_outputTo = MEI; } + else if (outputTo == "mei-facs") { + m_outputTo = MEI; + } else if (outputTo == "midi") { m_outputTo = MIDI; } @@ -816,6 +819,7 @@ std::string Toolkit::GetMEI(const std::string &jsonOptions) std::string firstMeasure; std::string lastMeasure; std::string mdiv; + bool generateFacs = false; jsonxx::Object json; @@ -838,6 +842,7 @@ std::string Toolkit::GetMEI(const std::string &jsonOptions) if (json.has("firstMeasure")) firstMeasure = json.get("firstMeasure"); if (json.has("lastMeasure")) lastMeasure = json.get("lastMeasure"); if (json.has("mdiv")) mdiv = json.get("mdiv"); + if (json.has("generateFacs")) generateFacs = json.get("generateFacs"); } } @@ -858,8 +863,6 @@ std::string Toolkit::GetMEI(const std::string &jsonOptions) m_doc.DeactiveateSelection(); } - m_doc.SyncToFacsimileDoc(); - MEIOutput meioutput(&m_doc); meioutput.SetScoreBasedMEI(scoreBased); meioutput.SetBasic(basic); @@ -875,6 +878,16 @@ std::string Toolkit::GetMEI(const std::string &jsonOptions) if (!lastMeasure.empty()) meioutput.SetLastMeasure(lastMeasure); if (!mdiv.empty()) meioutput.SetMdiv(mdiv); + if (generateFacs) { + if (meioutput.HasFilter() || !scoreBased || (m_options->m_breaks.GetValue() != BREAKS_encoded) + || m_doc.HasSelection()) { + LogError("Generating facsimile is only possible with all pages, encoded breaks, score-based output and " + "without selection."); + return ""; + } + m_doc.SyncToFacsimileDoc(); + } + std::string output = meioutput.GetOutput(); if (hadSelection) m_doc.ReactivateSelection(false); diff --git a/tools/main.cpp b/tools/main.cpp index 6f5aba3d793..3c0c8ee647f 100644 --- a/tools/main.cpp +++ b/tools/main.cpp @@ -279,10 +279,11 @@ int main(int argc, char **argv) } if ((outformat != "svg") && (outformat != "mei") && (outformat != "mei-basic") && (outformat != "mei-pb") - && (outformat != "midi") && (outformat != "timemap") && (outformat != "expansionmap") - && (outformat != "humdrum") && (outformat != "hum") && (outformat != "pae")) { + && (outformat != "mei-facs") && (outformat != "midi") && (outformat != "timemap") + && (outformat != "expansionmap") && (outformat != "humdrum") && (outformat != "hum") && (outformat != "pae")) { std::cerr << "Output format (" << outformat - << ") can only be 'mei', 'mei-basic', 'mei-pb', 'svg', 'midi', 'timemap', 'expansionmap', 'humdrum' " + << ") can only be 'mei', 'mei-basic', 'mei-pb', mei-facs', 'svg', 'midi', 'timemap', 'expansionmap', " + "'humdrum' " "or 'pae'." << std::endl; exit(1); @@ -553,10 +554,12 @@ int main(int argc, char **argv) const char *scoreBased = (outformat == "mei-pb") ? "false" : "true"; const char *basic = (outformat == "mei-basic") ? "true" : "false"; const char *removeIds = (options->m_removeIds.GetValue()) ? "true" : "false"; + const char *generateFacs = (outformat == "mei-facs") ? "true" : "false"; outfile += ".mei"; if (all_pages) { std::string params - = vrv::StringFormat("{'scoreBased': %s, 'basic': %s, 'removeIds': %s}", scoreBased, basic, removeIds); + = vrv::StringFormat("{'scoreBased': %s, 'basic': %s, 'removeIds': %s, 'generateFacs': %s}", scoreBased, + basic, removeIds, generateFacs); if (std_output) { std::string output; std::cout << toolkit.GetMEI(params); @@ -570,7 +573,8 @@ int main(int argc, char **argv) } else { std::string params = vrv::StringFormat( - "{'scoreBased': %s, 'basic': %s, 'pageNo': %d, 'removeIds': %s}", scoreBased, basic, page, removeIds); + "{'scoreBased': %s, 'basic': %s, 'pageNo': %d, 'removeIds': %s, 'generateFacs': %s}", scoreBased, basic, + page, removeIds, generateFacs); if (std_output) { std::cout << toolkit.GetMEI(params); }