Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/engraving/api/v1/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "dom/measure.h"
#include "dom/score.h"
#include "dom/segment.h"
#include "dom/spanner.h"
#include "dom/spannermap.h"
#include "dom/text.h"
#include "editing/editsystemlocks.h"
#include "types/typesconv.h"
Expand All @@ -39,6 +41,51 @@

using namespace mu::engraving::apiv1;

qsizetype Score::spannerListCount(QQmlListProperty<Spanner>* list)
{
auto* scoreWrapper = static_cast<Score*>(list->data);
if (!scoreWrapper) {
return 0;
}

mu::engraving::Score* nativeScore = scoreWrapper->score();
if (!nativeScore) {
return 0;
}

return static_cast<qsizetype>(nativeScore->spannerMap().map().size());
}

Spanner* Score::spannerListAt(QQmlListProperty<Spanner>* list, qsizetype index)
{
auto* scoreWrapper = static_cast<Score*>(list->data);
if (!scoreWrapper || index < 0) {
return nullptr;
}

mu::engraving::Score* nativeScore = scoreWrapper->score();
if (!nativeScore) {
return nullptr;
}

const auto& spanMap = nativeScore->spannerMap().map();
qsizetype current = 0;
for (const auto& [tick, spanner] : spanMap) {
UNUSED(tick);
if (!spanner) {
continue;
}

if (current == index) {
return qobject_cast<Spanner*>(wrap(spanner, Ownership::SCORE));
}

++current;
}

return nullptr;
}

Cursor* Score::newCursor()
{
return new Cursor(score());
Expand Down Expand Up @@ -262,6 +309,15 @@ QQmlListProperty<System> Score::systems()
return wrapContainerProperty<System>(this, score()->systems());
}

//---------------------------------------------------------
// Score::spanners
//---------------------------------------------------------

QQmlListProperty<Spanner> Score::spanners()
{
return QQmlListProperty<Spanner>(this, this, &Score::spannerListCount, &Score::spannerListAt);
}

//---------------------------------------------------------
// Score::startCmd
//---------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions src/engraving/api/v1/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Q_MOC_INCLUDE("engraving/api/v1/selection.h")
namespace mu::engraving {
class InstrumentTemplate;
class Selection;
class Spanner;
}

namespace mu::engraving::apiv1 {
Expand All @@ -53,6 +54,7 @@ class System;
class Selection;
class Score;
class Staff;
class Spanner;

extern Selection* selectionWrap(mu::engraving::Selection* select);

Expand Down Expand Up @@ -165,6 +167,9 @@ class Score : public apiv1::ScoreElement, public muse::Injectable
/// List of systems in this score.
/// \since MuseScore 4.6
Q_PROPERTY(QQmlListProperty<apiv1::System> systems READ systems)
/// List of score-level spanners.
/// \since MuseScore 4.7
Q_PROPERTY(QQmlListProperty<apiv1::Spanner> spanners READ spanners)

muse::Inject<mu::context::IGlobalContext> context = { this };

Expand Down Expand Up @@ -345,12 +350,16 @@ class Score : public apiv1::ScoreElement, public muse::Injectable
QQmlListProperty<apiv1::Staff> staves();
QQmlListProperty<apiv1::Page> pages();
QQmlListProperty<apiv1::System> systems();
QQmlListProperty<apiv1::Spanner> spanners();

static const mu::engraving::InstrumentTemplate* instrTemplateFromName(const QString& name); // used by PluginAPI::newScore()
/// \endcond

private:
mu::notation::INotationPtr notation() const;
mu::notation::INotationUndoStackPtr undoStack() const;

static qsizetype spannerListCount(QQmlListProperty<Spanner>* list);
static Spanner* spannerListAt(QQmlListProperty<Spanner>* list, qsizetype index);
};
}
2 changes: 1 addition & 1 deletion src/engraving/dom/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class Note final : public EngravingItem
EngravingItem* prevInEl(EngravingItem* e);
EngravingItem* nextElement() override;
EngravingItem* prevElement() override;
virtual EngravingItem* lastElementBeforeSegment();
EngravingItem* lastElementBeforeSegment();
EngravingItem* nextSegmentElement() override;
EngravingItem* prevSegmentElement() override;

Expand Down
Loading