Skip to content

Commit

Permalink
Change instrument id from musicXMLid to an unique instrument id as de…
Browse files Browse the repository at this point in the history
…fined by the "id" attribute of the "instrument" tag in instruments.xml.

Reasons for this change are:
 - musicXMLid isn't unique for instruments.
 - not all instruments have a musicXMLid defined.
  • Loading branch information
njvdberg committed May 5, 2021
1 parent 2e59281 commit 02beed5
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/instruments/instrumentstypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct Instrument
StaffNameList longNames;
StaffNameList shortNames;
QString name;
QString musicXMLid;
QString description;

bool extended = false;
Expand Down
8 changes: 5 additions & 3 deletions src/instruments/internal/instrumentsreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ InstrumentTemplate InstrumentsReader::readInstrumentTemplate(Ms::XmlReader& read
InstrumentTemplate instrumentTemplate;
Instrument& instrument = instrumentTemplate.instrument;

instrumentTemplate.id = reader.attributes().value("id").toString();
instrument.id = reader.attributes().value("id").toString();
instrumentTemplate.id = instrument.id;

bool customDrumset = false;

Expand Down Expand Up @@ -242,7 +243,7 @@ InstrumentTemplate InstrumentsReader::readInstrumentTemplate(Ms::XmlReader& read
} else if (reader.name() == "transposeDiatonic") {
instrument.transpose.diatonic = reader.readElementText().toInt();
} else if (reader.name() == "instrumentId") {
instrument.id = reader.readElementText();
instrument.musicXMLid = reader.readElementText();
} else if (reader.name() == "StringData") {
instrument.stringData = readStringData(reader);
} else if (reader.name() == "useDrumset") {
Expand Down Expand Up @@ -296,7 +297,7 @@ InstrumentTemplate InstrumentsReader::readInstrumentTemplate(Ms::XmlReader& read
QString templateId = reader.readElementText();
initInstrument(instrument, generalMeta.instrumentTemplates[templateId].instrument);
} else if (reader.name() == "musicXMLid") {
instrument.id = reader.readElementText();
instrument.musicXMLid = reader.readElementText();
} else if (reader.name() == "genre") {
instrument.genreIds << reader.readElementText();
} else if (reader.name() == "singleNoteDynamics") {
Expand Down Expand Up @@ -417,6 +418,7 @@ void InstrumentsReader::fillByDefault(Instrument& instrument) const
void InstrumentsReader::initInstrument(Instrument& sourceInstrument, const Instrument& destinationInstrument) const
{
sourceInstrument.id = destinationInstrument.id;
sourceInstrument.musicXMLid = destinationInstrument.musicXMLid;
sourceInstrument.longNames = destinationInstrument.longNames;
sourceInstrument.shortNames = destinationInstrument.shortNames;
sourceInstrument.staves = destinationInstrument.staves;
Expand Down
1 change: 1 addition & 0 deletions src/libmscore/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class Instrument
bool isDifferentInstrument(const Instrument& i) const;

QString getId() const { return _id; }
void setId(const QString& id) { _id = id; }
void setMinPitchP(int v) { _minPitchP = v; }
void setMaxPitchP(int v) { _maxPitchP = v; }
void setMinPitchA(int v) { _minPitchA = v; }
Expand Down
4 changes: 2 additions & 2 deletions src/libmscore/part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ const InstrumentList* Part::instruments() const

bool Part::isDoublingInstrument(const QString& instrumentId) const
{
return instrument()->instrumentId() != instrumentId;
return instrument()->getId() != instrumentId;
}

//---------------------------------------------------------
Expand All @@ -409,7 +409,7 @@ bool Part::isDoublingInstrument(const QString& instrumentId) const

QString Part::instrumentId(const Fraction& tick) const
{
return instrument(tick)->instrumentId();
return instrument(tick)->getId();
}

//---------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions src/notation/internal/instrumentsconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Ms::Instrument InstrumentsConverter::convertInstrument(const mu::instruments::In

result.setTrackName(instrument.name);
result.setTranspose(instrument.transpose);
result.setInstrumentId(instrument.id);
result.setId(instrument.id);
result.setInstrumentId(instrument.musicXMLid);

if (instrument.useDrumset) {
result.setDrumset(instrument.drumset ? instrument.drumset : Ms::smDrumset);
Expand Down Expand Up @@ -82,7 +83,8 @@ mu::instruments::Instrument InstrumentsConverter::convertInstrument(const Ms::In

result.name = instrument.trackName();
result.transpose = instrument.transpose();
result.id = instrument.instrumentId();
result.id = instrument.getId();
result.musicXMLid = instrument.instrumentId();
result.useDrumset = instrument.useDrumset();
result.drumset = instrument.drumset();

Expand Down
22 changes: 11 additions & 11 deletions src/notation/internal/notationparts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ bool NotationParts::needAssignInstrumentToChord(const ID& instrumentId, const ID
QMap<Ms::Fraction, Ms::InstrumentChange*> instrumentChangeElements = this->instrumentChangeElements(fromPartId);

for (const Ms::InstrumentChange* instrumentChange: instrumentChangeElements.values()) {
if (instrumentChange->instrument()->instrumentId() == instrumentId) {
if (instrumentChange->instrument()->getId() == instrumentId) {
return false;
}
}
Expand All @@ -306,7 +306,7 @@ void NotationParts::assignIstrumentToSelectedChord(Ms::Instrument* instrument)
}

Part* part = chord->part();
part->removeInstrument(instrument->instrumentId());
part->removeInstrument(instrument->getId());
part->setInstrument(instrument, chord->segment()->tick());

auto instrumentChange = new Ms::InstrumentChange(*instrument, score());
Expand Down Expand Up @@ -656,7 +656,7 @@ void NotationParts::appendStaff(Staff* staff, const ID& destinationPartId)
Ms::Instrument* instrument = instrumentInfo.instrument;
instrument->setClefType(staffIndex, staff->defaultClefType());

ChangedNotifier<const Staff*>* notifier = instrumentNotifier(instrument->instrumentId(), destinationPartId);
ChangedNotifier<const Staff*>* notifier = instrumentNotifier(instrument->getId(), destinationPartId);
notifier->itemAdded(staff);
}

Expand Down Expand Up @@ -889,7 +889,7 @@ QMap<Ms::Fraction, Ms::Instrument*> NotationParts::instruments(const Part* fromP
Ms::Fraction fraction = Ms::Fraction::fromTicks(it->first);
Ms::Instrument* instrument = it->second;

bool acceptedByFilter = !filterInstrumentsIds.isEmpty() ? filterInstrumentsIds.contains(instrument->instrumentId()) : true;
bool acceptedByFilter = !filterInstrumentsIds.isEmpty() ? filterInstrumentsIds.contains(instrument->getId()) : true;
if (acceptedByFilter) {
result.insert(fraction, instrument);
}
Expand All @@ -913,7 +913,7 @@ void NotationParts::doInsertInstruments(const QMap<Ms::Fraction, Ms::Instrument*

int destinationIndex = 0;
for (int i = 0; i < partInstruments.size(); i++) {
if (partInstruments[i]->instrumentId() == destinationInstrumentId) {
if (partInstruments[i]->getId() == destinationInstrumentId) {
destinationIndex = i;
break;
}
Expand Down Expand Up @@ -1080,7 +1080,7 @@ NotationParts::InstrumentInfo NotationParts::instrumentInfo(const ID& instrument

for (const Ms::Fraction& fraction: partInstruments.keys()) {
Ms::Instrument* instrument = partInstruments.value(fraction);
if (instrument->instrumentId() == instrumentId) {
if (instrument->getId() == instrumentId) {
return InstrumentInfo(fraction, instrument);
}
}
Expand Down Expand Up @@ -1232,8 +1232,8 @@ void NotationParts::removeMissingInstruments(const InstrumentList& instruments)
IDList instrumentsToRemove;

for (const Ms::Instrument* instrument: partInstruments.values()) {
if (!instrumentIds.contains(instrument->instrumentId())) {
instrumentsToRemove << instrument->instrumentId();
if (!instrumentIds.contains(instrument->getId())) {
instrumentsToRemove << instrument->getId();
}
}

Expand Down Expand Up @@ -1283,7 +1283,7 @@ void NotationParts::sortParts(const InstrumentList& instruments)
Q_ASSERT(score()->parts().size() == static_cast<int>(instruments.size()));

auto mainInstrumentId = [](const Part* part) {
return part->instrument()->instrumentId();
return part->instrument()->getId();
};

for (int i = 0; i < instruments.size(); ++i) {
Expand Down Expand Up @@ -1312,7 +1312,7 @@ IDList NotationParts::allInstrumentsIds() const
auto partInstruments = instruments(part);

for (const Ms::Instrument* instrument: partInstruments.values()) {
result << instrument->instrumentId();
result << instrument->getId();
}
}

Expand Down Expand Up @@ -1351,7 +1351,7 @@ void NotationParts::notifyAboutStaffChanged(const ID& staffId) const
}

InstrumentInfo instrumentInfo = this->instrumentInfo(staff);
ChangedNotifier<const Staff*>* notifier = instrumentNotifier(instrumentInfo.instrument->instrumentId(), staff->part()->id());
ChangedNotifier<const Staff*>* notifier = instrumentNotifier(instrumentInfo.instrument->getId(), staff->part()->id());
notifier->itemChanged(staff);
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/api/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class Instrument : public QObject

Ms::Part* part() { return _part; }

QString instrumentId() const { return instrument()->instrumentId(); }
QString instrumentId() const { return instrument()->getId(); }
QString longName() const;
QString shortName() const;

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/api/part.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Part : public Ms::PluginAPI::ScoreElement

int startTrack() const { return part()->startTrack(); }
int endTrack() const { return part()->endTrack(); }
QString instrumentId() const { return part()->instrument()->instrumentId(); }
QString instrumentId() const { return part()->instrument()->getId(); }
int harmonyCount() const { return part()->harmonyCount(); }
bool hasPitchedStaff() const { return part()->hasPitchedStaff(); }
bool hasTabStaff() const { return part()->hasTabStaff(); }
Expand Down

0 comments on commit 02beed5

Please sign in to comment.