Skip to content

Commit

Permalink
Don't allow multiple staff type changes on the same measure
Browse files Browse the repository at this point in the history
  • Loading branch information
mathesoncalum committed Jan 31, 2025
1 parent dccaa95 commit ea85076
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/engraving/dom/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,9 @@ bool Measure::acceptDrop(EditData& data) const
viewer->setDropRectangle(canvasBoundingRect());
return true;
case ActionIconType::STAFF_TYPE_CHANGE:
if (!canAddStaffTypeChange(staffIdx)) {
return false;
}
viewer->setDropRectangle(staffRect);
return true;
case ActionIconType::SYSTEM_LOCK:
Expand Down Expand Up @@ -1736,6 +1739,9 @@ EngravingItem* Measure::drop(EditData& data)
score()->insertMeasure(ElementType::MEASURE, this);
break;
case ActionIconType::STAFF_TYPE_CHANGE: {
if (!canAddStaffTypeChange(staffIdx)) {
return nullptr;
}
EngravingItem* stc = Factory::createStaffTypeChange(this);
stc->setParent(this);
stc->setTrack(staffIdx * VOICES);
Expand Down Expand Up @@ -3475,6 +3481,21 @@ bool Measure::canAddStringTunings(staff_idx_t staffIdx) const
return !alreadyHasStringTunings;
}

bool Measure::canAddStaffTypeChange(staff_idx_t staffIdx) const
{
for (const EngravingObject* child : scanChildren()) {
if (!child || !child->isStaffTypeChange()) {
continue;
}
const StaffTypeChange* stc = toStaffTypeChange(child);
if (stc->staffIdx() == staffIdx) {
// Staff already has a StaffTypeChange at this measure...
return false;
}
}
return true;
}

Fraction Measure::maxTicks() const
{
Segment* s = first();
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class Measure final : public MeasureBase
void respaceSegments();

bool canAddStringTunings(staff_idx_t staffIdx) const;
bool canAddStaffTypeChange(staff_idx_t staffIdx) const;

private:

Expand Down
8 changes: 6 additions & 2 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2516,9 +2516,13 @@ bool NotationInteraction::dragMeasureAnchorElement(const PointF& pos)
RectF measureRect = targetMeasure->staffPageBoundingRect(staffIdx);
measureRect.adjust(page->x(), page->y(), page->x(), page->y());
m_dropData.ed.pos = measureRect.center();
setAnchorLines({ LineF(pos, measureRect.topLeft()) });

return targetMeasure->acceptDrop(m_dropData.ed);
const bool dropAccepted = targetMeasure->acceptDrop(m_dropData.ed);
if (dropAccepted) {
setAnchorLines({ LineF(pos, measureRect.topLeft()) });
}

return dropAccepted;
}
dropElem->score()->addRefresh(dropElem->canvasBoundingRect());
setDropTarget(nullptr);
Expand Down

0 comments on commit ea85076

Please sign in to comment.