Skip to content

Conversation

@mike-spa
Copy link
Contributor

@mike-spa mike-spa commented Nov 6, 2025

Prompted from this consideration, I took a closer look at the functions in scoretree.cpp, namely scanParent and scanChildren. As far as I could see, they were introduced for some score tree visualization feature back in version 3, but as far as I'm aware that feature doesn't exist in version 4. Everything about this is quite weird, because the parent and child relationships sometimes don't follow the true hierarchy of our model (ChordRests collect spanners among their children, Spanner collect SpannerSegment even though the parent of a SpannerSegment is always the System, scanParent sometimes returns an item that isn't the parent...). Most of these functions are either stale or are a copy of the corresponding scanElements method. The "source of truth" is obviously scanElements, cause that's what we use to determine what is drawn on screen.

This PR:

  • Removes all the scanParent and scanChildren functions, moving all the relevant functionality to scanElements
  • Introduces EngravingObject::getChildren, which collects the list of children using scanElements
  • Refactors scanElements using std::function instead of the old C-style function pointers. This makes everything nicer, especially avoiding all the void* pointers.
  • Removes from scanElements all the logic that had to do with showing or not showing the item on screen. The whole point of something like scanElement is that it doesn't know what func will do, so putting that logic in scanElement is an antipattern. Deciding whether or not to collect an element should be decided inside func itself.

@mike-spa mike-spa force-pushed the cleanupScanParentAndScanChildren branch from bd9297a to 84175c0 Compare November 6, 2025 16:59
--level;
}

void EngravingElementsProvider::dumpTreeTree(const mu::engraving::EngravingObject* obj, int& level)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's either delete these methods or fix them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkTree and dumpTree above also look like they're unused


if (r) {
assert(mode != Asyncable::Mode::SetOnce && "callback is already set");
//assert(mode != Asyncable::Mode::SetOnce && "callback is already set");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should perhaps not have been committed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yes it shouldn't have. But I will point out that I was getting a ton of failures from it (including when runnign the vtest scripts locally)


std::vector<EngravingItem*> NotationElements::filterElements(const FilterElementsOptions* elementsOptions) const
{
ElementPattern* pattern = constructElementPattern(elementsOptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it now also doesn't have to be a pointer anymore (that's leaked at the end of the function...)

}

return children;
EngravingItem::scanElements(func);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe StaffTextBase instead of EngravingItem, just to prevent surprises in the future

//---------------------------------------------------------

void Score::scanElementsInRange(void* data, void (* func)(void*, EngravingItem*), bool all)
void Score::scanElementsInRange(std::function<void(EngravingItem*)> func, bool includeInvisible)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning about includeInvisible being unused

#include "mscore.h"
#include "score.h"
#include "staff.h"
#include "stafflines.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these used?

}

static void findTextByType(void* data, mu::engraving::EngravingItem* element)
static void findTextByType(std::pair<TextStyleType, QStringList*>* typeStringsData, mu::engraving::EngravingItem* element)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void findTextByType(std::pair<TextStyleType, QStringList*>* typeStringsData, mu::engraving::EngravingItem* element)
static void findTextByType(TextStyleType textStyleType, QStringList& strings, mu::engraving::EngravingItem* element)

const EngravingObjectList& children() const { return m_children; }

// Score Tree functions for scan function
friend class EngravingElementsProvider;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also remove this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants