Skip to content

Commit

Permalink
Adjust chromatic alteration display in Humdrum-to-MEI converter.
Browse files Browse the repository at this point in the history
  • Loading branch information
craigsapp committed Dec 29, 2022
1 parent 3a49fbf commit e7ee42f
Showing 1 changed file with 29 additions and 63 deletions.
92 changes: 29 additions & 63 deletions src/iohumdrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ void HumdrumInput::analyzeDegreeInterpretations(hum::HTp starttok)
bool solfQ = false;
bool dirQ = true;
bool aboveQ = false;
bool degaccQ = true;
hum::HTp keydesig = NULL;
hum::HTp current = starttok;
while (current) {
Expand All @@ -1007,6 +1008,9 @@ void HumdrumInput::analyzeDegreeInterpretations(hum::HTp starttok)
if (hatQ) {
current->setValue("auto", "hat", 1);
}
if (!degaccQ) {
current->setValue("auto", "nodegacc", 1);
}
if (circleQ) {
current->setValue("auto", "circle", 1);
}
Expand Down Expand Up @@ -1039,6 +1043,12 @@ void HumdrumInput::analyzeDegreeInterpretations(hum::HTp starttok)
if (*current == "*Xcircle") {
circleQ = false;
}
if (*current == "*acc") {
degaccQ = true;
}
if (*current == "*Xacc") {
degaccQ = false;
}
if (*current == "*solf") {
solfQ = true;
}
Expand Down Expand Up @@ -8343,7 +8353,6 @@ std::u32string HumdrumInput::cleanDegreeString(hum::HTp token, int n)
int flats = 0;
for (int i = 0; i < (int)temp.size(); i++) {
switch (temp[i]) {
case '#': sharps++; break; // Alias for +
case '+': sharps++; break;
case '-': flats++; break;
}
Expand All @@ -8364,68 +8373,6 @@ std::u32string HumdrumInput::cleanDegreeString(hum::HTp token, int n)

bool solfege = token->getValueInt("auto", "solf");

if (solfege) {
// do nothing
}
else if (sharps > 0) {
if (sharps == 1) {
output += U"\u266F";
}
else if (sharps == 2) {
output += U"\u266F\u266F";
// output += U"\u1D12A"; // double sharp
}
else if (sharps == 3) {
output += U"\u266F\u266F\u266F";
// output += U"\u1D12A\u266F";
}
else if (sharps == 4) {
output += U"\u266F\u266F\u266F\u266F";
// output += U"\u1D12A\u1D12A";
}
else if (sharps == 5) {
output += U"\u266F\u266F\u266F\u266F\u266F";
// output += U"\u1D12A\u1D12A\u266F";
}
else if (sharps == 6) {
output += U"\u266F\u266F\u266F\u266F\u266F\u266F";
// output += U"\u1D12A\u1D12A\u1D12A";
}
else {
// excessive number of sharps
output += U"?";
}
}
else if (flats > 0) {
if (flats == 1) {
output += U"\u266D";
}
else if (flats == 2) {
output += U"\u266D\u266D";
// output += U"\u1D12B"; // double flat
}
else if (flats == 3) {
output += U"\u266D\u266D\u266D";
// output += U"\u1D12B\u266D";
}
else if (flats == 4) {
output += U"\u266D\u266D\u266D\u266D";
// output += U"\u1D12B\u1D12B";
}
else if (flats == 5) {
output += U"\u266D\u266D\u266D\u266D\u266D";
// output += U"\u1D12B\u1D12B\u266D";
}
else if (flats == 6) {
output += U"\u266D\u266D\u266D\u266D\u266D\u266D";
// output += U"\u1D12B\u1D12B\u1D12B";
}
else {
// excessive number of flats
output += U"?";
}
}

hum::HumRegex hre;
if (hre.search(temp, "(\\d+)")) {
int degree = hre.getMatchInt(1);
Expand Down Expand Up @@ -8455,6 +8402,25 @@ std::u32string HumdrumInput::cleanDegreeString(hum::HTp token, int n)
}
}

int accidQ = !token->getValueInt("auto", "nodegacc");

// Add semitone adjustments
if (accidQ) {
if (solfege) {
// do nothing
}
else if (sharps > 0) {
for (int i = 0; i < sharps; i++) {
output += U"\u2191"; // up arrow
}
}
else if (flats > 0) {
for (int i = 0; i < flats; i++) {
output += U"\u2193"; // down arrow
}
}
}

return output;
}

Expand Down

1 comment on commit e7ee42f

@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 changes display of chromatic alterations in the display of chromatic alterations in **deg data conversions from Humdrum to MEI. Sharps are changed to ↑ and flats to ↓. Double arrows are used for wholetone alterations.

Example:

Screen Shot 2022-12-28 at 7 29 05 PM

**kern	**deg
*C:	*C:
*	*circle
*	*color:steelblue
=	=
!!LO:TX:a:t=*acc:color=steelblue
4c	1
4c#	1+
4c##	1++
4e	3
4e-	3-
4e--	3--
=||	=||
*	*Xacc
!!LO:TX:a:t=*Xacc:color=steelblue
4c	1
4c#	1+
4c##	1++
4e	3
4e-	3-
4e--	3--
==	==
*-	*-
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-28T19:28:34" version="3.15.0-dev-3a49fbf">
     <name>Verovio</name>
     <p>Transcoded from Humdrum</p>
    </application>
   </appInfo>
  </encodingDesc>
  <workList>
   <work>
    <title />
   </work>
  </workList>
 </meiHead>
 <music>
  <body>
   <mdiv xml:id="m1pogxkh">
    <score xml:id="ssh045m">
     <scoreDef xml:id="sc4i2tn">
      <staffGrp xml:id="s17a58nw">
       <staffDef xml:id="staffdef-L1F1" n="1" lines="5">
        <clef xml:id="cu2aoc7" shape="G" line="2" />
       </staffDef>
      </staffGrp>
     </scoreDef>
     <section xml:id="section-L1F1">
      <measure xml:id="measure-L1" right="dbl">
       <staff xml:id="staff-L1F1" n="1">
        <layer xml:id="layer-L1F1N1" n="1">
         <note xml:id="note-L7F1" dur="4" oct="4" pname="c" accid.ges="n" />
         <note xml:id="note-L8F1" dur="4" oct="4" pname="c" accid="s" />
         <note xml:id="note-L9F1" dur="4" oct="4" pname="c" accid="x" />
         <note xml:id="note-L10F1" dur="4" oct="4" pname="e" accid.ges="n" />
         <note xml:id="note-L11F1" dur="4" oct="4" pname="e" accid="f" />
         <note xml:id="note-L12F1" dur="4" oct="4" pname="e" accid="ff" />
        </layer>
       </staff>
       <dir xml:id="dir-L6F1" place="above" staff="1" tstamp="1.000000">
        <rend xml:id="rxujgfu" color="steelblue" fontstyle="normal">*acc</rend>
       </dir>
       <harm xml:id="harm-L7F2" type="deg" place="below" staff="1" tstamp="1.000000" n="2">
        <rend xml:id="rpxk41m" color="steelblue" rend="circle">1</rend>
       </harm>
       <harm xml:id="harm-L8F2" type="deg" place="below" staff="1" tstamp="2.000000" n="2">
        <rend xml:id="rhl1zz7" color="steelblue" rend="circle">1↑</rend>
       </harm>
       <harm xml:id="harm-L9F2" type="deg" place="below" staff="1" tstamp="3.000000" n="2">
        <rend xml:id="r1b8arl8" color="steelblue" rend="circle">1⇑</rend>
       </harm>
       <harm xml:id="harm-L10F2" type="deg" place="below" staff="1" tstamp="4.000000" n="2">
        <rend xml:id="r1w9vker" color="steelblue" rend="circle">3</rend>
       </harm>
       <harm xml:id="harm-L11F2" type="deg" place="below" staff="1" tstamp="5.000000" n="2">
        <rend xml:id="rxp1wmd" color="steelblue" rend="circle">3↓</rend>
       </harm>
       <harm xml:id="harm-L12F2" type="deg" place="below" staff="1" tstamp="6.000000" n="2">
        <rend xml:id="r1vkvyfv" color="steelblue" rend="circle">3⇓</rend>
       </harm>
      </measure>
      <measure xml:id="measure-L13" right="end">
       <staff xml:id="staff-L13F1N1" n="1">
        <layer xml:id="layer-L13F1N1" n="1">
         <note xml:id="note-L16F1" dur="4" oct="4" pname="c" accid.ges="n" />
         <note xml:id="note-L17F1" dur="4" oct="4" pname="c" accid="s" />
         <note xml:id="note-L18F1" dur="4" oct="4" pname="c" accid="x" />
         <note xml:id="note-L19F1" dur="4" oct="4" pname="e" accid.ges="n" />
         <note xml:id="note-L20F1" dur="4" oct="4" pname="e" accid="f" />
         <note xml:id="note-L21F1" dur="4" oct="4" pname="e" accid="ff" />
        </layer>
       </staff>
       <dir xml:id="dir-L15F1" place="above" staff="1" tstamp="1.000000">
        <rend xml:id="r14cg9pk" color="steelblue" fontstyle="normal">*Xacc</rend>
       </dir>
       <harm xml:id="harm-L16F2" type="deg" place="below" staff="1" tstamp="1.000000" n="2">
        <rend xml:id="r1x5hwy8" color="steelblue" rend="circle">1</rend>
       </harm>
       <harm xml:id="harm-L17F2" type="deg" place="below" staff="1" tstamp="2.000000" n="2">
        <rend xml:id="ryig3r2" color="steelblue" rend="circle">1</rend>
       </harm>
       <harm xml:id="harm-L18F2" type="deg" place="below" staff="1" tstamp="3.000000" n="2">
        <rend xml:id="r11rrcwv" color="steelblue" rend="circle">1</rend>
       </harm>
       <harm xml:id="harm-L19F2" type="deg" place="below" staff="1" tstamp="4.000000" n="2">
        <rend xml:id="r6dvabs" color="steelblue" rend="circle">3</rend>
       </harm>
       <harm xml:id="harm-L20F2" type="deg" place="below" staff="1" tstamp="5.000000" n="2">
        <rend xml:id="rzfadat" color="steelblue" rend="circle">3</rend>
       </harm>
       <harm xml:id="harm-L21F2" type="deg" place="below" staff="1" tstamp="6.000000" n="2">
        <rend xml:id="r1htlic" color="steelblue" rend="circle">3</rend>
       </harm>
      </measure>
     </section>
    </score>
   </mdiv>
  </body>
 </music>
</mei>

Using # instead of + is now disallowed since the standard **deg definition does not use #.

The interpretations *acc/*Xacc can be used to show/hide chromatic alterations of the scale degrees (default is to show them). The second measure in the example hides them.

The location of the display of alterations is also moved from in front of the scale degree to behind them.

Please sign in to comment.