LCOV - code coverage report
Current view: top level - src/engraving/dom - rest.h Coverage Total Hit
Test: filtered_coverage.info Lines: 92.9 % 28 26
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 "containers.h"
      26              : 
      27              : #include "chordrest.h"
      28              : #include "notedot.h"
      29              : 
      30              : namespace mu::engraving {
      31              : class TDuration;
      32              : class Transaction;
      33              : 
      34              : struct RestVerticalClearance {
      35              : public:
      36        10731 :     void reset()
      37              :     {
      38        10731 :         m_above = 1000; // arbitrary high value
      39        10731 :         m_below = 1000; // arbitrary high value
      40        10731 :         m_locked = false;
      41        10731 :     }
      42              : 
      43          795 :     int above() const { return m_above; }
      44          971 :     int below() const { return m_below; }
      45         1006 :     void setAbove(int v) { m_above = std::max(std::min(m_above, v), 0); }
      46          798 :     void setBelow(int v) { m_below = std::max(std::min(m_below, v), 0); }
      47              : 
      48            9 :     bool locked() const { return m_locked; }
      49          389 :     void setLocked(bool v) { m_locked = v; }
      50              : 
      51              : private:
      52              :     int m_above = 0.0; // In space units
      53              :     int m_below = 0.0; // In space units
      54              :     bool m_locked = false;
      55              : };
      56              : 
      57              : //---------------------------------------------------------
      58              : //    @@ Rest
      59              : ///     This class implements a rest.
      60              : //---------------------------------------------------------
      61              : 
      62              : class Rest : public ChordRest
      63              : {
      64        51198 :     OBJECT_ALLOCATOR(engraving, Rest)
      65         1350 :     DECLARE_CLASSOF(ElementType::REST)
      66              : 
      67              : public:
      68              : 
      69        49258 :     ~Rest() { muse::DeleteAll(m_dots); }
      70              : 
      71              :     void hack_toRestType();
      72              : 
      73              :     Rest& operator=(const Rest&) = delete;
      74              : 
      75          627 :     Rest* clone() const override { return new Rest(*this, false); }
      76          375 :     void setOwnershipParent(DummyParentOr<Segment> parent) { EngravingItem::setOwnershipParent(parent); }
      77         1129 :     EngravingItem* linkedClone() override { return new Rest(*this, true); }
      78      1970923 :     Measure* measure() const override { return ownershipParent() ? toMeasure(ownershipParent()->ownershipParent()) : 0; }
      79              :     double mag() const override;
      80              :     double intrinsicMag() const override;
      81              : 
      82              :     void scanElements(std::function<void(EngravingItem*)> func) override;
      83              :     void setTrack(track_idx_t val) override;
      84              : 
      85              :     bool acceptDrop(EditData&) const override;
      86              :     EngravingItem* drop(Transaction& tx, EditData&) override;
      87              : 
      88       623381 :     bool isGap() const { return m_gap; }
      89         2494 :     virtual void setGap(bool v) { m_gap = v; }
      90              : 
      91              :     virtual void add(EngravingItem*) override;
      92              :     virtual void remove(EngravingItem*) override;
      93              : 
      94              :     void checkDots();
      95              : 
      96              :     NoteDot* dot(int n);
      97              :     const std::vector<NoteDot*>& dotList() const;
      98        75509 :     int dotLine() const { return m_dotline; }
      99        75509 :     void setDotLine(int l) { m_dotline = l; }
     100              : 
     101              :     static int getDotline(DurationType durationType);
     102              :     bool accent();
     103              :     void setAccent(bool flag);
     104              : 
     105              :     bool isWholeRest() const;
     106              :     bool isBreveRest() const;
     107              : 
     108        75789 :     DeadSlapped* deadSlapped() const { return m_deadSlapped; }
     109              : 
     110              :     double rightEdge() const override;
     111              :     double centerX() const;
     112              : 
     113        16564 :     bool alignWithOtherRests() const { return m_alignWithOtherRests; }
     114            0 :     void setAlignWithOtherRests(bool v) { m_alignWithOtherRests = v; }
     115              : 
     116              :     void localSpatiumChanged(double oldValue, double newValue) override;
     117              :     PropertyValue propertyDefault(Pid) const override;
     118              :     void resetProperty(Pid id) override;
     119              :     bool setProperty(Pid propertyId, const PropertyValue& v) override;
     120              :     PropertyValue getProperty(Pid propertyId) const override;
     121              :     void undoChangeDotsVisible(bool v);
     122              : 
     123              :     EngravingItem* nextElement() override;
     124              :     EngravingItem* prevElement() override;
     125              :     String accessibleInfo() const override;
     126              :     String screenReaderInfo() const override;
     127              : 
     128              :     bool shouldNotBeDrawn() const;
     129              :     bool debugDrawGap() const;
     130              : 
     131        13770 :     RestVerticalClearance& verticalClearance() { return m_verticalClearance; }
     132              : 
     133              :     struct LayoutData : public ChordRest::LayoutData {
     134              :         std::vector<Rest*> mergedRests;     // Rests from other voices that may be merged with this
     135              :         ld_field<SymId> sym = { "[Rest] sym", SymId::restQuarter };
     136              :     };
     137       397463 :     DECLARE_LAYOUTDATA_METHODS(Rest)
     138              : 
     139              :     SymId getSymbol(DurationType type, int line, int lines) const;
     140              :     double symWidthNoLedgerLines(LayoutData* ldata) const;
     141              : 
     142              : protected:
     143              :     Rest(const ElementType& type, DummyParentOr<Segment> parent);
     144              :     Rest(const ElementType& type, DummyParentOr<Segment> parent, const TDuration&);
     145              :     Rest(const Rest&, bool link = false);
     146              : 
     147              :     Sid getPropertyStyle(Pid pid) const override;
     148            0 :     virtual RectF numberRect() const { return RectF(); } // TODO: add style to show number over 1-measure rests
     149              : 
     150              : private:
     151              : 
     152              :     friend class Factory;
     153              :     Rest(DummyParentOr<Segment> parent);
     154              :     Rest(DummyParentOr<Segment> parent, const TDuration&);
     155              : 
     156              :     RectF drag(EditData&) override;
     157              :     double upPos() const override;
     158              :     double downPos() const override;
     159              :     void setOffset(const PointF& o) override;
     160              : 
     161              :     // values calculated by layout:
     162              : 
     163              :     int m_dotline = -1;             // depends on rest symbol
     164              :     bool m_gap = false;             // invisible and not selectable for user
     165              :     std::vector<NoteDot*> m_dots;
     166              :     DeadSlapped* m_deadSlapped = nullptr;
     167              : 
     168              :     RestVerticalClearance m_verticalClearance;
     169              : 
     170              :     bool m_alignWithOtherRests = true;
     171              : };
     172              : }
        

Generated by: LCOV version 2.0-1