LCOV - code coverage report
Current view: top level - src/importexport/mei/internal - meireader.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 28.6 % 35 10
Test Date: 2026-11-05 04:07:02

            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 "meireader.h"
      24              : 
      25              : #include "translation.h"
      26              : 
      27              : #include "engraving/engravingerrors.h"
      28              : #include "engraving/dom/masterscore.h"
      29              : 
      30              : #include "meiimporter.h"
      31              : #include "meiconverter.h"
      32              : 
      33              : using namespace muse;
      34              : using namespace mu::iex::mei;
      35              : using namespace mu::engraving;
      36              : 
      37            0 : Ret MeiReader::read(MasterScore* score, const muse::io::path_t& path, const Options& options)
      38              : {
      39            0 :     Err result = this->import(score, path, options);
      40            0 :     return (result == Err::NoError) ? muse::make_ok() : make_ret(result, path);
      41              : }
      42              : 
      43           64 : Err MeiReader::import(MasterScore* score, const muse::io::path_t& path, const Options& options)
      44              : {
      45           64 :     if (!fileSystem()->exists(path)) {
      46            0 :         return Err::FileNotFound;
      47              :     }
      48              : 
      49           64 :     MeiImporter importer(score);
      50           64 :     if (!importer.read(path)) {
      51            0 :         return Err::FileCriticallyCorrupted;
      52              :     }
      53              : 
      54           64 :     bool forceMode = false;
      55           64 :     if (options.count(INotationReader::OptionKey::ForceMode)) {
      56            0 :         Val val = options.at(INotationReader::OptionKey::ForceMode);
      57            0 :         forceMode = (!val.isNull() && val.toBool());
      58            0 :     }
      59              : 
      60           64 :     bool hasWarnings = (Convert::logs.size() > 0);
      61              : 
      62           64 :     if (!forceMode && !MScore::noGui && hasWarnings) {
      63            0 :         int numLogs = static_cast<int>(Convert::logs.size());
      64            0 :         const String text = muse::qtrc("iex_mei", "%Ln problem(s) occurred and the import may be incomplete.",
      65            0 :                                        nullptr, numLogs);
      66            0 :         if (!this->askToLoadDespiteWarnings(text, Convert::logs.join(u"\n"))) {
      67            0 :             return Err::FileBadFormat;
      68              :         }
      69            0 :     }
      70              : 
      71           64 :     return Err::NoError;
      72           64 : }
      73              : 
      74              : /**
      75              :  * Show a dialog displaying the MEI import problem(s) and ask whether to load or cancel.
      76              :  */
      77            0 : bool MeiReader::askToLoadDespiteWarnings(const String& title, const String& detailedText)
      78              : {
      79            0 :     IInteractive::Text t;
      80            0 :     t.text = muse::trc("iex_mei", "Do you want to try to load this MEI file anyway?");
      81            0 :     t.detailedText = detailedText.toStdString();
      82              : 
      83            0 :     IInteractive::Button btn = interactive()->warningSync(
      84            0 :         title.toStdString(), t, {
      85            0 :         interactive()->buttonData(IInteractive::Button::Cancel),
      86            0 :         interactive()->buttonData(IInteractive::Button::Yes)
      87            0 :     }, (int)IInteractive::Button::Yes).standardButton();
      88              : 
      89            0 :     return btn == IInteractive::Button::Yes;
      90            0 : }
        

Generated by: LCOV version 2.0-1