Skip to content

Conversation

@manolo
Copy link
Contributor

@manolo manolo commented Nov 25, 2025

Resolves: #31201

Add a new Score.replaceInstrument(part, instrumentId) method to the Plugin API, allowing plugins to programmatically change instruments on score parts.

Changes

  • Add Q_INVOKABLE Score::replaceInstrument(Part*, QString) to the plugin API
  • Bridge plugin API to existing NotationParts::replaceInstrument() infrastructure
  • Use Part::MAIN_INSTRUMENT_TICK to correctly identify the main instrument vs mid-score instrument changes
  • Add unit tests for instrument replacement with undo/redo support
  • Add test environment setup for API tests

Usage Example

var part = curScore.parts[0];
curScore.replaceInstrument(part, "violin");

The instrumentId parameter should match IDs from instruments.xml.


  • I signed the CLA
  • The title of the PR describes the problem it addresses
  • Each commit's message describes its purpose and effects, and references the issue it resolves
  • If changes are extensive, there is a sequence of easily reviewable commits
  • The code in the PR follows the coding rules
  • There are no unnecessary changes
  • The code compiles and runs on my machine, preferably after each commit individually
  • I created a unit test or vtest to verify the changes I made (if applicable)

@manolo manolo force-pushed the pr_replace_instrument branch from 4fb76ec to 30635e5 Compare November 25, 2025 20:57
@manolo manolo marked this pull request as draft November 25, 2025 21:27
@manolo manolo force-pushed the pr_replace_instrument branch 2 times, most recently from 0e22080 to 0a9d2fe Compare November 25, 2025 21:45
@manolo manolo marked this pull request as ready for review November 25, 2025 22:09
@manolo manolo marked this pull request as draft November 25, 2025 22:11
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");
@manolo manolo force-pushed the pr_replace_instrument branch from 8be6616 to 245bdd8 Compare November 26, 2025 07:20
Remove dependency on notation module by using engraving::ChangePart
command directly instead of going through INotationParts. This:
- Eliminates need for NotationMock and NotationPartsMock in tests
- Simplifies test setup (no mock injection required)
- Keeps the implementation purely at the engraving layer
- Makes the API self-contained within the plugin API module
@manolo manolo force-pushed the pr_replace_instrument branch from 245bdd8 to 125d62c Compare November 26, 2025 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add replaceInstrument() or similar method to Plugin API

1 participant