Skip to content
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

Adjust position when insert new glyphs #131

Merged
merged 7 commits into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/editortoolkit_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,11 +881,12 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
= (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);
const int offsetX = (int)(noteWidth / 2);

// Set up facsimile
zone->SetUlx(ulx);
zone->SetUlx(ulx - offsetX);
zone->SetUly(uly);
zone->SetLrx(ulx + noteWidth);
zone->SetLrx(ulx + offsetX);
zone->SetLry(uly + noteHeight);

// add syl bounding box if Facs
Expand Down Expand Up @@ -995,9 +996,9 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in

// Apply offset due to rotate
newUly += (newUlx - ulx) * tan(-staff->GetDrawingRotate() * M_PI / 180.0);
newZone->SetUlx(newUlx);
newZone->SetUlx(newUlx - offsetX);
newZone->SetUly(newUly);
newZone->SetLrx(newUlx + noteWidth);
newZone->SetLrx(newUlx + offsetX);
newZone->SetLry(newUly + noteHeight);

newNc->AttachZone(newZone);
Expand Down Expand Up @@ -1027,14 +1028,21 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
Clef *clef = new Clef();
data_CLEFSHAPE clefShape = CLEFSHAPE_NONE;

const int staffSize = m_doc->GetDrawingDoubleUnit(staff->m_drawingStaffSize);
int offsetR, offsetL;

for (auto it = attributes.begin(); it != attributes.end(); ++it) {
if (it->first == "shape") {
if (it->second == "C") {
clefShape = CLEFSHAPE_C;
offsetR = (int)(staffSize / NOTE_WIDTH_TO_STAFF_SIZE_RATIO / 2);
offsetL = offsetR;
break;
}
else if (it->second == "F") {
clefShape = CLEFSHAPE_F;
offsetR = 0;
offsetL = (int)(staffSize / NOTE_WIDTH_TO_STAFF_SIZE_RATIO / 2);
break;
}
}
Expand All @@ -1048,17 +1056,16 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
return false;
}
clef->SetShape(clefShape);
const int staffSize = m_doc->GetDrawingDoubleUnit(staff->m_drawingStaffSize);
int yDiff = -staff->GetDrawingY() + uly;
yDiff += ((ulx - staff->GetZone()->GetUlx()))
* tan(-staff->GetDrawingRotate() * M_PI / 180.0); // Subtract distance due to rotate.
int clefLine = staff->m_drawingLines - round((double)yDiff / (double)staffSize);
clef->SetLine(clefLine);

Zone *zone = new Zone();
zone->SetUlx(ulx);
zone->SetUlx(ulx - offsetR);
zone->SetUly(uly);
zone->SetLrx(ulx + staffSize / NOTE_WIDTH_TO_STAFF_SIZE_RATIO);
zone->SetLrx(ulx + offsetL);
zone->SetLry(uly + staffSize / NOTE_HEIGHT_TO_STAFF_SIZE_RATIO);
clef->AttachZone(zone);
Surface *surface = dynamic_cast<Surface *>(facsimile->FindDescendantByType(SURFACE));
Expand Down Expand Up @@ -1104,13 +1111,14 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
= (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);
const int offsetX = (int)(noteWidth / 4);

ulx -= noteWidth / 2;
uly -= noteHeight / 2;

zone->SetUlx(ulx);
zone->SetUlx(ulx + offsetX);
zone->SetUly(uly);
zone->SetLrx(ulx + noteWidth);
zone->SetLrx(ulx + noteWidth + offsetX);
zone->SetLry(uly + noteHeight);
layer->ReorderByXPos();
if (!AdjustPitchFromPosition(custos)) {
Expand Down Expand Up @@ -1157,13 +1165,14 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
= (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);
const int offsetX = (int)(noteWidth / 2);

ulx -= noteWidth / 2;
uly -= noteHeight / 2;

zone->SetUlx(ulx);
zone->SetUlx(ulx + offsetX);
zone->SetUly(uly);
zone->SetLrx(ulx + noteWidth);
zone->SetLrx(ulx + noteWidth + offsetX);
zone->SetLry(uly + noteHeight);
layer->ReorderByXPos();

Expand Down Expand Up @@ -1221,13 +1230,14 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
= (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);
const int offsetX = (int)(noteWidth / 2);

ulx -= noteWidth / 2;
uly -= noteHeight / 2;

zone->SetUlx(ulx);
zone->SetUlx(ulx + offsetX);
zone->SetUly(uly);
zone->SetLrx(ulx + noteWidth);
zone->SetLrx(ulx + noteWidth + offsetX);
zone->SetLry(uly + noteHeight);
layer->ReorderByXPos();

Expand Down