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
60 changes: 60 additions & 0 deletions src/engraving/api/v1/qmlpluginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@

#include "notation/inotation.h"
#include "notation/inotationelements.h" // IWYU pragma: keep
#include "notation/inotationinteraction.h"
#include "notation/inotationundostack.h"
#include "notation/inotationparts.h"
#include "project/inotationproject.h"
#include "notation/imasternotation.h"

// api
#include "engravingapiv1.h"
Expand Down Expand Up @@ -236,6 +241,8 @@ void PluginAPI::setup(QQmlEngine* e)

engravingApi->setApi(this);
m_engine = engravingApi->engine();

initScoreStateNotifications();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

PluginAPI::PluginAPI(QQuickItem* parent)
Expand Down Expand Up @@ -495,6 +502,8 @@ apiv1::Fraction* PluginAPI::fractionFromTicks(int ticks) const

void PluginAPI::quit()
{
m_notationSubscriptions.async_disconnectAll();
async_disconnectAll();
emit closeRequested();
m_closeRequested.notify();
}
Expand Down Expand Up @@ -662,3 +671,54 @@ IntervalWrapper* PluginAPI::intervalFromOrnamentInterval(OrnamentIntervalWrapper
{
return wrap(mu::engraving::Interval::fromOrnamentInterval(o->ornamentInterval()));
}

void PluginAPI::initScoreStateNotifications()
{
context()->currentNotationChanged().onNotify(this, [this]() {
subscribeToNotationState(context()->currentNotation());
});

subscribeToNotationState(context()->currentNotation());
}

void PluginAPI::subscribeToNotationState(notation::INotationPtr n)
{
m_notationSubscriptions.async_disconnectAll();

if (!n) {
return;
}

auto emitState = [this](bool selection, bool undoRedo, bool instruments, bool excerpts) {
QMap<QString, QVariant> state;
state["selectionChanged"] = selection;
state["undoRedo"] = undoRedo;
state["instrumentsChanged"] = instruments;
state["excerptsChanged"] = excerpts;
emit scoreStateChanged(state);
};

if (n->interaction()) {
n->interaction()->selectionChanged().onNotify(&m_notationSubscriptions, [emitState]() {
emitState(true, false, false, false);
});
}

if (n->undoStack()) {
n->undoStack()->stackChanged().onNotify(&m_notationSubscriptions, [emitState]() {
emitState(false, true, false, false);
});
}

if (n->parts()) {
n->parts()->partsChanged().onNotify(&m_notationSubscriptions, [emitState]() {
emitState(false, false, true, false);
});
}

if (n->project() && n->project()->masterNotation()) {
n->project()->masterNotation()->excerptsChanged().onNotify(&m_notationSubscriptions, [emitState]() {
emitState(false, false, false, true);
});
}
}
Comment thread
Ash-86 marked this conversation as resolved.
9 changes: 7 additions & 2 deletions src/engraving/api/v1/qmlpluginapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <QQuickItem>

#include "extensions/api/v1/ipluginapiv1.h"

#include "async/asyncable.h"
#include "global/api/apiutils.h"

#include "modularity/ioc.h"
Expand Down Expand Up @@ -92,7 +92,7 @@ class Score;
// @P scores array[mu::engraving::Score] all currently open scores (read only)
//---------------------------------------------------------

class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV1, public muse::Contextable
class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV1, public muse::Contextable, public muse::async::Asyncable
{
Q_OBJECT

Expand Down Expand Up @@ -592,6 +592,11 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV

private:
mu::engraving::Score* currentScore() const;
void initScoreStateNotifications();
void subscribeToNotationState(notation::INotationPtr notation);

struct NotationSubscriptions : public muse::async::Asyncable {};
NotationSubscriptions m_notationSubscriptions;

muse::api::IApiEngine* m_engine = nullptr;
QString m_pluginType;
Expand Down
Loading