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) 2026 MuseScore Limited
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 "editstretch.h"
24 :
25 : #include "../dom/measure.h"
26 : #include "../dom/score.h"
27 : #include "../dom/segment.h"
28 : #include "../dom/select.h"
29 :
30 : using namespace mu::engraving;
31 :
32 0 : void EditStretch::addStretch(Transaction&, Score* score, double val)
33 : {
34 0 : if (!score->selection().isRange()) {
35 0 : return;
36 : }
37 :
38 0 : Fraction startTick = score->selection().tickStart();
39 0 : Fraction endTick = score->selection().tickEnd();
40 0 : for (Measure* m = score->firstMeasureMM(); m; m = m->nextMeasureMM()) {
41 0 : if (m->tick() < startTick) {
42 0 : continue;
43 : }
44 0 : if (m->tick() >= endTick) {
45 0 : break;
46 : }
47 0 : double stretch = m->userStretch();
48 0 : stretch += val;
49 0 : if (stretch < 0) {
50 0 : stretch = 0;
51 : }
52 0 : m->undoChangeProperty(Pid::USER_STRETCH, stretch);
53 : }
54 : }
55 :
56 0 : void EditStretch::resetUserStretch(Transaction&, Score* score)
57 : {
58 0 : Measure* m1 = nullptr;
59 0 : Measure* m2 = nullptr;
60 : // retrieve span of selection
61 0 : Segment* s1 = score->selection().startSegment();
62 0 : Segment* s2 = score->selection().endSegment();
63 : // if either segment is not returned by the selection
64 : // (for instance, no selection) fall back to first/last measure
65 0 : if (!s1) {
66 0 : m1 = score->firstMeasureMM();
67 : } else {
68 0 : m1 = s1->measure();
69 : }
70 0 : if (!s2) {
71 0 : m2 = score->lastMeasureMM();
72 : } else {
73 0 : m2 = s2->measure();
74 : }
75 0 : if (!m1 || !m2) { // should not happen!
76 0 : return;
77 : }
78 :
79 0 : for (Measure* m = m1; m; m = m->nextMeasureMM()) {
80 0 : m->undoChangeProperty(Pid::USER_STRETCH, 1.0);
81 0 : if (m == m2) {
82 0 : break;
83 : }
84 : }
85 : }
|