Skip to content

Commit

Permalink
Adding bold and italic font stylings to harm data in Humdrum-to-MEI c…
Browse files Browse the repository at this point in the history
…onverter.
  • Loading branch information
craigsapp committed Dec 31, 2022
1 parent 6887ca9 commit eedbc09
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 36 deletions.
2 changes: 2 additions & 0 deletions include/vrv/iohumdrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ class HumdrumInput : public vrv::Input {
void addPlicaDown(Note *note);
void setLayoutSlurDirection(Slur *slur, hum::HTp token);
void setFontStyle(Rend *rend, const string &fontstyle);
void setFontWeight(Rend *rend, const std::string &fontweight);
void importVerovioOptions(Doc *doc);
void adjustChordNoteDurations(Chord *chord, std::vector<Note *> &notes, std::vector<string> &tstrings);
void adjustChordNoteDuration(Note *note, hum::HumNum hdur, int dur, int dots, hum::HumNum chorddur,
Expand Down Expand Up @@ -801,6 +802,7 @@ class HumdrumInput : public vrv::Input {
void addHarmLabel(Harm *harm, const std::string &label);
std::u32string getMoveableDoName(int degree, int semitones, int minorQ);
void setFontsizeForHarm(Harm *harm, const std::string &fontsize);
void setFontStyleForHarm(Harm *harm, const std::string &style);

// header related functions: ///////////////////////////////////////////
void createHeader();
Expand Down
200 changes: 164 additions & 36 deletions src/iohumdrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,18 @@ void HumdrumInput::analyzeHarmInterpretations(hum::HTp starttok)

void HumdrumInput::analyzeDegreeInterpretations(hum::HTp starttok)
{
bool hatQ = false;
bool aboveQ = false;
bool arrowQ = true;
bool boldQ = false;
bool italicQ = false;
bool circleQ = false;
bool degaccQ = true;
bool dirQ = true;
bool hatQ = false;
bool minorQ = false;
bool solfQ = false;
bool dirQ = true;
bool aboveQ = false;
bool degaccQ = true;
std::string fontsize;

hum::HTp keydesig = NULL;
hum::HTp current = starttok;
while (current) {
Expand All @@ -996,79 +1000,111 @@ void HumdrumInput::analyzeDegreeInterpretations(hum::HTp starttok)
}
if (current->isData() && !current->isNull()) {
if (aboveQ) {
// display scale degrees above the staff
current->setValue("auto", "above", 1);
}
if (minorQ) {
current->setValue("auto", "minor", 1);
if (arrowQ) {
// display chromatic alterations as up/down arrows,
// but only inform tokens that contain an alteration
if ((current->find('+') != std::string::npos) || (current->find('-') != std::string::npos)
|| (current->find('n') != std::string::npos)) {
current->setValue("auto", "arrow", 1);
}
}
if (solfQ) {
current->setValue("auto", "solf", 1);
if (boldQ) {
// show scale degree in a bold style
current->setValue("auto", "bold", 1);
}
if (hatQ) {
current->setValue("auto", "hat", 1);
if (circleQ) {
// show scale degree inside of a circle
current->setValue("auto", "circle", 1);
}
if (!degaccQ) {
// hide chromatic alterations
current->setValue("auto", "nodegacc", 1);
}
if (circleQ) {
current->setValue("auto", "circle", 1);
}
if (!dirQ) {
// do not show the melodic approach direction
current->setValue("auto", "Xdir", 1);
}
if (!fontsize.empty()) {
// set the size of the scale degree
current->setValue("auto", "fontsize", fontsize);
}
if (hatQ) {
// display a hat on top of the scale degrees
current->setValue("auto", "hat", 1);
}
if (italicQ) {
// show scale degree in an italic style
current->setValue("auto", "italic", 1);
}
if (keydesig) {
// add key designation as a label on the next
// scale degree found in the data
current->setValue("auto", "meilabel", keydesig->substr(1));
keydesig = NULL;
}
if (minorQ) {
// scale degrees are for a minor key
current->setValue("auto", "minor", 1);
}
if (solfQ) {
// display scale degrees as moveable do
current->setValue("auto", "solf", 1);
}
}
if (!current->isInterpretation()) {
continue;
}
if (*current == "*above") {
aboveQ = true;
}
else if (*current == "*acc") {
degaccQ = true;
}
else if (*current == "*Xacc") {
degaccQ = false;
}
else if (*current == "*arrow") {
arrowQ = true;
}
else if (*current == "*Xarrow") {
arrowQ = false;
}
else if (*current == "*below") {
aboveQ = false;
}
else if (*current == "*hat") {
hatQ = true;
else if (*current == "*bold") {
boldQ = true;
}
else if (*current == "*Xhat") {
hatQ = false;
else if (*current == "*Xbold") {
boldQ = false;
}
else if (*current == "*circle") {
circleQ = true;
}
else if (*current == "*Xcircle") {
circleQ = false;
}
else if (*current == "*acc") {
degaccQ = true;
}
else if (*current == "*Xacc") {
degaccQ = false;
}
else if (*current == "*solf") {
solfQ = true;
}
else if (*current == "*Xsolf") {
solfQ = false;
}
else if (*current == "*dir") {
dirQ = true;
}
else if (*current == "*Xdir") {
dirQ = false;
}
else if (current->compare(0, 4, "*fs:") == 0) {
fontsize = current->substr(4);
if (fontsize == "normal") {
fontsize.clear();
}
}
else if (*current == "*hat") {
hatQ = true;
}
else if (*current == "*Xhat") {
hatQ = false;
}
else if (*current == "*italic") {
italicQ = true;
}
else if (*current == "*Xitalic") {
italicQ = false;
}
else if (current->isKeyDesignation()) {
keydesig = current;
char letter = current->at(1);
Expand All @@ -1083,6 +1119,12 @@ void HumdrumInput::analyzeDegreeInterpretations(hum::HTp starttok)
minorQ = false;
}
}
else if (*current == "*solf") {
solfQ = true;
}
else if (*current == "*Xsolf") {
solfQ = false;
}
}
}

Expand Down Expand Up @@ -7777,7 +7819,7 @@ void HumdrumInput::addStringNumbersForMeasure(int startline, int endline)

//////////////////////////////
//
// HumdrumInput::addHarmFloatsForMeasure --
// HumdrumInput::addHarmFloatsForMeasure -- Does not handle chords in **deg yet.
//

void HumdrumInput::addHarmFloatsForMeasure(int startline, int endline)
Expand Down Expand Up @@ -8012,11 +8054,97 @@ void HumdrumInput::addHarmFloatsForMeasure(int startline, int endline)
setFontsizeForHarm(harm, fontsize);
}

int boldQ = token->getValueInt("auto", "bold");
if (boldQ) {
setFontStyleForHarm(harm, "bold");
}
int italicQ = token->getValueInt("auto", "italic");
if (italicQ) {
setFontStyleForHarm(harm, "italic");
}

setLocationId(harm, token);
}
}
}

//////////////////////////////
//
// HumdrumInput::setFontStyleFormHarm -- Add italic and/or bold font styling to harm data.
// If there is more than one child, wrap all of them in a new rend with the font
// style. Also do this if the only child is not a rend. If there is a single
// rend, then apply the styling directly to that rend.
//

void HumdrumInput::setFontStyleForHarm(Harm *harm, const std::string &style)
{
int childcount = harm->GetChildCount();
Object *child = NULL;
bool makeRendQ = false;
if (childcount == 0) {
return;
}
else if (childcount != 1) {
makeRendQ = true;
}
else {
// If the only child is a rend, then set the style of that rend.
// If the only child is not a rend, then create a new rend and
// have it adopt the child.
child = harm->GetChild(0);
if (!child) {
return;
}
std::string childname = child->GetClassName();
if (childname == "Rend") {
if (style == "bold") {
setFontWeight((Rend *)child, style);
}
else if (style == "italic") {
setFontStyle((Rend *)child, style);
}
return;
}
else {
makeRendQ = true;
}
}

if (!makeRendQ) {
return;
}

// Create a new rend to insert between harm and its children,
// and then set the fontsize for the new rend.
Rend *newrend = new Rend();

// Transfer the children of harm to newrend:
for (int i = 0; i < (int)childcount; i++) {
Object *obj = harm->Relinquish(i);
if (obj) {
newrend->AddChild(obj);
}
}
harm->ClearRelinquishedChildren();
harm->AddChild(newrend);
if (style == "bold") {
setFontWeight(newrend, style);
}
else if (style == "italic") {
setFontStyle(newrend, style);
}
}

//////////////////////////////
//
// HumdrumInput::setFontWeight --
//

void HumdrumInput::setFontWeight(Rend *rend, const std::string &fontweight)
{
rend->SetFontweight(rend->AttTypography::StrToFontweight(fontweight));
}

//////////////////////////////
//
// HumdrumInput::setFontsizeForHarm -- Add rend@fontsize to harm data. If there is more than
Expand Down

1 comment on commit eedbc09

@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 adds bold and italic stylings to <harm> data in the Humdrum-to-MEI converter.

Example:

Screen Shot 2022-12-30 at 8 38 03 PM

Humdrum data:

**kern	**deg
*clefG2	*
*M4/4	*
=1	=1
4c	1
4d	2
*	*bold
4e	3
4f	4
=2	=2
*	*italic
4g	5
*	*Xbold
4a	6
4b	7
*	*Xitalic
4c	1
=	=
*-	*-
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-30T20:26:25" version="3.15.0-dev-6887ca9">
     <name>Verovio</name>
     <p>Transcoded from Humdrum</p>
    </application>
   </appInfo>
  </encodingDesc>
  <workList>
   <work>
    <title />
   </work>
  </workList>
 </meiHead>
 <music>
  <body>
   <mdiv xml:id="mqifgya">
    <score xml:id="s1fgsmcf">
     <scoreDef xml:id="sr6pi5">
      <staffGrp xml:id="s1koqx5f">
       <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-L5F1" dur="4" oct="4" pname="c" accid.ges="n" />
         <note xml:id="note-L6F1" dur="4" oct="4" pname="d" accid.ges="n" />
         <note xml:id="note-L8F1" dur="4" oct="4" pname="e" accid.ges="n" />
         <note xml:id="note-L9F1" dur="4" oct="4" pname="f" accid.ges="n" />
        </layer>
       </staff>
       <harm xml:id="harm-L5F2" type="deg" place="below" staff="1" tstamp="1.000000" n="2">1</harm>
       <harm xml:id="harm-L6F2" type="deg" place="below" staff="1" tstamp="2.000000" n="2">2</harm>
       <harm xml:id="harm-L8F2" type="deg" place="below" staff="1" tstamp="3.000000" n="2">
        <rend xml:id="rciyhyq" fontweight="bold">3</rend>
       </harm>
       <harm xml:id="harm-L9F2" type="deg" place="below" staff="1" tstamp="4.000000" n="2">
        <rend xml:id="r1ic2rgb" fontweight="bold">4</rend>
       </harm>
      </measure>
      <measure xml:id="measure-L10" n="2">
       <staff xml:id="staff-L10F1N1" n="1">
        <layer xml:id="layer-L10F1N1" n="1">
         <note xml:id="note-L12F1" dur="4" oct="4" pname="g" accid.ges="n" />
         <note xml:id="note-L14F1" dur="4" oct="4" pname="a" accid.ges="n" />
         <note xml:id="note-L15F1" dur="4" oct="4" pname="b" accid.ges="n" />
         <note xml:id="note-L17F1" dur="4" oct="4" pname="c" accid.ges="n" />
        </layer>
       </staff>
       <harm xml:id="harm-L12F2" type="deg" place="below" staff="1" tstamp="1.000000" n="2">
        <rend xml:id="r63aalk" fontstyle="italic" fontweight="bold">5</rend>
       </harm>
       <harm xml:id="harm-L14F2" type="deg" place="below" staff="1" tstamp="2.000000" n="2">
        <rend xml:id="rrjudb0" fontstyle="italic">6</rend>
       </harm>
       <harm xml:id="harm-L15F2" type="deg" place="below" staff="1" tstamp="3.000000" n="2">
        <rend xml:id="r4wj4jw" fontstyle="italic">7</rend>
       </harm>
       <harm xml:id="harm-L17F2" type="deg" place="below" staff="1" tstamp="4.000000" n="2">1</harm>
      </measure>
     </section>
    </score>
   </mdiv>
  </body>
 </music>
</mei>

Please sign in to comment.