Skip to content

Commit

Permalink
Percussion mouse input popup - implement percussion note popup content
Browse files Browse the repository at this point in the history
  • Loading branch information
mathesoncalum committed Feb 7, 2025
1 parent 3f3dabd commit 54069cb
Show file tree
Hide file tree
Showing 13 changed files with 468 additions and 26 deletions.
14 changes: 13 additions & 1 deletion src/engraving/dom/noteentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,18 @@ NoteVal Score::noteValForPosition(Position pos, AccidentalType at, bool& error)
break;
}
const Drumset* ds = instr->drumset();
nval.pitch = m_is.drumNote();
nval.pitch = m_is.drumNote();
if (nval.pitch < 0 || !ds->isValid(nval.pitch) || ds->line(nval.pitch) != line) {
// Drum note from input state is not valid - fall back to the first valid pitch for this line...
m_is.setDrumNote(-1);
for (int pitch = 0; pitch < mu::engraving::DRUM_INSTRUMENTS; ++pitch) {
if (!ds->isValid(pitch) || ds->line(pitch) != line) {
continue;
}
nval.pitch = pitch;
break;
}
}
if (nval.pitch < 0) {
error = true;
return nval;
Expand Down Expand Up @@ -447,6 +458,7 @@ Ret Score::putNote(const Position& p, bool replace)

if (ds) {
stemDirection = ds->stemDirection(nval.pitch);
m_is.setVoice(ds->voice(nval.pitch));
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/shadownote.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ShadowNote final : public EngravingItem
SymId flagSym() const;
AccidentalType accidentalType() const;
const std::set<SymId>& articulationIds() const;

double segmentSkylineBottomY() const;
double segmentSkylineTopY() const;

Expand Down
4 changes: 4 additions & 0 deletions src/notation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/view/internal/dynamicpopupmodel.h
${CMAKE_CURRENT_LIST_DIR}/view/internal/partialtiepopupmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/internal/partialtiepopupmodel.h

${CMAKE_CURRENT_LIST_DIR}/view/internal/shadownotepopupmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/internal/shadownotepopupmodel.h
${CMAKE_CURRENT_LIST_DIR}/view/internal/percussionnotepopupcontentmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/internal/percussionnotepopupcontentmodel.h

${CMAKE_CURRENT_LIST_DIR}/view/selectionfiltermodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/selectionfiltermodel.h
${CMAKE_CURRENT_LIST_DIR}/view/editgridsizedialogmodel.cpp
Expand Down
43 changes: 29 additions & 14 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,10 @@ bool NotationInteraction::showShadowNote(const PointF& pos)
params.accidentalType = inputState.accidentalType();
params.articulationIds = inputState.articulationIds();

showShadowNoteAtPosition(shadowNote, params, position);
return true;
return showShadowNoteAtPosition(shadowNote, params, position);
}

void NotationInteraction::showShadowNoteAtPosition(ShadowNote& shadowNote, const ShadowNoteParams& params, Position& position)
bool NotationInteraction::showShadowNoteAtPosition(ShadowNote& shadowNote, const ShadowNoteParams& params, Position& position)
{
const mu::engraving::InputState& inputState = score()->inputState();
const Staff* staff = score()->staff(position.staffIdx);
Expand All @@ -414,20 +413,35 @@ void NotationInteraction::showShadowNoteAtPosition(ShadowNote& shadowNote, const

mu::engraving::NoteHeadGroup noteheadGroup = mu::engraving::NoteHeadGroup::HEAD_NORMAL;
mu::engraving::NoteHeadType noteHead = params.duration.headType();

int line = position.line;
voice_idx_t voice = 0;
int drumNotePitch = -1;

if (instr->useDrumset()) {
const mu::engraving::Drumset* ds = instr->drumset();
int pitch = inputState.drumNote();
if (pitch >= 0 && ds->isValid(pitch)) {
line = ds->line(pitch);
noteheadGroup = ds->noteHead(pitch);
}
}
const Drumset* ds = instr->drumset();

voice_idx_t voice = 0;
if (inputState.drumNote() != -1 && inputState.drumset() && inputState.drumset()->isValid(inputState.drumNote())) {
voice = inputState.drumset()->voice(inputState.drumNote());
const int noteInputPitch = inputState.drumNote();

if (noteInputPitch > 0 && ds->isValid(noteInputPitch) && ds->line(noteInputPitch) == line) {
noteheadGroup = ds->noteHead(noteInputPitch);
voice = ds->voice(noteInputPitch);
drumNotePitch = noteInputPitch;
} else {
for (int pitch = 0; pitch < mu::engraving::DRUM_INSTRUMENTS; ++pitch) {
if (ds->isValid(pitch) && ds->line(pitch) == line) {
noteheadGroup = ds->noteHead(pitch);
voice = ds->voice(pitch);
drumNotePitch = pitch;
break;
}
}
if (drumNotePitch < 0) {
shadowNote.setVisible(false);
m_shadowNoteChanged.notify();
return false;
}
}
} else {
voice = inputState.voice();
}
Expand Down Expand Up @@ -458,7 +472,7 @@ void NotationInteraction::showShadowNoteAtPosition(ShadowNote& shadowNote, const
delete rest;
} else {
if (mu::engraving::NoteHeadGroup::HEAD_CUSTOM == noteheadGroup) {
symNotehead = instr->drumset()->noteHeads(inputState.drumNote(), noteHead);
symNotehead = instr->drumset()->noteHeads(drumNotePitch, noteHead);
} else {
symNotehead = Note::noteHead(0, noteheadGroup, noteHead);
}
Expand All @@ -472,6 +486,7 @@ void NotationInteraction::showShadowNoteAtPosition(ShadowNote& shadowNote, const
shadowNote.setPos(position.pos);

m_shadowNoteChanged.notify();
return true;
}

void NotationInteraction::hideShadowNote()
Expand Down
2 changes: 1 addition & 1 deletion src/notation/internal/notationinteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class NotationInteraction : public INotationInteraction, public muse::Injectable
std::set<SymId> articulationIds;
};

void showShadowNoteAtPosition(mu::engraving::ShadowNote& note, const ShadowNoteParams& params, mu::engraving::Position& pos);
bool showShadowNoteAtPosition(mu::engraving::ShadowNote& note, const ShadowNoteParams& params, mu::engraving::Position& pos);

bool needStartEditGrip(QKeyEvent* event) const;
bool handleKeyPress(QKeyEvent* event);
Expand Down
3 changes: 3 additions & 0 deletions src/notation/notationmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
#include "view/internal/stringtuningssettingsmodel.h"
#include "view/internal/dynamicpopupmodel.h"
#include "view/internal/partialtiepopupmodel.h"

#include "view/internal/shadownotepopupmodel.h"
#include "view/internal/percussionnotepopupcontentmodel.h"

#include "view/percussionpanel/percussionpanelmodel.h"

Expand Down Expand Up @@ -201,6 +203,7 @@ void NotationModule::registerUiTypes()

qmlRegisterUncreatableType<ShadowNotePopupContent>("MuseScore.NotationScene", 1, 0, "ShadowNotePopupContent", "Cannot create");
qmlRegisterType<ShadowNotePopupModel>("MuseScore.NotationScene", 1, 0, "ShadowNotePopupModel");
qmlRegisterType<PercussionNotePopupContentModel>("MuseScore.NotationScene", 1, 0, "PercussionNotePopupContentModel");

qmlRegisterType<PaintedEngravingItem>("MuseScore.NotationScene", 1, 0, "PaintedEngravingItem");

Expand Down
1 change: 1 addition & 0 deletions src/notation/notationscene.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@
<file>qml/MuseScore/NotationScene/internal/PartialTieMenuRowItem.qml</file>
<file>qml/MuseScore/NotationScene/EditPercussionShortcutDialog.qml</file>
<file>qml/MuseScore/NotationScene/internal/ShadowNotePopup.qml</file>
<file>qml/MuseScore/NotationScene/internal/PercussionNotePopupContent.qml</file>
</qresource>
</RCC>
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-Studio-CLA-applies
*
* MuseScore Studio
* Music Composition & Notation
*
* Copyright (C) 2025 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/>.
*/

import QtQuick 2.15

import Muse.Ui 1.0
import Muse.UiComponents 1.0
import MuseScore.NotationScene 1.0

Row {
id: root

height: 72
spacing: 6

PercussionNotePopupContentModel {
id: contentModel

Component.onCompleted: {
contentModel.init()
}
}

Row {
id: buttonRow

visible: contentModel.shouldShowButtons

height: root.height
spacing: 6

FlatButton {
id: prevButton

height: buttonRow.height
width: 48

contentItem: StyledIconLabel {
iconCode: IconCode.CHEVRON_LEFT
font.pixelSize: 36
}

onClicked: {
contentModel.prevDrumNote()
}
}

FlatButton {
id: nextButton

height: buttonRow.height
width: 48

contentItem: StyledIconLabel {
iconCode: IconCode.CHEVRON_RIGHT
font.pixelSize: 36
}

onClicked: {
contentModel.nextDrumNote()
}
}
}

Row {
id: labelRow

height: root.height
spacing: 18

rightPadding: 18
leftPadding: 18

StyledTextLabel {
id: percussionNoteName

height: labelRow.height
verticalAlignment: Text.AlignVCenter

text: contentModel.percussionNoteName
font: ui.theme.headerBoldFont
}

StyledTextLabel {
id: keyboardShortcut

height: labelRow.height
verticalAlignment: Text.AlignVCenter

text: contentModel.keyboardShortcut
font: ui.theme.headerBoldFont
opacity: 0.8
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ StyledPopupView {
takeFocusOnClick: false

padding: 0 // The popup will "steal" mouse events if the padding overlaps with the shadow note area
margins: 0
margins: 6

signal elementRectChanged(var elementRect)

Expand Down Expand Up @@ -75,11 +75,7 @@ StyledPopupView {

Component {
id: percussionContent

Rectangle { // Placeholder...
color: "red"
width: 200
height: 50
PercussionNotePopupContent {
}
}
}
Expand Down
Loading

0 comments on commit 54069cb

Please sign in to comment.