Skip to content

Commit

Permalink
Percussion panel - notation preview basics
Browse files Browse the repository at this point in the history
  • Loading branch information
mathesoncalum committed Nov 6, 2024
1 parent a0f2a79 commit 8bb9e07
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/notation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/view/noteinputbarcustomiseitem.h
${CMAKE_CURRENT_LIST_DIR}/view/continuouspanel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/continuouspanel.h
${CMAKE_CURRENT_LIST_DIR}/view/paintedengravingitem.cpp
${CMAKE_CURRENT_LIST_DIR}/view/paintedengravingitem.h
${CMAKE_CURRENT_LIST_DIR}/view/abstractelementpopupmodel.h
${CMAKE_CURRENT_LIST_DIR}/view/abstractelementpopupmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/internal/undoredotoolbarmodel.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/notation/notationmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "view/notationnavigator.h"
#include "view/selectionfiltermodel.h"
#include "view/editgridsizedialogmodel.h"
#include "view/paintedengravingitem.h"

#include "view/pianokeyboard/pianokeyboardview.h"
#include "view/pianokeyboard/pianokeyboardpanelcontextmenumodel.h"
Expand Down Expand Up @@ -184,6 +185,7 @@ void NotationModule::registerUiTypes()
qmlRegisterType<HarpPedalPopupModel>("MuseScore.NotationScene", 1, 0, "HarpPedalPopupModel");
qmlRegisterType<CapoSettingsModel>("MuseScore.NotationScene", 1, 0, "CapoSettingsModel");
qmlRegisterType<StringTuningsSettingsModel>("MuseScore.NotationScene", 1, 0, "StringTuningsSettingsModel");
qmlRegisterType<PaintedEngravingItem>("MuseScore.NotationScene", 1, 0, "PaintedEngravingItem");

qmlRegisterType<PercussionPanelModel>("MuseScore.NotationScene", 1, 0, "PercussionPanelModel");
qmlRegisterUncreatableType<PanelMode>("MuseScore.NotationScene", 1, 0, "PanelMode", "Cannot create");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ Column {
text: Boolean(root.padModel) ? root.padModel.instrumentName : ""
}

PaintedEngravingItem {
id: notationPreview

visible: root.useNotationPreview

anchors.fill: parent

Component.onCompleted: {
if (!Boolean(root.padModel)) {
return;
}
root.padModel.notationPreview = notationPreview
}
}

states: [
State {
name: "MOUSE_HOVERED"
Expand All @@ -98,7 +113,7 @@ Column {
width: parent.width
height: 1

color: ui.theme.accentColor
color: root.useNotationPreview ? ui.theme.strokeColor : ui.theme.accentColor
}

Rectangle {
Expand Down
73 changes: 73 additions & 0 deletions src/notation/view/paintedengravingitem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-Studio-CLA-applies
*
* MuseScore Studio
* Music Composition & Notation
*
* Copyright (C) 2024 MuseScore Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "paintedengravingitem.h"

#include "notation/utilities/engravingitempreviewpainter.h"

using namespace mu::notation;

PaintedEngravingItem::PaintedEngravingItem(QQuickItem* parent)
: QQuickPaintedItem(parent)
{
}

void PaintedEngravingItem::setEngravingItem(mu::engraving::EngravingItem* item)
{
if (item == m_item) {
return;
}
m_item = item;
}

void PaintedEngravingItem::paint(QPainter* painter)
{
qreal dpi = painter->device()->logicalDpiX();
muse::draw::Painter p(painter, "paintedengravingitem");
p.save();
p.setAntialiasing(true);
paintNotationPreview(p, dpi);
p.restore();
}

void PaintedEngravingItem::paintNotationPreview(muse::draw::Painter& painter, qreal dpi) const
{
IF_ASSERT_FAILED(m_item) {
return;
}

EngravingItemPreviewPainter::PaintParams params;
params.painter = &painter;

params.color = QColor("black"); // TODO: set this properly

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.drawStaff = true;

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

EngravingItemPreviewPainter::paintPreview(m_item, params);
}
53 changes: 53 additions & 0 deletions src/notation/view/paintedengravingitem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-Studio-CLA-applies
*
* MuseScore Studio
* Music Composition & Notation
*
* Copyright (C) 2024 MuseScore Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <QQuickPaintedItem>

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

#include "engraving/dom/engravingitem.h"

#include "notation/utilities/engravingitempreviewpainter.h"

namespace mu::notation {
class PaintedEngravingItem : public QQuickPaintedItem
{
// TODO: don't use the palette for this
INJECT_STATIC(palette::IPaletteConfiguration, configuration)

Q_OBJECT

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

void setEngravingItem(mu::engraving::EngravingItem* item);
void paint(QPainter* painter) override;

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

mu::engraving::EngravingItem* m_item = nullptr;
};
}
2 changes: 2 additions & 0 deletions src/notation/view/percussionpanel/percussionpanelmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "percussionpanelpadlistmodel.h"

namespace mu::notation {
class PanelMode
{
Q_GADGET
Expand Down Expand Up @@ -100,3 +101,4 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus

PercussionPanelPadListModel* m_padListModel = nullptr;
};
}
11 changes: 11 additions & 0 deletions src/notation/view/percussionpanel/percussionpanelpadlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "global/utils.h"
#include "percussionpanelpadlistmodel.h"

#include "notation/utilities/percussionutilities.h"

using namespace mu::notation;

PercussionPanelPadListModel::PercussionPanelPadListModel(QObject* parent)
: QAbstractListModel(parent)
{
Expand Down Expand Up @@ -132,6 +136,13 @@ void PercussionPanelPadListModel::resetLayout()
m_triggeredChannel.send(pitch);
});

auto drumNote = PercussionUtilities::getDrumNoteForPreview(m_drumset, pitch);
connect(model, &PercussionPanelPadModel::notationPreviewChanged, this, [model, drumNote]() {
if (PaintedEngravingItem* notationPreview = model->notationPreview()) {
notationPreview->setEngravingItem(drumNote.get());
}
});

model->setIsEmptySlot(false);

m_padModels.append(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
#include "async/asyncable.h"
#include "async/channel.h"

#include "notation/utilities/engravingitempreviewpainter.h"

#include "engraving/dom/drumset.h"

#include "percussionpanelpadmodel.h"

namespace mu::notation {
class PercussionPanelPadListModel : public QAbstractListModel, public muse::async::Asyncable
{
Q_OBJECT
Expand Down Expand Up @@ -87,3 +90,4 @@ class PercussionPanelPadListModel : public QAbstractListModel, public muse::asyn

muse::async::Channel<int /*pitch*/> m_triggeredChannel;
};
}
12 changes: 12 additions & 0 deletions src/notation/view/percussionpanel/percussionpanelpadmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "percussionpanelpadmodel.h"

using namespace mu::notation;

PercussionPanelPadModel::PercussionPanelPadModel(QObject* parent)
: QObject(parent)
{
Expand Down Expand Up @@ -57,6 +59,16 @@ void PercussionPanelPadModel::setMidiNote(const QString& midiNote)
emit midiNoteChanged();
}

void PercussionPanelPadModel::setNotationPreview(mu::notation::PaintedEngravingItem* notationPreview)
{
if (m_notationPreview == notationPreview) {
return;
}

m_notationPreview = notationPreview;
emit notationPreviewChanged();
}

void PercussionPanelPadModel::setIsEmptySlot(bool isEmptySlot)
{
if (m_isEmptySlot == isEmptySlot) {
Expand Down
13 changes: 13 additions & 0 deletions src/notation/view/percussionpanel/percussionpanelpadmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "async/asyncable.h"
#include "async/notification.h"

#include "notation/view/paintedengravingitem.h"

namespace mu::notation {
class PercussionPanelPadModel : public QObject, public muse::async::Asyncable
{
Q_OBJECT
Expand All @@ -36,6 +39,8 @@ class PercussionPanelPadModel : public QObject, public muse::async::Asyncable
Q_PROPERTY(QString keyboardShortcut READ keyboardShortcut NOTIFY keyboardShortcutChanged)
Q_PROPERTY(QString midiNote READ midiNote NOTIFY midiNoteChanged)

Q_PROPERTY(PaintedEngravingItem * notationPreview READ notationPreview WRITE setNotationPreview NOTIFY notationPreviewChanged)

Q_PROPERTY(bool isEmptySlot READ isEmptySlot NOTIFY isEmptySlotChanged)

public:
Expand All @@ -50,6 +55,9 @@ class PercussionPanelPadModel : public QObject, public muse::async::Asyncable
QString midiNote() const { return m_midiNote; }
void setMidiNote(const QString& midiNote);

PaintedEngravingItem* notationPreview() const { return m_notationPreview; }
void setNotationPreview(PaintedEngravingItem* notationPreview);

bool isEmptySlot() const { return m_isEmptySlot; }
void setIsEmptySlot(bool isEmptySlot);

Expand All @@ -62,6 +70,8 @@ class PercussionPanelPadModel : public QObject, public muse::async::Asyncable
void keyboardShortcutChanged();
void midiNoteChanged();

void notationPreviewChanged();

void isEmptySlotChanged();

private:
Expand All @@ -70,7 +80,10 @@ class PercussionPanelPadModel : public QObject, public muse::async::Asyncable
QString m_keyboardShortcut;
QString m_midiNote;

PaintedEngravingItem* m_notationPreview = nullptr;

bool m_isEmptySlot = true;

muse::async::Notification m_triggeredNotification;
};
}

0 comments on commit 8bb9e07

Please sign in to comment.