Merge pull request #8794 from Eism/instruments_notifications
[MU4] Instruments clenup. Parts notifications
This commit is contained in:
commit
20a8304c79
6 changed files with 110 additions and 49 deletions
|
@ -2350,7 +2350,11 @@ qreal Segment::minHorizontalCollidingDistance(Segment* ns) const
|
|||
qreal Segment::elementsTopOffsetFromSkyline(int staffIndex) const
|
||||
{
|
||||
System* segmentSystem = measure()->system();
|
||||
SysStaff* staffSystem = segmentSystem->staff(staffIndex);
|
||||
SysStaff* staffSystem = segmentSystem ? segmentSystem->staff(staffIndex) : nullptr;
|
||||
|
||||
if (!staffSystem) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ms::SkylineLine north = staffSystem->skyline().north();
|
||||
int topOffset = INT_MAX;
|
||||
|
@ -2379,7 +2383,11 @@ qreal Segment::elementsTopOffsetFromSkyline(int staffIndex) const
|
|||
qreal Segment::elementsBottomOffsetFromSkyline(int staffIndex) const
|
||||
{
|
||||
System* segmentSystem = measure()->system();
|
||||
SysStaff* staffSystem = segmentSystem->staff(staffIndex);
|
||||
SysStaff* staffSystem = segmentSystem ? segmentSystem->staff(staffIndex) : nullptr;
|
||||
|
||||
if (!staffSystem) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ms::SkylineLine south = staffSystem->skyline().south();
|
||||
int bottomOffset = INT_MIN;
|
||||
|
|
|
@ -119,7 +119,7 @@ void PartTreeItem::removeChildren(const int row, const int count, const bool del
|
|||
}
|
||||
|
||||
if (deleteChild) {
|
||||
notation()->parts()->removeStaves(stavesIds);
|
||||
masterNotation()->parts()->removeStaves(stavesIds);
|
||||
}
|
||||
|
||||
AbstractInstrumentsPanelTreeItem::removeChildren(row, count, deleteChild);
|
||||
|
|
|
@ -55,6 +55,10 @@ MasterNotation::MasterNotation()
|
|||
: Notation()
|
||||
{
|
||||
m_parts = std::make_shared<MasterNotationParts>(this, interaction(), undoStack());
|
||||
|
||||
m_parts->partsChanged().onNotify(this, [this]() {
|
||||
notifyAboutNotationChanged();
|
||||
});
|
||||
}
|
||||
|
||||
MasterNotation::~MasterNotation()
|
||||
|
|
|
@ -97,7 +97,7 @@ void MasterNotationParts::removeStaves(const IDList& stavesIds)
|
|||
{
|
||||
TRACEFUNC;
|
||||
|
||||
startEdit();
|
||||
startGlobalEdit();
|
||||
|
||||
NotationParts::removeStaves(stavesIds);
|
||||
|
||||
|
@ -105,14 +105,14 @@ void MasterNotationParts::removeStaves(const IDList& stavesIds)
|
|||
parts->removeStaves(stavesIds);
|
||||
}
|
||||
|
||||
apply();
|
||||
endGlobalEdit();
|
||||
}
|
||||
|
||||
void MasterNotationParts::appendStaff(Staff* staff, const ID& destinationPartId)
|
||||
{
|
||||
TRACEFUNC;
|
||||
|
||||
startEdit();
|
||||
startGlobalEdit();
|
||||
|
||||
NotationParts::appendStaff(staff, destinationPartId);
|
||||
|
||||
|
@ -120,14 +120,14 @@ void MasterNotationParts::appendStaff(Staff* staff, const ID& destinationPartId)
|
|||
parts->appendStaff(staff->clone(), destinationPartId);
|
||||
}
|
||||
|
||||
apply();
|
||||
endGlobalEdit();
|
||||
}
|
||||
|
||||
void MasterNotationParts::linkStaves(const ID& sourceStaffId, const ID& destinationStaffId)
|
||||
{
|
||||
TRACEFUNC;
|
||||
|
||||
startEdit();
|
||||
startGlobalEdit();
|
||||
|
||||
NotationParts::linkStaves(sourceStaffId, destinationStaffId);
|
||||
|
||||
|
@ -135,14 +135,14 @@ void MasterNotationParts::linkStaves(const ID& sourceStaffId, const ID& destinat
|
|||
parts->linkStaves(sourceStaffId, destinationStaffId);
|
||||
}
|
||||
|
||||
apply();
|
||||
endGlobalEdit();
|
||||
}
|
||||
|
||||
void MasterNotationParts::replaceInstrument(const InstrumentKey& instrumentKey, const Instrument& newInstrument)
|
||||
{
|
||||
TRACEFUNC;
|
||||
|
||||
startEdit();
|
||||
startGlobalEdit();
|
||||
|
||||
NotationParts::replaceInstrument(instrumentKey, newInstrument);
|
||||
|
||||
|
@ -150,14 +150,14 @@ void MasterNotationParts::replaceInstrument(const InstrumentKey& instrumentKey,
|
|||
parts->replaceInstrument(instrumentKey, newInstrument);
|
||||
}
|
||||
|
||||
apply();
|
||||
endGlobalEdit();
|
||||
}
|
||||
|
||||
void MasterNotationParts::replaceDrumset(const InstrumentKey& instrumentKey, const Drumset& newDrumset)
|
||||
{
|
||||
TRACEFUNC;
|
||||
|
||||
startEdit();
|
||||
startGlobalEdit();
|
||||
|
||||
NotationParts::replaceDrumset(instrumentKey, newDrumset);
|
||||
|
||||
|
@ -165,7 +165,7 @@ void MasterNotationParts::replaceDrumset(const InstrumentKey& instrumentKey, con
|
|||
parts->replaceDrumset(instrumentKey, newDrumset);
|
||||
}
|
||||
|
||||
apply();
|
||||
endGlobalEdit();
|
||||
}
|
||||
|
||||
std::vector<INotationPartsPtr> MasterNotationParts::excerptsParts() const
|
||||
|
|
|
@ -78,12 +78,6 @@ NotationParts::~NotationParts()
|
|||
delete m_partChangedNotifier;
|
||||
}
|
||||
|
||||
void NotationParts::updateScore()
|
||||
{
|
||||
score()->doLayout();
|
||||
m_partsChanged.notify();
|
||||
}
|
||||
|
||||
NotifyList<const Part*> NotationParts::partList() const
|
||||
{
|
||||
NotifyList<const Part*> result;
|
||||
|
@ -166,6 +160,8 @@ void NotationParts::setParts(const PartInstrumentList& parts)
|
|||
|
||||
QList<Ms::Staff*> originalStaves = score()->staves();
|
||||
|
||||
startEdit();
|
||||
|
||||
removeMissingParts(parts);
|
||||
appendNewParts(parts);
|
||||
updateSoloist(parts);
|
||||
|
@ -174,7 +170,7 @@ void NotationParts::setParts(const PartInstrumentList& parts)
|
|||
|
||||
setBracketsAndBarlines();
|
||||
|
||||
updateScore();
|
||||
apply();
|
||||
|
||||
m_partChangedNotifier->changed();
|
||||
}
|
||||
|
@ -194,8 +190,11 @@ void NotationParts::setPartVisible(const ID& partId, bool visible)
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
part->undoChangeProperty(Ms::Pid::VISIBLE, visible);
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutPartChanged(part);
|
||||
}
|
||||
|
@ -209,8 +208,11 @@ void NotationParts::setPartName(const ID& partId, const QString& name)
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
doSetPartName(part, name);
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutPartChanged(part);
|
||||
}
|
||||
|
@ -224,8 +226,11 @@ void NotationParts::setPartSharpFlat(const ID& partId, const SharpFlat& sharpFla
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
part->undoChangeProperty(Ms::Pid::PREFER_SHARP_FLAT, static_cast<int>(sharpFlat));
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutPartChanged(part);
|
||||
}
|
||||
|
@ -239,8 +244,11 @@ void NotationParts::setPartTransposition(const ID& partId, const Interval& trans
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
score()->transpositionChanged(part, transpose);
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutPartChanged(part);
|
||||
}
|
||||
|
@ -289,8 +297,11 @@ void NotationParts::setInstrumentName(const InstrumentKey& instrumentKey, const
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
score()->undo(new Ms::ChangeInstrumentLong(instrumentKey.tick, part, { StaffName(name, 0) }));
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutPartChanged(part);
|
||||
}
|
||||
|
@ -304,8 +315,11 @@ void NotationParts::setInstrumentAbbreviature(const InstrumentKey& instrumentKey
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
score()->undo(new Ms::ChangeInstrumentShort(instrumentKey.tick, part, { StaffName(abbreviature, 0) }));
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutPartChanged(part);
|
||||
}
|
||||
|
@ -319,8 +333,11 @@ void NotationParts::setVoiceVisible(const ID& staffId, int voiceIndex, bool visi
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
doSetStaffVoiceVisible(staff, voiceIndex, visible);
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutStaffChanged(staff);
|
||||
}
|
||||
|
@ -338,8 +355,11 @@ void NotationParts::setStaffVisible(const ID& staffId, bool visible)
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
doSetStaffVisible(staff, visible);
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutStaffChanged(staff);
|
||||
}
|
||||
|
@ -367,8 +387,11 @@ void NotationParts::setStaffType(const ID& staffId, StaffType type)
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
score()->undo(new Ms::ChangeStaffType(staff, *staffType));
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutStaffChanged(staff);
|
||||
}
|
||||
|
@ -382,9 +405,12 @@ void NotationParts::setCutawayEnabled(const ID& staffId, bool enabled)
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
staff->setCutaway(enabled);
|
||||
score()->undo(new Ms::ChangeStaff(staff));
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutStaffChanged(staff);
|
||||
}
|
||||
|
@ -403,9 +429,12 @@ void NotationParts::setSmallStaff(const ID& staffId, bool smallStaff)
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
staffType->setSmall(smallStaff);
|
||||
score()->undo(new Ms::ChangeStaffType(staff, *staffType));
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutStaffChanged(staff);
|
||||
}
|
||||
|
@ -424,6 +453,8 @@ void NotationParts::setStaffConfig(const ID& staffId, const StaffConfig& config)
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
staff->setVisible(config.visible);
|
||||
staff->undoChangeProperty(Ms::Pid::STAFF_COLOR, config.linesColor);
|
||||
staff->setInvisible(Fraction(0, 1), config.visibleLines);
|
||||
|
@ -447,7 +478,8 @@ void NotationParts::setStaffConfig(const ID& staffId, const StaffConfig& config)
|
|||
staff->undoChangeProperty(Ms::Pid::SMALL, config.small);
|
||||
|
||||
score()->undo(new Ms::ChangeStaff(staff));
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutStaffChanged(staff);
|
||||
}
|
||||
|
@ -498,6 +530,8 @@ void NotationParts::appendStaff(Staff* staff, const ID& destinationPartId)
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
int staffIndex = destinationPart->nstaves();
|
||||
|
||||
staff->setScore(score());
|
||||
|
@ -507,10 +541,10 @@ void NotationParts::appendStaff(Staff* staff, const ID& destinationPartId)
|
|||
|
||||
setBracketsAndBarlines();
|
||||
|
||||
updateScore();
|
||||
|
||||
destinationPart->instrument()->setClefType(staffIndex, staff->defaultClefType());
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutStaffAdded(staff, destinationPartId);
|
||||
}
|
||||
|
||||
|
@ -521,6 +555,8 @@ void NotationParts::appendPart(Part* part)
|
|||
QList<Staff*> stavesCopy = *part->staves();
|
||||
part->staves()->clear();
|
||||
|
||||
startEdit();
|
||||
|
||||
int partIndex = score()->parts().size();
|
||||
score()->parts().insert(partIndex, part);
|
||||
|
||||
|
@ -545,7 +581,7 @@ void NotationParts::appendPart(Part* part)
|
|||
|
||||
part->setScore(score());
|
||||
|
||||
updateScore();
|
||||
apply();
|
||||
|
||||
notifyAboutPartAdded(part);
|
||||
}
|
||||
|
@ -561,9 +597,12 @@ void NotationParts::linkStaves(const ID& sourceStaffId, const ID& destinationSta
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
Ms::Excerpt::cloneStaff(sourceStaff, destinationStaff);
|
||||
|
||||
updateScore();
|
||||
apply();
|
||||
|
||||
notifyAboutStaffChanged(destinationStaff);
|
||||
}
|
||||
|
||||
|
@ -576,9 +615,12 @@ void NotationParts::replaceInstrument(const InstrumentKey& instrumentKey, const
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
score()->undo(new Ms::ChangePart(part, new Ms::Instrument(InstrumentsConverter::convertInstrument(newInstrument)),
|
||||
formatPartTitle(part)));
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutPartChanged(part);
|
||||
}
|
||||
|
@ -595,8 +637,11 @@ void NotationParts::replaceDrumset(const InstrumentKey& instrumentKey, const Dru
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
score()->undo(new Ms::ChangeDrumset(instrument, &newDrumset));
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
notifyAboutPartChanged(part);
|
||||
}
|
||||
|
@ -623,7 +668,10 @@ void NotationParts::startEdit()
|
|||
|
||||
void NotationParts::apply()
|
||||
{
|
||||
score()->doLayout();
|
||||
undoStack()->commitChanges();
|
||||
|
||||
m_partsChanged.notify();
|
||||
}
|
||||
|
||||
void NotationParts::removeParts(const IDList& partsIds)
|
||||
|
@ -642,11 +690,7 @@ void NotationParts::removeParts(const IDList& partsIds)
|
|||
|
||||
setBracketsAndBarlines();
|
||||
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
|
||||
m_partsChanged.notify();
|
||||
}
|
||||
|
||||
void NotationParts::doRemoveParts(const IDList& partsIds)
|
||||
|
@ -668,13 +712,16 @@ void NotationParts::removeStaves(const IDList& stavesIds)
|
|||
return;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
for (Staff* staff: staves(stavesIds)) {
|
||||
notifyAboutStaffRemoved(staff);
|
||||
score()->cmdRemoveStaff(staff->idx());
|
||||
}
|
||||
|
||||
setBracketsAndBarlines();
|
||||
updateScore();
|
||||
|
||||
apply();
|
||||
}
|
||||
|
||||
void NotationParts::doSetPartName(Part* part, const QString& name)
|
||||
|
@ -709,11 +756,13 @@ void NotationParts::moveParts(const IDList& sourcePartsIds, const ID& destinatio
|
|||
parts << pi;
|
||||
}
|
||||
|
||||
startEdit();
|
||||
|
||||
sortParts(parts, score()->staves());
|
||||
|
||||
setBracketsAndBarlines();
|
||||
|
||||
updateScore();
|
||||
apply();
|
||||
|
||||
m_partChangedNotifier->changed();
|
||||
}
|
||||
|
@ -736,11 +785,13 @@ void NotationParts::moveStaves(const IDList& sourceStavesIds, const ID& destinat
|
|||
int destinationStaffIndex = (mode == InsertMode::Before ? destinationStaff->idx() : destinationStaff->idx() + 1);
|
||||
destinationStaffIndex -= score()->staffIdx(destinationPart); // NOTE: convert to local part's staff index
|
||||
|
||||
startEdit();
|
||||
|
||||
doMoveStaves(staves, destinationStaffIndex, destinationPart);
|
||||
|
||||
setBracketsAndBarlines();
|
||||
|
||||
updateScore();
|
||||
apply();
|
||||
}
|
||||
|
||||
void NotationParts::appendStaves(Part* part, const Instrument& instrument)
|
||||
|
|
|
@ -77,12 +77,10 @@ protected:
|
|||
Ms::Score* score() const;
|
||||
INotationUndoStackPtr undoStack() const;
|
||||
|
||||
virtual void startEdit();
|
||||
virtual void apply();
|
||||
void startEdit();
|
||||
void apply();
|
||||
|
||||
private:
|
||||
void updateScore();
|
||||
|
||||
void updatePartTitles();
|
||||
|
||||
void doMoveStaves(const std::vector<Staff*>& staves, int destinationStaffIndex, Part* destinationPart = nullptr);
|
||||
|
|
Loading…
Reference in a new issue