Skip to content

Commit

Permalink
Merge pull request #25751 from mathesoncalum/percussions_refinements_2
Browse files Browse the repository at this point in the history
Percussion panel - refinements round 2
  • Loading branch information
mathesoncalum authored Dec 10, 2024
2 parents 2c7851c + f417fc8 commit ae4ebdc
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/engraving/dom/drumset.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct DrumInstrument {

// if notehead = HEAD_CUSTOM, custom, use noteheads
NoteHeadGroup notehead = NoteHeadGroup::HEAD_INVALID; ///< notehead symbol set
SymId noteheads[int(NoteHeadType::HEAD_TYPES)]
std::array<SymId, int(NoteHeadType::HEAD_TYPES)> noteheads
= { SymId::noteheadWhole, SymId::noteheadHalf, SymId::noteheadBlack, SymId::noteheadDoubleWhole };

int line = 0; ///< place notehead onto this line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Item {
// If this is the swap target - move the swappable area to the swap origin (preview the swap)
State {
name: "SWAP_TARGET"
when: Boolean(padGrid.swapOriginPad) && (pad.containsDrag || pad.padNavigationCtrl.active) && padGrid.swapOriginPad !== pad
when: Boolean(padGrid.swapOriginPad) && (pad.containsDrag || pad.padNavigation.active) && padGrid.swapOriginPad !== pad

ParentChange {
target: pad.swappableArea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,49 @@ Column {

property bool padSwapActive: false

Rectangle {
Item {
id: mainContentArea

width: parent.width
height: parent.height - separator.height - footerArea.height

color: Utils.colorWithAlpha(ui.theme.accentColor, ui.theme.buttonOpacityNormal)

MouseArea {
id: mouseArea

anchors.fill: parent
hoverEnabled: true

onPressed: {
ui.tooltip.hide(root)

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

root.padModel.triggerPad()
}

onContainsMouseChanged: {
if (!Boolean(root.padModel)) {
ui.tooltip.hide(root)
return
}

if (mouseArea.containsMouse && root.useNotationPreview) {
ui.tooltip.show(root, root.padModel.instrumentName)
} else {
ui.tooltip.hide(root)
}
}
}

Rectangle {
id: instrumentNameBackground

visible: !root.useNotationPreview
anchors.fill: parent

color: Utils.colorWithAlpha(ui.theme.accentColor, ui.theme.buttonOpacityNormal)
}

StyledTextLabel {
Expand All @@ -82,24 +105,35 @@ Column {
anchors.fill: parent

engravingItem: Boolean(root.padModel) ? root.padModel.notationPreviewItem : null
spatium: 6.25 // Value approximated visually (needs to accomodate "extreme ledger line" situations)

opacity: 0.9
}

states: [
State {
name: "MOUSE_HOVERED"
when: mouseArea.containsMouse && !mouseArea.pressed && !root.padSwapActive
PropertyChanges {
target: mainContentArea
target: instrumentNameBackground
color: Utils.colorWithAlpha(ui.theme.accentColor, ui.theme.buttonOpacityHover)
}
PropertyChanges {
target: notationPreview
opacity: 0.7
}
},
State {
name: "MOUSE_HIT"
when: mouseArea.pressed || root.padSwapActive
PropertyChanges {
target: mainContentArea
target: instrumentNameBackground
color: Utils.colorWithAlpha(ui.theme.accentColor, ui.theme.buttonOpacityHit)
}
PropertyChanges {
target: notationPreview
opacity: 1.0
}
}
]
}
Expand Down
21 changes: 18 additions & 3 deletions src/notation/view/paintedengravingitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ void PaintedEngravingItem::setEngravingItemVariant(QVariant engravingItemVariant
return;
}
m_item = item;
emit engravingItemVariantChanged();
}

double PaintedEngravingItem::spatium() const
{
return m_spatium;
}

void PaintedEngravingItem::setSpatium(double spatium)
{
if (spatium == m_spatium) {
return;
}
m_spatium = spatium;
emit spatiumChanged();
}

void PaintedEngravingItem::paint(QPainter* painter)
Expand All @@ -64,16 +79,16 @@ void PaintedEngravingItem::paintNotationPreview(muse::draw::Painter& painter, qr
EngravingItemPreviewPainter::PaintParams params;
params.painter = &painter;

params.color = muse::draw::Color::BLACK; // TODO: set this properly
params.color = configuration()->defaultColor();

params.rect = muse::RectF(0, 0, parentItem()->width(), parentItem()->height());
params.dpi = dpi;

params.spatium = configuration()->paletteSpatium(); // TODO: don't use the palette for this
params.spatium = m_spatium;

params.drawStaff = true;

painter.fillRect(params.rect, muse::draw::Color::WHITE); // TODO: set this properly
painter.fillRect(params.rect, configuration()->scoreInversionColor());

EngravingItemPreviewPainter::paintPreview(m_item.get(), params);
}
11 changes: 8 additions & 3 deletions src/notation/view/paintedengravingitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <QQuickPaintedItem>

#include "modularity/ioc.h"
#include "palette/ipaletteconfiguration.h"
#include "engraving/iengravingconfiguration.h"

#include "engraving/dom/engravingitem.h"

Expand All @@ -34,27 +34,32 @@
namespace mu::notation {
class PaintedEngravingItem : public QQuickPaintedItem
{
// TODO: don't use the palette for this
INJECT_STATIC(palette::IPaletteConfiguration, configuration)
INJECT_STATIC(engraving::IEngravingConfiguration, configuration)

Q_OBJECT

Q_PROPERTY(QVariant engravingItem READ engravingItemVariant WRITE setEngravingItemVariant NOTIFY engravingItemVariantChanged)
Q_PROPERTY(double spatium READ spatium WRITE setSpatium NOTIFY spatiumChanged)

public:
explicit PaintedEngravingItem(QQuickItem* parent = nullptr);

QVariant engravingItemVariant() const;
void setEngravingItemVariant(QVariant engravingItemVariant);

double spatium() const;
void setSpatium(double spatium);

void paint(QPainter* painter) override;

signals:
void engravingItemVariantChanged();
void spatiumChanged();

private:
void paintNotationPreview(muse::draw::Painter& painter, qreal dpi) const;

mu::engraving::ElementPtr m_item;
double m_spatium = 1.0;
};
}
93 changes: 65 additions & 28 deletions src/notation/view/percussionpanel/percussionpanelmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include "engraving/dom/factory.h"
#include "engraving/dom/undo.h"

#include "defer.h"

static const QString INSTRUMENT_NAMES_CODE("percussion-instrument-names");
static const QString NOTATION_PREVIEW_CODE("percussion-notation-preview");
static const QString EDIT_LAYOUT_CODE("percussion-edit-layout");
Expand Down Expand Up @@ -63,7 +61,7 @@ PanelMode::Mode PercussionPanelModel::currentPanelMode() const
return m_currentPanelMode;
}

void PercussionPanelModel::setCurrentPanelMode(const PanelMode::Mode& panelMode, bool updateNoteInput)
void PercussionPanelModel::setCurrentPanelMode(const PanelMode::Mode& panelMode)
{
if (m_currentPanelMode == panelMode) {
return;
Expand All @@ -76,13 +74,6 @@ void PercussionPanelModel::setCurrentPanelMode(const PanelMode::Mode& panelMode,

m_currentPanelMode = panelMode;
emit currentPanelModeChanged(m_currentPanelMode);

if (!updateNoteInput || !interaction() || !interaction()->noteInput()) {
return;
}

const INotationNoteInputPtr noteInput = interaction()->noteInput();
panelMode == PanelMode::Mode::WRITE ? noteInput->startNoteInput() : noteInput->endNoteInput();
}

bool PercussionPanelModel::useNotationPreview() const
Expand Down Expand Up @@ -159,15 +150,21 @@ void PercussionPanelModel::handleMenuItem(const QString& itemId)
setUseNotationPreview(true);
} else if (itemId == EDIT_LAYOUT_CODE) {
const bool currentlyEditing = m_currentPanelMode == PanelMode::Mode::EDIT_LAYOUT;
currentlyEditing ? finishEditing() : setCurrentPanelMode(PanelMode::Mode::EDIT_LAYOUT, false);
currentlyEditing ? finishEditing() : setCurrentPanelMode(PanelMode::Mode::EDIT_LAYOUT);
} else if (itemId == RESET_LAYOUT_CODE) {
// TODO: Need a mechanism for "default" layouts...
// m_padListModel->resetLayout();
resetLayout();
}
}

void PercussionPanelModel::finishEditing()
void PercussionPanelModel::finishEditing(bool discardChanges)
{
if (!interaction()) {
//! NOTE: Can happen if we close the project while editing the layout...
m_padListModel->setDrumset(nullptr);
setCurrentPanelMode(m_panelModeToRestore);
return;
}

Drumset* updatedDrumset = m_padListModel->drumset();
m_padListModel->removeEmptyRows();

Expand All @@ -180,13 +177,13 @@ void PercussionPanelModel::finishEditing()

Instrument* inst = staff->part()->instrument(inputState.segment->tick());

IF_ASSERT_FAILED(inst) {
IF_ASSERT_FAILED(inst && inst->drumset()) {
return;
}

// Return if nothing changed after edit...
if (inst->drumset() && updatedDrumset
&& *inst->drumset() == *updatedDrumset) {
if (discardChanges) {
m_padListModel->setDrumset(inst->drumset());
setCurrentPanelMode(m_panelModeToRestore);
return;
}

Expand All @@ -202,16 +199,20 @@ void PercussionPanelModel::finishEditing()
drum.panelColumn = column;
}

INotationUndoStackPtr undoStack = notation()->undoStack();
// Return if nothing changed after edit...
if (inst->drumset() && updatedDrumset
&& *inst->drumset() == *updatedDrumset) {
setCurrentPanelMode(m_panelModeToRestore);
return;
}

DEFER {
undoStack->commitChanges();
};
INotationUndoStackPtr undoStack = notation()->undoStack();

undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Edit percussion panel layout"));
score()->undo(new engraving::ChangeDrumset(inst, updatedDrumset, staff->part()));
undoStack->commitChanges();

setCurrentPanelMode(m_panelModeToRestore, false);
setCurrentPanelMode(m_panelModeToRestore);
}

void PercussionPanelModel::customizeKit()
Expand All @@ -227,7 +228,7 @@ void PercussionPanelModel::setUpConnections()
}

if (m_currentPanelMode == PanelMode::Mode::EDIT_LAYOUT) {
finishEditing();
finishEditing(/*discardChanges*/ true);
}

m_padListModel->setDrumset(drumset);
Expand Down Expand Up @@ -271,15 +272,12 @@ void PercussionPanelModel::writePitch(int pitch)
return;
}

DEFER {
undoStack->commitChanges();
};

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

interaction()->noteInput()->startNoteInput();

score()->addMidiPitch(pitch, false, /*transpose*/ false);
undoStack->commitChanges();

const mu::engraving::InputState& inputState = score()->inputState();
if (inputState.cr()) {
Expand Down Expand Up @@ -311,6 +309,45 @@ void PercussionPanelModel::playPitch(int pitch)
delete note;
}

void PercussionPanelModel::resetLayout()
{
if (m_currentPanelMode == PanelMode::Mode::EDIT_LAYOUT) {
finishEditing(/*discardChanges*/ true);
}

NoteInputState inputState = interaction()->noteInput()->state();
const Staff* staff = inputState.staff;

IF_ASSERT_FAILED(staff && staff->part()) {
return;
}

Instrument* inst = staff->part()->instrument(inputState.segment->tick());

IF_ASSERT_FAILED(inst) {
return;
}

const InstrumentTemplate& instTemplate = instrumentsRepository()->instrumentTemplate(inst->id());
const Drumset* defaultDrumset = instTemplate.drumset;

IF_ASSERT_FAILED(defaultDrumset) {
return;
}

Drumset defaultLayout = m_padListModel->constructDefaultLayout(defaultDrumset);
if (defaultLayout == *m_padListModel->drumset()) {
// Nothing changed after reset...
return;
}

INotationUndoStackPtr undoStack = notation()->undoStack();

undoStack->prepareChanges(muse::TranslatableString("undoableAction", "Reset percussion panel layout"));
score()->undo(new engraving::ChangeDrumset(inst, &defaultLayout, staff->part()));
undoStack->commitChanges();
}

const INotationPtr PercussionPanelModel::notation() const
{
return globalContext()->currentNotation();
Expand Down
Loading

0 comments on commit ae4ebdc

Please sign in to comment.