Skip to content

Commit

Permalink
Add mei-facs output option in the command-line tool
Browse files Browse the repository at this point in the history
  • Loading branch information
lpugin committed Dec 28, 2023
1 parent ca05528 commit cc9269d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
17 changes: 15 additions & 2 deletions src/toolkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand All @@ -838,6 +842,7 @@ std::string Toolkit::GetMEI(const std::string &jsonOptions)
if (json.has<jsonxx::String>("firstMeasure")) firstMeasure = json.get<jsonxx::String>("firstMeasure");
if (json.has<jsonxx::String>("lastMeasure")) lastMeasure = json.get<jsonxx::String>("lastMeasure");
if (json.has<jsonxx::String>("mdiv")) mdiv = json.get<jsonxx::String>("mdiv");
if (json.has<jsonxx::Boolean>("generateFacs")) generateFacs = json.get<jsonxx::Boolean>("generateFacs");
}
}

Expand All @@ -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);
Expand All @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions tools/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit cc9269d

Please sign in to comment.