LCOV - code coverage report
Current view: top level - src/engraving/dom - key.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 20 20
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 <vector>
      26              : #include <array>
      27              : 
      28              : #include "../types/types.h"
      29              : 
      30              : namespace mu::engraving {
      31              : class Score;
      32              : 
      33              : enum class AccidentalVal : signed char;
      34              : 
      35              : //---------------------------------------------------------
      36              : //   KeySym
      37              : //    position of one symbol in KeySig
      38              : //---------------------------------------------------------
      39              : 
      40              : struct KeySym {
      41              :     SymId sym = SymId::noSym;
      42              :     int line = 0;       // relative line position (first staffline: line == 0, first gap: line == 1, ...)
      43              :     Spatium xPos = 0.0_sp;    // x position in staff spatium units
      44              : };
      45              : 
      46              : //---------------------------------------------------------
      47              : //   CustDef
      48              : //    definition of one symbol in Custom KeySig
      49              : //---------------------------------------------------------
      50              : 
      51              : struct CustDef {
      52              :     int degree = 0;             // scale degree
      53              :     SymId sym = SymId::noSym;
      54              :     Spatium xAlt = 0.0_sp;    // x position alteration in spatium units (default symbol position is based on index)
      55              :     int octAlt = 0;       // octave alteration
      56              : };
      57              : 
      58              : //---------------------------------------------------------
      59              : //   KeySigEvent
      60              : //---------------------------------------------------------
      61              : 
      62              : class KeySigEvent
      63              : {
      64              : public:
      65         8104 :     KeySigEvent() = default;
      66              : 
      67              :     bool operator==(const KeySigEvent& e) const;
      68            1 :     bool operator!=(const KeySigEvent& e) const { return !(*this == e); }
      69              : 
      70              :     void setConcertKey(Key v);
      71              :     void setKey(Key v);
      72              :     void setCustom(bool val);
      73              :     void print() const;
      74              : 
      75        14253 :     Key concertKey() const { return m_concertKey; }
      76      1786637 :     Key key() const { return m_key; }
      77         5424 :     KeyMode mode() const { return m_mode; }
      78          394 :     void setMode(KeyMode m) { m_mode = m; }
      79        95838 :     bool custom() const { return m_custom; }
      80              : 
      81              :     // Jianpu tonic numbering: per key-signature override of the digit/mode mapping
      82         4987 :     JianpuNumbering jianpuNumbering() const { return m_jianpuNumbering; }
      83           12 :     void setJianpuNumbering(JianpuNumbering v) { m_jianpuNumbering = v; }
      84          345 :     Key jianpuTonicKey() const { return m_jianpuTonicKey; }
      85           12 :     void setJianpuTonicKey(Key v) { m_jianpuTonicKey = v; }
      86          343 :     KeyMode jianpuTonicMode() const { return m_jianpuTonicMode; }
      87           12 :     void setJianpuTonicMode(KeyMode v) { m_jianpuTonicMode = v; }
      88         1080 :     bool isValid() const { return m_key != Key::INVALID; }
      89         1973 :     bool isAtonal() const { return m_mode == KeyMode::NONE; }
      90            5 :     void setForInstrumentChange(bool forInstrumentChange) { m_forInstrumentChange = forInstrumentChange; }
      91         1430 :     bool forInstrumentChange() const { return m_forInstrumentChange; }
      92              :     void initFromSubtype(int);      // for backward compatibility
      93              :     int degInKey(int degree) const; // return "absolute degree"
      94              :     SymId symInKey(SymId sym, int degree) const;
      95           45 :     std::vector<CustDef>& customKeyDefs() { return m_customKeyDefs; }
      96          180 :     const std::vector<CustDef>& customKeyDefs() const { return m_customKeyDefs; }
      97              : 
      98              : private:
      99              : 
     100              :     void enforceLimits(bool transposing = false);       // if true, enforce only trnasposing, otherways both
     101              : 
     102              :     Key m_concertKey = Key::INVALID;               // -7 -> +7
     103              :     Key m_key = Key::INVALID;               // actual key, depends on staff transposition
     104              :     KeyMode m_mode = KeyMode::UNKNOWN;
     105              :     bool m_custom = false;
     106              :     bool m_forInstrumentChange = false;
     107              :     std::vector<CustDef> m_customKeyDefs;
     108              : 
     109              :     JianpuNumbering m_jianpuNumbering = JianpuNumbering::FOLLOW_SCORE_KEY;
     110              :     Key m_jianpuTonicKey = Key::C;
     111              :     KeyMode m_jianpuTonicMode = KeyMode::MAJOR;
     112              : };
     113              : 
     114              : //---------------------------------------------------------
     115              : //   AccidentalState
     116              : ///   Contains a state for every absolute staff line.
     117              : //---------------------------------------------------------
     118              : 
     119              : static const int TIE_CONTEXT = 0x10;
     120              : static const int MIN_ACC_STATE = 0;
     121              : static const int MAX_ACC_STATE = 75;
     122              : 
     123              : class AccidentalState
     124              : {
     125              : public:
     126        52569 :     AccidentalState() {}
     127              :     void init(Key key);
     128              :     void init(const KeySigEvent&);
     129              :     AccidentalVal accidentalVal(int line, bool& error) const;
     130              :     AccidentalVal accidentalVal(int line) const;
     131              :     bool forceRestateAccidental(int line) const;
     132              :     bool tieContext(int line) const;
     133              :     void setAccidentalVal(int line, AccidentalVal val, bool tieContext = false);
     134              :     void setForceRestateAccidental(int line, bool forceRestate);
     135              : 
     136              : private:
     137              : 
     138              :     uint8_t m_state[MAX_ACC_STATE] = {};      // (0 -- 4) | TIE_CONTEXT
     139              :     std::array<bool, MAX_ACC_STATE> m_forceRestateAccidental;
     140              : };
     141              : 
     142              : struct Interval;
     143              : 
     144              : enum class PreferSharpFlat : char;
     145              : extern Interval calculateInterval(Key key1, Key key2);
     146              : } // namespace mu::engraving
        

Generated by: LCOV version 2.0-1