Skip to content

Commit

Permalink
Merge pull request #61 from WolfgangDrescher/deg
Browse files Browse the repository at this point in the history
Implement --solfege option for deg tool
  • Loading branch information
craigsapp authored Jan 19, 2023
2 parents b8b4abc + 9132437 commit 6d7ddb8
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 28 deletions.
7 changes: 6 additions & 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: Tue Jan 17 21:33:56 PST 2023
// Last Modified: Fr 20 Jan 2023 00:01:35 CET
// Filename: humlib.h
// URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h
// Syntax: C++11
Expand Down Expand Up @@ -6736,13 +6736,15 @@ class Tool_deg : public HumTool {
bool isDegCircleLine (HumdrumFile& infile, int lineIndex);
bool isDegColorLine (HumdrumFile& infile, int lineIndex);
bool isDegHatLine (HumdrumFile& infile, int lineIndex);
bool isDegSolfegeLine (HumdrumFile& infile, int lineIndex);
bool isKeyDesignationLine (HumdrumFile& infile, int lineIndex);

void checkAboveStatus (string& value, bool arrowStatus);
void checkArrowStatus (string& value, bool arrowStatus);
void checkCircleStatus (string& value, bool arrowStatus);
void checkColorStatus (string& value, bool arrowStatus);
void checkHatStatus (string& value, bool arrowStatus);
void checkSolfegeStatus (string& value, bool arrowStatus);

void checkKeyDesignationStatus(string& value, int keyDesignationStatus);

Expand Down Expand Up @@ -6783,6 +6785,7 @@ class Tool_deg : public HumTool {
bool m_hatQ = false; // used with --hat option
bool m_colorQ = false; // used with --color option
std::string m_color; // used with --color option
bool m_solfegeQ = false; // used with --solfege option

bool m_degOnlyQ = false; // used with -I option
bool m_recipQ = false; // used with -r option
Expand All @@ -6808,6 +6811,7 @@ class Tool_deg : public HumTool {
bool foundColorLine;
bool foundHatLine;
bool foundKeyDesignationLine;
bool foundSolfegeLine;

InterleavedPrintVariables(void) { clear(); }
void clear(void) {
Expand All @@ -6819,6 +6823,7 @@ class Tool_deg : public HumTool {
foundColorLine = false;
foundHatLine = false;
foundKeyDesignationLine = false;
foundSolfegeLine = false;
}
};
InterleavedPrintVariables m_ipv;
Expand Down
5 changes: 5 additions & 0 deletions include/tool-deg.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,15 @@ class Tool_deg : public HumTool {
bool isDegCircleLine (HumdrumFile& infile, int lineIndex);
bool isDegColorLine (HumdrumFile& infile, int lineIndex);
bool isDegHatLine (HumdrumFile& infile, int lineIndex);
bool isDegSolfegeLine (HumdrumFile& infile, int lineIndex);
bool isKeyDesignationLine (HumdrumFile& infile, int lineIndex);

void checkAboveStatus (string& value, bool arrowStatus);
void checkArrowStatus (string& value, bool arrowStatus);
void checkCircleStatus (string& value, bool arrowStatus);
void checkColorStatus (string& value, bool arrowStatus);
void checkHatStatus (string& value, bool arrowStatus);
void checkSolfegeStatus (string& value, bool arrowStatus);

void checkKeyDesignationStatus(string& value, int keyDesignationStatus);

Expand Down Expand Up @@ -235,6 +237,7 @@ class Tool_deg : public HumTool {
bool m_hatQ = false; // used with --hat option
bool m_colorQ = false; // used with --color option
std::string m_color; // used with --color option
bool m_solfegeQ = false; // used with --solfege option

bool m_degOnlyQ = false; // used with -I option
bool m_recipQ = false; // used with -r option
Expand All @@ -260,6 +263,7 @@ class Tool_deg : public HumTool {
bool foundColorLine;
bool foundHatLine;
bool foundKeyDesignationLine;
bool foundSolfegeLine;

InterleavedPrintVariables(void) { clear(); }
void clear(void) {
Expand All @@ -271,6 +275,7 @@ class Tool_deg : public HumTool {
foundColorLine = false;
foundHatLine = false;
foundKeyDesignationLine = false;
foundSolfegeLine = false;
}
};
InterleavedPrintVariables m_ipv;
Expand Down
104 changes: 90 additions & 14 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: Tue Jan 17 21:33:56 PST 2023
// Last Modified: Fr 20 Jan 2023 00:01:35 CET
// Filename: /include/humlib.cpp
// URL: https://github.com/craigsapp/humlib/blob/master/src/humlib.cpp
// Syntax: C++11
Expand Down Expand Up @@ -68933,10 +68933,11 @@ string Tool_deg::ScaleDegree::m_forcedKey = "";
Tool_deg::Tool_deg(void) {
define("above=b", "Display scale degrees above analyzed staff");
define("arr|arrow|arrows=b", "Display scale degree alterations as arrows");
define("b|boxes|box=b", "Display scale degrees in boxes");
define("color=s", "Display color for scale degrees");
define("c|circ|circles|circle=b", "Display scale degrees in circles");
define("hat|caret|circumflex=b", "Display hats on scale degrees");
define("b|boxes|box=b", "Display scale degrees in boxes");
define("color=s", "Display color for scale degrees");
define("c|circ|circles|circle=b", "Display scale degrees in circles");
define("hat|caret|circumflex=b", "Display hats on scale degrees");
define("solf|solfege=b", "Display (relative) solfege syllables instead of scale degree numbers");
define("I|no-input=b", "Do not interleave **deg data with input score in output");
define("kern=b", "Prefix composite rhythm **kern spine with -I option");
define("k|kern-tracks=s", "Process only the specified kern spines");
Expand Down Expand Up @@ -69008,6 +69009,7 @@ void Tool_deg::initialize(void) {
m_circleQ = getBoolean("circle");
m_colorQ = getBoolean("color");
m_hatQ = getBoolean("hat");
m_solfegeQ = getBoolean("solfege");

if (m_colorQ) {
m_color = getString("color");
Expand Down Expand Up @@ -69217,6 +69219,7 @@ string Tool_deg::createOutputHumdrumLine(HumdrumFile& infile, int lineIndex) {
bool colorStatus = false;
bool hatStatus = false;
bool keyDesignationStatus = false;
bool solfegeStatus = false;

// Keep track of an existing styling line and if such a line is found,
// then insert a styling interpretation for the new **deg spines here
Expand All @@ -69243,6 +69246,9 @@ string Tool_deg::createOutputHumdrumLine(HumdrumFile& infile, int lineIndex) {
if (m_hatQ && !m_ipv.foundHatLine) {
hatStatus = isDegHatLine(infile, lineIndex);
}
if (m_solfegeQ && !m_ipv.foundSolfegeLine) {
solfegeStatus = isDegSolfegeLine(infile, lineIndex);
}
}

// spineData: The output Humdrum data line stored in a 2D vector.
Expand Down Expand Up @@ -69281,6 +69287,7 @@ string Tool_deg::createOutputHumdrumLine(HumdrumFile& infile, int lineIndex) {
checkCircleStatus(value, circleStatus);
checkColorStatus(value, colorStatus);
checkHatStatus(value, hatStatus);
checkSolfegeStatus(value, hatStatus);
spineData.back().push_back(value);
if (value == "*v") {
hasDegMerger = true;
Expand All @@ -69307,6 +69314,7 @@ string Tool_deg::createOutputHumdrumLine(HumdrumFile& infile, int lineIndex) {
checkCircleStatus(value, circleStatus);
checkColorStatus(value, colorStatus);
checkHatStatus(value, hatStatus);
checkSolfegeStatus(value, hatStatus);
spineData.back().push_back(value);
if (value == "*v") {
hasDegMerger = true;
Expand Down Expand Up @@ -69336,6 +69344,9 @@ string Tool_deg::createOutputHumdrumLine(HumdrumFile& infile, int lineIndex) {
if (hatStatus) {
m_ipv.foundHatLine = true;
}
if (solfegeStatus) {
m_ipv.foundSolfegeLine = true;
}


// if styling interpretation lines were not found before the data,
Expand Down Expand Up @@ -69393,6 +69404,15 @@ string Tool_deg::createOutputHumdrumLine(HumdrumFile& infile, int lineIndex) {
}
}

if (!m_ipv.foundSolfegeLine) {
if (m_solfegeQ && !m_ipv.foundSolfegeLine) {
string line = printDegInterpretation("*solf", infile, lineIndex);
if (!line.empty()) {
extraLines.push_back(line);
}
}
}

if (!m_ipv.foundKeyDesignationLine) {
if (!m_defaultKey.empty() && !m_ipv.foundKeyDesignationLine) {
string line = printDegInterpretation(m_defaultKey, infile, lineIndex);
Expand Down Expand Up @@ -69468,7 +69488,7 @@ void Tool_deg::checkKeyDesignationStatus(string& value, int keyDesignationStatus

//////////////////////////////
//
// Tool_deg::checkAboveStatus -- Add *arr interpretation to spine if needed.
// Tool_deg::checkAboveStatus -- Add *above interpretation to spine if needed.
//

void Tool_deg::checkAboveStatus(string& value, bool aboveStatus) {
Expand Down Expand Up @@ -69512,7 +69532,7 @@ void Tool_deg::checkCircleStatus(string& value, bool circleStatus) {

//////////////////////////////
//
// Tool_deg::checkColorStatus -- Add *arr interpretation to spine if needed.
// Tool_deg::checkColorStatus -- Add *color interpretation to spine if needed.
//

void Tool_deg::checkColorStatus(string& value, bool colorStatus) {
Expand Down Expand Up @@ -69540,6 +69560,21 @@ void Tool_deg::checkHatStatus(string& value, bool hatStatus) {



//////////////////////////////
//
// Tool_deg::checkSolfegeStatus -- Add *solfege interpretation to spine if needed.
//

void Tool_deg::checkSolfegeStatus(string& value, bool hatStatus) {
if (hatStatus && m_solfegeQ && (!m_ipv.foundSolfegeLine) && (!m_ipv.foundData)) {
if (value == "*") {
value = "*solf";
}
}
}



//////////////////////////////
//
// Tool_deg::isKeyDesignationLine -- Returns true if any spine on the line
Expand Down Expand Up @@ -69567,8 +69602,7 @@ bool Tool_deg::isKeyDesignationLine(HumdrumFile& infile, int lineIndex) {
//////////////////////////////
//
// Tool_deg::isDegAboveLine -- Return true if **deg spines only
// include *arr, *Xarr, *acc, *Xacc interpretations
// and "*" (but not all "*").
// include *above, *below, interpretations and "*" (but not all "*").
//

bool Tool_deg::isDegAboveLine(HumdrumFile& infile, int lineIndex) {
Expand Down Expand Up @@ -69679,8 +69713,7 @@ bool Tool_deg::isDegCircleLine(HumdrumFile& infile, int lineIndex) {
//////////////////////////////
//
// Tool_deg::isDegColorLine -- Return true if **deg spines only
// include *arr, *Xarr, *acc, *Xacc interpretations
// and "*" (but not all "*").
// include *color interpretations and "*" (but not all "*").
//

bool Tool_deg::isDegColorLine(HumdrumFile& infile, int lineIndex) {
Expand Down Expand Up @@ -69748,6 +69781,42 @@ bool Tool_deg::isDegHatLine(HumdrumFile& infile, int lineIndex) {



//////////////////////////////
//
// Tool_deg::isDegSolfegeLine -- Return true if **deg spines includes
// any *solf, or *Xsolf, interpretations and "*" (but not all "*").
//

bool Tool_deg::isDegSolfegeLine(HumdrumFile& infile, int lineIndex) {
// If there are no **deg spines, then don't bother searching for them.
if (!m_ipv.hasDegSpines) {
return false;
}
if (!infile[lineIndex].isInterpretation()) {
return false;
} if (infile[lineIndex].isManipulator()) {
return false;
}

int degCount = 0;
for (int i=0; i<infile[lineIndex].getFieldCount(); i++) {
HTp token = infile.token(lineIndex, i);
if (!token->isDataType("**deg")) {
continue;
}
degCount++;
if (*token == "*solf") { return true; }
if (*token == "*Xsolf") { return true; }
}
if (degCount == 0) {
m_ipv.hasDegSpines = false;
}

return false;
}



//////////////////////////////
//
// Tool_deg::printDegInterpretation --
Expand Down Expand Up @@ -69905,7 +69974,7 @@ string Tool_deg::prepareMergerLine(vector<vector<string>>& merge) {

//////////////////////////////
//
// Tool_deg::calculateManipulatorOutput -- Deal with *^ *v *- *+ manipulators
// Tool_deg::calculateManipulatorOutputForSpine -- Deal with *^ *v *- *+ manipulators
//

void Tool_deg::calculateManipulatorOutputForSpine(vector<string>& lineout,
Expand Down Expand Up @@ -69964,6 +70033,7 @@ void Tool_deg::printDegScore(HumdrumFile& infile) {
bool printCircle = !m_circleQ;
bool printColor = !m_colorQ;
bool printHat = !m_hatQ;
bool printSolfege = !m_solfegeQ;

int lineCount = (int)m_degSpines[0].size();
int spineCount = (int)m_degSpines.size();
Expand Down Expand Up @@ -70032,11 +70102,17 @@ void Tool_deg::printDegScore(HumdrumFile& infile) {
}

if (!printHat) {
string line = createDegInterpretation("*arr", i, m_recipQ);
string line = createDegInterpretation("*hat", i, m_recipQ);
m_humdrum_text << line << endl;
printHat = true;
}

if (!printSolfege) {
string line = createDegInterpretation("*solf", i, m_recipQ);
m_humdrum_text << line << endl;
printSolfege = true;
}

}

for (int j=0; j<spineCount; j++) {
Expand Down Expand Up @@ -70680,7 +70756,7 @@ string Tool_deg::ScaleDegree::generateDegDataToken(void) const {

//////////////////////////////
//
// Tool_deg::ScaleDegree::createDegDataSubToken -- Convert the ScaleDegree
// Tool_deg::ScaleDegree::generateDegDataSubtoken -- Convert the ScaleDegree
// subtoken (chord note) into **deg data.
//

Expand Down
Loading

0 comments on commit 6d7ddb8

Please sign in to comment.