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-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              : #include "beambase.h"
      23              : 
      24              : using namespace mu::engraving;
      25              : 
      26         3269 : BeamBase::BeamBase(const ElementType& type, EngravingObject* parent, ElementFlags flags)
      27         3269 :     : EngravingItem(type, parent, flags)
      28              : {
      29         3269 : }
      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        15619 : PropertyValue BeamBase::getProperty(Pid propertyId) const
      58              : {
      59        15619 :     switch (propertyId) {
      60         1663 :     case Pid::BEAM_CROSS_STAFF_MOVE:
      61         1663 :         return crossStaffMove();
      62         1670 :     case Pid::STEM_DIRECTION:
      63         1670 :         return direction();
      64            0 :     case Pid::USER_MODIFIED:
      65            0 :         return userModified();
      66        12286 :     default:
      67        12286 :         return EngravingItem::getProperty(propertyId);
      68              :     }
      69              : }
      70              : 
      71         3597 : bool BeamBase::setProperty(Pid propertyId, const PropertyValue& v)
      72              : {
      73         3597 :     switch (propertyId) {
      74         3196 :     case Pid::BEAM_CROSS_STAFF_MOVE:
      75         3196 :         setCrossStaffMove(v.toInt());
      76         3196 :         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         3597 :     triggerLayout();
      91         3597 :     setGenerated(false);
      92         3597 :     return true;
      93              : }
      94              : 
      95        22000 : PropertyValue BeamBase::propertyDefault(Pid propertyId) const
      96              : {
      97        22000 :     switch (propertyId) {
      98         4859 :     case Pid::BEAM_CROSS_STAFF_MOVE:
      99         4859 :         return 0;
     100         1663 :     case Pid::STEM_DIRECTION:
     101         1663 :         return DirectionV::AUTO;
     102            0 :     case Pid::USER_MODIFIED:
     103            0 :         return false;
     104        15478 :     default:
     105        15478 :         return EngravingItem::propertyDefault(propertyId);
     106              :     }
     107              : }
     108              : 
     109        36759 : int BeamBase::crossStaffIdx() const
     110              : {
     111        36759 :     return defaultCrossStaffIdx() + _crossStaffMove;
     112              : }
     113              : 
     114        36759 : int BeamBase::defaultCrossStaffIdx() const
     115              : {
     116        36759 :     double average = 0.5 * (static_cast<double>(minCRMove()) + static_cast<double>(maxCRMove()));
     117        36759 :     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       103192 : bool BeamBase::userModified() const
     127              : {
     128       103192 :     int idx = directionIdx();
     129       103192 :     return m_userModified[idx];
     130              : }
     131              : 
     132            8 : void BeamBase::setUserModified(bool val)
     133              : {
     134            8 :     int idx = directionIdx();
     135            8 :     m_userModified[idx] = val;
     136            8 : }
     137              : 
     138        13340 : void BeamBase::clearBeamSegments()
     139              : {
     140        13340 :     muse::DeleteAll(m_beamSegments);
     141        13340 :     m_beamSegments.clear();
     142        13340 : }
        

Generated by: LCOV version 2.0-1