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 : #include "staffwrite.h"
23 :
24 : #include "dom/score.h"
25 : #include "dom/staff.h"
26 : #include "dom/measure.h"
27 :
28 : #include "twrite.h"
29 : #include "measurewrite.h"
30 :
31 : using namespace mu::engraving;
32 : using namespace mu::engraving::write;
33 :
34 17364 : static void writeMeasure(XmlWriter& xml, WriteContext& ctx, MeasureBase* m,
35 : staff_idx_t staffIdx,
36 : bool writeSystemElements,
37 : bool forceTimeSig)
38 : {
39 : //
40 : // special case multi measure rest
41 : //
42 17364 : if (m->isMeasure() || staffIdx == 0) {
43 16990 : if (Measure::classof(m)) {
44 16337 : MeasureWrite::writeMeasure(toMeasure(m), xml, ctx, staffIdx, writeSystemElements, forceTimeSig);
45 : } else {
46 653 : TWrite::writeItem(m, xml, ctx);
47 : }
48 : }
49 :
50 17364 : if (m->score()->style().styleB(Sid::createMultiMeasureRests) && m->isMeasure() && toMeasure(m)->mmRest()) {
51 34 : MeasureWrite::writeMeasure(toMeasure(m)->mmRest(), xml, ctx, staffIdx, writeSystemElements, forceTimeSig);
52 : }
53 :
54 17364 : ctx.setCurTick(m->endTick());
55 17364 : }
56 :
57 1969 : void StaffWrite::writeStaff(const Staff* staff, XmlWriter& xml, write::WriteContext& ctx,
58 : MeasureBase* measureStart, MeasureBase* measureEnd,
59 : staff_idx_t staffStart, staff_idx_t staffIdx)
60 : {
61 5907 : xml.startElement(staff, { { "id", static_cast<int>(staffIdx + 1 - staffStart) } });
62 :
63 1969 : ctx.setCurTick(measureStart->tick());
64 1969 : ctx.setTickDiff(ctx.curTick());
65 1969 : ctx.setCurTrack(staffIdx * VOICES);
66 1969 : bool writeSystemElements = (staffIdx == staffStart);
67 1969 : bool firstMeasureWritten = false;
68 1969 : bool forceTimeSig = false;
69 19333 : for (MeasureBase* m = measureStart; m != measureEnd; m = m->next()) {
70 : // force timesig if first measure and range is set
71 17364 : if (ctx.shouldWriteRange() && m->isMeasure()) {
72 0 : if (!firstMeasureWritten) {
73 0 : forceTimeSig = true;
74 0 : firstMeasureWritten = true;
75 : } else {
76 0 : forceTimeSig = false;
77 : }
78 : }
79 17364 : writeMeasure(xml, ctx, m, staffIdx, writeSystemElements, forceTimeSig);
80 : }
81 :
82 1969 : xml.endElement();
83 3938 : }
|