LCOV - code coverage report
Current view: top level - src/engraving/editing - editcrossstaff.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 86.7 % 30 26
Test Date: 2026-11-19 04:14:36

            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 :     const StaffGroup sourceGroup = staff->staffType(cr->tick())->group();
      49            2 :     const StaffGroup targetGroup = staves.at(rstaff + staffMove - 1)->staffType(cr->tick())->group();
      50            2 :     if ((sourceGroup != StaffGroup::STANDARD && sourceGroup != StaffGroup::JIANPU)
      51            2 :         || (targetGroup != StaffGroup::STANDARD && targetGroup != StaffGroup::JIANPU)) {
      52            0 :         LOGD("User attempted to move a note from/to a staff which does not use standard notation - ignoring.");
      53              :     } else {
      54              :         // move the chord up a staff
      55            2 :         score->undo(new ChangeChordStaffMove(cr, staffMove - 1));
      56              :     }
      57              : }
      58              : 
      59            2 : void EditCrossStaff::moveDown(Transaction&, Score* score, ChordRest* cr)
      60              : {
      61            2 :     Staff* staff  = cr->staff();
      62            2 :     Part* part    = staff->part();
      63            2 :     staff_idx_t rstaff = staff->rstaff();
      64            2 :     int staffMove = cr->staffMove();
      65              :     // calculate the number of staves available so that we know whether there is another staff to move down to
      66            2 :     size_t rstaves = part->nstaves();
      67              : 
      68            2 :     if ((staffMove == 1) || (rstaff + staffMove >= rstaves - 1)) {
      69            0 :         LOGD("moveDown staffMove==%d  rstaff %zu rstaves %zu", staffMove, rstaff, rstaves);
      70            0 :         return;
      71              :     }
      72              : 
      73            2 :     const std::vector<Staff*>& staves = part->staves();
      74              :     // we know that staffMove+rstaff+1 index exists due to the previous condition.
      75            2 :     const StaffGroup sourceGroup = staff->staffType(cr->tick())->group();
      76            2 :     const StaffGroup targetGroup = staves.at(staffMove + rstaff + 1)->staffType(cr->tick())->group();
      77            2 :     if ((sourceGroup != StaffGroup::STANDARD && sourceGroup != StaffGroup::JIANPU)
      78            2 :         || (targetGroup != StaffGroup::STANDARD && targetGroup != StaffGroup::JIANPU)) {
      79            0 :         LOGD("User attempted to move a note from/to a staff which does not use standard notation - ignoring.");
      80              :     } else {
      81              :         // move the chord down a staff
      82            2 :         score->undo(new ChangeChordStaffMove(cr, staffMove + 1));
      83              :     }
      84              : }
        

Generated by: LCOV version 2.0-1