diff --git a/include/hum/humlib.h b/include/hum/humlib.h index db788fbafa..77490888c8 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: Wed Nov 13 13:08:51 PST 2024 +// Last Modified: Tue Dec 10 14:37:55 JST 2024 // Filename: min/humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.h // Syntax: C++11 @@ -5957,31 +5957,6 @@ class Tool_autostem : public HumTool { }; -class Tool_bardash : public HumTool { - - public: - Tool_bardash (void); - ~Tool_bardash() {}; - - bool run (HumdrumFileSet& infiles); - bool run (HumdrumFile& infile); - bool run (const std::string& indata, std::ostream& out); - bool run (HumdrumFile& infile, std::ostream& out); - - protected: - void initialize (void); - void processFile (HumdrumFile& infile); - void removeBarStylings(HumdrumFile& infile); - void removeBarStylings(HTp spine); - void applyBarStylings(HumdrumFile& infile); - void applyBarStylings(HTp spine); - - private: - bool m_removeQ = false; // used with -r option - -}; - - class Tool_binroll : public HumTool { public: Tool_binroll (void); @@ -6005,6 +5980,31 @@ class Tool_binroll : public HumTool { }; +class Tool_bstyle : public HumTool { + + public: + Tool_bstyle (void); + ~Tool_bstyle() {}; + + bool run (HumdrumFileSet& infiles); + bool run (HumdrumFile& infile); + bool run (const std::string& indata, std::ostream& out); + bool run (HumdrumFile& infile, std::ostream& out); + + protected: + void initialize (void); + void processFile (HumdrumFile& infile); + void removeBarStylings(HumdrumFile& infile); + void removeBarStylings(HTp spine); + void applyBarStylings(HumdrumFile& infile); + void applyBarStylings(HTp spine); + + private: + bool m_removeQ = false; // used with -r option + +}; + + class Tool_chantize : public HumTool { public: Tool_chantize (void); @@ -10856,6 +10856,7 @@ class Tool_shed : public HumTool { protected: void processFile (HumdrumFile& infile); + void processExpression (HumdrumFile& infile); void searchAndReplaceInterpretation (HumdrumFile& infile); void searchAndReplaceExinterp (HumdrumFile& infile); void searchAndReplaceData (HumdrumFile& infile); diff --git a/src/hum/humlib.cpp b/src/hum/humlib.cpp index b513566285..1c914a2120 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: Wed Nov 13 13:08:51 PST 2024 +// Last Modified: Tue Dec 10 14:37:55 JST 2024 // Filename: min/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.cpp // Syntax: C++11 @@ -58774,10 +58774,229 @@ void Tool_autostem::countBeamStuff(const string& token, int& start, int& stop, ///////////////////////////////// // -// Tool_bardash::Tool_bardash -- Set the recognized options for the tool. +// Tool_binroll::Tool_binroll -- Set the recognized options for the tool. +// + +Tool_binroll::Tool_binroll(void) { + // add options here + define("t|timebase=s:16", "timebase to do analysis at"); +} + + + +///////////////////////////////// +// +// Tool_binroll::run -- Do the main work of the tool. +// + +bool Tool_binroll::run(HumdrumFileSet& infiles) { + bool status = true; + for (int i=0; i> output; + output.resize(128); + int count = (infile.getScoreDuration() / m_duration).getInteger() + 1; + for (int i=0; i<(int)output.size(); i++) { + output[i].resize(count); + std::fill(output[i].begin(), output[i].end(), 0); + } + + int strandcount = infile.getStrandCount(); + for (int i=0; iisKern()) { + continue; + } + HTp ending = infile.getStrandEnd(i); + processStrand(output, starting, ending); + } + + printAnalysis(infile, output); + +} + + + +////////////////////////////// +// +// Tool_binroll::printAnalysis -- +// + +void Tool_binroll::printAnalysis(HumdrumFile& infile, + vector>& roll) { + HumRegex hre; + + for (int i=0; i=0; i--) { + if (infile[i].isManipulator()) { + startindex = i+1; + break; + } + startindex = i; + } + + for (int i=startindex; i>& roll, HTp starting, + HTp ending) { + HTp current = starting; + int base12; + HumNum starttime; + HumNum duration; + int startindex; + int endindex; + while (current && (current != ending)) { + if (!current->isNonNullData()) { + current = current->getNextToken(); + continue; + } + if (current->isRest()) { + current = current->getNextToken(); + continue; + } + + if (current->isChord()) { + int stcount = current->getSubtokenCount(); + starttime = current->getDurationFromStart(); + startindex = (starttime / m_duration).getInteger(); + for (int s=0; sgetSubtoken(s); + base12 = Convert::kernToMidiNoteNumber(tok); + if ((base12 < 0) || (base12 > 127)) { + continue; + } + duration = Convert::recipToDuration(tok); + endindex = ((starttime+duration) / m_duration).getInteger(); + roll[base12][startindex] = 2; + for (int i=startindex+1; i 127)) { + current = current->getNextToken(); + continue; + } + starttime = current->getDurationFromStart(); + duration = current->getDuration(); + startindex = (starttime / m_duration).getInteger(); + endindex = ((starttime+duration) / m_duration).getInteger(); + roll[base12][startindex] = 2; + for (int i=startindex+1; igetNextToken(); + } +} + + + + + + +///////////////////////////////// +// +// Tool_bstyle::Tool_bstyle -- Set the recognized options for the tool. +// + +Tool_bstyle::Tool_bstyle(void) { define("r|remove=b", "remove any dot/dash/invisible barline stylings"); } @@ -58785,10 +59004,10 @@ Tool_bardash::Tool_bardash(void) { /////////////////////////////// // -// Tool_bardash::run -- Primary interfaces to the tool. +// Tool_bstyle::run -- Primary interfaces to the tool. // -bool Tool_bardash::run(HumdrumFileSet& infiles) { +bool Tool_bstyle::run(HumdrumFileSet& infiles) { bool status = true; for (int i=0; i kstarts = infile.getKernSpineStartList(); for (int i=0; i<(int)kstarts.size(); i++) { removeBarStylings(kstarts.at(i)); @@ -58862,10 +59081,10 @@ void Tool_bardash::removeBarStylings(HumdrumFile& infile) { ////////////////////////////// // -// Tool_bardash::removeBarStylings -- +// Tool_bstyle::removeBarStylings -- // -void Tool_bardash::removeBarStylings(HTp spine) { +void Tool_bstyle::removeBarStylings(HTp spine) { HTp current = spine->getNextToken(); bool activeQ = false; @@ -58875,7 +59094,7 @@ void Tool_bardash::removeBarStylings(HTp spine) { HumRegex hre; while (current) { if (current->isInterpretation()) { - if (hre.search(current, "^\\*bar:")) { + if (hre.search(current, "^\\*bstyle:")) { if (hre.search(current, "stop")) { activeQ = false; dashQ = false; @@ -58883,15 +59102,15 @@ void Tool_bardash::removeBarStylings(HTp spine) { invisQ = false; } else { activeQ = true; - if (hre.search(current, "^\\*bar:.*dash=(\\d+)")) { + if (hre.search(current, "^\\*bstyle:.*dash=(\\d+)")) { dashQ = true; dotQ = false; invisQ = false; - } else if (hre.search(current, "^\\*bar:.*dot=(\\d+)")) { + } else if (hre.search(current, "^\\*bstyle:.*dot=(\\d+)")) { dashQ = false; dotQ = true; invisQ = false; - } else if (hre.search(current, "^\\*bar:.*invis=(\\d+)")) { + } else if (hre.search(current, "^\\*bstyle:.*invis=(\\d+)")) { dashQ = false; dotQ = false; invisQ = true; @@ -58936,10 +59155,10 @@ void Tool_bardash::removeBarStylings(HTp spine) { ////////////////////////////// // -// Tool_bardash::applyBarStylings -- +// Tool_bstyle::applyBarStylings -- // -void Tool_bardash::applyBarStylings(HumdrumFile& infile) { +void Tool_bstyle::applyBarStylings(HumdrumFile& infile) { vector kstarts = infile.getKernSpineStartList(); for (int i=0; i<(int)kstarts.size(); i++) { applyBarStylings(kstarts.at(i)); @@ -58950,10 +59169,10 @@ void Tool_bardash::applyBarStylings(HumdrumFile& infile) { ////////////////////////////// // -// Tool_bardash::applyBarStylings -- +// Tool_bstyle::applyBarStylings -- // -void Tool_bardash::applyBarStylings(HTp spine) { +void Tool_bstyle::applyBarStylings(HTp spine) { HTp current = spine->getNextToken(); bool activeQ = false; @@ -58967,7 +59186,7 @@ void Tool_bardash::applyBarStylings(HTp spine) { HumRegex hre; while (current) { if (current->isInterpretation()) { - if (hre.search(current, "^\\*bar:")) { + if (hre.search(current, "^\\*bstyle:")) { if (hre.search(current, "stop")) { activeQ = false; dashQ = false; @@ -58978,19 +59197,19 @@ void Tool_bardash::applyBarStylings(HTp spine) { invis = 0; } else { activeQ = true; - if (hre.search(current, "^\\*bar:.*dash=(\\d+)")) { + if (hre.search(current, "^\\*bstyle:.*dash=(\\d+)")) { dashQ = true; dotQ = false; invisQ = false; dash = hre.getMatchInt(1); counter = 0; - } else if (hre.search(current, "^\\*bar:.*dot=(\\d+)")) { + } else if (hre.search(current, "^\\*bstyle:.*dot=(\\d+)")) { dashQ = false; dotQ = true; invisQ = false; dot = hre.getMatchInt(1); counter = 0; - } else if (hre.search(current, "^\\*bar:.*invis=(\\d+)")) { + } else if (hre.search(current, "^\\*bstyle:.*invis=(\\d+)")) { dashQ = false; dotQ = false; invisQ = true; @@ -59071,225 +59290,6 @@ void Tool_bardash::applyBarStylings(HTp spine) { -///////////////////////////////// -// -// Tool_binroll::Tool_binroll -- Set the recognized options for the tool. -// - -Tool_binroll::Tool_binroll(void) { - // add options here - define("t|timebase=s:16", "timebase to do analysis at"); -} - - - -///////////////////////////////// -// -// Tool_binroll::run -- Do the main work of the tool. -// - -bool Tool_binroll::run(HumdrumFileSet& infiles) { - bool status = true; - for (int i=0; i> output; - output.resize(128); - int count = (infile.getScoreDuration() / m_duration).getInteger() + 1; - for (int i=0; i<(int)output.size(); i++) { - output[i].resize(count); - std::fill(output[i].begin(), output[i].end(), 0); - } - - int strandcount = infile.getStrandCount(); - for (int i=0; iisKern()) { - continue; - } - HTp ending = infile.getStrandEnd(i); - processStrand(output, starting, ending); - } - - printAnalysis(infile, output); - -} - - - -////////////////////////////// -// -// Tool_binroll::printAnalysis -- -// - -void Tool_binroll::printAnalysis(HumdrumFile& infile, - vector>& roll) { - HumRegex hre; - - for (int i=0; i=0; i--) { - if (infile[i].isManipulator()) { - startindex = i+1; - break; - } - startindex = i; - } - - for (int i=startindex; i>& roll, HTp starting, - HTp ending) { - HTp current = starting; - int base12; - HumNum starttime; - HumNum duration; - int startindex; - int endindex; - while (current && (current != ending)) { - if (!current->isNonNullData()) { - current = current->getNextToken(); - continue; - } - if (current->isRest()) { - current = current->getNextToken(); - continue; - } - - if (current->isChord()) { - int stcount = current->getSubtokenCount(); - starttime = current->getDurationFromStart(); - startindex = (starttime / m_duration).getInteger(); - for (int s=0; sgetSubtoken(s); - base12 = Convert::kernToMidiNoteNumber(tok); - if ((base12 < 0) || (base12 > 127)) { - continue; - } - duration = Convert::recipToDuration(tok); - endindex = ((starttime+duration) / m_duration).getInteger(); - roll[base12][startindex] = 2; - for (int i=startindex+1; i 127)) { - current = current->getNextToken(); - continue; - } - starttime = current->getDurationFromStart(); - duration = current->getDuration(); - startindex = (starttime / m_duration).getInteger(); - endindex = ((starttime+duration) / m_duration).getInteger(); - roll[base12][startindex] = 2; - for (int i=startindex+1; igetNextToken(); - } -} - - - - - - ///////////////////////////////// // // Tool_chantize::Tool_chantize -- Set the recognized options for the tool. @@ -87253,8 +87253,8 @@ bool Tool_filter::run(HumdrumFileSet& infiles) { RUNTOOL(autobeam, infile, commands[i].second, status); } else if (commands[i].first == "autostem") { RUNTOOL(autostem, infile, commands[i].second, status); - } else if (commands[i].first == "bardash") { - RUNTOOL(bardash, infile, commands[i].second, status); + } else if (commands[i].first == "bstyle") { + RUNTOOL(bstyle, infile, commands[i].second, status); } else if (commands[i].first == "binroll") { RUNTOOL(binroll, infile, commands[i].second, status); } else if (commands[i].first == "chantize") { @@ -120419,8 +120419,10 @@ void Tool_prange::assignHorizontalPosition(vector<_VoiceInfo>& voiceInfo, int mi } vector hpos(count, 0); - hpos[0] = maxval; - hpos.back() = minval; + if (count >= 2) { + hpos[0] = maxval; + hpos.back() = minval; + } if (hpos.size() > 2) { for (int i=1; i<(int)hpos.size()-1; i++) { @@ -126363,10 +126365,7 @@ bool Tool_shed::run(HumdrumFile& infile) { cerr << "Error: -e option is required" << endl; return false; } - for (int i=0; i<(int)m_options.size(); i++) { - prepareSearch(i); - processFile(infile); - } + processFile(infile); return true; } @@ -126658,6 +126657,21 @@ vector Tool_shed::addToExInterpList(void) { // void Tool_shed::processFile(HumdrumFile& infile) { + for (int i=0; i<(int)m_options.size(); i++) { + prepareSearch(i); + processExpression(infile); + } + m_humdrum_text << infile; +} + + + +////////////////////////////// +// +// Tool_shed::processExpression -- +// + +void Tool_shed::processExpression(HumdrumFile& infile) { if (m_search == "") { // nothing to do return; @@ -126703,9 +126717,6 @@ void Tool_shed::processFile(HumdrumFile& infile) { if (m_modified) { infile.createLinesFromTokens(); } - - // needed only for command-line version of tool?: - m_humdrum_text << infile; }