LCOV - code coverage report
Current view: top level - src/engraving/rendering/score - systemlayout.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 2 2
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) 2023 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              : #pragma once
      23              : 
      24              : #include <vector>
      25              : 
      26              : #include "layoutcontext.h"
      27              : 
      28              : #include "../../dom/measure.h"
      29              : #include "../../dom/segment.h"
      30              : #include "../../dom/sharedpart.h"
      31              : #include "../../types/types.h"
      32              : 
      33              : namespace mu::engraving {
      34              : class BarLine;
      35              : class Bracket;
      36              : class BracketItem;
      37              : class Chord;
      38              : class Dynamic;
      39              : class Expression;
      40              : class FiguredBass;
      41              : class FretDiagram;
      42              : class Harmony;
      43              : class HarpPedalDiagram;
      44              : class Image;
      45              : class InstrumentChange;
      46              : class Measure;
      47              : class MeasureNumber;
      48              : class MMRest;
      49              : class MMRestRange;
      50              : class Parenthesis;
      51              : class RehearsalMark;
      52              : class Score;
      53              : class Segment;
      54              : class SkylineLine;
      55              : class Spanner;
      56              : class StaffText;
      57              : class StaveSharingChange;
      58              : class Sticking;
      59              : class System;
      60              : class SystemText;
      61              : class TempoText;
      62              : class TimeSig;
      63              : }
      64              : 
      65              : namespace mu::engraving::rendering::score {
      66              : class SystemLayout
      67              : {
      68              : public:
      69              :     static System* collectSystem(LayoutContext& ctx);
      70              :     static void layoutSystemElements(System* system, LayoutContext& ctx);
      71              : 
      72              :     static void layoutSystem(System* system, LayoutContext& ctx, double xo1);
      73              : 
      74              :     static void hideEmptyStaves(System* system, LayoutContext& ctx, bool isFirstSystem);
      75              :     static bool canChangeSysStaffVisibility(const System* system, const staff_idx_t staffIdx);
      76              : 
      77              :     static void layout2(System* system, LayoutContext& ctx);
      78              :     static void restoreLayout2(System* system, LayoutContext& ctx);
      79              :     static void setMeasureHeight(System* system, double height, const LayoutContext& ctx);
      80              : 
      81              :     static double minDistance(const System* top, const System* bottom, const LayoutContext& ctx);
      82              : 
      83              :     static void centerElementsBetweenStaves(const System* system);
      84              :     /* Centers the systems which were laid out during this layout but whose page was not
      85              :      * collected (e.g. the first system of the next page, re-laid out by a partial layout),
      86              :      * so centerElementsBetweenStaves has not been called for them yet. Call it after the
      87              :      * system/page collection loop, before any leftover systems are deleted. */
      88              :     static void centerPendingSystems(LayoutContext& ctx);
      89              :     static void centerBigTimeSigsAcrossStaves(const System* system);
      90              : 
      91              :     static void updateSkylineForElement(EngravingItem* element, const System* system, double yMove);
      92              :     static void removeElementFromSkyline(EngravingItem* element, const System* system);
      93              : 
      94              :     static void layoutSystemLockIndicators(System* system, LayoutContext& ctx);
      95              :     static void layoutPageLockIndicators(System* system);
      96              : 
      97              : private:
      98              :     struct MeasureState
      99              :     {
     100              :         Measure* measure = nullptr;
     101              :         double measureWidth = 0.0;
     102              :         double measurePos = 0.0;
     103              :         std::map<EngravingItem*, PointF> elementPositions;
     104              :         std::map<EngravingItem*, double> elementWidths;
     105              :         std::map<SharedPart*, std::optional<StaveSharingState> > staveSharingStates;
     106              :         bool curHeader = false;
     107              :         bool curTrailer = false;
     108              : 
     109              :         void clear();
     110              : 
     111              :         void restoreMeasure(LayoutContext& ctx);
     112              :     };
     113              : 
     114              :     struct ElementsToLayout
     115              :     {
     116              :         System* system;
     117              :         std::vector<Measure*> measures;
     118              :         std::vector<Segment*> segments;
     119              : 
     120              :         std::vector<ChordRest*> chordRests;
     121              :         std::vector<Chord*> chords;
     122              :         std::vector<BarLine*> barlines;
     123              :         std::vector<TimeSig*> timeSigAboveStaves;
     124              : 
     125              :         std::vector<MeasureNumber*> measureNumbers;
     126              :         std::vector<MMRestRange*> mmrRanges;
     127              :         std::vector<EngravingItem*> markersAndJumps;
     128              : 
     129              :         std::vector<Sticking*> stickings;
     130              :         std::vector<EngravingItem*> fermatasAndTremoloBars;
     131              :         std::vector<FiguredBass*> figuredBass;
     132              :         std::vector<Dynamic*> dynamics;
     133              :         std::vector<Expression*> expressions;
     134              :         std::vector<HarpPedalDiagram*> harpDiagrams;
     135              :         std::vector<FretDiagram*> fretDiagrams;
     136              :         std::vector<StaffTextBase*> staffText;
     137              :         std::vector<StaveSharingChange*> staveSharingChanges;
     138              :         std::vector<InstrumentChange*> instrChanges;
     139              :         std::vector<SystemText*> systemText;
     140              :         std::vector<EngravingItem*> playTechCapoStringTunTripletFeel;
     141              :         std::vector<RehearsalMark*> rehMarks;
     142              :         std::vector<TempoText*> tempoText;
     143              :         std::vector<Image*> images;
     144              :         std::vector<Parenthesis*> parenthesis;
     145              :         std::vector<Harmony*> harmonies;
     146              :         std::vector<PlayCountText*> playCountText;
     147              : 
     148              :         std::vector<Spanner*> slurs;
     149              :         std::vector<Spanner*> trills;
     150              :         std::vector<Spanner*> hairpins;
     151              :         std::vector<Spanner*> ottavas;
     152              :         std::vector<Spanner*> pedal;
     153              :         std::vector<Spanner*> voltas;
     154              :         std::vector<Spanner*> tempoChangeLines;
     155              :         std::vector<Spanner*> partialLyricsLines;
     156              :         std::vector<Spanner*> allOtherSpanners;
     157              : 
     158              :         std::vector<GuitarBend*> guitarBends;
     159              : 
     160         8239 :         ElementsToLayout(System* s)
     161         8239 :             : system(s) {}
     162              :     };
     163              : 
     164              :     static void collectElementsToLayout(Measure* measure, ElementsToLayout& elements, const LayoutContext& ctx);
     165              :     static void collectSpannersToLayout(ElementsToLayout& elements, const LayoutContext& ctx);
     166              : 
     167              :     static System* getNextSystem(LayoutContext& lc);
     168              :     static void createSkylines(const ElementsToLayout& elementsToLayout, LayoutContext& ctx);
     169              :     static void processLines(System* system, LayoutContext& ctx, const std::vector<Spanner*>& lines, bool align = false);
     170              :     static void layoutTies(Chord* ch, System* system, const Fraction& stick, LayoutContext& ctx);
     171              :     static void doLayoutTies(System* system, const std::vector<Segment*>& sl, const Fraction& stick, const Fraction& etick,
     172              :                              LayoutContext& ctx);
     173              :     static void doLayoutNoteSpannersLinear(System* system, LayoutContext& ctx);
     174              :     static void layoutNoteAnchoredSpanners(System* system, Chord* chord);
     175              :     static void updateCrossBeams(System* system, LayoutContext& ctx);
     176              :     static bool measureHasCrossStuffOrModifiedBeams(const Measure* measure);
     177              :     static void restoreOldSystemLayout(System* system, LayoutContext& ctx);
     178              :     static void layoutTuplets(const std::vector<ChordRest*>& chordRests, LayoutContext& ctx);
     179              : 
     180              :     static void layoutTiesAndBends(const ElementsToLayout& elementsToLayout, LayoutContext& ctx);
     181              : 
     182              :     static double minVertSpaceForCrossStaffBeams(System* system, staff_idx_t staffIdx1, staff_idx_t staffIdx2, LayoutContext& ctx);
     183              : 
     184              :     struct CenterableItem {
     185              :         EngravingItem* item = nullptr;
     186              :         Shape shape; // x relative to the system, y relative to the upper staff of the item's gap
     187              :         bool isLyrics = false;
     188              :         bool onUpperGapStaff = false; // whether the item hangs below the upper staff of its gap or sits above the lower one
     189              :     };
     190              : 
     191              :     // The space between two vertically adjacent visible staves
     192              :     struct Gap {
     193              :         staff_idx_t upperStaffIdx = muse::nidx;
     194              :         staff_idx_t lowerStaffIdx = muse::nidx;
     195              :         double yStaffDiff = 0.0; // Inside a gap, everything is expressed relative to its upper staff, so we need the y diff between staves
     196              :         std::vector<CenterableItem> items;
     197              :     };
     198              : 
     199              :     static bool snapChainShouldBeCenteredBetweenStaves(EngravingItem* item, const System* system);
     200              :     static bool elementShouldBeCenteredBetweenStaves(const EngravingItem* item, const System* system, bool placeAbove);
     201              :     static bool mmRestShouldBeCenteredBetweenStaves(const MMRest* mmRest, const System* system);
     202              :     static bool whammyBarShouldBeCenteredBetweenStaves(const WhammyBarSegment* wbar, const System* system);
     203              :     static bool elementHasAnotherStackedOutside(const EngravingItem* element, const Shape& elementShape, const SkylineLine& skylineLine);
     204              :     static bool shapesStackVertically(const Shape& shape1, const Shape& shape2, double minHorizontalClearance);
     205              :     static void collectCenterableItems(const System* system, std::vector<Gap>& gaps, std::vector<MMRest*>& mmRestsToCenter);
     206              :     static std::vector<std::vector<const CenterableItem*> > groupItemsToCenterTogether(const std::vector<const CenterableItem*>& items,
     207              :                                                                                        double minHorizontalClearance);
     208              :     static void centerItemsInGap(const Gap& gap, const System* system, double minHorizontalClearance);
     209              :     static double gapConvergeDistance(const std::vector<const CenterableItem*>& group, double yStaffDiff, double minHorizontalClearance);
     210              :     static double convergenceMoveFor(const CenterableItem* centerableItem, double convergeDistance);
     211              :     static void centerItemGroup(const std::vector<const CenterableItem*>& group, const System* system, const SkylineLine& upperSkyline,
     212              :                                 const SkylineLine& lowerSkyline, double yStaffDiff, double minHorizontalClearance);
     213              :     static void centerMMRestBetweenStaves(MMRest* mmRest, const System* system);
     214              : 
     215              :     static bool shouldBeJustified(System* system, double curSysWidth, double targetSystemWidth, LayoutContext& ctx);
     216              : 
     217              :     static void updateTimeSigAboveStavesXPos(System* system, LayoutContext& ctx);
     218              :     static void clearBigTimeSigNotShown(System* system, LayoutContext& ctx);
     219              : 
     220              :     static void layoutSticking(const std::vector<Sticking*> stickings, System* system, LayoutContext& ctx);
     221              : 
     222              :     static void layoutLyrics(const ElementsToLayout& elements, LayoutContext& ctx);
     223              : 
     224              :     static void layoutVoltas(const ElementsToLayout& elementsToLayout, LayoutContext& ctx);
     225              : 
     226              :     static void layoutDynamicExpressionAndHairpins(const ElementsToLayout& elementsToLayout, LayoutContext& ctx);
     227              : 
     228              :     static void layoutParenthesisAndBigTimeSigs(const ElementsToLayout& elementsToLayout);
     229              : 
     230              :     static void layoutHarmonies(const std::vector<Harmony*> harmonies, System* system, LayoutContext& ctx);
     231              :     static void layoutFretDiagrams(const ElementsToLayout& elements, System* system, LayoutContext& ctx);
     232              : 
     233              :     static void alignRests(const ElementsToLayout& elementsToLayout, LayoutContext& ctx);
     234              :     static void checkFullMeasureRestCollisions(const ElementsToLayout& elementsToLayout, LayoutContext& ctx);
     235              : };
     236              : }
        

Generated by: LCOV version 2.0-1