Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions src/engraving/api/tests/score_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEST_F(Engraving_ApiScoreTests, replaceInstrumentAtDomLevel)
newInstrument.setTrackName(u"Replaced Instrument");

score->startCmd(TranslatableString::untranslatable("Replace instrument test"));
score->undo(new ChangePart(part, new Instrument(newInstrument), u"Replaced Part"));
score->undo(new ChangePart(part, new Instrument(newInstrument)));
score->endCmd();

// [THEN] The part's instrument should be changed
Expand Down Expand Up @@ -116,7 +116,7 @@ TEST_F(Engraving_ApiScoreTests, replaceInstrumentUndo)
newInstrument.setTrackName(u"New Instrument");

score->startCmd(TranslatableString::untranslatable("Replace instrument test"));
score->undo(new ChangePart(part, new Instrument(newInstrument), u"New Part"));
score->undo(new ChangePart(part, new Instrument(newInstrument)));
score->endCmd();

// Verify it changed
Expand Down Expand Up @@ -155,7 +155,7 @@ TEST_F(Engraving_ApiScoreTests, replaceInstrumentRedo)
newInstrument.setId(u"test.replaced");

score->startCmd(TranslatableString::untranslatable("Replace instrument test"));
score->undo(new ChangePart(part, new Instrument(newInstrument), u"Replaced"));
score->undo(new ChangePart(part, new Instrument(newInstrument)));
score->endCmd();

EXPECT_EQ(part->instrumentId(), u"test.replaced");
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/dom.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ set(DOM_SRC
${CMAKE_CURRENT_LIST_DIR}/staff.h
${CMAKE_CURRENT_LIST_DIR}/stafflines.cpp
${CMAKE_CURRENT_LIST_DIR}/stafflines.h
${CMAKE_CURRENT_LIST_DIR}/staffname.h
${CMAKE_CURRENT_LIST_DIR}/stafflabel.h
${CMAKE_CURRENT_LIST_DIR}/staffstate.cpp
${CMAKE_CURRENT_LIST_DIR}/staffstate.h
${CMAKE_CURRENT_LIST_DIR}/stafftext.cpp
Expand Down
1 change: 0 additions & 1 deletion src/engraving/dom/excerpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ void Excerpt::createExcerpt(Excerpt* excerpt)
Part* p = new Part(score);
p->setId(part->id());
p->setInstrument(*part->instrument());
p->setPartName(part->partName());
p->setPreferSharpFlat(part->preferSharpFlat());

for (Staff* staff : part->staves()) {
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/instrtemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class InstrumentTemplate
String id;
String soundId;
String trackName;
StaffName instrumentName;
InstrumentLabel instrumentName;
String musicXmlId; ///< used in MusicXML 3.0
String description; ///< a longer description of the instrument

Expand Down
50 changes: 36 additions & 14 deletions src/engraving/dom/instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Instrument::Instrument(const Instrument& i)
{
m_id = i.m_id;
m_soundId = i.m_soundId;
m_instrumentName = i.m_instrumentName;
m_instrumentLabel = i.m_instrumentLabel;
m_trackName = i.m_trackName;
m_minPitchA = i.m_minPitchA;
m_maxPitchA = i.m_maxPitchA;
Expand Down Expand Up @@ -106,7 +106,7 @@ void Instrument::operator=(const Instrument& i)

m_id = i.m_id;
m_soundId = i.m_soundId;
m_instrumentName = i.m_instrumentName;
m_instrumentLabel = i.m_instrumentLabel;
m_trackName = i.m_trackName;
m_minPitchA = i.m_minPitchA;
m_maxPitchA = i.m_maxPitchA;
Expand Down Expand Up @@ -152,8 +152,8 @@ String Instrument::recognizeMusicXmlId() const
nameList.reserve(3);

nameList.push_back(m_trackName);
nameList.push_back(m_instrumentName.longName());
nameList.push_back(m_instrumentName.shortName());
nameList.push_back(m_instrumentLabel.longName());
nameList.push_back(m_instrumentLabel.shortName());

const InstrumentTemplate* tmplByName = mu::engraving::searchTemplateForInstrNameList(nameList, m_useDrumset);

Expand Down Expand Up @@ -805,7 +805,7 @@ void Instrument::setGlissandoStyle(GlissandoStyle style)

bool Instrument::operator==(const Instrument& i) const
{
bool equal = i.m_instrumentName == m_instrumentName;
bool equal = i.m_instrumentLabel == m_instrumentLabel;
equal &= i.m_trackName == m_trackName;
equal &= i.m_id == m_id;
equal &= i.m_soundId == m_soundId;
Expand Down Expand Up @@ -864,14 +864,36 @@ bool Instrument::isDifferentInstrument(const Instrument& i) const

String Instrument::family() const
{
auto search = searchTemplateIndexForId(m_id);
static const String NO_FAMILY = u"-";

if (!search.instrTemplate) {
static String empty;
return empty;
if (m_familyCache.empty()) {
auto search = searchTemplateIndexForId(m_id);

if (search.instrTemplate) {
m_familyCache = search.instrTemplate->familyId();
} else {
m_familyCache = NO_FAMILY;
}
}

return m_familyCache == NO_FAMILY ? String() : m_familyCache;
}

String Instrument::group() const
{
static const String NO_GROUP = u"-";

if (m_groupCache.empty()) {
auto search = searchTemplateIndexForId(m_id);

if (search.instrTemplate) {
m_groupCache = search.instrTemplate->groupId;
} else {
m_groupCache = NO_GROUP;
}
}

return search.instrTemplate->familyId();
return m_groupCache == NO_GROUP ? String() : m_groupCache;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1051,22 +1073,22 @@ void Instrument::setTrackName(const String& s)

String Instrument::nameAsXmlText() const
{
return m_instrumentName.longName();
return m_instrumentLabel.longName();
}

String Instrument::nameAsPlainText() const
{
return TextBase::unEscape(m_instrumentName.longName());
return TextBase::unEscape(m_instrumentLabel.longName());
}

String Instrument::abbreviatureAsXmlText() const
{
return m_instrumentName.shortName();
return m_instrumentLabel.shortName();
}

String Instrument::abbreviatureAsPlainText() const
{
return TextBase::unEscape(m_instrumentName.shortName());
return TextBase::unEscape(m_instrumentLabel.shortName());
}

Instrument Instrument::fromTemplate(const InstrumentTemplate* templ)
Expand Down
27 changes: 19 additions & 8 deletions src/engraving/dom/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "clef.h"
#include "interval.h"
#include "notifier.h"
#include "staffname.h"
#include "stafflabel.h"
#include "stringdata.h"

#include "../compat/midi/midicoreevent.h"
Expand Down Expand Up @@ -285,6 +285,7 @@ class Instrument
const String& soundId() const { return m_soundId; }
void setSoundId(const String& id) { m_soundId = id; }
String family() const;
String group() const;
void setId(const String& id) { m_id = id; }
void setMinPitchP(int v) { m_minPitchP = v; }
void setMaxPitchP(int v) { m_maxPitchP = v; }
Expand Down Expand Up @@ -326,12 +327,19 @@ class Instrument
void setStringData(const StringData& d) { m_stringData.set(d); }
bool hasStrings() const { return m_stringData.strings() > 0; }

void setLongName(const String& f) { m_instrumentName.setLongName(f); }
void setShortName(const String& f) { m_instrumentName.setShortName(f); }
void setInstrumentName(const StaffName& n) { m_instrumentName = n; }
const String& longName() const { return m_instrumentName.longName(); }
const String& shortName() const { return m_instrumentName.shortName(); }
const StaffName& instrumentName() const { return m_instrumentName; }
void setLongName(const String& f) { m_instrumentLabel.setLongName(f); }
void setShortName(const String& f) { m_instrumentLabel.setShortName(f); }
void setInstrumentName(const InstrumentLabel& n) { m_instrumentLabel = n; }
const String& longName() const { return m_instrumentLabel.longName(); }
const String& shortName() const { return m_instrumentLabel.shortName(); }
const InstrumentLabel& instrumentLabel() const { return m_instrumentLabel; }
InstrumentLabel& instrumentLabel() { return m_instrumentLabel; }

int number() const { return m_instrumentLabel.number(); }
void setNumber(int v) { return m_instrumentLabel.setNumber(v); }

const String& transposition() const { return m_instrumentLabel.transposition(); }
void setTransposition(const String& s) { m_instrumentLabel.setTransposition(s); }

int minPitchP() const;
int maxPitchP() const;
Expand Down Expand Up @@ -369,7 +377,7 @@ class Instrument

private:

StaffName m_instrumentName;
InstrumentLabel m_instrumentLabel;

String m_trackName;
String m_id;
Expand All @@ -396,6 +404,9 @@ class Instrument
Trait m_trait;
bool m_isPrimary = false;

mutable String m_familyCache;
mutable String m_groupCache;

GlissandoStyle m_glissandoStyle = GlissandoStyle::CHROMATIC;
};

Expand Down
8 changes: 6 additions & 2 deletions src/engraving/dom/instrumentname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ mu::engraving::staff_idx_t mu::engraving::InstrumentName::effectiveStaffIdx() co
{
if (m_sysStaff->show() || m_instrumentNameRole == InstrumentNameRole::STAFF) {
return staffIdx();
} else if (m_instrumentNameRole == InstrumentNameRole::PART) {
return system()->firstVisibleSysStaffOfPart(score()->staff(staffIdx())->part());
} else {
staff_idx_t curIdx = staffIdx();
Instrument* instr = score()->staff(curIdx)->part()->instrument(system()->first()->tick());
return system()->firstVisibleSysStaffWithInstrument(instr->id(), curIdx);
}

return system()->firstVisibleSysStaffOfPart(score()->staff(staffIdx())->part());
}
}
15 changes: 14 additions & 1 deletion src/engraving/dom/instrumentname.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum class InstrumentNameType : char {
LONG, SHORT
};
enum class InstrumentNameRole : char {
STAFF, PART
STAFF, PART, GROUP
};

class System;
Expand Down Expand Up @@ -71,6 +71,19 @@ class InstrumentName final : public TextBase

staff_idx_t effectiveStaffIdx() const override;

struct LayoutData : public TextBase::LayoutData {
public:
int column() const { return m_column; }
void setColumn(int v) { m_column = v; }
staff_idx_t endIdxOfGroup() const { return m_endIdxOfGroup; }
void setEndIdxOfGroup(staff_idx_t v) { m_endIdxOfGroup = v; }

private:
int m_column = 0;
staff_idx_t m_endIdxOfGroup = muse::nidx; // one-after last spanned staff (for GROUP types)
};
DECLARE_LAYOUTDATA_METHODS(InstrumentName)

private:

InstrumentNameType m_instrumentNameType = InstrumentNameType::LONG;
Expand Down
40 changes: 39 additions & 1 deletion src/engraving/dom/part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Part::Part(Score* s)

void Part::initFromInstrTemplate(const InstrumentTemplate* t)
{
m_partName = t->instrumentName.longName();
setInstrument(Instrument::fromTemplate(t));
}

Expand Down Expand Up @@ -557,6 +556,26 @@ void Part::setShortNameAll(const String& s)
}
}

int Part::number(const Fraction& tick) const
{
return instrument(tick)->number();
}

void Part::setNumber(int v, const Fraction& tick)
{
instrument(tick)->setNumber(v);
}

String Part::transposition(const Fraction& tick) const
{
return instrument(tick)->transposition();
}

void Part::setTransposition(const String& s, const Fraction& tick)
{
instrument(tick)->setTransposition(s);
}

//---------------------------------------------------------
// setPlainLongName
//---------------------------------------------------------
Expand Down Expand Up @@ -832,6 +851,25 @@ Fraction Part::currentHarpDiagramTick(const Fraction& tick) const
return Fraction::fromTicks(i->first);
}

String Part::partName() const
{
const Instrument* i = instrument();
String fullName = i->longName();

const String& transp = i->transposition();
if (!transp.empty()) {
//: For instrument transposition, e.g. Horn in F
fullName += u" " + muse::mtrc("notation", "in") + u" " + transp;
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps leave some context for translators with a //: comment above, saying that this is for instrument transpositions

}

int n = number();
if (n != 0) {
fullName += u" " + String::number(n);
}

return fullName;
}

bool Part::isVisible() const
{
return m_show;
Expand Down
11 changes: 8 additions & 3 deletions src/engraving/dom/part.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ class Part final : public EngravingObject
void setLongNameAll(const String& s); // For all instruments in _instruments
void setShortNameAll(const String& s); // For all instruments in _instruments

int number(const Fraction& tick = { -1, 1 }) const;
void setNumber(int v, const Fraction& tick = { -1, 1 });

String transposition(const Fraction& tick = { -1, 1 }) const;
void setTransposition(const String& s, const Fraction& tick = { -1, 1 });

void setPlainLongName(const String& s);
void setPlainShortName(const String& s);
void setPlainLongNameAll(const String& s);
Expand Down Expand Up @@ -153,8 +159,8 @@ class Part final : public EngravingObject
HarpPedalDiagram* prevHarpDiagram(const Fraction&) const;
Fraction currentHarpDiagramTick(const Fraction&) const;

String partName() const { return m_partName; }
void setPartName(const String& s) { m_partName = s; }
String partName() const;

int color() const { return m_color; }
void setColor(int value) { m_color = value; }

Expand Down Expand Up @@ -196,7 +202,6 @@ class Part final : public EngravingObject
private:
friend class read206::Read206;

String m_partName; ///< used in tracklist (mixer)
InstrumentList m_instruments;
std::vector<Staff*> m_staves;
muse::ID m_id = INVALID_ID; ///< used for MusicXML import
Expand Down
Loading
Loading