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 "editcrossstaff.h"
24 :
25 : #include "editchord.h"
26 :
27 : #include "../dom/chordrest.h"
28 : #include "../dom/part.h"
29 : #include "../dom/score.h"
30 : #include "../dom/staff.h"
31 : #include "../dom/stafftype.h"
32 :
33 : using namespace mu::engraving;
34 :
35 3 : void EditCrossStaff::moveUp(Transaction&, Score* score, ChordRest* cr)
36 : {
37 3 : Staff* staff = cr->staff();
38 3 : Part* part = staff->part();
39 3 : staff_idx_t rstaff = staff->rstaff();
40 3 : int staffMove = cr->staffMove();
41 :
42 3 : if ((staffMove == -1) || (static_cast<int>(rstaff) + staffMove <= 0)) {
43 1 : return;
44 : }
45 :
46 2 : const std::vector<Staff*>& staves = part->staves();
47 : // we know that staffMove+rstaff-1 index exists due to the previous condition.
48 2 : if (staff->staffType(cr->tick())->group() != StaffGroup::STANDARD
49 2 : || staves.at(rstaff + staffMove - 1)->staffType(cr->tick())->group() != StaffGroup::STANDARD) {
50 0 : LOGD("User attempted to move a note from/to a staff which does not use standard notation - ignoring.");
51 : } else {
52 : // move the chord up a staff
53 2 : score->undo(new ChangeChordStaffMove(cr, staffMove - 1));
54 : }
55 : }
56 :
57 2 : void EditCrossStaff::moveDown(Transaction&, Score* score, ChordRest* cr)
58 : {
59 2 : Staff* staff = cr->staff();
60 2 : Part* part = staff->part();
61 2 : staff_idx_t rstaff = staff->rstaff();
62 2 : int staffMove = cr->staffMove();
63 : // calculate the number of staves available so that we know whether there is another staff to move down to
64 2 : size_t rstaves = part->nstaves();
65 :
66 2 : if ((staffMove == 1) || (rstaff + staffMove >= rstaves - 1)) {
67 0 : LOGD("moveDown staffMove==%d rstaff %zu rstaves %zu", staffMove, rstaff, rstaves);
68 0 : return;
69 : }
70 :
71 2 : const std::vector<Staff*>& staves = part->staves();
72 : // we know that staffMove+rstaff+1 index exists due to the previous condition.
73 2 : if (staff->staffType(cr->tick())->group() != StaffGroup::STANDARD
74 2 : || staves.at(staffMove + rstaff + 1)->staffType(cr->tick())->group() != StaffGroup::STANDARD) {
75 0 : LOGD("User attempted to move a note from/to a staff which does not use standard notation - ignoring.");
76 : } else {
77 : // move the chord down a staff
78 2 : score->undo(new ChangeChordStaffMove(cr, staffMove + 1));
79 : }
80 : }
|