LCOV - code coverage report
Current view: top level - src/engraving/dom - chordrest.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 50.6 % 718 363
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              : 
      23              : #include "chordrest.h"
      24              : 
      25              : #include "translation.h"
      26              : 
      27              : #include "types/typesconv.h"
      28              : 
      29              : #include "actionicon.h"
      30              : #include "barline.h"
      31              : #include "beam.h"
      32              : #include "breath.h"
      33              : #include "chord.h"
      34              : #include "clef.h"
      35              : #include "factory.h"
      36              : #include "figuredbass.h"
      37              : #include "harmony.h"
      38              : #include "harppedaldiagram.h"
      39              : #include "hook.h"
      40              : #include "instrchange.h"
      41              : #include "jianpudurationline.h"
      42              : #include "keysig.h"
      43              : #include "lyrics.h"
      44              : #include "marker.h"
      45              : #include "measure.h"
      46              : #include "note.h"
      47              : #include "page.h"
      48              : #include "part.h"
      49              : #include "rehearsalmark.h"
      50              : #include "score.h"
      51              : #include "segment.h"
      52              : #include "slur.h"
      53              : #include "staff.h"
      54              : #include "stafftype.h"
      55              : #include "system.h"
      56              : #include "tabdurationsymbol.h"
      57              : #include "tuplet.h"
      58              : #include "utils.h"
      59              : #include "volta.h"
      60              : 
      61              : #include "editing/editclef.h"
      62              : #include "editing/editkeysig.h"
      63              : #include "editing/editrehearsalmark.h"
      64              : #include "editing/navigation.h"
      65              : #include "editing/editstavesharing.h"
      66              : #include "editing/splitjoinmeasure.h"
      67              : #include "editing/transaction/transaction.h"
      68              : #include "editing/transpose.h"
      69              : 
      70              : #include "rendering/iscorerenderer.h"
      71              : 
      72              : #include "log.h"
      73              : 
      74              : using namespace mu;
      75              : using namespace mu::engraving;
      76              : 
      77              : namespace mu::engraving {
      78              : //---------------------------------------------------------
      79              : //   ChordRest
      80              : //---------------------------------------------------------
      81              : 
      82        57797 : ChordRest::ChordRest(const ElementType& type, DummyParentOr<Segment, Chord> parent)
      83        57797 :     : DurationElement(type, parent)
      84              : {
      85        57797 :     m_staffMove    = 0;
      86        57797 :     m_beam         = 0;
      87        57797 :     m_tabDur       = 0;
      88        57797 :     m_beamMode     = BeamMode::AUTO;
      89        57797 :     m_isSmall     = false;
      90        57797 :     m_melismaEnd   = false;
      91        57797 :     m_crossMeasure = CrossMeasure::UNKNOWN;
      92        57797 : }
      93              : 
      94         5721 : ChordRest::ChordRest(const ChordRest& cr, bool link)
      95         5721 :     : DurationElement(cr, link)
      96              : {
      97         5721 :     m_durationType = cr.m_durationType;
      98         5721 :     m_staffMove    = cr.m_staffMove;
      99         5721 :     m_beam         = 0;
     100         5721 :     m_tabDur       = 0;    // tab sur. symb. depends upon context: can't be
     101              :                            // simply copied from another CR
     102              : 
     103         5721 :     m_beamMode     = cr.m_beamMode;
     104         5721 :     m_isSmall     = cr.m_isSmall;
     105         5721 :     m_melismaEnd   = cr.m_melismaEnd;
     106         5721 :     m_crossMeasure = cr.m_crossMeasure;
     107              : 
     108         5723 :     for (Lyrics* l : cr.m_lyrics) {          // make deep copy
     109            2 :         Lyrics* nl = Factory::copyLyrics(*l);
     110            2 :         if (link) {
     111            0 :             nl->linkTo(l);
     112              :         }
     113            2 :         nl->setOwnershipParent(this);
     114            2 :         nl->setTrack(track());
     115            2 :         m_lyrics.push_back(nl);
     116              :     }
     117         5721 : }
     118              : 
     119              : //---------------------------------------------------------
     120              : //   undoUnlink
     121              : //---------------------------------------------------------
     122              : 
     123          494 : void ChordRest::undoUnlink()
     124              : {
     125          494 :     DurationElement::undoUnlink();
     126          500 :     for (Lyrics* l : m_lyrics) {
     127            6 :         l->undoUnlink();
     128              :     }
     129          494 : }
     130              : 
     131              : //---------------------------------------------------------
     132              : //   ChordRest
     133              : //---------------------------------------------------------
     134              : 
     135        57445 : ChordRest::~ChordRest()
     136              : {
     137        57445 :     muse::DeleteAll(m_lyrics);
     138        57445 :     muse::DeleteAll(m_el);
     139        57445 :     muse::DeleteAll(m_jianpuDurationLines);
     140        57445 :     delete m_tabDur;
     141              : 
     142        57445 :     if (m_beam) {
     143         8122 :         muse::remove(m_beam->elements(), this);
     144         8122 :         m_beam = nullptr;
     145              :     }
     146              : 
     147        57445 :     if (m_beamlet) {
     148           95 :         m_beamlet = nullptr;
     149              :     }
     150        57445 : }
     151              : 
     152              : //---------------------------------------------------------
     153              : //   drop
     154              : //---------------------------------------------------------
     155              : 
     156            9 : bool ChordRest::acceptDrop(EditData& data) const
     157              : {
     158            9 :     EngravingItem* e = data.dropElement;
     159              : 
     160            9 :     switch (e->type()) {
     161            9 :     case ElementType::FERMATA:
     162              :     case ElementType::CLEF:
     163              :     case ElementType::KEYSIG:
     164              :     case ElementType::TIMESIG:
     165              :     case ElementType::SYSTEM_TEXT:
     166              :     case ElementType::TRIPLET_FEEL:
     167              :     case ElementType::STAFF_TEXT:
     168              :     case ElementType::PLAYTECH_ANNOTATION:
     169              :     case ElementType::CAPO:
     170              :     case ElementType::BAR_LINE:
     171              :     case ElementType::BREATH:
     172              :     case ElementType::STAFF_STATE:
     173              :     case ElementType::INSTRUMENT_CHANGE:
     174              :     case ElementType::DYNAMIC:
     175              :     case ElementType::EXPRESSION:
     176              :     case ElementType::HARMONY:
     177              :     case ElementType::TEMPO_TEXT:
     178              :     case ElementType::REHEARSAL_MARK:
     179              :     case ElementType::FRET_DIAGRAM:
     180              :     case ElementType::TREMOLOBAR:
     181              :     case ElementType::HARP_DIAGRAM:
     182            9 :         return true;
     183            0 :     case ElementType::ACTION_ICON: {
     184            0 :         switch (toActionIcon(e)->actionType()) {
     185            0 :         case ActionIconType::BEAM_AUTO:
     186              :         case ActionIconType::BEAM_NONE:
     187              :         case ActionIconType::BEAM_BREAK_LEFT:
     188              :         case ActionIconType::BEAM_BREAK_INNER_8TH:
     189              :         case ActionIconType::BEAM_BREAK_INNER_16TH:
     190              :         case ActionIconType::BEAM_JOIN:
     191            0 :             return true;
     192            0 :         case ActionIconType::STAVE_SHARING_CHANGE:
     193              :         case ActionIconType::RESET_STAVE_SHARING_CHANGE:
     194            0 :             return part() && part()->isSharedPart();
     195            0 :         default: break;
     196              :         }
     197            0 :         break;
     198              :     }
     199            0 :     default: break;
     200              :     }
     201            0 :     return measure()->acceptDrop(data);
     202              : }
     203              : 
     204           30 : EngravingItem* ChordRest::drop(Transaction& tx, EditData& data)
     205              : {
     206           30 :     EngravingItem* e = data.dropElement;
     207           30 :     Measure* m       = measure();
     208           30 :     bool fromPalette = (e->track() == muse::nidx);
     209           30 :     switch (e->type()) {
     210           13 :     case ElementType::BREATH:
     211              :     {
     212           13 :         Breath* b = toBreath(e);
     213           13 :         b->setPos(PointF());
     214              :         // allow breath marks in voice > 1
     215           13 :         b->setTrack(track());
     216           13 :         b->setPlacement(b->track() & 1 ? PlacementV::BELOW : PlacementV::ABOVE);
     217              : 
     218              :         // TODO: insert automatically in all staves?
     219              : 
     220           13 :         Segment* seg = m->undoGetSegment(SegmentType::Breath, endTick());
     221              : 
     222           13 :         if (seg->element(b->track())) {
     223              :             // Already a breath present, change its symbol
     224            0 :             Breath* existingBreath = toBreath(seg->element(b->track()));
     225            0 :             existingBreath->undoChangeProperty(Pid::SYMBOL, b->symId());
     226            0 :             delete b;
     227            0 :             return existingBreath;
     228              :         } else {
     229           13 :             b->setOwnershipParent(seg);
     230           13 :             score()->undoAddElement(b);
     231           13 :             return e;
     232              :         }
     233              :     }
     234              : 
     235            0 :     case ElementType::BAR_LINE:
     236              :     {
     237            0 :         BarLine* bl = toBarLine(e);
     238            0 :         Fraction barLineTick = bl->barLineType() == BarLineType::START_REPEAT ? tick() : endTick();
     239              : 
     240            0 :         if (data.control()) {
     241            0 :             SplitJoinMeasure::splitMeasure(tx, masterScore(), barLineTick);
     242            0 :             m = score()->tick2measure(tick());
     243              :             // consume the ControlModifier flag
     244            0 :             data.modifiers &= ~ControlModifier;
     245              :         }
     246              : 
     247            0 :         if (barLineTick == m->tick() || barLineTick == m->endTick()) {
     248            0 :             return m->drop(tx, data);
     249              :         }
     250              : 
     251            0 :         bl->setPos(PointF());
     252            0 :         bl->setTrack(staffIdx() * VOICES);
     253            0 :         bl->setGenerated(false);
     254              : 
     255            0 :         BarLine* obl = nullptr;
     256            0 :         for (Staff* st : staff()->staffList()) {
     257            0 :             Score* score = st->score();
     258            0 :             Measure* measure = score->tick2measure(m->tick());
     259            0 :             Segment* seg = measure->undoGetSegment(SegmentType::BarLine, barLineTick);
     260              :             BarLine* l;
     261            0 :             if (!obl) {
     262            0 :                 obl = l = bl->clone();
     263              :             } else {
     264            0 :                 l = toBarLine(obl->linkedClone());
     265              :             }
     266            0 :             l->setTrack(st->idx() * VOICES);
     267            0 :             l->setOwnershipParent(seg);
     268            0 :             score->undoAddElement(l);
     269            0 :         }
     270              : 
     271            0 :         delete e;
     272            0 :         return nullptr;
     273              :     }
     274              : 
     275            0 :     case ElementType::CLEF:
     276            0 :         EditClef::insertClef(tx, score(), toClef(e), this);
     277            0 :         return nullptr;
     278              : 
     279            0 :     case ElementType::FERMATA:
     280            0 :         e->setPlacement(track() & 1 ? PlacementV::BELOW : PlacementV::ABOVE);
     281            0 :         for (EngravingItem* el: segment()->annotations()) {
     282            0 :             if (el->isFermata() && (el->track() == track())) {
     283            0 :                 if (el->subtype() == e->subtype()) {
     284            0 :                     delete e;
     285            0 :                     return el;
     286              :                 } else {
     287            0 :                     e->setPlacement(el->placement());
     288            0 :                     e->setTrack(track());
     289            0 :                     e->setOwnershipParent(segment());
     290            0 :                     score()->undoChangeElement(el, e);
     291            0 :                     return e;
     292              :                 }
     293              :             }
     294              :         }
     295              :         [[fallthrough]];
     296              :     case ElementType::TEMPO_TEXT:
     297              :     case ElementType::EXPRESSION:
     298              :     case ElementType::FRET_DIAGRAM:
     299              :     case ElementType::TREMOLOBAR:
     300              :     case ElementType::SYMBOL:
     301              :     case ElementType::IMAGE:
     302            0 :         e->setTrack(track());
     303            0 :         e->setOwnershipParent(segment());
     304            0 :         score()->undoAddElement(e);
     305            0 :         return e;
     306              : 
     307            5 :     case ElementType::DYNAMIC:
     308            5 :         e->setTrack(track());
     309            5 :         e->checkVoiceAssignmentCompatibleWithTrack();
     310            5 :         e->setOwnershipParent(segment());
     311            5 :         score()->undoAddElement(e);
     312            5 :         return e;
     313              : 
     314            1 :     case ElementType::NOTE: {
     315            1 :         Note* note = toNote(e);
     316              :         // calculate correct transposed tpc
     317            1 :         Interval v = staff()->transpose(tick());
     318            1 :         v.flip();
     319            1 :         note->setTpc2(Transpose::transposeTpc(note->tpc1(), v, true));
     320              : 
     321            1 :         Segment* seg = segment();
     322            1 :         score()->undoRemoveElement(this);
     323            1 :         Chord* chord = Factory::createChord(score()->dummy());
     324            1 :         chord->setTrack(track());
     325            1 :         chord->setDurationType(durationType());
     326            1 :         chord->setTicks(ticks());
     327            1 :         chord->setTuplet(tuplet());
     328            1 :         chord->add(note);
     329            1 :         score()->undoAddCR(chord, seg->measure(), seg->tick());
     330            1 :         return note;
     331              :     }
     332              : 
     333            0 :     case ElementType::HARMONY:
     334              :     {
     335              :         // transpose
     336            0 :         Harmony* harmony = toHarmony(e);
     337            0 :         Interval interval = staff()->transpose(tick());
     338            0 :         if (!style().styleB(Sid::concertPitch) && !interval.isZero()) {
     339            0 :             interval.flip();
     340            0 :             Transpose::undoTransposeHarmony(tx, harmony, interval);
     341              :         }
     342              :     }
     343              :         [[fallthrough]];
     344           10 :     case ElementType::TEXT:
     345              :     case ElementType::STAFF_TEXT:
     346              :     case ElementType::SYSTEM_TEXT:
     347              :     case ElementType::TRIPLET_FEEL:
     348              :     case ElementType::PLAYTECH_ANNOTATION:
     349              :     case ElementType::CAPO:
     350              :     case ElementType::STICKING:
     351              :     case ElementType::STAFF_STATE:
     352              :     case ElementType::HARP_DIAGRAM:
     353              :     case ElementType::REHEARSAL_MARK:
     354              :     {
     355           10 :         e->setOwnershipParent(segment());
     356           10 :         e->setTrack(trackZeroVoice(track()));
     357           10 :         if (e->isRehearsalMark() && fromPalette) {
     358            0 :             RehearsalMark* r = toRehearsalMark(e);
     359            0 :             r->setXmlText(EditRehearsalMark::createRehearsalMarkText(score(), r));
     360           10 :         } else if (e->isHarpPedalDiagram() && fromPalette && originPart()) {
     361              :             // Match pedal config with previous diagram's
     362            5 :             if (HarpPedalDiagram* prevDiagram = originPart()->prevHarpDiagram(segment()->tick())) {
     363            4 :                 toHarpPedalDiagram(e)->setPedalState(prevDiagram->getPedalState());
     364              :             }
     365              :         }
     366           10 :         score()->undoAddElement(e);
     367           10 :         return e;
     368              :     }
     369            1 :     case ElementType::INSTRUMENT_CHANGE:
     370            1 :         if (part()->instruments().find(tick().ticks()) != part()->instruments().end()) {
     371            0 :             LOGD() << "InstrumentChange already exists at tick = " << tick().ticks();
     372            0 :             delete e;
     373            0 :             return nullptr;
     374              :         } else {
     375            1 :             InstrumentChange* ic = toInstrumentChange(e);
     376            1 :             ic->setOwnershipParent(segment());
     377            1 :             ic->setTrack(trackZeroVoice(track()));
     378              : 
     379            1 :             const Instrument* prevInstr = part()->instrument(tick());
     380            1 :             const Instrument instr = *ic->instrument();
     381              : 
     382            1 :             IF_ASSERT_FAILED(prevInstr) {
     383            0 :                 delete e;
     384            0 :                 return nullptr;
     385              :             }
     386              : 
     387              :             // temporarily set previous instrument, for correct transposition calculation
     388            1 :             ic->setInstrument(*prevInstr);
     389            1 :             score()->undoAddElement(ic);
     390              : 
     391            1 :             if (!fromPalette) {
     392            1 :                 ic->setupInstrument(&instr, /*updateText*/ false);
     393              :             }
     394            1 :             return e;
     395            1 :         }
     396            0 :     case ElementType::FIGURED_BASS:
     397              :     {
     398              :         bool bNew;
     399            0 :         FiguredBass* fb = toFiguredBass(e);
     400            0 :         fb->setOwnershipParent(segment());
     401            0 :         fb->setTrack(trackZeroVoice(track()));
     402            0 :         fb->setTicks(ticks());
     403            0 :         fb->setOnNote(true);
     404            0 :         FiguredBass::addFiguredBassToSegment(segment(), fb->track(), fb->ticks(), &bNew);
     405            0 :         if (bNew) {
     406            0 :             score()->undoAddElement(e);
     407              :         }
     408            0 :         return e;
     409              :     }
     410              : 
     411            0 :     case ElementType::ACTION_ICON:
     412              :     {
     413            0 :         ActionIconType actionType = toActionIcon(e)->actionType();
     414              :         static const std::unordered_map<ActionIconType, BeamMode> beamModeTable = {
     415              :             { ActionIconType::BEAM_AUTO,             BeamMode::AUTO },
     416              :             { ActionIconType::BEAM_NONE,             BeamMode::NONE },
     417              :             { ActionIconType::BEAM_BREAK_LEFT,       BeamMode::BEGIN },
     418              :             { ActionIconType::BEAM_BREAK_INNER_8TH,  BeamMode::BEGIN16 },
     419              :             { ActionIconType::BEAM_BREAK_INNER_16TH, BeamMode::BEGIN32 },
     420              :             { ActionIconType::BEAM_JOIN,             BeamMode::MID },
     421            0 :         };
     422            0 :         if (muse::contains(beamModeTable, actionType)) {
     423            0 :             undoChangeProperty(Pid::BEAM_MODE, muse::value(beamModeTable, actionType));
     424            0 :             delete e;
     425            0 :             return nullptr;
     426              :         }
     427            0 :         if (actionType == ActionIconType::STAVE_SHARING_CHANGE || actionType == ActionIconType::RESET_STAVE_SHARING_CHANGE) {
     428            0 :             bool reset = actionType == ActionIconType::RESET_STAVE_SHARING_CHANGE;
     429            0 :             EditStaveSharing::addStaveSharingChange(tx, segment(), part(), reset);
     430            0 :             delete e;
     431            0 :             return nullptr;
     432              :         }
     433            0 :         break;
     434              :     }
     435              : 
     436            0 :     case ElementType::KEYSIG:
     437              :     {
     438            0 :         if (data.modifiers & ControlModifier) {
     439              :             // apply only to this stave
     440            0 :             KeySigEvent k = toKeySig(e)->keySigEvent();
     441            0 :             EditKeySig::undoChangeKeySig(tx, score(), staff(), tick(), k);
     442            0 :             delete e;
     443            0 :             return nullptr;
     444            0 :         }
     445            0 :         break;
     446              :     }
     447              : 
     448            0 :     default:
     449            0 :         if (e->isSpanner()) {
     450            0 :             Spanner* spanner = toSpanner(e);
     451            0 :             spanner->setTick(tick());
     452            0 :             if (spanner->systemFlag()) {
     453            0 :                 spanner->setTrack(0);
     454            0 :                 spanner->setTrack2(0);
     455              :             } else {
     456            0 :                 spanner->setTrack(track());
     457            0 :                 spanner->setTrack2(track());
     458              :             }
     459            0 :             score()->undoAddElement(spanner);
     460            0 :             return e;
     461              :         }
     462            0 :         break;
     463              :     }
     464            0 :     return m->drop(tx, data);
     465              : }
     466              : 
     467              : //---------------------------------------------------------
     468              : //   beam
     469              : //---------------------------------------------------------
     470              : 
     471      2913910 : Beam* ChordRest::beam() const
     472              : {
     473      2913910 :     return !(measure() && measure()->stemless(staffIdx())) ? m_beam : nullptr;
     474              : }
     475              : 
     476              : //---------------------------------------------------------
     477              : //   setBeam
     478              : //---------------------------------------------------------
     479              : 
     480        12595 : void ChordRest::setBeam(Beam* b)
     481              : {
     482        12595 :     m_beam = b;
     483        12595 : }
     484              : 
     485       219884 : void ChordRest::setBeamlet(BeamSegment* b)
     486              : {
     487       219884 :     m_beamlet = b;
     488       219884 : }
     489              : 
     490              : //---------------------------------------------------------
     491              : //   setDurationType
     492              : //---------------------------------------------------------
     493              : 
     494        53006 : void ChordRest::setDurationType(DurationType t)
     495              : {
     496        53006 :     m_durationType.setType(t);
     497        53006 :     m_crossMeasure = CrossMeasure::UNKNOWN;
     498        53006 : }
     499              : 
     500           41 : void ChordRest::setDurationType(const Fraction& ticks)
     501              : {
     502           41 :     m_durationType.setVal(ticks.ticks());
     503           41 :     m_crossMeasure = CrossMeasure::UNKNOWN;
     504           41 : }
     505              : 
     506        28309 : void ChordRest::setDurationType(TDuration v)
     507              : {
     508        28309 :     m_durationType = v;
     509        28309 :     m_crossMeasure = CrossMeasure::UNKNOWN;
     510        28309 : }
     511              : 
     512              : //---------------------------------------------------------
     513              : //   durationUserName
     514              : //---------------------------------------------------------
     515              : 
     516            0 : String ChordRest::durationUserName() const
     517              : {
     518            0 :     String tupletType;
     519            0 :     if (tuplet()) {
     520            0 :         switch (tuplet()->ratio().numerator()) {
     521            0 :         case 2:
     522            0 :             tupletType = muse::mtrc("engraving", "Duplet");
     523            0 :             break;
     524            0 :         case 3:
     525            0 :             tupletType = muse::mtrc("engraving", "Triplet");
     526            0 :             break;
     527            0 :         case 4:
     528            0 :             tupletType = muse::mtrc("engraving", "Quadruplet");
     529            0 :             break;
     530            0 :         case 5:
     531            0 :             tupletType = muse::mtrc("engraving", "Quintuplet");
     532            0 :             break;
     533            0 :         case 6:
     534            0 :             tupletType = muse::mtrc("engraving", "Sextuplet");
     535            0 :             break;
     536            0 :         case 7:
     537            0 :             tupletType = muse::mtrc("engraving", "Septuplet");
     538            0 :             break;
     539            0 :         case 8:
     540            0 :             tupletType = muse::mtrc("engraving", "Octuplet");
     541            0 :             break;
     542            0 :         case 9:
     543            0 :             tupletType = muse::mtrc("engraving", "Nonuplet");
     544            0 :             break;
     545            0 :         default:
     546              :             //: %1 is tuplet ratio numerator (i.e. the number of notes in the tuplet)
     547            0 :             tupletType = muse::mtrc("engraving", "%1 note tuplet").arg(tuplet()->ratio().numerator());
     548              :         }
     549              :     }
     550            0 :     String dotString;
     551            0 :     if (!tupletType.isEmpty()) {
     552            0 :         dotString += u' ';
     553              :     }
     554              : 
     555            0 :     switch (dots()) {
     556            0 :     case 1:
     557            0 :         dotString += muse::mtrc("engraving", "Dotted %1").arg(TConv::translatedUserName(durationType().type()));
     558            0 :         break;
     559            0 :     case 2:
     560            0 :         dotString += muse::mtrc("engraving", "Double dotted %1").arg(TConv::translatedUserName(durationType().type()));
     561            0 :         break;
     562            0 :     case 3:
     563            0 :         dotString += muse::mtrc("engraving", "Triple dotted %1").arg(TConv::translatedUserName(durationType().type()));
     564            0 :         break;
     565            0 :     case 4:
     566            0 :         dotString += muse::mtrc("engraving", "Quadruple dotted %1").arg(TConv::translatedUserName(durationType().type()));
     567            0 :         break;
     568            0 :     default:
     569            0 :         dotString += TConv::translatedUserName(durationType().type());
     570              :     }
     571            0 :     return String(u"%1%2").arg(tupletType, dotString);
     572            0 : }
     573              : 
     574              : //---------------------------------------------------------
     575              : //   add
     576              : //---------------------------------------------------------
     577              : 
     578         1872 : void ChordRest::add(EngravingItem* e)
     579              : {
     580         1872 :     e->setOwnershipParent(this);
     581         1872 :     e->setTrack(track());
     582         1872 :     switch (e->type()) {
     583            0 :     case ElementType::ARTICULATION:             // for backward compatibility
     584            0 :         LOGD("ChordRest::add: unknown element %s", e->typeName());
     585            0 :         break;
     586         1872 :     case ElementType::LYRICS:
     587         1872 :         m_lyrics.push_back(toLyrics(e));
     588         1872 :         e->added();
     589         1872 :         break;
     590            0 :     default:
     591            0 :         EngravingItem::add(e);
     592            0 :         break;
     593              :     }
     594         1872 : }
     595              : 
     596              : //---------------------------------------------------------
     597              : //   remove
     598              : //---------------------------------------------------------
     599              : 
     600           23 : void ChordRest::remove(EngravingItem* e)
     601              : {
     602           23 :     switch (e->type()) {
     603           23 :     case ElementType::LYRICS: {
     604           23 :         toLyrics(e)->removeFromScore();
     605           23 :         auto i = std::find(m_lyrics.begin(), m_lyrics.end(), toLyrics(e));
     606           23 :         if (i != m_lyrics.end()) {
     607           23 :             m_lyrics.erase(i);
     608           23 :             e->removed();
     609              :         } else {
     610            0 :             LOGD("ChordRest::remove: %s %p not found", e->typeName(), e);
     611              :         }
     612              :     }
     613           23 :     break;
     614            0 :     default:
     615            0 :         EngravingItem::remove(e);
     616              :     }
     617           23 : }
     618              : 
     619              : //---------------------------------------------------------
     620              : //   removeDeleteBeam
     621              : ///   Remove ChordRest from beam, delete beam if empty.
     622              : ///   \param beamed - if the chordrest is beamed (will get
     623              : ///                   a (new) beam)
     624              : //---------------------------------------------------------
     625              : 
     626        87263 : void ChordRest::removeDeleteBeam(bool beamed)
     627              : {
     628        87263 :     setBeamlet(nullptr);
     629        87263 :     if (m_beam) {
     630          256 :         Beam* b = m_beam;
     631          256 :         m_beam->remove(this);
     632          256 :         if (b->empty()) {
     633           96 :             score()->doUndoRemoveElement(b);
     634              :         } else {
     635          160 :             renderer()->layoutBeam1(b);
     636              :         }
     637              :     }
     638        87263 :     if (!beamed && isChord()) {
     639        36705 :         Chord* c = toChord(this);
     640        36705 :         if (c->shouldHaveHook()) {
     641         2243 :             if (!c->hook()) {
     642         1337 :                 c->createHook();
     643              :             }
     644        34462 :         } else if (c->hook()) {
     645           21 :             score()->doUndoRemoveElement(c->hook());
     646              :         }
     647        36705 :         renderer()->layoutStem(c);
     648              :     }
     649        87263 : }
     650              : 
     651            0 : void ChordRest::computeUp()
     652              : {
     653            0 :     UNREACHABLE;
     654              : }
     655              : 
     656              : //---------------------------------------------------------
     657              : //   replaceBeam
     658              : //---------------------------------------------------------
     659              : 
     660        13893 : void ChordRest::replaceBeam(Beam* newBeam)
     661              : {
     662        13893 :     if (m_beam == newBeam) {
     663         6200 :         return;
     664              :     }
     665         7693 :     removeDeleteBeam(true);
     666         7693 :     newBeam->add(this);
     667              : }
     668              : 
     669           14 : Slur* ChordRest::slur(const ChordRest* secondChordRest) const
     670              : {
     671           14 :     if (secondChordRest == nullptr) {
     672            7 :         ChordRestNavigateOptions options;
     673            7 :         options.disableOverRepeats = true;
     674            7 :         secondChordRest = Navigation::nextChordRest(const_cast<ChordRest*>(this), options);
     675              :     }
     676           14 :     int currentTick = tick().ticks();
     677           14 :     Slur* result = nullptr;
     678           15 :     for (auto it : score()->spannerMap().findOverlapping(currentTick, currentTick + 1)) {
     679            3 :         Spanner* spanner = it.value;
     680            3 :         if (!spanner->isSlur()) {
     681            0 :             continue;
     682              :         }
     683            3 :         Slur* slur = toSlur(spanner);
     684            3 :         if (slur->startElement() == this && slur->endElement() == secondChordRest) {
     685            2 :             if (slur->slurDirection() == DirectionV::AUTO) {
     686            2 :                 return slur;
     687              :             }
     688            0 :             result = slur;
     689              :         }
     690              :     }
     691           12 :     return result;
     692              : }
     693              : 
     694          818 : void ChordRest::undoChangeProperty(Pid id, const PropertyValue& newValue, PropertyFlags ps)
     695              : {
     696          818 :     if (id == Pid::BEAM_MODE) {
     697           46 :         if (isChord() && m_durationType.hooks() == 0) {
     698           43 :             const StaffType* tab = staffType();
     699           43 :             if (!tab || !tab->isTabStaff() || !tab->genDurations()) {
     700           37 :                 return;
     701              :             }
     702              :         }
     703            9 :         BeamMode newBeamMode = newValue.value<BeamMode>();
     704            1 :         if ((newBeamMode == BeamMode::BEGIN16 && m_durationType.hooks() < 2)
     705           10 :             || (newBeamMode == BeamMode::BEGIN32 && m_durationType.hooks() < 3)) {
     706            2 :             return;
     707              :         }
     708              :     }
     709              : 
     710          779 :     EngravingItem::undoChangeProperty(id, newValue, ps);
     711              : }
     712              : 
     713              : //---------------------------------------------------------
     714              : //   localSpatiumChanged
     715              : //---------------------------------------------------------
     716              : 
     717            0 : void ChordRest::localSpatiumChanged(double oldValue, double newValue)
     718              : {
     719            0 :     DurationElement::localSpatiumChanged(oldValue, newValue);
     720            0 :     for (EngravingItem* e : lyrics()) {
     721            0 :         e->localSpatiumChanged(oldValue, newValue);
     722              :     }
     723            0 :     for (EngravingItem* e : el()) {
     724            0 :         e->localSpatiumChanged(oldValue, newValue);
     725              :     }
     726            0 : }
     727              : 
     728              : //---------------------------------------------------------
     729              : //   getProperty
     730              : //---------------------------------------------------------
     731              : 
     732       411945 : PropertyValue ChordRest::getProperty(Pid propertyId) const
     733              : {
     734       411945 :     switch (propertyId) {
     735        33781 :     case Pid::SMALL:      return PropertyValue::fromValue(isSmall());
     736           35 :     case Pid::BEAM_MODE:  return beamMode();
     737        33669 :     case Pid::STAFF_MOVE: return staffMove();
     738          224 :     case Pid::DURATION_TYPE_WITH_DOTS: return actualDurationType().typeWithDots();
     739       344236 :     default:              return DurationElement::getProperty(propertyId);
     740              :     }
     741              : }
     742              : 
     743              : //---------------------------------------------------------
     744              : //   setProperty
     745              : //---------------------------------------------------------
     746              : 
     747          485 : bool ChordRest::setProperty(Pid propertyId, const PropertyValue& v)
     748              : {
     749          485 :     switch (propertyId) {
     750           56 :     case Pid::SMALL:
     751           56 :         setSmall(v.toBool());
     752           56 :         break;
     753           18 :     case Pid::BEAM_MODE:
     754           18 :         setBeamMode(v.value<BeamMode>());
     755           18 :         break;
     756            0 :     case Pid::STAFF_MOVE:
     757            0 :         setStaffMove(v.toInt());
     758            0 :         break;
     759            1 :     case Pid::VISIBLE:
     760            1 :         setVisible(v.toBool());
     761            1 :         measure()->checkMultiVoices(staffIdx());
     762            1 :         break;
     763           80 :     case Pid::DURATION_TYPE_WITH_DOTS:
     764           80 :         setDurationType(v.value<DurationTypeWithDots>());
     765           80 :         break;
     766          330 :     default:
     767          330 :         return DurationElement::setProperty(propertyId, v);
     768              :     }
     769          155 :     triggerLayout();
     770          155 :     return true;
     771              : }
     772              : 
     773              : //---------------------------------------------------------
     774              : //   propertyDefault
     775              : //---------------------------------------------------------
     776              : 
     777       371156 : PropertyValue ChordRest::propertyDefault(Pid propertyId) const
     778              : {
     779       371156 :     switch (propertyId) {
     780        33669 :     case Pid::SMALL:
     781        33669 :         return false;
     782            0 :     case Pid::BEAM_MODE:
     783            0 :         return BeamMode::AUTO;
     784        33669 :     case Pid::STAFF_MOVE:
     785        33669 :         return 0;
     786       303818 :     default:
     787       303818 :         return DurationElement::propertyDefault(propertyId);
     788              :     }
     789              :     // Prevent unreachable code warning
     790              :     // triggerLayout();
     791              : }
     792              : 
     793              : //---------------------------------------------------------
     794              : //   isGrace
     795              : //---------------------------------------------------------
     796              : 
     797       224029 : bool ChordRest::isGrace() const
     798              : {
     799       224029 :     return isChord() && toChord(this)->isGrace();
     800              : }
     801              : 
     802              : //---------------------------------------------------------
     803              : //   isGraceBefore
     804              : //---------------------------------------------------------
     805              : 
     806         8117 : bool ChordRest::isGraceBefore() const
     807              : {
     808         8117 :     return isChord()
     809         8117 :            && (toChord(this)->noteType() & (
     810              :                    NoteType::ACCIACCATURA | NoteType::APPOGGIATURA | NoteType::GRACE4 | NoteType::GRACE16 | NoteType::GRACE32
     811         8117 :                    ));
     812              : }
     813              : 
     814              : //---------------------------------------------------------
     815              : //   isGraceAfter
     816              : //---------------------------------------------------------
     817              : 
     818        22101 : bool ChordRest::isGraceAfter() const
     819              : {
     820        22101 :     return isChord()
     821        22101 :            && (toChord(this)->noteType() & (NoteType::GRACE8_AFTER | NoteType::GRACE16_AFTER | NoteType::GRACE32_AFTER));
     822              : }
     823              : 
     824              : //---------------------------------------------------------
     825              : //   hasBreathMark - determine if chordrest has breath-mark
     826              : //---------------------------------------------------------
     827         8231 : Breath* ChordRest::hasBreathMark() const
     828              : {
     829         8231 :     Segment* s = measure()->findSegment(SegmentType::Breath, endTick());
     830         8231 :     return s ? toBreath(s->element(track())) : nullptr;
     831              : }
     832              : 
     833              : //---------------------------------------------------------
     834              : //   nextSegmentAfterCR
     835              : //    returns first segment at tick CR->tick + CR->actualTicks
     836              : //    of given types
     837              : //---------------------------------------------------------
     838              : 
     839          252 : Segment* ChordRest::nextSegmentAfterCR(SegmentType types) const
     840              : {
     841          252 :     Fraction end = tick() + actualTicks();
     842          252 :     for (Segment* s = segment()->next1MM(types); s; s = s->next1MM(types)) {
     843          252 :         if (s->tick() >= end) {
     844          252 :             return s;
     845              :         }
     846              :     }
     847            0 :     return nullptr;
     848              : }
     849              : 
     850              : //---------------------------------------------------------
     851              : //   setTrack
     852              : //---------------------------------------------------------
     853              : 
     854        72830 : void ChordRest::setTrack(track_idx_t val)
     855              : {
     856        72830 :     EngravingItem::setTrack(val);
     857        74102 :     processSiblings([val](EngravingItem* e) { e->setTrack(val); });
     858        72830 : }
     859              : 
     860              : //---------------------------------------------------------
     861              : //   setScore
     862              : //---------------------------------------------------------
     863              : 
     864         8833 : void ChordRest::setScore(Score* s)
     865              : {
     866         8833 :     EngravingItem::setScore(s);
     867         9397 :     processSiblings([s](EngravingItem* e) { e->setScore(s); });
     868         8833 : }
     869              : 
     870              : //---------------------------------------------------------
     871              : //   processSiblings
     872              : //---------------------------------------------------------
     873              : 
     874        81663 : void ChordRest::processSiblings(std::function<void(EngravingItem*)> func)
     875              : {
     876        81663 :     if (m_beam) {
     877          451 :         func(m_beam);
     878              :     }
     879        81663 :     if (m_tabDur) {
     880            0 :         func(m_tabDur);
     881              :     }
     882        81670 :     for (Lyrics* l : m_lyrics) {
     883            7 :         func(l);
     884              :     }
     885        81663 :     if (tuplet()) {
     886         1368 :         func(tuplet());
     887              :     }
     888        81673 :     for (EngravingItem* e : m_el) {
     889           10 :         func(e);
     890              :     }
     891        81663 :     for (JianpuDurationLine* dl : m_jianpuDurationLines) {
     892            0 :         func(dl);
     893              :     }
     894        81663 : }
     895              : 
     896              : //---------------------------------------------------------
     897              : //   nextArticulationOrLyric
     898              : //---------------------------------------------------------
     899              : 
     900            0 : EngravingItem* ChordRest::nextArticulationOrLyric(EngravingItem* e)
     901              : {
     902            0 :     if (e->isLyrics()) {
     903              :         // The next element after Lyrics is the LyricsLine (if it exists)...
     904            0 :         if (LyricsLine* line = toLyrics(e)->separator()) {
     905            0 :             return line;
     906              :         }
     907              :     }
     908            0 :     if (e->isLyricsLine()) {
     909            0 :         LyricsLine* lyricsLine = toLyricsLine(e);
     910            0 :         Lyrics* lyrics = lyricsLine->lyrics();
     911            0 :         IF_ASSERT_FAILED(lyrics) {
     912            0 :             return nullptr;
     913              :         }
     914              :         // We were on a LyricsLine - now we'll try to move to the next Lyrics...
     915            0 :         e = lyrics;
     916              :     }
     917              : 
     918            0 :     if (!isChord() || !e->isArticulationFamily()) {
     919              :         // Move to the next Lyrics...
     920            0 :         auto i = std::find(m_lyrics.begin(), m_lyrics.end(), e);
     921            0 :         if (i == m_lyrics.end() || i == m_lyrics.end() - 1) {
     922            0 :             return nullptr;
     923              :         }
     924            0 :         return *(i + 1);
     925              :     }
     926              : 
     927              :     // Cycle through articulations...
     928            0 :     Chord* c = toChord(this);
     929            0 :     auto i = std::find(c->articulations().begin(), c->articulations().end(), e);
     930            0 :     if (i == c->articulations().end()) {
     931            0 :         return nullptr;
     932              :     }
     933            0 :     if (i != c->articulations().end() - 1) {
     934            0 :         return *(i + 1);
     935              :     }
     936            0 :     if (!m_lyrics.empty()) {
     937            0 :         return m_lyrics[0];
     938              :     }
     939              : 
     940            0 :     return nullptr;
     941              : }
     942              : 
     943              : //---------------------------------------------------------
     944              : //   prevArticulationOrLyric
     945              : //---------------------------------------------------------
     946              : 
     947            0 : EngravingItem* ChordRest::prevArticulationOrLyric(EngravingItem* e)
     948              : {
     949            0 :     const std::vector<Articulation*> artics = isChord() ? toChord(this)->articulations() : std::vector<Articulation*>();
     950              : 
     951            0 :     if (e->isLyricsLine()) {
     952              :         // The previous element to a LyricsLine is the associated Lyrics...
     953            0 :         return toLyricsLine(e)->lyrics();
     954              :     }
     955              : 
     956            0 :     auto i = std::find(m_lyrics.begin(), m_lyrics.end(), e);
     957            0 :     if (i == m_lyrics.end()) {
     958              :         // Cycle through articulations...
     959            0 :         if (artics.empty()) {
     960            0 :             return nullptr;
     961              :         }
     962            0 :         auto j = std::find(artics.begin(), artics.end(), e);
     963            0 :         if (j == artics.end() || j == artics.begin()) {
     964            0 :             return nullptr;
     965              :         }
     966            0 :         return *(j - 1);
     967              :     }
     968            0 :     if (i == m_lyrics.begin()) {
     969            0 :         return !artics.empty() ? artics.back() : nullptr;
     970              :     }
     971              : 
     972              :     // Move to the previous Lyrics...
     973            0 :     Lyrics* lyrics = *(i - 1);
     974            0 :     IF_ASSERT_FAILED(lyrics) {
     975            0 :         return nullptr;
     976              :     }
     977            0 :     if (lyrics->separator()) {
     978              :         // Move to the LyricsLine of the previous Lyrics (if it exists)...
     979            0 :         return lyrics->separator();
     980              :     }
     981            0 :     return lyrics;
     982            0 : }
     983              : 
     984              : //---------------------------------------------------------
     985              : //   nextElement
     986              : //---------------------------------------------------------
     987              : 
     988            0 : EngravingItem* ChordRest::nextElement()
     989              : {
     990            0 :     EngravingItem* e = score()->selection().element();
     991            0 :     if (!e && !score()->selection().elements().empty()) {
     992            0 :         e = score()->selection().elements().front();
     993              :     }
     994            0 :     switch (e->type()) {
     995            0 :     case ElementType::ARTICULATION:
     996              :     case ElementType::ORNAMENT:
     997              :     case ElementType::TAPPING:
     998              :     case ElementType::LYRICS:
     999              :     case ElementType::LYRICSLINE: {
    1000            0 :         EngravingItem* next = nextArticulationOrLyric(e);
    1001            0 :         if (next) {
    1002            0 :             return next;
    1003              :         } else {
    1004            0 :             break;
    1005              :         }
    1006              :     }
    1007            0 :     default: {
    1008            0 :         if (isChord() && !toChord(this)->articulations().empty()) {
    1009            0 :             return toChord(this)->articulations()[0];
    1010            0 :         } else if (!m_lyrics.empty()) {
    1011            0 :             return m_lyrics[0];
    1012              :         } else {
    1013            0 :             break;
    1014              :         }
    1015              :     }
    1016              :     }
    1017            0 :     staff_idx_t staffId = e->staffIdx();
    1018            0 :     return segment()->nextElement(staffId);
    1019              : }
    1020              : 
    1021              : //---------------------------------------------------------
    1022              : //   prevElement
    1023              : //---------------------------------------------------------
    1024              : 
    1025            0 : EngravingItem* ChordRest::prevElement()
    1026              : {
    1027            0 :     EngravingItem* e = score()->selection().element();
    1028            0 :     if (!e && !score()->selection().elements().empty()) {
    1029            0 :         e = score()->selection().elements().back();
    1030              :     }
    1031            0 :     switch (e->type()) {
    1032            0 :     case ElementType::ARTICULATION:
    1033              :     case ElementType::ORNAMENT:
    1034              :     case ElementType::TAPPING:
    1035              :     case ElementType::LYRICS:
    1036              :     case ElementType::LYRICSLINE: {
    1037            0 :         EngravingItem* prev = prevArticulationOrLyric(e);
    1038            0 :         if (prev) {
    1039            0 :             return prev;
    1040              :         } else {
    1041            0 :             if (isChord()) {
    1042            0 :                 return toChord(this)->lastElementBeforeSegment();
    1043              :             }
    1044              :         }
    1045              :         // fall through
    1046              :     }
    1047              :     default: {
    1048            0 :         break;
    1049              :     }
    1050              :     }
    1051              : 
    1052            0 :     Tuplet* tuplet = this->tuplet();
    1053            0 :     if (tuplet && this == tuplet->elements().front()) {
    1054            0 :         return tuplet;
    1055              :     }
    1056              : 
    1057            0 :     staff_idx_t staffId = e->staffIdx();
    1058            0 :     EngravingItem* prevItem = segment()->prevElement(staffId);
    1059            0 :     if (prevItem && prevItem->isNote()) {
    1060            0 :         const Chord* prevChord = toNote(prevItem)->chord();
    1061            0 :         if (prevChord && !prevChord->articulations().empty()) {
    1062            0 :             return prevChord->articulations().back();
    1063              :         }
    1064              :     }
    1065            0 :     return prevItem;
    1066              : }
    1067              : 
    1068              : //---------------------------------------------------------
    1069              : //   lastElementBeforeSegment
    1070              : //---------------------------------------------------------
    1071              : 
    1072            0 : EngravingItem* ChordRest::lastElementBeforeSegment()
    1073              : {
    1074            0 :     if (m_lyrics.empty()) {
    1075            0 :         return nullptr;
    1076              :     }
    1077            0 :     Lyrics* lyrics = m_lyrics.back();
    1078            0 :     IF_ASSERT_FAILED(lyrics) {
    1079            0 :         return nullptr;
    1080              :     }
    1081            0 :     if (LyricsLine* lyricsLine = lyrics->separator()) {
    1082            0 :         return lyricsLine;
    1083              :     }
    1084            0 :     return lyrics;
    1085              : }
    1086              : 
    1087              : //---------------------------------------------------------
    1088              : //   nextSegmentElement
    1089              : //---------------------------------------------------------
    1090              : 
    1091            0 : EngravingItem* ChordRest::nextSegmentElement()
    1092              : {
    1093            0 :     return segment()->firstInNextSegments(staffIdx());
    1094              : }
    1095              : 
    1096              : //---------------------------------------------------------
    1097              : //   scanElements
    1098              : //---------------------------------------------------------
    1099              : 
    1100        20992 : void ChordRest::scanElements(std::function<void(EngravingItem*)> func)
    1101              : {
    1102         5529 :     if (m_beam && (m_beam->elements().front() == this)
    1103        26521 :         && !measure()->stemless(staffIdx())) {
    1104         2513 :         m_beam->scanElements(func);
    1105              :     }
    1106        21220 :     for (Lyrics* l : m_lyrics) {
    1107          228 :         l->scanElements(func);
    1108              :     }
    1109        20992 :     DurationElement* de = this;
    1110        22205 :     while (de->tuplet() && de->tuplet()->elements().front() == de) {
    1111         1213 :         de->tuplet()->scanElements(func);
    1112         1213 :         de = de->tuplet();
    1113              :     }
    1114        20992 :     if (m_tabDur) {
    1115            0 :         func(m_tabDur);
    1116              :     }
    1117        20994 :     for (JianpuDurationLine* dl : m_jianpuDurationLines) {
    1118            2 :         func(dl);
    1119              :     }
    1120        20992 : }
    1121              : 
    1122              : //---------------------------------------------------------
    1123              : //   prevSegmentElement
    1124              : //---------------------------------------------------------
    1125              : 
    1126            0 : EngravingItem* ChordRest::prevSegmentElement()
    1127              : {
    1128            0 :     return segment()->lastInPrevSegments(staffIdx());
    1129              : }
    1130              : 
    1131            0 : String ChordRest::accessibleExtraInfo() const
    1132              : {
    1133            0 :     String rez;
    1134            0 :     for (EngravingItem* l : lyrics()) {
    1135            0 :         if (!score()->selectionFilter().canSelect(l)) {
    1136            0 :             continue;
    1137              :         }
    1138            0 :         rez = String(u"%1 %2").arg(rez, l->screenReaderInfo());
    1139              :     }
    1140              : 
    1141            0 :     if (segment()) {
    1142            0 :         for (EngravingItem* e : segment()->annotations()) {
    1143            0 :             if (!score()->selectionFilter().canSelect(e)) {
    1144            0 :                 continue;
    1145              :             }
    1146            0 :             if (e->track() == track()) {
    1147            0 :                 rez = String(u"%1 %2").arg(rez, e->screenReaderInfo());
    1148              :             }
    1149              :         }
    1150              : 
    1151            0 :         SpannerMap& smap = score()->spannerMap();
    1152            0 :         auto spanners = smap.findOverlapping(tick().ticks(), tick().ticks());
    1153            0 :         for (auto interval : spanners) {
    1154            0 :             Spanner* s = interval.value;
    1155            0 :             if (!score()->selectionFilter().canSelect(s)) {
    1156            0 :                 continue;
    1157              :             }
    1158              :             // voltas are added for barlines, ties are added in notes
    1159            0 :             if (s->isVolta() || s->isTie()) {
    1160            0 :                 continue;
    1161              :             }
    1162              : 
    1163            0 :             if (s->isSlur()) {
    1164            0 :                 if (s->tick() == tick() && s->track() == track()) {
    1165            0 :                     rez += u" " + muse::mtrc("engraving", "Start of %1").arg(s->screenReaderInfo());
    1166              :                 }
    1167            0 :                 if (s->tick2() == tick() && s->track2() == track()) {
    1168            0 :                     rez += u" " + muse::mtrc("engraving", "End of %1").arg(s->screenReaderInfo());
    1169              :                 }
    1170            0 :             } else if (s->staffIdx() == staffIdx()) {
    1171            0 :                 bool start = s->tick() == tick();
    1172            0 :                 bool end   = s->tick2() == tick() + ticks();
    1173            0 :                 if (start && end) {
    1174            0 :                     rez += u" " + muse::mtrc("engraving", "Start and end of %1").arg(s->screenReaderInfo());
    1175            0 :                 } else if (start) {
    1176            0 :                     rez += u" " + muse::mtrc("engraving", "Start of %1").arg(s->screenReaderInfo());
    1177            0 :                 } else if (end) {
    1178            0 :                     rez += u" " + muse::mtrc("engraving", "End of %1").arg(s->screenReaderInfo());
    1179              :                 }
    1180              :             }
    1181              :         }
    1182            0 :     }
    1183            0 :     return rez;
    1184            0 : }
    1185              : 
    1186              : //---------------------------------------------------------
    1187              : //   isMelismaEnd
    1188              : //    returns true if chordrest represents the end of a melisma
    1189              : //---------------------------------------------------------
    1190              : 
    1191        11581 : bool ChordRest::isMelismaEnd() const
    1192              : {
    1193        11581 :     return m_melismaEnd;
    1194              : }
    1195              : 
    1196              : //---------------------------------------------------------
    1197              : //   setMelismaEnd
    1198              : //---------------------------------------------------------
    1199              : 
    1200          113 : void ChordRest::setMelismaEnd(bool v)
    1201              : {
    1202          113 :     m_melismaEnd = v;
    1203              :     // TODO: don't take "false" at face value
    1204              :     // check to see if some other melisma ends here,
    1205              :     // in which case we can leave this set to true
    1206              :     // for now, rely on the fact that we'll generate the value correctly on layout
    1207          113 : }
    1208              : 
    1209              : //---------------------------------------------------------
    1210              : //   lyrics
    1211              : //---------------------------------------------------------
    1212              : 
    1213           34 : Lyrics* ChordRest::lyrics(int verse) const
    1214              : {
    1215           49 :     for (Lyrics* l : m_lyrics) {
    1216           46 :         if (l->verse() == verse) {
    1217           31 :             return l;
    1218              :         }
    1219              :     }
    1220            3 :     return 0;
    1221              : }
    1222              : 
    1223          868 : Lyrics* ChordRest::lyrics(int verse, PlacementV p) const
    1224              : {
    1225         1122 :     for (Lyrics* l : m_lyrics) {
    1226          874 :         if (l->placement() == p && l->verse() == verse) {
    1227          620 :             return l;
    1228              :         }
    1229              :     }
    1230          248 :     return 0;
    1231              : }
    1232              : 
    1233              : //---------------------------------------------------------
    1234              : //   lastVerse
    1235              : //    return last verse number (starting from 0)
    1236              : //    return -1 if there are no lyrics;
    1237              : //---------------------------------------------------------
    1238              : 
    1239            0 : int ChordRest::lastVerse(PlacementV p) const
    1240              : {
    1241            0 :     int lastVerse = -1;
    1242              : 
    1243            0 :     for (Lyrics* l : m_lyrics) {
    1244            0 :         if (l->placement() == p && l->verse() > lastVerse) {
    1245            0 :             lastVerse = l->verse();
    1246              :         }
    1247              :     }
    1248              : 
    1249            0 :     return lastVerse;
    1250              : }
    1251              : 
    1252              : //---------------------------------------------------------
    1253              : //   removeMarkings
    1254              : //    - this is normally called after cloning a chord to tie a note over the barline
    1255              : //    - there is no special undo handling; the assumption is that undo will simply remove the cloned chord
    1256              : //    - two note tremolos are converted into simple notes
    1257              : //    - single note tremolos are optionally retained
    1258              : //---------------------------------------------------------
    1259              : 
    1260          133 : void ChordRest::removeMarkings(bool /* keepTremolo */)
    1261              : {
    1262          133 :     muse::DeleteAll(el());
    1263          133 :     clearEls();
    1264          133 :     muse::DeleteAll(lyrics());
    1265          133 :     lyrics().clear();
    1266          133 : }
    1267              : 
    1268              : //---------------------------------------------------------
    1269              : //   isBefore
    1270              : //---------------------------------------------------------
    1271              : 
    1272            8 : bool ChordRest::isBefore(const EngravingItem* o) const
    1273              : {
    1274            8 :     if (!o || this == o) {
    1275            4 :         return false;
    1276              :     }
    1277              : 
    1278            4 :     const ChordRest* otherCr = nullptr;
    1279            4 :     if (o->isChordRest()) {
    1280            2 :         otherCr = toChordRest(o);
    1281            2 :     } else if (o->isNote()) {
    1282            0 :         otherCr = toNote(o)->chord();
    1283              :     }
    1284              : 
    1285            4 :     if (!otherCr) {
    1286            2 :         return EngravingItem::isBefore(o);
    1287              :     }
    1288              : 
    1289            2 :     Fraction thisTick = tick();
    1290            2 :     Fraction otherTick = otherCr->tick();
    1291            2 :     if (thisTick != otherTick) {
    1292            2 :         return thisTick < otherTick;
    1293              :     }
    1294              : 
    1295            0 :     bool thisIsGraceBefore = isGraceBefore();
    1296            0 :     bool otherIsGraceBefore = otherCr->isGraceBefore();
    1297            0 :     if (thisIsGraceBefore != otherIsGraceBefore) {
    1298            0 :         return thisIsGraceBefore;
    1299            0 :     } else if (thisIsGraceBefore) {
    1300            0 :         return toChord(this)->graceIndex() < toChord(otherCr)->graceIndex();
    1301              :     }
    1302              : 
    1303            0 :     bool thisIsGraceAfter = isGraceAfter();
    1304            0 :     bool otherIsGraceAfter = otherCr->isGraceAfter();
    1305            0 :     if (thisIsGraceAfter != otherIsGraceAfter) {
    1306            0 :         return !thisIsGraceAfter;
    1307            0 :     } else if (thisIsGraceAfter) {
    1308            0 :         return toChord(this)->graceIndex() > toChord(otherCr)->graceIndex();
    1309              :     }
    1310              : 
    1311            0 :     return false;
    1312              : }
    1313              : 
    1314        36759 : bool ChordRest::isBelowCrossBeam(const BeamBase* beamBase) const
    1315              : {
    1316        36759 :     return staffMove() >= beamBase->crossStaffIdx();
    1317              : }
    1318              : 
    1319          745 : void ChordRest::checkStaffMoveValidity()
    1320              : {
    1321          745 :     if (!staff()) {
    1322            0 :         return;
    1323              :     }
    1324          745 :     staff_idx_t idx = m_staffMove ? vStaffIdx() : staffIdx() + m_storedStaffMove;
    1325          745 :     const Staff* baseStaff = staff();
    1326          745 :     const StaffType* baseStaffType = baseStaff->staffTypeForElement(this);
    1327          745 :     const Staff* targetStaff  = score()->staff(idx);
    1328          745 :     const StaffType* targetStaffType = targetStaff ? targetStaff->staffTypeForElement(this) : nullptr;
    1329              :     // check that destination staff makes sense
    1330          745 :     const TrackRange trackRange = part()->trackRange();
    1331          745 :     staff_idx_t minStaff = track2staff(trackRange.startTrack);
    1332          745 :     staff_idx_t maxStaff = track2staff(trackRange.endTrack);
    1333          745 :     bool isDestinationValid = targetStaff && targetStaff->visible() && idx >= minStaff && idx < maxStaff
    1334         1490 :                               && targetStaffType->group() == baseStaffType->group() && targetStaff->isLinked() == baseStaff->isLinked();
    1335          745 :     if (!isDestinationValid) {
    1336            1 :         LOGD("staffMove out of scope %zu + %d min %zu max %zu",
    1337              :              staffIdx(), m_staffMove, minStaff, maxStaff);
    1338              :         // If destination staff is invalid, reset to base staff
    1339            1 :         if (m_staffMove) {
    1340              :             // Remember the intended staff move, so it can be re-applied if
    1341              :             // destination staff becomes valid (e.g. unihidden)
    1342            1 :             m_storedStaffMove = m_staffMove;
    1343              :         }
    1344            1 :         setStaffMove(0);
    1345          744 :     } else if (!m_staffMove && m_storedStaffMove) {
    1346            1 :         setStaffMove(m_storedStaffMove);
    1347            1 :         m_storedStaffMove = 0;
    1348              :     }
    1349              : 
    1350          745 :     if (isDestinationValid) {
    1351              :         // Move valid, clear stored move
    1352          744 :         m_storedStaffMove = 0;
    1353              :     }
    1354              : }
    1355              : 
    1356        69777 : bool ChordRest::hasFollowingJumpItem() const
    1357              : {
    1358        69777 :     const Segment* seg = segment();
    1359        69777 :     const Measure* measure = seg ? seg->measure() : nullptr;
    1360        69777 :     if (!measure) {
    1361            0 :         return false;
    1362              :     }
    1363              : 
    1364        69777 :     if (endTick() != measure->endTick()) {
    1365        34086 :         return false;
    1366              :     }
    1367              : 
    1368        35691 :     std::vector<Measure*> followingRepeatMeasures = findFollowingRepeatMeasures(measure);
    1369              : 
    1370        35691 :     return !followingRepeatMeasures.empty();
    1371        35691 : }
    1372              : 
    1373          730 : bool ChordRest::hasPrecedingJumpItem() const
    1374              : {
    1375          736 :     TRACEFUNC;
    1376          730 :     const Segment* seg = segment();
    1377          730 :     const Measure* measure = seg->measure();
    1378              : 
    1379          730 :     if (tick() != measure->tick()) {
    1380          447 :         return false;
    1381              :     }
    1382              : 
    1383          283 :     std::vector<Measure*> precedingRepeatMeasures = findPreviousRepeatMeasures(measure);
    1384              : 
    1385          283 :     return !precedingRepeatMeasures.empty();
    1386          730 : }
    1387              : 
    1388           52 : void ChordRest::setJianpuDurationLineCount(size_t count)
    1389              : {
    1390           80 :     while (m_jianpuDurationLines.size() < count) {
    1391           28 :         JianpuDurationLine* dl = new JianpuDurationLine(this);
    1392           28 :         dl->setOwnershipParent(this);
    1393           28 :         dl->setTrack(track());
    1394           28 :         m_jianpuDurationLines.push_back(dl);
    1395              :     }
    1396              : 
    1397           52 :     while (m_jianpuDurationLines.size() > count) {
    1398            0 :         delete m_jianpuDurationLines.back();
    1399            0 :         m_jianpuDurationLines.pop_back();
    1400              :     }
    1401           52 : }
    1402              : }
        

Generated by: LCOV version 2.0-1