LCOV - code coverage report
Current view: top level - src/engraving/dom - instrumentname.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 83.3 % 42 35
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 "instrumentname.h"
      24              : 
      25              : #include "measure.h"
      26              : #include "part.h"
      27              : #include "score.h"
      28              : #include "staff.h"
      29              : #include "style/style.h"
      30              : #include "system.h"
      31              : 
      32              : #include "log.h"
      33              : 
      34              : using namespace mu;
      35              : using namespace mu::engraving;
      36              : 
      37              : namespace mu::engraving {
      38              : //---------------------------------------------------------
      39              : //   longInstrumentStyle
      40              : //---------------------------------------------------------
      41              : 
      42              : static const ElementStyle longInstrumentStyle {
      43              : };
      44              : 
      45              : //---------------------------------------------------------
      46              : //   shortInstrumentStyle
      47              : //---------------------------------------------------------
      48              : 
      49              : static const ElementStyle shortInstrumentStyle {
      50              : };
      51              : 
      52              : //---------------------------------------------------------
      53              : //   InstrumentName
      54              : //---------------------------------------------------------
      55              : 
      56         3771 : InstrumentName::InstrumentName(DummyParentOr<System> s)
      57         3771 :     : TextBase(ElementType::INSTRUMENT_NAME, s, TextStyleType::INSTRUMENT_LONG, ElementFlag::NOTHING)
      58              : {
      59         3771 :     setFlag(ElementFlag::MOVABLE, false);
      60         3771 :     setInstrumentNameType(InstrumentNameType::LONG);
      61         3771 : }
      62              : 
      63       102501 : double InstrumentName::largestStaffSpatium() const
      64              : {
      65       102501 :     if (systemFlag() || (layoutParent() && layoutParent()->systemFlag())) {
      66            0 :         return style().spatium();
      67              :     }
      68              : 
      69              :     // Get spatium for instrument names from largest staff of part,
      70              :     // instead of staff it is attached to
      71       102501 :     Part* p = part();
      72       102501 :     if (!part()) {
      73            0 :         return style().spatium();
      74              :     }
      75       102501 :     double largestSpatium = 0;
      76       218259 :     for (Staff* s: p->staves()) {
      77       115758 :         double sp = s->spatium(tick());
      78       115758 :         if (sp > largestSpatium) {
      79       102501 :             largestSpatium = sp;
      80              :         }
      81              :     }
      82       102501 :     return largestSpatium;
      83              : }
      84              : 
      85              : //---------------------------------------------------------
      86              : //   setInstrumentNameType
      87              : //---------------------------------------------------------
      88              : 
      89        11746 : void InstrumentName::setInstrumentNameType(InstrumentNameType st)
      90              : {
      91        11746 :     m_instrumentNameType = st;
      92        11746 :     if (st == InstrumentNameType::SHORT) {
      93         3216 :         setTextStyleType(TextStyleType::INSTRUMENT_SHORT);
      94         3216 :         initElementStyle(&shortInstrumentStyle);
      95              :     } else {
      96         8530 :         setTextStyleType(TextStyleType::INSTRUMENT_LONG);
      97         8530 :         initElementStyle(&longInstrumentStyle);
      98              :     }
      99        11746 : }
     100              : 
     101       190304 : bool InstrumentName::setProperty(Pid id, const PropertyValue& v)
     102              : {
     103       190304 :     bool rv = true;
     104       190304 :     switch (id) {
     105            0 :     case Pid::VISIBLE:
     106              :         // not supported
     107            0 :         break;
     108       190304 :     default:
     109       190304 :         rv = TextBase::setProperty(id, v);
     110       190304 :         break;
     111              :     }
     112       190304 :     return rv;
     113              : }
     114              : 
     115        47911 : mu::engraving::staff_idx_t mu::engraving::InstrumentName::effectiveStaffIdx() const
     116              : {
     117        47911 :     if (m_sysStaff->show() || m_instrumentNameRole == InstrumentNameRole::STAFF) {
     118        47769 :         return staffIdx();
     119          142 :     } else if (m_instrumentNameRole == InstrumentNameRole::PART) {
     120          142 :         return system()->firstVisibleSysStaffOfPart(score()->staff(staffIdx())->part());
     121              :     } else {
     122            0 :         staff_idx_t curIdx = staffIdx();
     123            0 :         Instrument* instr = score()->staff(curIdx)->part()->instrument(system()->first()->tick());
     124            0 :         return system()->firstVisibleSysStaffWithInstrument(instr->id(), curIdx);
     125              :     }
     126              : }
     127              : }
        

Generated by: LCOV version 2.0-1