Skip to content

Commit

Permalink
Merge pull request #74 from WolfgangDrescher/myank
Browse files Browse the repository at this point in the history
[myank] Improve data token handling at start end end of `myank`ed section
  • Loading branch information
craigsapp authored Mar 21, 2023
2 parents 3cebf1c + 3002315 commit e6faa0d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 34 deletions.
2 changes: 1 addition & 1 deletion include/humlib.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Sat Aug 8 12:24:49 PDT 2015
// Last Modified: Di 14 Mär 2023 19:56:17 CET
// Last Modified: Di 14 Mär 2023 22:41:15 CET
// Filename: humlib.h
// URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h
// Syntax: C++11
Expand Down
58 changes: 41 additions & 17 deletions src/humlib.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Sat Aug 8 12:24:49 PDT 2015
// Last Modified: Di 14 Mär 2023 19:56:17 CET
// Last Modified: Di 14 Mär 2023 22:41:15 CET
// Filename: /include/humlib.cpp
// URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp
// Syntax: C++11
Expand Down Expand Up @@ -103509,6 +103509,7 @@ void Tool_myank::printDataLine(HLp line,
const vector<int>& lastLineResolvedTokenLineIndex,
const vector<HumNum>& lastLineDurationsFromNoteStart) {
bool lineChange = false;
string recipRegex = R"re(([\d%.]+))re";
// Handle cutting the previeous token of a note that hangs into the selected
// section
if (startLineHandled == false) {
Expand All @@ -103521,13 +103522,28 @@ void Tool_myank::printDataLine(HLp line,
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 recip = Convert::durationToRecip(token->getDurationToNoteEnd());
vector<string> subtokens = resolvedToken->getSubtokens();
string tokenText;
for (int i=0; i<(int)subtokens.size(); i++) {
if (hre.search(subtokens[i], recipRegex)) {
string before = hre.getPrefix();
string after = hre.getSuffix();
hre.replaceDestructive(after, "", recipRegex, "g");
string subtokenText;
// Replace the old duration with the clipped one
subtokenText += before + recip + after;
// Add a tie end if not already in a tie group
if (!hre.search(subtokens[i], "[_\\]]")) {
subtokenText += "]";
}
tokenText += subtokenText;
if (i < (int)subtokens.size() - 1) {
tokenText += " ";
}
}
}
string tokenText = recip + pitch + "]";
token->setText(tokenText);
lineChange = true;
}
Expand All @@ -103548,19 +103564,27 @@ void Tool_myank::printDataLine(HLp line,
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 += "[";
string recip = Convert::durationToRecip(dur);
vector<string> subtokens = resolvedToken->getSubtokens();
for (int i=0; i<(int)subtokens.size(); i++) {
if (hre.search(subtokens[i], recipRegex)) {
string before = hre.getPrefix();
string after = hre.getSuffix();
hre.replaceDestructive(after, "", recipRegex, "g");
string subtokenText;
if (resolvedToken->getDuration() > dur) {
// Add a tie start if not already in a tie group
if (!hre.search(subtokens[i], "[_\\[]")) {
subtokenText += "[";
}
}
// Replace the old duration with the clipped one
subtokenText += before + recip + after;
token->replaceSubtoken(i, subtokenText);
lineChange = true;
}
}
tokenText += recip + pitch;
token->setText(tokenText);
lineChange = true;
}
}
}
Expand Down
56 changes: 40 additions & 16 deletions src/tool-myank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,7 @@ void Tool_myank::printDataLine(HLp line,
const vector<int>& lastLineResolvedTokenLineIndex,
const vector<HumNum>& lastLineDurationsFromNoteStart) {
bool lineChange = false;
string recipRegex = R"re(([\d%.]+))re";
// Handle cutting the previeous token of a note that hangs into the selected
// section
if (startLineHandled == false) {
Expand All @@ -1340,13 +1341,28 @@ void Tool_myank::printDataLine(HLp line,
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 recip = Convert::durationToRecip(token->getDurationToNoteEnd());
vector<string> subtokens = resolvedToken->getSubtokens();
string tokenText;
for (int i=0; i<(int)subtokens.size(); i++) {
if (hre.search(subtokens[i], recipRegex)) {
string before = hre.getPrefix();
string after = hre.getSuffix();
hre.replaceDestructive(after, "", recipRegex, "g");
string subtokenText;
// Replace the old duration with the clipped one
subtokenText += before + recip + after;
// Add a tie end if not already in a tie group
if (!hre.search(subtokens[i], "[_\\]]")) {
subtokenText += "]";
}
tokenText += subtokenText;
if (i < (int)subtokens.size() - 1) {
tokenText += " ";
}
}
}
string tokenText = recip + pitch + "]";
token->setText(tokenText);
lineChange = true;
}
Expand All @@ -1367,19 +1383,27 @@ void Tool_myank::printDataLine(HLp line,
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 += "[";
string recip = Convert::durationToRecip(dur);
vector<string> subtokens = resolvedToken->getSubtokens();
for (int i=0; i<(int)subtokens.size(); i++) {
if (hre.search(subtokens[i], recipRegex)) {
string before = hre.getPrefix();
string after = hre.getSuffix();
hre.replaceDestructive(after, "", recipRegex, "g");
string subtokenText;
if (resolvedToken->getDuration() > dur) {
// Add a tie start if not already in a tie group
if (!hre.search(subtokens[i], "[_\\[]")) {
subtokenText += "[";
}
}
// Replace the old duration with the clipped one
subtokenText += before + recip + after;
token->replaceSubtoken(i, subtokenText);
lineChange = true;
}
}
tokenText += recip + pitch;
token->setText(tokenText);
lineChange = true;
}
}
}
Expand Down

0 comments on commit e6faa0d

Please sign in to comment.