Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved interactions for System Locks #25677

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/configs/data/shortcuts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,11 @@
<seq>Ctrl+Return</seq>
<seq>Ctrl+Enter</seq>
</SC>
<SC>
<key>apply-system-lock</key>
<seq>Alt+Return</seq>
<seq>Alt+Enter</seq>
</SC>
<SC>
<key>move-measure-to-prev-system</key>
<seq>Alt+Up</seq>
Expand Down
5 changes: 5 additions & 0 deletions src/app/configs/data/shortcuts_azerty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,11 @@
<seq>Ctrl+Return</seq>
<seq>Ctrl+Enter</seq>
</SC>
<SC>
<key>apply-system-lock</key>
<seq>Alt+Return</seq>
<seq>Alt+Enter</seq>
</SC>
<SC>
<key>move-measure-to-prev-system</key>
<seq>Alt+Up</seq>
Expand Down
5 changes: 5 additions & 0 deletions src/app/configs/data/shortcuts_mac.xml
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,11 @@
<seq>Ctrl+Return</seq>
<seq>Ctrl+Enter</seq>
</SC>
<SC>
<key>apply-system-lock</key>
<seq>Alt+Return</seq>
<seq>Alt+Enter</seq>
</SC>
<SC>
<key>move-measure-to-prev-system</key>
<seq>Alt+Up</seq>
Expand Down
69 changes: 35 additions & 34 deletions src/engraving/dom/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4777,6 +4777,40 @@ void Score::cmdToggleSystemLock()
toggleSystemLock(m_selection.selectedSystems());
}

void Score::cmdApplyLockToSelection()
{
MeasureBase* first = nullptr;
MeasureBase* last = nullptr;

if (selection().isRange()) {
first = selection().startMeasureBase();
last = selection().endMeasureBase();
} else {
for (EngravingItem* el : selection().elements()) {
MeasureBase* mb = el->findMeasureBase();
if (!mb) {
continue;
}
if (!first || mb->isBefore(first)) {
first = mb;
}
if (!last || mb->isAfter(last)) {
last = mb;
}
}
}

if (!first || !last) {
return;
}

if (first != last) {
makeIntoSystem(first, last);
} else {
makeIntoSystem(first->system()->first(), last);
}
}

void Score::cmdToggleScoreLock()
{
bool unlockAll = true;
Expand Down Expand Up @@ -4815,40 +4849,7 @@ void Score::cmdMakeIntoSystem()
return;
}

bool mmrests = style().styleB(Sid::createMultiMeasureRests);

const SystemLock* lockContainingFirstSelected = m_systemLocks.lockContaining(firstSelected);
const SystemLock* lockContainingLastSelected = m_systemLocks.lockContaining(lastSelected);

if (lockContainingFirstSelected) {
undoRemoveSystemLock(lockContainingFirstSelected);
if (lockContainingFirstSelected->startMB()->isBefore(firstSelected)) {
MeasureBase* oneBeforeFirst = mmrests ? firstSelected->prevMM() : firstSelected->prev();
SystemLock* newLockBefore = new SystemLock(lockContainingFirstSelected->startMB(), oneBeforeFirst);
undoAddSystemLock(newLockBefore);
}
}

if (lockContainingLastSelected) {
if (lockContainingLastSelected != lockContainingFirstSelected) {
undoRemoveSystemLock(lockContainingLastSelected);
}
if (lastSelected->isBefore(lockContainingLastSelected->endMB())) {
MeasureBase* oneAfterLast = mmrests ? lastSelected->nextMM() : lastSelected->next();
SystemLock* newLockAfter = new SystemLock(oneAfterLast, lockContainingLastSelected->endMB());
undoAddSystemLock(newLockAfter);
}
}

std::vector<const SystemLock*> locksContainedInRange = m_systemLocks.locksContainedInRange(firstSelected, lastSelected);
for (const SystemLock* lock : locksContainedInRange) {
if (lock != lockContainingFirstSelected && lock != lockContainingLastSelected) {
undoRemoveSystemLock(lock);
}
}

SystemLock* newLock = new SystemLock(firstSelected, lastSelected);
undoAddSystemLock(newLock);
makeIntoSystem(firstSelected, lastSelected);
}

void Score::cmdAddStaffTypeChange(Measure* measure, staff_idx_t staffIdx, StaffTypeChange* stc)
Expand Down
38 changes: 38 additions & 0 deletions src/engraving/dom/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6555,6 +6555,44 @@ void Score::toggleSystemLock(const std::vector<System*>& systems)
}
}

void Score::makeIntoSystem(MeasureBase* first, MeasureBase* last)
{
bool mmrests = style().styleB(Sid::createMultiMeasureRests);

const SystemLock* lockContainingfirst = m_systemLocks.lockContaining(first);
const SystemLock* lockContaininglast = m_systemLocks.lockContaining(last);

if (lockContainingfirst) {
undoRemoveSystemLock(lockContainingfirst);
if (lockContainingfirst->startMB()->isBefore(first)) {
MeasureBase* oneBeforeFirst = mmrests ? first->prevMM() : first->prev();
SystemLock* newLockBefore = new SystemLock(lockContainingfirst->startMB(), oneBeforeFirst);
undoAddSystemLock(newLockBefore);
}
}

if (lockContaininglast) {
if (lockContaininglast != lockContainingfirst) {
undoRemoveSystemLock(lockContaininglast);
}
if (last->isBefore(lockContaininglast->endMB())) {
MeasureBase* oneAfterLast = mmrests ? last->nextMM() : last->next();
SystemLock* newLockAfter = new SystemLock(oneAfterLast, lockContaininglast->endMB());
undoAddSystemLock(newLockAfter);
}
}

std::vector<const SystemLock*> locksContainedInRange = m_systemLocks.locksContainedInRange(first, last);
for (const SystemLock* lock : locksContainedInRange) {
if (lock != lockContainingfirst && lock != lockContaininglast) {
undoRemoveSystemLock(lock);
}
}

SystemLock* newLock = new SystemLock(first, last);
undoAddSystemLock(newLock);
}

void Score::removeSystemLocksOnAddLayoutBreak(LayoutBreakType breakType, const MeasureBase* measure)
{
IF_ASSERT_FAILED(breakType != LayoutBreakType::NOBREAK) {
Expand Down
5 changes: 2 additions & 3 deletions src/engraving/dom/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1383,8 +1383,7 @@ bool Measure::acceptDrop(EditData& data) const
{
LayoutMode layoutMode = score()->layoutMode();
if (layoutMode == LayoutMode::PAGE || layoutMode == LayoutMode::SYSTEM) {
const System* sys = system();
viewer->setDropRectangle(sys->canvasBoundingRect().adjusted(sys->leftMargin(), 0.0, 0.0, 0.0));
viewer->setDropRectangle(canvasBoundingRect().adjusted(-x(), 0.0, 0.0, 0.0));
return true;
}
return false;
Expand Down Expand Up @@ -1726,7 +1725,7 @@ EngravingItem* Measure::drop(EditData& data)
break;
}
case ActionIconType::SYSTEM_LOCK:
score()->toggleSystemLock({ system() });
score()->makeIntoSystem(system()->first(), this);
break;
default:
break;
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ class Score : public EngravingObject, public muse::Injectable
void cmdMoveMeasureToPrevSystem();
void cmdMoveMeasureToNextSystem();
void cmdToggleSystemLock();
void cmdApplyLockToSelection();
void cmdToggleScoreLock();
void cmdMakeIntoSystem();
void cmdAddStaffTypeChange(Measure* measure, staff_idx_t staffIdx, StaffTypeChange* stc);
Expand Down Expand Up @@ -1018,6 +1019,7 @@ class Score : public EngravingObject, public muse::Injectable
void undoRemoveSystemLock(const SystemLock* lock);
void undoRemoveAllLocks();
void toggleSystemLock(const std::vector<System*>& systems);
void makeIntoSystem(MeasureBase* first, MeasureBase* last);
void removeSystemLocksOnAddLayoutBreak(LayoutBreakType breakType, const MeasureBase* measure);
void removeLayoutBreaksOnAddSystemLock(const SystemLock* lock);

Expand Down
1 change: 1 addition & 0 deletions src/notation/inotationinteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class INotationInteraction
virtual void toggleSystemLock() = 0;
virtual void toggleScoreLock() = 0;
virtual void makeIntoSystem() = 0;
virtual void applySystemLock() = 0;

virtual void addRemoveSystemLocks(AddRemoveSystemLockType intervalType, int interval = 0) = 0;
virtual bool transpose(const TransposeOptions& options) = 0;
Expand Down
1 change: 1 addition & 0 deletions src/notation/internal/notationactioncontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void NotationActionController::init()
registerAction("section-break", &Interaction::toggleLayoutBreak, LayoutBreakType::SECTION, PlayMode::NoPlay,
&Controller::toggleLayoutBreakAvailable);

registerAction("apply-system-lock", &Interaction::applySystemLock);
registerAction("move-measure-to-prev-system", &Interaction::moveMeasureToPrevSystem);
registerAction("move-measure-to-next-system", &Interaction::moveMeasureToNextSystem);
registerAction("toggle-system-lock", &Interaction::toggleSystemLock);
Expand Down
13 changes: 9 additions & 4 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ bool NotationInteraction::applyPaletteElement(mu::engraving::EngravingItem* elem
mu::engraving::LayoutBreak* breakElement = toLayoutBreak(element);
score->cmdToggleLayoutBreak(breakElement->layoutBreakType());
} else if (element->isActionIcon() && toActionIcon(element)->actionType() == ActionIconType::SYSTEM_LOCK) {
score->cmdToggleSystemLock();
score->cmdApplyLockToSelection();
} else if (element->isSlur() && addSingle) {
doAddSlur(toSlur(element));
} else if (element->isSLine() && !element->isGlissando() && !element->isGuitarBend() && addSingle) {
Expand Down Expand Up @@ -2022,9 +2022,7 @@ bool NotationInteraction::applyPaletteElement(mu::engraving::EngravingItem* elem
}
}
} else if (element->isActionIcon() && toActionIcon(element)->actionType() == ActionIconType::SYSTEM_LOCK) {
if (sel.isRange()) {
score->toggleSystemLock(sel.selectedSystems());
}
score->cmdApplyLockToSelection();
} else {
track_idx_t track1 = sel.staffStart() * mu::engraving::VOICES;
track_idx_t track2 = sel.staffEnd() * mu::engraving::VOICES;
Expand Down Expand Up @@ -4529,6 +4527,13 @@ void NotationInteraction::makeIntoSystem()
apply();
}

void NotationInteraction::applySystemLock()
{
startEdit(TranslatableString("undoableAction", "Apply system lock to selection"));
score()->cmdApplyLockToSelection();
apply();
}

void NotationInteraction::addRemoveSystemLocks(AddRemoveSystemLockType intervalType, int interval)
{
interval = intervalType == AddRemoveSystemLockType::MeasuresInterval ? interval : 0;
Expand Down
1 change: 1 addition & 0 deletions src/notation/internal/notationinteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class NotationInteraction : public INotationInteraction, public muse::Injectable
void toggleSystemLock() override;
void toggleScoreLock() override;
void makeIntoSystem() override;
void applySystemLock() override;

void addRemoveSystemLocks(AddRemoveSystemLockType intervalType, int interval = 0) override;
bool transpose(const TransposeOptions& options) override;
Expand Down
6 changes: 6 additions & 0 deletions src/notation/internal/notationuiactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,12 @@ const UiActionList NotationUiActions::m_actions = {
TranslatableString("action", "Add/remove page break"),
TranslatableString("action", "Add/remove page break")
),
UiAction("apply-system-lock",
mu::context::UiCtxProjectOpened,
mu::context::CTX_NOTATION_FOCUSED,
TranslatableString("action", "Add/remove system lock"),
TranslatableString("action", "Add/remove system lock")
),
UiAction("move-measure-to-prev-system",
mu::context::UiCtxProjectOpened,
mu::context::CTX_NOTATION_FOCUSED,
Expand Down
1 change: 1 addition & 0 deletions src/notation/tests/mocks/notationinteractionmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class NotationInteractionMock : public INotationInteraction
MOCK_METHOD(void, toggleSystemLock, (), (override));
MOCK_METHOD(void, toggleScoreLock, (), (override));
MOCK_METHOD(void, makeIntoSystem, (), (override));
MOCK_METHOD(void, applySystemLock, (), (override));

MOCK_METHOD(void, addRemoveSystemLocks, (AddRemoveSystemLockType, int), (override));
MOCK_METHOD(bool, transpose, (const TransposeOptions&), (override));
Expand Down