Skip to content

Write liquescent via nc@curve #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 14, 2024
576 changes: 287 additions & 289 deletions fonts/poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions include/vrv/editortoolkit_neume.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class EditorToolkitNeume : public EditorToolkit {
bool Set(std::string elementId, std::string attrType, std::string attrValue);
bool SetText(std::string elementId, const std::string &text);
bool SetClef(std::string elementId, std::string shape);
bool SetLiquescent(std::string elementId, std::string shape);
bool Split(std::string elementId, int x);
bool SplitNeume(std::string elementId, std::string ncId);
bool Remove(std::string elementId);
Expand Down Expand Up @@ -80,6 +81,7 @@ class EditorToolkitNeume : public EditorToolkit {
bool ParseSetAction(jsonxx::Object param, std::string *elementId, std::string *attrType, std::string *attrValue);
bool ParseSetTextAction(jsonxx::Object param, std::string *elementId, std::string *text);
bool ParseSetClefAction(jsonxx::Object param, std::string *elementId, std::string *shape);
bool ParseSetLiquescentAction(jsonxx::Object param, std::string *elementId, std::string *shape);
bool ParseSplitAction(jsonxx::Object param, std::string *elementId, int *x);
bool ParseSplitNeumeAction(jsonxx::Object param, std::string *elementId, std::string *ncId);
bool ParseRemoveAction(jsonxx::Object param, std::string *elementId);
Expand Down
68 changes: 67 additions & 1 deletion src/editortoolkit_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ bool EditorToolkitNeume::ParseEditorAction(const std::string &json_editorAction)
}
LogWarning("Could not parse the set clef action");
}
else if (action == "setLiquescent") {
std::string elementId, curve;
if (this->ParseSetLiquescentAction(json.get<jsonxx::Object>("param"), &elementId, &curve)) {
return this->SetLiquescent(elementId, curve);
}
LogWarning("Could not parse the set liquescent action");
}
else if (action == "remove") {
std::string elementId;
if (this->ParseRemoveAction(json.get<jsonxx::Object>("param"), &elementId)) {
Expand Down Expand Up @@ -947,7 +954,6 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
contour = it->second;
}
else if (it->first == "curve") {
Liquescent *liquescent = new Liquescent();
curvatureDirection_CURVE curve = curvatureDirection_CURVE_NONE;
if (it->second == "a") {
curve = curvatureDirection_CURVE_a;
Expand All @@ -957,6 +963,7 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
curve = curvatureDirection_CURVE_c;
nc->SetCurve(curve);
}
Liquescent *liquescent = new Liquescent();
nc->AddChild(liquescent);
}
}
Expand Down Expand Up @@ -1986,6 +1993,50 @@ bool EditorToolkitNeume::SetClef(std::string elementId, std::string shape)
return true;
}

bool EditorToolkitNeume::SetLiquescent(std::string elementId, std::string curve)
{
if (!m_doc->GetDrawingPage()) {
LogError("Could not get the drawing page.");
m_editInfo.import("status", "FAILURE");
m_editInfo.import("message", "Could not get the drawing page.");
return false;
}

Nc *nc = vrv_cast<Nc *>(m_doc->GetDrawingPage()->FindDescendantByID(elementId));
assert(nc);
bool hasLiquscent = nc->GetChildCount();

if (curve == "a") {
curvatureDirection_CURVE curve = curvatureDirection_CURVE_a;
nc->SetCurve(curve);
if (!hasLiquscent) {
Liquescent *liquescent = new Liquescent();
nc->AddChild(liquescent);
}
}
else if (curve == "c") {
curvatureDirection_CURVE curve = curvatureDirection_CURVE_c;
nc->SetCurve(curve);
if (!hasLiquscent) {
Liquescent *liquescent = new Liquescent();
nc->AddChild(liquescent);
}
}
else {
// For unset curve
curvatureDirection_CURVE curve = curvatureDirection_CURVE_NONE;
nc->SetCurve(curve);
if (hasLiquscent) {
Liquescent *liquescent = vrv_cast<Liquescent *>(nc->FindDescendantByType(LIQUESCENT));
nc->DeleteChild(liquescent);
}
}

m_editInfo.import("status", "OK");
m_editInfo.import("message", "");
return true;
}

bool EditorToolkitNeume::Split(std::string elementId, int x)
{
if (!m_doc->GetDrawingPage()) {
Expand Down Expand Up @@ -3845,6 +3896,21 @@ bool EditorToolkitNeume::ParseSetClefAction(jsonxx::Object param, std::string *e
return true;
}

bool EditorToolkitNeume::ParseSetLiquescentAction(jsonxx::Object param, std::string *elementId, std::string *curve)
{
if (!param.has<jsonxx::String>("elementId")) {
LogWarning("Could not parse 'elementId'");
return false;
}
*elementId = param.get<jsonxx::String>("elementId");
if (!param.has<jsonxx::String>("curve")) {
LogWarning("Could not parse 'curve'");
return false;
}
*curve = param.get<jsonxx::String>("curve");
return true;
}

bool EditorToolkitNeume::ParseRemoveAction(jsonxx::Object param, std::string *elementId)
{
if (!param.has<jsonxx::String>("elementId")) return false;
Expand Down
2 changes: 2 additions & 0 deletions src/iomei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2702,6 +2702,7 @@ void MEIOutput::WriteNc(pugi::xml_node currentNode, Nc *nc)
this->WritePitchInterface(currentNode, nc);
this->WritePositionInterface(currentNode, nc);
nc->WriteColor(currentNode);
nc->WriteCurvatureDirection(currentNode);
nc->WriteIntervalMelodic(currentNode);
nc->WriteNcForm(currentNode);
}
Expand Down Expand Up @@ -6797,6 +6798,7 @@ bool MEIInput::ReadNc(Object *parent, pugi::xml_node nc)
this->ReadPitchInterface(nc, vrvNc);
this->ReadPositionInterface(nc, vrvNc);
vrvNc->ReadColor(nc);
vrvNc->ReadCurvatureDirection(nc);
vrvNc->ReadIntervalMelodic(nc);
vrvNc->ReadNcForm(nc);

Expand Down
2 changes: 1 addition & 1 deletion src/view_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void View::DrawLayerElement(DeviceContext *dc, LayerElement *element, Layer *lay
this->DrawCustos(dc, element, layer, staff, measure);
}
else if (element->Is(DIVLINE)) {
DrawDivLine(dc, element, layer, staff, measure);
this->DrawDivLine(dc, element, layer, staff, measure);
}
else if (element->Is(DOT)) {
this->DrawDot(dc, element, layer, staff, measure);
Expand Down
8 changes: 5 additions & 3 deletions src/view_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void View::DrawNc(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
params.at(0).fontNo = SMUFL_E997_chantPunctumVirgaReversed;
}

else if (nc->GetCurve() == curvatureDirection_CURVE_c) {
else if (nc->GetCurve() == curvatureDirection_CURVE_c && nc->FindDescendantByType(LIQUESCENT)) {
params.at(0).fontNoLiq[0] = SMUFL_E9BE_chantConnectingLineAsc3rd;
params.at(0).fontNoLiq[1] = SMUFL_EB92_staffPosRaise3;
params.at(0).fontNoLiq[2] = SMUFL_E995_chantAuctumDesc;
Expand All @@ -187,7 +187,7 @@ void View::DrawNc(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
params.at(0).yOffsetLiq[0] = -1.5;
params.at(0).yOffsetLiq[4] = -1.75;
}
else if (nc->GetCurve() == curvatureDirection_CURVE_a) {
else if (nc->GetCurve() == curvatureDirection_CURVE_a && nc->FindDescendantByType(LIQUESCENT)) {
params.at(0).fontNoLiq[0] = SMUFL_E9BE_chantConnectingLineAsc3rd;
params.at(0).fontNoLiq[1] = SMUFL_EB98_staffPosLower1;
params.at(0).fontNoLiq[2] = SMUFL_E994_chantAuctumAsc;
Expand Down Expand Up @@ -274,7 +274,9 @@ void View::DrawNc(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
}

// Draw the children
this->DrawLayerChildren(dc, nc, layer, staff, measure);
if (!nc->FindDescendantByType(LIQUESCENT)) {
Copy link
Member

Choose a reason for hiding this comment

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

Normally we always render child elements individually. So if the encoding is:

<nc>
  <liquescent/>
</nc>

We expect the liquescent to be drawn in a call to DrawLayerChildren so the SVG will be

<g class="nc">
  <g class="liquescent"/>
</g>

This is important if you have editorial markup:

<nc>
  <add>
     <liquescent/>
   </add>
</nc>

Which then becomes:

<g class="nc">
  <g class="add">
    <g class="liquescent"/>
  <g/>
</g>

Which allows (for example) to highlight what has been added. This would be missing with your implementation because <liquescent> drawing is happening in nc drawing.

this->DrawLayerChildren(dc, nc, layer, staff, measure);
}

dc->EndGraphic(element, this);
}
Expand Down