LCOV - code coverage report
Current view: top level - src/engraving/dom - noteline.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 78.9 % 76 60
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              : #include "note.h"
      24              : #include "noteline.h"
      25              : #include "text.h"
      26              : 
      27              : namespace mu::engraving {
      28              : static const ElementStyle noteLineStyle {
      29              :     { Sid::noteLinePlacement,                  Pid::PLACEMENT },
      30              :     { Sid::noteLineFontFace,                   Pid::BEGIN_FONT_FACE },
      31              :     { Sid::noteLineFontFace,                   Pid::CONTINUE_FONT_FACE },
      32              :     { Sid::noteLineFontFace,                   Pid::END_FONT_FACE },
      33              :     { Sid::noteLineFontSize,                   Pid::BEGIN_FONT_SIZE },
      34              :     { Sid::noteLineFontSize,                   Pid::CONTINUE_FONT_SIZE },
      35              :     { Sid::noteLineFontSize,                   Pid::END_FONT_SIZE },
      36              :     { Sid::noteLineFontStyle,                  Pid::BEGIN_FONT_STYLE },
      37              :     { Sid::noteLineFontStyle,                  Pid::CONTINUE_FONT_STYLE },
      38              :     { Sid::noteLineFontStyle,                  Pid::END_FONT_STYLE },
      39              :     { Sid::noteLineAlign,                      Pid::BEGIN_TEXT_ALIGN },
      40              :     { Sid::noteLineAlign,                      Pid::CONTINUE_TEXT_ALIGN },
      41              :     { Sid::noteLineAlign,                      Pid::END_TEXT_ALIGN },
      42              :     { Sid::noteLinePosition,                   Pid::BEGIN_TEXT_POSITION },
      43              :     { Sid::noteLinePosition,                   Pid::CONTINUE_TEXT_POSITION },
      44              :     { Sid::noteLinePosition,                   Pid::END_TEXT_POSITION },
      45              :     { Sid::noteLineFontSpatiumDependent,       Pid::TEXT_SIZE_SPATIUM_DEPENDENT },
      46              :     { Sid::noteLineWidth,                      Pid::LINE_WIDTH },
      47              :     { Sid::noteLineStyle,                      Pid::LINE_STYLE },
      48              :     { Sid::noteLineDashLineLen,                Pid::DASH_LINE_LEN },
      49              :     { Sid::noteLineDashGapLen,                 Pid::DASH_GAP_LEN },
      50              :     { Sid::noteLineEndLineArrowHeight,         Pid::END_LINE_ARROW_HEIGHT },
      51              :     { Sid::noteLineEndLineArrowWidth,          Pid::END_LINE_ARROW_WIDTH },
      52              :     { Sid::noteLineBeginLineArrowHeight,       Pid::BEGIN_LINE_ARROW_HEIGHT },
      53              :     { Sid::noteLineBeginLineArrowWidth,        Pid::BEGIN_LINE_ARROW_WIDTH },
      54              :     { Sid::noteLineEndFilledArrowHeight,       Pid::END_FILLED_ARROW_HEIGHT },
      55              :     { Sid::noteLineEndFilledArrowWidth,        Pid::END_FILLED_ARROW_WIDTH },
      56              :     { Sid::noteLineBeginFilledArrowHeight,     Pid::BEGIN_FILLED_ARROW_HEIGHT },
      57              :     { Sid::noteLineBeginFilledArrowWidth,      Pid::BEGIN_FILLED_ARROW_WIDTH },
      58              :     { Sid::noteLineMusicalSymbolSize,          Pid::BEGIN_TEXT_MUSIC_SYMBOLS_SIZE },
      59              :     { Sid::noteLineMusicalSymbolSize,          Pid::CONTINUE_TEXT_MUSIC_SYMBOLS_SIZE },
      60              :     { Sid::noteLineMusicalSymbolSize,          Pid::END_TEXT_MUSIC_SYMBOLS_SIZE },
      61              :     { Sid::dummyMusicalSymbolsScale,           Pid::BEGIN_TEXT_MUSICAL_SYMBOLS_SCALE },
      62              :     { Sid::dummyMusicalSymbolsScale,           Pid::CONTINUE_TEXT_MUSICAL_SYMBOLS_SCALE },
      63              :     { Sid::dummyMusicalSymbolsScale,           Pid::END_TEXT_MUSICAL_SYMBOLS_SCALE },
      64              : };
      65              : 
      66            1 : NoteLineSegment::NoteLineSegment(NoteLine* sp)
      67            1 :     : TextLineBaseSegment(ElementType::NOTELINE_SEGMENT, sp, ElementFlag::MOVABLE)
      68              : {
      69            1 :     m_text->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
      70            1 :     m_endText->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
      71            1 : }
      72              : 
      73           13 : EngravingObject* NoteLineSegment::propertyDelegate(Pid pid) const
      74              : {
      75           13 :     if (pid == Pid::NOTELINE_PLACEMENT) {
      76            0 :         return noteLine();
      77              :     }
      78              : 
      79           13 :     return TextLineBaseSegment::propertyDelegate(pid);
      80              : }
      81              : 
      82            1 : NoteLine::NoteLine(EngravingObject* parent)
      83            1 :     : TextLineBase(ElementType::NOTELINE, parent, ElementFlag::MOVABLE)
      84              : {
      85            1 :     initElementStyle(&noteLineStyle);
      86              : 
      87              :     static const std::array<Pid, 18> propertiesToInitialise {
      88              :         Pid::BEGIN_TEXT,
      89              :         Pid::CONTINUE_TEXT,
      90              :         Pid::END_TEXT,
      91              :         Pid::LINE_VISIBLE,
      92              :         Pid::BEGIN_TEXT_OFFSET,
      93              :         Pid::CONTINUE_TEXT_OFFSET,
      94              :         Pid::END_TEXT_OFFSET,
      95              :         Pid::BEGIN_HOOK_TYPE,
      96              :         Pid::END_HOOK_TYPE,
      97              :         Pid::BEGIN_TEXT_PLACE,
      98              :         Pid::CONTINUE_TEXT_PLACE,
      99              :         Pid::END_TEXT_PLACE,
     100              :         Pid::BEGIN_HOOK_HEIGHT,
     101              :         Pid::END_HOOK_HEIGHT,
     102              :         Pid::DIAGONAL,
     103              :         Pid::NOTELINE_PLACEMENT,
     104              :         Pid::GAP_BETWEEN_TEXT_AND_LINE,
     105              :         Pid::SYSTEM_FLAG
     106              :     };
     107              : 
     108           19 :     for (const Pid& pid : propertiesToInitialise) {
     109           18 :         resetProperty(pid);
     110              :     }
     111            1 : }
     112              : 
     113            0 : NoteLine::NoteLine(const NoteLine& nl)
     114            0 :     : TextLineBase(nl)
     115              : {
     116            0 : }
     117              : 
     118            1 : LineSegment* NoteLine::createLineSegment()
     119              : {
     120            1 :     NoteLineSegment* seg = new NoteLineSegment(this);
     121            1 :     seg->setTrack(track());
     122            1 :     return seg;
     123              : }
     124              : 
     125           66 : PropertyValue NoteLine::propertyDefault(Pid propertyId) const
     126              : {
     127           66 :     switch (propertyId) {
     128            9 :     case Pid::BEGIN_TEXT:
     129              :     case Pid::CONTINUE_TEXT:
     130              :     case Pid::END_TEXT:
     131            9 :         return "";
     132            3 :     case Pid::LINE_VISIBLE:
     133            3 :         return true;
     134            9 :     case Pid::BEGIN_TEXT_OFFSET:
     135              :     case Pid::CONTINUE_TEXT_OFFSET:
     136              :     case Pid::END_TEXT_OFFSET:
     137           18 :         return PointF(0, 0);
     138            6 :     case Pid::BEGIN_HOOK_TYPE:
     139              :     case Pid::END_HOOK_TYPE:
     140            6 :         return HookType::NONE;
     141            9 :     case Pid::BEGIN_TEXT_PLACE:
     142              :     case Pid::CONTINUE_TEXT_PLACE:
     143              :     case Pid::END_TEXT_PLACE:
     144            9 :         return TextPlace::LEFT;
     145            6 :     case Pid::BEGIN_HOOK_HEIGHT:
     146              :     case Pid::END_HOOK_HEIGHT:
     147            6 :         return 1.5_sp;
     148            0 :     case Pid::PLACEMENT:
     149            0 :         return PlacementV::ABOVE;
     150            1 :     case Pid::DIAGONAL:
     151            1 :         return true;
     152            1 :     case Pid::NOTELINE_PLACEMENT:
     153            2 :         return NoteLineEndPlacement::OFFSET_ENDS;
     154            3 :     case Pid::GAP_BETWEEN_TEXT_AND_LINE:
     155            3 :         return 0.5_sp;
     156            1 :     case Pid::SYSTEM_FLAG:
     157            1 :         return false;
     158            2 :     case Pid::TEXT_STYLE:
     159            2 :         return TextStyleType::NOTELINE;
     160           16 :     default:
     161           16 :         return TextLineBase::propertyDefault(propertyId);
     162              :     }
     163              : }
     164              : 
     165           51 : PropertyValue NoteLine::getProperty(Pid propertyId) const
     166              : {
     167           51 :     switch (propertyId) {
     168            2 :     case Pid::PLAY:
     169            2 :         return PropertyValue();
     170            0 :     case Pid::PLACEMENT:
     171            0 :         return PlacementV::ABOVE;
     172            0 :     case Pid::NOTELINE_PLACEMENT:
     173            0 :         return m_lineEndPlacement;
     174           49 :     default:
     175           49 :         return TextLineBase::getProperty(propertyId);
     176              :     }
     177              : }
     178              : 
     179           54 : bool NoteLine::setProperty(Pid propertyId, const PropertyValue& val)
     180              : {
     181           54 :     switch (propertyId) {
     182            0 :     case Pid::PLAY:
     183            0 :         break;
     184            1 :     case Pid::NOTELINE_PLACEMENT:
     185            1 :         setLineEndPlacement(val.value<NoteLineEndPlacement>());
     186            1 :         break;
     187           53 :     default:
     188           53 :         return TextLineBase::setProperty(propertyId, val);
     189              :     }
     190              : 
     191            1 :     return true;
     192              : }
     193              : 
     194            0 : void NoteLine::reset()
     195              : {
     196            0 :     undoResetProperty(Pid::NOTELINE_PLACEMENT);
     197            0 :     TextLineBase::reset();
     198            0 : }
     199              : 
     200           12 : Sid NoteLine::defaultPosSid() const
     201              : {
     202           12 :     return Sid::NOSTYLE;
     203              : }
     204              : } // namespace mu::engraving
        

Generated by: LCOV version 2.0-1