changed interface for appending/linking staves to prevent occurring of staves with different id in different excerpts
This commit is contained in:
parent
deccf9b7f9
commit
e03cfddee5
14 changed files with 138 additions and 117 deletions
|
@ -28,7 +28,26 @@ StaffControlTreeItem::StaffControlTreeItem(INotationPartsPtr notationParts, QObj
|
|||
|
||||
void StaffControlTreeItem::appendNewItem()
|
||||
{
|
||||
notationParts()->appendStaff(m_partId);
|
||||
Staff* lastStaff = this->lastStaff();
|
||||
if (!lastStaff) {
|
||||
return;
|
||||
}
|
||||
|
||||
Staff* staff = lastStaff->clone();
|
||||
staff->setId(Staff::makeId());
|
||||
|
||||
notationParts()->appendStaff(staff, m_partId);
|
||||
}
|
||||
|
||||
Staff* StaffControlTreeItem::lastStaff() const
|
||||
{
|
||||
for (const Part* part : notationParts()->partList()) {
|
||||
if (part->id() == m_partId) {
|
||||
return part->staves()->last();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void StaffControlTreeItem::setPartId(const QString& id)
|
||||
|
|
|
@ -36,6 +36,8 @@ public:
|
|||
void setPartId(const QString& id);
|
||||
|
||||
private:
|
||||
notation::Staff* lastStaff() const;
|
||||
|
||||
QString m_partId;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -142,9 +142,33 @@ void StaffSettingsModel::setCutawayEnabled(bool value)
|
|||
|
||||
void StaffSettingsModel::createLinkedStaff()
|
||||
{
|
||||
if (parts()) {
|
||||
parts()->appendLinkedStaff(m_staffId);
|
||||
if (!parts()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Staff* sourceStaff = staff();
|
||||
if (!sourceStaff) {
|
||||
return;
|
||||
}
|
||||
|
||||
Staff* linkedStaff = sourceStaff->clone();
|
||||
linkedStaff->setId(Staff::makeId());
|
||||
|
||||
parts()->appendStaff(linkedStaff, sourceStaff->part()->id());
|
||||
parts()->cloneStaff(sourceStaff->id(), linkedStaff->id());
|
||||
}
|
||||
|
||||
Staff* StaffSettingsModel::staff() const
|
||||
{
|
||||
for (const Part* part : parts()->partList()) {
|
||||
for (Staff* staff : *part->staves()) {
|
||||
if (staff->id() == m_staffId) {
|
||||
return staff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
INotationPartsPtr StaffSettingsModel::parts() const
|
||||
|
|
|
@ -59,6 +59,7 @@ signals:
|
|||
void dataChanged();
|
||||
|
||||
private:
|
||||
notation::Staff* staff() const;
|
||||
notation::INotationPartsPtr parts() const;
|
||||
|
||||
notation::ID m_staffId;
|
||||
|
|
|
@ -1053,73 +1053,44 @@ Measure* Score::searchMeasure(const QPointF& p, const System* preferredSystem, q
|
|||
|
||||
//---------------------------------------------------------
|
||||
// getNextValidInputSegment
|
||||
// - s is of type SegmentType::ChordRest
|
||||
// - segment is of type SegmentType::ChordRest
|
||||
//---------------------------------------------------------
|
||||
|
||||
static Segment* getNextValidInputSegment(Segment* s, int track, int voice)
|
||||
static Segment* getNextValidInputSegment(Segment* segment, int track, int voice)
|
||||
{
|
||||
if (s == 0) {
|
||||
return 0;
|
||||
if (segment == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
Q_ASSERT(s->segmentType() == SegmentType::ChordRest);
|
||||
// Segment* s1 = s;
|
||||
ChordRest* cr1 = nullptr;
|
||||
for (Segment* s1 = s; s1; s1 = s1->prev(SegmentType::ChordRest)) {
|
||||
cr1 = toChordRest(s1->element(track + voice));
|
||||
if (cr1) {
|
||||
|
||||
Q_ASSERT(segment->segmentType() == SegmentType::ChordRest);
|
||||
|
||||
ChordRest* chordRest = nullptr;
|
||||
for (Segment* s1 = segment; s1; s1 = s1->prev(SegmentType::ChordRest)) {
|
||||
Element* element = s1->element(track + voice);
|
||||
chordRest = toChordRest(element);
|
||||
|
||||
if (chordRest) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Fraction nextTick = (cr1 == nullptr) ? s->measure()->tick() : cr1->tick() + cr1->actualTicks();
|
||||
|
||||
Fraction nextTick = (chordRest == nullptr) ? segment->measure()->tick() :
|
||||
chordRest->tick() + chordRest->actualTicks();
|
||||
|
||||
static const SegmentType st { SegmentType::ChordRest };
|
||||
while (s) {
|
||||
if (s->element(track + voice)) {
|
||||
while (segment) {
|
||||
if (segment->element(track + voice)) {
|
||||
break;
|
||||
}
|
||||
if (voice && s->tick() == nextTick) {
|
||||
return s;
|
||||
|
||||
if (voice && segment->tick() == nextTick) {
|
||||
return segment;
|
||||
}
|
||||
#if 0
|
||||
int v;
|
||||
for (v = 0; v < VOICES; ++v) {
|
||||
if (s->element(track + v)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((v != VOICES) && voice) {
|
||||
int ntick;
|
||||
bool skipChord = false;
|
||||
bool ns = false;
|
||||
for (Segment* s1 = s->measure()->first(st); s1; s1 = s1->next(st)) {
|
||||
ChordRest* cr = toChordRest(s1->element(track + voice));
|
||||
if (cr) {
|
||||
if (ns) {
|
||||
return s1;
|
||||
}
|
||||
ntick = s1->tick() + cr->actualTicks();
|
||||
skipChord = true;
|
||||
}
|
||||
if (s1 == s) {
|
||||
ns = true;
|
||||
}
|
||||
if (skipChord) {
|
||||
if (s->tick() >= ntick) {
|
||||
skipChord = false;
|
||||
}
|
||||
}
|
||||
if (!skipChord && ns) {
|
||||
return s1;
|
||||
}
|
||||
}
|
||||
if (!skipChord) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
s = s->next(st);
|
||||
|
||||
segment = segment->next(st);
|
||||
}
|
||||
return s;
|
||||
|
||||
return segment;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
|
|
@ -1222,6 +1222,15 @@ void Staff::init(const Staff* s)
|
|||
_userDist = s->_userDist;
|
||||
}
|
||||
|
||||
void Staff::setScore(Score* score)
|
||||
{
|
||||
Element::setScore(score);
|
||||
|
||||
for (BracketItem* bracket: _brackets) {
|
||||
bracket->setScore(score);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// initFromStaffType
|
||||
//---------------------------------------------------------
|
||||
|
|
|
@ -117,6 +117,8 @@ public:
|
|||
|
||||
ElementType type() const override { return ElementType::STAFF; }
|
||||
|
||||
void setScore(Score* score) override;
|
||||
|
||||
bool isTop() const;
|
||||
QString partName() const;
|
||||
int rstaff() const;
|
||||
|
|
|
@ -74,8 +74,9 @@ public:
|
|||
virtual void moveStaves(const IDList& sourceStavesIds, const ID& destinationStaffId, InsertMode mode = InsertMode::Before) = 0;
|
||||
|
||||
virtual void appendDoublingInstrument(const instruments::Instrument& instrument, const ID& destinationPartId) = 0;
|
||||
virtual void appendStaff(const ID& destinationPartId) = 0;
|
||||
virtual void appendLinkedStaff(const ID& originStaffId) = 0;
|
||||
virtual void appendStaff(const Staff* staff, const ID& destinationPartId) = 0;
|
||||
|
||||
virtual void cloneStaff(const ID& sourceStaffId, const ID& destinationStaffId) = 0;
|
||||
|
||||
virtual void replaceInstrument(const ID& instrumentId, const ID& fromPartId, const instruments::Instrument& newInstrument) = 0;
|
||||
|
||||
|
|
|
@ -606,33 +606,11 @@ void MasterNotation::setExcerpts(const ExcerptNotationList& excerpts)
|
|||
return;
|
||||
}
|
||||
|
||||
removeMissingExcerpts(excerpts);
|
||||
createNonexistentExcerpts(excerpts);
|
||||
|
||||
doSetExcerpts(excerpts);
|
||||
}
|
||||
|
||||
void MasterNotation::removeMissingExcerpts(const ExcerptNotationList& newExcerpts)
|
||||
{
|
||||
for (IExcerptNotationPtr excerpt : m_excerpts.val) {
|
||||
bool missingExcerpt = std::find(newExcerpts.begin(), newExcerpts.end(), excerpt) == newExcerpts.end();
|
||||
|
||||
if (!missingExcerpt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
excerpt->setOpened(false);
|
||||
|
||||
IDList partsToRemove;
|
||||
|
||||
for (const Part* part: excerpt->parts()->partList()) {
|
||||
partsToRemove << part->id();
|
||||
}
|
||||
|
||||
excerpt->parts()->removeParts(partsToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
void MasterNotation::createNonexistentExcerpts(const ExcerptNotationList& newExcerpts)
|
||||
{
|
||||
for (IExcerptNotationPtr excerptNotation : newExcerpts) {
|
||||
|
|
|
@ -70,7 +70,6 @@ private:
|
|||
void initExcerpts();
|
||||
void initExcerpt(Ms::Excerpt* excerpt);
|
||||
|
||||
void removeMissingExcerpts(const ExcerptNotationList& newExcerpts);
|
||||
void createNonexistentExcerpts(const ExcerptNotationList& newExcerpts);
|
||||
|
||||
void updateExcerpts();
|
||||
|
|
|
@ -176,21 +176,21 @@ void MasterNotationParts::appendDoublingInstrument(const instruments::Instrument
|
|||
}
|
||||
}
|
||||
|
||||
void MasterNotationParts::appendStaff(const ID& destinationPartId)
|
||||
void MasterNotationParts::appendStaff(const Staff* staff, const ID& destinationPartId)
|
||||
{
|
||||
NotationParts::appendStaff(destinationPartId);
|
||||
NotationParts::appendStaff(staff, destinationPartId);
|
||||
|
||||
for (INotationPartsPtr parts : excerptsParts()) {
|
||||
parts->appendStaff(destinationPartId);
|
||||
parts->appendStaff(staff, destinationPartId);
|
||||
}
|
||||
}
|
||||
|
||||
void MasterNotationParts::appendLinkedStaff(const ID& originStaffId)
|
||||
void MasterNotationParts::cloneStaff(const ID& sourceStaffId, const ID& destinationStaffId)
|
||||
{
|
||||
NotationParts::appendLinkedStaff(originStaffId);
|
||||
NotationParts::cloneStaff(sourceStaffId, destinationStaffId);
|
||||
|
||||
for (INotationPartsPtr parts : excerptsParts()) {
|
||||
parts->appendLinkedStaff(originStaffId);
|
||||
parts->cloneStaff(sourceStaffId, destinationStaffId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,9 @@ public:
|
|||
void moveStaves(const IDList& sourceStavesIds, const ID& destinationStaffId, InsertMode mode = InsertMode::Before) override;
|
||||
|
||||
void appendDoublingInstrument(const instruments::Instrument& instrument, const ID& destinationPartId) override;
|
||||
void appendStaff(const ID& destinationPartId) override;
|
||||
void appendLinkedStaff(const ID& originStaffId) override;
|
||||
void appendStaff(const Staff* staff, const ID& destinationPartId) override;
|
||||
|
||||
void cloneStaff(const ID& sourceStaffId, const ID& destinationStaffId) override;
|
||||
|
||||
void replaceInstrument(const ID& instrumentId, const ID& fromPartId, const instruments::Instrument& newInstrument) override;
|
||||
|
||||
|
|
|
@ -387,7 +387,7 @@ void NotationParts::doMoveStaves(const std::vector<Staff*>& staves, int destinat
|
|||
|
||||
bool needUnlink = !staff->isLinked();
|
||||
|
||||
score()->undoInsertStaff(movedStaff, destinationStaffIndex);
|
||||
insertStaff(movedStaff, destinationStaffIndex);
|
||||
Ms::Excerpt::cloneStaff(staff, movedStaff);
|
||||
|
||||
if (needUnlink) {
|
||||
|
@ -661,52 +661,49 @@ void NotationParts::appendDoublingInstrument(const mu::instruments::Instrument&
|
|||
m_partsChanged.notify();
|
||||
}
|
||||
|
||||
void NotationParts::appendStaff(const ID& destinationPartId)
|
||||
void NotationParts::appendStaff(const Staff* staff, const ID& destinationPartId)
|
||||
{
|
||||
Part* part = this->part(destinationPartId);
|
||||
if (!part) {
|
||||
Part* destinationPart = part(destinationPartId);
|
||||
if (!destinationPart) {
|
||||
return;
|
||||
}
|
||||
|
||||
InstrumentInfo instrumentInfo = this->instrumentInfo(part->instrumentId(), part);
|
||||
InstrumentInfo instrumentInfo = this->instrumentInfo(destinationPart->instrumentId(), destinationPart);
|
||||
if (!instrumentInfo.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ms::Instrument* instrument = instrumentInfo.instrument;
|
||||
int staffIndex = destinationPart->nstaves();
|
||||
|
||||
Staff* copy = staff->clone();
|
||||
copy->setPart(destinationPart);
|
||||
copy->setScore(score());
|
||||
|
||||
startEdit();
|
||||
Staff* staff = part->staves()->front()->clone();
|
||||
staff->setId(Staff::makeId());
|
||||
int staffIndex = staff->part()->nstaves();
|
||||
score()->undoInsertStaff(staff, staffIndex);
|
||||
instrument->setClefType(staffIndex, staff->defaultClefType());
|
||||
insertStaff(copy, staffIndex);
|
||||
apply();
|
||||
|
||||
Ms::Instrument* instrument = instrumentInfo.instrument;
|
||||
instrument->setClefType(staffIndex, staff->defaultClefType());
|
||||
|
||||
ChangedNotifier<const Staff*>* notifier = instrumentNotifier(instrument->instrumentId(), destinationPartId);
|
||||
notifier->itemAdded(staff);
|
||||
m_partsChanged.notify();
|
||||
}
|
||||
|
||||
void NotationParts::appendLinkedStaff(const ID& originStaffId)
|
||||
void NotationParts::cloneStaff(const ID& sourceStaffId, const ID& destinationStaffId)
|
||||
{
|
||||
Staff* staff = this->staff(originStaffId);
|
||||
if (!staff || !staff->part()) {
|
||||
Staff* sourceStaff = staff(sourceStaffId);
|
||||
Staff* destinationStaff = staff(destinationStaffId);
|
||||
|
||||
if (!sourceStaff || !destinationStaff) {
|
||||
return;
|
||||
}
|
||||
|
||||
Staff* linkedStaff = staff->clone();
|
||||
linkedStaff->setId(Staff::makeId());
|
||||
int linkedStaffIndex = staff->part()->nstaves();
|
||||
|
||||
startEdit();
|
||||
score()->undoInsertStaff(linkedStaff, linkedStaffIndex);
|
||||
Ms::Excerpt::cloneStaff(staff, linkedStaff);
|
||||
Ms::Excerpt::cloneStaff(sourceStaff, destinationStaff);
|
||||
apply();
|
||||
|
||||
InstrumentInfo instrumentInfo = this->instrumentInfo(linkedStaff);
|
||||
ChangedNotifier<const Staff*>* notifier = instrumentNotifier(instrumentInfo.instrument->instrumentId(), linkedStaff->part()->id());
|
||||
notifier->itemAdded(linkedStaff);
|
||||
m_partsChanged.notify();
|
||||
}
|
||||
|
||||
|
@ -816,6 +813,20 @@ void NotationParts::doSetPartName(Part* part, const QString& name)
|
|||
score()->undo(new Ms::ChangePart(part, new Ms::Instrument(*part->instrument()), name));
|
||||
}
|
||||
|
||||
void NotationParts::insertStaff(Staff *staff, int destinationStaffIndex)
|
||||
{
|
||||
if (score()->excerpt()) {
|
||||
int globalDestinationStaffIndex = score()->staffIdx(staff->part()) + destinationStaffIndex;
|
||||
|
||||
for (int voiceIndex = 0; voiceIndex < VOICES; ++voiceIndex) {
|
||||
int track = globalDestinationStaffIndex * VOICES + voiceIndex % VOICES;
|
||||
score()->excerpt()->tracks().insert(track, track);
|
||||
}
|
||||
}
|
||||
|
||||
score()->undoInsertStaff(staff, destinationStaffIndex);
|
||||
}
|
||||
|
||||
void NotationParts::moveParts(const IDList& sourcePartsIds, const ID& destinationPartId, InsertMode mode)
|
||||
{
|
||||
startEdit();
|
||||
|
@ -1192,7 +1203,7 @@ void NotationParts::appendPart(Part* part)
|
|||
staffCopy->setPart(partCopy);
|
||||
staffCopy->init(staff);
|
||||
|
||||
score()->undoInsertStaff(staffCopy, staffIndex);
|
||||
insertStaff(staffCopy, staffIndex);
|
||||
|
||||
Ms::Fraction startTick = score()->firstMeasure()->tick();
|
||||
Ms::Fraction endTick = score()->lastMeasure()->tick();
|
||||
|
@ -1257,7 +1268,7 @@ void NotationParts::appendStaves(Part* part, const mu::instruments::Instrument&
|
|||
staff->setBarLineSpan(score()->staff(lastStaffIndex - 1)->barLineSpan());
|
||||
}
|
||||
|
||||
score()->undoInsertStaff(staff, staffIndex);
|
||||
insertStaff(staff, staffIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,8 +66,9 @@ public:
|
|||
void moveStaves(const IDList& sourceStavesIds, const ID& destinationStaffId, InsertMode mode = InsertMode::Before) override;
|
||||
|
||||
void appendDoublingInstrument(const instruments::Instrument& instrument, const ID& destinationPartId) override;
|
||||
void appendStaff(const ID& destinationPartId) override;
|
||||
void appendLinkedStaff(const ID& originStaffId) override;
|
||||
void appendStaff(const Staff* staff, const ID& destinationPartId) override;
|
||||
|
||||
void cloneStaff(const ID& sourceStaffId, const ID& destinationStaffId) override;
|
||||
|
||||
void replaceInstrument(const ID& instrumentId, const ID& fromPartId, const instruments::Instrument& newInstrument) override;
|
||||
|
||||
|
@ -125,6 +126,8 @@ private:
|
|||
void doRemoveInstruments(const IDList& instrumentsIds, Part* fromPart);
|
||||
void doSetPartName(Part* part, const QString& name);
|
||||
|
||||
void insertStaff(Staff* staff, int destinationStaffIndex);
|
||||
|
||||
Part* part(const ID& partId, const Ms::Score* score = nullptr) const;
|
||||
InstrumentInfo instrumentInfo(const ID& instrumentId, const Part* fromPart) const;
|
||||
InstrumentInfo instrumentInfo(const Staff* staff) const;
|
||||
|
|
Loading…
Reference in a new issue