[engraving] added check condition for articulation layout

This commit is contained in:
Igor Korsukov 2023-09-08 15:39:59 +03:00
parent 5c2c8c6676
commit f076735c5a
6 changed files with 72 additions and 11 deletions

View File

@ -61,7 +61,6 @@ Articulation::Articulation(ChordRest* parent, ElementType type)
m_symId = SymId::noSym;
m_anchor = ArticulationAnchor::AUTO;
m_direction = DirectionV::AUTO;
m_up = true;
m_ornamentStyle = OrnamentStyle::DEFAULT;
m_playArticulation = true;
@ -116,7 +115,16 @@ int Articulation::subtype() const
void Articulation::setUp(bool val)
{
m_up = val;
Articulation::LayoutData* ldata = mutLayoutData();
ldata->setUp(val);
//! NOTE member of Articulation m_symId - this is `given` data
//! member of LayoutData m_symId - this is layout data
//! I would not like to change the `given` data here, but they are changing for backward compatibility
//! Even better, I wouldnt want symId to be `given` data,
//! it would be better if there was some type,
//! and from it we would already figure out how (with what symbol) to display it
bool dup = m_direction == DirectionV::AUTO ? val : m_direction == DirectionV::UP;
String s = String::fromAscii(SymNames::nameForSymId(m_symId).ascii());
if (s.endsWith(!dup ? u"Above" : u"Below")) {
@ -132,6 +140,8 @@ void Articulation::setUp(bool val)
m_symId = sym;
}
}
ldata->setSymId(m_symId);
}
//---------------------------------------------------------

View File

@ -136,8 +136,6 @@ public:
void resetProperty(Pid id) override;
Sid getPropertyStyle(Pid id) const override;
bool up() const { return m_up; }
void setUp(bool val);
void setDirection(DirectionV d) { m_direction = d; }
DirectionV direction() const { return m_direction; }
@ -178,9 +176,53 @@ public:
struct LayoutData : public EngravingItem::LayoutData
{
void reset() override
{
EngravingItem::LayoutData::reset();
m_up.reset();
m_symId.reset();
}
bool isSetUp() const { return m_up.has_value(); }
bool up(LD_ACCESS mode = LD_ACCESS::CHECK) const
{
if (!m_up.has_value()) {
if (mode == LD_ACCESS::CHECK) {
//LOGE() << "BAD ACCESS to bbox (not set)";
}
return true;
}
return m_up.value();
}
void setUp(bool val) { m_up = std::make_optional<bool>(val); }
bool isSetSymId() const { return m_symId.has_value(); }
SymId symId(LD_ACCESS mode = LD_ACCESS::CHECK) const
{
if (!m_symId.has_value()) {
if (mode == LD_ACCESS::CHECK) {
//LOGE() << "BAD ACCESS to bbox (not set)";
}
return SymId::noSym;
}
return m_symId.value();
}
void setSymId(SymId val) { m_symId = std::make_optional<SymId>(val); }
private:
std::optional<bool> m_up;
std::optional<SymId> m_symId;
};
DECLARE_LAYOUTDATA_METHODS(Articulation);
void setUp(bool val);
//! --- DEPRECATED ---
bool up() const { return layoutData()->up(); }
//! ------------------
protected:
friend class mu::engraving::Factory;
Articulation(ChordRest* parent, ElementType type = ElementType::ARTICULATION);
@ -209,7 +251,6 @@ private:
ArticulationAnchor m_anchor = ArticulationAnchor::AUTO;
bool m_up = true;
OrnamentStyle m_ornamentStyle = OrnamentStyle::DEFAULT; // for use in ornaments such as trill
bool m_playArticulation = true;

View File

@ -495,7 +495,7 @@ public:
Autoplace autoplace;
void reset()
virtual void reset()
{
m_bbox.reset();
}

View File

@ -36,6 +36,7 @@ void PassLayoutIndependentItems::doRun(Score* score, LayoutContext& ctx)
void PassLayoutIndependentItems::scan(EngravingItem* item, LayoutContext& ctx)
{
//! NOTE These items are independent
switch (item->type()) {
case ElementType::ACCIDENTAL:
case ElementType::ACTION_ICON:

View File

@ -155,6 +155,17 @@
#include "tremololayout.h"
#include "tupletlayout.h"
#ifdef MUE_ENABLE_ENGRAVING_LD_ACCESS
#define LD_CONDITION(val, name) \
if (!val) { \
LOGE() << "BAD ACCESS, not set" << name; \
} \
#else
#define LD_CONDITION(val, name)
#endif
using namespace mu::draw;
using namespace mu::engraving;
using namespace mu::engraving::rtti;
@ -617,7 +628,9 @@ void TLayout::layout(const Articulation* item, Articulation::LayoutData* ldata)
RectF bbox;
if (item->textType() == ArticulationTextType::NO_TEXT) {
bbox = item->symBbox(item->symId());
//! NOTE Must already be set previously
LD_CONDITION(ldata->isSetSymId(), "symId");
bbox = item->symBbox(ldata->symId());
} else {
Font scaledFont(item->font());
scaledFont.setPointSizeF(item->font().pointSizeF() * item->magS());

View File

@ -7,12 +7,8 @@
#include "importexport/guitarpro/guitarpromodule.h"
#include "global/async/asyncable.h"
int main(int argc, char* argv[])
{
mu::async::Asyncable a;
mu::modularity::ioc()->registerExport<mu::draw::IFontProvider>("test", new mu::draw::FontProviderStub());
mu::engraving::compat::ScoreAccess::createMasterScore();