LCOV - code coverage report
Current view: top level - src/project/internal - engravingpluginapihelper.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 44 0
Test Date: 2026-11-19 04:14:36

            Line data    Source code
       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 and others
       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              : 
      23              : #include "engravingpluginapihelper.h"
      24              : 
      25              : #include "notation/inotation.h"
      26              : #include "notation/inotationelements.h" // IWYU pragma: keep
      27              : 
      28              : #include "inotationwriter.h"
      29              : #include "types/projectfile.h"
      30              : 
      31              : #include "log.h"
      32              : 
      33              : using namespace mu::project;
      34              : using namespace mu::notation;
      35              : using namespace mu::engraving;
      36              : using namespace muse;
      37              : 
      38            0 : bool EngravingPluginAPIHelper::writeScore(const QString& name, const QString& ext)
      39              : {
      40            0 :     const INotationPtr notation = projectSession()->currentNotation();
      41            0 :     if (!notation) {
      42            0 :         LOGW() << "No notation found";
      43            0 :         return false;
      44              :     }
      45              : 
      46            0 :     const auto unitType = determineWriterUnitType(ext.toStdString());
      47            0 :     if (!unitType) {
      48            0 :         LOGW() << "'" << ext << "' format is not supported";
      49            0 :         return false;
      50              :     }
      51              : 
      52            0 :     const QString outPath = name.endsWith(ext) ? name : (name + '.' + ext);
      53            0 :     exportProjectScenario()->exportScores({ notation }, outPath, *unitType, /* openDestinationFolderOnExport */ false)
      54            0 :     .onResolve(this, [outPath](const Ret& ret) {
      55            0 :         if (!ret) {
      56            0 :             LOGE() << "score was not written to " << outPath << ": " << ret.toString();
      57              :         }
      58            0 :     });
      59              : 
      60              :     //! TODO: return promise to js
      61            0 :     return true;
      62            0 : }
      63              : 
      64            0 : Score* EngravingPluginAPIHelper::readScore(const QString& name)
      65              : {
      66            0 :     const muse::io::path_t path(name);
      67            0 :     const ProjectFile file(path);
      68              : 
      69            0 :     openProjectScenario()->openProject(file)
      70            0 :     .onResolve(this, [](const Ret& ret) {
      71            0 :         if (!ret) {
      72            0 :             LOGD() << "score was not opened: " << ret.toString();
      73              :         }
      74            0 :     });
      75              : 
      76              :     //! TODO: return promise to js
      77            0 :     return nullptr;
      78            0 : }
      79              : 
      80            0 : void EngravingPluginAPIHelper::closeScore()
      81              : {
      82            0 :     closeProjectController()->closeOpenedProject()
      83            0 :     .onResolve(this, [](const Ret& ret) {
      84            0 :         if (!ret) {
      85            0 :             LOGD() << "score was not closed: " << ret.toString();
      86              :         }
      87            0 :     });
      88            0 : }
      89              : 
      90            0 : std::optional<INotationWriter::UnitType> EngravingPluginAPIHelper::determineWriterUnitType(const std::string& ext) const
      91              : {
      92            0 :     const INotationWriterPtr writer = writers()->writer(ext);
      93            0 :     if (!writer) {
      94            0 :         return std::nullopt;
      95              :     }
      96              : 
      97            0 :     if (writer->supportsUnitType(INotationWriter::UnitType::PER_PAGE)) {
      98            0 :         return INotationWriter::UnitType::PER_PAGE;
      99            0 :     } else if (writer->supportsUnitType(INotationWriter::UnitType::PER_PART)) {
     100            0 :         return INotationWriter::UnitType::PER_PART;
     101              :     } else {
     102            0 :         return INotationWriter::UnitType::MULTI_PART;
     103              :     }
     104            0 : }
        

Generated by: LCOV version 2.0-1