LCOV - code coverage report
Current view: top level - src/engraving/dom - repeatlist.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 5 5
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              : #ifndef MU_ENGRAVING_REPEATLIST_H
      24              : #define MU_ENGRAVING_REPEATLIST_H
      25              : 
      26              : #include <set>
      27              : #include <vector>
      28              : 
      29              : #include "global/allocator.h"
      30              : #include "types/string.h"
      31              : 
      32              : namespace mu::engraving {
      33              : class Score;
      34              : class Measure;
      35              : class Volta;
      36              : class Jump;
      37              : class RepeatListElement;
      38              : using RepeatListElementList = std::vector<RepeatListElement*>;
      39              : 
      40              : //---------------------------------------------------------
      41              : //   RepeatSegment
      42              : //---------------------------------------------------------
      43              : 
      44              : class RepeatSegment
      45              : {
      46         4913 :     OBJECT_ALLOCATOR(engraving, RepeatSegment)
      47              : public:
      48              :     int tick;           // start tick
      49              :     int utick;
      50              :     double pause;
      51              :     int playbackCount;
      52              : 
      53              :     RepeatSegment(int playbackCount);
      54              : 
      55              :     void addMeasure(Measure const* const);
      56              :     void addMeasures(Measure const* const);
      57              :     bool containsMeasure(Measure const* const) const;
      58              :     bool endsWithMeasure(Measure const* const) const;
      59              :     bool startsWithMeasure(Measure const* const) const;
      60              :     bool isEmpty() const;
      61              :     int len() const;
      62              :     int endTick() const;
      63              :     void popMeasure();
      64              : 
      65         2261 :     Measure const* firstMeasure() const { return m_measureList.empty() ? nullptr : m_measureList.front(); }
      66          884 :     Measure const* lastMeasure() const { return m_measureList.empty() ? nullptr : m_measureList.back(); }
      67              : 
      68              :     const std::vector<const Measure*>& measureList() const;
      69              : 
      70              :     friend bool operator==(const RepeatSegment& lhs, const RepeatSegment& rhs);
      71              :     inline friend bool operator!=(const RepeatSegment& lhs, const RepeatSegment& rhs) { return !(lhs == rhs); }
      72              : 
      73              :     friend class RepeatList;
      74              : private:
      75              :     std::vector<const Measure*> m_measureList;
      76              : };
      77              : 
      78              : struct RepeatSegmentInfo {
      79              :     int tick = 0;
      80              :     int endTick = 0;
      81              :     int utick = 0;
      82              : };
      83              : 
      84              : //---------------------------------------------------------
      85              : //   RepeatList
      86              : //---------------------------------------------------------
      87              : 
      88              : class RepeatList : public std::vector<RepeatSegment*>
      89              : {
      90         8226 :     OBJECT_ALLOCATOR(engraving, RepeatList)
      91              : 
      92              : public:
      93              :     RepeatList(Score* s);
      94              :     RepeatList(const RepeatList&) = delete;
      95              :     RepeatList& operator=(const RepeatList&) = delete;
      96              :     ~RepeatList();
      97              : 
      98              :     void update(bool expand, bool updateTies = true);
      99        17184 :     void setScoreChanged() { m_scoreChanged = true; }
     100              :     const Score* score() const { return m_score; }
     101              : 
     102              :     int utick2tick(int tick) const;
     103              :     int tick2utick(int tick) const;
     104              :     void updateUticks();
     105              :     int ticks() const;
     106              : 
     107              :     std::vector<RepeatSegment*>::const_iterator findRepeatSegmentFromUTick(int utick) const;
     108              :     std::vector<RepeatSegmentInfo> segmentInfoList() const;
     109              : 
     110              : private:
     111              :     void collectRepeatListElements();
     112              :     std::pair<std::vector<RepeatListElementList>::const_iterator, RepeatListElementList::const_iterator> findMarker(
     113              :         muse::String label, std::vector<RepeatListElementList>::const_iterator referenceSectionIt,
     114              :         RepeatListElementList::const_iterator referenceRepeatListElementIt) const;
     115              : 
     116              :     void performJump(std::vector<RepeatListElementList>::const_iterator sectionIt,
     117              :                      RepeatListElementList::const_iterator repeatListElementTargetIt, bool withRepeats, int* const playbackCount,
     118              :                      Volta const** const activeVolta, RepeatListElement const** const startRepeatReference) const;
     119              :     void unwind();
     120              :     void flatten();
     121              : 
     122              :     Score* m_score = nullptr;
     123              :     mutable unsigned m_utick2tickHint = 0; // cached RepeatList index for utick2tick
     124              : 
     125              :     bool m_expanded = false;
     126              :     bool m_scoreChanged = true;
     127              : 
     128              :     std::set<std::pair<Jump const* const, int> > m_jumpsTaken;     // take the jumps only once, so track them during unwind
     129              :     std::vector<RepeatListElementList> m_rlElements;               // all elements of the score that influence the RepeatList
     130              : };
     131              : } // namespace mu::engraving
     132              : #endif
        

Generated by: LCOV version 2.0-1