diff --git a/src/engraving/dom/undo.h b/src/engraving/dom/undo.h index e2ca09bf1924d..7db6f5a602f0c 100644 --- a/src/engraving/dom/undo.h +++ b/src/engraving/dom/undo.h @@ -1505,8 +1505,8 @@ class ChangeDrumset : public UndoCommand void flip(EditData*) override; public: - ChangeDrumset(Instrument* i, const Drumset* d, Part* p) - : instrument(i), drumset(*d), part(p) {} + ChangeDrumset(Instrument* i, const Drumset& d, Part* p) + : instrument(i), drumset(d), part(p) {} UNDO_TYPE(CommandType::ChangeDrumset) UNDO_NAME("ChangeDrumset") diff --git a/src/notation/internal/notationconfiguration.h b/src/notation/internal/notationconfiguration.h index a24da7e3a5687..bcce30892ff6b 100644 --- a/src/notation/internal/notationconfiguration.h +++ b/src/notation/internal/notationconfiguration.h @@ -207,11 +207,11 @@ class NotationConfiguration : public INotationConfiguration, public muse::async: muse::async::Notification autoShowPercussionPanelChanged() const override; bool showPercussionPanelPadSwapDialog() const override; - void setShowPercussionPanelPadSwapDialog(bool show); + void setShowPercussionPanelPadSwapDialog(bool show) override; muse::async::Notification showPercussionPanelPadSwapDialogChanged() const override; bool percussionPanelMoveMidiNotesAndShortcuts() const override; - void setPercussionPanelMoveMidiNotesAndShortcuts(bool move); + void setPercussionPanelMoveMidiNotesAndShortcuts(bool move) override; muse::async::Notification percussionPanelMoveMidiNotesAndShortcutsChanged() const override; muse::io::path_t styleFileImportPath() const override; diff --git a/src/notation/internal/notationparts.cpp b/src/notation/internal/notationparts.cpp index 919d9e86451ef..022212fd9e088 100644 --- a/src/notation/internal/notationparts.cpp +++ b/src/notation/internal/notationparts.cpp @@ -640,7 +640,7 @@ void NotationParts::replaceDrumset(const InstrumentKey& instrumentKey, const Dru if (undoable) { startEdit(TranslatableString("undoableAction", "Edit drumset")); - score()->undo(new mu::engraving::ChangeDrumset(instrument, &newDrumset, part)); + score()->undo(new mu::engraving::ChangeDrumset(instrument, newDrumset, part)); apply(); } else { instrument->setDrumset(&newDrumset); diff --git a/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml b/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml index 446243502b166..3052c00ab85c0 100644 --- a/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml +++ b/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml @@ -415,6 +415,7 @@ Item { orientation: Qt.Horizontal navigation.panel: addRowButtonPanel + drawFocusBorderInsideRect: true onClicked: { padGrid.model.addEmptyRow() @@ -428,9 +429,7 @@ Item { visible: !percModel.enabled - anchors.top: parent.top - anchors.horizontalCenter: parent.horizontalCenter - anchors.topMargin: (padGrid.cellHeight / 2) - (panelDisabledLabel.height / 2) + anchors.centerIn: parent font: ui.theme.bodyFont text: qsTrc("notation/percussion", "Select an unpitched percussion staff to see available sounds") diff --git a/src/notation/view/paintedengravingitem.cpp b/src/notation/view/paintedengravingitem.cpp index 896095e7b0f58..6d0458ec70450 100644 --- a/src/notation/view/paintedengravingitem.cpp +++ b/src/notation/view/paintedengravingitem.cpp @@ -88,7 +88,7 @@ void PaintedEngravingItem::paintNotationPreview(muse::draw::Painter& painter, qr params.drawStaff = true; - painter.fillRect(params.rect, configuration()->scoreInversionColor()); + painter.fillRect(params.rect, configuration()->noteBackgroundColor()); EngravingItemPreviewPainter::paintPreview(m_item.get(), params); } diff --git a/src/notation/view/percussionpanel/percussionpanelmodel.cpp b/src/notation/view/percussionpanel/percussionpanelmodel.cpp index fc4671c2cd206..da697654b4bd2 100644 --- a/src/notation/view/percussionpanel/percussionpanelmodel.cpp +++ b/src/notation/view/percussionpanel/percussionpanelmodel.cpp @@ -21,6 +21,9 @@ */ #include "percussionpanelmodel.h" + +#include "notation/utilities/percussionutilities.h" + #include "types/translatablestring.h" #include "ui/view/iconcodes.h" @@ -158,8 +161,13 @@ void PercussionPanelModel::handleMenuItem(const QString& itemId) } else if (itemId == NOTATION_PREVIEW_CODE) { setUseNotationPreview(true); } else if (itemId == EDIT_LAYOUT_CODE) { - const bool currentlyEditing = m_currentPanelMode == PanelMode::Mode::EDIT_LAYOUT; - currentlyEditing ? finishEditing() : setCurrentPanelMode(PanelMode::Mode::EDIT_LAYOUT); + if (m_currentPanelMode == PanelMode::Mode::EDIT_LAYOUT) { + finishEditing(); + m_padListModel->focusFirstActivePad(); + return; + } + setCurrentPanelMode(PanelMode::Mode::EDIT_LAYOUT); + m_padListModel->padFocusRequested(0); } else if (itemId == RESET_LAYOUT_CODE) { resetLayout(); } @@ -180,13 +188,13 @@ void PercussionPanelModel::finishEditing(bool discardChanges) Instrument* inst = instAndPart.first; Part* part = instAndPart.second; - IF_ASSERT_FAILED(inst && inst->drumset() && part) { + if (discardChanges) { + m_padListModel->setDrumset(inst ? inst->drumset() : nullptr); + setCurrentPanelMode(m_panelModeToRestore); return; } - if (discardChanges) { - m_padListModel->setDrumset(inst->drumset()); - setCurrentPanelMode(m_panelModeToRestore); + IF_ASSERT_FAILED(inst && inst->drumset() && part) { return; } @@ -211,7 +219,7 @@ void PercussionPanelModel::finishEditing(bool discardChanges) } // Return if nothing changed after edit... - if (inst->drumset() && *inst->drumset() == updatedDrumset) { + if (*inst->drumset() == updatedDrumset) { setCurrentPanelMode(m_panelModeToRestore); m_padListModel->focusLastActivePad(); return; @@ -220,7 +228,7 @@ void PercussionPanelModel::finishEditing(bool discardChanges) INotationUndoStackPtr undoStack = notation()->undoStack(); undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Edit percussion panel layout")); - score()->undo(new engraving::ChangeDrumset(inst, &updatedDrumset, part)); + score()->undo(new engraving::ChangeDrumset(inst, updatedDrumset, part)); undoStack->commitChanges(); setCurrentPanelMode(m_panelModeToRestore); @@ -376,7 +384,7 @@ void PercussionPanelModel::onDuplicatePadRequested(int pitch) INotationUndoStackPtr undoStack = notation()->undoStack(); undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Duplicate percussion panel pad")); - score()->undo(new engraving::ChangeDrumset(inst, &updatedDrumset, part)); + score()->undo(new engraving::ChangeDrumset(inst, updatedDrumset, part)); undoStack->commitChanges(); } @@ -396,7 +404,7 @@ void PercussionPanelModel::onDeletePadRequested(int pitch) INotationUndoStackPtr undoStack = notation()->undoStack(); undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Delete percussion panel pad")); - score()->undo(new engraving::ChangeDrumset(inst, &updatedDrumset, part)); + score()->undo(new engraving::ChangeDrumset(inst, updatedDrumset, part)); undoStack->commitChanges(); } @@ -427,26 +435,17 @@ void PercussionPanelModel::writePitch(int pitch) void PercussionPanelModel::playPitch(int pitch) { - const mu::engraving::InputState& inputState = score()->inputState(); - if (!inputState.cr()) { + if (!interaction()) { return; } - Chord* chord = mu::engraving::Factory::createChord(inputState.lastSegment()); - chord->setParent(inputState.lastSegment()); - - Note* note = mu::engraving::Factory::createNote(chord); - note->setParent(chord); - - note->setStaffIdx(mu::engraving::track2staff(inputState.cr()->track())); - - const mu::engraving::NoteVal nval = score()->noteVal(pitch, /*transpose*/ false); - note->setNval(nval); + const NoteInputState inputState = interaction()->noteInput()->state(); + std::shared_ptr chord = PercussionUtilities::getDrumNoteForPreview(m_padListModel->drumset(), pitch); - playbackController()->playElements({ note }); + chord->setParent(inputState.segment); + chord->setTrack(inputState.currentTrack); - note->setParent(nullptr); - delete note; + playbackController()->playElements({ chord.get() }); } void PercussionPanelModel::resetLayout() @@ -479,7 +478,7 @@ void PercussionPanelModel::resetLayout() INotationUndoStackPtr undoStack = notation()->undoStack(); undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Reset percussion panel layout")); - score()->undo(new engraving::ChangeDrumset(inst, &defaultLayout, part)); + score()->undo(new engraving::ChangeDrumset(inst, defaultLayout, part)); undoStack->commitChanges(); } diff --git a/src/notation/view/percussionpanel/percussionpanelpadlistmodel.cpp b/src/notation/view/percussionpanel/percussionpanelpadlistmodel.cpp index e5e15c465c69b..c8f4c23f2dc57 100644 --- a/src/notation/view/percussionpanel/percussionpanelpadlistmodel.cpp +++ b/src/notation/view/percussionpanel/percussionpanelpadlistmodel.cpp @@ -225,6 +225,16 @@ mu::engraving::Drumset PercussionPanelPadListModel::constructDefaultLayout(const return defaultLayout; } +void PercussionPanelPadListModel::focusFirstActivePad() +{ + for (int i = 0; i < m_padModels.size(); i++) { + if (m_padModels.at(i)) { + emit padFocusRequested(i); + return; + } + } +} + void PercussionPanelPadListModel::focusLastActivePad() { for (int i = m_padModels.size() - 1; i >= 0; --i) { diff --git a/src/notation/view/percussionpanel/percussionpanelpadlistmodel.h b/src/notation/view/percussionpanel/percussionpanelpadlistmodel.h index 764041b00bee8..0920dc3b40df2 100644 --- a/src/notation/view/percussionpanel/percussionpanelpadlistmodel.h +++ b/src/notation/view/percussionpanel/percussionpanelpadlistmodel.h @@ -81,6 +81,7 @@ class PercussionPanelPadListModel : public QAbstractListModel, public muse::Inje int nextAvailableIndex(int pitch) const; //! NOTE: This may be equal to m_padModels.size() int nextAvailablePitch(int pitch) const; + void focusFirstActivePad(); void focusLastActivePad(); muse::async::Notification hasActivePadsChanged() const { return m_hasActivePadsChanged; }