From cb41210d074dd2cdcdc411a3852b8396f46396fa Mon Sep 17 00:00:00 2001 From: Craig Stuart Sapp Date: Sun, 24 Sep 2023 20:57:42 -0700 Subject: [PATCH] Implementation for issue https://github.com/humdrum-tools/verovio-humdrum-viewer/issues/840 --- include/hum/humlib.h | 10 +++--- src/hum/humlib.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++- src/iohumdrum.cpp | 12 +++++-- 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/include/hum/humlib.h b/include/hum/humlib.h index 8ee9b86f573..cc4c4383696 100644 --- a/include/hum/humlib.h +++ b/include/hum/humlib.h @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Sat Sep 23 22:51:29 PDT 2023 +// Last Modified: Sun Sep 24 17:52:16 PDT 2023 // Filename: min/humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.h // Syntax: C++11 @@ -7914,9 +7914,10 @@ class Tool_kern2mens : public HumTool { bool run (HumdrumFile& infile, ostream& out); protected: - void convertToMens (HumdrumFile& infile); - string convertKernTokenToMens (HTp token); - void printBarline (HumdrumFile& infile, int line); + void convertToMens (HumdrumFile& infile); + std::string convertKernTokenToMens(HTp token); + void printBarline (HumdrumFile& infile, int line); + std::string getClefConversion (HTp token); private: bool m_numbersQ = true; // used with -N option @@ -8344,6 +8345,7 @@ class Tool_mens2kern : public HumTool { int brevis_def, int semibrevis_def); void getMensuralInfo (HTp token, int& maximodus, int& modus, int& tempus, int& prolatio); + std::string getClefConversion(HTp token); private: bool m_debugQ; diff --git a/src/hum/humlib.cpp b/src/hum/humlib.cpp index 15494811bc6..6bc49f32329 100644 --- a/src/hum/humlib.cpp +++ b/src/hum/humlib.cpp @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Sat Sep 23 22:51:29 PDT 2023 +// Last Modified: Sun Sep 24 17:52:16 PDT 2023 // Filename: min/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.cpp // Syntax: C++11 @@ -86326,6 +86326,9 @@ string Tool_kern2mens::convertKernTokenToMens(HTp token) { data += m_clef; return data; } + } else if (hre.search(token, "^\\*[mo]?clef")) { + string value = getClefConversion(token); + return value; } } if (!token->isData()) { @@ -86446,6 +86449,78 @@ void Tool_kern2mens::printBarline(HumdrumFile& infile, int line) { +////////////////////////////// +// +// Tool_kern2mens::getClefConversion -- +// If token is *oclef and there is an adjacent *clef, +// convert *oclef to *clef and *clef to *mclef; otherwise, +// return the given clef. +// +// + +string Tool_kern2mens::getClefConversion(HTp token) { + + vector clefs; + vector oclefs; + vector mclefs; + + HumRegex hre; + + HTp current = token->getNextToken(); + while (current) { + if (current->isData()) { + break; + } + if (current->compare(0, 5, "*clef") == 0) { + clefs.push_back(current); + } + if (current->compare(0, 6, "*oclef") == 0) { + oclefs.push_back(current); + } + if (current->compare(0, 6, "*mclef") == 0) { + mclefs.push_back(current); + } + current = current->getNextToken(); + } + + current = token->getPreviousToken(); + while (current) { + if (current->isData()) { + break; + } + if (current->compare(0, 5, "*clef") == 0) { + clefs.push_back(current); + } + if (current->compare(0, 6, "*oclef") == 0) { + oclefs.push_back(current); + } + if (current->compare(0, 6, "*mclef") == 0) { + mclefs.push_back(current); + } + current = current->getPreviousToken(); + } + + if (token->compare(0, 5, "*clef") == 0) { + if (oclefs.size() > 0) { + string value = *token; + hre.replaceDestructive(value, "mclef", "clef"); + return value; + } + } + + if (token->compare(0, 6, "*oclef") == 0) { + if (clefs.size() > 0) { + string value = *token; + hre.replaceDestructive(value, "clef", "oclef"); + return value; + } + } + + return *token; +} + + + ///////////////////////////////// // diff --git a/src/iohumdrum.cpp b/src/iohumdrum.cpp index 9633e944745..b861cf19d1e 100644 --- a/src/iohumdrum.cpp +++ b/src/iohumdrum.cpp @@ -5729,7 +5729,7 @@ void HumdrumInput::fillStaffInfo(hum::HTp staffstart, int staffnumber, int staff ss[staffindex].meter_bottom = bot; ss[staffindex].meter_top = top; if (bot == 0) { - // Can't to breve meters, so switch to semibreve meter (whole notes). + // Can't do breve meters, so switch to semibreve meter (whole notes). ss[staffindex].meter_bottom = 1; ss[staffindex].meter_top *= 2; } @@ -5785,7 +5785,10 @@ void HumdrumInput::fillStaffInfo(hum::HTp staffstart, int staffnumber, int staff // short-circuit *met with *omet for **mens data if (staffstart->isMensLike()) { if ((!m_omet.empty()) && (staffnumber == m_omet.back().first)) { - metersig = *m_omet.back().second; + auto ploc = m_omet.back().second->rfind(")"); + if (ploc != std::string::npos) { + metersig = m_omet.back().second->substr(6, ploc - 6); + } metertok = m_omet.back().second; } } @@ -11886,7 +11889,10 @@ bool HumdrumInput::fillContentsOfLayer(int track, int startline, int endline, in } } if (m_mens) { - if (token->isMensurationSymbol()) { + if (token->compare(0, 6, "*omet(") == 0) { + setMensurationSymbol(m_layer, *token, staffindex, token); + } + else if (token->isMensurationSymbol()) { // add mensuration change to layer. setMensurationSymbol(m_layer, *token, staffindex, token); }