Skip to content

Commit

Permalink
Evaluate/dispatch percussion shortcuts in NotationViewInputController…
Browse files Browse the repository at this point in the history
…::shortcutOverrideEvent
  • Loading branch information
mathesoncalum committed Jan 27, 2025
1 parent e7cf839 commit e88e5ef
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
21 changes: 21 additions & 0 deletions src/engraving/dom/drumset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/dom/drumset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 26 additions & 5 deletions src/notation/view/notationviewinputcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/notation/view/notationviewinputcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e88e5ef

Please sign in to comment.