Skip to content

Commit

Permalink
Merge pull request #26498 from mathesoncalum/percussion_refinements_7
Browse files Browse the repository at this point in the history
  • Loading branch information
cbjeukendrup authored Feb 15, 2025
2 parents fbff79a + 50ae2c5 commit fe85a78
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,21 @@ Column {
enabled: mainContentArea.enabled
hoverEnabled: true

onPressed: {
acceptedButtons: Qt.LeftButton | Qt.RightButton

onPressed: function(event) {
ui.tooltip.hide(root)

if (!Boolean(root.padModel)) {
return
}

root.padModel.triggerPad()
if (event.button === Qt.RightButton) {
root.openFooterContextMenu()
return
}

root.padModel.triggerPad(event.modifiers)
}

onContainsMouseChanged: {
Expand Down Expand Up @@ -168,6 +175,8 @@ Column {
anchors.fill: parent
enabled: root.panelMode !== PanelMode.EDIT_LAYOUT

acceptedButtons: Qt.LeftButton | Qt.RightButton

onClicked: {
root.openFooterContextMenu()
}
Expand Down
40 changes: 24 additions & 16 deletions src/notation/view/percussionpanel/percussionpanelmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ static const QString EDIT_LAYOUT_CODE("percussion-edit-layout");
static const QString RESET_LAYOUT_CODE("percussion-reset-layout");

using namespace muse;
using namespace ui;
using namespace muse::actions;
using namespace muse::ui;
using namespace mu::notation;

static const std::unordered_map<PercussionPanelPadModel::PadAction, NoteAddingMode> WRITE_ACTION_MAP = {
{ PercussionPanelPadModel::PadAction::TRIGGER_STANDARD, NoteAddingMode::NextChord },
{ PercussionPanelPadModel::PadAction::TRIGGER_ADD, NoteAddingMode::CurrentChord },
{ PercussionPanelPadModel::PadAction::TRIGGER_INSERT, NoteAddingMode::InsertChord }
};

PercussionPanelModel::PercussionPanelModel(QObject* parent)
: QObject(parent)
{
Expand Down Expand Up @@ -278,8 +285,10 @@ void PercussionPanelModel::setUpConnections()

m_padListModel->padActionRequested().onReceive(this, [this](PercussionPanelPadModel::PadAction action, int pitch) {
switch (action) {
case PercussionPanelPadModel::PadAction::TRIGGER:
onPadTriggered(pitch);
case PercussionPanelPadModel::PadAction::TRIGGER_STANDARD:
case PercussionPanelPadModel::PadAction::TRIGGER_ADD:
case PercussionPanelPadModel::PadAction::TRIGGER_INSERT:
onPadTriggered(pitch, action);
break;
case PercussionPanelPadModel::PadAction::DUPLICATE:
onDuplicatePadRequested(pitch);
Expand Down Expand Up @@ -361,12 +370,15 @@ bool PercussionPanelModel::eventFilter(QObject* watched, QEvent* event)
return true;
}

void PercussionPanelModel::onPadTriggered(int pitch)
void PercussionPanelModel::onPadTriggered(int pitch, const PercussionPanelPadModel::PadAction& action)
{
switch (currentPanelMode()) {
case PanelMode::Mode::EDIT_LAYOUT: return;
case PanelMode::Mode::WRITE: writePitch(pitch); // fall through
case PanelMode::Mode::SOUND_PREVIEW: playPitch(pitch);
case PanelMode::Mode::WRITE:
writePitch(pitch, WRITE_ACTION_MAP.at(action));
break;
case PanelMode::Mode::SOUND_PREVIEW:
playPitch(pitch);
break;
default: break;
}
}
Expand Down Expand Up @@ -445,24 +457,20 @@ void PercussionPanelModel::onDefinePadShortcutRequested(int pitch)
undoStack->commitChanges();
}

void PercussionPanelModel::writePitch(int pitch)
void PercussionPanelModel::writePitch(int pitch, const NoteAddingMode& addingMode)
{
INotationUndoStackPtr undoStack = notation()->undoStack();
if (!interaction() || !undoStack) {
return;
}

undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Enter percussion note"));

interaction()->noteInput()->startNoteInput(configuration()->defaultNoteInputMethod(), /*focusNotation*/ false);

score()->addMidiPitch(pitch, false, /*transpose*/ false);
undoStack->commitChanges();
NoteInputParams params;
params.drumPitch = pitch;

const mu::engraving::InputState& inputState = score()->inputState();
if (inputState.cr()) {
interaction()->showItem(inputState.cr());
}
const ActionData args = ActionData::make_arg2<NoteInputParams, NoteAddingMode>(params, addingMode);
dispatcher()->dispatch("note-action", args);
}

void PercussionPanelModel::playPitch(int pitch)
Expand Down
4 changes: 2 additions & 2 deletions src/notation/view/percussionpanel/percussionpanelmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus

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

void onPadTriggered(int pitch);
void onPadTriggered(int pitch, const PercussionPanelPadModel::PadAction& action);
void onDuplicatePadRequested(int pitch);
void onDeletePadRequested(int pitch);
void onDefinePadShortcutRequested(int pitch);

void writePitch(int pitch);
void writePitch(int pitch, const NoteAddingMode& addingMode);
void playPitch(int pitch);

void resetLayout();
Expand Down
22 changes: 14 additions & 8 deletions src/notation/view/percussionpanel/percussionpanelpadmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,20 @@ const QVariant PercussionPanelPadModel::notationPreviewItemVariant() const

QList<QVariantMap> PercussionPanelPadModel::footerContextMenuItems() const
{
static constexpr int definePadShortcutIcon = static_cast<int>(IconCode::Code::SHORTCUTS);
// static constexpr int duplicatePadIcon = static_cast<int>(IconCode::Code::COPY);
static constexpr int deletePadIcon = static_cast<int>(IconCode::Code::DELETE_TANK);
static constexpr int definePadShortcutIcon = static_cast<int>(IconCode::Code::SHORTCUTS);

QList<QVariantMap> menuItems = {
{ { "id", DEFINE_PAD_SHORTCUT_CODE }, { "title", muse::qtrc("shortcuts", "Define keyboard shortcut") },
{ "icon", definePadShortcutIcon }, { "enabled", true } },

//! NOTE: Disabled for now - will be re-introduced with new percussion mapping system...
// { { "id", DUPLICATE_PAD_CODE }, { "title", muse::qtrc("global", "Duplicate") },
// { "icon", duplicatePadIcon }, { "enabled", true } },

{ { "id", DELETE_PAD_CODE }, { "title", muse::qtrc("global", "Delete") },
{ "icon", deletePadIcon }, { "enabled", true } },

{ }, // separator

{ { "id", DEFINE_PAD_SHORTCUT_CODE }, { "title", muse::qtrc("shortcuts", "Define keyboard shortcut") },
{ "icon", definePadShortcutIcon }, { "enabled", true } },
};

return menuItems;
Expand All @@ -115,7 +113,15 @@ void PercussionPanelPadModel::handleMenuItem(const QString& itemId)
}
}

void PercussionPanelPadModel::triggerPad()
void PercussionPanelPadModel::triggerPad(const Qt::KeyboardModifiers& mods)
{
m_padActionTriggered.send(PadAction::TRIGGER);
PadAction action = PadAction::TRIGGER_STANDARD;

if (mods & Qt::ShiftModifier && (mods & Qt::ControlModifier || mods & Qt::MetaModifier)) {
action = PadAction::TRIGGER_INSERT;
} else if (mods & Qt::ShiftModifier) {
action = PadAction::TRIGGER_ADD;
}

m_padActionTriggered.send(action);
}
6 changes: 4 additions & 2 deletions src/notation/view/percussionpanel/percussionpanelpadmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ class PercussionPanelPadModel : public QObject, public muse::async::Asyncable
QList<QVariantMap> footerContextMenuItems() const;
Q_INVOKABLE void handleMenuItem(const QString& itemId);

Q_INVOKABLE void triggerPad();
Q_INVOKABLE void triggerPad(const Qt::KeyboardModifiers& modifiers);

enum class PadAction {
TRIGGER,
TRIGGER_STANDARD,
TRIGGER_ADD,
TRIGGER_INSERT,
DUPLICATE,
DELETE,
DEFINE_SHORTCUT,
Expand Down

0 comments on commit fe85a78

Please sign in to comment.