Skip to content

Commit

Permalink
Humlib updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
craigsapp committed Oct 3, 2023
1 parent 8ccd750 commit 82197ef
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 11 deletions.
12 changes: 8 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: Wed Sep 27 21:52:41 PDT 2023
// Last Modified: Mon Oct 2 19:58:27 PDT 2023
// Filename: min/humlib.h
// URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.h
// Syntax: C++11
Expand Down Expand Up @@ -39,13 +39,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef _HUMLIB_H_INCLUDED
#define _HUMLIB_H_INCLUDED

#include <stdarg.h>
#include <string.h>

#include <algorithm>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdarg>
#include <cstring>
#include <cstring>
#include <ctime>
#include <fstream>
Expand Down Expand Up @@ -7948,6 +7947,7 @@ class Tool_kern2mens : public HumTool {
void printBarline (HumdrumFile& infile, int line);
std::string getClefConversion (HTp token);
void storeKernEditorialAccidental(HumdrumFile& infile);
void storeKernTerminalLong (HumdrumFile& infile);
void addVerovioStyling (HumdrumFile& infile);

private:
Expand All @@ -7962,6 +7962,10 @@ class Tool_kern2mens : public HumTool {
int m_kernEdAccLineIndex = -1;
std::string m_mensEdAccLine;

std::string m_kernTerminalLong; // used with !!!RDF**kern:
int m_kernTerminalLongIndex = -1;
std::string m_mensTerminalLongLine;

};


Expand Down
71 changes: 64 additions & 7 deletions 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: Wed Sep 27 21:52:41 PDT 2023
// Last Modified: Mon Oct 2 19:58:27 PDT 2023
// Filename: min/humlib.cpp
// URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.cpp
// Syntax: C++11
Expand Down Expand Up @@ -86575,6 +86575,7 @@ bool Tool_kern2mens::run(HumdrumFile& infile) {
m_noverovioQ = getBoolean("no-verovio");
m_clef = getString("clef");
storeKernEditorialAccidental(infile);
storeKernTerminalLong(infile);
convertToMens(infile);
return true;
}
Expand All @@ -86595,7 +86596,9 @@ void Tool_kern2mens::convertToMens(HumdrumFile& infile) {
}
if (!infile[i].hasSpines()) {
if (i == m_kernEdAccLineIndex) {
m_humdrum_text << m_mensEdAccLine;
m_humdrum_text << m_mensEdAccLine << endl;
} else if (i == m_kernTerminalLongIndex) {
m_humdrum_text << m_mensTerminalLongLine << endl;
} else {
m_humdrum_text << infile[i] << "\n";
}
Expand All @@ -86622,7 +86625,9 @@ void Tool_kern2mens::convertToMens(HumdrumFile& infile) {

//////////////////////////////
//
// Tool_kern2mens::addVerovioStyling --
// Tool_kern2mens::addVerovioStyling -- Add a spacing of 0.3, 0.5 if no
// spacing is already found in the data. Use the -V option to no add any
// spacing options (to use the defaults in verovio).
//

void Tool_kern2mens::addVerovioStyling(HumdrumFile& infile) {
Expand All @@ -86631,11 +86636,19 @@ void Tool_kern2mens::addVerovioStyling(HumdrumFile& infile) {
if (infile[i].hasSpines()) {
continue;
}
if (hre.search(infile[i].token(0), "!!!verovio:\\s*evenNoteSpacing")) {
HTp token = infile[i].token(0);
if (hre.search(token, "!!!verovio:\\s*evenNoteSpacing")) {
return;
}
if (hre.search(token, "!!!verovio:\\s*spacingLinear")) {
return;
}
if (hre.search(token, "!!!verovio:\\s*spacingNonLinear")) {
return;
}
}
m_humdrum_text << "!!!verovio: evenNoteSpacing\n";
m_humdrum_text << "!!!verovio: spacingLinear 0.3\n";
m_humdrum_text << "!!!verovio: spacingNonLinear 0.5\n";
}


Expand Down Expand Up @@ -86714,6 +86727,15 @@ string Tool_kern2mens::convertKernTokenToMens(HTp token) {
hre.replaceDestructive(data, "$1z", "([#-n]+)", "g");
}
}

// transfer terminal longs
if (!m_kernTerminalLong.empty()) {
string searchTerm = "(" + m_kernTerminalLong + "+)";
if (hre.search(token, searchTerm)) {
data += hre.getMatch(1);
}
}

return data;
}

Expand Down Expand Up @@ -86901,6 +86923,41 @@ void Tool_kern2mens::storeKernEditorialAccidental(HumdrumFile& infile) {



//////////////////////////////
//
// Tool_kern2mens::storeKernTerminalLong --
//

void Tool_kern2mens::storeKernTerminalLong(HumdrumFile& infile) {
for (int i=infile.getLineCount() - 1; i>= 0; i--) {
if (infile[i].hasSpines()) {
continue;
}
if (!infile[i].isReferenceRecord()) {
continue;
}
string key = infile[i].getReferenceKey();
if (key != "RDF**kern") {
continue;
}
HumRegex hre;
string value = infile[i].getReferenceValue();
if (hre.search(value, "^\\s*([^\\s]+)\\s*=\\s*(.*)\\s*$")) {
string signifier = hre.getMatch(1);
string definition = hre.getMatch(2);
if (hre.search(definition, "terminal\\s+long")) {
m_kernTerminalLong = signifier;
m_kernTerminalLongIndex = i;
m_mensTerminalLongLine = "!!!RDF**mens: " + signifier + " = ";
m_mensTerminalLongLine += definition;
break;
}
}
}
}




/////////////////////////////////
//
Expand Down Expand Up @@ -106953,13 +107010,13 @@ void Tool_nproof::checkForValidInstrumentCode(HTp token,

if (!found1) {
m_errorCount++;
m_errorList += "!!!TOOL-nproof-error-" + to_string(m_errorCount) + ": Unknown instrument code \"" + inst1 + "\" in token " + *token + "on line " + to_string(token->getLineNumber()) + ", field " + to_string(token->getFieldNumber()) + ". See list of codes at <a target='_blank' href='https://bit.ly/humdrum-instrument-codes'>https://bit.ly/humdrum-instrument-codes</a>.\n";
m_errorList += "!!!TOOL-nproof-error-" + to_string(m_errorCount) + ": Unknown instrument code \"" + inst1 + "\" in token " + *token + " on line " + to_string(token->getLineNumber()) + ", field " + to_string(token->getFieldNumber()) + ". See list of codes at <a target='_blank' href='https://bit.ly/humdrum-instrument-codes'>https://bit.ly/humdrum-instrument-codes</a>.\n";
m_errorHtml += "!! <li> @{TOOL-nproof-error-" + to_string(m_errorCount) + "} </li>\n";
}

if (!found2) {
m_errorCount++;
m_errorList += "!!!TOOL-nproof-error-" + to_string(m_errorCount) + ": Unknown instrument code \"" + inst2 + "\" in token " + *token + "on line " + to_string(token->getLineNumber()) + ", field " + to_string(token->getFieldNumber()) + ". See list of codes at <a target='_blank' href='https://bit.ly/humdrum-instrument-codes'>https://bit.ly/humdrum-instrument-codes</a>.\n";
m_errorList += "!!!TOOL-nproof-error-" + to_string(m_errorCount) + ": Unknown instrument code \"" + inst2 + "\" in token " + *token + " on line " + to_string(token->getLineNumber()) + ", field " + to_string(token->getFieldNumber()) + ". See list of codes at <a target='_blank' href='https://bit.ly/humdrum-instrument-codes'>https://bit.ly/humdrum-instrument-codes</a>.\n";
m_errorHtml += "!! <li> @{TOOL-nproof-error-" + to_string(m_errorCount) + "} </li>\n";
}

Expand Down

0 comments on commit 82197ef

Please sign in to comment.