Skip to content

Commit

Permalink
Implementation for issue humdrum-tools/verovio-humdrum-viewer#840
Browse files Browse the repository at this point in the history
  • Loading branch information
craigsapp committed Sep 25, 2023
1 parent 7d7569a commit cb41210
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 8 deletions.
10 changes: 6 additions & 4 deletions include/hum/humlib.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Programmer: Craig Stuart Sapp <[email protected]>
// 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
77 changes: 76 additions & 1 deletion src/hum/humlib.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Programmer: Craig Stuart Sapp <[email protected]>
// 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
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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<HTp> clefs;
vector<HTp> oclefs;
vector<HTp> 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;
}




/////////////////////////////////
//
Expand Down
12 changes: 9 additions & 3 deletions src/iohumdrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit cb41210

Please sign in to comment.