Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[myank] Add -l flag to select line range and improve cutting null tokens #55

Merged
merged 23 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
09f499f
Basic implementation to enable line yank
WolfgangDrescher Dec 15, 2022
b9256e1
Fix indentation
WolfgangDrescher Dec 15, 2022
693ed16
Merge branch 'master' into myank
WolfgangDrescher Jan 24, 2023
8a35e6b
Add space between keyword and brackets
WolfgangDrescher Jan 24, 2023
0ed6ca9
Add `m_` prefix for member variables
WolfgangDrescher Jan 24, 2023
ebb5377
Use HumRegex
WolfgangDrescher Jan 24, 2023
eae2be6
Indentation
WolfgangDrescher Jan 24, 2023
de92b3c
Add line-range as long name for -l
WolfgangDrescher Jan 24, 2023
d792927
Add comments and improve method names
WolfgangDrescher Jan 24, 2023
f09a979
Add helper function to get duration from start and remaining duration…
WolfgangDrescher Jan 24, 2023
d024d03
Improve cutting sustained notes
WolfgangDrescher Jan 24, 2023
1fd549e
Update humlib.h and humlib.cpp
WolfgangDrescher Jan 24, 2023
47ff6c5
Disallow unreasonable line numbers
WolfgangDrescher Jan 25, 2023
12fc4b3
Remove bar line at end if in the middle of a bar
WolfgangDrescher Jan 25, 2023
ab079a0
Use isData
WolfgangDrescher Jan 25, 2023
ebec910
Add bar numbers when section starts at beginning of a bar
WolfgangDrescher Jan 25, 2023
a3a80f4
Update humlib.h and humlib.cpp
WolfgangDrescher Jan 25, 2023
3fc4f16
Fix adjustGlobalInterpretations when line is a global comment
WolfgangDrescher Jan 25, 2023
d5f8258
Add --hide-starting and --hide-ending options
WolfgangDrescher Jan 26, 2023
7bd1c08
Alway include !!!RDF reference records in starting and ending section
WolfgangDrescher Feb 7, 2023
c843e92
Limit createLineFromTokens for current line
WolfgangDrescher Feb 7, 2023
207f63d
Merge branch 'master' into myank
WolfgangDrescher Feb 7, 2023
a1eda08
Format long lines
WolfgangDrescher Feb 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/tool-myank.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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
Expand All @@ -175,6 +180,9 @@ class Tool_myank : public HumTool {
vector<MeasureInfo> MeasureInList; // used with -m option
vector<vector<MyCoord> > metstates;

string linesQ;
vector<int> BarNumbers; // used with -l option

};

// END_MERGE
Expand Down
57 changes: 55 additions & 2 deletions src/tool-myank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -295,6 +306,46 @@ void Tool_myank::processFile(HumdrumFile& infile) {
}


vector<int> Tool_myank::analyzeBarNumbers(HumdrumFile& infile) {
vector<int> m_barnum;
m_barnum.resize(infile.getLineCount());
int current = -1;
HumRegex hre;
for (int i=0; i<infile.getLineCount(); i++) {
if (!infile[i].isBarline()) {
m_barnum.at(i) = current;
continue;
}
if (hre.search(infile[i].token(0), "=(\\d+)")) {
current = hre.getMatchInt(1);
}
m_barnum.at(i) = current;
}
return m_barnum;
}

int Tool_myank::getBarNumberForLine(int line) {
return BarNumbers[line-1];
}

int Tool_myank::getStartLine() {
regex re("^(\\d+)\\-(\\d+)$");
std::smatch match;
if (regex_search(linesQ, match, re) && match.size() > 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;
}


//////////////////////////////
//
Expand Down Expand Up @@ -564,7 +615,9 @@ void Tool_myank::myank(HumdrumFile& infile, vector<MeasureInfo>& outmeasures) {
} else {
reconcileStartingPosition(infile, outmeasures[0].start);
}
for (i=outmeasures[h].start; i<outmeasures[h].stop; i++) {
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;
for (i=startLine; i<endLine; i++) {
counter++;
if ((!printed) && ((mcount == 0) || (counter == 2))) {
if ((datastart == 0) && outmeasures[h].num == 0) {
Expand Down