Skip to content

Commit

Permalink
Add hat and circle styling to **deg in Humdrum-to-MEI converter.
Browse files Browse the repository at this point in the history
  • Loading branch information
craigsapp committed Dec 27, 2022
1 parent bd5fc8c commit e8f18d3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 16 deletions.
3 changes: 2 additions & 1 deletion include/vrv/iohumdrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,8 @@ class HumdrumInput : public vrv::Input {
void setClefBasicShape(Clef *clef, hum::HTp token);
void setClefStaffLine(Clef *clef, hum::HTp token);
std::u32string cleanDegreeString(hum::HTp token);
void analyzeKeyLabels(hum::HTp starttok);
void analyzeHarmInterpretations(hum::HTp starttok);
void analyzeDegInterpretations(hum::HTp starttok);
void addHarmLabel(Harm *harm, const std::string &label);

// header related functions: ///////////////////////////////////////////
Expand Down
102 changes: 87 additions & 15 deletions src/iohumdrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,15 +824,15 @@ bool HumdrumInput::convertHumdrum()
m_mens = true;
}
else if (it->isDataType("**harm")) {
analyzeKeyLabels(it);
analyzeHarmInterpretations(it);
m_harm = true;
}
else if (it->isDataType("**deg")) {
analyzeKeyLabels(it);
analyzeDegInterpretations(it);
m_degree = true;
}
else if (it->isDataType("**degree")) {
analyzeKeyLabels(it);
analyzeDegInterpretations(it);
m_degree = true;
}
else if (it->isDataType("**rhrm")) { // **recip + **harm
Expand Down Expand Up @@ -925,10 +925,12 @@ bool HumdrumInput::convertHumdrum()

//////////////////////////////
//
// HumdrumInput::analyzeKeyLabels --
// HumdrumInput::analyzeHarmInterpretations --
// Known interpretations that affect **harm:
// *[A-Ga-g][#-]*:(dor|phr|lyd|mix|aeo|loc|ion)? == Key designation
//

void HumdrumInput::analyzeKeyLabels(hum::HTp starttok)
void HumdrumInput::analyzeHarmInterpretations(hum::HTp starttok)
{
hum::HTp current = starttok;
while (current) {
Expand Down Expand Up @@ -964,6 +966,61 @@ void HumdrumInput::analyzeKeyLabels(hum::HTp starttok)
}
}

//////////////////////////////
//
// HumdrumInput::analyzeDegInterpretations --
// Known interpretations that affect **harm:
// *[A-Ga-g][#-]*:(dor|phr|lyd|mix|aeo|loc|ion)? == Key designation
// *hat == add a hat above the scale degrees
// *Xhat == don't add a hat (default)
// *circle == add a circle around the scale degrees
// *Xcircle == don't add a circle (default)
//

void HumdrumInput::analyzeDegInterpretations(hum::HTp starttok)
{
bool hatQ = false;
bool circleQ = false;
hum::HTp keydesig = NULL;
hum::HTp current = starttok;
while (current) {
current = current->getNextToken();
if (!current) {
break;
}
if (current->isData() && !current->isNull()) {
if (hatQ) {
current->setValue("auto", "hat", 1);
}
if (circleQ) {
current->setValue("auto", "circle", 1);
}
if (keydesig) {
current->setValue("auto", "meilabel", keydesig->substr(1));
keydesig = NULL;
}
}
if (!current->isInterpretation()) {
continue;
}
if (*current == "*hat") {
hatQ = true;
}
if (*current == "*Xhat") {
hatQ = false;
}
if (*current == "*circle") {
circleQ = true;
}
if (*current == "*Xcircle") {
circleQ = false;
}
if (current->isKeyDesignation()) {
keydesig = current;
}
}
}

//////////////////////////////
//
// HumdrumInput::prepareFingerings -- Mark fingerings with explicit
Expand Down Expand Up @@ -7715,10 +7772,22 @@ void HumdrumInput::addHarmFloatsForMeasure(int startline, int endline)
rend->SetColor(ccolor);
harm->AddChild(rend);
rend->AddChild(text);
if (token->getValueInt("auto", "circle")) {
rend->SetRend(TEXTRENDITION_circle);
}
}
else {
harm->AddChild(text);
if (token->getValueInt("auto", "circle")) {
Rend *rend = new Rend();
rend->SetRend(TEXTRENDITION_circle);
harm->AddChild(rend);
harm->AddChild(text);
}
else {
harm->AddChild(text);
}
}

std::string tracktext = getTrackText(token);
harm->SetN(tracktext);

Expand Down Expand Up @@ -8163,15 +8232,18 @@ std::u32string HumdrumInput::cleanDegreeString(hum::HTp token)
if (hre.search(token, "(\\d+)")) {
int degree = hre.getMatchInt(1);
switch (degree) {
case 1: output = U"1\u0302"; break;
case 2: output = U"2\u0302"; break;
case 3: output = U"3\u0302"; break;
case 4: output = U"4\u0302"; break;
case 5: output = U"5\u0302"; break;
case 6: output = U"6\u0302"; break;
case 7: output = U"7\u0302"; break;
case 8: output = U"8\u0302"; break;
case 9: output = U"9\u0302"; break;
case 1: output = U"1"; break;
case 2: output = U"2"; break;
case 3: output = U"3"; break;
case 4: output = U"4"; break;
case 5: output = U"5"; break;
case 6: output = U"6"; break;
case 7: output = U"7"; break;
case 8: output = U"8"; break;
case 9: output = U"9"; break;
}
if (token->getValueInt("auto", "hat")) {
output += U"\u0302";
}
}

Expand Down

1 comment on commit e8f18d3

@craigsapp
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit add *hat/*Xhat and *circle/*Xcircle styling to scale degrees in **deg and **degree spine conversions in the Humdrum-to-MEI converter.

Example:

Screen Shot 2022-12-27 at 1 38 23 PM

Humdrum data:

**kern	**deg
*clefG2	*
*M4/4	*color:silver
*	*C:
=1	=1
4c	1
*	*circle
4d	2
*	*hat
4e	3
4f	4
*	*Xhat
=2	=2
4g	5
*	*Xcircle
4a	6
*	*hat
4b	7
*	*Xhat
4cc	8
==	==
*-	*-
Click to view MEI conversion of above Humdrum data.
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="https://music-encoding.org/schema/dev/mei-all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="https://music-encoding.org/schema/dev/mei-all.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<mei xmlns="http://www.music-encoding.org/ns/mei" meiversion="5.0.0-dev">
 <meiHead>
  <fileDesc>
   <titleStmt>
    <title />
   </titleStmt>
   <pubStmt />
  </fileDesc>
  <encodingDesc>
   <appInfo>
    <application isodate="2022-12-27T13:40:58" version="3.15.0-dev-1173e22">
     <name>Verovio</name>
     <p>Transcoded from Humdrum</p>
    </application>
   </appInfo>
  </encodingDesc>
  <workList>
   <work>
    <title />
   </work>
  </workList>
 </meiHead>
 <music>
  <body>
   <mdiv xml:id="maz7u91">
    <score xml:id="sv7c65p">
     <scoreDef xml:id="sdfav02">
      <staffGrp xml:id="szge3u1">
       <staffDef xml:id="staffdef-L1F1" n="1" lines="5">
        <clef xml:id="clef-L2F1" shape="G" line="2" />
        <meterSig xml:id="metersig-L3F1" count="4" unit="4" />
       </staffDef>
      </staffGrp>
     </scoreDef>
     <section xml:id="section-L1F1">
      <measure xml:id="measure-L1" n="1">
       <staff xml:id="staff-L1F1" n="1">
        <layer xml:id="layer-L1F1N1" n="1">
         <note xml:id="note-L6F1" dur="4" oct="4" pname="c" accid.ges="n" />
         <note xml:id="note-L8F1" dur="4" oct="4" pname="d" accid.ges="n" />
         <note xml:id="note-L10F1" dur="4" oct="4" pname="e" accid.ges="n" />
         <note xml:id="note-L11F1" dur="4" oct="4" pname="f" accid.ges="n" />
        </layer>
       </staff>
       <harm xml:id="harm-L6F2" type="deg" place="below" staff="1" tstamp="1.000000" n="2">
        <rend xml:id="r1822aky" color="silver">1</rend>
       </harm>
       <harm xml:id="harm-L8F2" type="deg" place="below" staff="1" tstamp="2.000000" n="2">
        <rend xml:id="ry3etae" color="silver" rend="circle">2</rend>
       </harm>
       <harm xml:id="harm-L10F2" type="deg" place="below" staff="1" tstamp="3.000000" n="2">
        <rend xml:id="rkgrex4" color="silver" rend="circle">3̂</rend>
       </harm>
       <harm xml:id="harm-L11F2" type="deg" place="below" staff="1" tstamp="4.000000" n="2">
        <rend xml:id="r2osv64" color="silver" rend="circle">4̂</rend>
       </harm>
      </measure>
      <measure xml:id="measure-L13" right="end" n="2">
       <staff xml:id="staff-L13F1N1" n="1">
        <layer xml:id="layer-L13F1N1" n="1">
         <note xml:id="note-L14F1" dur="4" oct="4" pname="g" accid.ges="n" />
         <note xml:id="note-L16F1" dur="4" oct="4" pname="a" accid.ges="n" />
         <note xml:id="note-L18F1" dur="4" oct="4" pname="b" accid.ges="n" />
         <note xml:id="note-L20F1" dur="4" oct="5" pname="c" accid.ges="n" />
        </layer>
       </staff>
       <harm xml:id="harm-L14F2" type="deg" place="below" staff="1" tstamp="1.000000" n="2">
        <rend xml:id="r13e81se" color="silver" rend="circle">5</rend>
       </harm>
       <harm xml:id="harm-L16F2" type="deg" place="below" staff="1" tstamp="2.000000" n="2">
        <rend xml:id="r1910tck" color="silver">6</rend>
       </harm>
       <harm xml:id="harm-L18F2" type="deg" place="below" staff="1" tstamp="3.000000" n="2">
        <rend xml:id="r1kkz7n0" color="silver">7̂</rend>
       </harm>
       <harm xml:id="harm-L20F2" type="deg" place="below" staff="1" tstamp="4.000000" n="2">
        <rend xml:id="r1m7eaoh" color="silver">8</rend>
       </harm>
      </measure>
     </section>
    </score>
   </mdiv>
  </body>
 </music>
</mei>

Please sign in to comment.