Skip to content

Commit

Permalink
Merge pull request #127 from DDMAL/write-liq-fix
Browse files Browse the repository at this point in the history
Write liquescent via nc@curve
  • Loading branch information
yinanazhou authored Mar 14, 2024
2 parents 9f0c4e7 + 02ab823 commit 944f191
Show file tree
Hide file tree
Showing 7 changed files with 471 additions and 322 deletions.
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
1 change: 1 addition & 0 deletions include/vrv/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ class View {
///@{
void DrawDivLine(DeviceContext *dc, LayerElement *element, Layer *layer, Staff *staff, Measure *measure);
void DrawSyllable(DeviceContext *dc, LayerElement *element, Layer *layer, Staff *staff, Measure *measure);
void DrawLiquescent(DeviceContext *dc, LayerElement *element, Layer *layer, Staff *staff, Measure *measure);
void DrawNc(DeviceContext *dc, LayerElement *element, Layer *layer, Staff *staff, Measure *measure);
void DrawNeume(DeviceContext *dc, LayerElement *element, Layer *layer, Staff *staff, Measure *measure);
///@}
Expand Down
70 changes: 69 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 @@ -948,7 +955,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 @@ -958,6 +964,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 @@ -1996,6 +2003,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 @@ -3859,6 +3910,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 Expand Up @@ -4088,6 +4154,8 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef)
const int staffSize = m_doc->GetDrawingUnit(staff->m_drawingStaffSize);

for (auto it = pitchedChildren.begin(); it != pitchedChildren.end(); ++it) {
if ((*it)->Is(LIQUESCENT)) continue;

FacsimileInterface *fi = (*it)->GetFacsimileInterface();
if (fi == NULL || !fi->HasFacs()) {
LogError("Could not adjust pitch: child %s does not have facsimile data", (*it)->GetID().c_str());
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
5 changes: 4 additions & 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 All @@ -139,6 +139,9 @@ void View::DrawLayerElement(DeviceContext *dc, LayerElement *element, Layer *lay
else if (element->Is(LIGATURE)) {
this->DrawLigature(dc, element, layer, staff, measure);
}
else if (element->Is(LIQUESCENT)) {
this->DrawLiquescent(dc, element, layer, staff, measure);
}
else if (element->Is(MENSUR)) {
this->DrawMensur(dc, element, layer, staff, measure);
}
Expand Down
137 changes: 106 additions & 31 deletions src/view_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,110 @@ void View::DrawSyllable(DeviceContext *dc, LayerElement *element, Layer *layer,
dc->EndGraphic(element, this);
}

void View::DrawLiquescent(DeviceContext *dc, LayerElement *element, Layer *layer, Staff *staff, Measure *measure)
{
assert(dc);
assert(layer);
assert(staff);
assert(measure);

Liquescent *liquescent = dynamic_cast<Liquescent *>(element);
assert(liquescent);

struct drawingParams {
wchar_t fontNo = SMUFL_E990_chantPunctum;
wchar_t fontNoLiq[5] = {};
float xOffsetLiq[5] = { 0, 0, 0, 0, 0 };
float yOffsetLiq[5] = { 0, 0, 0, 0, 0 };
};
std::vector<drawingParams> params;
params.push_back(drawingParams());

dc->StartGraphic(element, "", element->GetID());

Clef *clef = layer->GetClef(element);
int staffSize = m_doc->GetDrawingDoubleUnit(staff->m_drawingStaffSize);
int staffLineNumber = staff->m_drawingLines;
int clefLine = clef->GetLine();

Nc *nc = dynamic_cast<Nc *>(element->GetParent());
assert(liquescent);

if (nc->GetCurve() == curvatureDirection_CURVE_c) {
params.at(0).fontNoLiq[0] = SMUFL_E9BE_chantConnectingLineAsc3rd;
params.at(0).fontNoLiq[1] = SMUFL_EB92_staffPosRaise3;
params.at(0).fontNoLiq[2] = SMUFL_E995_chantAuctumDesc;
params.at(0).fontNoLiq[3] = SMUFL_EB91_staffPosRaise2;
params.at(0).fontNoLiq[4] = SMUFL_E9BE_chantConnectingLineAsc3rd;
params.at(0).xOffsetLiq[4] = 0.8;
params.at(0).yOffsetLiq[0] = -1.5;
params.at(0).yOffsetLiq[4] = -1.75;
}
else if (nc->GetCurve() == curvatureDirection_CURVE_a) {
params.at(0).fontNoLiq[0] = SMUFL_E9BE_chantConnectingLineAsc3rd;
params.at(0).fontNoLiq[1] = SMUFL_EB98_staffPosLower1;
params.at(0).fontNoLiq[2] = SMUFL_E994_chantAuctumAsc;
params.at(0).fontNoLiq[3] = SMUFL_EB99_staffPosLower2;
params.at(0).fontNoLiq[4] = SMUFL_E9BE_chantConnectingLineAsc3rd;
params.at(0).xOffsetLiq[4] = 0.8;
params.at(0).yOffsetLiq[0] = 0.5;
params.at(0).yOffsetLiq[4] = 0.75;
}

const int noteHeight
= (int)(m_doc->GetDrawingDoubleUnit(staff->m_drawingStaffSize) / NOTE_HEIGHT_TO_STAFF_SIZE_RATIO);
const int noteWidth
= (int)(m_doc->GetDrawingDoubleUnit(staff->m_drawingStaffSize) / NOTE_WIDTH_TO_STAFF_SIZE_RATIO);
int noteY, noteX;
int yValue;
if (nc->HasFacs() && m_doc->IsFacs()) {
noteY = ToLogicalY(staff->GetDrawingY());
noteX = nc->GetDrawingX();
}
else {
noteX = element->GetDrawingX();
noteY = element->GetDrawingY();
}

// Calculating proper y offset based on pname, clef, staff, and staff rotate
int clefYPosition = noteY - (staffSize * (staffLineNumber - clefLine));
int pitchOffset = 0;

// The default octave = 3, but the actual octave is calculated by
// taking into account the displacement of the clef
int clefOctave = 3;
if (clef->GetDis() && clef->GetDisPlace()) {
clefOctave += (clef->GetDisPlace() == STAFFREL_basic_above ? 1 : -1) * (clef->GetDis() / 7);
}
int octaveOffset = (nc->GetOct() - clefOctave) * ((staffSize / 2) * 7);
int rotateOffset;
if (m_doc->IsFacs() && (staff->GetDrawingRotate() != 0)) {
double deg = staff->GetDrawingRotate();
int xDiff = noteX - staff->GetDrawingX();
rotateOffset = int(xDiff * tan(deg * M_PI / 180.0));
}
else {
rotateOffset = 0;
}

if (clef->GetShape() == CLEFSHAPE_C) {
pitchOffset = (nc->GetPname() - 1) * (staffSize / 2);
}
else if (clef->GetShape() == CLEFSHAPE_F) {
pitchOffset = (nc->GetPname() - 4) * (staffSize / 2);
}
yValue = clefYPosition + pitchOffset + octaveOffset - rotateOffset;

for (auto it = params.begin(); it != params.end(); it++) {
for (int i = 0; i < static_cast<int>(sizeof(params.at(0).fontNoLiq)); i++) {
DrawSmuflCode(dc, noteX + it->xOffsetLiq[i] * noteWidth, yValue + it->yOffsetLiq[i] * noteHeight,
it->fontNoLiq[i], staff->m_drawingStaffSize, false, true);
}
}

dc->EndGraphic(element, this);
}

void View::DrawNc(DeviceContext *dc, LayerElement *element, Layer *layer, Staff *staff, Measure *measure)
{
assert(dc);
Expand All @@ -76,8 +180,6 @@ void View::DrawNc(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
wchar_t fontNoLiq[5] = {};
float xOffset = 0;
float yOffset = 0;
float xOffsetLiq[5] = { 0, 0, 0, 0, 0 };
float yOffsetLiq[5] = { 0, 0, 0, 0, 0 };
};
std::vector<drawingParams> params;
params.push_back(drawingParams());
Expand Down Expand Up @@ -177,27 +279,6 @@ void View::DrawNc(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
params.at(0).fontNo = SMUFL_E997_chantPunctumVirgaReversed;
}

else if (nc->GetCurve() == curvatureDirection_CURVE_c) {
params.at(0).fontNoLiq[0] = SMUFL_E9BE_chantConnectingLineAsc3rd;
params.at(0).fontNoLiq[1] = SMUFL_EB92_staffPosRaise3;
params.at(0).fontNoLiq[2] = SMUFL_E995_chantAuctumDesc;
params.at(0).fontNoLiq[3] = SMUFL_EB91_staffPosRaise2;
params.at(0).fontNoLiq[4] = SMUFL_E9BE_chantConnectingLineAsc3rd;
params.at(0).xOffsetLiq[4] = 0.8;
params.at(0).yOffsetLiq[0] = -1.5;
params.at(0).yOffsetLiq[4] = -1.75;
}
else if (nc->GetCurve() == curvatureDirection_CURVE_a) {
params.at(0).fontNoLiq[0] = SMUFL_E9BE_chantConnectingLineAsc3rd;
params.at(0).fontNoLiq[1] = SMUFL_EB98_staffPosLower1;
params.at(0).fontNoLiq[2] = SMUFL_E994_chantAuctumAsc;
params.at(0).fontNoLiq[3] = SMUFL_EB99_staffPosLower2;
params.at(0).fontNoLiq[4] = SMUFL_E9BE_chantConnectingLineAsc3rd;
params.at(0).xOffsetLiq[4] = 0.8;
params.at(0).yOffsetLiq[0] = 0.5;
params.at(0).yOffsetLiq[4] = 0.75;
}

const int noteHeight
= (int)(m_doc->GetDrawingDoubleUnit(staff->m_drawingStaffSize) / NOTE_HEIGHT_TO_STAFF_SIZE_RATIO);
const int noteWidth
Expand Down Expand Up @@ -251,14 +332,8 @@ void View::DrawNc(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
yValue = clefYPosition + pitchOffset + octaveOffset - rotateOffset;
}

for (auto it = params.begin(); it != params.end(); it++) {
if (nc->GetCurve() == curvatureDirection_CURVE_a || nc->GetCurve() == curvatureDirection_CURVE_c) {
for (int i = 0; i < static_cast<int>(sizeof(params.at(0).fontNoLiq)); i++) {
DrawSmuflCode(dc, noteX + it->xOffsetLiq[i] * noteWidth, yValue + it->yOffsetLiq[i] * noteHeight,
it->fontNoLiq[i], staff->m_drawingStaffSize, false, true);
}
}
else {
if (!nc->HasCurve()) {
for (auto it = params.begin(); it != params.end(); it++) {
DrawSmuflCode(dc, noteX + it->xOffset * noteWidth, yValue + it->yOffset * noteHeight, it->fontNo,
staff->m_drawingStaffSize, false, true);
}
Expand Down

0 comments on commit 944f191

Please sign in to comment.