From e88e5efb125d1c1f4c62bf4ed80abc343ee2405f Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Mon, 27 Jan 2025 10:35:40 +0000 Subject: [PATCH] Evaluate/dispatch percussion shortcuts in NotationViewInputController::shortcutOverrideEvent --- src/engraving/dom/drumset.cpp | 21 +++++++++++++ src/engraving/dom/drumset.h | 2 ++ .../view/notationviewinputcontroller.cpp | 31 ++++++++++++++++--- .../view/notationviewinputcontroller.h | 2 ++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/engraving/dom/drumset.cpp b/src/engraving/dom/drumset.cpp index 29571d9a1b295..95b12d4665aca 100644 --- a/src/engraving/dom/drumset.cpp +++ b/src/engraving/dom/drumset.cpp @@ -45,6 +45,27 @@ String Drumset::translatedName(int pitch) const return muse::mtrc("engraving/drumset", name(pitch)); } +int Drumset::pitchForShortcut(const String& shortcut) const +{ + if (shortcut.isEmpty()) { + return -1; + } + + for (int pitch = 0; pitch < DRUM_INSTRUMENTS; ++pitch) { + if (!isValid(pitch)) { + continue; + } + + if (drum(pitch).shortcut != shortcut) { + continue; + } + + return pitch; + } + + return -1; +} + //--------------------------------------------------------- // save //--------------------------------------------------------- diff --git a/src/engraving/dom/drumset.h b/src/engraving/dom/drumset.h index 7e808610bab80..16528b89eab81 100644 --- a/src/engraving/dom/drumset.h +++ b/src/engraving/dom/drumset.h @@ -115,6 +115,8 @@ class Drumset int panelRow(int pitch) const { return m_drums[pitch].panelRow; } int panelColumn(int pitch) const { return m_drums[pitch].panelColumn; } + int pitchForShortcut(const String& shortcut) const; + void save(XmlWriter&) const; void load(XmlReader&); bool readProperties(XmlReader&, int); diff --git a/src/notation/view/notationviewinputcontroller.cpp b/src/notation/view/notationviewinputcontroller.cpp index 0184ff96a0cc3..67ba6b8657350 100644 --- a/src/notation/view/notationviewinputcontroller.cpp +++ b/src/notation/view/notationviewinputcontroller.cpp @@ -31,6 +31,8 @@ #include "commonscene/commonscenetypes.h" #include "abstractelementpopupmodel.h" +#include "engraving/dom/drumset.h" + using namespace mu; using namespace mu::notation; using namespace mu::engraving; @@ -797,6 +799,24 @@ void NotationViewInputController::updateTextCursorPosition() } } +bool NotationViewInputController::tryPercussionShortcut(QKeyEvent* event) +{ + INotationNoteInputPtr noteInput = viewInteraction()->noteInput(); + const mu::engraving::Drumset* drumset = noteInput ? noteInput->state().drumset : nullptr; + if (!drumset || event->modifiers() != Qt::NoModifier) { + return false; + } + + const QKeySequence seq(event->keyCombination()); + const int pitchToWrite = drumset->pitchForShortcut(seq.toString()); + if (pitchToWrite > -1) { + // TODO: Dispatch a note input action using this pitch + return true; + } + + return false; +} + void NotationViewInputController::mouseMoveEvent(QMouseEvent* event) { if (viewInteraction()->isDragCopyStarted()) { @@ -1018,13 +1038,14 @@ bool NotationViewInputController::shortcutOverrideEvent(QKeyEvent* event) { if (viewInteraction()->isElementEditStarted()) { return viewInteraction()->isEditAllowed(event); - } else if (startTextEditingAllowed()) { - if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { - return true; - } } - return false; + const bool editTextKeysFound = event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter; + if (editTextKeysFound && startTextEditingAllowed()) { + return true; + } + + return tryPercussionShortcut(event); } void NotationViewInputController::keyPressEvent(QKeyEvent* event) diff --git a/src/notation/view/notationviewinputcontroller.h b/src/notation/view/notationviewinputcontroller.h index 52da43d25d3d4..5b81eb73700ee 100644 --- a/src/notation/view/notationviewinputcontroller.h +++ b/src/notation/view/notationviewinputcontroller.h @@ -184,6 +184,8 @@ class NotationViewInputController : public muse::actions::Actionable, public mus bool startTextEditingAllowed() const; void updateTextCursorPosition(); + bool tryPercussionShortcut(QKeyEvent* event); + EngravingItem* resolveStartPlayableElement() const; IControlledView* m_view = nullptr;