implemented opening/closing of the drumset panel when the note input

mode is on/off
This commit is contained in:
Roman Pudashkin 2021-07-27 18:05:55 +02:00
parent 218a671af2
commit 5519b54220
21 changed files with 221 additions and 140 deletions

View file

@ -41,7 +41,8 @@ enum class PanelType
Synthesizer,
SelectionFilter,
Piano,
ComparisonTool
ComparisonTool,
DrumsetPanel
};
using PanelTypeList = std::vector<PanelType>;

View file

@ -43,6 +43,7 @@ bool NotationPageState::isPanelVisible(PanelType type) const
case PanelType::NotationStatusBar:
case PanelType::Mixer:
case PanelType::Timeline:
case PanelType::DrumsetPanel:
return m_panelVisibleMap[type];
case PanelType::NotationNavigator:
return configuration()->isNotationNavigatorVisible();
@ -86,6 +87,7 @@ void NotationPageState::setIsPanelVisible(PanelType type, bool visible)
case PanelType::NotationStatusBar:
case PanelType::Mixer:
case PanelType::Timeline:
case PanelType::DrumsetPanel:
m_panelVisibleMap[type] = visible;
break;
case PanelType::NotationNavigator:

View file

@ -83,6 +83,7 @@ DockPage {
pageModel.setPianoRollDockName(pianoRollPanel.objectName)
pageModel.setMixerDockName(mixerPanel.objectName)
pageModel.setTimelineDockName(timelinePanel.objectName)
pageModel.setDrumsetPanelDockName(drumsetPanel.objectName)
pageModel.setStatusBarDockName(notationStatusBar.objectName)
Qt.callLater(pageModel.init, root.dockWindow)
@ -314,9 +315,8 @@ DockPage {
allowedAreas: Qt.TopDockWidgetArea | Qt.BottomDockWidgetArea
height: 100
minimumHeight: 100
maximumHeight: 100
minimumHeight: 30
maximumHeight: 30
DrumsetPanel {
anchors.fill: parent

View file

@ -196,17 +196,28 @@ DockPanelHolder* DockPage::panelHolderByLocation(DockBase::DockLocation location
return nullptr;
}
bool DockPage::isDockShown(const QString& dockName) const
bool DockPage::isDockOpened(const QString& dockName) const
{
const DockBase* dock = dockByName(dockName);
return dock ? dock->isShown() : false;
return dock ? dock->isOpen() : false;
}
void DockPage::toggleDockVisibility(const QString& dockName)
void DockPage::toggleDock(const QString& dockName)
{
setDockOpened(dockName, !isDockOpened(dockName));
}
void DockPage::setDockOpened(const QString &dockName, bool opened)
{
DockBase* dock = dockByName(dockName);
if (dock) {
dock->toggle();
if (!dock) {
return;
}
if (opened) {
dock->open();
} else {
dock->close();
}
}
@ -245,7 +256,7 @@ void DockPage::close()
TRACEFUNC;
for (DockBase* dock : allDocks()) {
dock->hide();
dock->close();
}
}

View file

@ -77,8 +77,9 @@ public:
DockToolBarHolder* toolBarHolderByLocation(DockBase::DockLocation location) const;
DockPanelHolder* panelHolderByLocation(DockBase::DockLocation location) const;
bool isDockShown(const QString& dockName) const;
void toggleDockVisibility(const QString& dockName);
bool isDockOpened(const QString& dockName) const;
void toggleDock(const QString& dockName);
void setDockOpened(const QString& dockName, bool opened);
public slots:
void setUri(const QString& uri);

View file

@ -98,7 +98,7 @@ void DockWindow::componentComplete()
hideCurrentToolBarDockingHolder();
if (holder) {
holder->show();
holder->open();
}
}
@ -124,7 +124,7 @@ void DockWindow::componentComplete()
if (holder) {
qDebug() << holder->location();
holder->show();
holder->open();
}
}
@ -195,7 +195,7 @@ void DockWindow::loadPage(const QString& uri)
for (DockBase* dock : newPage->allDocks()) {
if (!dock->isVisible()) {
dock->hide();
dock->close();
}
}
@ -203,17 +203,25 @@ void DockWindow::loadPage(const QString& uri)
emit currentPageUriChanged(uri);
}
bool DockWindow::isDockShown(const QString& dockName) const
bool DockWindow::isDockOpened(const QString& dockName) const
{
const DockPage* currPage = currentPage();
return currPage ? currPage->isDockShown(dockName) : false;
return currPage ? currPage->isDockOpened(dockName) : false;
}
void DockWindow::toggleDockVisibility(const QString& dockName)
void DockWindow::toggleDock(const QString& dockName)
{
DockPage* currPage = currentPage();
if (currPage) {
currPage->toggleDockVisibility(dockName);
currPage->toggleDock(dockName);
}
}
void DockWindow::setDockOpened(const QString& dockName, bool opened)
{
DockPage* currPage = currentPage();
if (currPage) {
currPage->setDockOpened(dockName, opened);
}
}
@ -258,7 +266,7 @@ void DockWindow::loadPageContent(const DockPage* page)
}
addDock(m_mainToolBarDockingHolder, KDDockWidgets::Location_OnTop);
m_mainToolBarDockingHolder->hide();
m_mainToolBarDockingHolder->close();
unitePanelsToTabs(page);
}
@ -562,7 +570,7 @@ void DockWindow::hideCurrentToolBarDockingHolder()
return;
}
m_currentToolBarDockingHolder->hide();
m_currentToolBarDockingHolder->close();
m_currentToolBarDockingHolder = nullptr;
}
@ -572,7 +580,7 @@ void DockWindow::hideCurrentPanelDockingHolder()
return;
}
m_currentPanelDockingHolder->hide();
m_currentPanelDockingHolder->close();
m_currentPanelDockingHolder = nullptr;
}

View file

@ -74,8 +74,9 @@ public:
Q_INVOKABLE void loadPage(const QString& uri);
bool isDockShown(const QString& dockName) const;
void toggleDockVisibility(const QString& dockName);
bool isDockOpened(const QString& dockName) const;
void toggleDock(const QString& dockName);
void setDockOpened(const QString& dockName, bool opened);
public slots:
void setMainToolBarDockingHolder(DockToolBarHolder* mainToolBarDockingHolder);

View file

@ -199,7 +199,7 @@ void DockBase::init()
applySizeConstraints();
}
bool DockBase::isShown() const
bool DockBase::isOpen() const
{
IF_ASSERT_FAILED(m_dockWidget) {
return false;
@ -208,7 +208,7 @@ bool DockBase::isShown() const
return m_dockWidget->isOpen();
}
void DockBase::show()
void DockBase::open()
{
IF_ASSERT_FAILED(m_dockWidget) {
return;
@ -217,7 +217,7 @@ void DockBase::show()
m_dockWidget->show();
}
void DockBase::hide()
void DockBase::close()
{
IF_ASSERT_FAILED(m_dockWidget) {
return;
@ -226,15 +226,6 @@ void DockBase::hide()
m_dockWidget->forceClose();
}
void DockBase::toggle()
{
if (isShown()) {
hide();
} else {
show();
}
}
DockBase::DockLocation DockBase::location() const
{
return m_location;

View file

@ -75,10 +75,9 @@ public:
virtual void init();
bool isShown() const;
void show();
void hide();
void toggle();
bool isOpen() const;
void open();
void close();
DockLocation location() const;

View file

@ -26,6 +26,7 @@
#include "dockwindow/dockwindow.h"
using namespace mu::appshell;
using namespace mu::notation;
NotationPageModel::NotationPageModel(QObject* parent)
: QObject(parent)
@ -87,6 +88,11 @@ void NotationPageModel::setTimelineDockName(const QString& dockName)
setPanelDockName(PanelType::Timeline, dockName);
}
void NotationPageModel::setDrumsetPanelDockName(const QString& dockName)
{
setPanelDockName(PanelType::DrumsetPanel, dockName);
}
void NotationPageModel::setStatusBarDockName(const QString& dockName)
{
setPanelDockName(PanelType::NotationStatusBar, dockName);
@ -110,7 +116,7 @@ void NotationPageModel::init(QQuickItem* dockWindow)
std::map<PanelType, bool> initialState;
for (PanelType type : m_panelTypeToDockName.keys()) {
initialState[type] = m_window->isDockShown(m_panelTypeToDockName[type]);
initialState[type] = m_window->isDockOpened(m_panelTypeToDockName[type]);
}
pageState()->setIsPanelsVisible(initialState);
@ -126,7 +132,7 @@ void NotationPageModel::init(QQuickItem* dockWindow)
{ "toggle-noteinput", PanelType::NoteInputBar },
{ "toggle-notationtoolbar", PanelType::NotationToolBar },
{ "toggle-undoredo", PanelType::UndoRedoToolBar },
{ "toggle-transport", PanelType::PlaybackToolBar }
{ "toggle-transport", PanelType::PlaybackToolBar },
};
for (const std::string& actionCode : actionToPanelType.keys()) {
@ -140,6 +146,11 @@ void NotationPageModel::init(QQuickItem* dockWindow)
}
}
});
updateDrumsetPanelVisibility();
globalContext()->currentNotationChanged().onNotify(this, [=]() {
updateDrumsetPanelVisibility();
});
}
void NotationPageModel::togglePanel(PanelType type)
@ -151,5 +162,26 @@ void NotationPageModel::togglePanel(PanelType type)
bool visible = pageState()->isPanelVisible(type);
pageState()->setIsPanelsVisible({ { type, !visible } });
m_window->toggleDockVisibility(m_panelTypeToDockName[type]);
m_window->toggleDock(m_panelTypeToDockName[type]);
}
void NotationPageModel::updateDrumsetPanelVisibility()
{
auto setDrumsetPanelVisible = [this](bool visible) {
m_window->setDockOpened(m_panelTypeToDockName[PanelType::DrumsetPanel], visible);
pageState()->setIsPanelsVisible({ { PanelType::DrumsetPanel, visible } });
};
setDrumsetPanelVisible(false);
INotationPtr notation = globalContext()->currentNotation();
if (!notation) {
return;
}
INotationNoteInputPtr noteInput = notation->interaction()->noteInput();
noteInput->stateChanged().onNotify(this, [noteInput, setDrumsetPanelVisible]() {
bool visible = noteInput->isNoteInputMode() && noteInput->state().drumset != nullptr;
setDrumsetPanelVisible(visible);
});
}

View file

@ -28,6 +28,7 @@
#include "async/asyncable.h"
#include "actions/actionable.h"
#include "actions/iactionsdispatcher.h"
#include "context/iglobalcontext.h"
#include "inotationpagestate.h"
namespace mu::dock {
@ -41,6 +42,7 @@ class NotationPageModel : public QObject, public async::Asyncable, public action
INJECT(appshell, INotationPageState, pageState)
INJECT(appshell, actions::IActionsDispatcher, dispatcher)
INJECT(appshell, context::IGlobalContext, globalContext)
Q_PROPERTY(bool isNavigatorVisible READ isNavigatorVisible NOTIFY isNavigatorVisibleChanged)
@ -61,6 +63,7 @@ public:
Q_INVOKABLE void setPianoRollDockName(const QString& dockName);
Q_INVOKABLE void setMixerDockName(const QString& dockName);
Q_INVOKABLE void setTimelineDockName(const QString& dockName);
Q_INVOKABLE void setDrumsetPanelDockName(const QString& dockName);
Q_INVOKABLE void setStatusBarDockName(const QString& dockName);
@ -73,6 +76,8 @@ private:
void setPanelDockName(PanelType type, const QString& dockName);
void togglePanel(PanelType type);
void updateDrumsetPanelVisibility();
QMap<PanelType, QString /* dockName */> m_panelTypeToDockName;
dock::DockWindow* m_window = nullptr;
};

View file

@ -44,6 +44,7 @@ public:
virtual void putNote(const QPointF& pos, bool replace, bool insert) = 0;
virtual void setAccidental(AccidentalType accidentalType) = 0;
virtual void setArticulation(SymbolId articulationSymbolId) = 0;
virtual void setDrumNote(int note) = 0;
virtual void addTuplet(const TupletOptions& options) = 0;
virtual void addSlur(Ms::Slur* slur) = 0;

View file

@ -60,7 +60,7 @@ bool NotationNoteInput::isNoteInputMode() const
NoteInputState NotationNoteInput::state() const
{
Ms::InputState& inputState = score()->inputState();
const Ms::InputState& inputState = score()->inputState();
NoteInputState noteInputState;
noteInputState.method = inputState.noteEntryMethod();
@ -69,6 +69,8 @@ NoteInputState NotationNoteInput::state() const
noteInputState.articulationIds = articulationIds();
noteInputState.withSlur = inputState.slur() != nullptr;
noteInputState.currentVoiceIndex = inputState.voice();
noteInputState.currentTrack = inputState.track();
noteInputState.drumset = inputState.drumset();
noteInputState.isRest = inputState.rest();
return noteInputState;
@ -209,6 +211,7 @@ void NotationNoteInput::putNote(const QPointF& pos, bool replace, bool insert)
apply();
notifyNoteAddedChanged();
notifyAboutStateChanged();
}
void NotationNoteInput::setAccidental(AccidentalType accidentalType)
@ -231,6 +234,12 @@ void NotationNoteInput::setArticulation(SymbolId articulationSymbolId)
notifyAboutStateChanged();
}
void NotationNoteInput::setDrumNote(int note)
{
score()->inputState().setDrumNote(note);
notifyAboutStateChanged();
}
void NotationNoteInput::setCurrentVoiceIndex(int voiceIndex)
{
if (!isVoiceIndexValid(voiceIndex)) {

View file

@ -56,6 +56,7 @@ public:
void putNote(const QPointF& pos, bool replace, bool insert) override;
void setAccidental(AccidentalType accidentalType) override;
void setArticulation(SymbolId articulationSymbolId) override;
void setDrumNote(int note) override;
void addTuplet(const TupletOptions& options) override;
void addSlur(Ms::Slur* slur) override;

View file

@ -223,6 +223,8 @@ struct NoteInputState
bool isRest = false;
bool withSlur = false;
int currentVoiceIndex = 0;
int currentTrack = 0;
const Drumset* drumset = nullptr;
};
enum class NoteFilter

View file

@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "drumsetpanel.h"
#include "drumsetpalette.h"
#include "translation.h"
#include "log.h"
@ -35,72 +35,70 @@
#include "libmscore/mscore.h"
#include "libmscore/undo.h"
using namespace mu::notation;
namespace Ms {
DrumsetPanel::DrumsetPanel(QWidget* parent)
DrumsetPalette::DrumsetPalette(QWidget* parent)
: PaletteScrollArea(nullptr, parent)
{
setObjectName("DrumsetPanel");
setObjectName("DrumsetPalette");
setFocusPolicy(Qt::NoFocus);
drumPalette = new Palette(this);
drumPalette->setMag(0.8);
drumPalette->setSelectable(true);
drumPalette->setUseDoubleClickToActivate(true);
drumPalette->setGrid(28, 60);
drumPalette->setContextMenuPolicy(Qt::PreventContextMenu);
m_drumPalette = new Palette(this);
m_drumPalette->setMag(0.8);
m_drumPalette->setSelectable(true);
m_drumPalette->setUseDoubleClickToActivate(true);
m_drumPalette->setGrid(28, 60);
m_drumPalette->setContextMenuPolicy(Qt::PreventContextMenu);
setWidget(drumPalette);
setWidget(m_drumPalette);
retranslate();
connect(drumPalette, SIGNAL(boxClicked(int)), SLOT(drumNoteSelected(int)));
connect(m_drumPalette, SIGNAL(boxClicked(int)), SLOT(drumNoteSelected(int)));
}
void DrumsetPanel::setNotation(mu::notation::INotationPtr notation)
void DrumsetPalette::setNotation(INotationPtr notation)
{
m_notation = notation;
updateDrumset();
}
Score* DrumsetPanel::score() const
void DrumsetPalette::retranslate()
{
return m_notation ? m_notation->elements()->msScore() : nullptr;
m_drumPalette->setName(mu::qtrc("palette", "Drumset"));
}
void DrumsetPanel::retranslate()
void DrumsetPalette::updateDrumset()
{
drumPalette->setName(mu::qtrc("palette", "Drumset"));
}
void DrumsetPanel::updateDrumset()
{
Score* score = this->score();
if (!score) {
INotationNoteInputPtr noteInput = this->noteInput();
if (!noteInput) {
return;
}
drumPalette->clear();
m_drumPalette->clear();
const InputState& inputState = score->inputState();
drumset = inputState.drumset();
staff = score->staff(inputState.track() / VOICES);
NoteInputState state = noteInput->state();
m_drumset = state.drumset;
if (!drumset) {
if (!m_drumset) {
return;
}
TRACEFUNC;
double _spatium = gscore->spatium();
for (int pitch = 0; pitch < 128; ++pitch) {
if (!drumset->isValid(pitch)) {
if (!m_drumset->isValid(pitch)) {
continue;
}
bool up;
int line = drumset->line(pitch);
NoteHead::Group noteHead = drumset->noteHead(pitch);
int voice = drumset->voice(pitch);
Direction dir = drumset->stemDirection(pitch);
bool up = false;
int line = m_drumset->line(pitch);
NoteHead::Group noteHead = m_drumset->noteHead(pitch);
int voice = m_drumset->voice(pitch);
Direction dir = m_drumset->stemDirection(pitch);
if (dir == Direction::UP) {
up = true;
} else if (dir == Direction::DOWN) {
@ -128,63 +126,63 @@ void DrumsetPanel::updateDrumset()
note->setHeadGroup(noteHead);
SymId noteheadSym = SymId::noteheadBlack;
if (noteHead == NoteHead::Group::HEAD_CUSTOM) {
noteheadSym = drumset->noteHeads(pitch, NoteHead::Type::HEAD_QUARTER);
noteheadSym = m_drumset->noteHeads(pitch, NoteHead::Type::HEAD_QUARTER);
} else {
noteheadSym = note->noteHead(true, noteHead, NoteHead::Type::HEAD_QUARTER);
}
note->setCachedNoteheadSym(noteheadSym); // we use the cached notehead so we don't recompute it at each layout
chord->add(note);
int sc = drumset->shortcut(pitch);
int sc = m_drumset->shortcut(pitch);
QString shortcut;
if (sc) {
shortcut = QChar(sc);
}
drumPalette->append(chord, mu::qtrc("drumset", drumset->name(pitch).toUtf8().data()), shortcut);
m_drumPalette->append(chord, mu::qtrc("drumset", m_drumset->name(pitch).toUtf8().data()), shortcut);
}
}
void DrumsetPanel::drumNoteSelected(int val)
void DrumsetPalette::drumNoteSelected(int val)
{
Score* score = this->score();
if (!score) {
INotationNoteInputPtr noteInput = this->noteInput();
if (!noteInput) {
return;
}
ElementPtr element = drumPalette->element(val);
ElementPtr element = m_drumPalette->element(val);
if (!element || element->type() != ElementType::CHORD) {
return;
}
TRACEFUNC;
const Chord* ch = dynamic_cast<Chord*>(element.get());
const Note* note = ch->downNote();
int pitch = note->pitch();
int voice = element->voice();
int track = (score->inputState().track() / VOICES) * VOICES + element->track();
score->inputState().setTrack(track);
score->inputState().setDrumNote(pitch);
m_notation->interaction()->noteInput()->stateChanged().notify();
noteInput->setCurrentVoiceIndex(voice);
noteInput->setDrumNote(pitch);
QString voiceActionCode = QString("voice-%1").arg(element->voice() + 1);
QString voiceActionCode = QString("voice-%1").arg(voice + 1);
dispatcher()->dispatch(voiceActionCode.toStdString());
auto pitchCell = drumPalette->cellAt(val);
auto pitchCell = m_drumPalette->cellAt(val);
m_pitchNameChanged.send(pitchCell->name);
}
int DrumsetPanel::selectedDrumNote()
int DrumsetPalette::selectedDrumNote()
{
int idx = drumPalette->getSelectedIdx();
int idx = m_drumPalette->getSelectedIdx();
if (idx < 0) {
return -1;
}
ElementPtr element = drumPalette->element(idx);
ElementPtr element = m_drumPalette->element(idx);
if (element && element->type() == ElementType::CHORD) {
const Chord* ch = dynamic_cast<Chord*>(element.get());
const Note* note = ch->downNote();
auto pitchCell = drumPalette->cellAt(idx);
auto pitchCell = m_drumPalette->cellAt(idx);
m_pitchNameChanged.send(pitchCell->name);
return note->pitch();
}
@ -192,7 +190,7 @@ int DrumsetPanel::selectedDrumNote()
return -1;
}
void DrumsetPanel::changeEvent(QEvent* event)
void DrumsetPalette::changeEvent(QEvent* event)
{
QWidget::changeEvent(event);
if (event->type() == QEvent::LanguageChange) {
@ -200,23 +198,28 @@ void DrumsetPanel::changeEvent(QEvent* event)
}
}
void DrumsetPanel::mousePressEvent(QMouseEvent* event)
void DrumsetPalette::mousePressEvent(QMouseEvent* event)
{
drumPalette->handleEvent(event);
m_drumPalette->handleEvent(event);
}
void DrumsetPanel::mouseMoveEvent(QMouseEvent* event)
void DrumsetPalette::mouseMoveEvent(QMouseEvent* event)
{
drumPalette->handleEvent(event);
m_drumPalette->handleEvent(event);
}
bool DrumsetPanel::handleEvent(QEvent* e)
bool DrumsetPalette::handleEvent(QEvent* e)
{
return QWidget::event(e);
}
mu::async::Channel<QString> DrumsetPanel::pitchNameChanged() const
mu::async::Channel<QString> DrumsetPalette::pitchNameChanged() const
{
return m_pitchNameChanged;
}
INotationNoteInputPtr DrumsetPalette::noteInput() const
{
return m_notation ? m_notation->interaction()->noteInput() : nullptr;
}
}

View file

@ -20,8 +20,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MU_PALETTE_DRUMSETPANEL_H
#define MU_PALETTE_DRUMSETPANEL_H
#ifndef MU_PALETTE_DRUMSETPALETTE_H
#define MU_PALETTE_DRUMSETPALETTE_H
#include "palette/palette.h"
#include "notation/inotation.h"
@ -34,14 +34,14 @@ class Score;
class Drumset;
class Staff;
class DrumsetPanel : public PaletteScrollArea
class DrumsetPalette : public PaletteScrollArea
{
Q_OBJECT
INJECT(Ms, mu::actions::IActionsDispatcher, dispatcher)
public:
explicit DrumsetPanel(QWidget* parent = nullptr);
explicit DrumsetPalette(QWidget* parent = nullptr);
void setNotation(mu::notation::INotationPtr notation);
void updateDrumset();
@ -60,15 +60,14 @@ private:
int selectedDrumNote();
void retranslate();
Score* score() const;
mu::notation::INotationNoteInputPtr noteInput() const;
Staff* staff = nullptr;
Palette* drumPalette = nullptr;
const Drumset* drumset = nullptr;
Palette* m_drumPalette = nullptr;
const Drumset* m_drumset = nullptr;
mu::notation::INotationPtr m_notation;
mu::async::Channel<QString> m_pitchNameChanged;
};
} // namespace Ms
#endif // MU_PALETTE_DRUMSETPANEL_H
#endif // MU_PALETTE_DRUMSETPALETTE_H

View file

@ -31,22 +31,28 @@ Rectangle {
RowLayout {
anchors.fill: parent
anchors.leftMargin: 26
anchors.rightMargin: 26
spacing: 6
spacing: 26
Column {
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: 175
Layout.leftMargin: 26
spacing: 6
StyledTextLabel {
anchors.horizontalCenter: parent.horizontalCenter
height: 20
width: editDrumsetButton.width
text: drumsetView.pitchName
}
FlatButton {
id: editDrumsetButton
text: qsTrc("palette", "Edit drumset")
onClicked: {

View file

@ -1,50 +1,50 @@
#include "drumsetpanelview.h"
#include "internal/widgets/drumsetpanel.h"
#include "internal/widgets/drumsetpalette.h"
using namespace mu::notation;
namespace mu::palette {
class DrumsetPanelAdapter : public ui::IDisplayableWidget
class DrumsetPaletteAdapter : public ui::IDisplayableWidget
{
public:
DrumsetPanelAdapter()
: m_msDrumsetPanel(new Ms::DrumsetPanel())
DrumsetPaletteAdapter()
: m_msDrumsetPalette(new Ms::DrumsetPalette())
{
}
~DrumsetPanelAdapter() override
~DrumsetPaletteAdapter() override
{
delete m_msDrumsetPanel;
delete m_msDrumsetPalette;
}
void setNotation(INotationPtr notation)
{
m_msDrumsetPanel->setNotation(notation);
m_msDrumsetPalette->setNotation(notation);
}
void updateDrumset()
{
m_msDrumsetPanel->updateDrumset();
m_msDrumsetPalette->updateDrumset();
}
async::Channel<QString> pitchNameChanged() const
{
return m_msDrumsetPanel->pitchNameChanged();
return m_msDrumsetPalette->pitchNameChanged();
}
private:
QWidget* qWidget() override
{
return m_msDrumsetPanel;
return m_msDrumsetPalette;
}
bool handleEvent(QEvent* event) override
{
return m_msDrumsetPanel->handleEvent(event);
return m_msDrumsetPalette->handleEvent(event);
}
Ms::DrumsetPanel* m_msDrumsetPanel = nullptr;
Ms::DrumsetPalette* m_msDrumsetPalette = nullptr;
};
}
@ -69,16 +69,16 @@ void DrumsetPanelView::componentComplete()
{
WidgetView::componentComplete();
auto drumsetPanel = std::make_shared<DrumsetPanelAdapter>();
auto drumsetPalette = std::make_shared<DrumsetPaletteAdapter>();
auto updateView = [this, drumsetPanel]() {
drumsetPanel->updateDrumset();
auto updateView = [this, drumsetPalette]() {
drumsetPalette->updateDrumset();
update();
};
globalContext()->currentNotationChanged().onNotify(this, [this, drumsetPanel, updateView]() {
globalContext()->currentNotationChanged().onNotify(this, [this, drumsetPalette, updateView]() {
INotationPtr notation = globalContext()->currentNotation();
drumsetPanel->setNotation(notation);
drumsetPalette->setNotation(notation);
updateView();
if (!notation) {
@ -90,10 +90,10 @@ void DrumsetPanelView::componentComplete()
});
});
drumsetPanel->pitchNameChanged().onReceive(this, [this](const QString& pitchName) {
drumsetPalette->pitchNameChanged().onReceive(this, [this](const QString& pitchName) {
m_pitchName = pitchName;
emit pitchNameChanged();
});
setWidget(drumsetPanel);
setWidget(drumsetPalette);
}

View file

@ -129,9 +129,12 @@ EditDrumsetDialog::EditDrumsetDialog(QWidget* parent)
setObjectName(EDIT_DRUMSET_DIALOG_NAME);
m_notation = globalContext()->currentNotation();
const INotationInteractionPtr interaction = m_notation ? m_notation->interaction() : nullptr;
INotationInteraction::HitElementContext context
= interaction ? interaction->hitElementContext() : INotationInteraction::HitElementContext();
if (!m_notation) {
return;
}
const INotationInteractionPtr interaction = m_notation->interaction();
INotationInteraction::HitElementContext context = interaction->hitElementContext();
const Measure* measure = toMeasure(context.element);
if (measure && context.staff) {
@ -139,6 +142,12 @@ EditDrumsetDialog::EditDrumsetDialog(QWidget* parent)
m_instrumentId = instrument->getId();
m_partId = context.staff->part()->id();
m_editedDrumset = *instrument->drumset();
} else {
NoteInputState state = m_notation->interaction()->noteInput()->state();
const Staff* staff = m_notation->elements()->msScore()->staff(track2staff(state.currentTrack));
m_instrumentId = staff ? staff->part()->instrumentId() : QString();
m_partId = staff ? staff->part()->id() : QString();
m_editedDrumset = state.drumset ? *state.drumset : Drumset();
}
setupUi(this);

View file

@ -19,8 +19,8 @@ set(WIDGETS_SRC
${CMAKE_CURRENT_LIST_DIR}/specialcharactersdialog.h
${CMAKE_CURRENT_LIST_DIR}/editdrumsetdialog.h
${CMAKE_CURRENT_LIST_DIR}/editdrumsetdialog.cpp
${CMAKE_CURRENT_LIST_DIR}/drumsetpanel.cpp
${CMAKE_CURRENT_LIST_DIR}/drumsetpanel.h
${CMAKE_CURRENT_LIST_DIR}/drumsetpalette.cpp
${CMAKE_CURRENT_LIST_DIR}/drumsetpalette.h
)
set (WIDGETS_UI