Skip to content

Commit 9dd57b8

Browse files
committed
Add Score spannerMap to plugin API
1 parent 9da9c63 commit 9dd57b8

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/engraving/api/v1/score.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "dom/measure.h"
2929
#include "dom/score.h"
3030
#include "dom/segment.h"
31+
#include "dom/spanner.h"
32+
#include "dom/spannermap.h"
3133
#include "dom/text.h"
3234
#include "editing/editsystemlocks.h"
3335
#include "types/typesconv.h"
@@ -39,6 +41,51 @@
3941

4042
using namespace mu::engraving::apiv1;
4143

44+
qsizetype Score::spannerListCount(QQmlListProperty<Spanner>* list)
45+
{
46+
auto* scoreWrapper = static_cast<Score*>(list->data);
47+
if (!scoreWrapper) {
48+
return 0;
49+
}
50+
51+
mu::engraving::Score* nativeScore = scoreWrapper->score();
52+
if (!nativeScore) {
53+
return 0;
54+
}
55+
56+
return static_cast<qsizetype>(nativeScore->spannerMap().map().size());
57+
}
58+
59+
Spanner* Score::spannerListAt(QQmlListProperty<Spanner>* list, qsizetype index)
60+
{
61+
auto* scoreWrapper = static_cast<Score*>(list->data);
62+
if (!scoreWrapper || index < 0) {
63+
return nullptr;
64+
}
65+
66+
mu::engraving::Score* nativeScore = scoreWrapper->score();
67+
if (!nativeScore) {
68+
return nullptr;
69+
}
70+
71+
const auto& spanMap = nativeScore->spannerMap().map();
72+
qsizetype current = 0;
73+
for (const auto& [tick, spanner] : spanMap) {
74+
UNUSED(tick);
75+
if (!spanner) {
76+
continue;
77+
}
78+
79+
if (current == index) {
80+
return qobject_cast<Spanner*>(wrap(spanner, Ownership::SCORE));
81+
}
82+
83+
++current;
84+
}
85+
86+
return nullptr;
87+
}
88+
4289
Cursor* Score::newCursor()
4390
{
4491
return new Cursor(score());
@@ -262,6 +309,15 @@ QQmlListProperty<System> Score::systems()
262309
return wrapContainerProperty<System>(this, score()->systems());
263310
}
264311

312+
//---------------------------------------------------------
313+
// Score::spanners
314+
//---------------------------------------------------------
315+
316+
QQmlListProperty<Spanner> Score::spanners()
317+
{
318+
return QQmlListProperty<Spanner>(this, this, &Score::spannerListCount, &Score::spannerListAt);
319+
}
320+
265321
//---------------------------------------------------------
266322
// Score::startCmd
267323
//---------------------------------------------------------

src/engraving/api/v1/score.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Q_MOC_INCLUDE("engraving/api/v1/selection.h")
4141
namespace mu::engraving {
4242
class InstrumentTemplate;
4343
class Selection;
44+
class Spanner;
4445
}
4546

4647
namespace mu::engraving::apiv1 {
@@ -53,6 +54,7 @@ class System;
5354
class Selection;
5455
class Score;
5556
class Staff;
57+
class Spanner;
5658

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

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

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

@@ -345,12 +350,16 @@ class Score : public apiv1::ScoreElement, public muse::Injectable
345350
QQmlListProperty<apiv1::Staff> staves();
346351
QQmlListProperty<apiv1::Page> pages();
347352
QQmlListProperty<apiv1::System> systems();
353+
QQmlListProperty<apiv1::Spanner> spanners();
348354

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

352358
private:
353359
mu::notation::INotationPtr notation() const;
354360
mu::notation::INotationUndoStackPtr undoStack() const;
361+
362+
static qsizetype spannerListCount(QQmlListProperty<Spanner>* list);
363+
static Spanner* spannerListAt(QQmlListProperty<Spanner>* list, qsizetype index);
355364
};
356365
}

0 commit comments

Comments
 (0)