LCOV - code coverage report
Current view: top level - src/engraving/editing - editpart.h Coverage Total Hit
Test: filtered_coverage.info Lines: 72.5 % 51 37
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) 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              : #pragma once
      24              : 
      25              : #include "staffconfig.h"
      26              : #include "transaction/undoablecommand.h"
      27              : 
      28              : #include "../compat/midi/midipatch.h"
      29              : #include "../dom/drumset.h"
      30              : #include "../dom/part.h"
      31              : #include "../dom/score.h"
      32              : #include "../dom/stringdata.h"
      33              : 
      34              : namespace mu::engraving {
      35              : class InsertPart : public UndoableCommand
      36              : {
      37          207 :     OBJECT_ALLOCATOR(engraving, InsertPart)
      38              : 
      39              :     Part* m_part = nullptr;
      40              :     size_t m_targetPartIdx = 0;
      41              : 
      42              : public:
      43              :     InsertPart(Part* p, size_t targetPartIdx);
      44              :     void undo() override;
      45              :     void redo() override;
      46              :     void cleanup(bool) override;
      47              : 
      48          110 :     UNDO_TYPE(CommandType::InsertPart)
      49            0 :     UNDO_NAME("InsertPart")
      50          330 :     UNDO_CHANGED_OBJECTS({ m_part })
      51              : };
      52              : 
      53              : class RemovePart : public UndoableCommand
      54              : {
      55           25 :     OBJECT_ALLOCATOR(engraving, RemovePart)
      56              : 
      57              :     Part* m_part = nullptr;
      58              :     size_t m_partIdx = muse::nidx;
      59              : 
      60              : public:
      61              :     RemovePart(Part*, size_t partIdx);
      62              :     void undo() override;
      63              :     void redo() override;
      64              :     void cleanup(bool) override;
      65              : 
      66           17 :     UNDO_TYPE(CommandType::RemovePart)
      67            0 :     UNDO_NAME("RemovePart")
      68           51 :     UNDO_CHANGED_OBJECTS({ m_part })
      69              : };
      70              : 
      71              : class SetSoloist : public UndoableCommand
      72              : {
      73            2 :     OBJECT_ALLOCATOR(engraving, SetSoloist)
      74              : 
      75              :     Part* part = nullptr;
      76              :     bool soloist = false;
      77              : 
      78              : public:
      79              :     SetSoloist(Part* p, bool b);
      80              :     void undo() override;
      81              :     void redo() override;
      82              : 
      83            1 :     UNDO_TYPE(CommandType::SetSoloist)
      84            0 :     UNDO_NAME("SetSoloist")
      85            3 :     UNDO_CHANGED_OBJECTS({ part })
      86              : };
      87              : 
      88              : class ChangePart : public UndoableCommand
      89              : {
      90           22 :     OBJECT_ALLOCATOR(engraving, ChangePart)
      91              : 
      92              :     Part* part = nullptr;
      93              :     Instrument* instrument = nullptr;
      94              : 
      95              :     void flip() override;
      96              : 
      97              : public:
      98              :     ChangePart(Part*, Instrument*);
      99              :     void cleanup(bool) override;
     100              : 
     101           15 :     UNDO_TYPE(CommandType::ChangePart)
     102            0 :     UNDO_NAME("ChangePart")
     103           45 :     UNDO_CHANGED_OBJECTS({ part })
     104              : };
     105              : 
     106              : class ChangeInstrumentLong : public UndoableCommand
     107              : {
     108            6 :     OBJECT_ALLOCATOR(engraving, ChangeInstrumentLong)
     109              : 
     110              :     Part* part = nullptr;
     111              :     Fraction tick;
     112              :     String longName;
     113              : 
     114              :     void flip() override;
     115              : 
     116              : public:
     117              :     ChangeInstrumentLong(const Fraction&, Part*, const String&);
     118              : 
     119            3 :     UNDO_TYPE(CommandType::ChangeInstrumentLong)
     120            0 :     UNDO_NAME("ChangeInstrumentLong")
     121            9 :     UNDO_CHANGED_OBJECTS({ part })
     122              : };
     123              : 
     124              : class ChangeInstrumentShort : public UndoableCommand
     125              : {
     126            4 :     OBJECT_ALLOCATOR(engraving, ChangeInstrumentShort)
     127              : 
     128              :     Part* part = nullptr;
     129              :     Fraction tick;
     130              :     String shortName;
     131              : 
     132              :     void flip() override;
     133              : 
     134              : public:
     135              :     ChangeInstrumentShort(const Fraction&, Part*, const String&);
     136              : 
     137            3 :     UNDO_TYPE(CommandType::ChangeInstrumentShort)
     138            0 :     UNDO_NAME("ChangeInstrumentShort")
     139            9 :     UNDO_CHANGED_OBJECTS({ part })
     140              : };
     141              : 
     142              : class ChangeInstrumentGroupOptions : public UndoableCommand
     143              : {
     144            2 :     OBJECT_ALLOCATOR(engraving, ChangeInstrumentGroupOptions)
     145              : 
     146              :     Part* part = nullptr;
     147              :     Fraction tick;
     148              :     bool useCustom;
     149              :     String longName;
     150              :     String shortName;
     151              : 
     152              :     void flip() override;
     153              : 
     154              : public:
     155              :     ChangeInstrumentGroupOptions(const Fraction&, Part*, bool, const String&, const String&);
     156              : 
     157            1 :     UNDO_TYPE(CommandType::ChangeInstrumentGroupOptions)
     158            0 :     UNDO_NAME("ChangeInstrumentGroupOptions")
     159            3 :     UNDO_CHANGED_OBJECTS({ part })
     160              : };
     161              : 
     162              : class ChangeInstrumentNumber : public UndoableCommand
     163              : {
     164            4 :     OBJECT_ALLOCATOR(engraving, ChangeInstrumentNumber)
     165              : 
     166              :     Part* part = nullptr;
     167              :     Fraction tick;
     168              :     int number;
     169              : 
     170              :     void flip() override;
     171              : 
     172              : public:
     173              :     ChangeInstrumentNumber(const Fraction&, Part*, int v);
     174              : 
     175            2 :     UNDO_TYPE(CommandType::ChangeInstrumentNumber)
     176            0 :     UNDO_NAME("ChangeInstrumentNumber")
     177            6 :     UNDO_CHANGED_OBJECTS({ part })
     178              : };
     179              : 
     180              : class ChangeDrumset : public UndoableCommand
     181              : {
     182            8 :     OBJECT_ALLOCATOR(engraving, ChangeDrumset)
     183              : 
     184              :     Instrument* instrument = nullptr;
     185              :     Drumset drumset;
     186              :     Part* part = nullptr;
     187              : 
     188              :     void flip() override;
     189              : 
     190              : public:
     191            4 :     ChangeDrumset(Instrument* i, const Drumset& d, Part* p)
     192            4 :         : instrument(i), drumset(d), part(p) {}
     193              : 
     194            6 :     UNDO_TYPE(CommandType::ChangeDrumset)
     195            0 :     UNDO_NAME("ChangeDrumset")
     196              : };
     197              : 
     198              : class ChangeStringData : public UndoableCommand
     199              : {
     200              :     Instrument* m_instrument = nullptr;
     201              :     StringTunings* m_stringTunings = nullptr;
     202              :     StringData m_stringData;
     203              : 
     204              : public:
     205            0 :     ChangeStringData(StringTunings* stringTunings, const StringData& stringData)
     206            0 :         : m_stringTunings(stringTunings), m_stringData(stringData) {}
     207            1 :     ChangeStringData(Instrument* instrument, const StringData& stringData)
     208            1 :         : m_instrument(instrument), m_stringData(stringData) {}
     209              : 
     210              :     void flip() override;
     211            0 :     UNDO_NAME("ChangeStringData")
     212              : };
     213              : 
     214              : class ChangePatch : public UndoableCommand
     215              : {
     216            4 :     OBJECT_ALLOCATOR(engraving, ChangePatch)
     217              : 
     218              :     Score* score = nullptr;
     219              :     InstrChannel* channel = nullptr;
     220              :     MidiPatch patch;
     221              : 
     222              :     void flip() override;
     223              : 
     224              : public:
     225            2 :     ChangePatch(Score* s, InstrChannel* c, const MidiPatch& pt)
     226            2 :         : score(s), channel(c), patch(pt) {}
     227            0 :     UNDO_NAME("ChangePatch")
     228            9 :     UNDO_CHANGED_OBJECTS({ score })
     229              : };
     230              : 
     231              : class SetUserBankController : public UndoableCommand
     232              : {
     233            2 :     OBJECT_ALLOCATOR(engraving, SetUserBankController)
     234              : 
     235              :     InstrChannel* channel = nullptr;
     236              :     bool val = false;
     237              : 
     238              :     void flip() override;
     239              : 
     240              : public:
     241            1 :     SetUserBankController(InstrChannel* c, bool v)
     242            1 :         : channel(c), val(v) {}
     243            0 :     UNDO_NAME("SetUserBankController")
     244              : };
     245              : 
     246              : class InstrumentTemplate;
     247              : class Staff;
     248              : class StaffType;
     249              : 
     250              : class EditPart
     251              : {
     252              : public:
     253              :     struct PartEntry {
     254              :         Part* part = nullptr;                                   // existing
     255              :         const InstrumentTemplate* instrumentTemplate = nullptr; // new
     256              :         bool isSoloist = false;
     257              :     };
     258              : 
     259              :     struct SetPartsResult {
     260              :         std::vector<Part*> addedParts;
     261              :         std::vector<Part*> removedParts;
     262              :     };
     263              : 
     264              :     static SetPartsResult setParts(Score* score, const std::vector<PartEntry>& entries, const ScoreOrder& order);
     265              :     static void setScoreOrder(Score* score, const ScoreOrder& order);
     266              : 
     267              :     static void setPartVisible(Score* score, Part* part, bool visible);
     268              :     static bool setVoiceVisible(Score* score, Staff* staff, int voiceIndex, bool visible);
     269              :     static void setStaffVisible(Score* score, Staff* staff, bool visible);
     270              :     static void setPartSharpFlat(Score* score, Part* part, PreferSharpFlat sharpFlat);
     271              :     static void setInstrumentName(Score* score, Part* part, const Fraction& tick, const String& name);
     272              :     static void setInstrumentAbbreviature(Score* score, Part* part, const Fraction& tick, const String& abbreviature);
     273              :     static bool setInstrumentGroupNameOptions(Score* score, Part* part, const Fraction& tick, bool useCustom, const String& longName,
     274              :                                               const String& shortName);
     275              :     static void setInstrumentNumber(Score* score, Part* part, const Fraction& tick, int number);
     276              :     static void setStaffType(Score* score, Staff* staff, StaffTypes typeId);
     277              :     static void setStaffConfig(Score* score, Staff* staff, const StaffConfig& config, const Fraction& tick = Fraction(0, 1));
     278              :     static void setSharedPartEnabled(Score* score, Part* part, bool enabled);
     279              : 
     280              :     static void removeParts(Score* score, const std::vector<Part*>& parts);
     281              :     static void removeStaves(Score* score, const std::vector<Staff*>& staves);
     282              : 
     283              :     struct SystemObjectsMove {
     284              :         Staff* staff = nullptr;
     285              :         Staff* destination = nullptr;
     286              :         bool belowBottomStaff = false;
     287              :     };
     288              : 
     289              :     static bool reorderPartsChangesScore(const Score* score, const std::vector<Part*>& parts, const std::vector<SystemObjectsMove>& moves);
     290              :     static void reorderParts(Score* score, const std::vector<Part*>& parts, const std::vector<SystemObjectsMove>& moves);
     291              : 
     292              :     static bool reorderStavesChangesScore(const std::vector<Staff*>& staves);
     293              :     static void reorderStaves(Score* score, const std::vector<Staff*>& staves);
     294              : 
     295              :     static void moveParts(Score* score, const std::vector<Part*>& sourceParts, Part* destinationPart, bool insertAfter);
     296              :     static void moveStaves(Score* score, const std::vector<Staff*>& sourceStaves, Staff* destinationStaff, bool insertAfter);
     297              : 
     298              :     static Staff* appendStaff(Score* score, Part* destinationPart);
     299              :     static void appendStaff(Score* score, Staff* staff, Part* destinationPart, bool createRests = true);
     300              : 
     301              :     static Staff* appendLinkedStaff(Score* score, Staff* sourceStaff, Part* destinationPart);
     302              :     static void appendLinkedStaff(Score* score, Staff* staff, Staff* sourceStaff, Part* destinationPart);
     303              : 
     304              :     static void insertPart(Score* score, const InstrumentTemplate* templ, size_t index);
     305              :     static void insertPart(Score* score, Part* part, size_t index);
     306              : 
     307              :     static void replacePart(Score* score, Part* oldPart, const InstrumentTemplate* templ);
     308              :     static void replacePart(Score* score, Part* oldPart, Part* newPart);
     309              : 
     310              :     static bool replaceInstrument(Score* score, Part* part, const Fraction& tick, const Instrument& newInstrument,
     311              :                                   const StaffType* newStaffType = nullptr);
     312              :     static void replacePartInstrument(Score* score, Part* part, const Instrument& newInstrument, const StaffType* newStaffType = nullptr);
     313              :     static void replaceDrumset(Score* score, Part* part, const Fraction& tick, const Drumset& newDrumset, bool undoable = true);
     314              : 
     315              :     static void addSystemObjects(Score* score, const std::vector<Staff*>& staves);
     316              :     static void removeSystemObjects(Score* score, const std::vector<Staff*>& staves);
     317              :     static void moveSystemObjects(Score* score, Staff* sourceStaff, Staff* destinationStaff);
     318              : 
     319              : private:
     320              :     static bool doReplaceInstrument(Score* score, Part* part, const Fraction& tick, const Instrument& newInstrument,
     321              :                                     const StaffType* newStaffType);
     322              :     static void renameExcerptOfPart(MasterScore* master, const Part* part);
     323              : 
     324              :     static void doRemoveParts(Score* score, const std::vector<Part*>& parts);
     325              :     static void doRemoveStaves(Score* score, const std::vector<Staff*>& staves);
     326              :     static void doReorderParts(Score* score, const std::vector<Part*>& parts, const std::vector<SystemObjectsMove>& moves);
     327              : 
     328              :     static void doAppendStaff(Score* score, Staff* staff, Part* destinationPart, bool createRests);
     329              :     static void doAppendLinkedStaff(Score* score, Staff* staff, Staff* sourceStaff, Part* destinationPart);
     330              : 
     331              :     static void doReplaceDrumset(Score* score, Part* part, const Fraction& tick, const Drumset& newDrumset, bool undoable);
     332              : 
     333              :     static void removeLocksContainingMMRests(Score* score);
     334              : 
     335              :     static void appendStaves(Score* score, Part* part, const InstrumentTemplate& templ, const KeyList& keyList);
     336              :     static Part* insertPart(Score* score, const InstrumentTemplate& templ, size_t index, const KeyList& keyList);
     337              :     static void doInsertPart(Score* score, Part* part, size_t index);
     338              :     static void insertPartCopy(Score* score, Part* part, size_t index);
     339              : 
     340              :     static std::vector<Part*> removeMissingParts(Score* score, const std::vector<PartEntry>& entries);
     341              :     static std::vector<Part*> insertNewParts(Score* score, const std::vector<PartEntry>& entries, const KeyList& keyList);
     342              :     static std::vector<int> resolveInstrumentNumbers(const std::vector<PartEntry>& entries);
     343              :     static void updateSoloist(Score* score, const std::vector<PartEntry>& entries);
     344              :     static void sortParts(Score* score, const std::vector<PartEntry>& entries);
     345              :     static void sortStaves(Score* score, const std::vector<Part*>& orderedParts);
     346              : 
     347              :     static void deleteExcerptsOfParts(MasterScore* master, const std::vector<Part*>& parts);
     348              :     static bool moveSystemObjects(Score* score, std::vector<std::pair<staff_idx_t, Staff*> > moves, bool belowBottomStaff);
     349              : };
     350              : }
        

Generated by: LCOV version 2.0-1