Skip to content

Commit 9bfa1ac

Browse files
committed
New engraving interface
1 parent b5ee747 commit 9bfa1ac

File tree

6 files changed

+139
-57
lines changed

6 files changed

+139
-57
lines changed

src/engraving/CMakeLists.txt

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

src/engraving/api/v1/qmlpluginapi.cpp

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#include "engraving/compat/scoreaccess.h"
2929
#include "engraving/dom/factory.h"
3030
#include "engraving/dom/masterscore.h"
31-
#include "notation/inotation.h"
32-
#include "project/inotationwriter.h"
3331

3432
// api
3533
#include "engravingapiv1.h"
@@ -186,44 +184,7 @@ bool PluginAPI::writeScore(Score* s, const QString& name, const QString& ext)
186184
LOGW("PluginAPI::writeScore: only writing the selected score is currently supported");
187185
return false;
188186
}
189-
190-
const notation::INotationPtr notation = context()->currentNotation();
191-
192-
if (!notation) {
193-
LOGW("PluginAPI::writeScore: no notation found");
194-
return false;
195-
}
196-
197-
const auto unitType = determineWriterUnitType(ext.toStdString());
198-
199-
if (!unitType) {
200-
LOGW("PluginAPI::writeScore: '%s' format is not supported", ext.toUtf8().constData());
201-
return false;
202-
}
203-
204-
const QString outPath = name.endsWith(ext) ? name : (name + '.' + ext);
205-
return exportProjectScenario()->exportScores({ notation }, outPath, *unitType, /* openDestinationFolderOnExport */ false);
206-
}
207-
208-
std::optional<project::INotationWriter::UnitType> PluginAPI::determineWriterUnitType(const std::string& ext) const
209-
{
210-
const project::INotationWriterPtr writer = writers()->writer(ext);
211-
212-
if (!writer) {
213-
return std::nullopt;
214-
}
215-
216-
project::INotationWriter::UnitType unitType;
217-
218-
if (writer->supportsUnitType(project::INotationWriter::UnitType::PER_PAGE)) {
219-
unitType = project::INotationWriter::UnitType::PER_PAGE;
220-
} else if (writer->supportsUnitType(project::INotationWriter::UnitType::PER_PART)) {
221-
unitType = project::INotationWriter::UnitType::PER_PART;
222-
} else {
223-
unitType = project::INotationWriter::UnitType::MULTI_PART;
224-
}
225-
226-
return unitType;
187+
return engravingInterface->APIwriteScore(name, ext);
227188
}
228189

229190
//---------------------------------------------------------
@@ -246,18 +207,23 @@ apiv1::Score* PluginAPI::readScore(const QString& name, bool noninteractive)
246207

247208
if (noninteractive) {
248209
LOGW("PluginAPI::readScore: noninteractive flag is not yet implemented");
210+
return nullptr;
249211
}
250212

251-
const muse::io::path_t path(name);
252-
const project::ProjectFile file(path);
253-
const muse::Ret ret = projectFilesController()->openProject(file);
254-
255-
return (ret.success() && !hadScoreOpened) ? curScore() : nullptr;
213+
mu::engraving::Score* score = engravingInterface->APIreadScore(name);
214+
if (score) {
215+
return wrap<apiv1::Score>(score, Ownership::SCORE);
216+
}
217+
return nullptr;
256218
}
257219

258220
//---------------------------------------------------------
259221
// closeScore
260222
//---------------------------------------------------------
223+
void PluginAPI::closeScore()
224+
{
225+
return closeScore(curScore());
226+
}
261227

262228
void PluginAPI::closeScore(apiv1::Score* score)
263229
{
@@ -271,7 +237,7 @@ void PluginAPI::closeScore(apiv1::Score* score)
271237
return;
272238
}
273239

274-
projectFilesController()->closeOpenedProject();
240+
engravingInterface->APIcloseScore();
275241
}
276242

277243
//---------------------------------------------------------

src/engraving/api/v1/qmlpluginapi.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "actions/iactionsdispatcher.h"
3232
#include "context/iglobalcontext.h"
3333
#include "global/iapplication.h"
34+
#include "engraving/iengraving.h"
3435

3536
#include "enums.h"
3637
#include "engraving/dom/score.h"
@@ -92,12 +93,6 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
9293
{
9394
Q_OBJECT
9495

95-
INJECT(muse::actions::IActionsDispatcher, actionsDispatcher)
96-
INJECT(mu::context::IGlobalContext, context)
97-
INJECT(mu::project::INotationWritersRegister, writers)
98-
INJECT(mu::project::IExportProjectScenario, exportProjectScenario)
99-
INJECT(mu::project::IProjectFilesController, projectFilesController)
100-
10196
/** Path where the plugin is placed in menu */
10297
Q_PROPERTY(QString menuPath READ menuPath WRITE setMenuPath)
10398
/** Title of this plugin */
@@ -138,9 +133,9 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
138133
/** List of currently open scores (read only).\n \since MuseScore 3.2 */
139134
Q_PROPERTY(QQmlListProperty<mu::engraving::apiv1::Score> scores READ scores)
140135

141-
muse::Inject<mu::context::IGlobalContext> context = { this };
142-
143136
public:
137+
muse::Inject<muse::actions::IActionsDispatcher> actionsDispatcher = { this };
138+
muse::Inject<mu::context::IGlobalContext> context = { this };
144139
muse::Inject<muse::IApplication> application = { this };
145140

146141
public:
@@ -285,6 +280,9 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
285280
/// \cond MS_INTERNAL
286281
PluginAPI(QQuickItem* parent = 0);
287282

283+
explicit PluginAPI(IEngraving* engraving)
284+
: engravingInterface(engraving) {}
285+
288286
static void registerQmlTypes();
289287

290288
void setup(QQmlEngine* e) override;
@@ -305,7 +303,8 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
305303
Q_INVOKABLE apiv1::MsProcess* newQProcess();
306304
Q_INVOKABLE bool writeScore(apiv1::Score*, const QString& name, const QString& ext);
307305
Q_INVOKABLE apiv1::Score* readScore(const QString& name, bool noninteractive = false);
308-
Q_INVOKABLE void closeScore(apiv1::Score*);
306+
Q_INVOKABLE void closeScore(apiv1::Score* score);
307+
Q_INVOKABLE void closeScore();
309308

310309
Q_INVOKABLE void log(const QString&);
311310
Q_INVOKABLE void logn(const QString&);
@@ -354,6 +353,8 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
354353
private:
355354
mu::engraving::Score* currentScore() const;
356355

356+
IEngraving* engravingInterface;
357+
357358
QString m_pluginType;
358359
QString m_title;
359360
QString m_version;
@@ -362,7 +363,6 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
362363
QString m_thumbnailName;
363364
QString m_categoryCode;
364365
muse::async::Notification m_closeRequested;
365-
std::optional<project::INotationWriter::UnitType> determineWriterUnitType(const std::string& ext) const;
366366
};
367367

368368
#undef DECLARE_API_ENUM

src/engraving/iengraving.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
#ifndef MU_ENGRAVING_IENGRAVING_H
23+
#define MU_ENGRAVING_IENGRAVING_H
24+
25+
#include <QString>
26+
27+
namespace mu::engraving {
28+
class IEngraving;
29+
30+
class IEngraving
31+
{
32+
public:
33+
virtual ~IEngraving() = default;
34+
35+
/// Methods for plugin API
36+
virtual bool APIwriteScore(const QString& name, const QString& ext) = 0;
37+
virtual Score* APIreadScore(const QString& name) = 0;
38+
virtual void APIcloseScore() = 0;
39+
};
40+
}
41+
42+
#endif // MU_ENGRAVING_IENGRAVING_H

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

@@ -1900,3 +1903,61 @@ void ProjectActionsController::openProjectProperties()
19001903
{
19011904
interactive()->open(PROJECT_PROPERTIES_URI);
19021905
}
1906+
1907+
std::optional<INotationWriter::UnitType> ProjectActionsController::determineWriterUnitType(const std::string& ext) const
1908+
{
1909+
const INotationWriterPtr writer = writers()->writer(ext);
1910+
1911+
if (!writer) {
1912+
return std::nullopt;
1913+
}
1914+
1915+
project::INotationWriter::UnitType unitType;
1916+
1917+
if (writer->supportsUnitType(project::INotationWriter::UnitType::PER_PAGE)) {
1918+
unitType = project::INotationWriter::UnitType::PER_PAGE;
1919+
} else if (writer->supportsUnitType(project::INotationWriter::UnitType::PER_PART)) {
1920+
unitType = project::INotationWriter::UnitType::PER_PART;
1921+
} else {
1922+
unitType = project::INotationWriter::UnitType::MULTI_PART;
1923+
}
1924+
1925+
return unitType;
1926+
}
1927+
1928+
bool ProjectActionsController::APIwriteScore(const QString& name, const QString& ext)
1929+
{
1930+
const INotationPtr notation = globalContext()->currentNotation();
1931+
1932+
if (!notation) {
1933+
LOGW("PluginAPI::writeScore: no notation found");
1934+
return false;
1935+
}
1936+
1937+
const auto unitType = determineWriterUnitType(ext.toStdString());
1938+
1939+
if (!unitType) {
1940+
LOGW("PluginAPI::writeScore: '%s' format is not supported", ext.toUtf8().constData());
1941+
return false;
1942+
}
1943+
1944+
const QString outPath = name.endsWith(ext) ? name : (name + '.' + ext);
1945+
return exportProjectScenario()->exportScores({ notation }, outPath, *unitType, /* openDestinationFolderOnExport */ false);
1946+
}
1947+
1948+
Score* ProjectActionsController::APIreadScore(const QString& name)
1949+
{
1950+
const muse::io::path_t path(name);
1951+
const ProjectFile file(path);
1952+
const Ret ret = projectFilesController()->openProject(file);
1953+
1954+
if (ret.success() && globalContext()->currentNotation()) {
1955+
return globalContext()->currentNotation()->elements()->msScore();
1956+
}
1957+
return nullptr;
1958+
}
1959+
1960+
void ProjectActionsController::APIcloseScore()
1961+
{
1962+
projectFilesController()->closeOpenedProject();
1963+
}

src/project/internal/projectactionscontroller.h

Lines changed: 13 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, 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 };
@@ -73,6 +79,7 @@ class ProjectActionsController : public IProjectFilesController, public muse::mi
7379
muse::Inject<muse::cloud::IMuseScoreComService> museScoreComService = { this };
7480
muse::Inject<muse::cloud::IAudioComService> audioComService = { this };
7581
muse::Inject<notation::INotationConfiguration> notationConfiguration = { this };
82+
// muse::Inject<engraving::IEngraving> engraving = { this };
7683
muse::Inject<playback::IPlaybackController> playbackController = { this };
7784
muse::Inject<print::IPrintProvider> printProvider = { this };
7885
muse::Inject<muse::io::IFileSystem> fileSystem = { this };
@@ -104,6 +111,11 @@ class ProjectActionsController : public IProjectFilesController, public muse::mi
104111
const ProjectBeingDownloaded& projectBeingDownloaded() const override;
105112
muse::async::Notification projectBeingDownloadedChanged() const override;
106113

114+
std::optional<INotationWriter::UnitType> determineWriterUnitType(const std::string& ext) const;
115+
bool APIwriteScore(const QString& name, const QString& ext) override;
116+
mu::engraving::Score* APIreadScore(const QString& name) override;
117+
void APIcloseScore() override;
118+
107119
private:
108120
void setupConnections();
109121

0 commit comments

Comments
 (0)