LCOV - code coverage report
Current view: top level - src/engraving/dom - beambase.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 80.8 % 78 63
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 "beambase.h"
      23              : 
      24              : using namespace mu::engraving;
      25              : 
      26         2945 : BeamBase::BeamBase(const ElementType& type, EngravingObject* parent, ElementFlags flags)
      27         2945 :     : EngravingItem(type, parent, flags)
      28              : {
      29         2945 : }
      30              : 
      31           26 : BeamBase::BeamBase(const BeamBase& b)
      32           26 :     : EngravingItem(b)
      33              : {
      34           26 :     m_beamSegments.reserve(b.m_beamSegments.size());
      35           63 :     for (const BeamSegment* bs : b.m_beamSegments) {
      36           37 :         m_beamSegments.push_back(new BeamSegment(*bs));
      37              :     }
      38           26 :     _crossStaffMove = b._crossStaffMove;
      39           26 :     m_direction       = b.m_direction;
      40           26 :     m_up              = b.m_up;
      41           26 :     m_userModified[0] = b.m_userModified[0];
      42           26 :     m_userModified[1] = b.m_userModified[1];
      43           26 : }
      44              : 
      45          127 : void BeamBase::undoChangeProperty(Pid id, const PropertyValue& v, PropertyFlags ps)
      46              : {
      47          127 :     if (id == Pid::BEAM_CROSS_STAFF_MOVE) {
      48            0 :         if (!acceptCrossStaffMove(v.toInt())) {
      49            0 :             return;
      50              :         }
      51            0 :         undoResetProperty(Pid::USER_MODIFIED);
      52            0 :         undoResetProperty(Pid::BEAM_POS);
      53              :     }
      54          127 :     EngravingItem::undoChangeProperty(id, v, ps);
      55              : }
      56              : 
      57        15232 : PropertyValue BeamBase::getProperty(Pid propertyId) const
      58              : {
      59        15232 :     switch (propertyId) {
      60         1620 :     case Pid::BEAM_CROSS_STAFF_MOVE:
      61         1620 :         return crossStaffMove();
      62         1627 :     case Pid::STEM_DIRECTION:
      63         1627 :         return direction();
      64            0 :     case Pid::USER_MODIFIED:
      65            0 :         return userModified();
      66        11985 :     default:
      67        11985 :         return EngravingItem::getProperty(propertyId);
      68              :     }
      69              : }
      70              : 
      71         3273 : bool BeamBase::setProperty(Pid propertyId, const PropertyValue& v)
      72              : {
      73         3273 :     switch (propertyId) {
      74         2872 :     case Pid::BEAM_CROSS_STAFF_MOVE:
      75         2872 :         setCrossStaffMove(v.toInt());
      76         2872 :         break;
      77          376 :     case Pid::STEM_DIRECTION:
      78          376 :         setDirection(v.value<DirectionV>());
      79          376 :         break;
      80            0 :     case Pid::USER_MODIFIED:
      81            0 :         setUserModified(v.toBool());
      82            0 :         break;
      83           25 :     default:
      84           25 :         if (!EngravingItem::setProperty(propertyId, v)) {
      85            0 :             return false;
      86              :         }
      87           25 :         break;
      88              :     }
      89              : 
      90         3273 :     triggerLayout();
      91         3273 :     setGenerated(false);
      92         3273 :     return true;
      93              : }
      94              : 
      95        21202 : PropertyValue BeamBase::propertyDefault(Pid propertyId) const
      96              : {
      97        21202 :     switch (propertyId) {
      98         4492 :     case Pid::BEAM_CROSS_STAFF_MOVE:
      99         4492 :         return 0;
     100         1620 :     case Pid::STEM_DIRECTION:
     101         1620 :         return DirectionV::AUTO;
     102            0 :     case Pid::USER_MODIFIED:
     103            0 :         return false;
     104        15090 :     default:
     105        15090 :         return EngravingItem::propertyDefault(propertyId);
     106              :     }
     107              : }
     108              : 
     109        30771 : int BeamBase::crossStaffIdx() const
     110              : {
     111        30771 :     return defaultCrossStaffIdx() + _crossStaffMove;
     112              : }
     113              : 
     114        30771 : int BeamBase::defaultCrossStaffIdx() const
     115              : {
     116        30771 :     double average = 0.5 * (static_cast<double>(minCRMove()) + static_cast<double>(maxCRMove()));
     117        30771 :     return std::ceil(average);
     118              : }
     119              : 
     120            0 : bool BeamBase::acceptCrossStaffMove(int move) const
     121              : {
     122            0 :     int newCrossStaffIdx = defaultCrossStaffIdx() + move;
     123            0 :     return newCrossStaffIdx >= minCRMove() && newCrossStaffIdx <= maxCRMove() + 1;
     124              : }
     125              : 
     126        87629 : bool BeamBase::userModified() const
     127              : {
     128        87629 :     int idx = directionIdx();
     129        87629 :     return m_userModified[idx];
     130              : }
     131              : 
     132            6 : void BeamBase::setUserModified(bool val)
     133              : {
     134            6 :     int idx = directionIdx();
     135            6 :     m_userModified[idx] = val;
     136            6 : }
     137              : 
     138        11701 : void BeamBase::clearBeamSegments()
     139              : {
     140        11701 :     muse::DeleteAll(m_beamSegments);
     141        11701 :     m_beamSegments.clear();
     142        11701 : }
        

Generated by: LCOV version 2.0-1