From 09f499f4f392952bf5422c4a546efe12b123bddf Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Thu, 15 Dec 2022 11:30:36 +0100 Subject: [PATCH 01/21] Basic implementation to enable line yank --- include/tool-myank.h | 8 +++++++ src/tool-myank.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/include/tool-myank.h b/include/tool-myank.h index d1b6c219..61617b95 100644 --- a/include/tool-myank.h +++ b/include/tool-myank.h @@ -155,6 +155,11 @@ class Tool_myank : public HumTool { void printMeasureStart (HumdrumFile& infile, int line, const string& style); std::string expandMultipliers (const string& inputstring); + vector analyzeBarNumbers(HumdrumFile& infile); + int getBarNumberForLine(int line); + int getStartLine(); + int getEndLine(); + private: int debugQ = 0; // used with --debug option // int inputlist = 0; // used with --inlist option @@ -175,6 +180,9 @@ class Tool_myank : public HumTool { vector MeasureInList; // used with -m option vector > metstates; + string linesQ; + vector BarNumbers; // used with -l option + }; // END_MERGE diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index b051672b..d4abdd51 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -39,6 +39,7 @@ Tool_myank::Tool_myank(void) { define("T|M|bar-number-text=b", "print barnum with LO text above system "); define("d|double|dm|md|mdsep|mdseparator=b", "Put double barline between non-consecutive measure segments"); define("m|b|measures|bars|measure|bar=s", "Measures to yank"); + define("l|lines=s", "Lines to yank"); define("I|i|instrument=b", "Include instrument codes from start of data"); define("visible|not-invisible=b", "Do not make initial measure invisible"); define("B|noendbar=b", "Do not print barline at end of data"); @@ -217,8 +218,10 @@ void Tool_myank::initialize(HumdrumFile& infile) { sectionCountQ = getBoolean("section-count"); Section = getInteger("section"); + linesQ = getString("lines"); + if (!Section) { - if (!(getBoolean("measures") || markQ)) { + if (!(getBoolean("measures") || markQ) && !getBoolean("lines")) { // if -m option is not given, then --mark option presumed markQ = 1; // cerr << "Error: the -m option is required" << endl; @@ -246,6 +249,14 @@ void Tool_myank::processFile(HumdrumFile& infile) { getMeasureStartStop(MeasureInList, infile); string measurestring = getString("measures"); + + if(getBoolean("lines")) { + BarNumbers = analyzeBarNumbers(infile); + int startBarNumber = getBarNumberForLine(getStartLine()); + int endBarNumber = getBarNumberForLine(getEndLine()); + measurestring = to_string(startBarNumber) + "-" + to_string(endBarNumber); + } + measurestring = expandMultipliers(measurestring); if (markQ) { stringstream mstring; @@ -295,6 +306,46 @@ void Tool_myank::processFile(HumdrumFile& infile) { } +vector Tool_myank::analyzeBarNumbers(HumdrumFile& infile) { + vector m_barnum; + m_barnum.resize(infile.getLineCount()); + int current = -1; + HumRegex hre; + for (int i=0; i 1) { + return stoi(match.str(1)); + } + return -1; +} + +int Tool_myank::getEndLine() { + regex re("^(\\d+)\\-(\\d+)$"); + std::smatch match; + if (regex_search(linesQ, match, re) && match.size() > 1) { + return stoi(match.str(2)); + } + return -1; +} + ////////////////////////////// // @@ -564,7 +615,9 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } else { reconcileStartingPosition(infile, outmeasures[0].start); } - for (i=outmeasures[h].start; i Date: Thu, 15 Dec 2022 11:33:43 +0100 Subject: [PATCH 02/21] Fix indentation --- src/tool-myank.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index d4abdd51..e1d49778 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -330,7 +330,7 @@ int Tool_myank::getBarNumberForLine(int line) { int Tool_myank::getStartLine() { regex re("^(\\d+)\\-(\\d+)$"); - std::smatch match; + std::smatch match; if (regex_search(linesQ, match, re) && match.size() > 1) { return stoi(match.str(1)); } @@ -339,7 +339,7 @@ int Tool_myank::getStartLine() { int Tool_myank::getEndLine() { regex re("^(\\d+)\\-(\\d+)$"); - std::smatch match; + std::smatch match; if (regex_search(linesQ, match, re) && match.size() > 1) { return stoi(match.str(2)); } From 8a35e6b1eb208984787f1fa96e34ac518583167f Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 24 Jan 2023 17:36:21 +0100 Subject: [PATCH 03/21] Add space between keyword and brackets --- src/tool-myank.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index e1d49778..de28eaec 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -250,7 +250,7 @@ void Tool_myank::processFile(HumdrumFile& infile) { string measurestring = getString("measures"); - if(getBoolean("lines")) { + if (getBoolean("lines")) { BarNumbers = analyzeBarNumbers(infile); int startBarNumber = getBarNumberForLine(getStartLine()); int endBarNumber = getBarNumberForLine(getEndLine()); From 0ed6ca951b8435f36372ad73b4914488b64bef7f Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 24 Jan 2023 21:34:22 +0100 Subject: [PATCH 04/21] Add `m_` prefix for member variables --- include/tool-myank.h | 42 ++++++------- src/tool-myank.cpp | 136 +++++++++++++++++++++---------------------- 2 files changed, 89 insertions(+), 89 deletions(-) diff --git a/include/tool-myank.h b/include/tool-myank.h index 61617b95..24c6b1f5 100644 --- a/include/tool-myank.h +++ b/include/tool-myank.h @@ -161,27 +161,27 @@ class Tool_myank : public HumTool { int getEndLine(); private: - int debugQ = 0; // used with --debug option - // int inputlist = 0; // used with --inlist option - int inlistQ = 0; // used with --inlist option - int outlistQ = 0; // used with --outlist option - int verboseQ = 0; // used with -v option - int invisibleQ = 1; // used with --visible option - int maxQ = 0; // used with --max option - int minQ = 0; // used with --min option - int instrumentQ = 0; // used with -I option - int nolastbarQ = 0; // used with -B option - int markQ = 0; // used with --mark option - int doubleQ = 0; // used with --mdsep option - int barnumtextQ = 0; // used with -T option - int Section = 0; // used with --section option - int sectionCountQ = 0; // used with --section-count option - vector MeasureOutList; // used with -m option - vector MeasureInList; // used with -m option - vector > metstates; - - string linesQ; - vector BarNumbers; // used with -l option + int m_debugQ = 0; // used with --debug option + // int inputlist = 0; // used with --inlist option + int m_inlistQ = 0; // used with --inlist option + int m_outlistQ = 0; // used with --outlist option + int m_verboseQ = 0; // used with -v option + int m_invisibleQ = 1; // used with --visible option + int m_maxQ = 0; // used with --max option + int m_minQ = 0; // used with --min option + int m_instrumentQ = 0; // used with -I option + int m_nolastbarQ = 0; // used with -B option + int m_markQ = 0; // used with --mark option + int m_doubleQ = 0; // used with --mdsep option + int m_barnumtextQ = 0; // used with -T option + int m_section = 0; // used with --section option + int m_sectionCountQ = 0; // used with --section-count option + vector m_measureOutList; // used with -m option + vector m_measureInList; // used with -m option + vector > m_metstates; + + string m_lineRange; // used with -l option + vector m_barNumbersPerLine; // used with -l option }; diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index de28eaec..f2bebfb5 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -202,28 +202,28 @@ void Tool_myank::initialize(HumdrumFile& infile) { return; } - debugQ = getBoolean("debug"); - inlistQ = getBoolean("inlist"); - outlistQ = getBoolean("outlist"); - verboseQ = getBoolean("verbose"); - maxQ = getBoolean("max"); - minQ = getBoolean("min"); - - invisibleQ = !getBoolean("not-invisible"); - instrumentQ = getBoolean("instrument"); - nolastbarQ = getBoolean("noendbar"); - markQ = getBoolean("mark"); - doubleQ = getBoolean("mdsep"); - barnumtextQ = getBoolean("bar-number-text"); - sectionCountQ = getBoolean("section-count"); - Section = getInteger("section"); - - linesQ = getString("lines"); - - if (!Section) { - if (!(getBoolean("measures") || markQ) && !getBoolean("lines")) { + m_debugQ = getBoolean("debug"); + m_inlistQ = getBoolean("inlist"); + m_outlistQ = getBoolean("outlist"); + m_verboseQ = getBoolean("verbose"); + m_maxQ = getBoolean("max"); + m_minQ = getBoolean("min"); + + m_invisibleQ = !getBoolean("not-invisible"); + m_instrumentQ = getBoolean("instrument"); + m_nolastbarQ = getBoolean("noendbar"); + m_markQ = getBoolean("mark"); + m_doubleQ = getBoolean("mdsep"); + m_barnumtextQ = getBoolean("bar-number-text"); + m_sectionCountQ = getBoolean("section-count"); + m_section = getInteger("section"); + + m_lineRange = getString("lines"); + + if (!m_section) { + if (!(getBoolean("measures") || m_markQ) && !getBoolean("lines")) { // if -m option is not given, then --mark option presumed - markQ = 1; + m_markQ = 1; // cerr << "Error: the -m option is required" << endl; // exit(1); } @@ -239,70 +239,70 @@ void Tool_myank::initialize(HumdrumFile& infile) { // void Tool_myank::processFile(HumdrumFile& infile) { - if (sectionCountQ) { + if (m_sectionCountQ) { int sections = getSectionCount(infile); m_humdrum_text << sections << endl; return; } - getMetStates(metstates, infile); - getMeasureStartStop(MeasureInList, infile); + getMetStates(m_metstates, infile); + getMeasureStartStop(m_measureInList, infile); string measurestring = getString("measures"); if (getBoolean("lines")) { - BarNumbers = analyzeBarNumbers(infile); + m_barNumbersPerLine = analyzeBarNumbers(infile); int startBarNumber = getBarNumberForLine(getStartLine()); int endBarNumber = getBarNumberForLine(getEndLine()); measurestring = to_string(startBarNumber) + "-" + to_string(endBarNumber); } measurestring = expandMultipliers(measurestring); - if (markQ) { + if (m_markQ) { stringstream mstring; getMarkString(mstring, infile); measurestring = mstring.str(); - if (debugQ) { + if (m_debugQ) { m_free_text << "MARK STRING: " << mstring.str() << endl; } - } else if (Section) { + } else if (m_section) { string sstring; - getSectionString(sstring, infile, Section); + getSectionString(sstring, infile, m_section); measurestring = sstring; } - if (debugQ) { + if (m_debugQ) { m_free_text << "MARK MEASURES: " << measurestring << endl; } // expand to multiple measures later. - expandMeasureOutList(MeasureOutList, MeasureInList, infile, + expandMeasureOutList(m_measureOutList, m_measureInList, infile, measurestring); - if (inlistQ) { + if (m_inlistQ) { m_free_text << "INPUT MEASURE MAP: " << endl; - for (int i=0; i<(int)MeasureInList.size(); i++) { - m_free_text << MeasureInList[i]; + for (int i=0; i<(int)m_measureInList.size(); i++) { + m_free_text << m_measureInList[i]; } } - if (outlistQ) { + if (m_outlistQ) { m_free_text << "OUTPUT MEASURE MAP: " << endl; - for (int i=0; i<(int)MeasureOutList.size(); i++) { - m_free_text << MeasureOutList[i]; + for (int i=0; i<(int)m_measureOutList.size(); i++) { + m_free_text << m_measureOutList[i]; } } - if (MeasureOutList.size() == 0) { + if (m_measureOutList.size() == 0) { // disallow processing files with no barlines return; } // move stopStyle to startStyle of next measure group. - for (int i=(int)MeasureOutList.size()-1; i>0; i--) { - MeasureOutList[i].startStyle = MeasureOutList[i-1].stopStyle; - MeasureOutList[i-1].stopStyle = ""; + for (int i=(int)m_measureOutList.size()-1; i>0; i--) { + m_measureOutList[i].startStyle = m_measureOutList[i-1].stopStyle; + m_measureOutList[i-1].stopStyle = ""; } - myank(infile, MeasureOutList); + myank(infile, m_measureOutList); } @@ -324,23 +324,23 @@ vector Tool_myank::analyzeBarNumbers(HumdrumFile& infile) { return m_barnum; } -int Tool_myank::getBarNumberForLine(int line) { - return BarNumbers[line-1]; +int Tool_myank::getBarNumberForLine(int lineNumber) { + return m_barNumbersPerLine[lineNumber-1]; } -int Tool_myank::getStartLine() { +int Tool_myank::getStartLine(void) { regex re("^(\\d+)\\-(\\d+)$"); std::smatch match; - if (regex_search(linesQ, match, re) && match.size() > 1) { + if (regex_search(m_lineRange, match, re) && match.size() > 1) { return stoi(match.str(1)); } return -1; } -int Tool_myank::getEndLine() { +int Tool_myank::getEndLine(void) { regex re("^(\\d+)\\-(\\d+)$"); std::smatch match; - if (regex_search(linesQ, match, re) && match.size() > 1) { + if (regex_search(m_lineRange, match, re) && match.size() > 1) { return stoi(match.str(2)); } return -1; @@ -415,7 +415,7 @@ void Tool_myank::getMetStates(vector >& metstates, } } - if (debugQ) { + if (m_debugQ) { for (int i=0; i& outmeasures) { measurestart = 1; printed = 0; counter = 0; - if (debugQ) { + if (m_debugQ) { m_humdrum_text << "!! =====================================\n"; m_humdrum_text << "!! processing " << outmeasures[h].num << endl; } @@ -634,17 +634,17 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { if (infile[i].isBarline()) { mcount++; } - if ((mcount == 1) && invisibleQ && infile[i].isBarline()) { + if ((mcount == 1) && m_invisibleQ && infile[i].isBarline()) { printInvisibleMeasure(infile, i); measurestart = 0; if ((bartextcount++ == 0) && infile[i].isBarline()) { int barline = 0; sscanf(infile.token(i, 0)->c_str(), "=%d", &barline); - if (barnumtextQ && (barline > 0)) { + if (m_barnumtextQ && (barline > 0)) { m_humdrum_text << "!!LO:TX:Z=20:X=-90:t=" << barline << endl; } } - } else if (doubleQ && (lastbarnum > -1) && (abs(barnum - lastbarnum) > 1)) { + } else if (m_doubleQ && (lastbarnum > -1) && (abs(barnum - lastbarnum) > 1)) { printDoubleBarline(infile, i); measurestart = 0; } else if (measurestart && infile[i].isBarline()) { @@ -652,7 +652,7 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { measurestart = 0; } else { m_humdrum_text << infile[i] << "\n"; - if (barnumtextQ && (bartextcount++ == 0) && infile[i].isBarline()) { + if (m_barnumtextQ && (bartextcount++ == 0) && infile[i].isBarline()) { int barline = 0; sscanf(infile.token(i, 0)->c_str(), "=%d", &barline); if (barline > 0) { @@ -673,13 +673,13 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } else { lasti = -1; } - if ((!nolastbarQ) && (lasti >= 0) && infile[lasti].isBarline()) { + if ((!m_nolastbarQ) && (lasti >= 0) && infile[lasti].isBarline()) { for (j=0; j& outmeasures) { collapseSpines(infile, lasti); - if (debugQ) { + if (m_debugQ) { m_free_text << "PROCESSING ENDING" << endl; } @@ -1245,7 +1245,7 @@ void Tool_myank::printMeasureStart(HumdrumFile& infile, int line, const string& } m_humdrum_text << "\n"; - if (barnumtextQ) { + if (m_barnumtextQ) { int barline = 0; sscanf(infile.token(line, 0)->c_str(), "=%d", &barline); if (barline > 0) { @@ -1282,7 +1282,7 @@ void Tool_myank::printDoubleBarline(HumdrumFile& infile, int line) { } m_humdrum_text << "\n"; - if (barnumtextQ) { + if (m_barnumtextQ) { int barline = 0; sscanf(infile.token(line, 0)->c_str(), "=%d", &barline); if (barline > 0) { @@ -1340,7 +1340,7 @@ void Tool_myank::printInvisibleMeasure(HumdrumFile& infile, int line) { void Tool_myank::reconcileSpineBoundary(HumdrumFile& infile, int index1, int index2) { - if (debugQ) { + if (m_debugQ) { m_humdrum_text << "RECONCILING LINES " << index1+1 << " and " << index2+1 << endl; m_humdrum_text << "FIELD COUNT OF " << index1+1 << " is " << infile[index1].getFieldCount() << endl; @@ -1507,7 +1507,7 @@ void Tool_myank::printStarting(HumdrumFile& infile) { int hasI = 0; - if (instrumentQ) { + if (m_instrumentQ) { // print any tandem interpretations which start with *I found // at the start of the data before measures, notes, or any // spine manipulator lines @@ -1558,7 +1558,7 @@ void Tool_myank::printStarting(HumdrumFile& infile) { // void Tool_myank::printEnding(HumdrumFile& infile, int lastline, int adjlin) { - if (debugQ) { + if (m_debugQ) { m_humdrum_text << "IN printEnding" << endl; } int ending = -1; @@ -1881,14 +1881,14 @@ void Tool_myank::expandMeasureOutList(vector& measureout, cerr << "Error: ridiculusly large measure number: " << maxmeasure << endl; exit(1); } - if (maxQ) { + if (m_maxQ) { if (measurein.size() == 0) { m_humdrum_text << 0 << endl; } else { m_humdrum_text << maxmeasure << endl; } exit(0); - } else if (minQ) { + } else if (m_minQ) { for (int ii=0; ii& measureout, string ostring = optionstring; removeDollarsFromString(ostring, maxmeasure); - if (debugQ) { + if (m_debugQ) { m_free_text << "Option string expanded: " << ostring << endl; } @@ -2453,7 +2453,7 @@ void Tool_myank::removeDollarsFromString(string& buffer, int maxx) { int outval; int value; - if (debugQ) { + if (m_debugQ) { m_free_text << "MEASURE STRING BEFORE DOLLAR REMOVAL: " << buffer << endl; } @@ -2475,7 +2475,7 @@ void Tool_myank::removeDollarsFromString(string& buffer, int maxx) { obuf += hre.getMatch(1); hre.replaceDestructive(buffer, tbuf, obuf); } - if (debugQ) { + if (m_debugQ) { m_free_text << "DOLLAR EXPAND: " << buffer << endl; } } From ebb537796d341c08309c1e034c233044892c72a1 Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 24 Jan 2023 21:44:20 +0100 Subject: [PATCH 05/21] Use HumRegex --- src/tool-myank.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index f2bebfb5..ffcb8cc2 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -329,20 +329,18 @@ int Tool_myank::getBarNumberForLine(int lineNumber) { } int Tool_myank::getStartLine(void) { - regex re("^(\\d+)\\-(\\d+)$"); - std::smatch match; - if (regex_search(m_lineRange, match, re) && match.size() > 1) { - return stoi(match.str(1)); - } + HumRegex hre; + if (hre.search(m_lineRange, "^(\\d+)\\-(\\d+)$")) { + return hre.getMatchInt(1); + } return -1; } int Tool_myank::getEndLine(void) { - regex re("^(\\d+)\\-(\\d+)$"); - std::smatch match; - if (regex_search(m_lineRange, match, re) && match.size() > 1) { - return stoi(match.str(2)); - } + HumRegex hre; + if (hre.search(m_lineRange, "^(\\d+)\\-(\\d+)$")) { + return hre.getMatchInt(2); + } return -1; } From eae2be6986e07e0d91d098cc8eba719bfe533d3d Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 24 Jan 2023 21:46:35 +0100 Subject: [PATCH 06/21] Indentation --- include/tool-myank.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/tool-myank.h b/include/tool-myank.h index 24c6b1f5..5fa2ddd9 100644 --- a/include/tool-myank.h +++ b/include/tool-myank.h @@ -155,10 +155,10 @@ class Tool_myank : public HumTool { void printMeasureStart (HumdrumFile& infile, int line, const string& style); std::string expandMultipliers (const string& inputstring); - vector analyzeBarNumbers(HumdrumFile& infile); - int getBarNumberForLine(int line); - int getStartLine(); - int getEndLine(); + vector analyzeBarNumbers (HumdrumFile& infile); + int getBarNumberForLine(int line); + int getStartLine (void); + int getEndLine (void); private: int m_debugQ = 0; // used with --debug option From de92b3cf105a9126e8ef49c296c336142cd1965f Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 24 Jan 2023 21:47:37 +0100 Subject: [PATCH 07/21] Add line-range as long name for -l --- src/tool-myank.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index ffcb8cc2..f86323dc 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -39,7 +39,7 @@ Tool_myank::Tool_myank(void) { define("T|M|bar-number-text=b", "print barnum with LO text above system "); define("d|double|dm|md|mdsep|mdseparator=b", "Put double barline between non-consecutive measure segments"); define("m|b|measures|bars|measure|bar=s", "Measures to yank"); - define("l|lines=s", "Lines to yank"); + define("l|lines|line-range=s", "Line numbers range to yank (e.g. 40-50)"); define("I|i|instrument=b", "Include instrument codes from start of data"); define("visible|not-invisible=b", "Do not make initial measure invisible"); define("B|noendbar=b", "Do not print barline at end of data"); From d792927b937103a7a37f76f3c01fdcf92f2f3f11 Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 24 Jan 2023 21:51:51 +0100 Subject: [PATCH 08/21] Add comments and improve method names --- include/tool-myank.h | 6 +++--- src/tool-myank.cpp | 42 +++++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/include/tool-myank.h b/include/tool-myank.h index 5fa2ddd9..ebf71126 100644 --- a/include/tool-myank.h +++ b/include/tool-myank.h @@ -156,9 +156,9 @@ class Tool_myank : public HumTool { std::string expandMultipliers (const string& inputstring); vector analyzeBarNumbers (HumdrumFile& infile); - int getBarNumberForLine(int line); - int getStartLine (void); - int getEndLine (void); + int getBarNumberForLineNumber(int lineNumber); + int getStartLineNumber (void); + int getEndLineNumber (void); private: int m_debugQ = 0; // used with --debug option diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index f86323dc..2447a1c2 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -252,8 +252,8 @@ void Tool_myank::processFile(HumdrumFile& infile) { if (getBoolean("lines")) { m_barNumbersPerLine = analyzeBarNumbers(infile); - int startBarNumber = getBarNumberForLine(getStartLine()); - int endBarNumber = getBarNumberForLine(getEndLine()); + int startBarNumber = getBarNumberForLineNumber(getStartLineNumber()); + int endBarNumber = getBarNumberForLineNumber(getEndLineNumber()); measurestring = to_string(startBarNumber) + "-" + to_string(endBarNumber); } @@ -306,6 +306,12 @@ void Tool_myank::processFile(HumdrumFile& infile) { } + +//////////////////////// +// +// Tool_myank::analyzeBarNumbers -- Stores the bar number of each line in a vector +// + vector Tool_myank::analyzeBarNumbers(HumdrumFile& infile) { vector m_barnum; m_barnum.resize(infile.getLineCount()); @@ -324,11 +330,25 @@ vector Tool_myank::analyzeBarNumbers(HumdrumFile& infile) { return m_barnum; } -int Tool_myank::getBarNumberForLine(int lineNumber) { + + +//////////////////////// +// +// Tool_myank::getBarNumberForLineNumber -- +// + +int Tool_myank::getBarNumberForLineNumber(int lineNumber) { return m_barNumbersPerLine[lineNumber-1]; } -int Tool_myank::getStartLine(void) { + + +//////////////////////// +// +// Tool_myank::getStartLineNumber -- Get start line number from --lines +// + +int Tool_myank::getStartLineNumber(void) { HumRegex hre; if (hre.search(m_lineRange, "^(\\d+)\\-(\\d+)$")) { return hre.getMatchInt(1); @@ -336,7 +356,14 @@ int Tool_myank::getStartLine(void) { return -1; } -int Tool_myank::getEndLine(void) { + + +//////////////////////// +// +// Tool_myank::getEndLineNumber -- Get end line number from --lines +// + +int Tool_myank::getEndLineNumber(void) { HumRegex hre; if (hre.search(m_lineRange, "^(\\d+)\\-(\\d+)$")) { return hre.getMatchInt(2); @@ -345,6 +372,7 @@ int Tool_myank::getEndLine(void) { } + ////////////////////////////// // // Tool_myank::expandMultipliers -- 2*5 => 2,2,2,2,2 @@ -613,8 +641,8 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } else { reconcileStartingPosition(infile, outmeasures[0].start); } - int startLine = getBoolean("lines") ? std::max(getStartLine()-1, outmeasures[h].start): outmeasures[h].start; - int endLine = getBoolean("lines") ? std::min(getEndLine(), outmeasures[h].stop): outmeasures[h].stop; + int startLine = getBoolean("lines") ? std::max(getStartLineNumber()-1, outmeasures[h].start): outmeasures[h].start; + int endLine = getBoolean("lines") ? std::min(getEndLineNumber(), outmeasures[h].stop): outmeasures[h].stop; for (i=startLine; i Date: Tue, 24 Jan 2023 22:14:48 +0100 Subject: [PATCH 09/21] Add helper function to get duration from start and remaining duration to end Add `HumdrumToken::getDurationFromNoteStart` and `HumdrumToken::getDurationToNoteEnd` --- include/HumdrumToken.h | 6 ++++++ src/HumdrumToken.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/HumdrumToken.h b/include/HumdrumToken.h index ecfec566..056bb204 100644 --- a/include/HumdrumToken.h +++ b/include/HumdrumToken.h @@ -195,6 +195,12 @@ class HumdrumToken : public std::string, public HumHash { HumNum getDurationToEnd (void); HumNum getDurationToEnd (HumNum scale); + HumNum getDurationFromNoteStart (void); + HumNum getDurationFromNoteStart (HumNum scale); + + HumNum getDurationToNoteEnd (void); + HumNum getDurationToNoteEnd (HumNum scale); + HumNum getDurationFromBarline (void); HumNum getDurationFromBarline (HumNum scale); diff --git a/src/HumdrumToken.cpp b/src/HumdrumToken.cpp index 36e82b33..f45a955a 100644 --- a/src/HumdrumToken.cpp +++ b/src/HumdrumToken.cpp @@ -1090,6 +1090,52 @@ HumNum HumdrumToken::getDurationToEnd(HumNum scale) { +////////////////////////////// +// +// HumdrumToken::getDurationFromNoteStart -- Returns the duration from the start +// of the resolved HumdrumToken to the starting time of this token. This is +// useful to get the pased duration of a null token. +// + +HumNum HumdrumToken::getDurationFromNoteStart(void) { + HumNum dur = HumNum(); + HTp resolvedToken = this->resolveNull(); + HumdrumFile* infile = getLine()->getOwner(); + int startLineIndex = resolvedToken->getLineIndex(); + int thisLineIndex = getLineIndex(); + for (int i = startLineIndex; i < thisLineIndex; i++) { + dur += infile->getLine(i)->getDuration(); + } + // TODO handle tied notes + return dur; +} + + +HumNum HumdrumToken::getDurationFromNoteStart(HumNum scale) { + return this->getDurationFromNoteStart() * scale; +} + + + +////////////////////////////// +// +// HumdrumToken::getDurationToNoteEnd -- Returns the duration from this token to +// the end of the resolved HumdrumToken duration. This is useful to get the +// remaining duration of a null token. +// + +HumNum HumdrumToken::getDurationToNoteEnd(void) { + // TODO handle tied notes + return this->resolveNull()->getDuration() - getDurationFromNoteStart(); +} + + +HumNum HumdrumToken::getDurationToNoteEnd(HumNum scale) { + return this->getDurationToNoteEnd() * scale; +} + + + ////////////////////////////// // // HumdrumToken::getBarlineDuration -- Returns the duration between From d024d033380bb027cc5c50fb90712bac1f876995 Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 24 Jan 2023 22:30:08 +0100 Subject: [PATCH 10/21] Improve cutting sustained notes --- include/tool-myank.h | 1 + src/tool-myank.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/include/tool-myank.h b/include/tool-myank.h index ebf71126..1eb52010 100644 --- a/include/tool-myank.h +++ b/include/tool-myank.h @@ -159,6 +159,7 @@ class Tool_myank : public HumTool { int getBarNumberForLineNumber(int lineNumber); int getStartLineNumber (void); int getEndLineNumber (void); + void printDataLine (HLp line, bool& startLineHandled, const vector& lastLineResolvedTokenLineIndex, const vector& lastLineDurationsFromNoteStart); private: int m_debugQ = 0; // used with --debug option diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index 2447a1c2..0a0e6e97 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -17,6 +17,7 @@ #include "tool-myank.h" #include "HumRegex.h" +#include "Convert.h" using namespace std; @@ -626,6 +627,33 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { int barnum = -1; int datastart = 0; int bartextcount = 0; + bool startLineHandled = false; + + int lastLineIndex = getBoolean("lines") ? getEndLineNumber() - 1 : outmeasures[outmeasures.size() - 1].stop; + + // Find the actual last line of the selected section that is a line with + // data tokens + while (infile.getLine(lastLineIndex)->isData() == false) { + lastLineIndex--; + } + + // Mapping with with the start token for each spine + vector lastLineResolvedTokenLineIndex; + // Mapping with the later needed durations of the note that fits within the + // selected section + vector lastLineDurationsFromNoteStart; + + lastLineResolvedTokenLineIndex.resize(infile.getLine(lastLineIndex)->getTokenCount()); + lastLineDurationsFromNoteStart.resize(infile.getLine(lastLineIndex)->getTokenCount()); + + for (int a = 0; a < infile.getLine(lastLineIndex)->getTokenCount(); a++) { + HTp token = infile.token(lastLineIndex, a); + // Get lineIndex for last data token with an attack + lastLineResolvedTokenLineIndex[a] = infile.token(lastLineIndex, a)->resolveNull()->getLineIndex(); + // Get needed duration for this token until section end + lastLineDurationsFromNoteStart[a] = token->getDurationFromNoteStart() + token->getLine()->getDuration(); + } + for (h=0; h<(int)outmeasures.size(); h++) { barnum = outmeasures[h].num; measurestart = 1; @@ -677,7 +705,7 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { printMeasureStart(infile, i, outmeasures[h].startStyle); measurestart = 0; } else { - m_humdrum_text << infile[i] << "\n"; + printDataLine(infile.getLine(i), startLineHandled, lastLineResolvedTokenLineIndex, lastLineDurationsFromNoteStart); if (m_barnumtextQ && (bartextcount++ == 0) && infile[i].isBarline()) { int barline = 0; sscanf(infile.token(i, 0)->c_str(), "=%d", &barline); @@ -1235,6 +1263,77 @@ void Tool_myank::adjustGlobalInterpretationsStart(HumdrumFile& infile, int ii, } + +////////////////////////////// +// +// Tool_myank::printDataLine -- Print line with data tokens of selected section +// + +void Tool_myank::printDataLine(HLp line, bool& startLineHandled, const vector& lastLineResolvedTokenLineIndex, const vector& lastLineDurationsFromNoteStart) { + bool lineChange = false; + // Handle cutting the previeous token of a note that hangs into the selected + // section + if (startLineHandled == false) { + if (line->isData()) { + vector tokens; + line->getTokens(tokens); + for (HTp token : tokens) { + if (token->isKern() && token->isNull()) { + HTp resolvedToken = token->resolveNull(); + if (resolvedToken->isNull()) { + continue; + } + string recip = Convert::durationToRecip(token->getDurationToNoteEnd()); + string pitch; + HumRegex hre; + if (hre.search(resolvedToken, "([rRA-Ga-gxyXYn#-]+)")) { + pitch = hre.getMatch(1); + } + string tokenText = recip + pitch + "]"; + token->setText(tokenText); + lineChange = true; + } + } + startLineHandled = true; + } + // Handle cutting the last attacked note of the selected section + } else { + // Check if line has a note that needs to be handled + if (std::find(lastLineResolvedTokenLineIndex.begin(), lastLineResolvedTokenLineIndex.end(), line->getLineIndex()) != lastLineResolvedTokenLineIndex.end()) { + for (int i = 0; i < line->getTokenCount(); i++) { + HTp token = line->token(i); + // Check if token need the be handled and is of type **kern + if (token->isKern() && (lastLineResolvedTokenLineIndex[i] == line->getLineIndex())) { + HTp resolvedToken = token->resolveNull(); + if (resolvedToken->isNull()) { + continue; + } + HumNum dur = lastLineDurationsFromNoteStart[i]; + string recip = Convert::durationToRecip(dur); + string pitch; + HumRegex hre; + if (hre.search(resolvedToken, "([rRA-Ga-gxyXYn#-]+)")) { + pitch = hre.getMatch(1); + } + string tokenText; + if (resolvedToken->getDuration() > dur) { + tokenText += "["; + } + tokenText += recip + pitch; + token->setText(tokenText); + lineChange = true; + } + } + } + } + if (lineChange) { + line->getOwner()->createLinesFromTokens(); + } + m_humdrum_text << line << "\n"; +} + + + ////////////////////////////// // // Tool_myank::printMeasureStart -- print a starting measure of a segment. From 1fd549eb37adbeb3fdab0dfe0ca1090ec96472e3 Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 24 Jan 2023 22:30:20 +0100 Subject: [PATCH 11/21] Update humlib.h and humlib.cpp --- include/humlib.h | 53 +++++--- src/humlib.cpp | 347 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 319 insertions(+), 81 deletions(-) diff --git a/include/humlib.h b/include/humlib.h index 102677c7..deab0c99 100644 --- a/include/humlib.h +++ b/include/humlib.h @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Mo 23 Jan 2023 17:51:36 CET +// Last Modified: Di 24 Jan 2023 22:28:46 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 @@ -1619,6 +1619,12 @@ class HumdrumToken : public std::string, public HumHash { HumNum getDurationToEnd (void); HumNum getDurationToEnd (HumNum scale); + HumNum getDurationFromNoteStart (void); + HumNum getDurationFromNoteStart (HumNum scale); + + HumNum getDurationToNoteEnd (void); + HumNum getDurationToNoteEnd (HumNum scale); + HumNum getDurationFromBarline (void); HumNum getDurationFromBarline (HumNum scale); @@ -9173,25 +9179,34 @@ class Tool_myank : public HumTool { void printMeasureStart (HumdrumFile& infile, int line, const string& style); std::string expandMultipliers (const string& inputstring); + vector analyzeBarNumbers (HumdrumFile& infile); + int getBarNumberForLineNumber(int lineNumber); + int getStartLineNumber (void); + int getEndLineNumber (void); + void printDataLine (HLp line, bool& startLineHandled, const vector& lastLineResolvedTokenLineIndex, const vector& lastLineDurationsFromNoteStart); + private: - int debugQ = 0; // used with --debug option - // int inputlist = 0; // used with --inlist option - int inlistQ = 0; // used with --inlist option - int outlistQ = 0; // used with --outlist option - int verboseQ = 0; // used with -v option - int invisibleQ = 1; // used with --visible option - int maxQ = 0; // used with --max option - int minQ = 0; // used with --min option - int instrumentQ = 0; // used with -I option - int nolastbarQ = 0; // used with -B option - int markQ = 0; // used with --mark option - int doubleQ = 0; // used with --mdsep option - int barnumtextQ = 0; // used with -T option - int Section = 0; // used with --section option - int sectionCountQ = 0; // used with --section-count option - vector MeasureOutList; // used with -m option - vector MeasureInList; // used with -m option - vector > metstates; + int m_debugQ = 0; // used with --debug option + // int inputlist = 0; // used with --inlist option + int m_inlistQ = 0; // used with --inlist option + int m_outlistQ = 0; // used with --outlist option + int m_verboseQ = 0; // used with -v option + int m_invisibleQ = 1; // used with --visible option + int m_maxQ = 0; // used with --max option + int m_minQ = 0; // used with --min option + int m_instrumentQ = 0; // used with -I option + int m_nolastbarQ = 0; // used with -B option + int m_markQ = 0; // used with --mark option + int m_doubleQ = 0; // used with --mdsep option + int m_barnumtextQ = 0; // used with -T option + int m_section = 0; // used with --section option + int m_sectionCountQ = 0; // used with --section-count option + vector m_measureOutList; // used with -m option + vector m_measureInList; // used with -m option + vector > m_metstates; + + string m_lineRange; // used with -l option + vector m_barNumbersPerLine; // used with -l option }; diff --git a/src/humlib.cpp b/src/humlib.cpp index 80a5b518..ca903ae7 100644 --- a/src/humlib.cpp +++ b/src/humlib.cpp @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Mo 23 Jan 2023 17:51:36 CET +// Last Modified: Di 24 Jan 2023 22:28:46 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 @@ -32905,6 +32905,52 @@ HumNum HumdrumToken::getDurationToEnd(HumNum scale) { +////////////////////////////// +// +// HumdrumToken::getDurationFromNoteStart -- Returns the duration from the start +// of the resolved HumdrumToken to the starting time of this token. This is +// useful to get the pased duration of a null token. +// + +HumNum HumdrumToken::getDurationFromNoteStart(void) { + HumNum dur = HumNum(); + HTp resolvedToken = this->resolveNull(); + HumdrumFile* infile = getLine()->getOwner(); + int startLineIndex = resolvedToken->getLineIndex(); + int thisLineIndex = getLineIndex(); + for (int i = startLineIndex; i < thisLineIndex; i++) { + dur += infile->getLine(i)->getDuration(); + } + // TODO handle tied notes + return dur; +} + + +HumNum HumdrumToken::getDurationFromNoteStart(HumNum scale) { + return this->getDurationFromNoteStart() * scale; +} + + + +////////////////////////////// +// +// HumdrumToken::getDurationToNoteEnd -- Returns the duration from this token to +// the end of the resolved HumdrumToken duration. This is useful to get the +// remaining duration of a null token. +// + +HumNum HumdrumToken::getDurationToNoteEnd(void) { + // TODO handle tied notes + return this->resolveNull()->getDuration() - getDurationFromNoteStart(); +} + + +HumNum HumdrumToken::getDurationToNoteEnd(HumNum scale) { + return this->getDurationToNoteEnd() * scale; +} + + + ////////////////////////////// // // HumdrumToken::getBarlineDuration -- Returns the duration between @@ -101899,6 +101945,7 @@ Tool_myank::Tool_myank(void) { define("T|M|bar-number-text=b", "print barnum with LO text above system "); define("d|double|dm|md|mdsep|mdseparator=b", "Put double barline between non-consecutive measure segments"); define("m|b|measures|bars|measure|bar=s", "Measures to yank"); + define("l|lines|line-range=s", "Line numbers range to yank (e.g. 40-50)"); define("I|i|instrument=b", "Include instrument codes from start of data"); define("visible|not-invisible=b", "Do not make initial measure invisible"); define("B|noendbar=b", "Do not print barline at end of data"); @@ -102061,26 +102108,28 @@ void Tool_myank::initialize(HumdrumFile& infile) { return; } - debugQ = getBoolean("debug"); - inlistQ = getBoolean("inlist"); - outlistQ = getBoolean("outlist"); - verboseQ = getBoolean("verbose"); - maxQ = getBoolean("max"); - minQ = getBoolean("min"); - - invisibleQ = !getBoolean("not-invisible"); - instrumentQ = getBoolean("instrument"); - nolastbarQ = getBoolean("noendbar"); - markQ = getBoolean("mark"); - doubleQ = getBoolean("mdsep"); - barnumtextQ = getBoolean("bar-number-text"); - sectionCountQ = getBoolean("section-count"); - Section = getInteger("section"); - - if (!Section) { - if (!(getBoolean("measures") || markQ)) { + m_debugQ = getBoolean("debug"); + m_inlistQ = getBoolean("inlist"); + m_outlistQ = getBoolean("outlist"); + m_verboseQ = getBoolean("verbose"); + m_maxQ = getBoolean("max"); + m_minQ = getBoolean("min"); + + m_invisibleQ = !getBoolean("not-invisible"); + m_instrumentQ = getBoolean("instrument"); + m_nolastbarQ = getBoolean("noendbar"); + m_markQ = getBoolean("mark"); + m_doubleQ = getBoolean("mdsep"); + m_barnumtextQ = getBoolean("bar-number-text"); + m_sectionCountQ = getBoolean("section-count"); + m_section = getInteger("section"); + + m_lineRange = getString("lines"); + + if (!m_section) { + if (!(getBoolean("measures") || m_markQ) && !getBoolean("lines")) { // if -m option is not given, then --mark option presumed - markQ = 1; + m_markQ = 1; // cerr << "Error: the -m option is required" << endl; // exit(1); } @@ -102096,62 +102145,136 @@ void Tool_myank::initialize(HumdrumFile& infile) { // void Tool_myank::processFile(HumdrumFile& infile) { - if (sectionCountQ) { + if (m_sectionCountQ) { int sections = getSectionCount(infile); m_humdrum_text << sections << endl; return; } - getMetStates(metstates, infile); - getMeasureStartStop(MeasureInList, infile); + getMetStates(m_metstates, infile); + getMeasureStartStop(m_measureInList, infile); string measurestring = getString("measures"); + + if (getBoolean("lines")) { + m_barNumbersPerLine = analyzeBarNumbers(infile); + int startBarNumber = getBarNumberForLineNumber(getStartLineNumber()); + int endBarNumber = getBarNumberForLineNumber(getEndLineNumber()); + measurestring = to_string(startBarNumber) + "-" + to_string(endBarNumber); + } + measurestring = expandMultipliers(measurestring); - if (markQ) { + if (m_markQ) { stringstream mstring; getMarkString(mstring, infile); measurestring = mstring.str(); - if (debugQ) { + if (m_debugQ) { m_free_text << "MARK STRING: " << mstring.str() << endl; } - } else if (Section) { + } else if (m_section) { string sstring; - getSectionString(sstring, infile, Section); + getSectionString(sstring, infile, m_section); measurestring = sstring; } - if (debugQ) { + if (m_debugQ) { m_free_text << "MARK MEASURES: " << measurestring << endl; } // expand to multiple measures later. - expandMeasureOutList(MeasureOutList, MeasureInList, infile, + expandMeasureOutList(m_measureOutList, m_measureInList, infile, measurestring); - if (inlistQ) { + if (m_inlistQ) { m_free_text << "INPUT MEASURE MAP: " << endl; - for (int i=0; i<(int)MeasureInList.size(); i++) { - m_free_text << MeasureInList[i]; + for (int i=0; i<(int)m_measureInList.size(); i++) { + m_free_text << m_measureInList[i]; } } - if (outlistQ) { + if (m_outlistQ) { m_free_text << "OUTPUT MEASURE MAP: " << endl; - for (int i=0; i<(int)MeasureOutList.size(); i++) { - m_free_text << MeasureOutList[i]; + for (int i=0; i<(int)m_measureOutList.size(); i++) { + m_free_text << m_measureOutList[i]; } } - if (MeasureOutList.size() == 0) { + if (m_measureOutList.size() == 0) { // disallow processing files with no barlines return; } // move stopStyle to startStyle of next measure group. - for (int i=(int)MeasureOutList.size()-1; i>0; i--) { - MeasureOutList[i].startStyle = MeasureOutList[i-1].stopStyle; - MeasureOutList[i-1].stopStyle = ""; + for (int i=(int)m_measureOutList.size()-1; i>0; i--) { + m_measureOutList[i].startStyle = m_measureOutList[i-1].stopStyle; + m_measureOutList[i-1].stopStyle = ""; } - myank(infile, MeasureOutList); + myank(infile, m_measureOutList); +} + + + +//////////////////////// +// +// Tool_myank::analyzeBarNumbers -- Stores the bar number of each line in a vector +// + +vector Tool_myank::analyzeBarNumbers(HumdrumFile& infile) { + vector m_barnum; + m_barnum.resize(infile.getLineCount()); + int current = -1; + HumRegex hre; + for (int i=0; i >& metstates, } } - if (debugQ) { + if (m_debugQ) { for (int i=0; i& outmeasures) { int barnum = -1; int datastart = 0; int bartextcount = 0; + bool startLineHandled = false; + + int lastLineIndex = getBoolean("lines") ? getEndLineNumber() - 1 : outmeasures[outmeasures.size() - 1].stop; + + // Find the actual last line of the selected section that is a line with + // data tokens + while (infile.getLine(lastLineIndex)->isData() == false) { + lastLineIndex--; + } + + // Mapping with with the start token for each spine + vector lastLineResolvedTokenLineIndex; + // Mapping with the later needed durations of the note that fits within the + // selected section + vector lastLineDurationsFromNoteStart; + + lastLineResolvedTokenLineIndex.resize(infile.getLine(lastLineIndex)->getTokenCount()); + lastLineDurationsFromNoteStart.resize(infile.getLine(lastLineIndex)->getTokenCount()); + + for (int a = 0; a < infile.getLine(lastLineIndex)->getTokenCount(); a++) { + HTp token = infile.token(lastLineIndex, a); + // Get lineIndex for last data token with an attack + lastLineResolvedTokenLineIndex[a] = infile.token(lastLineIndex, a)->resolveNull()->getLineIndex(); + // Get needed duration for this token until section end + lastLineDurationsFromNoteStart[a] = token->getDurationFromNoteStart() + token->getLine()->getDuration(); + } + for (h=0; h<(int)outmeasures.size(); h++) { barnum = outmeasures[h].num; measurestart = 1; printed = 0; counter = 0; - if (debugQ) { + if (m_debugQ) { m_humdrum_text << "!! =====================================\n"; m_humdrum_text << "!! processing " << outmeasures[h].num << endl; } @@ -102424,7 +102574,9 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } else { reconcileStartingPosition(infile, outmeasures[0].start); } - for (i=outmeasures[h].start; i& outmeasures) { if (infile[i].isBarline()) { mcount++; } - if ((mcount == 1) && invisibleQ && infile[i].isBarline()) { + if ((mcount == 1) && m_invisibleQ && infile[i].isBarline()) { printInvisibleMeasure(infile, i); measurestart = 0; if ((bartextcount++ == 0) && infile[i].isBarline()) { int barline = 0; sscanf(infile.token(i, 0)->c_str(), "=%d", &barline); - if (barnumtextQ && (barline > 0)) { + if (m_barnumtextQ && (barline > 0)) { m_humdrum_text << "!!LO:TX:Z=20:X=-90:t=" << barline << endl; } } - } else if (doubleQ && (lastbarnum > -1) && (abs(barnum - lastbarnum) > 1)) { + } else if (m_doubleQ && (lastbarnum > -1) && (abs(barnum - lastbarnum) > 1)) { printDoubleBarline(infile, i); measurestart = 0; } else if (measurestart && infile[i].isBarline()) { printMeasureStart(infile, i, outmeasures[h].startStyle); measurestart = 0; } else { - m_humdrum_text << infile[i] << "\n"; - if (barnumtextQ && (bartextcount++ == 0) && infile[i].isBarline()) { + printDataLine(infile.getLine(i), startLineHandled, lastLineResolvedTokenLineIndex, lastLineDurationsFromNoteStart); + if (m_barnumtextQ && (bartextcount++ == 0) && infile[i].isBarline()) { int barline = 0; sscanf(infile.token(i, 0)->c_str(), "=%d", &barline); if (barline > 0) { @@ -102480,13 +102632,13 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } else { lasti = -1; } - if ((!nolastbarQ) && (lasti >= 0) && infile[lasti].isBarline()) { + if ((!m_nolastbarQ) && (lasti >= 0) && infile[lasti].isBarline()) { for (j=0; j& outmeasures) { collapseSpines(infile, lasti); - if (debugQ) { + if (m_debugQ) { m_free_text << "PROCESSING ENDING" << endl; } @@ -103016,6 +103168,77 @@ void Tool_myank::adjustGlobalInterpretationsStart(HumdrumFile& infile, int ii, } + +////////////////////////////// +// +// Tool_myank::printDataLine -- Print line with data tokens of selected section +// + +void Tool_myank::printDataLine(HLp line, bool& startLineHandled, const vector& lastLineResolvedTokenLineIndex, const vector& lastLineDurationsFromNoteStart) { + bool lineChange = false; + // Handle cutting the previeous token of a note that hangs into the selected + // section + if (startLineHandled == false) { + if (line->isData()) { + vector tokens; + line->getTokens(tokens); + for (HTp token : tokens) { + if (token->isKern() && token->isNull()) { + HTp resolvedToken = token->resolveNull(); + if (resolvedToken->isNull()) { + continue; + } + string recip = Convert::durationToRecip(token->getDurationToNoteEnd()); + string pitch; + HumRegex hre; + if (hre.search(resolvedToken, "([rRA-Ga-gxyXYn#-]+)")) { + pitch = hre.getMatch(1); + } + string tokenText = recip + pitch + "]"; + token->setText(tokenText); + lineChange = true; + } + } + startLineHandled = true; + } + // Handle cutting the last attacked note of the selected section + } else { + // Check if line has a note that needs to be handled + if (std::find(lastLineResolvedTokenLineIndex.begin(), lastLineResolvedTokenLineIndex.end(), line->getLineIndex()) != lastLineResolvedTokenLineIndex.end()) { + for (int i = 0; i < line->getTokenCount(); i++) { + HTp token = line->token(i); + // Check if token need the be handled and is of type **kern + if (token->isKern() && (lastLineResolvedTokenLineIndex[i] == line->getLineIndex())) { + HTp resolvedToken = token->resolveNull(); + if (resolvedToken->isNull()) { + continue; + } + HumNum dur = lastLineDurationsFromNoteStart[i]; + string recip = Convert::durationToRecip(dur); + string pitch; + HumRegex hre; + if (hre.search(resolvedToken, "([rRA-Ga-gxyXYn#-]+)")) { + pitch = hre.getMatch(1); + } + string tokenText; + if (resolvedToken->getDuration() > dur) { + tokenText += "["; + } + tokenText += recip + pitch; + token->setText(tokenText); + lineChange = true; + } + } + } + } + if (lineChange) { + line->getOwner()->createLinesFromTokens(); + } + m_humdrum_text << line << "\n"; +} + + + ////////////////////////////// // // Tool_myank::printMeasureStart -- print a starting measure of a segment. @@ -103052,7 +103275,7 @@ void Tool_myank::printMeasureStart(HumdrumFile& infile, int line, const string& } m_humdrum_text << "\n"; - if (barnumtextQ) { + if (m_barnumtextQ) { int barline = 0; sscanf(infile.token(line, 0)->c_str(), "=%d", &barline); if (barline > 0) { @@ -103089,7 +103312,7 @@ void Tool_myank::printDoubleBarline(HumdrumFile& infile, int line) { } m_humdrum_text << "\n"; - if (barnumtextQ) { + if (m_barnumtextQ) { int barline = 0; sscanf(infile.token(line, 0)->c_str(), "=%d", &barline); if (barline > 0) { @@ -103147,7 +103370,7 @@ void Tool_myank::printInvisibleMeasure(HumdrumFile& infile, int line) { void Tool_myank::reconcileSpineBoundary(HumdrumFile& infile, int index1, int index2) { - if (debugQ) { + if (m_debugQ) { m_humdrum_text << "RECONCILING LINES " << index1+1 << " and " << index2+1 << endl; m_humdrum_text << "FIELD COUNT OF " << index1+1 << " is " << infile[index1].getFieldCount() << endl; @@ -103314,7 +103537,7 @@ void Tool_myank::printStarting(HumdrumFile& infile) { int hasI = 0; - if (instrumentQ) { + if (m_instrumentQ) { // print any tandem interpretations which start with *I found // at the start of the data before measures, notes, or any // spine manipulator lines @@ -103365,7 +103588,7 @@ void Tool_myank::printStarting(HumdrumFile& infile) { // void Tool_myank::printEnding(HumdrumFile& infile, int lastline, int adjlin) { - if (debugQ) { + if (m_debugQ) { m_humdrum_text << "IN printEnding" << endl; } int ending = -1; @@ -103688,14 +103911,14 @@ void Tool_myank::expandMeasureOutList(vector& measureout, cerr << "Error: ridiculusly large measure number: " << maxmeasure << endl; exit(1); } - if (maxQ) { + if (m_maxQ) { if (measurein.size() == 0) { m_humdrum_text << 0 << endl; } else { m_humdrum_text << maxmeasure << endl; } exit(0); - } else if (minQ) { + } else if (m_minQ) { for (int ii=0; ii& measureout, string ostring = optionstring; removeDollarsFromString(ostring, maxmeasure); - if (debugQ) { + if (m_debugQ) { m_free_text << "Option string expanded: " << ostring << endl; } @@ -104260,7 +104483,7 @@ void Tool_myank::removeDollarsFromString(string& buffer, int maxx) { int outval; int value; - if (debugQ) { + if (m_debugQ) { m_free_text << "MEASURE STRING BEFORE DOLLAR REMOVAL: " << buffer << endl; } @@ -104282,7 +104505,7 @@ void Tool_myank::removeDollarsFromString(string& buffer, int maxx) { obuf += hre.getMatch(1); hre.replaceDestructive(buffer, tbuf, obuf); } - if (debugQ) { + if (m_debugQ) { m_free_text << "DOLLAR EXPAND: " << buffer << endl; } } From 47ff6c5f13f79689b7ea1b9c11a56c7b5ada2479 Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Wed, 25 Jan 2023 16:05:00 +0100 Subject: [PATCH 12/21] Disallow unreasonable line numbers --- src/tool-myank.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index 0a0e6e97..aef47d65 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -252,9 +252,16 @@ void Tool_myank::processFile(HumdrumFile& infile) { string measurestring = getString("measures"); if (getBoolean("lines")) { + int startLineNumber = getStartLineNumber(); + int endLineNumber = getEndLineNumber(); + if ((startLineNumber > endLineNumber) || (endLineNumber > infile.getLineCount())) { + // Disallow when end line number is bigger then line count or when + // start line number greather than end line number + return; + } m_barNumbersPerLine = analyzeBarNumbers(infile); - int startBarNumber = getBarNumberForLineNumber(getStartLineNumber()); - int endBarNumber = getBarNumberForLineNumber(getEndLineNumber()); + int startBarNumber = getBarNumberForLineNumber(startLineNumber); + int endBarNumber = getBarNumberForLineNumber(endLineNumber); measurestring = to_string(startBarNumber) + "-" + to_string(endBarNumber); } From 12fc4b33fe1eeee0695b0e7b8ebdc5827c346b02 Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Wed, 25 Jan 2023 16:06:09 +0100 Subject: [PATCH 13/21] Remove bar line at end if in the middle of a bar --- src/tool-myank.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index aef47d65..af84aeb2 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -625,6 +625,7 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } int lastline = -1; + int lastDataLine = -1; int h, i, j; int counter; int printed = 0; @@ -722,10 +723,17 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } } lastline = i; + if (infile.getLine(i)->token(0)->isKern()) { + lastDataLine = i; + } } lastbarnum = barnum; } + if (getBoolean("lines") && (lastDataLine >= 0) && (infile.getLine(lastDataLine)->getDurationToBarline() > infile.getLine(lastDataLine)->getDuration())) { + m_nolastbarQ = true; + } + HumRegex hre; string token; int lasti; From ab079a090a26d9d6a9820eea6545f759c503ed1f Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Wed, 25 Jan 2023 16:11:14 +0100 Subject: [PATCH 14/21] Use isData --- src/tool-myank.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index af84aeb2..1ebaa282 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -723,7 +723,7 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } } lastline = i; - if (infile.getLine(i)->token(0)->isKern()) { + if (infile.getLine(i)->isData()) { lastDataLine = i; } } From ebec910878d7c3bef25d74aa2b9551ec1f59667a Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Wed, 25 Jan 2023 16:21:41 +0100 Subject: [PATCH 15/21] Add bar numbers when section starts at beginning of a bar --- src/tool-myank.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index 1ebaa282..c9f3d4aa 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -662,6 +662,29 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { lastLineDurationsFromNoteStart[a] = token->getDurationFromNoteStart() + token->getLine()->getDuration(); } + int startLineNumber = getStartLineNumber(); + int endLineNumber = getEndLineNumber(); + + if (getBoolean("lines")) { + int firstDataLineIndex = -1; + for (int b = startLineNumber - 1; b <= endLineNumber - 1; b++) { + if (infile.getLine(b)->isData()) { + firstDataLineIndex = b; + break; + } + } + if (firstDataLineIndex >= 0) { + if (infile.getLine(firstDataLineIndex)->getDurationFromBarline() == 0) { + for (int c = startLineNumber - 1; c >= 0; c--) { + if (infile.getLine(c)->isBarline()) { + startLineNumber = c + 1; + break; + } + } + } + } + } + for (h=0; h<(int)outmeasures.size(); h++) { barnum = outmeasures[h].num; measurestart = 1; @@ -677,8 +700,8 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } else { reconcileStartingPosition(infile, outmeasures[0].start); } - int startLine = getBoolean("lines") ? std::max(getStartLineNumber()-1, outmeasures[h].start): outmeasures[h].start; - int endLine = getBoolean("lines") ? std::min(getEndLineNumber(), outmeasures[h].stop): outmeasures[h].stop; + int startLine = getBoolean("lines") ? std::max(startLineNumber-1, outmeasures[h].start): outmeasures[h].start; + int endLine = getBoolean("lines") ? std::min(endLineNumber, outmeasures[h].stop): outmeasures[h].stop; for (i=startLine; i Date: Wed, 25 Jan 2023 16:23:32 +0100 Subject: [PATCH 16/21] Update humlib.h and humlib.cpp --- include/humlib.h | 2 +- src/humlib.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/include/humlib.h b/include/humlib.h index deab0c99..1ee1c8b2 100644 --- a/include/humlib.h +++ b/include/humlib.h @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Di 24 Jan 2023 22:28:46 CET +// Last Modified: Mi 25 Jan 2023 16:23:25 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 diff --git a/src/humlib.cpp b/src/humlib.cpp index ca903ae7..0a8fcf72 100644 --- a/src/humlib.cpp +++ b/src/humlib.cpp @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Di 24 Jan 2023 22:28:46 CET +// Last Modified: Mi 25 Jan 2023 16:23:25 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 @@ -102157,9 +102157,16 @@ void Tool_myank::processFile(HumdrumFile& infile) { string measurestring = getString("measures"); if (getBoolean("lines")) { + int startLineNumber = getStartLineNumber(); + int endLineNumber = getEndLineNumber(); + if ((startLineNumber > endLineNumber) || (endLineNumber > infile.getLineCount())) { + // Disallow when end line number is bigger then line count or when + // start line number greather than end line number + return; + } m_barNumbersPerLine = analyzeBarNumbers(infile); - int startBarNumber = getBarNumberForLineNumber(getStartLineNumber()); - int endBarNumber = getBarNumberForLineNumber(getEndLineNumber()); + int startBarNumber = getBarNumberForLineNumber(startLineNumber); + int endBarNumber = getBarNumberForLineNumber(endLineNumber); measurestring = to_string(startBarNumber) + "-" + to_string(endBarNumber); } @@ -102523,6 +102530,7 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } int lastline = -1; + int lastDataLine = -1; int h, i, j; int counter; int printed = 0; @@ -102559,6 +102567,29 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { lastLineDurationsFromNoteStart[a] = token->getDurationFromNoteStart() + token->getLine()->getDuration(); } + int startLineNumber = getStartLineNumber(); + int endLineNumber = getEndLineNumber(); + + if (getBoolean("lines")) { + int firstDataLineIndex = -1; + for (int b = startLineNumber - 1; b <= endLineNumber - 1; b++) { + if (infile.getLine(b)->isData()) { + firstDataLineIndex = b; + break; + } + } + if (firstDataLineIndex >= 0) { + if (infile.getLine(firstDataLineIndex)->getDurationFromBarline() == 0) { + for (int c = startLineNumber - 1; c >= 0; c--) { + if (infile.getLine(c)->isBarline()) { + startLineNumber = c + 1; + break; + } + } + } + } + } + for (h=0; h<(int)outmeasures.size(); h++) { barnum = outmeasures[h].num; measurestart = 1; @@ -102574,8 +102605,8 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { } else { reconcileStartingPosition(infile, outmeasures[0].start); } - int startLine = getBoolean("lines") ? std::max(getStartLineNumber()-1, outmeasures[h].start): outmeasures[h].start; - int endLine = getBoolean("lines") ? std::min(getEndLineNumber(), outmeasures[h].stop): outmeasures[h].stop; + int startLine = getBoolean("lines") ? std::max(startLineNumber-1, outmeasures[h].start): outmeasures[h].start; + int endLine = getBoolean("lines") ? std::min(endLineNumber, outmeasures[h].stop): outmeasures[h].stop; for (i=startLine; i& outmeasures) { } } lastline = i; + if (infile.getLine(i)->isData()) { + lastDataLine = i; + } } lastbarnum = barnum; } + if (getBoolean("lines") && (lastDataLine >= 0) && (infile.getLine(lastDataLine)->getDurationToBarline() > infile.getLine(lastDataLine)->getDuration())) { + m_nolastbarQ = true; + } + HumRegex hre; string token; int lasti; From 3fc4f16a370d04a1bafefe8a64b0a56cd294936b Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Wed, 25 Jan 2023 23:38:40 +0100 Subject: [PATCH 17/21] Fix adjustGlobalInterpretations when line is a global comment --- include/humlib.h | 2 +- src/humlib.cpp | 14 ++++++++++++-- src/tool-myank.cpp | 12 +++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/humlib.h b/include/humlib.h index 1ee1c8b2..cf150e02 100644 --- a/include/humlib.h +++ b/include/humlib.h @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Mi 25 Jan 2023 16:23:25 CET +// Last Modified: Mi 25 Jan 2023 23:37:27 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 diff --git a/src/humlib.cpp b/src/humlib.cpp index 0a8fcf72..05a9772c 100644 --- a/src/humlib.cpp +++ b/src/humlib.cpp @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Mi 25 Jan 2023 16:23:25 CET +// Last Modified: Mi 25 Jan 2023 23:37:27 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 @@ -102614,7 +102614,17 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { // not ideal setup... datastart = 1; } else{ - adjustGlobalInterpretations(infile, i, outmeasures, h); + // Fix adjustGlobalInterpretations when line is a global comment + int nextLineIndexWithSpines = i; + if (infile.getLine(i)->isCommentGlobal()) { + for (int d = i; d <= endLineNumber - 1; d++) { + if (!infile.getLine(d)->isCommentGlobal()) { + nextLineIndexWithSpines = d; + break; + } + } + } + adjustGlobalInterpretations(infile, nextLineIndexWithSpines, outmeasures, h); printed = 1; } } diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index c9f3d4aa..bef5066f 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -709,7 +709,17 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { // not ideal setup... datastart = 1; } else{ - adjustGlobalInterpretations(infile, i, outmeasures, h); + // Fix adjustGlobalInterpretations when line is a global comment + int nextLineIndexWithSpines = i; + if (infile.getLine(i)->isCommentGlobal()) { + for (int d = i; d <= endLineNumber - 1; d++) { + if (!infile.getLine(d)->isCommentGlobal()) { + nextLineIndexWithSpines = d; + break; + } + } + } + adjustGlobalInterpretations(infile, nextLineIndexWithSpines, outmeasures, h); printed = 1; } } From d5f825862e9f3fc80de11f6167bc777268d38fd0 Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Thu, 26 Jan 2023 15:01:14 +0100 Subject: [PATCH 18/21] Add --hide-starting and --hide-ending options --- include/humlib.h | 4 +++- include/tool-myank.h | 2 ++ src/humlib.cpp | 14 ++++++++++++-- src/tool-myank.cpp | 12 +++++++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/humlib.h b/include/humlib.h index cf150e02..066f58a5 100644 --- a/include/humlib.h +++ b/include/humlib.h @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Mi 25 Jan 2023 23:37:27 CET +// Last Modified: Do 26 Jan 2023 15:01:06 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 @@ -9207,6 +9207,8 @@ class Tool_myank : public HumTool { string m_lineRange; // used with -l option vector m_barNumbersPerLine; // used with -l option + bool m_hideStarting; // used with --hide-starting option + bool m_hideEnding; // used with --hide-ending option }; diff --git a/include/tool-myank.h b/include/tool-myank.h index 1eb52010..07028d0b 100644 --- a/include/tool-myank.h +++ b/include/tool-myank.h @@ -183,6 +183,8 @@ class Tool_myank : public HumTool { string m_lineRange; // used with -l option vector m_barNumbersPerLine; // used with -l option + bool m_hideStarting; // used with --hide-starting option + bool m_hideEnding; // used with --hide-ending option }; diff --git a/src/humlib.cpp b/src/humlib.cpp index 05a9772c..3235ea35 100644 --- a/src/humlib.cpp +++ b/src/humlib.cpp @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Mi 25 Jan 2023 23:37:27 CET +// Last Modified: Do 26 Jan 2023 15:01:06 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 @@ -101957,6 +101957,8 @@ Tool_myank::Tool_myank(void) { define("version=b", "Program version"); define("example=b", "Program examples"); define("h|help=b", "Short description"); + define("hide-starting=b", "Prevent printStarting"); + define("hide-ending=b", "Prevent printEnding"); } @@ -102125,6 +102127,9 @@ void Tool_myank::initialize(HumdrumFile& infile) { m_section = getInteger("section"); m_lineRange = getString("lines"); + m_hideStarting = getBoolean("hide-starting"); + m_hideEnding = getBoolean("hide-ending"); + if (!m_section) { if (!(getBoolean("measures") || m_markQ) && !getBoolean("lines")) { @@ -103580,7 +103585,9 @@ void Tool_myank::printStarting(HumdrumFile& infile) { exi = i; break; } - m_humdrum_text << infile[i] << "\n"; + if (!m_hideStarting) { + m_humdrum_text << infile[i] << "\n"; + } } int hasI = 0; @@ -103673,6 +103680,9 @@ void Tool_myank::printEnding(HumdrumFile& infile, int lastline, int adjlin) { if (startline >= 0) { for (i=startline; i= ending)) { + break; + } } } diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index bef5066f..611af7b5 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -52,6 +52,8 @@ Tool_myank::Tool_myank(void) { define("version=b", "Program version"); define("example=b", "Program examples"); define("h|help=b", "Short description"); + define("hide-starting=b", "Prevent printStarting"); + define("hide-ending=b", "Prevent printEnding"); } @@ -220,6 +222,9 @@ void Tool_myank::initialize(HumdrumFile& infile) { m_section = getInteger("section"); m_lineRange = getString("lines"); + m_hideStarting = getBoolean("hide-starting"); + m_hideEnding = getBoolean("hide-ending"); + if (!m_section) { if (!(getBoolean("measures") || m_markQ) && !getBoolean("lines")) { @@ -1675,7 +1680,9 @@ void Tool_myank::printStarting(HumdrumFile& infile) { exi = i; break; } - m_humdrum_text << infile[i] << "\n"; + if (!m_hideStarting) { + m_humdrum_text << infile[i] << "\n"; + } } int hasI = 0; @@ -1768,6 +1775,9 @@ void Tool_myank::printEnding(HumdrumFile& infile, int lastline, int adjlin) { if (startline >= 0) { for (i=startline; i= ending)) { + break; + } } } From 7bd1c080afce677e82d76eb13ffd659307a0c74b Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 7 Feb 2023 15:04:19 +0100 Subject: [PATCH 19/21] Alway include !!!RDF reference records in starting and ending section --- include/humlib.h | 2 +- src/humlib.cpp | 13 ++++++++++--- src/tool-myank.cpp | 11 +++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/humlib.h b/include/humlib.h index 066f58a5..3d265a1a 100644 --- a/include/humlib.h +++ b/include/humlib.h @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Do 26 Jan 2023 15:01:06 CET +// Last Modified: Di 7 Feb 2023 15:00:18 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 diff --git a/src/humlib.cpp b/src/humlib.cpp index 3235ea35..5d9832f5 100644 --- a/src/humlib.cpp +++ b/src/humlib.cpp @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Do 26 Jan 2023 15:01:06 CET +// Last Modified: Di 7 Feb 2023 15:00:18 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 @@ -103587,6 +103587,10 @@ void Tool_myank::printStarting(HumdrumFile& infile) { } if (!m_hideStarting) { m_humdrum_text << infile[i] << "\n"; + } else { + if (infile[i].rfind("!!!RDF", 0) == 0) { + m_humdrum_text << infile[i] << "\n"; + } } } @@ -103679,9 +103683,12 @@ void Tool_myank::printEnding(HumdrumFile& infile, int lastline, int adjlin) { if (startline >= 0) { for (i=startline; i= ending)) { - break; + if (infile[i].rfind("!!!RDF", 0) == 0) { + m_humdrum_text << infile[i] << "\n"; + } + } else { + m_humdrum_text << infile[i] << "\n"; } } } diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index 611af7b5..b4648eef 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -1682,6 +1682,10 @@ void Tool_myank::printStarting(HumdrumFile& infile) { } if (!m_hideStarting) { m_humdrum_text << infile[i] << "\n"; + } else { + if (infile[i].rfind("!!!RDF", 0) == 0) { + m_humdrum_text << infile[i] << "\n"; + } } } @@ -1774,9 +1778,12 @@ void Tool_myank::printEnding(HumdrumFile& infile, int lastline, int adjlin) { if (startline >= 0) { for (i=startline; i= ending)) { - break; + if (infile[i].rfind("!!!RDF", 0) == 0) { + m_humdrum_text << infile[i] << "\n"; + } + } else { + m_humdrum_text << infile[i] << "\n"; } } } From c843e92ebfb679cdf196c84f9c602a93f0685125 Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 7 Feb 2023 15:04:48 +0100 Subject: [PATCH 20/21] Limit createLineFromTokens for current line --- include/humlib.h | 2 +- src/humlib.cpp | 4 ++-- src/tool-myank.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/humlib.h b/include/humlib.h index 3d265a1a..d7cde6f1 100644 --- a/include/humlib.h +++ b/include/humlib.h @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Di 7 Feb 2023 15:00:18 CET +// Last Modified: Di 7 Feb 2023 15:04:23 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 diff --git a/src/humlib.cpp b/src/humlib.cpp index 5d9832f5..9c468e6f 100644 --- a/src/humlib.cpp +++ b/src/humlib.cpp @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Di 7 Feb 2023 15:00:18 CET +// Last Modified: Di 7 Feb 2023 15:04:23 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 @@ -103285,7 +103285,7 @@ void Tool_myank::printDataLine(HLp line, bool& startLineHandled, const vectorgetOwner()->createLinesFromTokens(); + line->createLineFromTokens(); } m_humdrum_text << line << "\n"; } diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index b4648eef..7ad03c0d 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -1380,7 +1380,7 @@ void Tool_myank::printDataLine(HLp line, bool& startLineHandled, const vectorgetOwner()->createLinesFromTokens(); + line->createLineFromTokens(); } m_humdrum_text << line << "\n"; } From a1eda085011dad89eef809a931de45488963097b Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Tue, 7 Feb 2023 19:02:14 +0100 Subject: [PATCH 21/21] Format long lines --- include/humlib.h | 2 +- src/humlib.cpp | 13 +++++++++---- src/tool-myank.cpp | 11 ++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/humlib.h b/include/humlib.h index 873b2d7d..868ba816 100644 --- a/include/humlib.h +++ b/include/humlib.h @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Di 7 Feb 2023 15:20:03 CET +// Last Modified: Di 7 Feb 2023 18:58:16 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 diff --git a/src/humlib.cpp b/src/humlib.cpp index 9fcf6c86..6f68858b 100644 --- a/src/humlib.cpp +++ b/src/humlib.cpp @@ -1,7 +1,7 @@ // // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 8 12:24:49 PDT 2015 -// Last Modified: Di 7 Feb 2023 15:20:03 CET +// Last Modified: Di 7 Feb 2023 18:58:16 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 @@ -102673,7 +102673,8 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { lastbarnum = barnum; } - if (getBoolean("lines") && (lastDataLine >= 0) && (infile.getLine(lastDataLine)->getDurationToBarline() > infile.getLine(lastDataLine)->getDuration())) { + if (getBoolean("lines") && (lastDataLine >= 0) && + (infile.getLine(lastDataLine)->getDurationToBarline() > infile.getLine(lastDataLine)->getDuration())) { m_nolastbarQ = true; } @@ -103227,7 +103228,10 @@ void Tool_myank::adjustGlobalInterpretationsStart(HumdrumFile& infile, int ii, // Tool_myank::printDataLine -- Print line with data tokens of selected section // -void Tool_myank::printDataLine(HLp line, bool& startLineHandled, const vector& lastLineResolvedTokenLineIndex, const vector& lastLineDurationsFromNoteStart) { +void Tool_myank::printDataLine(HLp line, + bool& startLineHandled, + const vector& lastLineResolvedTokenLineIndex, + const vector& lastLineDurationsFromNoteStart) { bool lineChange = false; // Handle cutting the previeous token of a note that hangs into the selected // section @@ -103257,7 +103261,8 @@ void Tool_myank::printDataLine(HLp line, bool& startLineHandled, const vectorgetLineIndex()) != lastLineResolvedTokenLineIndex.end()) { + if (std::find(lastLineResolvedTokenLineIndex.begin(), lastLineResolvedTokenLineIndex.end(), line->getLineIndex()) != + lastLineResolvedTokenLineIndex.end()) { for (int i = 0; i < line->getTokenCount(); i++) { HTp token = line->token(i); // Check if token need the be handled and is of type **kern diff --git a/src/tool-myank.cpp b/src/tool-myank.cpp index 7ad03c0d..3c88cba0 100644 --- a/src/tool-myank.cpp +++ b/src/tool-myank.cpp @@ -768,7 +768,8 @@ void Tool_myank::myank(HumdrumFile& infile, vector& outmeasures) { lastbarnum = barnum; } - if (getBoolean("lines") && (lastDataLine >= 0) && (infile.getLine(lastDataLine)->getDurationToBarline() > infile.getLine(lastDataLine)->getDuration())) { + if (getBoolean("lines") && (lastDataLine >= 0) && + (infile.getLine(lastDataLine)->getDurationToBarline() > infile.getLine(lastDataLine)->getDuration())) { m_nolastbarQ = true; } @@ -1322,7 +1323,10 @@ void Tool_myank::adjustGlobalInterpretationsStart(HumdrumFile& infile, int ii, // Tool_myank::printDataLine -- Print line with data tokens of selected section // -void Tool_myank::printDataLine(HLp line, bool& startLineHandled, const vector& lastLineResolvedTokenLineIndex, const vector& lastLineDurationsFromNoteStart) { +void Tool_myank::printDataLine(HLp line, + bool& startLineHandled, + const vector& lastLineResolvedTokenLineIndex, + const vector& lastLineDurationsFromNoteStart) { bool lineChange = false; // Handle cutting the previeous token of a note that hangs into the selected // section @@ -1352,7 +1356,8 @@ void Tool_myank::printDataLine(HLp line, bool& startLineHandled, const vectorgetLineIndex()) != lastLineResolvedTokenLineIndex.end()) { + if (std::find(lastLineResolvedTokenLineIndex.begin(), lastLineResolvedTokenLineIndex.end(), line->getLineIndex()) != + lastLineResolvedTokenLineIndex.end()) { for (int i = 0; i < line->getTokenCount(); i++) { HTp token = line->token(i); // Check if token need the be handled and is of type **kern