Skip to content

Commit a0e3c29

Browse files
Merge pull request #26075 from mathesoncalum/percussion_refinements_5
Percussion panel - refinements round 5
2 parents fcdafac + 9dcbfac commit a0e3c29

File tree

9 files changed

+155
-101
lines changed

9 files changed

+155
-101
lines changed

src/appshell/qml/NotationPage/NotationPage.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@ DockPage {
554554
Component.onDestruction: {
555555
percussionPanel.toolbarComponent = null
556556
}
557+
558+
onResizeRequested: function(newWidth, newHeight) {
559+
percussionPanel.resize(newWidth, newHeight)
560+
}
557561
}
558562
}
559563
]

src/appshell/qml/Preferences/PercussionPreferencesPage.qml

Lines changed: 95 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ PreferencesPage {
4343
id: percussionPanelPreferences
4444

4545
title: qsTrc("appshell/preferences", "Percussion")
46+
rowSpacing: 20
4647

4748
navigation.section: root.navigationSection
4849

4950
CheckBox {
5051
id: unpitchedSelectedCheckbox
5152

52-
visible: percussionPreferencesModel.useNewPercussionPanel
53+
enabled: percussionPreferencesModel.useNewPercussionPanel
5354
width: parent.width
5455

5556
text: qsTrc("appshell/preferences", "Open the percussion panel when an unpitched staff is selected")
@@ -65,109 +66,138 @@ PreferencesPage {
6566
}
6667
}
6768

68-
StyledTextLabel {
69-
id: padSwapInfo
69+
Column {
70+
id: swappingOptionsColumn
7071

71-
visible: percussionPreferencesModel.useNewPercussionPanel
7272
width: parent.width
73+
spacing: 12
7374

74-
horizontalAlignment: Text.AlignLeft
75-
wrapMode: Text.Wrap
76-
text: qsTrc("notation/percussion", "When swapping the positions of two drum pads:")
77-
}
78-
79-
RadioButtonGroup {
80-
id: radioButtons
75+
StyledTextLabel {
76+
id: padSwapInfo
8177

82-
property int navigationRowStart: unpitchedSelectedCheckbox.navigation.row + 1
83-
property int navigationRowEnd: radioButtons.navigationRowStart + model.length
78+
enabled: percussionPreferencesModel.useNewPercussionPanel
79+
width: parent.width
8480

85-
visible: percussionPreferencesModel.useNewPercussionPanel
81+
horizontalAlignment: Text.AlignLeft
82+
wrapMode: Text.Wrap
83+
text: qsTrc("notation/percussion", "When swapping the positions of two drum pads:")
84+
}
8685

87-
width: parent.width
88-
spacing: percussionPanelPreferences.spacing
86+
RadioButtonGroup {
87+
id: radioButtons
8988

90-
orientation: ListView.Vertical
89+
property int navigationRowStart: unpitchedSelectedCheckbox.navigation.row + 1
90+
property int navigationRowEnd: radioButtons.navigationRowStart + model.length
9191

92-
model: [
93-
{ text: qsTrc("notation/percussion", "Move MIDI notes and keyboard shortcuts with their sounds"), value: true },
94-
{ text: qsTrc("notation/percussion", "Leave MIDI notes and keyboard shortcuts fixed to original pad positions"), value: false }
95-
]
92+
enabled: percussionPreferencesModel.useNewPercussionPanel
9693

97-
delegate: Row {
9894
width: parent.width
99-
spacing: 6
95+
spacing: swappingOptionsColumn.spacing
96+
97+
orientation: ListView.Vertical
98+
99+
model: [
100+
{ text: qsTrc("notation/percussion", "Move MIDI notes and keyboard shortcuts with their sounds"), value: true },
101+
{ text: qsTrc("notation/percussion", "Leave MIDI notes and keyboard shortcuts fixed to original pad positions"), value: false }
102+
]
103+
104+
delegate: Row {
105+
width: parent.width
106+
spacing: 6
100107

101-
RoundedRadioButton {
102-
id: radioButton
108+
RoundedRadioButton {
109+
id: radioButton
103110

104-
anchors.verticalCenter: parent.verticalCenter
111+
anchors.verticalCenter: parent.verticalCenter
105112

106-
navigation.name: modelData.text
107-
navigation.panel: percussionPanelPreferences.navigation
108-
navigation.row: radioButtons.navigationRowStart + model.index
113+
navigation.name: modelData.text
114+
navigation.panel: percussionPanelPreferences.navigation
115+
navigation.row: radioButtons.navigationRowStart + model.index
109116

110-
checked: modelData.value === percussionPreferencesModel.percussionPanelMoveMidiNotesAndShortcuts
117+
checked: modelData.value === percussionPreferencesModel.percussionPanelMoveMidiNotesAndShortcuts
111118

112-
onToggled: {
113-
percussionPreferencesModel.percussionPanelMoveMidiNotesAndShortcuts = modelData.value
119+
onToggled: {
120+
percussionPreferencesModel.percussionPanelMoveMidiNotesAndShortcuts = modelData.value
121+
}
114122
}
115-
}
116123

117-
//! NOTE: Can't use radioButton.text because it won't wrap
118-
StyledTextLabel {
119-
width: parent.width - parent.spacing - radioButton.width
124+
//! NOTE: Can't use radioButton.text because it won't wrap
125+
StyledTextLabel {
126+
width: parent.width - parent.spacing - radioButton.width
120127

121-
anchors.verticalCenter: parent.verticalCenter
128+
anchors.verticalCenter: parent.verticalCenter
122129

123-
horizontalAlignment: Text.AlignLeft
124-
wrapMode: Text.Wrap
125-
text: modelData.text
130+
horizontalAlignment: Text.AlignLeft
131+
wrapMode: Text.Wrap
132+
text: modelData.text
126133

127-
MouseArea {
128-
id: mouseArea
134+
MouseArea {
135+
id: mouseArea
129136

130-
anchors.fill: parent
137+
anchors.fill: parent
131138

132-
onClicked: {
133-
percussionPreferencesModel.percussionPanelMoveMidiNotesAndShortcuts = modelData.value
139+
onClicked: {
140+
percussionPreferencesModel.percussionPanelMoveMidiNotesAndShortcuts = modelData.value
141+
}
134142
}
135143
}
136144
}
137145
}
146+
147+
CheckBox {
148+
id: alwaysAsk
149+
150+
enabled: percussionPreferencesModel.useNewPercussionPanel
151+
width: parent.width
152+
153+
text: qsTrc("global", "Always ask")
154+
155+
navigation.name: "AlwaysAskCheckBox"
156+
navigation.panel: percussionPanelPreferences.navigation
157+
navigation.row: radioButtons.navigationRowEnd
158+
159+
checked: percussionPreferencesModel.showPercussionPanelPadSwapDialog
160+
161+
onClicked: {
162+
percussionPreferencesModel.showPercussionPanelPadSwapDialog = !alwaysAsk.checked
163+
}
164+
}
138165
}
139166

140-
CheckBox {
141-
id: alwaysAsk
167+
Row {
168+
id: useLegacyToggleRow
142169

143-
visible: percussionPreferencesModel.useNewPercussionPanel
170+
height: useLegacyToggle.height
144171
width: parent.width
145172

146-
text: qsTrc("global", "Always ask")
173+
spacing: 6
147174

148-
navigation.name: "AlwaysAskCheckBox"
149-
navigation.panel: percussionPanelPreferences.navigation
150-
navigation.row: radioButtons.navigationRowEnd
175+
ToggleButton {
176+
id: useLegacyToggle
151177

152-
checked: percussionPreferencesModel.showPercussionPanelPadSwapDialog
178+
checked: !percussionPreferencesModel.useNewPercussionPanel
153179

154-
onClicked: {
155-
percussionPreferencesModel.showPercussionPanelPadSwapDialog = !alwaysAsk.checked
180+
navigation.name: "UseLegacyPercussionPanel"
181+
navigation.panel: percussionPanelPreferences.navigation
182+
navigation.row: alwaysAsk.navigation.row + 1
183+
184+
onToggled: {
185+
percussionPreferencesModel.useNewPercussionPanel = !percussionPreferencesModel.useNewPercussionPanel
186+
}
156187
}
157-
}
158188

159-
FlatButton {
160-
id: useNewPercussionPanel
189+
StyledTextLabel {
190+
id: legacyToggleInfo
161191

162-
text: percussionPreferencesModel.useNewPercussionPanel ? qsTrc("notation/percussion", "Switch to old percussion panel")
163-
: qsTrc("notation/percussion", "Switch to new percussion panel")
192+
enabled: percussionPreferencesModel.useNewPercussionPanel
164193

165-
navigation.name: "SwitchPercussionPanels"
166-
navigation.panel: percussionPanelPreferences.navigation
167-
navigation.row: alwaysAsk.navigation.row + 1
194+
height: parent.height
195+
196+
horizontalAlignment: Text.AlignLeft
197+
verticalAlignment: Text.AlignVCenter
168198

169-
onClicked: {
170-
percussionPreferencesModel.useNewPercussionPanel = !percussionPreferencesModel.useNewPercussionPanel
199+
wrapMode: Text.Wrap
200+
text: qsTrc("notation/percussion", "Use legacy percussion panel")
171201
}
172202
}
173203
}

src/engraving/dom/noteentry.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ Note* Score::addPitch(NoteVal& nval, bool addFlag, InputState* externalInputStat
211211
}
212212

213213
if (!is.cr()) {
214-
return 0;
214+
handleOverlappingChordRest(is);
215215
}
216+
216217
Measure* measure = is.segment()->measure();
217218
if (measure->isMeasureRepeatGroup(track2staff(track))) {
218219
MeasureRepeat* mr = measure->measureRepeatElement(track2staff(track));
@@ -456,29 +457,7 @@ Ret Score::putNote(const Position& p, bool replace)
456457

457458
// If there's an overlapping ChordRest at the current input position, shorten it...
458459
if (!cr) {
459-
MasterScore* ms = masterScore();
460-
ChordRest* prevCr = m_is.segment()->nextChordRest(m_is.track(), /*backwards*/ true, /*stopAtMeasureBoundary*/ true);
461-
if (prevCr && prevCr->endTick() > m_is.tick()) {
462-
const Fraction overlapDuration = prevCr->endTick() - m_is.tick();
463-
const Fraction desiredDuration = prevCr->ticks() - overlapDuration;
464-
465-
const InputState inputStateToRestore = m_is; // because changeCRlen will alter the input state
466-
ms->changeCRlen(prevCr, desiredDuration, /*fillWithRest*/ false);
467-
468-
// Fill the difference with tied notes if necessary...
469-
const Fraction difference = desiredDuration - prevCr->ticks();
470-
if (prevCr->isChord() && difference.isNotZero()) {
471-
Fraction startTick = prevCr->endTick();
472-
Chord* prevChord = toChord(prevCr);
473-
const std::vector<TDuration> durationList = toDurationList(difference, true);
474-
for (const TDuration& dur : durationList) {
475-
prevChord = ms->addChord(startTick, dur, prevChord, /*genTie*/ bool(prevChord), prevChord->tuplet());
476-
startTick += dur.fraction();
477-
}
478-
}
479-
480-
m_is = inputStateToRestore;
481-
}
460+
handleOverlappingChordRest(m_is);
482461
}
483462

484463
auto checkTied = [&](){
@@ -587,6 +566,33 @@ Ret Score::putNote(const Position& p, bool replace)
587566
return ret;
588567
}
589568

569+
void Score::handleOverlappingChordRest(InputState& inputState)
570+
{
571+
MasterScore* ms = masterScore();
572+
ChordRest* prevCr = inputState.segment()->nextChordRest(inputState.track(), /*backwards*/ true, /*stopAtMeasureBoundary*/ true);
573+
if (prevCr && prevCr->endTick() > inputState.tick()) {
574+
const Fraction overlapDuration = prevCr->endTick() - inputState.tick();
575+
const Fraction desiredDuration = prevCr->ticks() - overlapDuration;
576+
577+
const InputState inputStateToRestore = inputState; // because changeCRlen will alter the input state
578+
ms->changeCRlen(prevCr, desiredDuration, /*fillWithRest*/ true);
579+
580+
// Fill the difference with tied notes if necessary...
581+
const Fraction difference = desiredDuration - prevCr->ticks();
582+
if (prevCr->isChord() && difference.isNotZero()) {
583+
Fraction startTick = prevCr->endTick();
584+
Chord* prevChord = toChord(prevCr);
585+
const std::vector<TDuration> durationList = toDurationList(difference, true);
586+
for (const TDuration& dur : durationList) {
587+
prevChord = ms->addChord(startTick, dur, prevChord, /*genTie*/ bool(prevChord), prevChord->tuplet());
588+
startTick += dur.fraction();
589+
}
590+
}
591+
592+
inputState = inputStateToRestore;
593+
}
594+
}
595+
590596
//---------------------------------------------------------
591597
// repitchNote
592598
//---------------------------------------------------------

src/engraving/dom/score.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ class Score : public EngravingObject, public muse::Injectable
10721072
void selectRange(EngravingItem* e, staff_idx_t staffIdx);
10731073

10741074
muse::Ret putNote(const Position&, bool replace);
1075+
void handleOverlappingChordRest(InputState& inputState);
10751076

10761077
void resetTempo();
10771078
void resetTempoRange(const Fraction& tick1, const Fraction& tick2);

src/engraving/dom/select.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,10 +817,11 @@ void Selection::setRange(Segment* startSegment, Segment* endSegment, staff_idx_t
817817
assert(!(endSegment && !startSegment));
818818

819819
m_startSegment = startSegment;
820-
m_endSegment = endSegment;
820+
m_endSegment = endSegment;
821821
m_activeSegment = endSegment;
822-
m_staffStart = staffStart;
823-
m_staffEnd = staffEnd;
822+
m_staffStart = staffStart;
823+
m_staffEnd = staffEnd;
824+
m_activeTrack = staff2track(staffStart);
824825

825826
if (m_state == SelState::RANGE) {
826827
m_score->setSelectionChanged(true);
@@ -844,8 +845,9 @@ void Selection::setRangeTicks(const Fraction& tick1, const Fraction& tick2, staf
844845
m_plannedTick1 = tick1;
845846
m_plannedTick2 = tick2;
846847
m_startSegment = m_endSegment = m_activeSegment = nullptr;
847-
m_staffStart = staffStart;
848-
m_staffEnd = staffEnd;
848+
m_staffStart = staffStart;
849+
m_staffEnd = staffEnd;
850+
m_activeTrack = staff2track(staffStart);
849851

850852
if (m_state == SelState::RANGE) {
851853
m_score->setSelectionChanged(true);

src/notation/internal/notationinteraction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ NotationInteraction::NotationInteraction(Notation* notation, INotationUndoStackP
196196

197197
m_undoStack->undoRedoNotification().onNotify(this, [this]() {
198198
endEditElement();
199-
notifyAboutNoteInputStateChanged();
200199
});
201200

202201
m_undoStack->stackChanged().onNotify(this, [this]() {
203202
notifyAboutSelectionChangedIfNeed();
203+
notifyAboutNoteInputStateChanged();
204204
});
205205

206206
m_dragData.ed = mu::engraving::EditData(&m_scoreCallbacks);

src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Item {
3434
property NavigationSection navigationSection: null
3535
property int contentNavigationPanelOrderStart: 1
3636

37+
signal resizeRequested(var newWidth, var newHeight)
38+
3739
anchors.fill: parent
3840

3941
property Component toolbarComponent: PercussionPanelToolBar {
@@ -47,6 +49,8 @@ Item {
4749

4850
Component.onCompleted: {
4951
padGrid.model.init()
52+
var newHeight = (padGrid.numRows * padGrid.cellHeight) + (soundTitleLabel.height * 2)
53+
root.resizeRequested(root.width, newHeight)
5054
}
5155

5256
PercussionPanelModel {
@@ -325,6 +329,11 @@ Item {
325329
}
326330
pad.padNavigation.requestActive()
327331
}
332+
333+
function onNumPadsChanged() {
334+
var newHeight = (padGrid.numRows * padGrid.cellHeight) + (soundTitleLabel.height * 2)
335+
root.resizeRequested(root.width, newHeight)
336+
}
328337
}
329338
}
330339

0 commit comments

Comments
 (0)