Skip to content

Commit bf9dc4a

Browse files
committed
New engraving interface
1 parent f6b87e1 commit bf9dc4a

File tree

7 files changed

+136
-55
lines changed

7 files changed

+136
-55
lines changed

src/engraving/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ set(MODULE_SRC
6161
${CMAKE_CURRENT_LIST_DIR}/engravingerrors.h
6262
${CMAKE_CURRENT_LIST_DIR}/engravingproject.cpp
6363
${CMAKE_CURRENT_LIST_DIR}/engravingproject.h
64+
${CMAKE_CURRENT_LIST_DIR}/iengraving.h
6465
${CMAKE_CURRENT_LIST_DIR}/iengravingconfiguration.h
6566
${CMAKE_CURRENT_LIST_DIR}/iengravingfont.h
6667
${CMAKE_CURRENT_LIST_DIR}/iengravingfontsprovider.h

src/engraving/api/v1/qmlpluginapi.cpp

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -249,44 +249,7 @@ bool PluginAPI::writeScore(Score* s, const QString& name, const QString& ext)
249249
LOGW("PluginAPI::writeScore: only writing the selected score is currently supported");
250250
return false;
251251
}
252-
253-
const notation::INotationPtr notation = context()->currentNotation();
254-
255-
if (!notation) {
256-
LOGW("PluginAPI::writeScore: no notation found");
257-
return false;
258-
}
259-
260-
const auto unitType = determineWriterUnitType(ext.toStdString());
261-
262-
if (!unitType) {
263-
LOGW("PluginAPI::writeScore: '%s' format is not supported", ext.toUtf8().constData());
264-
return false;
265-
}
266-
267-
const QString outPath = name.endsWith(ext) ? name : (name + '.' + ext);
268-
return exportProjectScenario()->exportScores({ notation }, outPath, *unitType, /* openDestinationFolderOnExport */ false);
269-
}
270-
271-
std::optional<project::INotationWriter::UnitType> PluginAPI::determineWriterUnitType(const std::string& ext) const
272-
{
273-
const project::INotationWriterPtr writer = writers()->writer(ext);
274-
275-
if (!writer) {
276-
return std::nullopt;
277-
}
278-
279-
project::INotationWriter::UnitType unitType;
280-
281-
if (writer->supportsUnitType(project::INotationWriter::UnitType::PER_PAGE)) {
282-
unitType = project::INotationWriter::UnitType::PER_PAGE;
283-
} else if (writer->supportsUnitType(project::INotationWriter::UnitType::PER_PART)) {
284-
unitType = project::INotationWriter::UnitType::PER_PART;
285-
} else {
286-
unitType = project::INotationWriter::UnitType::MULTI_PART;
287-
}
288-
289-
return unitType;
252+
return engravingInterface.get()->APIwriteScore(name, ext);
290253
}
291254

292255
//---------------------------------------------------------
@@ -309,18 +272,23 @@ apiv1::Score* PluginAPI::readScore(const QString& name, bool noninteractive)
309272

310273
if (noninteractive) {
311274
LOGW("PluginAPI::readScore: noninteractive flag is not yet implemented");
275+
return nullptr;
312276
}
313277

314-
const muse::io::path_t path(name);
315-
const project::ProjectFile file(path);
316-
const muse::Ret ret = projectFilesController()->openProject(file);
317-
318-
return (ret.success() && !hadScoreOpened) ? curScore() : nullptr;
278+
mu::engraving::Score* score = engravingInterface.get()->APIreadScore(name);
279+
if (score) {
280+
return wrap<apiv1::Score>(score, Ownership::SCORE);
281+
}
282+
return nullptr;
319283
}
320284

321285
//---------------------------------------------------------
322286
// closeScore
323287
//---------------------------------------------------------
288+
void PluginAPI::closeScore()
289+
{
290+
return closeScore(curScore());
291+
}
324292

325293
void PluginAPI::closeScore(apiv1::Score* score)
326294
{
@@ -334,7 +302,7 @@ void PluginAPI::closeScore(apiv1::Score* score)
334302
return;
335303
}
336304

337-
projectFilesController()->closeOpenedProject();
305+
engravingInterface.get()->APIcloseScore();
338306
}
339307

340308
//---------------------------------------------------------

src/engraving/api/v1/qmlpluginapi.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "actions/iactionsdispatcher.h"
3030
#include "context/iglobalcontext.h"
3131
#include "global/iapplication.h"
32+
#include "engraving/iengraving.h"
3233

3334
#include "enums.h"
3435
#include "engraving/dom/score.h"
@@ -96,12 +97,6 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
9697
{
9798
Q_OBJECT
9899

99-
INJECT(muse::actions::IActionsDispatcher, actionsDispatcher)
100-
INJECT(mu::context::IGlobalContext, context)
101-
INJECT(mu::project::INotationWritersRegister, writers)
102-
INJECT(mu::project::IExportProjectScenario, exportProjectScenario)
103-
INJECT(mu::project::IProjectFilesController, projectFilesController)
104-
105100
/** Path where the plugin is placed in menu */
106101
Q_PROPERTY(QString menuPath READ menuPath WRITE setMenuPath)
107102
/** Title of this plugin */
@@ -142,10 +137,11 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
142137
/** List of currently open scores (read only).\n \since MuseScore 3.2 */
143138
Q_PROPERTY(QQmlListProperty<mu::engraving::apiv1::Score> scores READ scores)
144139

145-
muse::Inject<mu::context::IGlobalContext> context = { this };
146-
147140
public:
141+
muse::Inject<muse::actions::IActionsDispatcher> actionsDispatcher = { this };
142+
muse::Inject<mu::context::IGlobalContext> context = { this };
148143
muse::Inject<muse::IApplication> application = { this };
144+
muse::Inject<mu::engraving::IEngraving> engravingInterface = { this };
149145

150146
public:
151147
// Should be initialized in qmlpluginapi.cpp
@@ -487,7 +483,8 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
487483
Q_INVOKABLE apiv1::MsProcess* newQProcess();
488484
Q_INVOKABLE bool writeScore(apiv1::Score*, const QString& name, const QString& ext);
489485
Q_INVOKABLE apiv1::Score* readScore(const QString& name, bool noninteractive = false);
490-
Q_INVOKABLE void closeScore(apiv1::Score*);
486+
Q_INVOKABLE void closeScore(apiv1::Score* score);
487+
Q_INVOKABLE void closeScore();
491488

492489
Q_INVOKABLE void log(const QString&);
493490
Q_INVOKABLE void logn(const QString&);
@@ -550,7 +547,6 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
550547
QString m_thumbnailName;
551548
QString m_categoryCode;
552549
muse::async::Notification m_closeRequested;
553-
std::optional<project::INotationWriter::UnitType> determineWriterUnitType(const std::string& ext) const;
554550
};
555551

556552
#undef DECLARE_API_ENUM2

src/engraving/iengraving.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-only
3+
* MuseScore-Studio-CLA-applies
4+
*
5+
* MuseScore Studio
6+
* Music Composition & Notation
7+
*
8+
* Copyright (C) 2021 MuseScore Limited
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License version 3 as
12+
* published by the Free Software Foundation.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
#pragma once
23+
24+
#include <QString>
25+
#include "modularity/imoduleinterface.h"
26+
27+
namespace mu::engraving {
28+
class Score;
29+
30+
class IEngraving : MODULE_EXPORT_INTERFACE
31+
{
32+
INTERFACE_ID(IEngraving)
33+
public:
34+
virtual ~IEngraving() = default;
35+
36+
// methods for plugin API
37+
virtual bool APIwriteScore(const QString& name, const QString& ext) = 0;
38+
virtual Score* APIreadScore(const QString& name) = 0;
39+
virtual void APIcloseScore() = 0;
40+
};
41+
}

src/project/internal/projectactionscontroller.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535

3636
#include "cloud/clouderrors.h"
3737
#include "cloud/cloudqmltypes.h"
38+
#include "engraving/iengraving.h"
3839
#include "engraving/infrastructure/mscio.h"
3940
#include "engraving/engravingerrors.h"
4041

42+
#include "inotationwriter.h"
4143
#include "projecterrors.h"
4244
#include "projectextensionpoints.h"
4345

@@ -46,6 +48,7 @@
4648
using namespace mu;
4749
using namespace mu::project;
4850
using namespace mu::notation;
51+
using namespace mu::engraving;
4952
using namespace muse;
5053
using namespace muse::actions;
5154

@@ -1932,3 +1935,61 @@ void ProjectActionsController::openProjectProperties()
19321935
{
19331936
interactive()->open(PROJECT_PROPERTIES_URI);
19341937
}
1938+
1939+
std::optional<INotationWriter::UnitType> ProjectActionsController::determineWriterUnitType(const std::string& ext) const
1940+
{
1941+
const INotationWriterPtr writer = writers()->writer(ext);
1942+
1943+
if (!writer) {
1944+
return std::nullopt;
1945+
}
1946+
1947+
project::INotationWriter::UnitType unitType;
1948+
1949+
if (writer->supportsUnitType(project::INotationWriter::UnitType::PER_PAGE)) {
1950+
unitType = project::INotationWriter::UnitType::PER_PAGE;
1951+
} else if (writer->supportsUnitType(project::INotationWriter::UnitType::PER_PART)) {
1952+
unitType = project::INotationWriter::UnitType::PER_PART;
1953+
} else {
1954+
unitType = project::INotationWriter::UnitType::MULTI_PART;
1955+
}
1956+
1957+
return unitType;
1958+
}
1959+
1960+
bool ProjectActionsController::APIwriteScore(const QString& name, const QString& ext)
1961+
{
1962+
const INotationPtr notation = globalContext()->currentNotation();
1963+
1964+
if (!notation) {
1965+
LOGW("PluginAPI::writeScore: no notation found");
1966+
return false;
1967+
}
1968+
1969+
const auto unitType = determineWriterUnitType(ext.toStdString());
1970+
1971+
if (!unitType) {
1972+
LOGW("PluginAPI::writeScore: '%s' format is not supported", ext.toUtf8().constData());
1973+
return false;
1974+
}
1975+
1976+
const QString outPath = name.endsWith(ext) ? name : (name + '.' + ext);
1977+
return exportProjectScenario()->exportScores({ notation }, outPath, *unitType, /* openDestinationFolderOnExport */ false);
1978+
}
1979+
1980+
Score* ProjectActionsController::APIreadScore(const QString& name)
1981+
{
1982+
const muse::io::path_t path(name);
1983+
const ProjectFile file(path);
1984+
const Ret ret = projectFilesController()->openProject(file);
1985+
1986+
if (ret.success() && globalContext()->currentNotation()) {
1987+
return globalContext()->currentNotation()->elements()->msScore();
1988+
}
1989+
return nullptr;
1990+
}
1991+
1992+
void ProjectActionsController::APIcloseScore()
1993+
{
1994+
projectFilesController()->closeOpenedProject();
1995+
}

src/project/internal/projectactionscontroller.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "iprojectfilescontroller.h"
2626

2727
#include <QObject>
28+
#include <QString>
2829

2930
#include "modularity/ioc.h"
3031
#include "iinteractive.h"
@@ -39,28 +40,33 @@
3940
#include "print/iprintprovider.h"
4041
#include "iexportprojectscenario.h"
4142
#include "inotationreadersregister.h"
43+
#include "inotationwritersregister.h"
4244
#include "iopensaveprojectscenario.h"
4345
#include "imscmetareader.h"
4446
#include "io/ifilesystem.h"
4547
#include "notation/inotationconfiguration.h"
48+
#include "engraving/iengraving.h"
4649
#include "musesounds/imusesoundscheckupdatescenario.h"
4750
#include "extensions/iextensionsprovider.h"
4851
#include "tours/itoursservice.h"
4952

5053
#include "async/asyncable.h"
5154

55+
#include "inotationwriter.h"
5256
#include "iprojectconfiguration.h"
5357
#include "iprojectcreator.h"
5458
#include "irecentfilescontroller.h"
5559
#include "iprojectautosaver.h"
5660

5761
namespace mu::project {
5862
class ProjectActionsController : public IProjectFilesController, public muse::mi::IProjectProvider, public muse::Injectable,
59-
public muse::actions::Actionable, public muse::async::Asyncable
63+
public muse::actions::Actionable, public muse::async::Asyncable, virtual public engraving::IEngraving
6064
{
6165
muse::Inject<IProjectConfiguration> configuration = { this };
6266
muse::Inject<INotationReadersRegister> readers = { this };
67+
muse::Inject<INotationWritersRegister> writers = { this };
6368
muse::Inject<IProjectCreator> projectCreator = { this };
69+
muse::Inject<IProjectFilesController> projectFilesController = { this };
6470
muse::Inject<IRecentFilesController> recentFilesController = { this };
6571
muse::Inject<IProjectAutoSaver> projectAutoSaver = { this };
6672
muse::Inject<IOpenSaveProjectScenario> openSaveProjectScenario = { this };
@@ -104,6 +110,11 @@ class ProjectActionsController : public IProjectFilesController, public muse::mi
104110
const ProjectBeingDownloaded& projectBeingDownloaded() const override;
105111
muse::async::Notification projectBeingDownloadedChanged() const override;
106112

113+
// IEngraving interface (for plugin API)
114+
bool APIwriteScore(const QString& name, const QString& ext) override;
115+
mu::engraving::Score* APIreadScore(const QString& name) override;
116+
void APIcloseScore() override;
117+
107118
private:
108119
void setupConnections();
109120

@@ -218,6 +229,8 @@ class ProjectActionsController : public IProjectFilesController, public muse::mi
218229

219230
QUrl scoreManagerUrl() const;
220231

232+
std::optional<INotationWriter::UnitType> determineWriterUnitType(const std::string& ext) const;
233+
221234
bool m_isProjectSaving = false;
222235
bool m_isProjectClosing = false;
223236
bool m_isProjectProcessing = false;

src/project/projectmodule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ void ProjectModule::registerExports()
106106
ioc()->registerExport<ITemplatesRepository>(moduleName(), new TemplatesRepository());
107107
ioc()->registerExport<IProjectMigrator>(moduleName(), new ProjectMigrator());
108108
ioc()->registerExport<IProjectAutoSaver>(moduleName(), m_projectAutoSaver);
109+
ioc()->registerExport<mu::engraving::IEngraving>(moduleName(), m_actionsController);
109110

110111
//! TODO Should be replace INotationReaders/WritersRegister with IProjectRWRegister
111112
ioc()->registerExport<INotationReadersRegister>(moduleName(), new NotationReadersRegister());

0 commit comments

Comments
 (0)