LCOV - code coverage report
Current view: top level - src/engraving/rw/compat - readchordlisthook.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 87.1 % 31 27
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              : #include "readchordlisthook.h"
      23              : 
      24              : #include "style/style.h"
      25              : 
      26              : #include "dom/score.h"
      27              : 
      28              : #include "log.h"
      29              : 
      30              : using namespace mu::engraving::compat;
      31              : using namespace mu::engraving;
      32              : 
      33          813 : ReadChordListHook::ReadChordListHook(Score* score)
      34          813 :     : m_score(score)
      35              : {
      36          813 :     if (m_score) {
      37          813 :         m_oldChordDescriptionFile = m_score->style().styleSt(Sid::chordDescriptionFile);
      38              :     }
      39          813 : }
      40              : 
      41            1 : void ReadChordListHook::read(XmlReader& e)
      42              : {
      43            1 :     if (!m_score) {
      44            0 :         return;
      45              :     }
      46              : 
      47            1 :     m_score->chordList()->clear();
      48            1 :     m_score->chordList()->read(e, m_score->mscVersion());
      49            1 :     m_score->chordList()->setCustomChordList(true);
      50              : 
      51            1 :     m_chordListTag = true;
      52              : }
      53              : 
      54          813 : void ReadChordListHook::validate()
      55              : {
      56          813 :     if (!m_score) {
      57            1 :         return;
      58              :     }
      59              : 
      60          813 :     if (m_chordListTag) {
      61              :         // if we encountered a ChordList tag, everything is fine already
      62            1 :         return;
      63              :     }
      64              : 
      65              :     // if we just specified a new chord description file
      66              :     // and didn't encounter a ChordList tag
      67              :     // then load the chord description file
      68              : 
      69          812 :     MStyle& style = m_score->style();
      70          812 :     ChordList* chordList = m_score->chordList();
      71              : 
      72          812 :     String newChordDescriptionFile = style.styleSt(Sid::chordDescriptionFile);
      73          812 :     if (newChordDescriptionFile != m_oldChordDescriptionFile) {
      74            2 :         if (!newChordDescriptionFile.startsWith(u"chords_")
      75            2 :             && style.styleV(Sid::chordStyle).value<ChordStylePreset>() == ChordStylePreset::STANDARD) {
      76              :             // should not normally happen,
      77              :             // but treat as "old" (114) score just in case
      78            0 :             style.set(Sid::chordStyle, ChordStylePreset::CUSTOM);
      79            0 :             style.set(Sid::chordsXmlFile, true);
      80            0 :             LOGD("StyleData::load: custom chord description file %s with chordStyle == std", muPrintable(newChordDescriptionFile));
      81              :         }
      82              : 
      83            2 :         bool custom = style.styleV(Sid::chordStyle).value<ChordStylePreset>() == ChordStylePreset::CUSTOM;
      84            2 :         chordList->setCustomChordList(custom);
      85              : 
      86            2 :         chordList->unload();
      87              :     }
      88              : 
      89              :     // make sure we have a chordlist
      90          812 :     chordList->checkChordList(style);
      91          812 : }
        

Generated by: LCOV version 2.0-1