Skip to content

Commit

Permalink
Add SetLiquescent()
Browse files Browse the repository at this point in the history
  • Loading branch information
yinanazhou committed Jan 8, 2024
1 parent 8c9835a commit e28d1c7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
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
66 changes: 66 additions & 0 deletions 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 @@ -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

0 comments on commit e28d1c7

Please sign in to comment.