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) 2025 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 : #include "edittremolo.h"
24 :
25 : #include "../dom/chord.h"
26 : #include "../dom/measure.h"
27 : #include "../dom/score.h"
28 : #include "../dom/tremolotwochord.h"
29 :
30 : using namespace mu::engraving;
31 :
32 : //---------------------------------------------------------
33 : // MoveTremolo
34 : //---------------------------------------------------------
35 :
36 2 : void MoveTremolo::redo()
37 : {
38 : // Find new tremolo chords
39 2 : Measure* m1 = score->tick2measure(chord1Tick);
40 2 : Measure* m2 = score->tick2measure(chord2Tick);
41 2 : IF_ASSERT_FAILED(m1 && m2) {
42 0 : return;
43 : }
44 2 : Chord* c1 = m1->findChord(chord1Tick, track);
45 2 : Chord* c2 = m2->findChord(chord2Tick, track);
46 2 : IF_ASSERT_FAILED(c1 && c2) {
47 0 : return;
48 : }
49 :
50 : // Remember the old tremolo chords
51 2 : oldC1 = trem->chord1();
52 2 : oldC2 = trem->chord2();
53 :
54 : // Move tremolo away from old chords
55 2 : trem->chord1()->setTremoloTwoChord(nullptr);
56 2 : trem->chord2()->setTremoloTwoChord(nullptr);
57 :
58 : // Delete old tremolo on c1 and c2, if present
59 2 : if (c1->tremoloTwoChord() && (c1->tremoloTwoChord() != trem)) {
60 2 : if (c2->tremoloTwoChord() == c1->tremoloTwoChord()) {
61 0 : c2->tremoloTwoChord()->setChords(c1, c2);
62 : } else {
63 2 : c1->tremoloTwoChord()->setChords(c1, nullptr);
64 : }
65 2 : TremoloTwoChord* oldTremolo = c1->tremoloTwoChord();
66 2 : c1->setTremoloTwoChord(nullptr);
67 2 : delete oldTremolo;
68 : }
69 2 : if (c2->tremoloTwoChord() && (c2->tremoloTwoChord() != trem)) {
70 0 : c2->tremoloTwoChord()->setChords(nullptr, c2);
71 0 : TremoloTwoChord* oldTremolo = c2->tremoloTwoChord();
72 0 : c2->setTremoloTwoChord(nullptr);
73 0 : delete oldTremolo;
74 : }
75 :
76 : // Move tremolo to new chords
77 2 : c1->setTremoloTwoChord(trem);
78 2 : c2->setTremoloTwoChord(trem);
79 2 : trem->setChords(c1, c2);
80 2 : trem->setOwnershipParent(c1);
81 :
82 : // Tremolo would cross barline, so remove it
83 2 : if (m1 != m2) {
84 1 : score->undoRemoveElement(trem);
85 1 : return;
86 : }
87 : // One of the notes crosses a barline, so remove the tremolo
88 1 : if (c1->ticks() != c2->ticks()) {
89 0 : score->undoRemoveElement(trem);
90 : }
91 : }
92 :
93 2 : void MoveTremolo::undo()
94 : {
95 : // Move tremolo to old position
96 2 : trem->chord1()->setTremoloTwoChord(nullptr);
97 2 : trem->chord2()->setTremoloTwoChord(nullptr);
98 2 : oldC1->setTremoloTwoChord(trem);
99 2 : oldC2->setTremoloTwoChord(trem);
100 2 : trem->setChords(oldC1, oldC2);
101 2 : trem->setOwnershipParent(oldC1);
102 2 : }
|