LCOV - code coverage report
Current view: top level - src/engraving/dom - clef.h Coverage Total Hit
Test: filtered_coverage.info Lines: 82.9 % 35 29
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              : #ifndef MU_ENGRAVING_CLEF_H
      24              : #define MU_ENGRAVING_CLEF_H
      25              : 
      26              : /**
      27              :  \file
      28              :  Definition of classes Clef
      29              : */
      30              : 
      31              : #include "engravingitem.h"
      32              : 
      33              : namespace mu::engraving {
      34              : class Transaction;
      35              : class Factory;
      36              : class Segment;
      37              : 
      38              : static const int NO_CLEF = -1000;
      39              : 
      40              : //---------------------------------------------------------
      41              : //   ClefTypeList
      42              : //---------------------------------------------------------
      43              : 
      44              : struct ClefTypeList {
      45              :     ClefType concertClef = ClefType::G;
      46              :     ClefType transposingClef = ClefType::G;
      47              : 
      48        47280 :     ClefTypeList() {}
      49        56102 :     ClefTypeList(ClefType a, ClefType b)
      50        56102 :         : concertClef(a), transposingClef(b) {}
      51         8357 :     ClefTypeList(ClefType a)
      52         8357 :         : concertClef(a), transposingClef(a) {}
      53              :     bool operator==(const ClefTypeList& t) const;
      54              :     bool operator!=(const ClefTypeList& t) const;
      55              : };
      56              : 
      57              : //---------------------------------------------------------
      58              : //   ClefInfo
      59              : ///   Info about a clef.
      60              : //---------------------------------------------------------
      61              : 
      62              : struct ClefInfo
      63              : {
      64              :     static const ClefInfo clefTable[];
      65              : 
      66              :     ClefType m_type = ClefType::INVALID;
      67              :     int m_line = 0;                 ///< Line positioning on the staff
      68              :     int m_pitchOffset = 0;          ///< Pitch offset for line 0.
      69              :     signed char m_lines[14];
      70              :     SymId m_symId = SymId::noSym;
      71              :     StaffGroup m_staffGroup = StaffGroup::STANDARD;
      72              : 
      73        25254 :     static int line(ClefType t) { return clefTable[int(t)].m_line; }
      74        60416 :     static int pitchOffset(ClefType t) { return clefTable[int(t)].m_pitchOffset; }
      75        24461 :     static SymId symId(ClefType t) { return clefTable[int(t)].m_symId; }
      76        23079 :     static const signed char* lines(ClefType t) { return clefTable[int(t)].m_lines; }
      77        24462 :     static StaffGroup staffGroup(ClefType t) { return clefTable[int(t)].m_staffGroup; }
      78              : };
      79              : 
      80              : //---------------------------------------------------------
      81              : //   @@ Clef
      82              : ///    Graphic representation of a clef.
      83              : //
      84              : //   @P showCourtesy  bool    show/hide courtesy clef when applicable
      85              : //   @P isSmall       bool    small, mid-staff clef (read only, set by layout)
      86              : //---------------------------------------------------------
      87              : 
      88              : class Clef final : public EngravingItem
      89              : {
      90        12817 :     OBJECT_ALLOCATOR(engraving, Clef)
      91         1866 :     DECLARE_CLASSOF(ElementType::CLEF)
      92              : 
      93              : public:
      94              : 
      95           70 :     Clef* clone() const override { return new Clef(*this); }
      96              :     double mag() const override;
      97              : 
      98       446713 :     Segment* segment() const { return (Segment*)ownershipParent(); }
      99            0 :     Measure* measure() const { return (Measure*)ownershipParent()->ownershipParent(); }
     100              : 
     101              :     bool acceptDrop(EditData&) const override;
     102              :     EngravingItem* drop(Transaction& tx, EditData&) override;
     103              : 
     104            0 :     bool isEditable() const override { return false; }
     105              : 
     106            0 :     bool isSmall() const { return m_isSmall; }
     107              :     void setSmall(bool val);
     108              : 
     109         3730 :     bool showCourtesy() const { return m_showCourtesy; }
     110         5021 :     void setShowCourtesy(bool v) { m_showCourtesy = v; }
     111              :     void undoSetShowCourtesy(bool v);
     112              :     Clef* otherClef();
     113              : 
     114              :     ClefType clefType() const;
     115              :     void setClefType(ClefType i);
     116              : 
     117          114 :     bool isCourtesy() const { return m_isCourtesy; }
     118           10 :     void setIsCourtesy(const bool v) { m_isCourtesy = v; }
     119              : 
     120            0 :     int subtype() const override { return int(clefType()); }
     121              :     TranslatableString subtypeUserName() const override;
     122              : 
     123            0 :     void setForInstrumentChange(bool forInstrumentChange) { m_forInstrumentChange = forInstrumentChange; }
     124         1106 :     bool forInstrumentChange() const { return m_forInstrumentChange; }
     125              : 
     126         1839 :     ClefTypeList clefTypeList() const { return m_clefTypes; }
     127            2 :     ClefType concertClef() const { return m_clefTypes.concertClef; }
     128            2 :     ClefType transposingClef() const { return m_clefTypes.transposingClef; }
     129              :     void setConcertClef(ClefType val);
     130              :     void setTransposingClef(ClefType val);
     131        13837 :     void setClefType(const ClefTypeList& ctl) { m_clefTypes = ctl; }
     132              :     void spatiumChanged(double oldValue, double newValue) override;
     133              : 
     134              :     PropertyValue getProperty(Pid propertyId) const override;
     135              :     bool setProperty(Pid propertyId, const PropertyValue&) override;
     136              :     PropertyValue propertyDefault(Pid id) const override;
     137              : 
     138              :     EngravingItem* nextSegmentElement() override;
     139              :     EngravingItem* prevSegmentElement() override;
     140              :     String accessibleInfo() const override;
     141              :     void clear();
     142              : 
     143              :     void changeClefToBarlinePos(ClefToBarlinePosition newPos);
     144              : 
     145            7 :     void undoChangeProperty(Pid id, const PropertyValue& v) { EngravingObject::undoChangeProperty(id, v); }
     146              :     void undoChangeProperty(Pid id, const PropertyValue& v, PropertyFlags ps) override;
     147              : 
     148          394 :     ClefToBarlinePosition clefToBarlinePosition() const { return m_clefToBarlinePosition; }
     149          566 :     void setClefToBarlinePosition(ClefToBarlinePosition val) { m_clefToBarlinePosition = val; }
     150              :     bool isHeader() const;
     151              : 
     152          711 :     bool isTrailer() const { return m_isTrailer; }
     153          335 :     void setIsTrailer(bool val) { m_isTrailer = val; }
     154              : 
     155              :     bool isMidMeasureClef() const;
     156              : 
     157            0 :     bool canBeExcludedFromOtherParts() const override { return !isHeader(); }
     158              :     void manageExclusionFromParts(bool exclude) override;
     159              : 
     160              :     struct LayoutData : public EngravingItem::LayoutData {
     161              :         SymId symId = SymId::noSym;
     162              :     };
     163        48757 :     DECLARE_LAYOUTDATA_METHODS(Clef)
     164              : 
     165              : private:
     166              : 
     167              :     friend class Factory;
     168              :     Clef(DummyParentOr<Segment> parent);
     169              : 
     170              :     bool m_showCourtesy = true;
     171              :     bool m_isSmall = false;
     172              :     bool m_forInstrumentChange = false;
     173              :     bool m_isCourtesy = false;
     174              :     bool m_isTrailer = false;
     175              :     ClefToBarlinePosition m_clefToBarlinePosition = ClefToBarlinePosition::AUTO;
     176              :     ClefTypeList m_clefTypes = ClefType::INVALID;
     177              : };
     178              : } // namespace mu::engraving
     179              : #endif
        

Generated by: LCOV version 2.0-1