Skip to content

Commit 761f632

Browse files
committed
Automation - implement basic UI/rendering using Polyline
1 parent 96c743c commit 761f632

File tree

10 files changed

+257
-26
lines changed

10 files changed

+257
-26
lines changed

src/notation/inotationautomation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class INotationAutomation
3333
virtual bool isAutomationModeEnabled() const = 0;
3434
virtual void setAutomationModeEnabled(bool enabled) = 0;
3535
virtual muse::async::Notification automationModeEnabledChanged() const = 0;
36+
37+
virtual QVariant automationLinesData() const = 0;
38+
virtual muse::async::Notification automationLinesDataChanged() const = 0;
3639
};
3740

3841
using INotationAutomationPtr = std::shared_ptr<INotationAutomation>;

src/notation/internal/masternotation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ MasterNotation::MasterNotation(project::INotationProject* project, const muse::m
8686
m_notationPlayback = std::make_shared<NotationPlaybackStub>();
8787
#endif
8888

89-
m_notationAutomation = std::make_shared<NotationAutomation>();
89+
m_notationAutomation = std::make_shared<NotationAutomation>(this, m_notationChanged);
9090

9191
m_parts->partsChanged().onNotify(this, [this]() {
9292
notifyAboutNotationChanged();

src/notation/internal/notationautomation.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@
2121
*/
2222

2323
#include "notationautomation.h"
24+
#include "notationtypes.h"
2425

2526
using namespace mu::notation;
2627

28+
NotationAutomation::NotationAutomation(IGetScore* getScore,
29+
muse::async::Channel<muse::RectF> notationChanged)
30+
: m_getScore(getScore), m_notationChanged(notationChanged)
31+
{
32+
}
33+
2734
bool NotationAutomation::isAutomationModeEnabled() const
2835
{
2936
return m_isAutomationModeEnabled;
@@ -43,3 +50,56 @@ muse::async::Notification NotationAutomation::automationModeEnabledChanged() con
4350
{
4451
return m_automationModeEnabledChanged;
4552
}
53+
54+
QVariant NotationAutomation::automationLinesData() const
55+
{
56+
// TODO: Entire method is a dummy - here we'll construct from actual automation data...
57+
QVariantList dummyAutomationData;
58+
59+
// Hack - using second system because first is normally the title...
60+
const System* systemOne = m_getScore ? m_getScore->score()->systems().at(1) : nullptr;
61+
if (!systemOne) {
62+
return QVariantList();
63+
}
64+
65+
const muse::PointF systemOnePos = systemOne->canvasPos();
66+
for (const SysStaff* staff : systemOne->staves()) {
67+
QVariantMap lineData;
68+
69+
const muse::RectF staffRect = staff->bbox().translated(systemOnePos);
70+
71+
lineData["x"] = staffRect.x();
72+
lineData["y"] = staffRect.y();
73+
lineData["width"] = staffRect.width();
74+
lineData["height"] = staffRect.height();
75+
76+
QVariantList points;
77+
78+
// Dummy points...
79+
QVariantMap point1;
80+
point1["x"] = 0.10;
81+
point1["y"] = 0.50;
82+
points << point1;
83+
84+
QVariantMap point2;
85+
point2["x"] = 0.50;
86+
point2["y"] = 0.10;
87+
points << point2;
88+
89+
QVariantMap point3;
90+
point3["x"] = 0.66;
91+
point3["y"] = 0.90;
92+
points << point3;
93+
94+
lineData["points"] = points;
95+
96+
dummyAutomationData << lineData;
97+
}
98+
99+
return dummyAutomationData;
100+
}
101+
102+
muse::async::Notification NotationAutomation::automationLinesDataChanged() const
103+
{
104+
return m_automationLinesDataChanged;
105+
}

src/notation/internal/notationautomation.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,30 @@
2323

2424
#include "../inotationautomation.h"
2525

26+
#include "igetscore.h"
27+
#include "async/channel.h"
28+
#include "draw/types/geometry.h"
29+
2630
namespace mu::notation {
2731
class NotationAutomation : public INotationAutomation
2832
{
2933
public:
34+
NotationAutomation(IGetScore* getScore, muse::async::Channel<muse::RectF> notationChanged);
35+
3036
bool isAutomationModeEnabled() const override;
3137
void setAutomationModeEnabled(bool enabled) override;
3238
muse::async::Notification automationModeEnabledChanged() const override;
3339

40+
QVariant automationLinesData() const override;
41+
muse::async::Notification automationLinesDataChanged() const override; // TODO: probably a channel specifying indices
42+
3443
private:
44+
IGetScore* m_getScore = nullptr;
45+
muse::async::Channel<muse::RectF> m_notationChanged;
46+
3547
bool m_isAutomationModeEnabled = false;
3648
muse::async::Notification m_automationModeEnabledChanged;
49+
50+
muse::async::Notification m_automationLinesDataChanged;
3751
};
3852
}

src/notation/notationtypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
namespace mu::notation {
6464
using Page = mu::engraving::Page;
6565
using System = mu::engraving::System;
66+
using SysStaff = mu::engraving::SysStaff;
6667
using EngravingItem = mu::engraving::EngravingItem;
6768
using ElementType = mu::engraving::ElementType;
6869
using PropertyValue = engraving::PropertyValue;

src/notationscene/qml/MuseScore/NotationScene/NotationView.qml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,31 @@ FocusScope {
221221
}
222222

223223
Loader {
224+
id: automationOverlayLoader
225+
224226
active: notationView.automationMode
225227
anchors.fill: notationView
226228

227229
sourceComponent: AutomationOverlay {
230+
id: automationOverlay
231+
228232
viewMatrix: notationView.matrix
233+
234+
Connections {
235+
target: automationOverlayLoader
236+
function onLoaded() {
237+
const data = notationView.automationLinesData
238+
automationOverlay.initAutomationLinesData(data)
239+
}
240+
}
241+
242+
Connections {
243+
target: notationView
244+
function onAutomationLinesDataChanged() {
245+
const data = notationView.automationLinesData
246+
automationOverlay.initAutomationLinesData(data)
247+
}
248+
}
229249
}
230250
}
231251

src/notationscene/qml/MuseScore/NotationScene/abstractnotationpaintview.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,15 @@ void AbstractNotationPaintView::onLoadNotation(INotationPtr)
340340
});
341341

342342
// FIXME: only un-/re-subscribe when master notation changes
343-
m_notation->masterNotation()->automation()->automationModeEnabledChanged().onNotify(this, [this]() {
343+
notationAutomation()->automationModeEnabledChanged().onNotify(this, [this]() {
344344
scheduleRedraw();
345345
emit automationModeChanged();
346346
});
347347

348+
notationAutomation()->automationLinesDataChanged().onNotify(this, [this]() {
349+
emit automationLinesDataChanged();
350+
});
351+
348352
if (isMainView()) {
349353
connect(this, &QQuickPaintedItem::focusChanged, this, [this](bool focused) {
350354
if (notation()) {
@@ -375,6 +379,7 @@ void AbstractNotationPaintView::onLoadNotation(INotationPtr)
375379
emit verticalScrollChanged();
376380
emit viewportChanged();
377381
emit automationModeChanged();
382+
emit automationLinesDataChanged();
378383
}
379384

380385
void AbstractNotationPaintView::onUnloadNotation(INotationPtr)
@@ -391,7 +396,8 @@ void AbstractNotationPaintView::onUnloadNotation(INotationPtr)
391396
interaction->shadowNoteChanged().disconnect(this);
392397
notationPlayback()->loopBoundariesChanged().disconnect(this);
393398
m_notation->viewModeChanged().disconnect(this);
394-
m_notation->masterNotation()->automation()->automationModeEnabledChanged().disconnect(this);
399+
notationAutomation()->automationModeEnabledChanged().disconnect(this);
400+
notationAutomation()->automationLinesDataChanged().disconnect(this);
395401

396402
if (isMainView()) {
397403
disconnect(this, &QQuickPaintedItem::focusChanged, this, nullptr);
@@ -558,6 +564,12 @@ INotationSelectionPtr AbstractNotationPaintView::notationSelection() const
558564
return notationInteraction() ? notationInteraction()->selection() : nullptr;
559565
}
560566

567+
INotationAutomationPtr AbstractNotationPaintView::notationAutomation() const
568+
{
569+
const IMasterNotationPtr masterNotation = m_notation ? m_notation->masterNotation() : nullptr;
570+
return masterNotation ? masterNotation->automation() : nullptr;
571+
}
572+
561573
void AbstractNotationPaintView::onNoteInputStateChanged()
562574
{
563575
TRACEFUNC;
@@ -694,7 +706,7 @@ void AbstractNotationPaintView::paint(QPainter* qp)
694706
painter->setWorldTransform(m_matrix * guiScalingCompensation);
695707

696708
const bool isPrinting = publishMode() || m_inputController->readonly();
697-
const bool isAutomation = notation()->masterNotation()->automation()->isAutomationModeEnabled();
709+
const bool isAutomation = automationMode();
698710
notation()->painting()->paintView(painter, toLogical(rect), isPrinting, isAutomation);
699711

700712
const INotationNoteInputPtr noteInput = notationNoteInput();
@@ -848,6 +860,11 @@ QRectF AbstractNotationPaintView::viewport_property() const
848860
return viewport().toQRectF();
849861
}
850862

863+
QVariant AbstractNotationPaintView::automationLinesData() const
864+
{
865+
return notationAutomation() ? notationAutomation()->automationLinesData() : QVariant();
866+
}
867+
851868
RectF AbstractNotationPaintView::notationContentRect() const
852869
{
853870
TRACEFUNC;
@@ -1639,12 +1656,7 @@ void AbstractNotationPaintView::setPublishMode(bool arg)
16391656

16401657
bool AbstractNotationPaintView::automationMode() const
16411658
{
1642-
const IMasterNotationPtr masterNotation = m_notation ? m_notation->masterNotation() : nullptr;
1643-
const INotationAutomationPtr automation = masterNotation ? masterNotation->automation() : nullptr;
1644-
if (!automation) {
1645-
return false;
1646-
}
1647-
return automation->isAutomationModeEnabled();
1659+
return notationAutomation() ? notationAutomation()->isAutomationModeEnabled() : false;
16481660
}
16491661

16501662
bool AbstractNotationPaintView::isMainView() const

src/notationscene/qml/MuseScore/NotationScene/abstractnotationpaintview.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class AbstractNotationPaintView : public muse::uicomponents::QuickPaintedView, p
6464
Q_PROPERTY(QVariant matrix READ matrix NOTIFY matrixChanged)
6565
Q_PROPERTY(QRectF viewport READ viewport_property NOTIFY viewportChanged)
6666

67+
Q_PROPERTY(QVariant automationLinesData READ automationLinesData NOTIFY automationLinesDataChanged)
68+
6769
Q_PROPERTY(bool publishMode READ publishMode WRITE setPublishMode NOTIFY publishModeChanged)
6870
Q_PROPERTY(bool automationMode READ automationMode NOTIFY automationModeChanged)
6971

@@ -149,6 +151,8 @@ class AbstractNotationPaintView : public muse::uicomponents::QuickPaintedView, p
149151
muse::RectF viewport() const;
150152
QRectF viewport_property() const;
151153

154+
QVariant automationLinesData() const;
155+
152156
bool publishMode() const;
153157
void setPublishMode(bool arg);
154158

@@ -174,6 +178,8 @@ class AbstractNotationPaintView : public muse::uicomponents::QuickPaintedView, p
174178
void publishModeChanged();
175179
void automationModeChanged();
176180

181+
void automationLinesDataChanged();
182+
177183
void activeFocusRequested();
178184

179185
void isMainViewChanged(bool isMainView);
@@ -212,6 +218,7 @@ protected slots:
212218
INotationElementsPtr notationElements() const;
213219
INotationStylePtr notationStyle() const;
214220
INotationSelectionPtr notationSelection() const;
221+
INotationAutomationPtr notationAutomation() const;
215222

216223
void clear();
217224
void initBackground();

0 commit comments

Comments
 (0)