Skip to content

Commit

Permalink
Percussion panel - assorted small fixes:
Browse files Browse the repository at this point in the history
- Fixed notation preview background colour
- Fixed alignment of disabled state text
- Fixed panel not updating properly after selecting an unpitched stave
- Ensured keyboard focus moves to pads when entering/exiting edit layout mode
- Fixed clipped navigation outline for add row button
- Fixed sounds not previewing properly
- Added missing overrides
- Make the Drumset argument in ChangeDrumset const
  • Loading branch information
mathesoncalum committed Jan 3, 2025
1 parent 5bd3953 commit 5ac593c
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/engraving/dom/undo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions src/notation/internal/notationconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/notation/internal/notationparts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ Item {
orientation: Qt.Horizontal

navigation.panel: addRowButtonPanel
drawFocusBorderInsideRect: true

onClicked: {
padGrid.model.addEmptyRow()
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/notation/view/paintedengravingitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
49 changes: 24 additions & 25 deletions src/notation/view/percussionpanel/percussionpanelmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/

#include "percussionpanelmodel.h"

#include "notation/utilities/percussionutilities.h"

#include "types/translatablestring.h"
#include "ui/view/iconcodes.h"

Expand Down Expand Up @@ -163,8 +166,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();
}
Expand All @@ -185,13 +193,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;
}

Expand Down Expand Up @@ -225,7 +233,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);
Expand Down Expand Up @@ -381,7 +389,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();
}

Expand All @@ -401,7 +409,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();
}

Expand Down Expand Up @@ -432,26 +440,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> 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()
Expand Down Expand Up @@ -484,7 +483,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();
}

Expand Down
10 changes: 10 additions & 0 deletions src/notation/view/percussionpanel/percussionpanelpadlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 5ac593c

Please sign in to comment.