Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/engraving/dom/instrchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void InstrumentChange::setupInstrument(const Instrument* instrument)
}

//: The text of an "instrument change" marking. It is an instruction to the player to switch to another instrument.
const String newInstrChangeText = muse::mtrc("engraving", "To %1").arg(instrument->trackName());
const String newInstrChangeText = muse::mtrc("engraving", "To %1").arg(instrument->trackNameWithTrait());
undoChangeProperty(Pid::TEXT, TextBase::plainToXmlText(newInstrChangeText));
}

Expand Down
10 changes: 10 additions & 0 deletions src/engraving/dom/instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "instrument.h"

#include "translation.h"

#include "drumset.h"
#include "instrtemplate.h"
#include "masterscore.h"
Expand Down Expand Up @@ -1066,6 +1068,14 @@ String Instrument::trackName() const
return m_trackName;
}

String Instrument::trackNameWithTrait() const
{
if (m_trait.type == TraitType::Transposition && !m_trait.isHiddenOnScore) {
return muse::mtrc("engraving", "%1 in %2").arg(m_trackName, m_trait.name);
}
Comment on lines +1073 to +1075
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Guard against empty transposition trait names in formatted output.

If m_trait.name is empty, Line 1074 can yield a user-visible string like "Piccolo in ". Add a validity check before formatting.

💡 Proposed fix
 String Instrument::trackNameWithTrait() const
 {
-    if (m_trait.type == TraitType::Transposition && !m_trait.isHiddenOnScore) {
+    if (m_trait.type == TraitType::Transposition && !m_trait.isHiddenOnScore && m_trait.isValid()) {
         return muse::mtrc("engraving", "%1 in %2").arg(m_trackName, m_trait.name);
     }
     return m_trackName;
 }

return m_trackName;
}
Comment on lines +1071 to +1077
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Use a single shared formatter for instrument display names across contexts.

This method introduces another formatting path for transposition naming. To prevent drift between score text, mixer, and Staff/Part properties, prefer one canonical formatter and route all UI/display callers through it.


void Instrument::setTrackName(const String& s)
{
m_trackName = s;
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class Instrument
String musicXmlId() const;

String trackName() const;
String trackNameWithTrait() const;
void setTrackName(const String& s);
String nameAsXmlText() const;
String nameAsPlainText() const;
Expand Down
13 changes: 0 additions & 13 deletions src/notation/internal/notationparts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ using namespace mu::engraving;

static const mu::engraving::Fraction DEFAULT_TICK = mu::engraving::Fraction(0, 1);

static String formatInstrumentTitleOnScore(const String& instrumentName, const Trait& trait)
{
// Comments for translators start with //:

if (trait.type == TraitType::Transposition && !trait.isHiddenOnScore) {
//: %1=name ("Horn"), %2=transposition ("C alto"). Example: "Horn in C alto"
return muse::qtrc("notation", "%1 in %2", "Transposing instrument displayed in the score")
.arg(instrumentName, trait.name);
}

return instrumentName; // Example: "Flute"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also my #32771, which also removes this apparently unused method

NotationParts::NotationParts(IGetScore* getScore, INotationInteractionPtr interaction, INotationUndoStackPtr undoStack)
: m_getScore(getScore), m_undoStack(undoStack), m_interaction(interaction)
{
Expand Down
Loading