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 : #include "scorelayout.h"
23 :
24 : #include "dom/score.h"
25 : #include "dom/masterscore.h"
26 : #include "dom/system.h"
27 : #include "dom/page.h"
28 :
29 : #include "layoutcontext.h"
30 :
31 : #include "pagelayout.h"
32 : #include "scorepageviewlayout.h"
33 : #include "scorehorizontalviewlayout.h"
34 : #include "scoreverticalviewlayout.h"
35 :
36 : #include "dumplayoutdata.h"
37 :
38 : using namespace mu::engraving;
39 : using namespace mu::engraving::rendering::score;
40 :
41 : class CmdStateLocker
42 : {
43 : Score* m_score = nullptr;
44 : public:
45 4000 : CmdStateLocker(Score* s)
46 4000 : : m_score(s) { m_score->cmdState().lock(); }
47 4000 : ~CmdStateLocker() { m_score->cmdState().unlock(); }
48 : };
49 :
50 4000 : void ScoreLayout::layoutRange(Score* score, const Fraction& st, const Fraction& et)
51 : {
52 4015 : TRACEFUNC;
53 :
54 4000 : CmdStateLocker cmdStateLocker(score);
55 4000 : LayoutContext ctx(score);
56 :
57 4000 : Fraction stick(st);
58 4000 : Fraction etick(et);
59 4000 : assert(!(stick == Fraction(-1, 1) && etick == Fraction(-1, 1)));
60 :
61 : // Check empty score
62 4000 : if (!score->last() || (ctx.conf().isLinearMode() && !score->firstMeasure())) {
63 36 : LOGD() << "empty score";
64 36 : muse::DeleteAll(score->systems());
65 36 : score->systems().clear();
66 36 : muse::DeleteAll(score->pages());
67 36 : score->pages().clear();
68 36 : PageLayout::getNextPage(ctx);
69 36 : return;
70 : }
71 :
72 : // Check range
73 3964 : bool isLayoutAll = stick <= Fraction(0, 1) && (etick < Fraction(0, 1) || etick == Fraction::max());
74 3964 : if (stick < Fraction(0, 1)) {
75 5 : stick = Fraction(0, 1);
76 : }
77 3964 : if (etick < Fraction(0, 1) || etick == Fraction::max()) {
78 3360 : etick = score->last()->endTick();
79 : }
80 :
81 3964 : ctx.mutState().setIsLayoutAll(isLayoutAll);
82 :
83 : // Init context and layout
84 3964 : switch (ctx.conf().viewMode()) {
85 3964 : case LayoutMode::PAGE:
86 : case LayoutMode::FLOAT:
87 3964 : ScorePageViewLayout::layoutPageView(score, ctx, stick, etick);
88 3964 : break;
89 0 : case LayoutMode::LINE:
90 : case LayoutMode::HORIZONTAL_FIXED:
91 0 : ScoreHorizontalViewLayout::layoutHorizontalView(score, ctx, stick, etick);
92 0 : break;
93 0 : case LayoutMode::SYSTEM:
94 0 : ScoreVerticalViewLayout::layoutVerticalView(score, ctx, stick, etick);
95 0 : break;
96 : }
97 :
98 : //LOGDA() << DumpLayoutData::dump(score);
99 4072 : }
|