LCOV - code coverage report
Current view: top level - src/engraving/dom - harmonicmark.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 94.4 % 72 68
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 "harmonicmark.h"
      24              : 
      25              : #include "score.h"
      26              : #include "system.h"
      27              : #include "text.h"
      28              : 
      29              : using namespace mu;
      30              : using namespace mu::engraving;
      31              : 
      32              : namespace mu::engraving {
      33              : static const ElementStyle harmonicMarkStyle {
      34              :     { Sid::letRingFontFace,                      Pid::BEGIN_FONT_FACE },
      35              :     { Sid::letRingFontFace,                      Pid::CONTINUE_FONT_FACE },
      36              :     { Sid::letRingFontFace,                      Pid::END_FONT_FACE },
      37              :     { Sid::letRingFontSize,                      Pid::BEGIN_FONT_SIZE },
      38              :     { Sid::letRingFontSize,                      Pid::CONTINUE_FONT_SIZE },
      39              :     { Sid::letRingFontSize,                      Pid::END_FONT_SIZE },
      40              :     { Sid::letRingFontStyle,                     Pid::BEGIN_FONT_STYLE },
      41              :     { Sid::letRingFontStyle,                     Pid::CONTINUE_FONT_STYLE },
      42              :     { Sid::letRingFontStyle,                     Pid::END_FONT_STYLE },
      43              :     { Sid::letRingTextAlign,                     Pid::BEGIN_TEXT_ALIGN },
      44              :     { Sid::letRingTextAlign,                     Pid::CONTINUE_TEXT_ALIGN },
      45              :     { Sid::letRingTextAlign,                     Pid::END_TEXT_ALIGN },
      46              :     { Sid::letRingPosition,                      Pid::BEGIN_TEXT_POSITION },
      47              :     { Sid::letRingPosition,                      Pid::CONTINUE_TEXT_POSITION },
      48              :     { Sid::letRingPosition,                      Pid::END_TEXT_POSITION },
      49              :     { Sid::letRingHookHeight,                    Pid::BEGIN_HOOK_HEIGHT },
      50              :     { Sid::letRingHookHeight,                    Pid::END_HOOK_HEIGHT },
      51              :     { Sid::letRingLineStyle,                     Pid::LINE_STYLE },
      52              :     { Sid::letRingDashLineLen,                   Pid::DASH_LINE_LEN },
      53              :     { Sid::letRingDashGapLen,                    Pid::DASH_GAP_LEN },
      54              :     { Sid::letRingFontSpatiumDependent,          Pid::TEXT_SIZE_SPATIUM_DEPENDENT },
      55              :     { Sid::letRingEndHookType,                   Pid::END_HOOK_TYPE },
      56              :     { Sid::letRingLineWidth,                     Pid::LINE_WIDTH },
      57              :     { Sid::ottava8VAPlacement,                   Pid::PLACEMENT },
      58              : 
      59              :     { Sid::letRingMusicalSymbolSize,             Pid::BEGIN_TEXT_MUSIC_SYMBOLS_SIZE },
      60              :     { Sid::letRingMusicalSymbolSize,             Pid::CONTINUE_TEXT_MUSIC_SYMBOLS_SIZE },
      61              :     { Sid::letRingMusicalSymbolSize,             Pid::END_TEXT_MUSIC_SYMBOLS_SIZE },
      62              :     { Sid::dummyMusicalSymbolsScale,             Pid::BEGIN_TEXT_MUSICAL_SYMBOLS_SCALE },
      63              :     { Sid::dummyMusicalSymbolsScale,             Pid::CONTINUE_TEXT_MUSICAL_SYMBOLS_SCALE },
      64              :     { Sid::dummyMusicalSymbolsScale,             Pid::END_TEXT_MUSICAL_SYMBOLS_SCALE },
      65              : };
      66              : 
      67           29 : HarmonicMarkSegment::HarmonicMarkSegment(HarmonicMark* sp)
      68           29 :     : TextLineBaseSegment(ElementType::HARMONIC_MARK_SEGMENT, sp, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
      69              : {
      70           29 :     m_text->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
      71           29 :     m_endText->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
      72           29 : }
      73              : 
      74              : //---------------------------------------------------------
      75              : //   HarmonicMark
      76              : //---------------------------------------------------------
      77              : 
      78           91 : HarmonicMark::HarmonicMark(DummyParentOr<EngravingItem> parent)
      79           91 :     : ChordTextLineBase(ElementType::HARMONIC_MARK, parent)
      80              : {
      81           91 :     initElementStyle(&harmonicMarkStyle);
      82           91 :     resetProperty(Pid::LINE_VISIBLE);
      83              : 
      84           91 :     resetProperty(Pid::BEGIN_TEXT_PLACE);
      85           91 :     resetProperty(Pid::BEGIN_TEXT);
      86           91 :     resetProperty(Pid::CONTINUE_TEXT_PLACE);
      87           91 :     resetProperty(Pid::CONTINUE_TEXT);
      88           91 :     resetProperty(Pid::END_TEXT_PLACE);
      89           91 :     resetProperty(Pid::END_TEXT);
      90           91 : }
      91              : 
      92         3487 : bool HarmonicMark::setProperty(Pid propertyId, const PropertyValue& value)
      93              : {
      94         3487 :     if (propertyId == Pid::BEGIN_TEXT || propertyId == Pid::CONTINUE_TEXT) {
      95          182 :         m_text = value.value<String>();
      96              :     }
      97              : 
      98         3487 :     return TextLineBase::setProperty(propertyId, value);
      99              : }
     100              : 
     101              : static const ElementStyle harmonicMarkSegmentStyle {
     102              :     { Sid::letRingMinDistance,    Pid::MIN_DISTANCE },
     103              : };
     104              : 
     105              : //---------------------------------------------------------
     106              : //   createLineSegment
     107              : //---------------------------------------------------------
     108              : 
     109           29 : LineSegment* HarmonicMark::createLineSegment()
     110              : {
     111           29 :     HarmonicMarkSegment* hm = new HarmonicMarkSegment(this);
     112           29 :     hm->setTrack(track());
     113           29 :     hm->initElementStyle(&harmonicMarkSegmentStyle);
     114           29 :     return hm;
     115              : }
     116              : 
     117              : //---------------------------------------------------------
     118              : //   propertyDefault
     119              : //---------------------------------------------------------
     120              : 
     121         2495 : PropertyValue HarmonicMark::propertyDefault(Pid propertyId) const
     122              : {
     123         2495 :     switch (propertyId) {
     124            2 :     case Pid::LINE_WIDTH:
     125            2 :         return style().styleV(Sid::letRingLineWidth);
     126              : 
     127            0 :     case Pid::ALIGN:
     128            0 :         return Align(AlignH::LEFT, AlignV::BASELINE);
     129              : 
     130            2 :     case Pid::LINE_STYLE:
     131            2 :         return style().styleV(Sid::letRingLineStyle);
     132              : 
     133          151 :     case Pid::LINE_VISIBLE:
     134          151 :         return true;
     135              : 
     136          120 :     case Pid::CONTINUE_TEXT_OFFSET:
     137              :     case Pid::END_TEXT_OFFSET:
     138          120 :         return PropertyValue::fromValue(PointF(0, 0));
     139              : 
     140            2 :     case Pid::BEGIN_FONT_STYLE:
     141            2 :         return style().styleV(Sid::letRingFontStyle);
     142              : 
     143          302 :     case Pid::BEGIN_TEXT:
     144              :     case Pid::CONTINUE_TEXT:
     145          302 :         return PropertyValue::fromValue(m_text); // TODO: fix the style
     146          151 :     case Pid::END_TEXT:
     147          151 :         return "";
     148              : 
     149           60 :     case Pid::BEGIN_HOOK_TYPE:
     150           60 :         return HookType::NONE;
     151              : 
     152          453 :     case Pid::BEGIN_TEXT_PLACE:
     153              :     case Pid::CONTINUE_TEXT_PLACE:
     154              :     case Pid::END_TEXT_PLACE:
     155          453 :         return TextPlace::AUTO;
     156              : 
     157           58 :     case Pid::TEXT_STYLE:
     158           58 :         return TextStyleType::LET_RING;
     159              : 
     160          480 :     case Pid::BEGIN_FILLED_ARROW_HEIGHT:   // No arrow endings for harmonic mark
     161              :     case Pid::BEGIN_FILLED_ARROW_WIDTH:
     162              :     case Pid::END_FILLED_ARROW_HEIGHT:
     163              :     case Pid::END_FILLED_ARROW_WIDTH:
     164              :     case Pid::BEGIN_LINE_ARROW_HEIGHT:
     165              :     case Pid::BEGIN_LINE_ARROW_WIDTH:
     166              :     case Pid::END_LINE_ARROW_HEIGHT:
     167              :     case Pid::END_LINE_ARROW_WIDTH:
     168          480 :         return 0.0;
     169              : 
     170          714 :     default:
     171          714 :         return TextLineBase::propertyDefault(propertyId);
     172              :     }
     173              : }
     174              : 
     175              : //---------------------------------------------------------
     176              : //   getPropertyStyle
     177              : //---------------------------------------------------------
     178              : 
     179         2844 : Sid HarmonicMark::getPropertyStyle(Pid id) const
     180              : {
     181         2844 :     switch (id) {
     182           93 :     case Pid::PLACEMENT:
     183           93 :         return Sid::ottava8VAPlacement;
     184           93 :     case Pid::BEGIN_FONT_FACE:
     185           93 :         return Sid::letRingFontFace;
     186          279 :     case Pid::BEGIN_FONT_SIZE:
     187              :     case Pid::CONTINUE_FONT_SIZE:
     188              :     case Pid::END_FONT_SIZE:
     189          279 :         return Sid::letRingFontSize;
     190          277 :     case Pid::BEGIN_FONT_STYLE:
     191              :     case Pid::CONTINUE_FONT_STYLE:
     192              :     case Pid::END_FONT_STYLE:
     193          277 :         return Sid::letRingFontStyle;
     194          279 :     case Pid::BEGIN_TEXT_ALIGN:
     195              :     case Pid::CONTINUE_TEXT_ALIGN:
     196              :     case Pid::END_TEXT_ALIGN:
     197          279 :         return Sid::letRingTextAlign;
     198          186 :     case Pid::BEGIN_HOOK_HEIGHT:
     199              :     case Pid::END_HOOK_HEIGHT:
     200          186 :         return Sid::letRingHookHeight;
     201         1637 :     default:
     202         1637 :         break;
     203              :     }
     204         1637 :     return TextLineBase::getPropertyStyle(id);
     205              : }
     206              : 
     207            0 : Sid HarmonicMark::defaultPosSid() const
     208              : {
     209            0 :     return placeAbove() ? Sid::letRingPosAbove : Sid::letRingPosBelow;
     210              : }
     211              : }
        

Generated by: LCOV version 2.0-1