Skip to content

Commit

Permalink
Plugin API: partially restore readScore, closeScore and writeScore
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrio95 committed Jan 5, 2024
1 parent ec21fda commit f8d7b1e
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ set(MODULE_SRC
set(MODULE_LINK
uicomponents
engraving
notation
project
)

include(SetupModule)
Expand Down
67 changes: 57 additions & 10 deletions src/plugins/api/qmlpluginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "engraving/compat/scoreaccess.h"
#include "engraving/dom/factory.h"
#include "engraving/dom/masterscore.h"
#include "notation/inotation.h"
#include "project/inotationwriter.h"

#include "cursor.h"
#include "elements.h"
Expand Down Expand Up @@ -118,14 +120,41 @@ QQmlListProperty<Score> PluginAPI::scores()
bool PluginAPI::writeScore(Score* s, const QString& name, const QString& ext)
{
if (!s || !s->score()) {
LOGW("PluginAPI::writeScore: no score provided");
return false;
}

UNUSED(name);
UNUSED(ext);
if (s->score() != currentScore()) {
LOGW("PluginAPI::writeScore: only writing the selected score is currently supported");
return false;
}

NOT_IMPLEMENTED;
return false;
const notation::INotationPtr notation = context()->currentNotation();

if (!notation) {
LOGW("PluginAPI::writeScore: no notation found");
return false;
}

const project::INotationWriterPtr writer = writers()->writer(ext.toStdString());

if (!writer) {
LOGW("PluginAPI::writeScore: failed to create writer for the format '%s'", ext.toUtf8().constData());
return false;
}

project::INotationWriter::UnitType unitType;

if (writer->supportsUnitType(project::INotationWriter::UnitType::PER_PAGE)) {
unitType = project::INotationWriter::UnitType::PER_PAGE;
} else if (writer->supportsUnitType(project::INotationWriter::UnitType::PER_PART)) {
unitType = project::INotationWriter::UnitType::PER_PART;
} else {
unitType = project::INotationWriter::UnitType::MULTI_PART;
}

const QString outPath = name.endsWith(ext) ? name : (name + '.' + ext);
return exportProjectScenario()->exportScores({ notation }, outPath, unitType, /* openDestinationFolderOnExport */ false);
}

//---------------------------------------------------------
Expand All @@ -140,11 +169,21 @@ bool PluginAPI::writeScore(Score* s, const QString& name, const QString& ext)

Score* PluginAPI::readScore(const QString& name, bool noninteractive)
{
UNUSED(name);
UNUSED(noninteractive);
const bool hadScoreOpened = currentScore();

NOT_IMPLEMENTED;
return nullptr;
if (hadScoreOpened) {
LOGW("PluginAPI::readScore: will open a score in a new window");
}

if (noninteractive) {
LOGW("PluginAPI::readScore: noninteractive flag is not yet implemented");
}

const io::path_t path(name);
const project::ProjectFile file(path);
const Ret ret = projectFilesController()->openProject(file);

return (ret.success() && !hadScoreOpened) ? curScore() : nullptr;
}

//---------------------------------------------------------
Expand All @@ -153,9 +192,17 @@ Score* PluginAPI::readScore(const QString& name, bool noninteractive)

void PluginAPI::closeScore(mu::plugins::api::Score* score)
{
UNUSED(score);
if (!score || !score->score()) {
LOGW("PluginAPI::closeScore: no score provided");
return;
}

NOT_IMPLEMENTED;
if (score->score() != currentScore()) {
LOGW("PluginAPI::closeScore: only closing the selected score is currently supported");
return;
}

projectFilesController()->closeOpenedProject();
}

//---------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/api/qmlpluginapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include "engraving/dom/score.h"
#include "engraving/dom/types.h"
#include "engraving/types/types.h"
#include "project/iexportprojectscenario.h"
#include "project/inotationwritersregister.h"
#include "project/iprojectfilescontroller.h"

#include "apitypes.h"

Expand Down Expand Up @@ -77,6 +80,9 @@ class PluginAPI : public QmlPlugin

INJECT(mu::actions::IActionsDispatcher, actionsDispatcher)
INJECT(mu::context::IGlobalContext, context)
INJECT(mu::project::INotationWritersRegister, writers)
INJECT(mu::project::IExportProjectScenario, exportProjectScenario)
INJECT(mu::project::IProjectFilesController, projectFilesController)

/** Path where the plugin is placed in menu */
Q_PROPERTY(QString menuPath READ menuPath WRITE setMenuPath)
Expand Down
2 changes: 1 addition & 1 deletion src/project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/projectmodule.cpp
${CMAKE_CURRENT_LIST_DIR}/projectmodule.h
${CMAKE_CURRENT_LIST_DIR}/projecterrors.h
${CMAKE_CURRENT_LIST_DIR}/iexportprojectscenario.h
${CMAKE_CURRENT_LIST_DIR}/inotationproject.h
${CMAKE_CURRENT_LIST_DIR}/iprojectcreator.h
${CMAKE_CURRENT_LIST_DIR}/inotationreader.h
Expand Down Expand Up @@ -88,7 +89,6 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/internal/projectconfiguration.h
${CMAKE_CURRENT_LIST_DIR}/internal/exporttype.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/exporttype.h
${CMAKE_CURRENT_LIST_DIR}/internal/iexportprojectscenario.h
${CMAKE_CURRENT_LIST_DIR}/internal/exportprojectscenario.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/exportprojectscenario.h
${CMAKE_CURRENT_LIST_DIR}/internal/iopensaveprojectscenario.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "modularity/imoduleinterface.h"
#include "notation/inotation.h"
#include "inotationwriter.h"
#include "exporttype.h"
#include "internal/exporttype.h"
#include "types/projecttypes.h"

namespace mu::project {
Expand Down
3 changes: 3 additions & 0 deletions src/project/internal/exportprojectscenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ bool ExportProjectScenario::exportScores(const notation::INotationPtrList& notat
} break;
case INotationWriter::UnitType::MULTI_PART: {
auto exportFunction = [writer, notations, options](QIODevice& destinationDevice) {
if (notations.size() == 1) {
return writer->write(notations.front(), destinationDevice, options);
}
return writer->writeList(notations, destinationDevice, options);
};

Expand Down
2 changes: 1 addition & 1 deletion src/project/internal/projectactionscontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
#include "cloud/cloudqmltypes.h"
#include "playback/iplaybackcontroller.h"
#include "print/iprintprovider.h"
#include "iexportprojectscenario.h"
#include "inotationreadersregister.h"
#include "iopensaveprojectscenario.h"
#include "io/ifilesystem.h"
#include "internal/iexportprojectscenario.h"
#include "notation/inotationconfiguration.h"

#include "async/asyncable.h"
Expand Down
2 changes: 1 addition & 1 deletion src/project/view/exportdialogmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
#include "importexport/audioexport/iaudioexportconfiguration.h"
#include "importexport/mei/imeiconfiguration.h"

#include "iexportprojectscenario.h"
#include "inotationwritersregister.h"
#include "iprojectconfiguration.h"
#include "internal/iexportprojectscenario.h"
#include "types/projecttypes.h"

class QItemSelectionModel;
Expand Down

0 comments on commit f8d7b1e

Please sign in to comment.