From d8275a33615664625d252a7c662bcbc2aadbc50e Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Fri, 6 Dec 2024 08:24:06 +0000 Subject: [PATCH 1/8] Percussion panel - fix pads disappearing during edit (typo) --- src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml b/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml index 0bbef2cd29777..3c78352cbd5b6 100644 --- a/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml +++ b/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml @@ -301,7 +301,7 @@ Item { // If this is the swap target - move the swappable area to the swap origin (preview the swap) State { name: "SWAP_TARGET" - when: Boolean(padGrid.swapOriginPad) && (pad.containsDrag || pad.padNavigationCtrl.active) && padGrid.swapOriginPad !== pad + when: Boolean(padGrid.swapOriginPad) && (pad.containsDrag || pad.padNavigation.active) && padGrid.swapOriginPad !== pad ParentChange { target: pad.swappableArea From 5719d0256b637cc11b269b10810af06f4ca1c8d6 Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Tue, 10 Dec 2024 08:51:19 +0000 Subject: [PATCH 2/8] Percussion panel - address to-dos from initial notation preview PR --- .../internal/PercussionPanelPadContent.qml | 1 + src/notation/view/paintedengravingitem.cpp | 21 ++++++++++++++++--- src/notation/view/paintedengravingitem.h | 11 +++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml b/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml index 2547a8987e73a..7003ffdc7bf01 100644 --- a/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml +++ b/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml @@ -82,6 +82,7 @@ Column { anchors.fill: parent engravingItem: Boolean(root.padModel) ? root.padModel.notationPreviewItem : null + spatium: 6.25 // Value approximated visually (needs to accomodate "extreme ledger line" situations) } states: [ diff --git a/src/notation/view/paintedengravingitem.cpp b/src/notation/view/paintedengravingitem.cpp index 62697b0d4d423..896095e7b0f58 100644 --- a/src/notation/view/paintedengravingitem.cpp +++ b/src/notation/view/paintedengravingitem.cpp @@ -43,6 +43,21 @@ void PaintedEngravingItem::setEngravingItemVariant(QVariant engravingItemVariant return; } m_item = item; + emit engravingItemVariantChanged(); +} + +double PaintedEngravingItem::spatium() const +{ + return m_spatium; +} + +void PaintedEngravingItem::setSpatium(double spatium) +{ + if (spatium == m_spatium) { + return; + } + m_spatium = spatium; + emit spatiumChanged(); } void PaintedEngravingItem::paint(QPainter* painter) @@ -64,16 +79,16 @@ void PaintedEngravingItem::paintNotationPreview(muse::draw::Painter& painter, qr EngravingItemPreviewPainter::PaintParams params; params.painter = &painter; - params.color = muse::draw::Color::BLACK; // TODO: set this properly + params.color = configuration()->defaultColor(); params.rect = muse::RectF(0, 0, parentItem()->width(), parentItem()->height()); params.dpi = dpi; - params.spatium = configuration()->paletteSpatium(); // TODO: don't use the palette for this + params.spatium = m_spatium; params.drawStaff = true; - painter.fillRect(params.rect, muse::draw::Color::WHITE); // TODO: set this properly + painter.fillRect(params.rect, configuration()->scoreInversionColor()); EngravingItemPreviewPainter::paintPreview(m_item.get(), params); } diff --git a/src/notation/view/paintedengravingitem.h b/src/notation/view/paintedengravingitem.h index 7896f6e740eff..bc33cb06aa343 100644 --- a/src/notation/view/paintedengravingitem.h +++ b/src/notation/view/paintedengravingitem.h @@ -25,7 +25,7 @@ #include #include "modularity/ioc.h" -#include "palette/ipaletteconfiguration.h" +#include "engraving/iengravingconfiguration.h" #include "engraving/dom/engravingitem.h" @@ -34,12 +34,12 @@ namespace mu::notation { class PaintedEngravingItem : public QQuickPaintedItem { - // TODO: don't use the palette for this - INJECT_STATIC(palette::IPaletteConfiguration, configuration) + INJECT_STATIC(engraving::IEngravingConfiguration, configuration) Q_OBJECT Q_PROPERTY(QVariant engravingItem READ engravingItemVariant WRITE setEngravingItemVariant NOTIFY engravingItemVariantChanged) + Q_PROPERTY(double spatium READ spatium WRITE setSpatium NOTIFY spatiumChanged) public: explicit PaintedEngravingItem(QQuickItem* parent = nullptr); @@ -47,14 +47,19 @@ class PaintedEngravingItem : public QQuickPaintedItem QVariant engravingItemVariant() const; void setEngravingItemVariant(QVariant engravingItemVariant); + double spatium() const; + void setSpatium(double spatium); + void paint(QPainter* painter) override; signals: void engravingItemVariantChanged(); + void spatiumChanged(); private: void paintNotationPreview(muse::draw::Painter& painter, qreal dpi) const; mu::engraving::ElementPtr m_item; + double m_spatium = 1.0; }; } From b86c75bce1f559be09794d078e43bcd26adf93c2 Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Wed, 4 Dec 2024 23:13:19 +0000 Subject: [PATCH 3/8] Percussion panel - implement notation preview tooltip & hover/hit states --- .../internal/PercussionPanelPadContent.qml | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml b/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml index 7003ffdc7bf01..66f21e893df3b 100644 --- a/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml +++ b/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml @@ -37,14 +37,12 @@ Column { property bool padSwapActive: false - Rectangle { + Item { id: mainContentArea width: parent.width height: parent.height - separator.height - footerArea.height - color: Utils.colorWithAlpha(ui.theme.accentColor, ui.theme.buttonOpacityNormal) - MouseArea { id: mouseArea @@ -52,11 +50,36 @@ Column { hoverEnabled: true onPressed: { + ui.tooltip.hide(root) + if (!Boolean(root.padModel)) { return } + root.padModel.triggerPad() } + + onContainsMouseChanged: { + if (!Boolean(root.padModel)) { + ui.tooltip.hide(root) + return + } + + if (mouseArea.containsMouse && root.useNotationPreview) { + ui.tooltip.show(root, root.padModel.instrumentName) + } else { + ui.tooltip.hide(root) + } + } + } + + Rectangle { + id: instrumentNameBackground + + visible: !root.useNotationPreview + anchors.fill: parent + + color: Utils.colorWithAlpha(ui.theme.accentColor, ui.theme.buttonOpacityNormal) } StyledTextLabel { @@ -83,6 +106,8 @@ Column { engravingItem: Boolean(root.padModel) ? root.padModel.notationPreviewItem : null spatium: 6.25 // Value approximated visually (needs to accomodate "extreme ledger line" situations) + + opacity: 0.9 } states: [ @@ -90,17 +115,25 @@ Column { name: "MOUSE_HOVERED" when: mouseArea.containsMouse && !mouseArea.pressed && !root.padSwapActive PropertyChanges { - target: mainContentArea + target: instrumentNameBackground color: Utils.colorWithAlpha(ui.theme.accentColor, ui.theme.buttonOpacityHover) } + PropertyChanges { + target: notationPreview + opacity: 0.7 + } }, State { name: "MOUSE_HIT" when: mouseArea.pressed || root.padSwapActive PropertyChanges { - target: mainContentArea + target: instrumentNameBackground color: Utils.colorWithAlpha(ui.theme.accentColor, ui.theme.buttonOpacityHit) } + PropertyChanges { + target: notationPreview + opacity: 1.0 + } } ] } From 3bcc2cadc1b045f6daeb72399a67105b31495910 Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Tue, 10 Dec 2024 09:14:49 +0000 Subject: [PATCH 4/8] Percussion panel - implement layout reset function --- .../percussionpanel/percussionpanelmodel.cpp | 57 +++++++++++++++++-- .../percussionpanel/percussionpanelmodel.h | 8 ++- .../percussionpanelpadlistmodel.cpp | 46 +++++++++++++++ .../percussionpanelpadlistmodel.h | 2 + 4 files changed, 107 insertions(+), 6 deletions(-) diff --git a/src/notation/view/percussionpanel/percussionpanelmodel.cpp b/src/notation/view/percussionpanel/percussionpanelmodel.cpp index b0a8d0188aebc..10a0f545e23e6 100644 --- a/src/notation/view/percussionpanel/percussionpanelmodel.cpp +++ b/src/notation/view/percussionpanel/percussionpanelmodel.cpp @@ -161,12 +161,11 @@ void PercussionPanelModel::handleMenuItem(const QString& itemId) const bool currentlyEditing = m_currentPanelMode == PanelMode::Mode::EDIT_LAYOUT; currentlyEditing ? finishEditing() : setCurrentPanelMode(PanelMode::Mode::EDIT_LAYOUT, false); } else if (itemId == RESET_LAYOUT_CODE) { - // TODO: Need a mechanism for "default" layouts... - // m_padListModel->resetLayout(); + resetLayout(); } } -void PercussionPanelModel::finishEditing() +void PercussionPanelModel::finishEditing(bool discardChanges) { Drumset* updatedDrumset = m_padListModel->drumset(); m_padListModel->removeEmptyRows(); @@ -180,7 +179,13 @@ void PercussionPanelModel::finishEditing() Instrument* inst = staff->part()->instrument(inputState.segment->tick()); - IF_ASSERT_FAILED(inst) { + IF_ASSERT_FAILED(inst && inst->drumset()) { + return; + } + + if (discardChanges) { + m_padListModel->setDrumset(inst->drumset()); + setCurrentPanelMode(m_panelModeToRestore, false); return; } @@ -227,7 +232,7 @@ void PercussionPanelModel::setUpConnections() } if (m_currentPanelMode == PanelMode::Mode::EDIT_LAYOUT) { - finishEditing(); + finishEditing(/*discardChanges*/ true); } m_padListModel->setDrumset(drumset); @@ -311,6 +316,48 @@ void PercussionPanelModel::playPitch(int pitch) delete note; } +void PercussionPanelModel::resetLayout() +{ + if (m_currentPanelMode == PanelMode::Mode::EDIT_LAYOUT) { + finishEditing(/*discardChanges*/ true); + } + + NoteInputState inputState = interaction()->noteInput()->state(); + const Staff* staff = inputState.staff; + + IF_ASSERT_FAILED(staff && staff->part()) { + return; + } + + Instrument* inst = staff->part()->instrument(inputState.segment->tick()); + + IF_ASSERT_FAILED(inst) { + return; + } + + const InstrumentTemplate& instTemplate = instrumentsRepository()->instrumentTemplate(inst->id()); + const Drumset* defaultDrumset = instTemplate.drumset; + + IF_ASSERT_FAILED(defaultDrumset) { + return; + } + + Drumset defaultLayout = m_padListModel->constructDefaultLayout(defaultDrumset); + if (defaultLayout == *m_padListModel->drumset()) { + // Nothing changed after reset... + return; + } + + INotationUndoStackPtr undoStack = notation()->undoStack(); + + DEFER { + undoStack->commitChanges(); + }; + + undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Reset percussion panel layout")); + score()->undo(new engraving::ChangeDrumset(inst, &defaultLayout, staff->part())); +} + const INotationPtr PercussionPanelModel::notation() const { return globalContext()->currentNotation(); diff --git a/src/notation/view/percussionpanel/percussionpanelmodel.h b/src/notation/view/percussionpanel/percussionpanelmodel.h index 516add5ab6635..fd4b52b77d3c9 100644 --- a/src/notation/view/percussionpanel/percussionpanelmodel.h +++ b/src/notation/view/percussionpanel/percussionpanelmodel.h @@ -30,6 +30,7 @@ #include "context/iglobalcontext.h" #include "actions/iactionsdispatcher.h" #include "playback/iplaybackcontroller.h" +#include "iinstrumentsrepository.h" #include "percussionpanelpadlistmodel.h" @@ -52,6 +53,7 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus muse::Inject globalContext = { this }; muse::Inject dispatcher = { this }; muse::Inject playbackController = { this }; + muse::Inject instrumentsRepository = { this }; Q_OBJECT @@ -83,7 +85,9 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus QList layoutMenuItems() const; Q_INVOKABLE void handleMenuItem(const QString& itemId); - Q_INVOKABLE void finishEditing(); + //! NOTE: There are a handful of circumstances where we should discard changes (e.g. undoing/redoing a layout change mid + //! edit, resetting the layout mid edit, or selecting a different drumset mid edit) + Q_INVOKABLE void finishEditing(bool discardChanges = false); Q_INVOKABLE void customizeKit(); @@ -101,6 +105,8 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus void writePitch(int pitch); void playPitch(int pitch); + void resetLayout(); + const mu::notation::INotationPtr notation() const; const mu::notation::INotationInteractionPtr interaction() const; diff --git a/src/notation/view/percussionpanel/percussionpanelpadlistmodel.cpp b/src/notation/view/percussionpanel/percussionpanelpadlistmodel.cpp index e64c1d2a4a569..62c6cf3fb9950 100644 --- a/src/notation/view/percussionpanel/percussionpanelpadlistmodel.cpp +++ b/src/notation/view/percussionpanel/percussionpanelpadlistmodel.cpp @@ -136,6 +136,52 @@ void PercussionPanelPadListModel::setDrumset(const engraving::Drumset* drumset) removeEmptyRows(); } +mu::engraving::Drumset PercussionPanelPadListModel::constructDefaultLayout(const engraving::Drumset* defaultDrumset) const +{ + //! NOTE: The idea of this method is take a "default" (template) drumset, find matching drums in the current drumset, and evaluate/return + //! the default panel layout based on this information. The reason we can't simply revert to the default drumset in its entirety is that + //! there's no guarantee that all drums will match (the user may have added some of their own drums, removed some, tweaked some, etc). Any + //! drums that aren't accounted for in the default drumset are appended chromatically once the rest of the layout has been decided... + + mu::engraving::Drumset defaultLayout = *m_drumset; + + int highestIndex = -1; + QList noTemplateFound; + + for (int pitch = 0; pitch < mu::engraving::DRUM_INSTRUMENTS; ++pitch) { + if (!defaultLayout.isValid(pitch)) { + // We aren't currently using this pitch, doesn't matter if it's valid in the template.. + continue; + } + //! NOTE: Pitch + drum name isn't exactly the most robust identifier, but this will probably change with the new percussion ID system + if (!defaultDrumset->isValid(pitch) || defaultLayout.name(pitch) != defaultDrumset->name(pitch)) { + // Drum is valid, but we can't find a template for it. Set the position chromatically later... + noTemplateFound.emplaceBack(pitch); + continue; + } + + const int templateRow = defaultDrumset->drum(pitch).panelRow; + const int templateColumn = defaultDrumset->drum(pitch).panelColumn; + + defaultLayout.drum(pitch).panelRow = templateRow; + defaultLayout.drum(pitch).panelColumn = templateColumn; + + const int modelIndex = templateRow * NUM_COLUMNS + templateColumn; + + if (modelIndex > highestIndex) { + highestIndex = modelIndex; + } + } + + for (int pitch : noTemplateFound) { + ++highestIndex; + defaultLayout.drum(pitch).panelRow = highestIndex / NUM_COLUMNS; + defaultLayout.drum(pitch).panelColumn = highestIndex % NUM_COLUMNS; + } + + return defaultLayout; +} + void PercussionPanelPadListModel::load() { beginResetModel(); diff --git a/src/notation/view/percussionpanel/percussionpanelpadlistmodel.h b/src/notation/view/percussionpanel/percussionpanelpadlistmodel.h index df4fb975c18af..ded78c397c204 100644 --- a/src/notation/view/percussionpanel/percussionpanelpadlistmodel.h +++ b/src/notation/view/percussionpanel/percussionpanelpadlistmodel.h @@ -69,6 +69,8 @@ class PercussionPanelPadListModel : public QAbstractListModel, public muse::asyn QList padList() const { return m_padModels; } + mu::engraving::Drumset constructDefaultLayout(const engraving::Drumset* templateDrumset) const; + muse::async::Notification hasActivePadsChanged() const { return m_hasActivePadsChanged; } muse::async::Channel padTriggered() const { return m_triggeredChannel; } From a1a0c6cf392197272723c1f87d800941c14050be Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Fri, 6 Dec 2024 08:35:03 +0000 Subject: [PATCH 5/8] Percussion panel - don't enter/exit note input when switching panel modes --- .../view/percussionpanel/percussionpanelmodel.cpp | 15 ++++----------- .../view/percussionpanel/percussionpanelmodel.h | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/notation/view/percussionpanel/percussionpanelmodel.cpp b/src/notation/view/percussionpanel/percussionpanelmodel.cpp index 10a0f545e23e6..b1683655cdad6 100644 --- a/src/notation/view/percussionpanel/percussionpanelmodel.cpp +++ b/src/notation/view/percussionpanel/percussionpanelmodel.cpp @@ -63,7 +63,7 @@ PanelMode::Mode PercussionPanelModel::currentPanelMode() const return m_currentPanelMode; } -void PercussionPanelModel::setCurrentPanelMode(const PanelMode::Mode& panelMode, bool updateNoteInput) +void PercussionPanelModel::setCurrentPanelMode(const PanelMode::Mode& panelMode) { if (m_currentPanelMode == panelMode) { return; @@ -76,13 +76,6 @@ void PercussionPanelModel::setCurrentPanelMode(const PanelMode::Mode& panelMode, m_currentPanelMode = panelMode; emit currentPanelModeChanged(m_currentPanelMode); - - if (!updateNoteInput || !interaction() || !interaction()->noteInput()) { - return; - } - - const INotationNoteInputPtr noteInput = interaction()->noteInput(); - panelMode == PanelMode::Mode::WRITE ? noteInput->startNoteInput() : noteInput->endNoteInput(); } bool PercussionPanelModel::useNotationPreview() const @@ -159,7 +152,7 @@ void PercussionPanelModel::handleMenuItem(const QString& itemId) setUseNotationPreview(true); } else if (itemId == EDIT_LAYOUT_CODE) { const bool currentlyEditing = m_currentPanelMode == PanelMode::Mode::EDIT_LAYOUT; - currentlyEditing ? finishEditing() : setCurrentPanelMode(PanelMode::Mode::EDIT_LAYOUT, false); + currentlyEditing ? finishEditing() : setCurrentPanelMode(PanelMode::Mode::EDIT_LAYOUT); } else if (itemId == RESET_LAYOUT_CODE) { resetLayout(); } @@ -185,7 +178,7 @@ void PercussionPanelModel::finishEditing(bool discardChanges) if (discardChanges) { m_padListModel->setDrumset(inst->drumset()); - setCurrentPanelMode(m_panelModeToRestore, false); + setCurrentPanelMode(m_panelModeToRestore); return; } @@ -216,7 +209,7 @@ void PercussionPanelModel::finishEditing(bool discardChanges) undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Edit percussion panel layout")); score()->undo(new engraving::ChangeDrumset(inst, updatedDrumset, staff->part())); - setCurrentPanelMode(m_panelModeToRestore, false); + setCurrentPanelMode(m_panelModeToRestore); } void PercussionPanelModel::customizeKit() diff --git a/src/notation/view/percussionpanel/percussionpanelmodel.h b/src/notation/view/percussionpanel/percussionpanelmodel.h index fd4b52b77d3c9..ddc0d243083ed 100644 --- a/src/notation/view/percussionpanel/percussionpanelmodel.h +++ b/src/notation/view/percussionpanel/percussionpanelmodel.h @@ -73,7 +73,7 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus void setEnabled(bool enabled); PanelMode::Mode currentPanelMode() const; - void setCurrentPanelMode(const PanelMode::Mode& panelMode, bool updateNoteInput = true); + void setCurrentPanelMode(const PanelMode::Mode& panelMode); bool useNotationPreview() const; void setUseNotationPreview(bool useNotationPreview); From e48785af23fb708afbd811ab51699bfdc9d64278 Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Mon, 9 Dec 2024 10:31:52 +0000 Subject: [PATCH 6/8] Percussion panel - prevent crash when closing project while editing layout --- src/notation/view/percussionpanel/percussionpanelmodel.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/notation/view/percussionpanel/percussionpanelmodel.cpp b/src/notation/view/percussionpanel/percussionpanelmodel.cpp index b1683655cdad6..3a7e117f64855 100644 --- a/src/notation/view/percussionpanel/percussionpanelmodel.cpp +++ b/src/notation/view/percussionpanel/percussionpanelmodel.cpp @@ -160,6 +160,13 @@ void PercussionPanelModel::handleMenuItem(const QString& itemId) void PercussionPanelModel::finishEditing(bool discardChanges) { + if (!interaction()) { + //! NOTE: Can happen if we close the project while editing the layout... + m_padListModel->setDrumset(nullptr); + setCurrentPanelMode(m_panelModeToRestore); + return; + } + Drumset* updatedDrumset = m_padListModel->drumset(); m_padListModel->removeEmptyRows(); From c821e92f753bbd54733cffc9adbe487c41ccfdf3 Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Tue, 10 Dec 2024 09:32:27 +0000 Subject: [PATCH 7/8] Percussion panel - fix logic error when finishing editing --- src/engraving/dom/drumset.h | 2 +- .../view/percussionpanel/percussionpanelmodel.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/engraving/dom/drumset.h b/src/engraving/dom/drumset.h index fde9702a8fab6..4a6a2824bc030 100644 --- a/src/engraving/dom/drumset.h +++ b/src/engraving/dom/drumset.h @@ -54,7 +54,7 @@ struct DrumInstrument { // if notehead = HEAD_CUSTOM, custom, use noteheads NoteHeadGroup notehead = NoteHeadGroup::HEAD_INVALID; ///< notehead symbol set - SymId noteheads[int(NoteHeadType::HEAD_TYPES)] + std::array noteheads = { SymId::noteheadWhole, SymId::noteheadHalf, SymId::noteheadBlack, SymId::noteheadDoubleWhole }; int line = 0; ///< place notehead onto this line diff --git a/src/notation/view/percussionpanel/percussionpanelmodel.cpp b/src/notation/view/percussionpanel/percussionpanelmodel.cpp index 3a7e117f64855..eb6ade0182339 100644 --- a/src/notation/view/percussionpanel/percussionpanelmodel.cpp +++ b/src/notation/view/percussionpanel/percussionpanelmodel.cpp @@ -189,12 +189,6 @@ void PercussionPanelModel::finishEditing(bool discardChanges) return; } - // Return if nothing changed after edit... - if (inst->drumset() && updatedDrumset - && *inst->drumset() == *updatedDrumset) { - return; - } - for (int i = 0; i < m_padListModel->padList().size(); ++i) { const PercussionPanelPadModel* model = m_padListModel->padList().at(i); if (!model) { @@ -207,6 +201,13 @@ void PercussionPanelModel::finishEditing(bool discardChanges) drum.panelColumn = column; } + // Return if nothing changed after edit... + if (inst->drumset() && updatedDrumset + && *inst->drumset() == *updatedDrumset) { + setCurrentPanelMode(m_panelModeToRestore); + return; + } + INotationUndoStackPtr undoStack = notation()->undoStack(); DEFER { From f417fc8a23863067e73c41fda29ec83ce5cb661f Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Tue, 10 Dec 2024 10:07:54 +0000 Subject: [PATCH 8/8] Percussion panel - remove redundant DEFERs from PercussionPanelModel --- .../percussionpanel/percussionpanelmodel.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/notation/view/percussionpanel/percussionpanelmodel.cpp b/src/notation/view/percussionpanel/percussionpanelmodel.cpp index eb6ade0182339..f2741aaa57eb1 100644 --- a/src/notation/view/percussionpanel/percussionpanelmodel.cpp +++ b/src/notation/view/percussionpanel/percussionpanelmodel.cpp @@ -27,8 +27,6 @@ #include "engraving/dom/factory.h" #include "engraving/dom/undo.h" -#include "defer.h" - static const QString INSTRUMENT_NAMES_CODE("percussion-instrument-names"); static const QString NOTATION_PREVIEW_CODE("percussion-notation-preview"); static const QString EDIT_LAYOUT_CODE("percussion-edit-layout"); @@ -210,12 +208,9 @@ void PercussionPanelModel::finishEditing(bool discardChanges) INotationUndoStackPtr undoStack = notation()->undoStack(); - DEFER { - undoStack->commitChanges(); - }; - undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Edit percussion panel layout")); score()->undo(new engraving::ChangeDrumset(inst, updatedDrumset, staff->part())); + undoStack->commitChanges(); setCurrentPanelMode(m_panelModeToRestore); } @@ -277,15 +272,12 @@ void PercussionPanelModel::writePitch(int pitch) return; } - DEFER { - undoStack->commitChanges(); - }; - undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Enter percussion note")); interaction()->noteInput()->startNoteInput(); score()->addMidiPitch(pitch, false, /*transpose*/ false); + undoStack->commitChanges(); const mu::engraving::InputState& inputState = score()->inputState(); if (inputState.cr()) { @@ -351,12 +343,9 @@ void PercussionPanelModel::resetLayout() INotationUndoStackPtr undoStack = notation()->undoStack(); - DEFER { - undoStack->commitChanges(); - }; - undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Reset percussion panel layout")); score()->undo(new engraving::ChangeDrumset(inst, &defaultLayout, staff->part())); + undoStack->commitChanges(); } const INotationPtr PercussionPanelModel::notation() const