Skip to content

Commit 569a1e6

Browse files
committed
Add replaceInstrument() to Plugin API
Expose instrument replacement functionality to plugins through new Score.replaceInstrument() method. Allows plugins to change a part's instrument (name, clef, transposition, sound) with full undo/redo support. Changes: - Add Q_INVOKABLE Score::replaceInstrument(Part*, QString) to plugin API - Use Part::MAIN_INSTRUMENT_TICK (not Fraction(0,1)) to correctly identify main instrument vs. mid-score instrument changes Usage example: var part = curScore.parts[0]; curScore.replaceInstrument(part, "violin");
1 parent 8cf1081 commit 569a1e6

File tree

8 files changed

+583
-0
lines changed

8 files changed

+583
-0
lines changed

src/engraving/api/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
set(MODULE_TEST engraving_api_tests)
2222

2323
set(MODULE_TEST_SRC
24+
${CMAKE_CURRENT_LIST_DIR}/environment.cpp
2425
${CMAKE_CURRENT_LIST_DIR}/util_tests.cpp
26+
${CMAKE_CURRENT_LIST_DIR}/score_tests.cpp
2527
)
2628

2729
set(MODULE_TEST_LINK
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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
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 "testing/environment.h"
24+
25+
#include "draw/drawmodule.h"
26+
#include "engraving/engravingmodule.h"
27+
28+
#include "engraving/dom/instrtemplate.h"
29+
#include "engraving/dom/mscore.h"
30+
31+
#include "log.h"
32+
33+
static muse::testing::SuiteEnvironment engraving_api_se(
34+
{
35+
new muse::draw::DrawModule(),
36+
new mu::engraving::EngravingModule()
37+
},
38+
nullptr,
39+
[]() {
40+
LOGI() << "engraving API tests suite post init";
41+
42+
mu::engraving::MScore::testMode = true;
43+
mu::engraving::MScore::noGui = true;
44+
45+
// Load instrument templates for tests that need them
46+
mu::engraving::loadInstrumentTemplates(":/engraving/instruments/instruments.xml");
47+
}
48+
);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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
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+
#pragma once
23+
24+
#include <gmock/gmock.h>
25+
26+
#include "context/iglobalcontext.h"
27+
28+
namespace mu::context {
29+
class GlobalContextMock : public IGlobalContext
30+
{
31+
public:
32+
MOCK_METHOD(void, setCurrentProject, (const project::INotationProjectPtr&), (override));
33+
MOCK_METHOD(project::INotationProjectPtr, currentProject, (), (const, override));
34+
MOCK_METHOD(muse::async::Notification, currentProjectChanged, (), (const, override));
35+
36+
MOCK_METHOD(notation::IMasterNotationPtr, currentMasterNotation, (), (const, override));
37+
MOCK_METHOD(muse::async::Notification, currentMasterNotationChanged, (), (const, override));
38+
39+
MOCK_METHOD(void, setCurrentNotation, (const notation::INotationPtr&), (override));
40+
MOCK_METHOD(notation::INotationPtr, currentNotation, (), (const, override));
41+
MOCK_METHOD(muse::async::Notification, currentNotationChanged, (), (const, override));
42+
43+
MOCK_METHOD(void, setCurrentPlayer, (const muse::audio::IPlayerPtr&), (override));
44+
MOCK_METHOD(IPlaybackStatePtr, playbackState, (), (const, override));
45+
};
46+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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
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+
#pragma once
23+
24+
#include <gmock/gmock.h>
25+
26+
#include "notation/inotation.h"
27+
28+
namespace mu::notation {
29+
class NotationMock : public INotation
30+
{
31+
public:
32+
MOCK_METHOD(project::INotationProject*, project, (), (const, override));
33+
MOCK_METHOD(IMasterNotation*, masterNotation, (), (const, override));
34+
35+
MOCK_METHOD(QString, name, (), (const, override));
36+
MOCK_METHOD(QString, projectName, (), (const, override));
37+
MOCK_METHOD(QString, projectNameAndPartName, (), (const, override));
38+
MOCK_METHOD(QString, workTitle, (), (const, override));
39+
MOCK_METHOD(QString, projectWorkTitle, (), (const, override));
40+
MOCK_METHOD(QString, projectWorkTitleAndPartName, (), (const, override));
41+
42+
MOCK_METHOD(bool, isOpen, (), (const, override));
43+
MOCK_METHOD(void, setIsOpen, (bool), (override));
44+
MOCK_METHOD(muse::async::Notification, openChanged, (), (const, override));
45+
46+
MOCK_METHOD(bool, hasVisibleParts, (), (const, override));
47+
MOCK_METHOD(bool, isMaster, (), (const, override));
48+
49+
MOCK_METHOD(ViewMode, viewMode, (), (const, override));
50+
MOCK_METHOD(void, setViewMode, (const ViewMode&), (override));
51+
MOCK_METHOD(muse::async::Notification, viewModeChanged, (), (const, override));
52+
53+
MOCK_METHOD(INotationPaintingPtr, painting, (), (const, override));
54+
MOCK_METHOD(INotationViewStatePtr, viewState, (), (const, override));
55+
MOCK_METHOD(INotationSoloMuteStatePtr, soloMuteState, (), (const, override));
56+
MOCK_METHOD(INotationInteractionPtr, interaction, (), (const, override));
57+
MOCK_METHOD(INotationMidiInputPtr, midiInput, (), (const, override));
58+
MOCK_METHOD(INotationUndoStackPtr, undoStack, (), (const, override));
59+
MOCK_METHOD(INotationStylePtr, style, (), (const, override));
60+
MOCK_METHOD(INotationElementsPtr, elements, (), (const, override));
61+
MOCK_METHOD(INotationAccessibilityPtr, accessibility, (), (const, override));
62+
MOCK_METHOD(INotationPartsPtr, parts, (), (const, override));
63+
MOCK_METHOD(muse::async::Notification, notationChanged, (), (const, override));
64+
};
65+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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
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+
#pragma once
23+
24+
#include <gmock/gmock.h>
25+
26+
#include "notation/inotationparts.h"
27+
28+
namespace mu::notation {
29+
class NotationPartsMock : public INotationParts
30+
{
31+
public:
32+
MOCK_METHOD(muse::async::NotifyList<const Part*>, partList, (), (const, override));
33+
MOCK_METHOD(muse::async::NotifyList<const Staff*>, staffList, (const muse::ID&), (const, override));
34+
35+
MOCK_METHOD(bool, hasParts, (), (const, override));
36+
37+
MOCK_METHOD(const Part*, part, (const muse::ID&), (const, override));
38+
MOCK_METHOD(bool, partExists, (const muse::ID&), (const, override));
39+
40+
MOCK_METHOD(const Staff*, staff, (const muse::ID&), (const, override));
41+
MOCK_METHOD(bool, staffExists, (const muse::ID&), (const, override));
42+
43+
MOCK_METHOD(StaffConfig, staffConfig, (const muse::ID&), (const, override));
44+
MOCK_METHOD(ScoreOrder, scoreOrder, (), (const, override));
45+
46+
MOCK_METHOD(void, setParts, (const PartInstrumentList&, const ScoreOrder&), (override));
47+
MOCK_METHOD(void, setScoreOrder, (const ScoreOrder&), (override));
48+
MOCK_METHOD(void, setPartVisible, (const muse::ID&, bool), (override));
49+
MOCK_METHOD(bool, setVoiceVisible, (const muse::ID&, int, bool), (override));
50+
MOCK_METHOD(void, setStaffVisible, (const muse::ID&, bool), (override));
51+
MOCK_METHOD(void, setPartSharpFlat, (const muse::ID&, const SharpFlat&), (override));
52+
MOCK_METHOD(void, setInstrumentName, (const InstrumentKey&, const QString&), (override));
53+
MOCK_METHOD(void, setInstrumentAbbreviature, (const InstrumentKey&, const QString&), (override));
54+
MOCK_METHOD(void, setStaffType, (const muse::ID&, StaffTypeId), (override));
55+
MOCK_METHOD(void, setStaffConfig, (const muse::ID&, const StaffConfig&), (override));
56+
57+
MOCK_METHOD(void, removeParts, (const muse::IDList&), (override));
58+
MOCK_METHOD(void, removeStaves, (const muse::IDList&), (override));
59+
60+
MOCK_METHOD(void, moveParts, (const muse::IDList&, const muse::ID&, InsertMode), (override));
61+
MOCK_METHOD(void, moveStaves, (const muse::IDList&, const muse::ID&, InsertMode), (override));
62+
63+
MOCK_METHOD(bool, appendStaff, (Staff*, const muse::ID&), (override));
64+
MOCK_METHOD(bool, appendStaffLinkedToMaster, (Staff*, Staff*, const muse::ID&), (override));
65+
MOCK_METHOD(bool, appendLinkedStaff, (Staff*, const muse::ID&, const muse::ID&), (override));
66+
67+
MOCK_METHOD(void, insertPart, (Part*, size_t), (override));
68+
69+
MOCK_METHOD(void, replacePart, (const muse::ID&, Part*), (override));
70+
MOCK_METHOD(void, replaceInstrument, (const InstrumentKey&, const Instrument&, const StaffType*), (override));
71+
MOCK_METHOD(void, replaceDrumset, (const InstrumentKey&, const Drumset&, bool), (override));
72+
73+
MOCK_METHOD(const std::vector<Staff*>&, systemObjectStaves, (), (const, override));
74+
MOCK_METHOD(muse::async::Notification, systemObjectStavesChanged, (), (const, override));
75+
76+
MOCK_METHOD(void, addSystemObjects, (const muse::IDList&), (override));
77+
MOCK_METHOD(void, removeSystemObjects, (const muse::IDList&), (override));
78+
MOCK_METHOD(void, moveSystemObjects, (const muse::ID&, const muse::ID&), (override));
79+
MOCK_METHOD(void, moveSystemObjectLayerBelowBottomStaff, (), (override));
80+
MOCK_METHOD(void, moveSystemObjectLayerAboveBottomStaff, (), (override));
81+
82+
MOCK_METHOD(muse::async::Notification, partsChanged, (), (const, override));
83+
MOCK_METHOD(muse::async::Notification, scoreOrderChanged, (), (const, override));
84+
};
85+
}

0 commit comments

Comments
 (0)