Elements property on segment

• Jun 12, 2025 - 13:40

Hello,

being rather new to MuseScore and in particular to writing plugins, I wanted a simple means to traverse a score along measures, segments and elements BasicMuse. According to segment.h, "A segment holds all vertical aligned staff elements." Would it be not easily be possible to add a:

const std::vector<EngravingItem*>& elements() const

and make it available in the plugin API? Ideally, I would then like to filter as needed:

chords = segment.elements.filter(element => element.type === Muse.ElementType.CHORD);

and process the result.

BTW: segment.h also says: "Segments are typed and contain only Elements of the same type.". Is there a reason why Segment is not implemented as a generic class, e.g.:

template <typename T>
class Segment : public EngravingItem {
private:
    std::vector<T*> m_elements; // List to store elements of type T (derived from EngravingItem)
public:
    const std::vector<EngravingItem*>& elements() const { return m_elements } 
};

And then, when needed instantiate a new Segment for example.


Comments

Do you still have an unanswered question? Please log in first to post your question.