From ce351701752dea3724852232abb459f0fb48a020 Mon Sep 17 00:00:00 2001 From: Roman Pudashkin Date: Tue, 3 Aug 2021 15:53:21 +0200 Subject: [PATCH 1/3] fixed the ID generation process for parts/staves --- src/engraving/libmscore/excerpt.cpp | 1 + src/engraving/libmscore/part.cpp | 9 +++-- src/engraving/libmscore/staff.cpp | 13 ++----- src/engraving/libmscore/staff.h | 1 - src/framework/audio/internal/audiothread.cpp | 2 +- .../view/staffcontroltreeitem.cpp | 13 +------ .../view/staffcontroltreeitem.h | 2 - .../view/staffsettingsmodel.cpp | 2 - src/notation/internal/notationparts.cpp | 39 ++++++++++++++++++- src/notation/internal/notationparts.h | 3 ++ 10 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/engraving/libmscore/excerpt.cpp b/src/engraving/libmscore/excerpt.cpp index a5f9444e97..4b152f2de0 100644 --- a/src/engraving/libmscore/excerpt.cpp +++ b/src/engraving/libmscore/excerpt.cpp @@ -228,6 +228,7 @@ void Excerpt::createExcerpt(Excerpt* excerpt) // Set instruments and create linked staves for (const Part* part : parts) { Part* p = new Part(score); + p->setId(part->id()); p->setInstrument(*part->instrument()); p->setPartName(part->partName()); diff --git a/src/engraving/libmscore/part.cpp b/src/engraving/libmscore/part.cpp index 7286ac633c..25c08d6053 100644 --- a/src/engraving/libmscore/part.cpp +++ b/src/engraving/libmscore/part.cpp @@ -48,9 +48,6 @@ namespace Ms { Part::Part(Score* s) : ScoreElement(s) { - static std::atomic_int currentId { 0 }; - _id = QString::number(++currentId); - _color = DEFAULT_COLOR; _show = true; _soloist = false; @@ -178,6 +175,8 @@ bool Part::readProperties(XmlReader& e) void Part::read(XmlReader& e) { + _id = e.attribute("id"); + while (e.readNextStartElement()) { if (!readProperties(e)) { e.unknown(); @@ -194,7 +193,8 @@ void Part::read(XmlReader& e) void Part::write(XmlWriter& xml) const { - xml.stag(this); + xml.stag(this, QString("id=\"%1\"").arg(_id)); + for (const Staff* staff : _staves) { staff->write(xml); } @@ -213,6 +213,7 @@ void Part::write(XmlWriter& xml) const _preferSharpFlat == PreferSharpFlat::SHARPS ? "sharps" : "flats"); } instrument()->write(xml, this); + xml.etag(); } diff --git a/src/engraving/libmscore/staff.cpp b/src/engraving/libmscore/staff.cpp index 5777f1289b..dadc2c891a 100644 --- a/src/engraving/libmscore/staff.cpp +++ b/src/engraving/libmscore/staff.cpp @@ -63,7 +63,6 @@ namespace Ms { Staff::Staff(Score* score) : Element(score) { - setId(makeId()); initFromStaffType(0); } @@ -720,8 +719,8 @@ Fraction Staff::currentKeyTick(const Fraction& tick) const void Staff::write(XmlWriter& xml) const { - int idx = this->idx(); - xml.stag(this, QString("id=\"%1\"").arg(idx + 1)); + xml.stag(this, QString("id=\"%1\"").arg(_id)); + if (links()) { Score* s = masterScore(); for (auto le : *links()) { @@ -800,6 +799,8 @@ void Staff::write(XmlWriter& xml) const void Staff::read(XmlReader& e) { + _id = e.attribute("id"); + while (e.readNextStartElement()) { if (!readProperties(e)) { e.unknown(); @@ -942,12 +943,6 @@ void Staff::setId(const QString& id) _id = id; } -QString Staff::makeId() -{ - static std::atomic_int currentId { 0 }; - return QString::number(++currentId); -} - qreal Staff::staffMag(const Fraction& tick) const { return staffMag(staffType(tick)); diff --git a/src/engraving/libmscore/staff.h b/src/engraving/libmscore/staff.h index 1afac43629..a4c7dabe4c 100644 --- a/src/engraving/libmscore/staff.h +++ b/src/engraving/libmscore/staff.h @@ -137,7 +137,6 @@ public: int rstaff() const; QString id() const; void setId(const QString& id); - static QString makeId(); int idx() const; void read(XmlReader&) override; bool readProperties(XmlReader&) override; diff --git a/src/framework/audio/internal/audiothread.cpp b/src/framework/audio/internal/audiothread.cpp index 70c1c75efb..63977b0105 100644 --- a/src/framework/audio/internal/audiothread.cpp +++ b/src/framework/audio/internal/audiothread.cpp @@ -83,7 +83,7 @@ void AudioThread::main() } while (m_running) { - mu::async::processEvents(); + //mu::async::processEvents(); if (m_mainLoopBody) { m_mainLoopBody(); diff --git a/src/instrumentsscene/view/staffcontroltreeitem.cpp b/src/instrumentsscene/view/staffcontroltreeitem.cpp index 06db64e954..6ab0d34e97 100644 --- a/src/instrumentsscene/view/staffcontroltreeitem.cpp +++ b/src/instrumentsscene/view/staffcontroltreeitem.cpp @@ -31,7 +31,7 @@ StaffControlTreeItem::StaffControlTreeItem(IMasterNotationPtr masterNotation, IN void StaffControlTreeItem::appendNewItem() { - const Part* part = this->part(); + const Part* part = masterNotation()->parts()->part(m_partId); if (!part) { return; } @@ -44,17 +44,6 @@ void StaffControlTreeItem::appendNewItem() masterNotation()->parts()->appendStaff(staff, m_partId); } -const Part* StaffControlTreeItem::part() const -{ - for (const Part* part : notation()->parts()->partList()) { - if (part->id() == m_partId) { - return part; - } - } - - return nullptr; -} - void StaffControlTreeItem::setPartId(const QString& id) { m_partId = id; diff --git a/src/instrumentsscene/view/staffcontroltreeitem.h b/src/instrumentsscene/view/staffcontroltreeitem.h index e54c5623e2..2780a7453d 100644 --- a/src/instrumentsscene/view/staffcontroltreeitem.h +++ b/src/instrumentsscene/view/staffcontroltreeitem.h @@ -39,8 +39,6 @@ public: void setPartId(const QString& id); private: - const notation::Part* part() const; - QString m_partId; }; } diff --git a/src/instrumentsscene/view/staffsettingsmodel.cpp b/src/instrumentsscene/view/staffsettingsmodel.cpp index ad3d73f38e..43cecdf59d 100644 --- a/src/instrumentsscene/view/staffsettingsmodel.cpp +++ b/src/instrumentsscene/view/staffsettingsmodel.cpp @@ -163,8 +163,6 @@ void StaffSettingsModel::createLinkedStaff() } Staff* linkedStaff = sourceStaff->clone(); - linkedStaff->setId(Staff::makeId()); - masterNotationParts()->appendStaff(linkedStaff, sourceStaff->part()->id()); masterNotationParts()->linkStaves(sourceStaff->id(), linkedStaff->id()); } diff --git a/src/notation/internal/notationparts.cpp b/src/notation/internal/notationparts.cpp index 1d94d5ff70..dc28f24d30 100644 --- a/src/notation/internal/notationparts.cpp +++ b/src/notation/internal/notationparts.cpp @@ -260,6 +260,28 @@ void NotationParts::updatePartTitles() } } +ID NotationParts::newPartId() const +{ + ID maxId = ID(); + + for (const Part* part : score()->parts()) { + maxId = std::max(maxId, part->id()); + } + + return maxId + QString::number(1); +} + +ID NotationParts::newStaffId() const +{ + ID maxId = ID(); + + for (const Staff* staff : score()->staves()) { + maxId = std::max(maxId, staff->id()); + } + + return maxId + QString::number(1); +} + void NotationParts::doMoveStaves(const std::vector& staves, int destinationStaffIndex, Part* destinationPart) { TRACEFUNC; @@ -552,6 +574,14 @@ void NotationParts::appendPart(Part* part) { TRACEFUNC; + IF_ASSERT_FAILED(part) { + return; + } + + if (part->id().isNull()) { + part->setId(newPartId()); + } + QList stavesCopy = *part->staves(); part->staves()->clear(); @@ -798,10 +828,16 @@ void NotationParts::appendStaves(Part* part, const Instrument& instrument) { TRACEFUNC; + IF_ASSERT_FAILED(part) { + return; + } + for (int staffIndex = 0; staffIndex < instrument.staves; ++staffIndex) { int lastStaffIndex = !score()->staves().isEmpty() ? score()->staves().last()->idx() : 0; Staff* staff = new Staff(score()); + staff->setId(newStaffId()); + staff->setPart(part); initStaff(staff, instrument, Ms::StaffType::preset(StaffType::STANDARD), staffIndex); @@ -899,8 +935,9 @@ void NotationParts::appendNewParts(const PartInstrumentList& parts) } Part* part = new Part(score()); - const Instrument& instrument = pi.instrument; + part->setId(newPartId()); + const Instrument& instrument = pi.instrument; part->setSoloist(pi.isSoloist); part->setInstrument(InstrumentsConverter::convertInstrument(instrument)); diff --git a/src/notation/internal/notationparts.h b/src/notation/internal/notationparts.h index fff6a2f69d..27042f643b 100644 --- a/src/notation/internal/notationparts.h +++ b/src/notation/internal/notationparts.h @@ -83,6 +83,9 @@ protected: private: void updatePartTitles(); + ID newPartId() const; + ID newStaffId() const; + void doMoveStaves(const std::vector& staves, int destinationStaffIndex, Part* destinationPart = nullptr); void doSetStaffVisible(Staff* staff, bool visible); void doSetStaffVoiceVisible(Staff* staff, int voiceIndex, bool visible); From 4ad2376ccb268c49afd6983b9daefeff3c32c020 Mon Sep 17 00:00:00 2001 From: Roman Pudashkin Date: Wed, 4 Aug 2021 13:12:41 +0200 Subject: [PATCH 2/3] implemented ID instead of using strings --- src/engraving/libmscore/excerpt.cpp | 2 +- src/engraving/libmscore/excerpt.h | 2 +- src/engraving/libmscore/mscore.h | 3 + src/engraving/libmscore/part.cpp | 18 ++- src/engraving/libmscore/part.h | 17 +-- src/engraving/libmscore/score.cpp | 13 +- src/engraving/libmscore/score.h | 3 +- src/engraving/libmscore/staff.cpp | 33 ++--- src/engraving/libmscore/staff.h | 12 +- src/framework/audio/internal/audiothread.cpp | 2 +- src/framework/global/CMakeLists.txt | 2 + src/framework/global/id.cpp | 115 ++++++++++++++++++ src/framework/global/id.h | 75 ++++++++++++ .../bww/internal/bww/importbww.cpp | 2 - .../internal/musicxml/importmxmlpass1.cpp | 1 - .../internal/selectinstrumentscenario.cpp | 12 +- .../internal/selectinstrumentscenario.h | 5 +- .../internal/InstrumentsTreeItemDelegate.qml | 4 +- .../view/abstractinstrumentspaneltreeitem.cpp | 11 +- .../view/abstractinstrumentspaneltreeitem.h | 11 +- .../view/instrumentlistmodel.cpp | 26 ++-- .../view/instrumentlistmodel.h | 4 +- .../view/instrumentsettingsmodel.cpp | 6 +- .../view/instrumentspaneltreemodel.cpp | 18 +-- .../view/instrumentspaneltreemodel.h | 4 +- src/instrumentsscene/view/parttreeitem.cpp | 4 +- src/instrumentsscene/view/parttreeitem.h | 2 +- src/instrumentsscene/view/roottreeitem.cpp | 4 +- .../view/staffcontroltreeitem.cpp | 2 +- .../view/staffcontroltreeitem.h | 4 +- .../view/staffsettingsmodel.h | 2 +- src/notation/internal/notationparts.cpp | 45 +++---- src/notation/internal/notationparts.h | 5 +- src/notation/internal/notationplayback.cpp | 12 +- src/notation/internal/notationplayback.h | 2 +- src/notation/iselectinstrumentscenario.h | 4 +- src/notation/notationtypes.h | 6 +- src/notation/view/widgets/editstaff.cpp | 2 +- .../view/widgets/editdrumsetdialog.cpp | 2 +- 39 files changed, 353 insertions(+), 144 deletions(-) create mode 100644 src/framework/global/id.cpp create mode 100644 src/framework/global/id.h diff --git a/src/engraving/libmscore/excerpt.cpp b/src/engraving/libmscore/excerpt.cpp index 4b152f2de0..6e90e35d48 100644 --- a/src/engraving/libmscore/excerpt.cpp +++ b/src/engraving/libmscore/excerpt.cpp @@ -114,7 +114,7 @@ bool Excerpt::isEmpty() const return partScore() ? partScore()->parts().empty() : true; } -void Excerpt::removePart(const QString& id) +void Excerpt::removePart(const ID& id) { int index = 0; for (const Part* part: parts()) { diff --git a/src/engraving/libmscore/excerpt.h b/src/engraving/libmscore/excerpt.h index 71b99d47d5..8e4abb3ead 100644 --- a/src/engraving/libmscore/excerpt.h +++ b/src/engraving/libmscore/excerpt.h @@ -60,7 +60,7 @@ public: const QList& parts() const { return _parts; } bool containsPart(const Part* part) const; - void removePart(const QString& id); + void removePart(const ID& id); void setParts(const QList& p) { _parts = p; } diff --git a/src/engraving/libmscore/mscore.h b/src/engraving/libmscore/mscore.h index 6d4182e9a4..d43cfc3b83 100644 --- a/src/engraving/libmscore/mscore.h +++ b/src/engraving/libmscore/mscore.h @@ -135,6 +135,9 @@ static const int VISUAL_STRING_NONE = -100; // no ordinal for the visu static const int STRING_NONE = -1; // no ordinal for a physical string (0 = topmost in instrument) static const int FRET_NONE = -1; // no ordinal for a fret +using ID = uint64_t; +static constexpr ID INVALID_ID = 0; + //--------------------------------------------------------- // BracketType // System Brackets diff --git a/src/engraving/libmscore/part.cpp b/src/engraving/libmscore/part.cpp index 25c08d6053..6f4799db68 100644 --- a/src/engraving/libmscore/part.cpp +++ b/src/engraving/libmscore/part.cpp @@ -65,6 +65,16 @@ void Part::initFromInstrTemplate(const InstrumentTemplate* t) setInstrument(Instrument::fromTemplate(t)); } +ID Part::id() const +{ + return _id; +} + +void Part::setId(const ID& id) +{ + _id = id; +} + Part* Part::clone() const { return new Part(*this); @@ -175,7 +185,9 @@ bool Part::readProperties(XmlReader& e) void Part::read(XmlReader& e) { - _id = e.attribute("id"); + if (e.hasAttribute("id")) { + _id = e.attribute("id").toULongLong(); + } while (e.readNextStartElement()) { if (!readProperties(e)) { @@ -193,7 +205,9 @@ void Part::read(XmlReader& e) void Part::write(XmlWriter& xml) const { - xml.stag(this, QString("id=\"%1\"").arg(_id)); + if (_id != INVALID_ID) { + xml.stag(this, QString("id=\"%1\"").arg(_id)); + } for (const Staff* staff : _staves) { staff->write(xml); diff --git a/src/engraving/libmscore/part.h b/src/engraving/libmscore/part.h index 320075e918..ab1dcc1ce3 100644 --- a/src/engraving/libmscore/part.h +++ b/src/engraving/libmscore/part.h @@ -70,21 +70,24 @@ class Part final : public ScoreElement QString _partName; ///< used in tracklist (mixer) InstrumentList _instruments; QList _staves; - QString _id; ///< used for MusicXml import - bool _show; ///< show part in partitur if true - bool _soloist; ///< used in score ordering + ID _id = INVALID_ID; ///< used for MusicXml import + bool _show = false; ///< show part in partitur if true + bool _soloist = false; ///< used in score ordering static const int DEFAULT_COLOR = 0x3399ff; - int _color; ///User specified color for helping to label parts + int _color = 0; ///User specified color for helping to label parts - PreferSharpFlat _preferSharpFlat; + PreferSharpFlat _preferSharpFlat = PreferSharpFlat::DEFAULT; friend class mu::engraving::compat::Read206; public: - Part(Score* = 0); + Part(Score* score = nullptr); void initFromInstrTemplate(const InstrumentTemplate*); + ID id() const; + void setId(const ID& id); + Part* clone() const; ElementType type() const override { return ElementType::PART; } @@ -97,8 +100,6 @@ public: QList* staves() { return &_staves; } const QList* staves() const { return &_staves; } Staff* staff(int idx) const; - void setId(const QString& s) { _id = s; } - QString id() const { return _id; } QString familyId() const; int startTrack() const; diff --git a/src/engraving/libmscore/score.cpp b/src/engraving/libmscore/score.cpp index 93e1ddc824..4aae95e978 100644 --- a/src/engraving/libmscore/score.cpp +++ b/src/engraving/libmscore/score.cpp @@ -5162,7 +5162,7 @@ int Score::staffIdx(const Part* part) const return idx; } -Staff* Score::staff(const QString& staffId) const +Staff* Score::staff(const ID& staffId) const { for (Staff* staff : _staves) { if (staff->id() == staffId) { @@ -5173,6 +5173,17 @@ Staff* Score::staff(const QString& staffId) const return nullptr; } +Part* Score::part(const ID& partId) const +{ + for (Part* part : _parts) { + if (part->id() == partId) { + return part; + } + } + + return nullptr; +} + mu::score::AccessibleScore* Score::accessible() const { return m_accessible; diff --git a/src/engraving/libmscore/score.h b/src/engraving/libmscore/score.h index a1dfd6697c..9acb9f9084 100644 --- a/src/engraving/libmscore/score.h +++ b/src/engraving/libmscore/score.h @@ -695,7 +695,8 @@ public: int staffIdx(const Part*) const; Staff* staff(int n) const { return ((n >= 0) && (n < _staves.size())) ? _staves.at(n) : nullptr; } - Staff* staff(const QString& staffId) const; + Staff* staff(const ID& staffId) const; + Part* part(const ID& partId) const; Measure* pos2measure(const mu::PointF&, int* staffIdx, int* pitch, Segment**, mu::PointF* offset) const; void dragPosition(const mu::PointF&, int* staffIdx, Segment**, qreal spacingFactor = 0.5) const; diff --git a/src/engraving/libmscore/staff.cpp b/src/engraving/libmscore/staff.cpp index dadc2c891a..64505c3d6e 100644 --- a/src/engraving/libmscore/staff.cpp +++ b/src/engraving/libmscore/staff.cpp @@ -95,15 +95,6 @@ Staff* Staff::clone() const return new Staff(*this); } -//--------------------------------------------------------- -// id -//--------------------------------------------------------- - -QString Staff::id() const -{ - return _id; -} - //--------------------------------------------------------- // idx //--------------------------------------------------------- @@ -719,7 +710,9 @@ Fraction Staff::currentKeyTick(const Fraction& tick) const void Staff::write(XmlWriter& xml) const { - xml.stag(this, QString("id=\"%1\"").arg(_id)); + if (_id != INVALID_ID) { + xml.stag(this, QString("id=\"%1\"").arg(_id)); + } if (links()) { Score* s = masterScore(); @@ -799,7 +792,9 @@ void Staff::write(XmlWriter& xml) const void Staff::read(XmlReader& e) { - _id = e.attribute("id"); + if (e.hasAttribute("id")) { + _id = e.attribute("id").toULongLong(); + } while (e.readNextStartElement()) { if (!readProperties(e)) { @@ -938,11 +933,6 @@ qreal Staff::staffMag(const StaffType* stt) const return (stt->small() ? score()->styleD(Sid::smallStaffMag) : 1.0) * stt->userMag(); } -void Staff::setId(const QString& id) -{ - _id = id; -} - qreal Staff::staffMag(const Fraction& tick) const { return staffMag(staffType(tick)); @@ -1235,6 +1225,7 @@ void Staff::init(const InstrumentTemplate* t, const StaffType* staffType, int ci void Staff::init(const Staff* s) { + _id = s->_id; _staffTypeList = s->_staffTypeList; setDefaultClefType(s->defaultClefType()); for (BracketItem* i : s->_brackets) { @@ -1256,6 +1247,16 @@ void Staff::init(const Staff* s) _userDist = s->_userDist; } +ID Staff::id() const +{ + return _id; +} + +void Staff::setId(const ID& id) +{ + _id = id; +} + void Staff::setScore(Score* score) { Element::setScore(score); diff --git a/src/engraving/libmscore/staff.h b/src/engraving/libmscore/staff.h index a4c7dabe4c..b6f5028bed 100644 --- a/src/engraving/libmscore/staff.h +++ b/src/engraving/libmscore/staff.h @@ -78,8 +78,8 @@ public: }; private: - QString _id; - Part* _part { 0 }; + ID _id = INVALID_ID; + Part* _part = nullptr; ClefList clefs; ClefTypeList _defaultClefType; @@ -120,14 +120,18 @@ private: qreal staffMag(const StaffType*) const; public: - Staff(Score* score = 0); + Staff(Score* score = nullptr); Staff(const Staff& staff); Staff* clone() const override; ~Staff(); + void init(const InstrumentTemplate*, const StaffType* staffType, int); void initFromStaffType(const StaffType* staffType); void init(const Staff*); + ID id() const; + void setId(const ID& id); + ElementType type() const override { return ElementType::STAFF; } void setScore(Score* score) override; @@ -135,8 +139,6 @@ public: bool isTop() const; QString partName() const; int rstaff() const; - QString id() const; - void setId(const QString& id); int idx() const; void read(XmlReader&) override; bool readProperties(XmlReader&) override; diff --git a/src/framework/audio/internal/audiothread.cpp b/src/framework/audio/internal/audiothread.cpp index 63977b0105..70c1c75efb 100644 --- a/src/framework/audio/internal/audiothread.cpp +++ b/src/framework/audio/internal/audiothread.cpp @@ -83,7 +83,7 @@ void AudioThread::main() } while (m_running) { - //mu::async::processEvents(); + mu::async::processEvents(); if (m_mainLoopBody) { m_mainLoopBody(); diff --git a/src/framework/global/CMakeLists.txt b/src/framework/global/CMakeLists.txt index 938df0e004..bc74fa90fa 100644 --- a/src/framework/global/CMakeLists.txt +++ b/src/framework/global/CMakeLists.txt @@ -49,6 +49,8 @@ set(MODULE_SRC ${CMAKE_CURRENT_LIST_DIR}/logstream.h ${CMAKE_CURRENT_LIST_DIR}/dataformatter.cpp ${CMAKE_CURRENT_LIST_DIR}/dataformatter.h + ${CMAKE_CURRENT_LIST_DIR}/id.cpp + ${CMAKE_CURRENT_LIST_DIR}/id.h ${CMAKE_CURRENT_LIST_DIR}/val.cpp ${CMAKE_CURRENT_LIST_DIR}/val.h ${CMAKE_CURRENT_LIST_DIR}/settings.cpp diff --git a/src/framework/global/id.cpp b/src/framework/global/id.cpp new file mode 100644 index 0000000000..d4037c7ee8 --- /dev/null +++ b/src/framework/global/id.cpp @@ -0,0 +1,115 @@ +/* + * SPDX-License-Identifier: GPL-3.0-only + * MuseScore-CLA-applies + * + * MuseScore + * Music Composition & Notation + * + * Copyright (C) 2021 MuseScore BVBA and others + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "id.h" + +using namespace mu; + +ID::ID() + : m_id(0) +{ +} + +ID::ID(const ID& id) + : m_id(id.m_id) +{ +} + +ID::ID(const uint64_t& id) + : m_id(id) +{ +} + +bool ID::isValid() const +{ + return m_id != 0; +} + +ID& ID::operator=(const ID& id) +{ + m_id = id.m_id; + return *this; +} + +ID& ID::operator+=(const ID& id) +{ + m_id += id.m_id; + return *this; +} + +ID ID::operator+(const ID& id) const +{ + return ID(m_id + id.m_id); +} + +ID ID::operator^(const ID& id) const +{ + return ID(m_id ^ id.m_id); +} + +bool ID::operator==(const ID& id) const +{ + return m_id == id.m_id; +} + +bool ID::operator==(uint64_t id) const +{ + return m_id == id; +} + +bool ID::operator!=(const ID& id) const +{ + return m_id != id.m_id; +} + +bool ID::operator<(const ID& id) const +{ + return m_id < id.m_id; +} + +bool ID::operator>(const ID& id) const +{ + return m_id > id.m_id; +} + +uint64_t ID::toUint64() const +{ + return m_id; +} + +#ifndef NO_QT_SUPPORT +ID::ID(const QString& id) + : m_id(id.toULongLong()) +{ +} + +ID::ID(const QVariant& id) + : m_id(id.toULongLong()) +{ +} + +QString ID::toQString() const +{ + return QString::number(m_id); +} + +#endif diff --git a/src/framework/global/id.h b/src/framework/global/id.h new file mode 100644 index 0000000000..62de00e94b --- /dev/null +++ b/src/framework/global/id.h @@ -0,0 +1,75 @@ +/* + * SPDX-License-Identifier: GPL-3.0-only + * MuseScore-CLA-applies + * + * MuseScore + * Music Composition & Notation + * + * Copyright (C) 2021 MuseScore BVBA and others + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef MU_FRAMEWORK_ID_H +#define MU_FRAMEWORK_ID_H + +#include +#include + +#ifndef NO_QT_SUPPORT +#include +#endif + +namespace mu { +class ID +{ +public: + ID(); + ID(const ID& id); + ID(const uint64_t& id); + + bool isValid() const; + + ID& operator=(const ID& id); + ID& operator+=(const ID& id); + + ID operator+(const ID& id) const; + ID operator^(const ID& id) const; + + bool operator==(const ID& id) const; + bool operator==(uint64_t id) const; + bool operator!=(const ID& id) const; + bool operator<(const ID& id) const; + bool operator>(const ID& id) const; + + uint64_t toUint64() const; + +#ifndef NO_QT_SUPPORT + ID(const QString& id); + ID(const QVariant& id); + + QString toQString() const; +#endif + +private: + uint64_t m_id = 0; +}; + +using IDList = std::vector; + +inline bool containsId(const IDList& list, const ID& id) +{ + return std::find(list.cbegin(), list.cend(), id) != list.cend(); +} +} + +#endif // MU_FRAMEWORK_ID_H diff --git a/src/importexport/bww/internal/bww/importbww.cpp b/src/importexport/bww/internal/bww/importbww.cpp index 246746ac14..16b57300f6 100644 --- a/src/importexport/bww/internal/bww/importbww.cpp +++ b/src/importexport/bww/internal/bww/importbww.cpp @@ -549,9 +549,7 @@ Score::FileError importBww(MasterScore* score, const QString& path) return Score::FileError::FILE_OPEN_ERROR; } - QString id("importBww"); Part* part = new Part(score); - part->setId(id); score->appendPart(part); Staff* staff = new Staff(score); staff->setPart(part); diff --git a/src/importexport/musicxml/internal/musicxml/importmxmlpass1.cpp b/src/importexport/musicxml/internal/musicxml/importmxmlpass1.cpp index cf4088a7f2..1662400e28 100644 --- a/src/importexport/musicxml/internal/musicxml/importmxmlpass1.cpp +++ b/src/importexport/musicxml/internal/musicxml/importmxmlpass1.cpp @@ -1712,7 +1712,6 @@ static void createPart(Score* score, const QString& id, PartMap& pm) { Part* part = new Part(score); pm.insert(id, part); - part->setId(id); score->appendPart(part); Staff* staff = new Staff(score); staff->setPart(part); diff --git a/src/instrumentsscene/internal/selectinstrumentscenario.cpp b/src/instrumentsscene/internal/selectinstrumentscenario.cpp index b36195fbbc..9a59f3cec6 100644 --- a/src/instrumentsscene/internal/selectinstrumentscenario.cpp +++ b/src/instrumentsscene/internal/selectinstrumentscenario.cpp @@ -35,13 +35,13 @@ mu::RetVal SelectInstrumentsScenario::selectInstru return selectInstruments(params); } -mu::RetVal SelectInstrumentsScenario::selectInstrument(const std::string& currentInstrumentId) const +mu::RetVal SelectInstrumentsScenario::selectInstrument(const InstrumentKey& currentInstrumentKey) const { RetVal result; QStringList params { "canSelectMultipleInstruments=false", - "currentInstrumentId=" + QString::fromStdString(currentInstrumentId) + "currentInstrumentId=" + currentInstrumentKey.instrumentId.toQString() }; RetVal selectedInstruments = selectInstruments(params); @@ -101,18 +101,18 @@ INotationPartsPtr SelectInstrumentsScenario::notationParts() const return notation->parts(); } -IDList SelectInstrumentsScenario::partsIds() const +QStringList SelectInstrumentsScenario::partsIds() const { auto _notationParts = notationParts(); if (!_notationParts) { - return IDList(); + return QStringList(); } async::NotifyList parts = _notationParts->partList(); - IDList result; + QStringList result; for (const Part* part: parts) { - result << part->id(); + result << ID(part->id()).toQString(); } return result; diff --git a/src/instrumentsscene/internal/selectinstrumentscenario.h b/src/instrumentsscene/internal/selectinstrumentscenario.h index a746859a02..650b9dcf31 100644 --- a/src/instrumentsscene/internal/selectinstrumentscenario.h +++ b/src/instrumentsscene/internal/selectinstrumentscenario.h @@ -36,13 +36,14 @@ class SelectInstrumentsScenario : public notation::ISelectInstrumentsScenario public: RetVal selectInstruments(SelectInstrumentsMode mode = SelectInstrumentsMode::None) const override; - RetVal selectInstrument(const std::string& currentInstrumentId = "") const override; + RetVal selectInstrument(const notation::InstrumentKey& currentInstrumentId = notation::InstrumentKey()) const + override; private: RetVal selectInstruments(const QStringList& params) const; notation::INotationPartsPtr notationParts() const; - notation::IDList partsIds() const; + QStringList partsIds() const; notation::ScoreOrder scoreOrder() const; }; } diff --git a/src/instrumentsscene/qml/MuseScore/InstrumentsScene/internal/InstrumentsTreeItemDelegate.qml b/src/instrumentsscene/qml/MuseScore/InstrumentsScene/internal/InstrumentsTreeItemDelegate.qml index 1001f3a6bb..bf88a77e49 100644 --- a/src/instrumentsscene/qml/MuseScore/InstrumentsScene/internal/InstrumentsTreeItemDelegate.qml +++ b/src/instrumentsscene/qml/MuseScore/InstrumentsScene/internal/InstrumentsTreeItemDelegate.qml @@ -360,7 +360,7 @@ Item { popup = popupLoader.createPopup(instrumentSettingsComp, this) - item["partId"] = model.itemRole.id() + item["partId"] = model.itemRole.id item["partName"] = model.itemRole.title item["instrumentId"] = model.itemRole.instrumentId() item["instrumentName"] = model.itemRole.instrumentName() @@ -370,7 +370,7 @@ Item { popup = popupLoader.createPopup(staffSettingsComp, this) - item["staffId"] = model.itemRole.id() + item["staffId"] = model.itemRole.id item["isSmall"] = model.itemRole.isSmall() item["cutawayEnabled"] = model.itemRole.cutawayEnabled() item["type"] = model.itemRole.staffType() diff --git a/src/instrumentsscene/view/abstractinstrumentspaneltreeitem.cpp b/src/instrumentsscene/view/abstractinstrumentspaneltreeitem.cpp index 5a58595d5d..21d8a2298b 100644 --- a/src/instrumentsscene/view/abstractinstrumentspaneltreeitem.cpp +++ b/src/instrumentsscene/view/abstractinstrumentspaneltreeitem.cpp @@ -53,11 +53,16 @@ void AbstractInstrumentsPanelTreeItem::appendNewItem() { } -QString AbstractInstrumentsPanelTreeItem::id() const +mu::ID AbstractInstrumentsPanelTreeItem::id() const { return m_id; } +QString AbstractInstrumentsPanelTreeItem::idStr() const +{ + return m_id.toQString(); +} + bool AbstractInstrumentsPanelTreeItem::canChangeVisibility() const { return m_canChangeVisibility; @@ -105,7 +110,7 @@ bool AbstractInstrumentsPanelTreeItem::isEmpty() const return m_children.isEmpty(); } -AbstractInstrumentsPanelTreeItem* AbstractInstrumentsPanelTreeItem::childAtId(const QString& id) const +AbstractInstrumentsPanelTreeItem* AbstractInstrumentsPanelTreeItem::childAtId(const ID& id) const { for (AbstractInstrumentsPanelTreeItem* item: m_children) { if (item->id() == id) { @@ -244,7 +249,7 @@ void AbstractInstrumentsPanelTreeItem::setIsVisible(bool isVisible) } } -void AbstractInstrumentsPanelTreeItem::setId(const QString& id) +void AbstractInstrumentsPanelTreeItem::setId(const ID& id) { m_id = id; } diff --git a/src/instrumentsscene/view/abstractinstrumentspaneltreeitem.h b/src/instrumentsscene/view/abstractinstrumentspaneltreeitem.h index 45ff4416d1..a8cb28b36f 100644 --- a/src/instrumentsscene/view/abstractinstrumentspaneltreeitem.h +++ b/src/instrumentsscene/view/abstractinstrumentspaneltreeitem.h @@ -36,6 +36,7 @@ class AbstractInstrumentsPanelTreeItem : public QObject { Q_OBJECT + Q_PROPERTY(QString id READ idStr CONSTANT) Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) Q_PROPERTY(int type READ type NOTIFY typeChanged) Q_PROPERTY(bool canChangeVisibility READ canChangeVisibility NOTIFY canChangeVisibilityChanged) @@ -50,8 +51,8 @@ public: Q_INVOKABLE virtual bool canAcceptDrop(const int type) const; Q_INVOKABLE virtual void appendNewItem(); - Q_INVOKABLE QString id() const; - + ID id() const; + QString idStr() const; QString title() const; int type() const; bool isVisible() const; @@ -66,7 +67,7 @@ public: QList childrenItems() const; bool isEmpty() const; - AbstractInstrumentsPanelTreeItem* childAtId(const QString& id) const; + AbstractInstrumentsPanelTreeItem* childAtId(const ID& id) const; AbstractInstrumentsPanelTreeItem* childAtRow(const int row) const; void appendChild(AbstractInstrumentsPanelTreeItem* child); @@ -84,7 +85,7 @@ public slots: void setType(InstrumentsTreeItemType::ItemType type); void setTitle(QString title); void setIsVisible(bool isVisible); - void setId(const QString& id); + void setId(const ID& id); signals: void typeChanged(InstrumentsTreeItemType::ItemType type); @@ -101,7 +102,7 @@ private: QList m_children; AbstractInstrumentsPanelTreeItem* m_parent = nullptr; - QString m_id; + ID m_id; QString m_title; InstrumentsTreeItemType::ItemType m_type = InstrumentsTreeItemType::ItemType::UNDEFINED; bool m_isVisible = false; diff --git a/src/instrumentsscene/view/instrumentlistmodel.cpp b/src/instrumentsscene/view/instrumentlistmodel.cpp index a351d88c76..fbf2b90034 100644 --- a/src/instrumentsscene/view/instrumentlistmodel.cpp +++ b/src/instrumentsscene/view/instrumentlistmodel.cpp @@ -37,6 +37,17 @@ static const QString CONFIG_KEY("config"); static const QString SOLOIST_KEY("isSoloist"); static const QString IS_EXISTING_PART_KEY("isExistingPart"); +static mu::IDList parseIdList(const QString& str) +{ + mu::IDList result; + + for (const QString& idStr : str.split(',')) { + result.push_back(mu::ID(idStr)); + } + + return result; +} + InstrumentListModel::InstrumentListModel(QObject* parent) : QObject(parent) { @@ -59,7 +70,7 @@ void InstrumentListModel::load(bool canSelectMultipleInstruments, const QString& m_canSelectMultipleInstruments = canSelectMultipleInstruments; setInstrumentsMeta(instrumentsMeta.val); - initSelectedInstruments(selectedPartIds.split(',')); + initSelectedInstruments(parseIdList(selectedPartIds)); if (!currentInstrumentId.isEmpty()) { Instrument instrument = instrumentById(currentInstrumentId); @@ -78,8 +89,8 @@ void InstrumentListModel::initSelectedInstruments(const IDList& selectedPartIds) auto parts = _notationParts->partList(); for (const ID& partId: selectedPartIds) { - auto compareId = [partId](auto p) { - return p->id() == partId; + auto compareId = [partId](const Part* part) { + return ID(part->id()) == partId; }; auto pi = find_if(begin(parts), end(parts), compareId); @@ -91,11 +102,11 @@ void InstrumentListModel::initSelectedInstruments(const IDList& selectedPartIds) SelectedInstrumentInfo info; - info.id = partId; + info.id = partId.toQString(); info.isExistingPart = true; info.name = part->partName(); info.isSoloist = part->soloist(); - info.familyId = part->familyId(); + info.familyCode = part->familyId(); info.config = Instrument(); m_selectedInstruments << info; @@ -304,7 +315,7 @@ void InstrumentListModel::selectInstrument(const QString& instrumentName, const info.isSoloist = false; info.id = suitedInstrument.templateId; info.name = formatInstrumentTitle(suitedInstrument); - info.familyId = suitedInstrument.familyId; + info.familyCode = suitedInstrument.familyId; info.config = suitedInstrument; if (!m_canSelectMultipleInstruments) { @@ -469,8 +480,7 @@ int InstrumentListModel::sortInstrumentsIndex(const SelectedInstrumentInfo& info }; ScoreOrder order = m_scoreOrders[m_selectedScoreOrderIndex].info; - - const QString family = order.instrumentMap.contains(info.id) ? order.instrumentMap[info.id].id : info.familyId; + QString family = order.instrumentMap.contains(info.id) ? order.instrumentMap[info.id].id : info.familyCode; int index = order.groups.size(); Priority priority = Priority::Undefined; diff --git a/src/instrumentsscene/view/instrumentlistmodel.h b/src/instrumentsscene/view/instrumentlistmodel.h index d1f5b45697..95e4d745d8 100644 --- a/src/instrumentsscene/view/instrumentlistmodel.h +++ b/src/instrumentsscene/view/instrumentlistmodel.h @@ -90,7 +90,7 @@ private: { QString id; QString name; - QString familyId; + QString familyCode; bool isSoloist = false; bool isExistingPart = false; notation::Instrument config; @@ -107,7 +107,7 @@ private: bool operator==(const ScoreOrderInfo& orderInfo) const { return id == orderInfo.id; } }; - void initSelectedInstruments(const notation::IDList& selectedPartIds); + void initSelectedInstruments(const IDList& selectedPartIds); notation::INotationPartsPtr notationParts() const; void initScoreOrders(const QString& currentId); diff --git a/src/instrumentsscene/view/instrumentsettingsmodel.cpp b/src/instrumentsscene/view/instrumentsettingsmodel.cpp index 2a7a7f58e5..5be2ae656a 100644 --- a/src/instrumentsscene/view/instrumentsettingsmodel.cpp +++ b/src/instrumentsscene/view/instrumentsettingsmodel.cpp @@ -36,8 +36,8 @@ void InstrumentSettingsModel::load(const QVariant& instrument) { QVariantMap map = instrument.toMap(); - m_instrumentKey.partId = map["partId"].toString(); - m_instrumentKey.instrumentId = map["instrumentId"].toString(); + m_instrumentKey.partId = ID(map["partId"]); + m_instrumentKey.instrumentId = ID(map["instrumentId"]); m_partName = map["partName"].toString(); m_instrumentName = map["instrumentName"].toString(); m_instrumentAbbreviature = map["abbreviature"].toString(); @@ -51,7 +51,7 @@ void InstrumentSettingsModel::replaceInstrument() return; } - RetVal selectedInstrument = selectInstrumentsScenario()->selectInstrument(m_instrumentKey.instrumentId.toStdString()); + RetVal selectedInstrument = selectInstrumentsScenario()->selectInstrument(m_instrumentKey); if (!selectedInstrument.ret) { LOGE() << selectedInstrument.ret.toString(); return; diff --git a/src/instrumentsscene/view/instrumentspaneltreemodel.cpp b/src/instrumentsscene/view/instrumentspaneltreemodel.cpp index 0892225330..002307ed16 100644 --- a/src/instrumentsscene/view/instrumentspaneltreemodel.cpp +++ b/src/instrumentsscene/view/instrumentspaneltreemodel.cpp @@ -131,17 +131,6 @@ void InstrumentsPanelTreeModel::load() emit isAddingAvailableChanged(true); } -IDList InstrumentsPanelTreeModel::currentNotationPartIdList() const -{ - IDList result; - - for (const Part* part : m_notation->parts()->partList()) { - result << part->id(); - } - - return result; -} - void InstrumentsPanelTreeModel::selectRow(const QModelIndex& rowIndex) { m_selectionModel->select(rowIndex); @@ -500,7 +489,7 @@ AbstractInstrumentsPanelTreeItem* InstrumentsPanelTreeModel::loadPart(const Part TRACEFUNC; auto partItem = buildPartItem(part); - QString partId = part->id(); + ID partId = part->id(); async::NotifyList staves = m_masterNotation->parts()->staffList(partId); @@ -574,8 +563,7 @@ AbstractInstrumentsPanelTreeItem* InstrumentsPanelTreeModel::buildPartItem(const void InstrumentsPanelTreeModel::updatePartItem(PartTreeItem* item, const Part* part) { - IDList notationPartIdList = currentNotationPartIdList(); - bool visible = part->show() && notationPartIdList.contains(part->id()); + bool visible = part->show() && m_notation->parts()->partExists(part->id()); item->setId(part->id()); item->setTitle(part->partName().isEmpty() ? part->instrument()->name() : part->partName()); @@ -593,7 +581,7 @@ AbstractInstrumentsPanelTreeItem* InstrumentsPanelTreeModel::buildStaffItem(cons return result; } -AbstractInstrumentsPanelTreeItem* InstrumentsPanelTreeModel::buildAddStaffControlItem(const QString& partId) +AbstractInstrumentsPanelTreeItem* InstrumentsPanelTreeModel::buildAddStaffControlItem(const ID& partId) { auto result = new StaffControlTreeItem(m_masterNotation, m_notation, this); result->setTitle(qtrc("instruments", "Add staff")); diff --git a/src/instrumentsscene/view/instrumentspaneltreemodel.h b/src/instrumentsscene/view/instrumentspaneltreemodel.h index e5201d4ad4..f82fdf71a0 100644 --- a/src/instrumentsscene/view/instrumentspaneltreemodel.h +++ b/src/instrumentsscene/view/instrumentspaneltreemodel.h @@ -117,8 +117,6 @@ private: bool removeRows(int row, int count, const QModelIndex& parent) override; - notation::IDList currentNotationPartIdList() const; - AbstractInstrumentsPanelTreeItem* loadPart(const notation::Part* part); AbstractInstrumentsPanelTreeItem* modelIndexToItem(const QModelIndex& index) const; @@ -128,7 +126,7 @@ private: AbstractInstrumentsPanelTreeItem* buildPartItem(const mu::notation::Part* part); AbstractInstrumentsPanelTreeItem* buildStaffItem(const mu::notation::Staff* staff); - AbstractInstrumentsPanelTreeItem* buildAddStaffControlItem(const QString& partId); + AbstractInstrumentsPanelTreeItem* buildAddStaffControlItem(const ID& partId); AbstractInstrumentsPanelTreeItem* m_rootItem = nullptr; uicomponents::ItemMultiSelectionModel* m_selectionModel = nullptr; diff --git a/src/instrumentsscene/view/parttreeitem.cpp b/src/instrumentsscene/view/parttreeitem.cpp index a241bb98b5..ae001dc068 100644 --- a/src/instrumentsscene/view/parttreeitem.cpp +++ b/src/instrumentsscene/view/parttreeitem.cpp @@ -93,7 +93,7 @@ void PartTreeItem::moveChildren(const int sourceRow, const int count, AbstractIn IDList stavesIds; for (int i = sourceRow; i < sourceRow + count; ++i) { - stavesIds << childAtRow(i)->id(); + stavesIds.push_back(childAtRow(i)->id()); } int destinationRowLast = destinationRow; @@ -115,7 +115,7 @@ void PartTreeItem::removeChildren(const int row, const int count, const bool del IDList stavesIds; for (int i = row; i < row + count; ++i) { - stavesIds << childAtRow(i)->id(); + stavesIds.push_back(childAtRow(i)->id()); } if (deleteChild) { diff --git a/src/instrumentsscene/view/parttreeitem.h b/src/instrumentsscene/view/parttreeitem.h index 96e8aa21d3..4e9848d025 100644 --- a/src/instrumentsscene/view/parttreeitem.h +++ b/src/instrumentsscene/view/parttreeitem.h @@ -48,7 +48,7 @@ public: private: void listenVisibilityChanged(); - void createAndAppendPart(const notation::ID& masterPartId); + void createAndAppendPart(const ID& masterPartId); QString m_instrumentId; QString m_instrumentName; diff --git a/src/instrumentsscene/view/roottreeitem.cpp b/src/instrumentsscene/view/roottreeitem.cpp index a12f9a5b2e..230022aec2 100644 --- a/src/instrumentsscene/view/roottreeitem.cpp +++ b/src/instrumentsscene/view/roottreeitem.cpp @@ -35,7 +35,7 @@ void RootTreeItem::moveChildren(const int sourceRow, const int count, AbstractIn IDList partIds; for (int i = sourceRow; i < sourceRow + count; ++i) { - partIds << childAtRow(i)->id(); + partIds.push_back(childAtRow(i)->id()); } int destinationRow_ = destinationRow; @@ -61,7 +61,7 @@ void RootTreeItem::removeChildren(const int row, const int count, const bool del IDList partIds; for (int i = row; i < row + count; ++i) { - partIds << childAtRow(i)->id(); + partIds.push_back(childAtRow(i)->id()); } if (deleteChild) { diff --git a/src/instrumentsscene/view/staffcontroltreeitem.cpp b/src/instrumentsscene/view/staffcontroltreeitem.cpp index 6ab0d34e97..c2bd07674f 100644 --- a/src/instrumentsscene/view/staffcontroltreeitem.cpp +++ b/src/instrumentsscene/view/staffcontroltreeitem.cpp @@ -44,7 +44,7 @@ void StaffControlTreeItem::appendNewItem() masterNotation()->parts()->appendStaff(staff, m_partId); } -void StaffControlTreeItem::setPartId(const QString& id) +void StaffControlTreeItem::setPartId(const ID& id) { m_partId = id; } diff --git a/src/instrumentsscene/view/staffcontroltreeitem.h b/src/instrumentsscene/view/staffcontroltreeitem.h index 2780a7453d..7998db4e18 100644 --- a/src/instrumentsscene/view/staffcontroltreeitem.h +++ b/src/instrumentsscene/view/staffcontroltreeitem.h @@ -36,10 +36,10 @@ public: Q_INVOKABLE void appendNewItem() override; - void setPartId(const QString& id); + void setPartId(const ID& id); private: - QString m_partId; + ID m_partId; }; } diff --git a/src/instrumentsscene/view/staffsettingsmodel.h b/src/instrumentsscene/view/staffsettingsmodel.h index e3da490a07..35db28c6ce 100644 --- a/src/instrumentsscene/view/staffsettingsmodel.h +++ b/src/instrumentsscene/view/staffsettingsmodel.h @@ -68,7 +68,7 @@ private: notation::INotationPartsPtr notationParts() const; notation::INotationPartsPtr masterNotationParts() const; - notation::ID m_staffId; + ID m_staffId; bool m_isSmallStaff = false; bool m_cutawayEnabled = false; QList m_voicesVisibility; diff --git a/src/notation/internal/notationparts.cpp b/src/notation/internal/notationparts.cpp index dc28f24d30..f6d8337666 100644 --- a/src/notation/internal/notationparts.cpp +++ b/src/notation/internal/notationparts.cpp @@ -125,18 +125,12 @@ bool NotationParts::partExists(const ID& partId) const Part* NotationParts::partModifiable(const ID& partId) const { - for (Part* part: score()->parts()) { - if (part->id() == partId) { - return part; - } - } - - return nullptr; + return score()->part(partId.toUint64()); } Staff* NotationParts::staffModifiable(const ID& staffId) const { - return score()->staff(staffId); + return score()->staff(staffId.toUint64()); } std::vector NotationParts::staves(const IDList& stavesIds) const @@ -210,7 +204,7 @@ void NotationParts::setPartName(const ID& partId, const QString& name) startEdit(); - doSetPartName(part, name); + score()->undo(new Ms::ChangePart(part, new Ms::Instrument(*part->instrument()), name)); apply(); @@ -260,26 +254,26 @@ void NotationParts::updatePartTitles() } } -ID NotationParts::newPartId() const +Ms::ID NotationParts::newPartId() const { - ID maxId = ID(); + Ms::ID maxId = 0; for (const Part* part : score()->parts()) { maxId = std::max(maxId, part->id()); } - return maxId + QString::number(1); + return maxId + 1; } -ID NotationParts::newStaffId() const +Ms::ID NotationParts::newStaffId() const { - ID maxId = ID(); + Ms::ID maxId = 0; for (const Staff* staff : score()->staves()) { maxId = std::max(maxId, staff->id()); } - return maxId + QString::number(1); + return maxId + 1; } void NotationParts::doMoveStaves(const std::vector& staves, int destinationStaffIndex, Part* destinationPart) @@ -578,7 +572,7 @@ void NotationParts::appendPart(Part* part) return; } - if (part->id().isNull()) { + if (!ID(part->id()).isValid()) { part->setId(newPartId()); } @@ -754,21 +748,14 @@ void NotationParts::removeStaves(const IDList& stavesIds) apply(); } -void NotationParts::doSetPartName(Part* part, const QString& name) -{ - TRACEFUNC; - - score()->undo(new Ms::ChangePart(part, new Ms::Instrument(*part->instrument()), name)); -} - void NotationParts::moveParts(const IDList& sourcePartsIds, const ID& destinationPartId, InsertMode mode) { TRACEFUNC; - IDList partIds; + QList partIds; for (Ms::Part* currentPart: score()->parts()) { - partIds << currentPart->id(); + partIds.push_back(currentPart->id()); } for (const ID& sourcePartId: sourcePartsIds) { @@ -779,7 +766,7 @@ void NotationParts::moveParts(const IDList& sourcePartsIds, const ID& destinatio } PartInstrumentList parts; - for (ID& partId: partIds) { + for (const ID& partId: partIds) { PartInstrument pi; pi.isExistingPart = true; pi.partId = partId; @@ -903,15 +890,15 @@ void NotationParts::removeMissingParts(const PartInstrumentList& parts) IDList partIds; for (const PartInstrument& pi: parts) { if (pi.isExistingPart) { - partIds << pi.partId; + partIds.push_back(pi.partId); } } for (const Part* part: partList()) { - if (partIds.contains(part->id())) { + if (containsId(partIds, part->id())) { continue; } - partsToRemove << part->id(); + partsToRemove.push_back(part->id()); } doRemoveParts(partsToRemove); diff --git a/src/notation/internal/notationparts.h b/src/notation/internal/notationparts.h index 27042f643b..26db0133e4 100644 --- a/src/notation/internal/notationparts.h +++ b/src/notation/internal/notationparts.h @@ -83,14 +83,13 @@ protected: private: void updatePartTitles(); - ID newPartId() const; - ID newStaffId() const; + Ms::ID newPartId() const; + Ms::ID newStaffId() const; void doMoveStaves(const std::vector& staves, int destinationStaffIndex, Part* destinationPart = nullptr); void doSetStaffVisible(Staff* staff, bool visible); void doSetStaffVoiceVisible(Staff* staff, int voiceIndex, bool visible); void doRemoveParts(const IDList& partsIds); - void doSetPartName(Part* part, const QString& name); Part* partModifiable(const ID& partId) const; Staff* staffModifiable(const ID& staffId) const; diff --git a/src/notation/internal/notationplayback.cpp b/src/notation/internal/notationplayback.cpp index 2707fbd258..3a6cc5c975 100644 --- a/src/notation/internal/notationplayback.cpp +++ b/src/notation/internal/notationplayback.cpp @@ -178,17 +178,17 @@ void NotationPlayback::load() m_instrumentsMidiData.clear(); for (const Part* part : m_notationParts->partList()) { - m_instrumentsMidiData.insert({ part->id().toStdString(), buildMidiData(part) }); + m_instrumentsMidiData.insert({ std::to_string(part->id()), buildMidiData(part) }); } m_notationParts->partList().onItemAdded(this, [this](const Part* part) { - InstrumentTrackId id = part->id().toStdString(); + InstrumentTrackId id = std::to_string(part->id()); m_instrumentsMidiData.insert({ id, buildMidiData(part) }); m_instrumentTrackAdded.send(std::move(id)); }); m_notationParts->partList().onItemRemoved(this, [this](const Part* part) { - InstrumentTrackId id = part->id().toStdString(); + InstrumentTrackId id = std::to_string(part->id()); m_instrumentsMidiData.erase(id); m_instrumentTrackRemoved.send(std::move(id)); }); @@ -462,7 +462,7 @@ Ret NotationPlayback::playNoteMidiData(const Ms::Note* note) const const Ms::Instrument* instr = masterNote->part()->instrument(tick); channel_t midiChannel = instr->channel(masterNote->subchannel())->channel(); - MidiData midiData = instrumentMidiData(masterNote->part()->id().toStdString()); + MidiData midiData = instrumentMidiData(std::to_string(masterNote->part()->id())); Events events = m_midiEventsProvider->retrieveEventsForElement(masterNote, midiChannel); midiData.stream.backgroundStream.send(std::move(events), Ms::MScore::defaultPlayDuration* 2); @@ -477,7 +477,7 @@ Ret NotationPlayback::playChordMidiData(const Ms::Chord* chord) const Ms::Instrument* instr = part->instrument(tick); channel_t midiChannel = instr->channel(chord->notes()[0]->subchannel())->channel(); - MidiData midiData = instrumentMidiData(part->id().toStdString()); + MidiData midiData = instrumentMidiData(std::to_string(part->id())); Events events = m_midiEventsProvider->retrieveEventsForElement(chord, midiChannel); midiData.stream.backgroundStream.send(std::move(events), Ms::MScore::defaultPlayDuration* 2); @@ -502,7 +502,7 @@ Ret NotationPlayback::playHarmonyMidiData(const Ms::Harmony* harmony) const } channel_t midiChannel = hChannel->channel(); - MidiData midiData = instrumentMidiData(harmony->part()->id().toStdString()); + MidiData midiData = instrumentMidiData(std::to_string(harmony->part()->id())); Events events = m_midiEventsProvider->retrieveEventsForElement(harmony, midiChannel); midiData.stream.backgroundStream.send(std::move(events), Ms::MScore::defaultPlayDuration* 2); diff --git a/src/notation/internal/notationplayback.h b/src/notation/internal/notationplayback.h index 0e17361051..5fd0fdc0f7 100644 --- a/src/notation/internal/notationplayback.h +++ b/src/notation/internal/notationplayback.h @@ -105,7 +105,7 @@ private: async::Channel m_playPositionTickChanged; ValCh m_loopBoundaries; - std::unordered_map m_instrumentsMidiData; + std::unordered_map m_instrumentsMidiData; async::Channel m_instrumentTrackRemoved; async::Channel m_instrumentTrackAdded; }; diff --git a/src/notation/iselectinstrumentscenario.h b/src/notation/iselectinstrumentscenario.h index 0526675e25..aaf57920a0 100644 --- a/src/notation/iselectinstrumentscenario.h +++ b/src/notation/iselectinstrumentscenario.h @@ -39,9 +39,9 @@ public: ShowCurrentInstruments }; - virtual RetVal selectInstruments(SelectInstrumentsMode mode = SelectInstrumentsMode::None) const + virtual RetVal selectInstruments(SelectInstrumentsMode mode = SelectInstrumentsMode::None) const = 0; - virtual RetVal selectInstrument(const std::string& currentInstrumentId = "") const = 0; + virtual RetVal selectInstrument(const InstrumentKey& currentInstrumentKey = InstrumentKey()) const = 0; }; } diff --git a/src/notation/notationtypes.h b/src/notation/notationtypes.h index 25fc61b83e..55d07719b0 100644 --- a/src/notation/notationtypes.h +++ b/src/notation/notationtypes.h @@ -27,6 +27,7 @@ #include "io/path.h" #include "translation.h" +#include "id.h" #include "midi/midievent.h" #include "libmscore/element.h" @@ -121,9 +122,6 @@ using PageList = std::vector; using StaffList = QList; using PartList = QList; -using ID = QString; -using IDList = QList; - enum class DragMode { BothXY = 0, @@ -414,7 +412,7 @@ inline QString formatInstrumentTitle(const Instrument& instrument, int instrumen struct PartInstrument { - QString partId; + ID partId; Instrument instrument; bool isExistingPart = false; diff --git a/src/notation/view/widgets/editstaff.cpp b/src/notation/view/widgets/editstaff.cpp index 8adff12968..35deebcdbe 100644 --- a/src/notation/view/widgets/editstaff.cpp +++ b/src/notation/view/widgets/editstaff.cpp @@ -567,7 +567,7 @@ bool EditStaff::isInstrumentChanged() void EditStaff::showReplaceInstrumentDialog() { - RetVal selectedInstrument = selectInstrumentsScenario()->selectInstrument(m_instrumentKey.instrumentId.toStdString()); + RetVal selectedInstrument = selectInstrumentsScenario()->selectInstrument(m_instrumentKey); if (!selectedInstrument.ret) { LOGE() << selectedInstrument.ret.toString(); return; diff --git a/src/palette/view/widgets/editdrumsetdialog.cpp b/src/palette/view/widgets/editdrumsetdialog.cpp index 9ccfb4f80d..fc4a8e49ae 100644 --- a/src/palette/view/widgets/editdrumsetdialog.cpp +++ b/src/palette/view/widgets/editdrumsetdialog.cpp @@ -147,7 +147,7 @@ EditDrumsetDialog::EditDrumsetDialog(QWidget* parent) NoteInputState state = m_notation->interaction()->noteInput()->state(); const Staff* staff = m_notation->elements()->msScore()->staff(track2staff(state.currentTrack)); m_instrumentKey.instrumentId = staff ? staff->part()->instrumentId() : QString(); - m_instrumentKey.partId = staff ? staff->part()->id() : QString(); + m_instrumentKey.partId = staff ? staff->part()->id() : ID(); m_editedDrumset = state.drumset ? *state.drumset : Drumset(); } From 085511b5867bb8c524f82a23ae581c447f246124 Mon Sep 17 00:00:00 2001 From: Roman Pudashkin Date: Thu, 5 Aug 2021 09:37:21 +0200 Subject: [PATCH 3/3] transferred ID generation to the score layer --- src/engraving/compat/read114.cpp | 8 +- src/engraving/compat/read206.cpp | 8 +- src/engraving/libmscore/cmd.cpp | 4 +- src/engraving/libmscore/excerpt.cpp | 7 +- src/engraving/libmscore/mcursor.cpp | 3 +- src/engraving/libmscore/part.cpp | 41 ++++--- src/engraving/libmscore/part.h | 8 +- src/engraving/libmscore/score.cpp | 102 +++++++++++++----- src/engraving/libmscore/score.h | 15 ++- src/engraving/libmscore/staff.cpp | 8 +- src/engraving/libmscore/staff.h | 8 ++ src/importexport/bb/internal/bb.cpp | 6 +- .../bww/internal/bww/importbww.cpp | 6 +- src/importexport/capella/internal/capella.cpp | 6 +- .../guitarpro/internal/importgtp-gp4.cpp | 7 +- .../guitarpro/internal/importgtp-gp5.cpp | 7 +- .../guitarpro/internal/importgtp-gp6.cpp | 12 +-- .../guitarpro/internal/importgtp-gp7.cpp | 12 +-- .../guitarpro/internal/importgtp.cpp | 27 ++--- .../guitarpro/internal/importptb.cpp | 11 +- .../musedata/internal/musedata.cpp | 7 +- .../internal/musicxml/importmxmlpass1.cpp | 7 +- src/importexport/ove/internal/importove.cpp | 7 +- src/notation/internal/masternotation.cpp | 6 +- src/notation/internal/notationparts.cpp | 83 +++++--------- src/notation/internal/notationparts.h | 15 ++- 26 files changed, 213 insertions(+), 218 deletions(-) diff --git a/src/engraving/compat/read114.cpp b/src/engraving/compat/read114.cpp index ec09121d0c..9171dec859 100644 --- a/src/engraving/compat/read114.cpp +++ b/src/engraving/compat/read114.cpp @@ -2572,11 +2572,9 @@ static void readPart(Part* part, XmlReader& e) while (e.readNextStartElement()) { const QStringRef& tag(e.name()); if (tag == "Staff") { - Staff* staff = new Staff(_score); - staff->setPart(part); + Staff* staff = createStaff(_score, part); staff->setStaffType(Fraction(0, 1), StaffType()); // will reset later if needed - _score->staves().push_back(staff); - part->staves()->push_back(staff); + _score->appendStaff(staff); readStaff(staff, e); } else if (tag == "Instrument") { Instrument* i = part->instrument(); @@ -2917,7 +2915,7 @@ Score::FileError Read114::read114(MasterScore* masterScore, XmlReader& e) } else if (tag == "Part") { Part* part = new Part(masterScore); readPart(part, e); - masterScore->parts().push_back(part); + masterScore->appendPart(part); } else if (tag == "Slur") { Slur* slur = new Slur(masterScore); Read206::readSlur206(e, slur); diff --git a/src/engraving/compat/read206.cpp b/src/engraving/compat/read206.cpp index 7bd1321398..a1a6626472 100644 --- a/src/engraving/compat/read206.cpp +++ b/src/engraving/compat/read206.cpp @@ -780,10 +780,8 @@ void Read206::readPart206(Part* part, XmlReader& e) } } } else if (tag == "Staff") { - Staff* staff = new Staff(part->score()); - staff->setPart(part); - part->score()->staves().push_back(staff); - part->staves()->push_back(staff); + Staff* staff = createStaff(part->score(), part); + part->score()->appendStaff(staff); readStaff(staff, e); } else if (part->readProperties(e)) { } else { @@ -3406,7 +3404,7 @@ bool Read206::readScore206(Score* score, XmlReader& e) } else if (tag == "Part") { Part* part = new Part(score); Read206::readPart206(part, e); - score->parts().push_back(part); + score->appendPart(part); } else if ((tag == "HairPin") // TODO: do this elements exist here? || (tag == "Ottava") || (tag == "TextLine") diff --git a/src/engraving/libmscore/cmd.cpp b/src/engraving/libmscore/cmd.cpp index 66ad02ebd9..9b7f14aad1 100644 --- a/src/engraving/libmscore/cmd.cpp +++ b/src/engraving/libmscore/cmd.cpp @@ -2069,7 +2069,7 @@ void Score::moveUp(ChordRest* cr) return; } - QList* staves = part->staves(); + const QList* staves = part->staves(); // we know that staffMove+rstaff-1 index exists due to the previous condition. if (staff->staffType(cr->tick())->group() != StaffGroup::STANDARD || staves->at(rstaff + staffMove - 1)->staffType(cr->tick())->group() != StaffGroup::STANDARD) { @@ -2098,7 +2098,7 @@ void Score::moveDown(ChordRest* cr) return; } - QList* staves = part->staves(); + const QList* staves = part->staves(); // we know that staffMove+rstaff+1 index exists due to the previous condition. if (staff->staffType(cr->tick())->group() != StaffGroup::STANDARD || staves->at(staffMove + rstaff + 1)->staffType(cr->tick())->group() != StaffGroup::STANDARD) { diff --git a/src/engraving/libmscore/excerpt.cpp b/src/engraving/libmscore/excerpt.cpp index 6e90e35d48..2eef061336 100644 --- a/src/engraving/libmscore/excerpt.cpp +++ b/src/engraving/libmscore/excerpt.cpp @@ -233,18 +233,15 @@ void Excerpt::createExcerpt(Excerpt* excerpt) p->setPartName(part->partName()); for (Staff* staff : *part->staves()) { - Staff* s = new Staff(score); + Staff* s = createStaff(score, p); s->setId(staff->id()); - s->setPart(p); -// s->setStaffType(0, *staff->staffType(0)); // TODO s->init(staff); s->setDefaultClefType(staff->defaultClefType()); // the order of staff - s matters as staff should be the first entry in the // created link list to make primaryStaff() work // TODO: change implementation, maybe create an explicit "primary" flag score->undo(new Link(s, staff)); - p->staves()->append(s); - score->staves().append(s); + score->appendStaff(s); srcStaves.append(staff->idx()); } score->appendPart(p); diff --git a/src/engraving/libmscore/mcursor.cpp b/src/engraving/libmscore/mcursor.cpp index 17aefc063f..1cde0443fb 100644 --- a/src/engraving/libmscore/mcursor.cpp +++ b/src/engraving/libmscore/mcursor.cpp @@ -168,8 +168,7 @@ void MCursor::move(int t, const Fraction& tick) void MCursor::addPart(const QString& instrument) { Part* part = new Part(_score); - Staff* staff = new Staff(_score); - staff->setPart(part); + Staff* staff = createStaff(_score, part); InstrumentTemplate* it = searchTemplate(instrument); if (it == 0) { qFatal("Did not find instrument <%s>", qPrintable(instrument)); diff --git a/src/engraving/libmscore/part.cpp b/src/engraving/libmscore/part.cpp index 6f4799db68..1a2b331ec5 100644 --- a/src/engraving/libmscore/part.cpp +++ b/src/engraving/libmscore/part.cpp @@ -149,10 +149,8 @@ bool Part::readProperties(XmlReader& e) { const QStringRef& tag(e.name()); if (tag == "Staff") { - Staff* staff = new Staff(score()); - staff->setPart(this); - score()->staves().push_back(staff); - _staves.push_back(staff); + Staff* staff = createStaff(score(), this); + score()->appendStaff(staff); staff->read(e); } else if (tag == "Instrument") { Instrument* instr = new Instrument; @@ -185,10 +183,6 @@ bool Part::readProperties(XmlReader& e) void Part::read(XmlReader& e) { - if (e.hasAttribute("id")) { - _id = e.attribute("id").toULongLong(); - } - while (e.readNextStartElement()) { if (!readProperties(e)) { e.unknown(); @@ -205,9 +199,7 @@ void Part::read(XmlReader& e) void Part::write(XmlWriter& xml) const { - if (_id != INVALID_ID) { - xml.stag(this, QString("id=\"%1\"").arg(_id)); - } + xml.stag(this); for (const Staff* staff : _staves) { staff->write(xml); @@ -231,6 +223,26 @@ void Part::write(XmlWriter& xml) const xml.etag(); } +int Part::nstaves() const +{ + return _staves.size(); +} + +const QList* Part::staves() const +{ + return &_staves; +} + +void Part::appendStaff(Staff* staff) +{ + _staves.push_back(staff); +} + +void Part::clearStaves() +{ + _staves.clear(); +} + //--------------------------------------------------------- // setLongNames //--------------------------------------------------------- @@ -256,12 +268,13 @@ void Part::setStaves(int n) qDebug("Part::setStaves(): remove staves not implemented!"); return; } + int staffIdx = score()->staffIdx(this) + ns; for (int i = ns; i < n; ++i) { - Staff* staff = new Staff(score()); - staff->setPart(this); + Staff* staff = createStaff(score(), this); _staves.push_back(staff); - score()->staves().insert(staffIdx, staff); + const_cast&>(score()->staves()).insert(staffIdx, staff); + for (Measure* m = score()->firstMeasure(); m; m = m->nextMeasure()) { m->insertStaff(staff, staffIdx); if (m->hasMMRest()) { diff --git a/src/engraving/libmscore/part.h b/src/engraving/libmscore/part.h index ab1dcc1ce3..12d0e8e7f3 100644 --- a/src/engraving/libmscore/part.h +++ b/src/engraving/libmscore/part.h @@ -96,9 +96,11 @@ public: bool readProperties(XmlReader&); void write(XmlWriter& xml) const; - int nstaves() const { return _staves.size(); } - QList* staves() { return &_staves; } - const QList* staves() const { return &_staves; } + int nstaves() const; + const QList* staves() const; + void appendStaff(Staff* staff); + void clearStaves(); + Staff* staff(int idx) const; QString familyId() const; diff --git a/src/engraving/libmscore/score.cpp b/src/engraving/libmscore/score.cpp index 4aae95e978..d84121f029 100644 --- a/src/engraving/libmscore/score.cpp +++ b/src/engraving/libmscore/score.cpp @@ -1030,15 +1030,6 @@ void Score::spell(Note* note) note->setTpc(Ms::tpc(3, note->pitch(), opt)); } -//--------------------------------------------------------- -// appendPart -//--------------------------------------------------------- - -void Score::appendPart(Part* p) -{ - _parts.append(p); -} - //--------------------------------------------------------- // searchPage // p is in canvas coordinates @@ -2460,8 +2451,15 @@ void Score::cmdRemovePart(Part* part) void Score::insertPart(Part* part, int idx) { + if (!part) { + return; + } + bool inserted = false; int staff = 0; + + assignIdIfNeed(*part); + for (QList::iterator i = _parts.begin(); i != _parts.end(); ++i) { if (staff >= idx) { _parts.insert(i, part); @@ -2477,6 +2475,16 @@ void Score::insertPart(Part* part, int idx) setInstrumentsChanged(true); } +void Score::appendPart(Part* part) +{ + if (!part) { + return; + } + + assignIdIfNeed(*part); + _parts.push_back(part); +} + //--------------------------------------------------------- // removePart //--------------------------------------------------------- @@ -2517,6 +2525,11 @@ void Score::removePart(Part* part) void Score::insertStaff(Staff* staff, int ridx) { + if (!staff || !staff->part()) { + return; + } + + assignIdIfNeed(*staff); staff->part()->insertStaff(staff, ridx); int idx = staffIdx(staff->part()) + ridx; @@ -2542,21 +2555,53 @@ void Score::insertStaff(Staff* staff, int ridx) } } } -#if 0 - for (Spanner* s : staff->score()->unmanagedSpanners()) { - if (s->systemFlag()) { - continue; - } - if (s->staffIdx() >= idx) { - int t = s->track() + VOICES; - s->setTrack(t < ntracks() ? t : ntracks() - 1); - if (s->track2() != -1) { - t = s->track2() + VOICES; - s->setTrack2(t < ntracks() ? t : s->track()); - } - } +} + +void Score::appendStaff(Staff* staff) +{ + if (!staff || !staff->part()) { + return; } -#endif + + assignIdIfNeed(*staff); + staff->part()->appendStaff(staff); + _staves.push_back(staff); +} + +void Score::assignIdIfNeed(Staff& staff) const +{ + if (staff.id() == INVALID_ID) { + staff.setId(newStaffId()); + } +} + +void Score::assignIdIfNeed(Part& part) const +{ + if (part.id() == INVALID_ID) { + part.setId(newPartId()); + } +} + +ID Score::newStaffId() const +{ + ID maxId = 0; + + for (const Staff* staff : score()->staves()) { + maxId = std::max(maxId, staff->id()); + } + + return maxId + 1; +} + +ID Score::newPartId() const +{ + ID maxId = 0; + + for (const Part* part : score()->parts()) { + maxId = std::max(maxId, part->id()); + } + + return maxId + 1; } //--------------------------------------------------------- @@ -2785,10 +2830,10 @@ void Score::sortStaves(QList& dst) Staff* staff = _staves[idx]; if (staff->part() != curPart) { curPart = staff->part(); - curPart->staves()->clear(); + curPart->clearStaves(); _parts.push_back(curPart); } - curPart->staves()->push_back(staff); + curPart->appendStaff(staff); dl.push_back(staff); for (int itrack = 0; itrack < VOICES; ++itrack) { trackMap.insert(idx * VOICES + itrack, track++); @@ -4050,8 +4095,7 @@ void Score::appendPart(const InstrumentTemplate* t) part->initFromInstrTemplate(t); int n = nstaves(); for (int i = 0; i < t->nstaves(); ++i) { - Staff* staff = new Staff(this); - staff->setPart(part); + Staff* staff = createStaff(this, part); StaffType* stt = staff->staffType(Fraction(0, 1)); stt->setLines(t->staffLines[i]); stt->setSmall(t->smallStaff[i]); @@ -5162,7 +5206,7 @@ int Score::staffIdx(const Part* part) const return idx; } -Staff* Score::staff(const ID& staffId) const +Staff* Score::staffById(const ID& staffId) const { for (Staff* staff : _staves) { if (staff->id() == staffId) { @@ -5173,7 +5217,7 @@ Staff* Score::staff(const ID& staffId) const return nullptr; } -Part* Score::part(const ID& partId) const +Part* Score::partById(const ID& partId) const { for (Part* part : _parts) { if (part->id() == partId) { diff --git a/src/engraving/libmscore/score.h b/src/engraving/libmscore/score.h index 9acb9f9084..27a2ef3adb 100644 --- a/src/engraving/libmscore/score.h +++ b/src/engraving/libmscore/score.h @@ -571,6 +571,12 @@ private: void update(bool resetCmdState); + ID newStaffId() const; + ID newPartId() const; + + void assignIdIfNeed(Staff& staff) const; + void assignIdIfNeed(Part& part) const; + protected: int _fileDivision; ///< division of current loading *.msc file LayoutMode _layoutMode { LayoutMode::PAGE }; @@ -623,8 +629,10 @@ public: void rebuildBspTree(); bool noStaves() const { return _staves.empty(); } void insertPart(Part*, int); + void appendPart(Part*); void removePart(Part*); void insertStaff(Staff*, int); + void appendStaff(Staff*); void cmdRemoveStaff(int staffIdx); void removeStaff(Staff*); void addMeasure(MeasureBase*, MeasureBase*); @@ -688,15 +696,14 @@ public: bool read400(XmlReader& e); bool readScore400(XmlReader& e); - QList& staves() { return _staves; } const QList& staves() const { return _staves; } int nstaves() const { return _staves.size(); } int ntracks() const { return _staves.size() * VOICES; } int staffIdx(const Part*) const; Staff* staff(int n) const { return ((n >= 0) && (n < _staves.size())) ? _staves.at(n) : nullptr; } - Staff* staff(const ID& staffId) const; - Part* part(const ID& partId) const; + Staff* staffById(const ID& staffId) const; + Part* partById(const ID& partId) const; Measure* pos2measure(const mu::PointF&, int* staffIdx, int* pitch, Segment**, mu::PointF* offset) const; void dragPosition(const mu::PointF&, int* staffIdx, Segment**, qreal spacingFactor = 0.5) const; @@ -835,10 +842,8 @@ public: void changeSelectedNotesVoice(int); - QList& parts() { return _parts; } const QList& parts() const { return _parts; } - void appendPart(Part* p); void appendPart(const InstrumentTemplate*); void updateStaffIndex(); void sortStaves(QList& dst); diff --git a/src/engraving/libmscore/staff.cpp b/src/engraving/libmscore/staff.cpp index 64505c3d6e..a2adc56e72 100644 --- a/src/engraving/libmscore/staff.cpp +++ b/src/engraving/libmscore/staff.cpp @@ -710,9 +710,7 @@ Fraction Staff::currentKeyTick(const Fraction& tick) const void Staff::write(XmlWriter& xml) const { - if (_id != INVALID_ID) { - xml.stag(this, QString("id=\"%1\"").arg(_id)); - } + xml.stag(this, QString("id=\"%1\"").arg(idx() + 1)); if (links()) { Score* s = masterScore(); @@ -792,10 +790,6 @@ void Staff::write(XmlWriter& xml) const void Staff::read(XmlReader& e) { - if (e.hasAttribute("id")) { - _id = e.attribute("id").toULongLong(); - } - while (e.readNextStartElement()) { if (!readProperties(e)) { e.unknown(); diff --git a/src/engraving/libmscore/staff.h b/src/engraving/libmscore/staff.h index b6f5028bed..cd5ced8f7b 100644 --- a/src/engraving/libmscore/staff.h +++ b/src/engraving/libmscore/staff.h @@ -314,5 +314,13 @@ public: void triggerLayout() const override; void triggerLayout(const Fraction& tick); }; + +inline Staff* createStaff(Score* score, Part* part) +{ + Staff* staff = new Staff(score); + staff->setPart(part); + + return staff; +} } // namespace Ms #endif diff --git a/src/importexport/bb/internal/bb.cpp b/src/importexport/bb/internal/bb.cpp index 77ede7b915..9d75608fc3 100644 --- a/src/importexport/bb/internal/bb.cpp +++ b/src/importexport/bb/internal/bb.cpp @@ -414,10 +414,8 @@ Score::FileError importBB(MasterScore* score, const QString& name) } for (int i = 0; i < ntracks; ++i) { Part* part = new Part(score); - Staff* s = new Staff(score); - s->setPart(part); - part->insertStaff(s, 0); - score->staves().append(s); + Staff* s = createStaff(score, part); + score->appendStaff(s); score->appendPart(part); } diff --git a/src/importexport/bww/internal/bww/importbww.cpp b/src/importexport/bww/internal/bww/importbww.cpp index 16b57300f6..104d01411d 100644 --- a/src/importexport/bww/internal/bww/importbww.cpp +++ b/src/importexport/bww/internal/bww/importbww.cpp @@ -551,10 +551,8 @@ Score::FileError importBww(MasterScore* score, const QString& path) Part* part = new Part(score); score->appendPart(part); - Staff* staff = new Staff(score); - staff->setPart(part); - part->staves()->push_back(staff); - score->staves().push_back(staff); + Staff* staff = createStaff(score, part); + score->appendStaff(staff); Bww::Lexer lex(&fp); Bww::MsScWriter wrt; diff --git a/src/importexport/capella/internal/capella.cpp b/src/importexport/capella/internal/capella.cpp index 199b64c7bf..60767d67cf 100644 --- a/src/importexport/capella/internal/capella.cpp +++ b/src/importexport/capella/internal/capella.cpp @@ -1287,10 +1287,9 @@ void convertCapella(Score* score, Capella* cap, bool capxMode) } midiPatch = cl->sound; - Staff* s = new Staff(score); + Staff* s = createStaff(score, part); s->initFromStaffType(0); - s->setPart(part); if (cl->bPercussion) { part->setMidiProgram(0, 128); } else { @@ -1314,14 +1313,13 @@ void convertCapella(Score* score, Capella* cap, bool capxMode) } s->staffType(Fraction(0, 1))->setSmall(cl->bSmall); - part->insertStaff(s, -1); Interval interval; // guess diatonic transposition from chromatic transposition for the instrument int values[23] = { -6, -6, -5, -5, -4, -3, -3, -2, -2, -1, -1, 0, 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 6 }; interval.diatonic = values[(cl->transp % 12) + 11] + (cl->transp / 12) * 7; interval.chromatic = cl->transp; s->part()->instrument()->setTranspose(interval); - score->staves().push_back(s); + score->appendStaff(s); } if (bstaff) { bstaff->setBarLineSpan(span != 0); diff --git a/src/importexport/guitarpro/internal/importgtp-gp4.cpp b/src/importexport/guitarpro/internal/importgtp-gp4.cpp index cbdba7742a..c8de579740 100644 --- a/src/importexport/guitarpro/internal/importgtp-gp4.cpp +++ b/src/importexport/guitarpro/internal/importgtp-gp4.cpp @@ -708,10 +708,9 @@ bool GuitarPro4::read(QFile* fp) // for (int staffIdx = 0; staffIdx < staves; ++staffIdx) { Part* part = new Part(score); - Staff* s = new Staff(score); - s->setPart(part); - part->insertStaff(s, 0); - score->staves().push_back(s); + Staff* s = createStaff(score, part); + + score->appendStaff(s); score->appendPart(part); } diff --git a/src/importexport/guitarpro/internal/importgtp-gp5.cpp b/src/importexport/guitarpro/internal/importgtp-gp5.cpp index beeb0bef02..f181e6c7c9 100644 --- a/src/importexport/guitarpro/internal/importgtp-gp5.cpp +++ b/src/importexport/guitarpro/internal/importgtp-gp5.cpp @@ -919,10 +919,9 @@ bool GuitarPro5::read(QFile* fp) // for (int staffIdx = 0; staffIdx < staves; ++staffIdx) { Part* part = new Part(score); - Staff* s = new Staff(score); - s->setPart(part); - part->insertStaff(s, -1); - score->staves().push_back(s); + Staff* s = createStaff(score, part); + + score->appendStaff(s); score->appendPart(part); } diff --git a/src/importexport/guitarpro/internal/importgtp-gp6.cpp b/src/importexport/guitarpro/internal/importgtp-gp6.cpp index 05aad7fdf9..f3d1eca972 100644 --- a/src/importexport/guitarpro/internal/importgtp-gp6.cpp +++ b/src/importexport/guitarpro/internal/importgtp-gp6.cpp @@ -484,10 +484,8 @@ void GuitarPro6::readTracks(QDomNode* track) QDomNode currentNode = nextTrack.firstChild(); Part* part = new Part(score); bool hasTuning = false; - Staff* s = new Staff(score); - s->setPart(part); - part->insertStaff(s, -1); - score->staves().push_back(s); + Staff* s = createStaff(score, part); + score->appendStaff(s); while (!currentNode.isNull()) { QString nodeName = currentNode.nodeName(); if (nodeName == "Name") { @@ -528,10 +526,8 @@ void GuitarPro6::readTracks(QDomNode* track) qDebug() << "Unknown instrument: " << ref; } if (ref.endsWith("-gs") || ref.startsWith("2")) { // grand staff - Staff* s2 = new Staff(score); - s2->setPart(part); - part->insertStaff(s2, -1); - score->staves().push_back(s2); + Staff* s2 = createStaff(score, part); + score->appendStaff(s2); s->addBracket(new BracketItem(s->score(), BracketType::BRACE, 2)); s->setBarLineSpan(2); } diff --git a/src/importexport/guitarpro/internal/importgtp-gp7.cpp b/src/importexport/guitarpro/internal/importgtp-gp7.cpp index ed65dd36ea..13e4d2f5d0 100644 --- a/src/importexport/guitarpro/internal/importgtp-gp7.cpp +++ b/src/importexport/guitarpro/internal/importgtp-gp7.cpp @@ -42,10 +42,8 @@ void GuitarPro7::readTracks(QDomNode* track) QDomNode currentNode = nextTrack.firstChild(); Part* part = new Part(score); bool hasTuning = false; - Staff* s = new Staff(score); - s->setPart(part); - part->insertStaff(s, -1); - score->staves().push_back(s); + Staff* s = createStaff(score, part); + score->appendStaff(s); while (!currentNode.isNull()) { QString nodeName = currentNode.nodeName(); if (nodeName == "Name") { @@ -70,10 +68,8 @@ void GuitarPro7::readTracks(QDomNode* track) qDebug() << "Unknown instrument: " << ref; } if (ref.endsWith("-gs") || ref.startsWith("2")) { // grand staff - Staff* s2 = new Staff(score); - s2->setPart(part); - part->insertStaff(s2, -1); - score->staves().push_back(s2); + Staff* s2 = createStaff(score, part); + score->appendStaff(s2); s->addBracket(new BracketItem(s->score(), BracketType::BRACE, 2)); s->setBarLineSpan(2); } diff --git a/src/importexport/guitarpro/internal/importgtp.cpp b/src/importexport/guitarpro/internal/importgtp.cpp index 258179114e..231c22ee99 100644 --- a/src/importexport/guitarpro/internal/importgtp.cpp +++ b/src/importexport/guitarpro/internal/importgtp.cpp @@ -1145,10 +1145,9 @@ bool GuitarPro1::read(QFile* fp) // for (int staffIdx = 0; staffIdx < staves; ++staffIdx) { Part* part = new Part(score); - Staff* s = new Staff(score); - s->setPart(part); - part->insertStaff(s, 0); - score->staves().push_back(s); + Staff* s = createStaff(score, part); + + score->appendStaff(s); score->appendPart(part); } @@ -1583,10 +1582,9 @@ bool GuitarPro2::read(QFile* fp) // for (int staffIdx = 0; staffIdx < staves; ++staffIdx) { Part* part = new Part(score); - Staff* s = new Staff(score); - s->setPart(part); - part->insertStaff(s, 0); - score->staves().push_back(s); + Staff* s = createStaff(score, part); + + score->appendStaff(s); score->appendPart(part); } @@ -2274,10 +2272,9 @@ bool GuitarPro3::read(QFile* fp) // for (int staffIdx = 0; staffIdx < staves; ++staffIdx) { Part* part = new Part(score); - Staff* s = new Staff(score); - s->setPart(part); - part->insertStaff(s, 0); - score->staves().push_back(s); + Staff* s = createStaff(score, part); + + score->appendStaff(s); score->appendPart(part); } @@ -2990,14 +2987,12 @@ Score::FileError importGTP(MasterScore* score, const QString& name) Staff* staff = part->staves()->front(); - Staff* s = new Staff(pscore); - s->setPart(p); + Staff* s = createStaff(score, part); const StaffType* st = staff->constStaffType(Fraction(0, 1)); s->setStaffType(Fraction(0, 1), *st); s->linkTo(staff); - p->staves()->append(s); - pscore->staves().append(s); + pscore->appendStaff(s); stavesMap.append(staff->idx()); for (int i = staff->idx() * VOICES, j = 0; i < staff->idx() * VOICES + VOICES; i++, j++) { diff --git a/src/importexport/guitarpro/internal/importptb.cpp b/src/importexport/guitarpro/internal/importptb.cpp index 01916c2573..765b89c187 100644 --- a/src/importexport/guitarpro/internal/importptb.cpp +++ b/src/importexport/guitarpro/internal/importptb.cpp @@ -788,8 +788,7 @@ void PowerTab::addToScore(ptSection& sec) //int lastStaff = sec.staffMap.back() + 1; for (int i = 0; i < staves; ++i) { Part* part = new Part(score); - Staff* s = new Staff(score); - s->setPart(part); + Staff* s = createStaff(score, part); part->insertStaff(s, -1); auto info = &curTrack->infos[i]; std::string ss = info->name; @@ -805,7 +804,7 @@ void PowerTab::addToScore(ptSection& sec) part->setMidiProgram(info->instrument); - score->staves().push_back(s); + score->appendStaff(s); score->appendPart(part); } } @@ -1308,14 +1307,12 @@ Score::FileError PowerTab::read() Staff* staff = part->staves()->front(); - Staff* s = new Staff(pscore); - s->setPart(p); + Staff* s = createStaff(score, p); const StaffType* st = staff->staffType(Fraction(0, 1)); s->setStaffType(Fraction(0, 1), *st); s->linkTo(staff); - p->staves()->append(s); - pscore->staves().append(s); + pscore->appendStaff(s); stavesMap.append(staff->idx()); for (int i = staff->idx() * VOICES, j = 0; i < staff->idx() * VOICES + VOICES; i++, j++) { tracks.insert(i, j); diff --git a/src/importexport/musedata/internal/musedata.cpp b/src/importexport/musedata/internal/musedata.cpp index 3965d7f2d0..da392dc403 100644 --- a/src/importexport/musedata/internal/musedata.cpp +++ b/src/importexport/musedata/internal/musedata.cpp @@ -681,10 +681,9 @@ bool MuseData::read(const QString& name) Part* mpart = new Part(score); int staves = countStaves(part); for (int i = 0; i < staves; ++i) { - Staff* staff = new Staff(score); - staff->setPart(mpart); - mpart->insertStaff(staff, i); - score->staves().push_back(staff); + Staff* staff = createStaff(score, mpart); + score->appendStaff(staff); + if ((staves == 2) && (i == 0)) { staff->setBracketType(0, BracketType::BRACE); staff->setBracketSpan(0, 2); diff --git a/src/importexport/musicxml/internal/musicxml/importmxmlpass1.cpp b/src/importexport/musicxml/internal/musicxml/importmxmlpass1.cpp index 1662400e28..01bd4158de 100644 --- a/src/importexport/musicxml/internal/musicxml/importmxmlpass1.cpp +++ b/src/importexport/musicxml/internal/musicxml/importmxmlpass1.cpp @@ -1713,11 +1713,8 @@ static void createPart(Score* score, const QString& id, PartMap& pm) Part* part = new Part(score); pm.insert(id, part); score->appendPart(part); - Staff* staff = new Staff(score); - staff->setPart(part); - part->staves()->push_back(staff); - score->staves().push_back(staff); - // TODO TBD tuplets.resize(VOICES); // part now contains one staff, thus VOICES voices + Staff* staff = createStaff(score, part); + score->appendStaff(staff); } //--------------------------------------------------------- diff --git a/src/importexport/ove/internal/importove.cpp b/src/importexport/ove/internal/importove.cpp index 2c1a1b14bd..cb7db495d0 100644 --- a/src/importexport/ove/internal/importove.cpp +++ b/src/importexport/ove/internal/importove.cpp @@ -312,11 +312,8 @@ void OveToMScore::createStructure() for (int j = 0; j < partStaffCount; ++j) { //ovebase::Track* track = m_ove->getTrack(i, j); - Staff* staff = new Staff(m_score); - staff->setPart(part); - - part->staves()->push_back(staff); - m_score->staves().push_back(staff); + Staff* staff = createStaff(m_score, part); + m_score->appendStaff(staff); } m_score->appendPart(part); diff --git a/src/notation/internal/masternotation.cpp b/src/notation/internal/masternotation.cpp index fbd1d39368..5efefe3b55 100644 --- a/src/notation/internal/masternotation.cpp +++ b/src/notation/internal/masternotation.cpp @@ -114,15 +114,13 @@ mu::Ret MasterNotation::setupNewScore(Ms::MasterScore* score, Ms::MasterScore* t part->setPartName(tpart->partName()); for (Ms::Staff* tstaff : *tpart->staves()) { - Ms::Staff* staff = new Ms::Staff(score); - staff->setPart(part); + Ms::Staff* staff = Ms::createStaff(score, part); staff->init(tstaff); if (tstaff->links() && !part->staves()->isEmpty()) { Staff* linkedStaff = part->staves()->back(); staff->linkTo(linkedStaff); } - part->insertStaff(staff, -1); - score->staves().append(staff); + score->appendStaff(staff); } score->appendPart(part); } diff --git a/src/notation/internal/notationparts.cpp b/src/notation/internal/notationparts.cpp index f6d8337666..48ed267c5a 100644 --- a/src/notation/internal/notationparts.cpp +++ b/src/notation/internal/notationparts.cpp @@ -92,7 +92,7 @@ NotifyList NotationParts::partList() const NotifyList NotationParts::staffList(const ID& partId) const { - Part* part = this->partModifiable(partId); + const Part* part = this->part(partId); if (!part) { return NotifyList(); } @@ -125,12 +125,12 @@ bool NotationParts::partExists(const ID& partId) const Part* NotationParts::partModifiable(const ID& partId) const { - return score()->part(partId.toUint64()); + return score()->partById(partId.toUint64()); } Staff* NotationParts::staffModifiable(const ID& staffId) const { - return score()->staff(staffId.toUint64()); + return score()->staffById(staffId.toUint64()); } std::vector NotationParts::staves(const IDList& stavesIds) const @@ -178,7 +178,7 @@ void NotationParts::setPartVisible(const ID& partId, bool visible) { TRACEFUNC; - Part* part = this->partModifiable(partId); + Part* part = partModifiable(partId); if (part && part->show() == visible) { return; @@ -197,7 +197,7 @@ void NotationParts::setPartName(const ID& partId, const QString& name) { TRACEFUNC; - Part* part = this->partModifiable(partId); + Part* part = partModifiable(partId); if (!part || part->partName() == name) { return; } @@ -215,7 +215,7 @@ void NotationParts::setPartSharpFlat(const ID& partId, const SharpFlat& sharpFla { TRACEFUNC; - Part* part = this->partModifiable(partId); + Part* part = partModifiable(partId); if (!part) { return; } @@ -233,7 +233,7 @@ void NotationParts::setPartTransposition(const ID& partId, const Interval& trans { TRACEFUNC; - Part* part = this->partModifiable(partId); + Part* part = partModifiable(partId); if (!part) { return; } @@ -254,28 +254,6 @@ void NotationParts::updatePartTitles() } } -Ms::ID NotationParts::newPartId() const -{ - Ms::ID maxId = 0; - - for (const Part* part : score()->parts()) { - maxId = std::max(maxId, part->id()); - } - - return maxId + 1; -} - -Ms::ID NotationParts::newStaffId() const -{ - Ms::ID maxId = 0; - - for (const Staff* staff : score()->staves()) { - maxId = std::max(maxId, staff->id()); - } - - return maxId + 1; -} - void NotationParts::doMoveStaves(const std::vector& staves, int destinationStaffIndex, Part* destinationPart) { TRACEFUNC; @@ -308,7 +286,7 @@ void NotationParts::setInstrumentName(const InstrumentKey& instrumentKey, const { TRACEFUNC; - Part* part = this->partModifiable(instrumentKey.partId); + Part* part = partModifiable(instrumentKey.partId); if (!part) { return; } @@ -326,7 +304,7 @@ void NotationParts::setInstrumentAbbreviature(const InstrumentKey& instrumentKey { TRACEFUNC; - Part* part = this->partModifiable(instrumentKey.partId); + Part* part = partModifiable(instrumentKey.partId); if (!part) { return; } @@ -553,6 +531,9 @@ void NotationParts::appendStaff(Staff* staff, const ID& destinationPartId) staff->setScore(score()); staff->setPart(destinationPart); + //! NOTE: will be generated later after adding to the score + staff->setId(Ms::INVALID_ID); + insertStaff(staff, staffIndex); setBracketsAndBarlines(); @@ -572,17 +553,12 @@ void NotationParts::appendPart(Part* part) return; } - if (!ID(part->id()).isValid()) { - part->setId(newPartId()); - } - QList stavesCopy = *part->staves(); - part->staves()->clear(); + part->clearStaves(); startEdit(); - int partIndex = score()->parts().size(); - score()->parts().insert(partIndex, part); + score()->appendPart(part); if (score()->excerpt()) { score()->excerpt()->parts().append(part); @@ -634,7 +610,7 @@ void NotationParts::replaceInstrument(const InstrumentKey& instrumentKey, const { TRACEFUNC; - Part* part = this->partModifiable(instrumentKey.partId); + Part* part = partModifiable(instrumentKey.partId); if (!part) { return; } @@ -651,7 +627,7 @@ void NotationParts::replaceInstrument(const InstrumentKey& instrumentKey, const void NotationParts::replaceDrumset(const InstrumentKey& instrumentKey, const Drumset& newDrumset) { - Part* part = this->partModifiable(instrumentKey.partId); + Part* part = partModifiable(instrumentKey.partId); if (!part) { return; } @@ -822,10 +798,7 @@ void NotationParts::appendStaves(Part* part, const Instrument& instrument) for (int staffIndex = 0; staffIndex < instrument.staves; ++staffIndex) { int lastStaffIndex = !score()->staves().isEmpty() ? score()->staves().last()->idx() : 0; - Staff* staff = new Staff(score()); - staff->setId(newStaffId()); - - staff->setPart(part); + Staff* staff = Ms::createStaff(score(), part); initStaff(staff, instrument, Ms::StaffType::preset(StaffType::STANDARD), staffIndex); if (lastStaffIndex > 0) { @@ -921,10 +894,8 @@ void NotationParts::appendNewParts(const PartInstrumentList& parts) continue; } - Part* part = new Part(score()); - part->setId(newPartId()); - const Instrument& instrument = pi.instrument; + Part* part = new Part(score()); part->setSoloist(pi.isSoloist); part->setInstrument(InstrumentsConverter::convertInstrument(instrument)); @@ -953,8 +924,10 @@ void NotationParts::updateSoloist(const PartInstrumentList& parts) TRACEFUNC; for (const PartInstrument& pi: parts) { - if (pi.isExistingPart && (pi.isSoloist != partModifiable(pi.partId)->soloist())) { - score()->undo(new Ms::SetSoloist(partModifiable(pi.partId), pi.isSoloist)); + Part* part = partModifiable(pi.partId); + + if (pi.isExistingPart && (pi.isSoloist != part->soloist())) { + score()->undo(new Ms::SetSoloist(part, pi.isSoloist)); } } } @@ -1023,7 +996,7 @@ void NotationParts::setBracketsAndBarlines() score()->setBracketsAndBarlines(); } -void NotationParts::notifyAboutPartChanged(Part* part) const +void NotationParts::notifyAboutPartChanged(const Part* part) const { IF_ASSERT_FAILED(part) { return; @@ -1032,7 +1005,7 @@ void NotationParts::notifyAboutPartChanged(Part* part) const m_partChangedNotifier->itemChanged(part); } -void NotationParts::notifyAboutPartAdded(Part* part) const +void NotationParts::notifyAboutPartAdded(const Part* part) const { IF_ASSERT_FAILED(part) { return; @@ -1041,7 +1014,7 @@ void NotationParts::notifyAboutPartAdded(Part* part) const m_partChangedNotifier->itemAdded(part); } -void NotationParts::notifyAboutPartRemoved(Part* part) const +void NotationParts::notifyAboutPartRemoved(const Part* part) const { IF_ASSERT_FAILED(part) { return; @@ -1050,7 +1023,7 @@ void NotationParts::notifyAboutPartRemoved(Part* part) const m_partChangedNotifier->itemRemoved(part); } -void NotationParts::notifyAboutStaffChanged(Staff* staff) const +void NotationParts::notifyAboutStaffChanged(const Staff* staff) const { IF_ASSERT_FAILED(staff && staff->part()) { return; @@ -1063,7 +1036,7 @@ void NotationParts::notifyAboutStaffChanged(Staff* staff) const } } -void NotationParts::notifyAboutStaffAdded(Staff* staff, const ID& partId) const +void NotationParts::notifyAboutStaffAdded(const Staff* staff, const ID& partId) const { IF_ASSERT_FAILED(staff) { return; @@ -1076,7 +1049,7 @@ void NotationParts::notifyAboutStaffAdded(Staff* staff, const ID& partId) const } } -void NotationParts::notifyAboutStaffRemoved(Staff* staff) const +void NotationParts::notifyAboutStaffRemoved(const Staff* staff) const { IF_ASSERT_FAILED(staff) { return; diff --git a/src/notation/internal/notationparts.h b/src/notation/internal/notationparts.h index 26db0133e4..ffb6be8349 100644 --- a/src/notation/internal/notationparts.h +++ b/src/notation/internal/notationparts.h @@ -83,9 +83,6 @@ protected: private: void updatePartTitles(); - Ms::ID newPartId() const; - Ms::ID newStaffId() const; - void doMoveStaves(const std::vector& staves, int destinationStaffIndex, Part* destinationPart = nullptr); void doSetStaffVisible(Staff* staff, bool visible); void doSetStaffVoiceVisible(Staff* staff, int voiceIndex, bool visible); @@ -108,12 +105,12 @@ private: void setBracketsAndBarlines(); - void notifyAboutPartChanged(Part* part) const; - void notifyAboutPartAdded(Part* part) const; - void notifyAboutPartRemoved(Part* part) const; - void notifyAboutStaffChanged(Staff* staff) const; - void notifyAboutStaffAdded(Staff* staff, const ID& partId) const; - void notifyAboutStaffRemoved(Staff* staff) const; + void notifyAboutPartChanged(const Part* part) const; + void notifyAboutPartAdded(const Part* part) const; + void notifyAboutPartRemoved(const Part* part) const; + void notifyAboutStaffChanged(const Staff* staff) const; + void notifyAboutStaffAdded(const Staff* staff, const ID& partId) const; + void notifyAboutStaffRemoved(const Staff* staff) const; async::ChangedNotifier* staffChangedNotifier(const ID& partId) const; IGetScore* m_getScore = nullptr;