LCOV - code coverage report
Current view: top level - src/project/internal - exportprojectscenario.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 3 3
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              : #pragma once
      24              : 
      25              : #include <deque>
      26              : 
      27              : #include <QObject>
      28              : 
      29              : #include "modularity/ioc.h"
      30              : 
      31              : #include "iexportprojectscenario.h"
      32              : #include "iprojectconfiguration.h"
      33              : #include "interactive/iinteractive.h"
      34              : #include "interactive/iplatforminteractive.h"
      35              : #include "inotationwritersregister.h"
      36              : #include "importexport/imagesexport/iimagesexportconfiguration.h"
      37              : #include "project/iprojectsession.h"
      38              : #include "io/ifilesystem.h"
      39              : #include "async/asyncable.h"
      40              : #include "notation/types/viewmode.h"
      41              : 
      42              : namespace mu::project {
      43              : class ExportProjectScenario : public IExportProjectScenario, public muse::async::Asyncable, public muse::Contextable
      44              : {
      45              : public:
      46              :     muse::GlobalInject<muse::io::IFileSystem> fileSystem;
      47              :     muse::GlobalInject<IProjectConfiguration> configuration;
      48              :     muse::GlobalInject<iex::imagesexport::IImagesExportConfiguration> imagesExportConfiguration;
      49              :     muse::GlobalInject<INotationWritersRegister> writers;
      50              :     muse::GlobalInject<muse::IPlatformInteractive> platformInteractive;
      51              :     muse::ContextInject<muse::IInteractive> interactive = { this };
      52              :     muse::ContextInject<project::IProjectSession> context = { this };
      53              : 
      54           45 :     ExportProjectScenario(const muse::modularity::ContextPtr& iocCtx)
      55           45 :         : muse::Contextable(iocCtx)
      56              :     {
      57           45 :     }
      58              : 
      59              :     std::vector<INotationWriter::UnitType> supportedUnitTypes(const ExportType& exportType) const override;
      60              : 
      61              :     muse::RetVal<muse::io::path_t> askExportPath(const notation::INotationPtrList& notations, const ExportType& exportType,
      62              :                                                  INotationWriter::UnitType unitType = INotationWriter::UnitType::PER_PART,
      63              :                                                  muse::io::path_t defaultDirPath = "") const override;
      64              : 
      65              :     muse::async::Promise<muse::Ret> exportScores(notation::INotationPtrList notations, const muse::io::path_t destinationPath,
      66              :                                                  INotationWriter::UnitType unitType = INotationWriter::UnitType::PER_PART,
      67              :                                                  bool openDestinationFolderOnExport = false) const override;
      68              : 
      69              :     const ExportInfo& exportInfo() const override;
      70              :     void setExportInfo(const ExportInfo& exportInfo) override;
      71              : 
      72              : private:
      73              :     enum class FileConflictPolicy {
      74              :         Undefined,
      75              :         SkipAll,
      76              :         ReplaceAll
      77              :     };
      78              : 
      79              :     struct ExportFile {
      80              :         muse::io::path_t path;
      81              :         std::function<muse::Ret(muse::io::IODevice&)> exportFunction;
      82              :     };
      83              : 
      84              :     struct ExportState;
      85              :     using ExportStatePtr = std::shared_ptr<ExportState>;
      86              : 
      87              :     /// When the user is trying to export a part that is a "potential excerpt", the corresponding score
      88              :     /// is not initialized yet, so we can't be certain about the page count. We should not initialize
      89              :     /// these scores either, until the user really starts the export, because initializing these scores
      90              :     /// means making changes to the file, which can't be done without the user's consent.
      91              :     bool guessIsCreatingOnlyOneFile(const notation::INotationPtrList& notations, INotationWriter::UnitType unitType) const;
      92              : 
      93              :     bool isMainNotation(notation::INotationPtr notation) const;
      94              :     notation::IMasterNotationPtr masterNotation() const;
      95              : 
      96              :     muse::io::path_t completeExportPath(const muse::io::path_t& basePath, notation::INotationPtr notation, bool isMain,
      97              :                                         bool isExportingOnlyOneScore, int pageIndex = -1) const;
      98              : 
      99              :     std::vector<ExportFile> exportFiles(const notation::INotationPtrList& notations, const muse::io::path_t& destinationPath,
     100              :                                         INotationWriterPtr writer, INotationWriter::UnitType unitType, bool isCreatingOnlyOneFile) const;
     101              : 
     102              :     void startNextExportLater() const;
     103              :     void startExport(const notation::INotationPtrList& notations, const muse::io::path_t& destinationPath,
     104              :                      INotationWriter::UnitType unitType, bool openDestinationFolderOnExport,
     105              :                      const muse::async::Promise<muse::Ret>::Resolve& resolve) const;
     106              : 
     107              :     void exportNextFiles(const ExportStatePtr& state) const;
     108              :     void finishExport(const ExportStatePtr& state, const muse::Ret& ret) const;
     109              : 
     110              :     void askForReplaceFile(const ExportStatePtr& state) const;
     111              :     void askForRetry(const ExportStatePtr& state) const;
     112              :     void continueExportLater(const ExportStatePtr& state) const;
     113              : 
     114              :     muse::Ret writeFile(const ExportFile& file) const;
     115              : 
     116              :     void showExportProgress(bool isAudioExport) const;
     117              : 
     118              :     void openFolder(const muse::io::path_t& path) const;
     119              : 
     120              :     std::vector<notation::ViewMode> viewModes(const notation::INotationPtrList& notations) const;
     121              :     void setViewModes(const notation::INotationPtrList& notations, const std::vector<notation::ViewMode>& viewModes) const;
     122              :     void setViewModes(const notation::INotationPtrList& notations, notation::ViewMode viewMode) const;
     123              : 
     124              :     mutable muse::Progress m_exportProgress;
     125              :     ExportInfo m_exportInfo;
     126              : 
     127              :     mutable std::deque<std::function<void()> > m_pendingExports;
     128              :     mutable bool m_isExporting = false;
     129              : 
     130              :     //! NOTE The context of the timers, so that they do not outlive the scenario
     131              :     mutable QObject m_timersContext;
     132              : };
     133              : }
        

Generated by: LCOV version 2.0-1