Skip to content

Commit fe85a78

Browse files
authored
Merge pull request #26498 from mathesoncalum/percussion_refinements_7
2 parents fbff79a + 50ae2c5 commit fe85a78

File tree

5 files changed

+55
-30
lines changed

5 files changed

+55
-30
lines changed

src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,21 @@ Column {
5757
enabled: mainContentArea.enabled
5858
hoverEnabled: true
5959

60-
onPressed: {
60+
acceptedButtons: Qt.LeftButton | Qt.RightButton
61+
62+
onPressed: function(event) {
6163
ui.tooltip.hide(root)
6264

6365
if (!Boolean(root.padModel)) {
6466
return
6567
}
6668

67-
root.padModel.triggerPad()
69+
if (event.button === Qt.RightButton) {
70+
root.openFooterContextMenu()
71+
return
72+
}
73+
74+
root.padModel.triggerPad(event.modifiers)
6875
}
6976

7077
onContainsMouseChanged: {
@@ -168,6 +175,8 @@ Column {
168175
anchors.fill: parent
169176
enabled: root.panelMode !== PanelMode.EDIT_LAYOUT
170177

178+
acceptedButtons: Qt.LeftButton | Qt.RightButton
179+
171180
onClicked: {
172181
root.openFooterContextMenu()
173182
}

src/notation/view/percussionpanel/percussionpanelmodel.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@ static const QString EDIT_LAYOUT_CODE("percussion-edit-layout");
3939
static const QString RESET_LAYOUT_CODE("percussion-reset-layout");
4040

4141
using namespace muse;
42-
using namespace ui;
42+
using namespace muse::actions;
43+
using namespace muse::ui;
4344
using namespace mu::notation;
4445

46+
static const std::unordered_map<PercussionPanelPadModel::PadAction, NoteAddingMode> WRITE_ACTION_MAP = {
47+
{ PercussionPanelPadModel::PadAction::TRIGGER_STANDARD, NoteAddingMode::NextChord },
48+
{ PercussionPanelPadModel::PadAction::TRIGGER_ADD, NoteAddingMode::CurrentChord },
49+
{ PercussionPanelPadModel::PadAction::TRIGGER_INSERT, NoteAddingMode::InsertChord }
50+
};
51+
4552
PercussionPanelModel::PercussionPanelModel(QObject* parent)
4653
: QObject(parent)
4754
{
@@ -278,8 +285,10 @@ void PercussionPanelModel::setUpConnections()
278285

279286
m_padListModel->padActionRequested().onReceive(this, [this](PercussionPanelPadModel::PadAction action, int pitch) {
280287
switch (action) {
281-
case PercussionPanelPadModel::PadAction::TRIGGER:
282-
onPadTriggered(pitch);
288+
case PercussionPanelPadModel::PadAction::TRIGGER_STANDARD:
289+
case PercussionPanelPadModel::PadAction::TRIGGER_ADD:
290+
case PercussionPanelPadModel::PadAction::TRIGGER_INSERT:
291+
onPadTriggered(pitch, action);
283292
break;
284293
case PercussionPanelPadModel::PadAction::DUPLICATE:
285294
onDuplicatePadRequested(pitch);
@@ -361,12 +370,15 @@ bool PercussionPanelModel::eventFilter(QObject* watched, QEvent* event)
361370
return true;
362371
}
363372

364-
void PercussionPanelModel::onPadTriggered(int pitch)
373+
void PercussionPanelModel::onPadTriggered(int pitch, const PercussionPanelPadModel::PadAction& action)
365374
{
366375
switch (currentPanelMode()) {
367-
case PanelMode::Mode::EDIT_LAYOUT: return;
368-
case PanelMode::Mode::WRITE: writePitch(pitch); // fall through
369-
case PanelMode::Mode::SOUND_PREVIEW: playPitch(pitch);
376+
case PanelMode::Mode::WRITE:
377+
writePitch(pitch, WRITE_ACTION_MAP.at(action));
378+
break;
379+
case PanelMode::Mode::SOUND_PREVIEW:
380+
playPitch(pitch);
381+
break;
370382
default: break;
371383
}
372384
}
@@ -445,24 +457,20 @@ void PercussionPanelModel::onDefinePadShortcutRequested(int pitch)
445457
undoStack->commitChanges();
446458
}
447459

448-
void PercussionPanelModel::writePitch(int pitch)
460+
void PercussionPanelModel::writePitch(int pitch, const NoteAddingMode& addingMode)
449461
{
450462
INotationUndoStackPtr undoStack = notation()->undoStack();
451463
if (!interaction() || !undoStack) {
452464
return;
453465
}
454466

455-
undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Enter percussion note"));
456-
457467
interaction()->noteInput()->startNoteInput(configuration()->defaultNoteInputMethod(), /*focusNotation*/ false);
458468

459-
score()->addMidiPitch(pitch, false, /*transpose*/ false);
460-
undoStack->commitChanges();
469+
NoteInputParams params;
470+
params.drumPitch = pitch;
461471

462-
const mu::engraving::InputState& inputState = score()->inputState();
463-
if (inputState.cr()) {
464-
interaction()->showItem(inputState.cr());
465-
}
472+
const ActionData args = ActionData::make_arg2<NoteInputParams, NoteAddingMode>(params, addingMode);
473+
dispatcher()->dispatch("note-action", args);
466474
}
467475

468476
void PercussionPanelModel::playPitch(int pitch)

src/notation/view/percussionpanel/percussionpanelmodel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus
119119

120120
bool eventFilter(QObject* watched, QEvent* event) override;
121121

122-
void onPadTriggered(int pitch);
122+
void onPadTriggered(int pitch, const PercussionPanelPadModel::PadAction& action);
123123
void onDuplicatePadRequested(int pitch);
124124
void onDeletePadRequested(int pitch);
125125
void onDefinePadShortcutRequested(int pitch);
126126

127-
void writePitch(int pitch);
127+
void writePitch(int pitch, const NoteAddingMode& addingMode);
128128
void playPitch(int pitch);
129129

130130
void resetLayout();

src/notation/view/percussionpanel/percussionpanelpadmodel.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,20 @@ const QVariant PercussionPanelPadModel::notationPreviewItemVariant() const
8383

8484
QList<QVariantMap> PercussionPanelPadModel::footerContextMenuItems() const
8585
{
86+
static constexpr int definePadShortcutIcon = static_cast<int>(IconCode::Code::SHORTCUTS);
8687
// static constexpr int duplicatePadIcon = static_cast<int>(IconCode::Code::COPY);
8788
static constexpr int deletePadIcon = static_cast<int>(IconCode::Code::DELETE_TANK);
88-
static constexpr int definePadShortcutIcon = static_cast<int>(IconCode::Code::SHORTCUTS);
8989

9090
QList<QVariantMap> menuItems = {
91+
{ { "id", DEFINE_PAD_SHORTCUT_CODE }, { "title", muse::qtrc("shortcuts", "Define keyboard shortcut") },
92+
{ "icon", definePadShortcutIcon }, { "enabled", true } },
93+
9194
//! NOTE: Disabled for now - will be re-introduced with new percussion mapping system...
9295
// { { "id", DUPLICATE_PAD_CODE }, { "title", muse::qtrc("global", "Duplicate") },
9396
// { "icon", duplicatePadIcon }, { "enabled", true } },
9497

9598
{ { "id", DELETE_PAD_CODE }, { "title", muse::qtrc("global", "Delete") },
9699
{ "icon", deletePadIcon }, { "enabled", true } },
97-
98-
{ }, // separator
99-
100-
{ { "id", DEFINE_PAD_SHORTCUT_CODE }, { "title", muse::qtrc("shortcuts", "Define keyboard shortcut") },
101-
{ "icon", definePadShortcutIcon }, { "enabled", true } },
102100
};
103101

104102
return menuItems;
@@ -115,7 +113,15 @@ void PercussionPanelPadModel::handleMenuItem(const QString& itemId)
115113
}
116114
}
117115

118-
void PercussionPanelPadModel::triggerPad()
116+
void PercussionPanelPadModel::triggerPad(const Qt::KeyboardModifiers& mods)
119117
{
120-
m_padActionTriggered.send(PadAction::TRIGGER);
118+
PadAction action = PadAction::TRIGGER_STANDARD;
119+
120+
if (mods & Qt::ShiftModifier && (mods & Qt::ControlModifier || mods & Qt::MetaModifier)) {
121+
action = PadAction::TRIGGER_INSERT;
122+
} else if (mods & Qt::ShiftModifier) {
123+
action = PadAction::TRIGGER_ADD;
124+
}
125+
126+
m_padActionTriggered.send(action);
121127
}

src/notation/view/percussionpanel/percussionpanelpadmodel.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ class PercussionPanelPadModel : public QObject, public muse::async::Asyncable
6767
QList<QVariantMap> footerContextMenuItems() const;
6868
Q_INVOKABLE void handleMenuItem(const QString& itemId);
6969

70-
Q_INVOKABLE void triggerPad();
70+
Q_INVOKABLE void triggerPad(const Qt::KeyboardModifiers& modifiers);
7171

7272
enum class PadAction {
73-
TRIGGER,
73+
TRIGGER_STANDARD,
74+
TRIGGER_ADD,
75+
TRIGGER_INSERT,
7476
DUPLICATE,
7577
DELETE,
7678
DEFINE_SHORTCUT,

0 commit comments

Comments
 (0)