From b3800750fbfc61b3198f89945a27fb076bb93f1b Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Sat, 4 Feb 2023 16:29:09 +0100 Subject: [PATCH 1/5] Add lyricsformatter tool --- CMakeLists.txt | 2 + Makefile | 11 ++- cli/lyricsformatter.cpp | 17 ++++ include/humlib.h | 27 ++++- include/tool-lyricsformatter.h | 50 ++++++++++ src/humlib.cpp | 153 ++++++++++++++++++++++++++++- src/tool-filter.cpp | 3 + src/tool-lyricsformatter.cpp | 174 +++++++++++++++++++++++++++++++++ 8 files changed, 434 insertions(+), 3 deletions(-) create mode 100644 cli/lyricsformatter.cpp create mode 100644 include/tool-lyricsformatter.h create mode 100644 src/tool-lyricsformatter.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b923b49..593bd1a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,7 @@ set(SRCS src/tool-filter.cpp src/tool-hproof.cpp src/tool-imitation.cpp + src/tool-lyricsformatter.cpp src/tool-mei2hum.cpp src/tool-metlev.cpp src/tool-msearch.cpp @@ -154,6 +155,7 @@ set(HDRS include/tool-fb.h include/tool-hproof.h include/tool-imitation.h + include/tool-lyricsformatter.h include/tool-mei2hum.h include/tool-metlev.h include/tool-msearch.h diff --git a/Makefile b/Makefile index 6028d96a..30f023d5 100644 --- a/Makefile +++ b/Makefile @@ -644,7 +644,7 @@ tool-filter.o: tool-filter.cpp tool-filter.h \ tool-composite.h tool-dissonant.h \ tool-extract.h tool-fb.h tool-homorhythm.h \ tool-homorhythm2.h tool-hproof.h \ - tool-humdiff.h tool-shed.h tool-imitation.h \ + tool-humdiff.h tool-shed.h tool-imitation.h tool-lyricsformatter.h \ tool-kern2mens.h tool-melisma.h tool-metlev.h \ tool-msearch.h tool-myank.h tool-phrase.h \ tool-recip.h tool-restfill.h tool-satb2gs.h \ @@ -708,6 +708,15 @@ tool-imitation.o: tool-imitation.cpp tool-imitation.h \ NoteGrid.h NoteCell.h Convert.h \ HumRegex.h +tool-lyricsformatter.o: tool-lyricsformatter.cpp tool-lyricsformatter.h \ + HumTool.h Options.h HumdrumFileSet.h \ + HumdrumFile.h HumdrumFileContent.h \ + HumdrumFileStructure.h HumdrumFileBase.h \ + HumSignifiers.h HumSignifier.h HumdrumLine.h \ + HumdrumToken.h HumNum.h HumAddress.h \ + HumHash.h HumParamSet.h HumdrumFileStream.h \ + HumRegex.h + tool-kern2mens.o: tool-kern2mens.cpp tool-kern2mens.h \ HumTool.h Options.h HumdrumFileSet.h \ HumdrumFile.h HumdrumFileContent.h \ diff --git a/cli/lyricsformatter.cpp b/cli/lyricsformatter.cpp new file mode 100644 index 00000000..c22542eb --- /dev/null +++ b/cli/lyricsformatter.cpp @@ -0,0 +1,17 @@ +// +// Programmer: Wolfgang Drescher +// Creation Date: Sa 4 Feb 2023 16:27:58 CET +// Filename: lyricsformatter.cpp +// URL: https://github.com/craigsapp/humlib/blob/master/cli/lyricsformatter.cpp +// Syntax: C++11 +// vim: ts=3 noexpandtab nowrap +// +// Description: Lyrics formatter program. +// + +#include "humlib.h" + +STREAM_INTERFACE(Tool_lyricsformatter) + + + diff --git a/include/humlib.h b/include/humlib.h index 1941c190..7ecf7f52 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: Thu Jan 26 22:41:11 PST 2023 +// Last Modified: Sa 4 Feb 2023 16:27:58 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 @@ -7895,6 +7895,31 @@ class Tool_kernview : public HumTool { }; +class Tool_lyricsformatter : public HumTool { + + public: + Tool_lyricsformatter (void); + ~Tool_lyricsformatter() {}; + + bool run(HumdrumFileSet& infiles); + bool run(HumdrumFile& infile); + bool run(const string& indata, ostream& out); + bool run(HumdrumFile& infile, ostream& out); + + protected: + void initialize (void); + void processFile (HumdrumFile& infile); + void addUnderlines (vector spineStartList); + void removeUnderlines(vector spineStartList); + + + private: + bool m_addUnderlineQ; + bool m_removeUnderlineQ; + +}; + + class mei_staffDef { public: HumNum timestamp; diff --git a/include/tool-lyricsformatter.h b/include/tool-lyricsformatter.h new file mode 100644 index 00000000..2d41141d --- /dev/null +++ b/include/tool-lyricsformatter.h @@ -0,0 +1,50 @@ +// +// Programmer: Wolfgang Drescher +// Creation Date: Sa 4 Feb 2023 16:27:58 CET +// Filename: tool-lyricsformatter.h +// URL: https://github.com/craigsapp/humlib/blob/master/include/tool-lyricsformatter.h +// Syntax: C++11; humlib +// vim: syntax=cpp ts=3 noexpandtab nowrap +// +// Description: Interface for lyricsformatter tool, which formats lyrics of **text spines. +// + +#ifndef _TOOL_LYRICSFORMATTER_H +#define _TOOL_LYRICSFORMATTER_H + +#include "HumTool.h" +#include "HumdrumFile.h" + +namespace hum { + +// START_MERGE + +class Tool_lyricsformatter : public HumTool { + + public: + Tool_lyricsformatter (void); + ~Tool_lyricsformatter() {}; + + bool run(HumdrumFileSet& infiles); + bool run(HumdrumFile& infile); + bool run(const string& indata, ostream& out); + bool run(HumdrumFile& infile, ostream& out); + + protected: + void initialize (void); + void processFile (HumdrumFile& infile); + void addUnderlines (vector spineStartList); + void removeUnderlines(vector spineStartList); + + + private: + bool m_addUnderlineQ; + bool m_removeUnderlineQ; + +}; + +// END_MERGE + +} // end namespace hum + +#endif /* _TOOL_LYRICSFORMATTER_H */ diff --git a/src/humlib.cpp b/src/humlib.cpp index 84873abc..babff50e 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: Thu Jan 26 22:41:11 PST 2023 +// Last Modified: Sa 4 Feb 2023 16:27:58 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 @@ -79073,6 +79073,8 @@ bool Tool_filter::run(HumdrumFileSet& infiles) { RUNTOOL(humtr, infile, commands[i].second, status); } else if (commands[i].first == "imitation") { RUNTOOL(imitation, infile, commands[i].second, status); + } else if (commands[i].first == "lyricsformatter") { + RUNTOOL(lyricsformatter, infile, commands[i].second, status); } else if (commands[i].first == "kern2mens") { RUNTOOL(kern2mens, infile, commands[i].second, status); } else if (commands[i].first == "kernview") { @@ -86110,6 +86112,155 @@ void Tool_kernview::processFile(HumdrumFile& infile) { +////////////////////////////// +// +// Tool_lyricsformatter::Tool_lyricsformatter -- Set the recognized options for the tool. +// + +Tool_lyricsformatter::Tool_lyricsformatter(void) { + define("ul|aul|add-ul|add-underline|underline=b", "Add melismatic underlines at ending syllables of words"); + define("xul|rul|remove-ul|remove-underline=b", "Remove melismatic underlines at ending syllables of words"); +} + + + +////////////////////////////// +// +// Tool_lyricsformatter::run -- Do the main work of the tool. +// + +bool Tool_lyricsformatter::run(HumdrumFileSet &infiles) { + bool status = true; + for (int i = 0; i < infiles.getCount(); i++) { + status &= run(infiles[i]); + } + return status; +} + +bool Tool_lyricsformatter::run(const string &indata, ostream &out) { + HumdrumFile infile(indata); + bool status = run(infile); + if (hasAnyText()) { + getAllText(out); + } else { + out << infile; + } + return status; +} + +bool Tool_lyricsformatter::run(HumdrumFile &infile, ostream &out) { + bool status = run(infile); + if (hasAnyText()) { + getAllText(out); + } else { + out << infile; + } + return status; +} + +bool Tool_lyricsformatter::run(HumdrumFile &infile) { + initialize(); + processFile(infile); + return true; +} + + + +////////////////////////////// +// +// Tool_lyricsformatter::initialize -- +// + +void Tool_lyricsformatter::initialize(void) { + m_addUnderlineQ = getBoolean("add-underline"); + m_removeUnderlineQ = getBoolean("remove-underline"); +} + + + +////////////////////////////// +// +// Tool_lyricsformatter::processFile -- +// + +void Tool_lyricsformatter::processFile(HumdrumFile& infile) { + + vector textSpinesStartList; + infile.getSpineStartList(textSpinesStartList, "**text"); + + if (m_addUnderlineQ) { + addUnderlines(textSpinesStartList); + } else if (m_removeUnderlineQ) { + removeUnderlines(textSpinesStartList); + } + + infile.createLinesFromTokens(); + + m_humdrum_text << infile; +} + + + +////////////////////////////// +// +// Tool_lyricsformatter::addUnderlines -- +// + +void Tool_lyricsformatter::addUnderlines(vector spineStartList) { + for (HTp token : spineStartList) { + if (!token->isDataType("**text")) { + continue; + } + HTp currentToken = token; + while (currentToken) { + HTp nextToken = currentToken->getNextToken(); + while (nextToken != NULL && !nextToken->isData()) { + nextToken = nextToken->getNextToken(); + } + if (nextToken == NULL) { + break; + } + string syllableExtender = "-"; + bool isWordEnd = equal(syllableExtender.rbegin(), syllableExtender.rend(), currentToken->getText().rbegin()) == false; + string wordEndExtender = "_"; + bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; + if (nextToken->isNull() && currentToken->isNonNullData() && isWordEnd && !endsWithUnderscore) { + currentToken->setText(currentToken->getText() + "_"); + } + currentToken = nextToken; + } + } +} + + + +////////////////////////////// +// +// Tool_lyricsformatter::removeUnderlines -- +// + +void Tool_lyricsformatter::removeUnderlines(vector spineStartList) { + for (HTp token : spineStartList) { + if (!token->isDataType("**text")) { + continue; + } + HTp currentToken = token; + while (currentToken) { + if (currentToken->isNonNullData()) { + string wordEndExtender = "_"; + bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; + if (endsWithUnderscore) { + string text = currentToken->getText(); + text.pop_back(); + currentToken->setText(text); + } + } + currentToken = currentToken->getNextToken(); + } + } +} + + // #define QUARTER_CONVERT * 4 #define QUARTER_CONVERT diff --git a/src/tool-filter.cpp b/src/tool-filter.cpp index d43ff794..7f12203f 100644 --- a/src/tool-filter.cpp +++ b/src/tool-filter.cpp @@ -40,6 +40,7 @@ #include "tool-humsheet.h" #include "tool-humtr.h" #include "tool-imitation.h" +#include "tool-lyricsformatter.h" #include "tool-kern2mens.h" #include "tool-kernview.h" #include "tool-mei2hum.h" @@ -258,6 +259,8 @@ bool Tool_filter::run(HumdrumFileSet& infiles) { RUNTOOL(humtr, infile, commands[i].second, status); } else if (commands[i].first == "imitation") { RUNTOOL(imitation, infile, commands[i].second, status); + } else if (commands[i].first == "lyricsformatter") { + RUNTOOL(lyricsformatter, infile, commands[i].second, status); } else if (commands[i].first == "kern2mens") { RUNTOOL(kern2mens, infile, commands[i].second, status); } else if (commands[i].first == "kernview") { diff --git a/src/tool-lyricsformatter.cpp b/src/tool-lyricsformatter.cpp new file mode 100644 index 00000000..61e54013 --- /dev/null +++ b/src/tool-lyricsformatter.cpp @@ -0,0 +1,174 @@ +// +// Programmer: Wolfgang Drescher +// Creation Date: Sa 4 Feb 2023 16:27:58 CET +// Filename: tool-lyricsformatter.cpp +// URL: https://github.com/craigsapp/humlib/blob/master/src/tool-lyricsformatter.cpp +// Syntax: C++11; humlib +// vim: syntax=cpp ts=3 noexpandtab nowrap +// +// Description: Format the lyrics of **text spines +// + +#include "tool-lyricsformatter.h" +#include "Convert.h" +#include "HumRegex.h" +#include +#include + +using namespace std; + +namespace hum { + +// START_MERGE + +////////////////////////////// +// +// Tool_lyricsformatter::Tool_lyricsformatter -- Set the recognized options for the tool. +// + +Tool_lyricsformatter::Tool_lyricsformatter(void) { + define("ul|aul|add-ul|add-underline|underline=b", "Add melismatic underlines at ending syllables of words"); + define("xul|rul|remove-ul|remove-underline=b", "Remove melismatic underlines at ending syllables of words"); +} + + + +////////////////////////////// +// +// Tool_lyricsformatter::run -- Do the main work of the tool. +// + +bool Tool_lyricsformatter::run(HumdrumFileSet &infiles) { + bool status = true; + for (int i = 0; i < infiles.getCount(); i++) { + status &= run(infiles[i]); + } + return status; +} + +bool Tool_lyricsformatter::run(const string &indata, ostream &out) { + HumdrumFile infile(indata); + bool status = run(infile); + if (hasAnyText()) { + getAllText(out); + } else { + out << infile; + } + return status; +} + +bool Tool_lyricsformatter::run(HumdrumFile &infile, ostream &out) { + bool status = run(infile); + if (hasAnyText()) { + getAllText(out); + } else { + out << infile; + } + return status; +} + +bool Tool_lyricsformatter::run(HumdrumFile &infile) { + initialize(); + processFile(infile); + return true; +} + + + +////////////////////////////// +// +// Tool_lyricsformatter::initialize -- +// + +void Tool_lyricsformatter::initialize(void) { + m_addUnderlineQ = getBoolean("add-underline"); + m_removeUnderlineQ = getBoolean("remove-underline"); +} + + + +////////////////////////////// +// +// Tool_lyricsformatter::processFile -- +// + +void Tool_lyricsformatter::processFile(HumdrumFile& infile) { + + vector textSpinesStartList; + infile.getSpineStartList(textSpinesStartList, "**text"); + + if (m_addUnderlineQ) { + addUnderlines(textSpinesStartList); + } else if (m_removeUnderlineQ) { + removeUnderlines(textSpinesStartList); + } + + infile.createLinesFromTokens(); + + m_humdrum_text << infile; +} + + + +////////////////////////////// +// +// Tool_lyricsformatter::addUnderlines -- +// + +void Tool_lyricsformatter::addUnderlines(vector spineStartList) { + for (HTp token : spineStartList) { + if (!token->isDataType("**text")) { + continue; + } + HTp currentToken = token; + while (currentToken) { + HTp nextToken = currentToken->getNextToken(); + while (nextToken != NULL && !nextToken->isData()) { + nextToken = nextToken->getNextToken(); + } + if (nextToken == NULL) { + break; + } + string syllableExtender = "-"; + bool isWordEnd = equal(syllableExtender.rbegin(), syllableExtender.rend(), currentToken->getText().rbegin()) == false; + string wordEndExtender = "_"; + bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; + if (nextToken->isNull() && currentToken->isNonNullData() && isWordEnd && !endsWithUnderscore) { + currentToken->setText(currentToken->getText() + "_"); + } + currentToken = nextToken; + } + } +} + + + +////////////////////////////// +// +// Tool_lyricsformatter::removeUnderlines -- +// + +void Tool_lyricsformatter::removeUnderlines(vector spineStartList) { + for (HTp token : spineStartList) { + if (!token->isDataType("**text")) { + continue; + } + HTp currentToken = token; + while (currentToken) { + if (currentToken->isNonNullData()) { + string wordEndExtender = "_"; + bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; + if (endsWithUnderscore) { + string text = currentToken->getText(); + text.pop_back(); + currentToken->setText(text); + } + } + currentToken = currentToken->getNextToken(); + } + } +} + +// END_MERGE + +} // end namespace hum From f1e4867303fcfb155cfc0bdf7963c328aaca4029 Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Mon, 6 Feb 2023 10:29:14 +0100 Subject: [PATCH 2/5] Rename tool to worex --- cli/{lyricsformatter.cpp => worex.cpp} | 11 +- include/humlib.h | 51 ++- .../{tool-lyricsformatter.h => tool-worex.h} | 25 +- src/humlib.cpp | 302 +++++++++--------- src/tool-filter.cpp | 6 +- ...ool-lyricsformatter.cpp => tool-worex.cpp} | 52 ++- 6 files changed, 219 insertions(+), 228 deletions(-) rename cli/{lyricsformatter.cpp => worex.cpp} (64%) rename include/{tool-lyricsformatter.h => tool-worex.h} (55%) rename src/{tool-lyricsformatter.cpp => tool-worex.cpp} (64%) diff --git a/cli/lyricsformatter.cpp b/cli/worex.cpp similarity index 64% rename from cli/lyricsformatter.cpp rename to cli/worex.cpp index c22542eb..e5443d8f 100644 --- a/cli/lyricsformatter.cpp +++ b/cli/worex.cpp @@ -1,17 +1,14 @@ // // Programmer: Wolfgang Drescher // Creation Date: Sa 4 Feb 2023 16:27:58 CET -// Filename: lyricsformatter.cpp -// URL: https://github.com/craigsapp/humlib/blob/master/cli/lyricsformatter.cpp +// Filename: worex.cpp +// URL: https://github.com/craigsapp/humlib/blob/master/cli/worex.cpp // Syntax: C++11 // vim: ts=3 noexpandtab nowrap // -// Description: Lyrics formatter program. +// Description: Word extender program. // #include "humlib.h" -STREAM_INTERFACE(Tool_lyricsformatter) - - - +STREAM_INTERFACE(Tool_worex) diff --git a/include/humlib.h b/include/humlib.h index 7ecf7f52..8978ed4c 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: Sa 4 Feb 2023 16:27:58 CET +// Last Modified: Mo 6 Feb 2023 10:29:01 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 @@ -7895,31 +7895,6 @@ class Tool_kernview : public HumTool { }; -class Tool_lyricsformatter : public HumTool { - - public: - Tool_lyricsformatter (void); - ~Tool_lyricsformatter() {}; - - bool run(HumdrumFileSet& infiles); - bool run(HumdrumFile& infile); - bool run(const string& indata, ostream& out); - bool run(HumdrumFile& infile, ostream& out); - - protected: - void initialize (void); - void processFile (HumdrumFile& infile); - void addUnderlines (vector spineStartList); - void removeUnderlines(vector spineStartList); - - - private: - bool m_addUnderlineQ; - bool m_removeUnderlineQ; - -}; - - class mei_staffDef { public: HumNum timestamp; @@ -10272,6 +10247,30 @@ class Tool_trillspell : public HumTool { +class Tool_worex : public HumTool { + + public: + Tool_worex (void); + ~Tool_worex() {}; + + bool run(HumdrumFileSet& infiles); + bool run(HumdrumFile& infile); + bool run(const string& indata, ostream& out); + bool run(HumdrumFile& infile, ostream& out); + + protected: + void initialize (void); + void processFile (HumdrumFile& infile); + void addWordExtenders (vector spineStartList); + void removeWordExtenders(vector spineStartList); + + + private: + bool m_removeWordExtenderQ; + +}; + + } // end of namespace hum diff --git a/include/tool-lyricsformatter.h b/include/tool-worex.h similarity index 55% rename from include/tool-lyricsformatter.h rename to include/tool-worex.h index 2d41141d..a724eca0 100644 --- a/include/tool-lyricsformatter.h +++ b/include/tool-worex.h @@ -1,16 +1,16 @@ // // Programmer: Wolfgang Drescher // Creation Date: Sa 4 Feb 2023 16:27:58 CET -// Filename: tool-lyricsformatter.h -// URL: https://github.com/craigsapp/humlib/blob/master/include/tool-lyricsformatter.h +// Filename: tool-worex.h +// URL: https://github.com/craigsapp/humlib/blob/master/include/tool-worex.h // Syntax: C++11; humlib // vim: syntax=cpp ts=3 noexpandtab nowrap // -// Description: Interface for lyricsformatter tool, which formats lyrics of **text spines. +// Description: Interface for worex tool, which adds word extenders to the lyrics. // -#ifndef _TOOL_LYRICSFORMATTER_H -#define _TOOL_LYRICSFORMATTER_H +#ifndef _TOOL_WOREX_H +#define _TOOL_WOREX_H #include "HumTool.h" #include "HumdrumFile.h" @@ -19,11 +19,11 @@ namespace hum { // START_MERGE -class Tool_lyricsformatter : public HumTool { +class Tool_worex : public HumTool { public: - Tool_lyricsformatter (void); - ~Tool_lyricsformatter() {}; + Tool_worex (void); + ~Tool_worex() {}; bool run(HumdrumFileSet& infiles); bool run(HumdrumFile& infile); @@ -33,13 +33,12 @@ class Tool_lyricsformatter : public HumTool { protected: void initialize (void); void processFile (HumdrumFile& infile); - void addUnderlines (vector spineStartList); - void removeUnderlines(vector spineStartList); + void addWordExtenders (vector spineStartList); + void removeWordExtenders(vector spineStartList); private: - bool m_addUnderlineQ; - bool m_removeUnderlineQ; + bool m_removeWordExtenderQ; }; @@ -47,4 +46,4 @@ class Tool_lyricsformatter : public HumTool { } // end namespace hum -#endif /* _TOOL_LYRICSFORMATTER_H */ +#endif /* _TOOL_WOREX_H */ diff --git a/src/humlib.cpp b/src/humlib.cpp index babff50e..7c2cb403 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: Sa 4 Feb 2023 16:27:58 CET +// Last Modified: Mo 6 Feb 2023 10:29:01 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 @@ -79073,8 +79073,8 @@ bool Tool_filter::run(HumdrumFileSet& infiles) { RUNTOOL(humtr, infile, commands[i].second, status); } else if (commands[i].first == "imitation") { RUNTOOL(imitation, infile, commands[i].second, status); - } else if (commands[i].first == "lyricsformatter") { - RUNTOOL(lyricsformatter, infile, commands[i].second, status); + } else if (commands[i].first == "worex") { + RUNTOOL(worex, infile, commands[i].second, status); } else if (commands[i].first == "kern2mens") { RUNTOOL(kern2mens, infile, commands[i].second, status); } else if (commands[i].first == "kernview") { @@ -86112,155 +86112,6 @@ void Tool_kernview::processFile(HumdrumFile& infile) { -////////////////////////////// -// -// Tool_lyricsformatter::Tool_lyricsformatter -- Set the recognized options for the tool. -// - -Tool_lyricsformatter::Tool_lyricsformatter(void) { - define("ul|aul|add-ul|add-underline|underline=b", "Add melismatic underlines at ending syllables of words"); - define("xul|rul|remove-ul|remove-underline=b", "Remove melismatic underlines at ending syllables of words"); -} - - - -////////////////////////////// -// -// Tool_lyricsformatter::run -- Do the main work of the tool. -// - -bool Tool_lyricsformatter::run(HumdrumFileSet &infiles) { - bool status = true; - for (int i = 0; i < infiles.getCount(); i++) { - status &= run(infiles[i]); - } - return status; -} - -bool Tool_lyricsformatter::run(const string &indata, ostream &out) { - HumdrumFile infile(indata); - bool status = run(infile); - if (hasAnyText()) { - getAllText(out); - } else { - out << infile; - } - return status; -} - -bool Tool_lyricsformatter::run(HumdrumFile &infile, ostream &out) { - bool status = run(infile); - if (hasAnyText()) { - getAllText(out); - } else { - out << infile; - } - return status; -} - -bool Tool_lyricsformatter::run(HumdrumFile &infile) { - initialize(); - processFile(infile); - return true; -} - - - -////////////////////////////// -// -// Tool_lyricsformatter::initialize -- -// - -void Tool_lyricsformatter::initialize(void) { - m_addUnderlineQ = getBoolean("add-underline"); - m_removeUnderlineQ = getBoolean("remove-underline"); -} - - - -////////////////////////////// -// -// Tool_lyricsformatter::processFile -- -// - -void Tool_lyricsformatter::processFile(HumdrumFile& infile) { - - vector textSpinesStartList; - infile.getSpineStartList(textSpinesStartList, "**text"); - - if (m_addUnderlineQ) { - addUnderlines(textSpinesStartList); - } else if (m_removeUnderlineQ) { - removeUnderlines(textSpinesStartList); - } - - infile.createLinesFromTokens(); - - m_humdrum_text << infile; -} - - - -////////////////////////////// -// -// Tool_lyricsformatter::addUnderlines -- -// - -void Tool_lyricsformatter::addUnderlines(vector spineStartList) { - for (HTp token : spineStartList) { - if (!token->isDataType("**text")) { - continue; - } - HTp currentToken = token; - while (currentToken) { - HTp nextToken = currentToken->getNextToken(); - while (nextToken != NULL && !nextToken->isData()) { - nextToken = nextToken->getNextToken(); - } - if (nextToken == NULL) { - break; - } - string syllableExtender = "-"; - bool isWordEnd = equal(syllableExtender.rbegin(), syllableExtender.rend(), currentToken->getText().rbegin()) == false; - string wordEndExtender = "_"; - bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; - if (nextToken->isNull() && currentToken->isNonNullData() && isWordEnd && !endsWithUnderscore) { - currentToken->setText(currentToken->getText() + "_"); - } - currentToken = nextToken; - } - } -} - - - -////////////////////////////// -// -// Tool_lyricsformatter::removeUnderlines -- -// - -void Tool_lyricsformatter::removeUnderlines(vector spineStartList) { - for (HTp token : spineStartList) { - if (!token->isDataType("**text")) { - continue; - } - HTp currentToken = token; - while (currentToken) { - if (currentToken->isNonNullData()) { - string wordEndExtender = "_"; - bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; - if (endsWithUnderscore) { - string text = currentToken->getText(); - text.pop_back(); - currentToken->setText(text); - } - } - currentToken = currentToken->getNextToken(); - } - } -} - - // #define QUARTER_CONVERT * 4 #define QUARTER_CONVERT @@ -116648,4 +116499,151 @@ int Tool_trillspell::getBase40(int diatonic, int accidental) { +////////////////////////////// +// +// Tool_worex::Tool_worex -- Set the recognized options for the tool. +// + +Tool_worex::Tool_worex(void) { + define("r|remove=b", "Remove melismatic underlines at ending syllables of words"); +} + + + +////////////////////////////// +// +// Tool_worex::run -- Do the main work of the tool. +// + +bool Tool_worex::run(HumdrumFileSet &infiles) { + bool status = true; + for (int i = 0; i < infiles.getCount(); i++) { + status &= run(infiles[i]); + } + return status; +} + +bool Tool_worex::run(const string &indata, ostream &out) { + HumdrumFile infile(indata); + bool status = run(infile); + if (hasAnyText()) { + getAllText(out); + } else { + out << infile; + } + return status; +} + +bool Tool_worex::run(HumdrumFile &infile, ostream &out) { + bool status = run(infile); + if (hasAnyText()) { + getAllText(out); + } else { + out << infile; + } + return status; +} + +bool Tool_worex::run(HumdrumFile &infile) { + initialize(); + processFile(infile); + return true; +} + + + +////////////////////////////// +// +// Tool_worex::initialize -- +// + +void Tool_worex::initialize(void) { + m_removeWordExtenderQ = getBoolean("remove"); +} + + + +////////////////////////////// +// +// Tool_worex::processFile -- +// + +void Tool_worex::processFile(HumdrumFile& infile) { + + vector textSpinesStartList; + infile.getSpineStartList(textSpinesStartList, "**text"); + + if (m_removeWordExtenderQ) { + removeWordExtenders(textSpinesStartList); + } else { + addWordExtenders(textSpinesStartList); + } + + infile.createLinesFromTokens(); + + m_humdrum_text << infile; +} + + + +////////////////////////////// +// +// Tool_worex::addWordExtenders -- +// + +void Tool_worex::addWordExtenders(vector spineStartList) { + for (HTp token : spineStartList) { + if (!token->isDataType("**text")) { + continue; + } + HTp currentToken = token; + while (currentToken) { + HTp nextToken = currentToken->getNextToken(); + while (nextToken != NULL && !nextToken->isData()) { + nextToken = nextToken->getNextToken(); + } + if (nextToken == NULL) { + break; + } + string syllableExtender = "-"; + bool isWordEnd = equal(syllableExtender.rbegin(), syllableExtender.rend(), currentToken->getText().rbegin()) == false; + string wordEndExtender = "_"; + bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; + if (nextToken->isNull() && currentToken->isNonNullData() && isWordEnd && !endsWithUnderscore) { + currentToken->setText(currentToken->getText() + "_"); + } + currentToken = nextToken; + } + } +} + + + +////////////////////////////// +// +// Tool_worex::removeWordExtenders -- +// + +void Tool_worex::removeWordExtenders(vector spineStartList) { + for (HTp token : spineStartList) { + if (!token->isDataType("**text")) { + continue; + } + HTp currentToken = token; + while (currentToken) { + if (currentToken->isNonNullData()) { + string wordEndExtender = "_"; + bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; + if (endsWithUnderscore) { + string text = currentToken->getText(); + text.pop_back(); + currentToken->setText(text); + } + } + currentToken = currentToken->getNextToken(); + } + } +} + + } // end namespace hum diff --git a/src/tool-filter.cpp b/src/tool-filter.cpp index 7f12203f..e1a1da44 100644 --- a/src/tool-filter.cpp +++ b/src/tool-filter.cpp @@ -40,7 +40,7 @@ #include "tool-humsheet.h" #include "tool-humtr.h" #include "tool-imitation.h" -#include "tool-lyricsformatter.h" +#include "tool-worex.h" #include "tool-kern2mens.h" #include "tool-kernview.h" #include "tool-mei2hum.h" @@ -259,8 +259,8 @@ bool Tool_filter::run(HumdrumFileSet& infiles) { RUNTOOL(humtr, infile, commands[i].second, status); } else if (commands[i].first == "imitation") { RUNTOOL(imitation, infile, commands[i].second, status); - } else if (commands[i].first == "lyricsformatter") { - RUNTOOL(lyricsformatter, infile, commands[i].second, status); + } else if (commands[i].first == "worex") { + RUNTOOL(worex, infile, commands[i].second, status); } else if (commands[i].first == "kern2mens") { RUNTOOL(kern2mens, infile, commands[i].second, status); } else if (commands[i].first == "kernview") { diff --git a/src/tool-lyricsformatter.cpp b/src/tool-worex.cpp similarity index 64% rename from src/tool-lyricsformatter.cpp rename to src/tool-worex.cpp index 61e54013..6864a9af 100644 --- a/src/tool-lyricsformatter.cpp +++ b/src/tool-worex.cpp @@ -1,15 +1,15 @@ // // Programmer: Wolfgang Drescher // Creation Date: Sa 4 Feb 2023 16:27:58 CET -// Filename: tool-lyricsformatter.cpp -// URL: https://github.com/craigsapp/humlib/blob/master/src/tool-lyricsformatter.cpp +// Filename: tool-worex.cpp +// URL: https://github.com/craigsapp/humlib/blob/master/src/tool-worex.cpp // Syntax: C++11; humlib // vim: syntax=cpp ts=3 noexpandtab nowrap // -// Description: Format the lyrics of **text spines +// Description: Add melismatic underlines at ending syllables of words // -#include "tool-lyricsformatter.h" +#include "tool-worex.h" #include "Convert.h" #include "HumRegex.h" #include @@ -23,22 +23,21 @@ namespace hum { ////////////////////////////// // -// Tool_lyricsformatter::Tool_lyricsformatter -- Set the recognized options for the tool. +// Tool_worex::Tool_worex -- Set the recognized options for the tool. // -Tool_lyricsformatter::Tool_lyricsformatter(void) { - define("ul|aul|add-ul|add-underline|underline=b", "Add melismatic underlines at ending syllables of words"); - define("xul|rul|remove-ul|remove-underline=b", "Remove melismatic underlines at ending syllables of words"); +Tool_worex::Tool_worex(void) { + define("r|remove=b", "Remove melismatic underlines at ending syllables of words"); } ////////////////////////////// // -// Tool_lyricsformatter::run -- Do the main work of the tool. +// Tool_worex::run -- Do the main work of the tool. // -bool Tool_lyricsformatter::run(HumdrumFileSet &infiles) { +bool Tool_worex::run(HumdrumFileSet &infiles) { bool status = true; for (int i = 0; i < infiles.getCount(); i++) { status &= run(infiles[i]); @@ -46,7 +45,7 @@ bool Tool_lyricsformatter::run(HumdrumFileSet &infiles) { return status; } -bool Tool_lyricsformatter::run(const string &indata, ostream &out) { +bool Tool_worex::run(const string &indata, ostream &out) { HumdrumFile infile(indata); bool status = run(infile); if (hasAnyText()) { @@ -57,7 +56,7 @@ bool Tool_lyricsformatter::run(const string &indata, ostream &out) { return status; } -bool Tool_lyricsformatter::run(HumdrumFile &infile, ostream &out) { +bool Tool_worex::run(HumdrumFile &infile, ostream &out) { bool status = run(infile); if (hasAnyText()) { getAllText(out); @@ -67,7 +66,7 @@ bool Tool_lyricsformatter::run(HumdrumFile &infile, ostream &out) { return status; } -bool Tool_lyricsformatter::run(HumdrumFile &infile) { +bool Tool_worex::run(HumdrumFile &infile) { initialize(); processFile(infile); return true; @@ -77,30 +76,29 @@ bool Tool_lyricsformatter::run(HumdrumFile &infile) { ////////////////////////////// // -// Tool_lyricsformatter::initialize -- +// Tool_worex::initialize -- // -void Tool_lyricsformatter::initialize(void) { - m_addUnderlineQ = getBoolean("add-underline"); - m_removeUnderlineQ = getBoolean("remove-underline"); +void Tool_worex::initialize(void) { + m_removeWordExtenderQ = getBoolean("remove"); } ////////////////////////////// // -// Tool_lyricsformatter::processFile -- +// Tool_worex::processFile -- // -void Tool_lyricsformatter::processFile(HumdrumFile& infile) { +void Tool_worex::processFile(HumdrumFile& infile) { vector textSpinesStartList; infile.getSpineStartList(textSpinesStartList, "**text"); - if (m_addUnderlineQ) { - addUnderlines(textSpinesStartList); - } else if (m_removeUnderlineQ) { - removeUnderlines(textSpinesStartList); + if (m_removeWordExtenderQ) { + removeWordExtenders(textSpinesStartList); + } else { + addWordExtenders(textSpinesStartList); } infile.createLinesFromTokens(); @@ -112,10 +110,10 @@ void Tool_lyricsformatter::processFile(HumdrumFile& infile) { ////////////////////////////// // -// Tool_lyricsformatter::addUnderlines -- +// Tool_worex::addWordExtenders -- // -void Tool_lyricsformatter::addUnderlines(vector spineStartList) { +void Tool_worex::addWordExtenders(vector spineStartList) { for (HTp token : spineStartList) { if (!token->isDataType("**text")) { continue; @@ -145,10 +143,10 @@ void Tool_lyricsformatter::addUnderlines(vector spineStartList) { ////////////////////////////// // -// Tool_lyricsformatter::removeUnderlines -- +// Tool_worex::removeWordExtenders -- // -void Tool_lyricsformatter::removeUnderlines(vector spineStartList) { +void Tool_worex::removeWordExtenders(vector spineStartList) { for (HTp token : spineStartList) { if (!token->isDataType("**text")) { continue; From 7a56e20d01d8407e80a7957513db9f2736483b0a Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Mon, 6 Feb 2023 11:32:07 +0100 Subject: [PATCH 3/5] Fix missing renaming to worex --- CMakeLists.txt | 4 ++-- Makefile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 593bd1a4..221e61e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,7 +94,7 @@ set(SRCS src/tool-filter.cpp src/tool-hproof.cpp src/tool-imitation.cpp - src/tool-lyricsformatter.cpp + src/tool-worex.cpp src/tool-mei2hum.cpp src/tool-metlev.cpp src/tool-msearch.cpp @@ -155,7 +155,7 @@ set(HDRS include/tool-fb.h include/tool-hproof.h include/tool-imitation.h - include/tool-lyricsformatter.h + include/tool-worex.h include/tool-mei2hum.h include/tool-metlev.h include/tool-msearch.h diff --git a/Makefile b/Makefile index 30f023d5..3138bc9f 100644 --- a/Makefile +++ b/Makefile @@ -644,7 +644,7 @@ tool-filter.o: tool-filter.cpp tool-filter.h \ tool-composite.h tool-dissonant.h \ tool-extract.h tool-fb.h tool-homorhythm.h \ tool-homorhythm2.h tool-hproof.h \ - tool-humdiff.h tool-shed.h tool-imitation.h tool-lyricsformatter.h \ + tool-humdiff.h tool-shed.h tool-imitation.h tool-worex.h \ tool-kern2mens.h tool-melisma.h tool-metlev.h \ tool-msearch.h tool-myank.h tool-phrase.h \ tool-recip.h tool-restfill.h tool-satb2gs.h \ @@ -708,7 +708,7 @@ tool-imitation.o: tool-imitation.cpp tool-imitation.h \ NoteGrid.h NoteCell.h Convert.h \ HumRegex.h -tool-lyricsformatter.o: tool-lyricsformatter.cpp tool-lyricsformatter.h \ +tool-worex.o: tool-worex.cpp tool-worex.h \ HumTool.h Options.h HumdrumFileSet.h \ HumdrumFile.h HumdrumFileContent.h \ HumdrumFileStructure.h HumdrumFileBase.h \ From 1cd4cfe0ca9562759db8cdba06ead7e1d44f352c Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Wed, 8 Feb 2023 14:41:57 +0100 Subject: [PATCH 4/5] Fix indentation --- include/humlib.h | 6 +++--- include/tool-worex.h | 4 ++-- src/humlib.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/humlib.h b/include/humlib.h index 8978ed4c..d7a650b6 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 6 Feb 2023 10:29:01 CET +// Last Modified: Mi 8 Feb 2023 14:40:27 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 @@ -10259,8 +10259,8 @@ class Tool_worex : public HumTool { bool run(HumdrumFile& infile, ostream& out); protected: - void initialize (void); - void processFile (HumdrumFile& infile); + void initialize (void); + void processFile (HumdrumFile& infile); void addWordExtenders (vector spineStartList); void removeWordExtenders(vector spineStartList); diff --git a/include/tool-worex.h b/include/tool-worex.h index a724eca0..0bab91fb 100644 --- a/include/tool-worex.h +++ b/include/tool-worex.h @@ -31,8 +31,8 @@ class Tool_worex : public HumTool { bool run(HumdrumFile& infile, ostream& out); protected: - void initialize (void); - void processFile (HumdrumFile& infile); + void initialize (void); + void processFile (HumdrumFile& infile); void addWordExtenders (vector spineStartList); void removeWordExtenders(vector spineStartList); diff --git a/src/humlib.cpp b/src/humlib.cpp index 5beac4c5..705148fc 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 6 Feb 2023 10:29:01 CET +// Last Modified: Mi 8 Feb 2023 14:40:27 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 From 5b773afac04ec46f55cf5f9f721c41d2853acafc Mon Sep 17 00:00:00 2001 From: Wolfgang Drescher Date: Wed, 8 Feb 2023 14:46:44 +0100 Subject: [PATCH 5/5] Fix wrong word extenders when there were slices between a syllable token and the next syllable caused by the rhythm of other voices --- include/humlib.h | 3 +- include/tool-worex.h | 1 + src/humlib.cpp | 67 ++++++++++++++++++++++++++++++++++++++------ src/tool-worex.cpp | 65 +++++++++++++++++++++++++++++++++++++----- 4 files changed, 120 insertions(+), 16 deletions(-) diff --git a/include/humlib.h b/include/humlib.h index d7a650b6..fd85d628 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 8 Feb 2023 14:40:27 CET +// Last Modified: Mi 8 Feb 2023 14:42:01 CET // Filename: humlib.h // URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h // Syntax: C++11 @@ -10263,6 +10263,7 @@ class Tool_worex : public HumTool { void processFile (HumdrumFile& infile); void addWordExtenders (vector spineStartList); void removeWordExtenders(vector spineStartList); + HTp getParallelNote (HTp token); private: diff --git a/include/tool-worex.h b/include/tool-worex.h index 0bab91fb..9dde5ef4 100644 --- a/include/tool-worex.h +++ b/include/tool-worex.h @@ -35,6 +35,7 @@ class Tool_worex : public HumTool { void processFile (HumdrumFile& infile); void addWordExtenders (vector spineStartList); void removeWordExtenders(vector spineStartList); + HTp getParallelNote (HTp token); private: diff --git a/src/humlib.cpp b/src/humlib.cpp index 705148fc..f0d78fcd 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 8 Feb 2023 14:40:27 CET +// Last Modified: Mi 8 Feb 2023 14:42:01 CET // Filename: /include/humlib.cpp // URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp // Syntax: C++11 @@ -116598,19 +116598,33 @@ void Tool_worex::addWordExtenders(vector spineStartList) { } HTp currentToken = token; while (currentToken) { + HTp parallelNoteToken = getParallelNote(currentToken); HTp nextToken = currentToken->getNextToken(); - while (nextToken != NULL && !nextToken->isData()) { + // get token of next syllable + while (nextToken != NULL && !nextToken->isNonNullData()) { nextToken = nextToken->getNextToken(); } if (nextToken == NULL) { + // ignore current token if there is no next break; } - string syllableExtender = "-"; - bool isWordEnd = equal(syllableExtender.rbegin(), syllableExtender.rend(), currentToken->getText().rbegin()) == false; - string wordEndExtender = "_"; - bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; - if (nextToken->isNull() && currentToken->isNonNullData() && isWordEnd && !endsWithUnderscore) { - currentToken->setText(currentToken->getText() + "_"); + if (parallelNoteToken != NULL) { + // if next syllable if not direclty after the duration of the current parallel note token + if (nextToken->getDurationFromStart() > (parallelNoteToken->getDurationFromStart() + parallelNoteToken->getDuration())) { + // check if parallel note of current track is not followed by a rest + HTp nextNonNullDataToken = parallelNoteToken->getNextNonNullDataToken(); + if (!nextNonNullDataToken->isRest()) { + string syllableExtender = "-"; + bool isWordEnd = equal(syllableExtender.rbegin(), syllableExtender.rend(), currentToken->getText().rbegin()) == false; + string wordEndExtender = "_"; + bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; + // if current syllable is the end end of a word + // and the token does not alredy end with a underscore + if(isWordEnd && !endsWithUnderscore) { + currentToken->setText(currentToken->getText() + "_"); + } + } + } } currentToken = nextToken; } @@ -116646,4 +116660,41 @@ void Tool_worex::removeWordExtenders(vector spineStartList) { } + +////////////////////////////// +// +// Tool_worex::getParallelNote -- Go backwards on the line and count any note +// attack (or tied note) on the first staff-like spine (track) found to the +// left. If there is a spine split in the text and or **kern data, then this +// algorithm needs to be refined further. +// + +HTp Tool_worex::getParallelNote(hum::HTp token) { + hum::HTp current = token; + int track = -1; + while (current) { + current = current->getPreviousField(); + if (!current) { + break; + } + if (current->isStaff()) { + int ctrack = current->getTrack(); + if (track < 0) { + track = ctrack; + } + if (track != ctrack) { + return NULL; + } + if (current->isNull()) { + continue; + } + if (current->isNote()) { + return current; + } + } + } + return NULL; +} + + } // end namespace hum diff --git a/src/tool-worex.cpp b/src/tool-worex.cpp index 6864a9af..07eefa31 100644 --- a/src/tool-worex.cpp +++ b/src/tool-worex.cpp @@ -120,19 +120,33 @@ void Tool_worex::addWordExtenders(vector spineStartList) { } HTp currentToken = token; while (currentToken) { + HTp parallelNoteToken = getParallelNote(currentToken); HTp nextToken = currentToken->getNextToken(); - while (nextToken != NULL && !nextToken->isData()) { + // get token of next syllable + while (nextToken != NULL && !nextToken->isNonNullData()) { nextToken = nextToken->getNextToken(); } if (nextToken == NULL) { + // ignore current token if there is no next break; } - string syllableExtender = "-"; - bool isWordEnd = equal(syllableExtender.rbegin(), syllableExtender.rend(), currentToken->getText().rbegin()) == false; - string wordEndExtender = "_"; - bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; - if (nextToken->isNull() && currentToken->isNonNullData() && isWordEnd && !endsWithUnderscore) { - currentToken->setText(currentToken->getText() + "_"); + if (parallelNoteToken != NULL) { + // if next syllable if not direclty after the duration of the current parallel note token + if (nextToken->getDurationFromStart() > (parallelNoteToken->getDurationFromStart() + parallelNoteToken->getDuration())) { + // check if parallel note of current track is not followed by a rest + HTp nextNonNullDataToken = parallelNoteToken->getNextNonNullDataToken(); + if (!nextNonNullDataToken->isRest()) { + string syllableExtender = "-"; + bool isWordEnd = equal(syllableExtender.rbegin(), syllableExtender.rend(), currentToken->getText().rbegin()) == false; + string wordEndExtender = "_"; + bool endsWithUnderscore = equal(wordEndExtender.rbegin(), wordEndExtender.rend(), currentToken->getText().rbegin()) == true; + // if current syllable is the end end of a word + // and the token does not alredy end with a underscore + if(isWordEnd && !endsWithUnderscore) { + currentToken->setText(currentToken->getText() + "_"); + } + } + } } currentToken = nextToken; } @@ -167,6 +181,43 @@ void Tool_worex::removeWordExtenders(vector spineStartList) { } } + + +////////////////////////////// +// +// Tool_worex::getParallelNote -- Go backwards on the line and count any note +// attack (or tied note) on the first staff-like spine (track) found to the +// left. If there is a spine split in the text and or **kern data, then this +// algorithm needs to be refined further. +// + +HTp Tool_worex::getParallelNote(hum::HTp token) { + hum::HTp current = token; + int track = -1; + while (current) { + current = current->getPreviousField(); + if (!current) { + break; + } + if (current->isStaff()) { + int ctrack = current->getTrack(); + if (track < 0) { + track = ctrack; + } + if (track != ctrack) { + return NULL; + } + if (current->isNull()) { + continue; + } + if (current->isNote()) { + return current; + } + } + } + return NULL; +} + // END_MERGE } // end namespace hum