Skip to content

Commit

Permalink
Introduce new accidental placement algorithm and options
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-spa committed Apr 18, 2024
1 parent 5c3b7da commit 7bfe8d1
Show file tree
Hide file tree
Showing 39 changed files with 1,992 additions and 226 deletions.
10 changes: 10 additions & 0 deletions src/engraving/dom/accidental.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ double Accidental::subtype2centOffset(AccidentalType st)
return ACC_LIST[int(st)].centOffset;
}

int Accidental::line() const
{
return note()->line();
}

//---------------------------------------------------------
// name2subtype
//---------------------------------------------------------
Expand Down Expand Up @@ -437,6 +442,7 @@ PropertyValue Accidental::getProperty(Pid propertyId) const
case Pid::SMALL: return m_isSmall;
case Pid::ACCIDENTAL_BRACKET: return int(bracket());
case Pid::ACCIDENTAL_ROLE: return role();
case Pid::ACCIDENTAL_STACKING_ORDER_OFFSET: return stackingOrderOffset();
default:
return EngravingItem::getProperty(propertyId);
}
Expand All @@ -453,6 +459,7 @@ PropertyValue Accidental::propertyDefault(Pid propertyId) const
case Pid::SMALL: return false;
case Pid::ACCIDENTAL_BRACKET: return int(AccidentalBracket::NONE);
case Pid::ACCIDENTAL_ROLE: return AccidentalRole::AUTO;
case Pid::ACCIDENTAL_STACKING_ORDER_OFFSET: return 0;
default:
return EngravingItem::propertyDefault(propertyId);
}
Expand All @@ -477,6 +484,9 @@ bool Accidental::setProperty(Pid propertyId, const PropertyValue& v)
case Pid::ACCIDENTAL_ROLE:
m_role = v.value<AccidentalRole>();
break;
case Pid::ACCIDENTAL_STACKING_ORDER_OFFSET:
setStackingOrderOffset(v.toInt());
break;
default:
return EngravingItem::setProperty(propertyId, v);
}
Expand Down
12 changes: 12 additions & 0 deletions src/engraving/dom/accidental.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Accidental final : public EngravingItem
OBJECT_ALLOCATOR(engraving, Accidental)
DECLARE_CLASSOF(ElementType::ACCIDENTAL)

M_PROPERTY2(int, stackingOrderOffset, setStackingOrderOffset, 0)

public:

Accidental* clone() const override { return new Accidental(*this); }
Expand Down Expand Up @@ -109,6 +111,10 @@ class Accidental final : public EngravingItem
static bool isMicrotonal(AccidentalType t) { return t > AccidentalType::FLAT3; }
static double subtype2centOffset(AccidentalType);

int stackingOrder() const { return ldata()->stackingNumber + _stackingOrderOffset; }

int line() const;

String accessibleInfo() const override;

void computeMag();
Expand All @@ -124,6 +130,12 @@ class Accidental final : public EngravingItem

std::vector<Sym> syms;

ld_field<int> stackingNumber = { "[Accidental] stackingNumber", 0 };
ld_field<int> verticalSubgroup = { "[Accidental] verticalSubgroup", 0 };
ld_field<int> column = { "[Accidental] column", 0 };
ld_field<std::vector<Accidental*> > octaves = { "[Accidental] octaves", std::vector<Accidental*> {} };
ld_field<std::vector<Accidental*> > seconds = { "[Accidental] seconds", std::vector<Accidental*> {} };

bool isValid() const override { return EngravingItem::LayoutData::isValid() && !syms.empty(); }
};
DECLARE_LAYOUTDATA_METHODS(Accidental)
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ static constexpr PropertyMetaData propertyList[] = {
{ Pid::TEMPO_FOLLOW_TEXT, true, "followText", P_TYPE::BOOL, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "following text") },
{ Pid::ACCIDENTAL_BRACKET, false, "bracket", P_TYPE::INT, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "bracket") },
{ Pid::ACCIDENTAL_TYPE, true, "subtype", P_TYPE::INT, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "type") },
{ Pid::ACCIDENTAL_STACKING_ORDER_OFFSET, true, "stackingOrderOffset", P_TYPE::INT, PropertyGroup::NONE, DUMMY_QT_TR_NOOP("propertyName", "stacking order offset") },
{ Pid::NUMERATOR_STRING, false, "textN", P_TYPE::STRING, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "numerator string") },
{ Pid::DENOMINATOR_STRING, false, "textD", P_TYPE::STRING, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "denominator string") },
{ Pid::FBPREFIX, false, "prefix", P_TYPE::INT, PropertyGroup::APPEARANCE, DUMMY_QT_TR_NOOP("propertyName", "prefix") },
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ enum class Pid {
TEMPO_FOLLOW_TEXT,
ACCIDENTAL_BRACKET,
ACCIDENTAL_TYPE,
ACCIDENTAL_STACKING_ORDER_OFFSET,
NUMERATOR_STRING,
DENOMINATOR_STRING,
FBPREFIX, // used for FiguredBassItem
Expand Down
20 changes: 14 additions & 6 deletions src/engraving/infrastructure/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,19 @@ bool Shape::contains(const PointF& p) const
// intersects
//---------------------------------------------------------

bool Shape::intersects(const RectF& rr) const
bool Shape::intersects(const RectF& rr, double horClearance, double vertClearance) const
{
for (const RectF& r : m_elements) {
if (r.intersects(rr)) {
return true;
if (RealIsNull(horClearance) && RealIsNull(vertClearance)) {
for (const RectF& r : m_elements) {
if (r.intersects(rr)) {
return true;
}
}
} else {
for (const RectF& r : m_elements) {
if (r.intersects(rr.adjusted(-horClearance, -vertClearance, horClearance, vertClearance))) {
return true;
}
}
}
return false;
Expand All @@ -508,10 +516,10 @@ bool Shape::intersects(const RectF& rr) const
// intersects
//---------------------------------------------------------

bool Shape::intersects(const Shape& other) const
bool Shape::intersects(const Shape& other, double horClearance, double vertClearance) const
{
for (const RectF& r : other.m_elements) {
if (intersects(r)) {
if (intersects(r, horClearance, vertClearance)) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/infrastructure/shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ class Shape
double leftMostEdgeAtHeight(double yAbove, double yBelow) const;

bool contains(const PointF&) const;
bool intersects(const RectF& rr) const;
bool intersects(const Shape&) const;
bool intersects(const RectF& rr, double horClearance = 0.0, double vertClearance = 0.0) const;
bool intersects(const Shape& other, double horClearance = 0.0, double vertClearance = 0.0) const;
bool clearsVertically(const Shape& a) const;

void paint(muse::draw::Painter& painter) const;
Expand Down
Loading

0 comments on commit 7bfe8d1

Please sign in to comment.