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] Improve data token handling at start end end of myanked section #74

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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