LCOV - code coverage report
Current view: top level - src/engraving/dom - clef.h Coverage Total Hit
Test: filtered_coverage.info Lines: 83.3 % 36 30
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              : #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        48319 :     ClefTypeList() {}
      49        61952 :     ClefTypeList(ClefType a, ClefType b)
      50        61952 :         : concertClef(a), transposingClef(b) {}
      51         9127 :     ClefTypeList(ClefType a)
      52         9127 :         : 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        28427 :     static int line(ClefType t) { return clefTable[int(t)].m_line; }
      74        63800 :     static int pitchOffset(ClefType t) { return clefTable[int(t)].m_pitchOffset; }
      75        27638 :     static SymId symId(ClefType t) { return clefTable[int(t)].m_symId; }
      76        26342 :     static const signed char* lines(ClefType t) { return clefTable[int(t)].m_lines; }
      77        27635 :     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        14294 :     OBJECT_ALLOCATOR(engraving, Clef)
      91         1868 :     DECLARE_CLASSOF(ElementType::CLEF)
      92              : 
      93              : public:
      94              : 
      95           70 :     Clef* clone() const override { return new Clef(*this); }
      96           14 :     void setOwnershipParent(DummyParentOr<Segment> parent) { EngravingItem::setOwnershipParent(parent); }
      97              :     double mag() const override;
      98              : 
      99       483431 :     Segment* segment() const { return (Segment*)ownershipParent(); }
     100            0 :     Measure* measure() const { return (Measure*)ownershipParent()->ownershipParent(); }
     101              : 
     102              :     bool acceptDrop(EditData&) const override;
     103              :     EngravingItem* drop(Transaction& tx, EditData&) override;
     104              : 
     105            0 :     bool isEditable() const override { return false; }
     106              : 
     107            0 :     bool isSmall() const { return m_isSmall; }
     108              :     void setSmall(bool val);
     109              : 
     110         3868 :     bool showCourtesy() const { return m_showCourtesy; }
     111         5688 :     void setShowCourtesy(bool v) { m_showCourtesy = v; }
     112              :     void undoSetShowCourtesy(bool v);
     113              :     Clef* otherClef();
     114              : 
     115              :     ClefType clefType() const;
     116              :     void setClefType(ClefType i);
     117              : 
     118          114 :     bool isCourtesy() const { return m_isCourtesy; }
     119           10 :     void setIsCourtesy(const bool v) { m_isCourtesy = v; }
     120              : 
     121            0 :     int subtype() const override { return int(clefType()); }
     122              :     TranslatableString subtypeUserName() const override;
     123              : 
     124            0 :     void setForInstrumentChange(bool forInstrumentChange) { m_forInstrumentChange = forInstrumentChange; }
     125         1106 :     bool forInstrumentChange() const { return m_forInstrumentChange; }
     126              : 
     127         1908 :     ClefTypeList clefTypeList() const { return m_clefTypes; }
     128            2 :     ClefType concertClef() const { return m_clefTypes.concertClef; }
     129            2 :     ClefType transposingClef() const { return m_clefTypes.transposingClef; }
     130              :     void setConcertClef(ClefType val);
     131              :     void setTransposingClef(ClefType val);
     132        16347 :     void setClefType(const ClefTypeList& ctl) { m_clefTypes = ctl; }
     133              :     void spatiumChanged(double oldValue, double newValue) override;
     134              : 
     135              :     PropertyValue getProperty(Pid propertyId) const override;
     136              :     bool setProperty(Pid propertyId, const PropertyValue&) override;
     137              :     PropertyValue propertyDefault(Pid id) const override;
     138              : 
     139              :     EngravingItem* nextSegmentElement() override;
     140              :     EngravingItem* prevSegmentElement() override;
     141              :     String accessibleInfo() const override;
     142              :     void clear();
     143              : 
     144              :     void changeClefToBarlinePos(ClefToBarlinePosition newPos);
     145              : 
     146            7 :     void undoChangeProperty(Pid id, const PropertyValue& v) { EngravingObject::undoChangeProperty(id, v); }
     147              :     void undoChangeProperty(Pid id, const PropertyValue& v, PropertyFlags ps) override;
     148              : 
     149          394 :     ClefToBarlinePosition clefToBarlinePosition() const { return m_clefToBarlinePosition; }
     150          566 :     void setClefToBarlinePosition(ClefToBarlinePosition val) { m_clefToBarlinePosition = val; }
     151              :     bool isHeader() const;
     152              : 
     153          711 :     bool isTrailer() const { return m_isTrailer; }
     154          335 :     void setIsTrailer(bool val) { m_isTrailer = val; }
     155              : 
     156              :     bool isMidMeasureClef() const;
     157              : 
     158            0 :     bool canBeExcludedFromOtherParts() const override { return !isHeader(); }
     159              :     void manageExclusionFromParts(bool exclude) override;
     160              : 
     161              :     struct LayoutData : public EngravingItem::LayoutData {
     162              :         SymId symId = SymId::noSym;
     163              :     };
     164        55494 :     DECLARE_LAYOUTDATA_METHODS(Clef)
     165              : 
     166              : private:
     167              : 
     168              :     friend class Factory;
     169              :     Clef(DummyParentOr<Segment> parent);
     170              : 
     171              :     bool m_showCourtesy = true;
     172              :     bool m_isSmall = false;
     173              :     bool m_forInstrumentChange = false;
     174              :     bool m_isCourtesy = false;
     175              :     bool m_isTrailer = false;
     176              :     ClefToBarlinePosition m_clefToBarlinePosition = ClefToBarlinePosition::AUTO;
     177              :     ClefTypeList m_clefTypes = ClefType::INVALID;
     178              : };
     179              : } // namespace mu::engraving
     180              : #endif
        

Generated by: LCOV version 2.0-1