Skip to content

Commit

Permalink
Percussion panel - notation preview now reflects number of staff line…
Browse files Browse the repository at this point in the history
…s at input position
  • Loading branch information
mathesoncalum committed Feb 28, 2025
1 parent d49a3f4 commit 4a1d29f
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ Item {
panelEnabled: percModel.enabled
panelMode: percModel.currentPanelMode
useNotationPreview: percModel.useNotationPreview
notationPreviewNumStaffLines: percModel.notationPreviewNumStaffLines

// When swapping, only show the outline for the swap origin and the swap target...
showEditOutline: percModel.currentPanelMode === PanelMode.EDIT_LAYOUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ DropArea {

property int panelMode: -1
property bool useNotationPreview: false
property int notationPreviewNumStaffLines: 0
property bool showEditOutline: false

property alias totalBorderWidth: padLoader.anchors.margins
Expand Down Expand Up @@ -210,6 +211,7 @@ DropArea {
padModel: root.padModel
panelMode: root.panelMode
useNotationPreview: root.useNotationPreview
notationPreviewNumStaffLines: root.notationPreviewNumStaffLines

footerHeight: prv.footerHeight

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Column {

property int panelMode: -1
property bool useNotationPreview: false
property alias notationPreviewNumStaffLines: notationPreview.numStaffLines

property alias footerHeight: footerArea.height

Expand Down
11 changes: 5 additions & 6 deletions src/notation/utilities/engravingitempreviewpainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void EngravingItemPreviewPainter::paintPreview(mu::engraving::EngravingItem* ele
}

PointF origin = params.rect.center(); // draw element at center of cell by default
if (params.drawStaff) {
if (params.numStaffLines > 0) {
const double topLinePos = paintStaff(params); // draw dummy staff lines onto rect.
origin.setY(topLinePos); // vertical position relative to staff instead of cell center.
}
Expand Down Expand Up @@ -118,7 +118,7 @@ void EngravingItemPreviewPainter::paintPreviewForActionIcon(mu::engraving::Engra
painter->restore();
}

/// Paint a 5 line staff centered within a QRect and return the distance from the
/// Paint a staff centered within a QRect and return the distance from the
/// top of the QRect to the uppermost staff line.
double EngravingItemPreviewPainter::paintStaff(PaintParams& params)
{
Expand All @@ -135,8 +135,7 @@ double EngravingItemPreviewPainter::paintStaff(PaintParams& params)
pen.setWidthF(engraving::DefaultStyle::defaultStyle().styleS(Sid::staffLineWidth).val() * params.spatium);
painter->setPen(pen);

constexpr int numStaffLines = 5;
const double staffHeight = params.spatium * (numStaffLines - 1);
const double staffHeight = params.spatium * (params.numStaffLines - 1);
const double topLineDist = params.rect.center().y() - (staffHeight / 2.0);

// lines bounded horizontally by edge of target (with small margin)
Expand All @@ -146,7 +145,7 @@ double EngravingItemPreviewPainter::paintStaff(PaintParams& params)

// draw staff lines with middle line centered vertically on target
double y = topLineDist;
for (int i = 0; i < numStaffLines; ++i) {
for (int i = 0; i < params.numStaffLines; ++i) {
painter->drawLine(LineF(x1, y, x2, y));
y += params.spatium;
}
Expand Down Expand Up @@ -178,7 +177,7 @@ void EngravingItemPreviewPainter::paintPreviewForItem(mu::engraving::EngravingIt

PointF origin = element->ldata()->bbox().center();

if (params.drawStaff) {
if (params.numStaffLines > 0) {
// y = 0 is position of the element's parent.
// If the parent is the staff (or a segment on the staff) then
// y = 0 corresponds to the position of the top staff line.
Expand Down
2 changes: 1 addition & 1 deletion src/notation/utilities/engravingitempreviewpainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class EngravingItemPreviewPainter

bool useElementColors = false;
bool colorsInversionEnabled = false;
bool drawStaff = false;
int numStaffLines = 0;
};

static void paintPreview(mu::engraving::EngravingItem* element, PaintParams& params);
Expand Down
22 changes: 21 additions & 1 deletion src/notation/view/paintedengravingitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,27 @@ void PaintedEngravingItem::setEngravingItemVariant(QVariant engravingItemVariant
return;
}
m_item = item;

update();
emit engravingItemVariantChanged();
}

int PaintedEngravingItem::numStaffLines() const
{
return m_numStaffLines;
}

void PaintedEngravingItem::setNumStaffLines(int numStaffLines)
{
if (m_numStaffLines == numStaffLines) {
return;
}
m_numStaffLines = numStaffLines;

update();
emit numStaffLinesChanged();
}

double PaintedEngravingItem::spatium() const
{
return m_spatium;
Expand All @@ -58,6 +76,8 @@ void PaintedEngravingItem::setSpatium(double spatium)
return;
}
m_spatium = spatium;

update();
emit spatiumChanged();
}

Expand Down Expand Up @@ -87,7 +107,7 @@ void PaintedEngravingItem::paintNotationPreview(muse::draw::Painter& painter, qr

params.spatium = m_spatium;

params.drawStaff = true;
params.numStaffLines = m_numStaffLines;

painter.fillRect(params.rect, configuration()->noteBackgroundColor());

Expand Down
8 changes: 8 additions & 0 deletions src/notation/view/paintedengravingitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class PaintedEngravingItem : public QQuickPaintedItem
Q_OBJECT

Q_PROPERTY(QVariant engravingItem READ engravingItemVariant WRITE setEngravingItemVariant NOTIFY engravingItemVariantChanged)
Q_PROPERTY(int numStaffLines READ numStaffLines WRITE setNumStaffLines NOTIFY numStaffLinesChanged)

Q_PROPERTY(double spatium READ spatium WRITE setSpatium NOTIFY spatiumChanged)

public:
Expand All @@ -47,19 +49,25 @@ class PaintedEngravingItem : public QQuickPaintedItem
QVariant engravingItemVariant() const;
void setEngravingItemVariant(QVariant engravingItemVariant);

int numStaffLines() const;
void setNumStaffLines(int numStaffLines);

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

void paint(QPainter* painter) override;

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

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

mu::engraving::ElementPtr m_item;
int m_numStaffLines = 0;

double m_spatium = 1.0;
};
}
18 changes: 18 additions & 0 deletions src/notation/view/percussionpanel/percussionpanelmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ void PercussionPanelModel::setUseNotationPreview(bool useNotationPreview)
emit useNotationPreviewChanged(m_useNotationPreview);
}

int PercussionPanelModel::notationPreviewNumStaffLines() const
{
if (!interaction()) {
return 0;
}

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

if (!staff) {
return 0;
}

return staff->lines(inputState.tick());
}

PercussionPanelPadListModel* PercussionPanelModel::padListModel() const
{
return m_padListModel;
Expand Down Expand Up @@ -245,6 +261,8 @@ void PercussionPanelModel::customizeKit()
void PercussionPanelModel::setUpConnections()
{
const auto updatePadModels = [this](Drumset* drumset) {
emit notationPreviewNumStaffLinesChanged();

if (drumset && m_padListModel->drumset() && *drumset == *m_padListModel->drumset()) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/notation/view/percussionpanel/percussionpanelmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus

Q_PROPERTY(PanelMode::Mode currentPanelMode READ currentPanelMode WRITE setCurrentPanelMode NOTIFY currentPanelModeChanged)
Q_PROPERTY(bool useNotationPreview READ useNotationPreview WRITE setUseNotationPreview NOTIFY useNotationPreviewChanged)
Q_PROPERTY(int notationPreviewNumStaffLines READ notationPreviewNumStaffLines NOTIFY notationPreviewNumStaffLinesChanged)

Q_PROPERTY(PercussionPanelPadListModel * padListModel READ padListModel NOTIFY padListModelChanged)

Expand All @@ -87,6 +88,8 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus
bool useNotationPreview() const;
void setUseNotationPreview(bool useNotationPreview);

int notationPreviewNumStaffLines() const;

PercussionPanelPadListModel* padListModel() const;

Q_INVOKABLE void init();
Expand All @@ -107,6 +110,7 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus

void currentPanelModeChanged(const PanelMode::Mode& panelMode);
void useNotationPreviewChanged(bool useNotationPreview);
void notationPreviewNumStaffLinesChanged();

void padListModelChanged();

Expand Down
3 changes: 2 additions & 1 deletion src/palette/internal/palettecelliconengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ void PaletteCellIconEngine::paintCell(Painter& painter, const RectF& rect, bool
params.dpi = dpi;
params.spatium = configuration()->paletteSpatium() * params.mag;

params.drawStaff = m_cell->drawStaff;
//! NOTE: Slight hack - we can now specify exactly now many staff lines we want...
params.numStaffLines = m_cell->drawStaff ? 5 : 0;

notation::EngravingItemPreviewPainter::paintPreview(element, params);
}
Expand Down

0 comments on commit 4a1d29f

Please sign in to comment.