Skip to content

Commit e7675de

Browse files
committed
Update piano roll
1 parent 42daee4 commit e7675de

6 files changed

Lines changed: 122 additions & 3 deletions

File tree

src/plugins/visualeditor/internal/EditorPreference.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace VisualEditor::Internal {
1313

14+
static constexpr double kDefaultAutoPitchCurveDisplayPixelDensityThreshold = 0.07071;
15+
1416
class EditorPreferencePrivate {
1517
public:
1618
bool initialized{};
@@ -26,6 +28,8 @@ namespace VisualEditor::Internal {
2628
bool centerPianoRollOnClipDoubleClick{true};
2729
double pianoKeyboardBlackKeyLengthRatio{0.6};
2830
EditorPreference::PianoKeyboardLabelPolicy pianoKeyboardLabelPolicy{};
31+
EditorPreference::NoteEditPitchCurveDisplayMode noteEditPitchCurveDisplayMode{};
32+
double autoPitchCurveDisplayPixelDensityThreshold{kDefaultAutoPitchCurveDisplayPixelDensityThreshold};
2933
bool displayPronunciationBelowNote{};
3034
int shortNoteThreshold{30};
3135
bool warnOfOverlappingNotes{true};
@@ -76,6 +80,10 @@ namespace VisualEditor::Internal {
7680
emit pianoKeyboardBlackKeyLengthRatioChanged();
7781
d->pianoKeyboardLabelPolicy = settings->value("pianoKeyboardLabelPolicy", QVariant::fromValue(LP_All)).value<PianoKeyboardLabelPolicy>();
7882
emit pianoKeyboardLabelPolicyChanged();
83+
d->noteEditPitchCurveDisplayMode = settings->value("noteEditPitchCurveDisplayMode", QVariant::fromValue(PCDM_Automatic)).value<NoteEditPitchCurveDisplayMode>();
84+
Q_EMIT noteEditPitchCurveDisplayModeChanged();
85+
d->autoPitchCurveDisplayPixelDensityThreshold = settings->value("autoPitchCurveDisplayPixelDensityThreshold", kDefaultAutoPitchCurveDisplayPixelDensityThreshold).toDouble();
86+
Q_EMIT autoPitchCurveDisplayPixelDensityThresholdChanged();
7987
d->displayPronunciationBelowNote = settings->value("displayPronunciationBelowNote", false).toBool();
8088
emit displayPronunciationBelowNoteChanged();
8189
d->shortNoteThreshold = settings->value("shortNoteThreshold", 30).toInt();
@@ -110,6 +118,8 @@ namespace VisualEditor::Internal {
110118
settings->setValue("centerPianoRollOnClipDoubleClick", d->centerPianoRollOnClipDoubleClick);
111119
settings->setValue("pianoKeyboardBlackKeyLengthRatio", d->pianoKeyboardBlackKeyLengthRatio);
112120
settings->setValue("pianoKeyboardLabelPolicy", static_cast<int>(d->pianoKeyboardLabelPolicy));
121+
settings->setValue("noteEditPitchCurveDisplayMode", static_cast<int>(d->noteEditPitchCurveDisplayMode));
122+
settings->setValue("autoPitchCurveDisplayPixelDensityThreshold", d->autoPitchCurveDisplayPixelDensityThreshold);
113123
settings->setValue("displayPronunciationBelowNote", d->displayPronunciationBelowNote);
114124
settings->setValue("shortNoteThreshold", d->shortNoteThreshold);
115125
settings->setValue("warnOfOverlappingNotes", d->warnOfOverlappingNotes);
@@ -267,6 +277,32 @@ namespace VisualEditor::Internal {
267277
emit m_instance->pianoKeyboardLabelPolicyChanged();
268278
}
269279

280+
EditorPreference::NoteEditPitchCurveDisplayMode EditorPreference::noteEditPitchCurveDisplayMode() {
281+
M_INSTANCE_D;
282+
return d->noteEditPitchCurveDisplayMode;
283+
}
284+
285+
void EditorPreference::setNoteEditPitchCurveDisplayMode(NoteEditPitchCurveDisplayMode noteEditPitchCurveDisplayMode) {
286+
M_INSTANCE_D;
287+
if (d->noteEditPitchCurveDisplayMode == noteEditPitchCurveDisplayMode)
288+
return;
289+
d->noteEditPitchCurveDisplayMode = noteEditPitchCurveDisplayMode;
290+
Q_EMIT m_instance->noteEditPitchCurveDisplayModeChanged();
291+
}
292+
293+
double EditorPreference::autoPitchCurveDisplayPixelDensityThreshold() {
294+
M_INSTANCE_D;
295+
return d->autoPitchCurveDisplayPixelDensityThreshold;
296+
}
297+
298+
void EditorPreference::setAutoPitchCurveDisplayPixelDensityThreshold(double autoPitchCurveDisplayPixelDensityThreshold) {
299+
M_INSTANCE_D;
300+
if (qFuzzyCompare(d->autoPitchCurveDisplayPixelDensityThreshold, autoPitchCurveDisplayPixelDensityThreshold))
301+
return;
302+
d->autoPitchCurveDisplayPixelDensityThreshold = autoPitchCurveDisplayPixelDensityThreshold;
303+
Q_EMIT m_instance->autoPitchCurveDisplayPixelDensityThresholdChanged();
304+
}
305+
270306
bool EditorPreference::displayPronunciationBelowNote() {
271307
M_INSTANCE_D;
272308
return d->displayPronunciationBelowNote;

src/plugins/visualeditor/internal/EditorPreference.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace VisualEditor::Internal {
3333
Q_PROPERTY(bool centerPianoRollOnClipDoubleClick READ centerPianoRollOnClipDoubleClick WRITE setCenterPianoRollOnClipDoubleClick NOTIFY centerPianoRollOnClipDoubleClickChanged)
3434
Q_PROPERTY(double pianoKeyboardBlackKeyLengthRatio READ pianoKeyboardBlackKeyLengthRatio WRITE setPianoKeyboardBlackKeyLengthRatio NOTIFY pianoKeyboardBlackKeyLengthRatioChanged)
3535
Q_PROPERTY(EditorPreference::PianoKeyboardLabelPolicy pianoKeyboardLabelPolicy READ pianoKeyboardLabelPolicy WRITE setPianoKeyboardLabelPolicy NOTIFY pianoKeyboardLabelPolicyChanged)
36+
Q_PROPERTY(EditorPreference::NoteEditPitchCurveDisplayMode noteEditPitchCurveDisplayMode READ noteEditPitchCurveDisplayMode WRITE setNoteEditPitchCurveDisplayMode NOTIFY noteEditPitchCurveDisplayModeChanged)
37+
Q_PROPERTY(double autoPitchCurveDisplayPixelDensityThreshold READ autoPitchCurveDisplayPixelDensityThreshold WRITE setAutoPitchCurveDisplayPixelDensityThreshold NOTIFY autoPitchCurveDisplayPixelDensityThresholdChanged)
3638
Q_PROPERTY(bool displayPronunciationBelowNote READ displayPronunciationBelowNote WRITE setDisplayPronunciationBelowNote NOTIFY displayPronunciationBelowNoteChanged)
3739
Q_PROPERTY(int shortNoteThreshold READ shortNoteThreshold WRITE setShortNoteThreshold NOTIFY shortNoteThresholdChanged)
3840
Q_PROPERTY(bool warnOfOverlappingNotes READ warnOfOverlappingNotes WRITE setWarnOfOverlappingNotes NOTIFY warnOfOverlappingNotesChanged)
@@ -60,6 +62,13 @@ namespace VisualEditor::Internal {
6062
};
6163
Q_ENUM(PianoKeyboardLabelPolicy)
6264

65+
enum NoteEditPitchCurveDisplayMode {
66+
PCDM_Automatic,
67+
PCDM_AlwaysShow,
68+
PCDM_AlwaysHide,
69+
};
70+
Q_ENUM(NoteEditPitchCurveDisplayMode)
71+
6372
enum ScrollModifier {
6473
SM_Control,
6574
SM_Alt,
@@ -100,6 +109,12 @@ namespace VisualEditor::Internal {
100109
static PianoKeyboardLabelPolicy pianoKeyboardLabelPolicy();
101110
static void setPianoKeyboardLabelPolicy(PianoKeyboardLabelPolicy pianoKeyboardLabelPolicy);
102111

112+
static NoteEditPitchCurveDisplayMode noteEditPitchCurveDisplayMode();
113+
static void setNoteEditPitchCurveDisplayMode(NoteEditPitchCurveDisplayMode noteEditPitchCurveDisplayMode);
114+
115+
static double autoPitchCurveDisplayPixelDensityThreshold();
116+
static void setAutoPitchCurveDisplayPixelDensityThreshold(double autoPitchCurveDisplayPixelDensityThreshold);
117+
103118
static bool displayPronunciationBelowNote();
104119
static void setDisplayPronunciationBelowNote(bool displayPronunciationBelowNote);
105120

@@ -133,6 +148,8 @@ namespace VisualEditor::Internal {
133148
void centerPianoRollOnClipDoubleClickChanged();
134149
void pianoKeyboardBlackKeyLengthRatioChanged();
135150
void pianoKeyboardLabelPolicyChanged();
151+
void noteEditPitchCurveDisplayModeChanged();
152+
void autoPitchCurveDisplayPixelDensityThresholdChanged();
136153
void displayPronunciationBelowNoteChanged();
137154
void shortNoteThresholdChanged();
138155
void warnOfOverlappingNotesChanged();

src/plugins/visualeditor/internal/settings/EditorPage.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ namespace VisualEditor::Internal {
6969
qCDebug(lcEditorPage) << m_widget->property("pianoKeyboardBlackKeyLengthRatio");
7070
m_widget->setProperty("pianoKeyboardLabelPolicy", EditorPreference::instance()->property("pianoKeyboardLabelPolicy"));
7171
qCDebug(lcEditorPage) << m_widget->property("pianoKeyboardLabelPolicy");
72+
m_widget->setProperty("noteEditPitchCurveDisplayMode", EditorPreference::instance()->property("noteEditPitchCurveDisplayMode"));
73+
qCDebug(lcEditorPage) << m_widget->property("noteEditPitchCurveDisplayMode");
74+
m_widget->setProperty("autoPitchCurveDisplayPixelDensityThreshold", EditorPreference::instance()->property("autoPitchCurveDisplayPixelDensityThreshold"));
75+
qCDebug(lcEditorPage) << m_widget->property("autoPitchCurveDisplayPixelDensityThreshold");
7276
m_widget->setProperty("displayPronunciationBelowNote", EditorPreference::instance()->property("displayPronunciationBelowNote"));
7377
qCDebug(lcEditorPage) << m_widget->property("displayPronunciationBelowNote");
7478
m_widget->setProperty("shortNoteThreshold", EditorPreference::instance()->property("shortNoteThreshold"));
@@ -111,6 +115,10 @@ namespace VisualEditor::Internal {
111115
EditorPreference::instance()->setProperty("pianoKeyboardBlackKeyLengthRatio", m_widget->property("pianoKeyboardBlackKeyLengthRatio"));
112116
qCDebug(lcEditorPage) << "pianoKeyboardLabelPolicy" << m_widget->property("pianoKeyboardLabelPolicy");
113117
EditorPreference::instance()->setProperty("pianoKeyboardLabelPolicy", m_widget->property("pianoKeyboardLabelPolicy"));
118+
qCDebug(lcEditorPage) << "noteEditPitchCurveDisplayMode" << m_widget->property("noteEditPitchCurveDisplayMode");
119+
EditorPreference::instance()->setProperty("noteEditPitchCurveDisplayMode", m_widget->property("noteEditPitchCurveDisplayMode"));
120+
qCDebug(lcEditorPage) << "autoPitchCurveDisplayPixelDensityThreshold" << m_widget->property("autoPitchCurveDisplayPixelDensityThreshold");
121+
EditorPreference::instance()->setProperty("autoPitchCurveDisplayPixelDensityThreshold", m_widget->property("autoPitchCurveDisplayPixelDensityThreshold"));
114122
qCDebug(lcEditorPage) << "displayPronunciationBelowNote" << m_widget->property("displayPronunciationBelowNote");
115123
EditorPreference::instance()->setProperty("displayPronunciationBelowNote", m_widget->property("displayPronunciationBelowNote"));
116124
qCDebug(lcEditorPage) << "shortNoteThreshold" << m_widget->property("shortNoteThreshold");

src/plugins/visualeditor/qml/PianoRollView.qml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,19 +942,34 @@ Item {
942942
view.projectViewModelContext?.parameterEditorContext.pitchBinding ?? null
943943
readonly property real keyHeight:
944944
view.pianoRollPanelInterface?.clavierViewModel?.pixelDensity ?? 0
945+
readonly property real timePixelDensity:
946+
view.pianoRollPanelInterface?.timeLayoutViewModel?.pixelDensity ?? 0
945947
readonly property real clavierStart:
946948
view.pianoRollPanelInterface?.clavierViewModel?.start ?? 0
947949
readonly property real key128CenterY:
948950
(clavierStart - 128.5) * keyHeight
949951
readonly property real key0CenterY:
950952
(clavierStart - 0.5) * keyHeight
953+
readonly property bool noteEditPitchCurveVisible: {
954+
if (EditorPreference.noteEditPitchCurveDisplayMode === EditorPreference.PCDM_AlwaysShow)
955+
return true
956+
if (EditorPreference.noteEditPitchCurveDisplayMode === EditorPreference.PCDM_AlwaysHide)
957+
return false
958+
return timePixelDensity >= EditorPreference.autoPitchCurveDisplayPixelDensityThreshold
959+
}
960+
readonly property real noteEditPitchCurveOpacityFactor: {
961+
if (EditorPreference.noteEditPitchCurveDisplayMode !== EditorPreference.PCDM_Automatic)
962+
return 1.0
963+
const ratio = timePixelDensity / EditorPreference.autoPitchCurveDisplayPixelDensityThreshold
964+
return Math.max(0.0, Math.min(1.0, 2 * Math.log2(ratio)))
965+
}
951966
x: 0
952967
width: parent.width
953968
y: key128CenterY
954969
height: key0CenterY - key128CenterY
955-
visible: binding?.available ?? false
970+
visible: (binding?.available ?? false) && (enabled || noteEditPitchCurveVisible)
956971
enabled: view.pianoRollPanelInterface?.pitchToolActive ?? false
957-
opacity: enabled ? 1.0 : 0.5
972+
opacity: enabled ? 1.0 : 0.5 * noteEditPitchCurveOpacityFactor
958973
freeParameterViewModel: binding?.freeEdited ?? null
959974
anchorParameterViewModel: binding?.anchorEdited ?? null
960975
originalParameterViewModel: binding?.original ?? null

src/plugins/visualeditor/qml/settings/EditorPage.qml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ ScrollView {
2727
property bool centerPianoRollOnClipDoubleClick: true
2828
property double pianoKeyboardBlackKeyLengthRatio: 0.6
2929
property int pianoKeyboardLabelPolicy: 0
30+
property int noteEditPitchCurveDisplayMode: EditorPreference.PCDM_Automatic
31+
property double autoPitchCurveDisplayPixelDensityThreshold: defaultAutoPitchCurveDisplayPixelDensityThreshold
3032
property bool displayPronunciationBelowNote: false
3133
property int shortNoteThreshold: 30
3234
property bool warnOfOverlappingNotes: true
@@ -46,6 +48,8 @@ ScrollView {
4648
onCenterPianoRollOnClipDoubleClickChanged: if (started) pageHandle.markDirty()
4749
onPianoKeyboardBlackKeyLengthRatioChanged: if (started) pageHandle.markDirty()
4850
onPianoKeyboardLabelPolicyChanged: if (started) pageHandle.markDirty()
51+
onNoteEditPitchCurveDisplayModeChanged: if (started) pageHandle.markDirty()
52+
onAutoPitchCurveDisplayPixelDensityThresholdChanged: if (started) pageHandle.markDirty()
4953
onDisplayPronunciationBelowNoteChanged: if (started) pageHandle.markDirty()
5054
onShortNoteThresholdChanged: if (started) pageHandle.markDirty()
5155
onWarnOfOverlappingNotesChanged: if (started) pageHandle.markDirty()
@@ -58,6 +62,10 @@ ScrollView {
5862
contentWidth: availableWidth
5963

6064
readonly property TextMatcher matcher: TextMatcher {}
65+
readonly property double minAutoPitchCurveDisplayPixelDensityThreshold: 0.05
66+
readonly property double maxAutoPitchCurveDisplayPixelDensityThreshold: 0.1
67+
readonly property double defaultAutoPitchCurveDisplayPixelDensityThreshold:
68+
Math.sqrt(minAutoPitchCurveDisplayPixelDensityThreshold * maxAutoPitchCurveDisplayPixelDensityThreshold)
6169

6270
ColumnLayout {
6371
width: page.width
@@ -272,6 +280,41 @@ ScrollView {
272280
onActivated: (index) => page.displayPronunciationBelowNote = (index === 1)
273281
}
274282

283+
Label {
284+
text: qsTr("Pitch curve display in note edit mode")
285+
TextMatcherItem on text { matcher: page.matcher }
286+
}
287+
Item {
288+
Layout.fillWidth: true
289+
}
290+
ComboBox {
291+
model: [qsTr("Automatic"), qsTr("Always show"), qsTr("Always hide")]
292+
currentIndex: page.noteEditPitchCurveDisplayMode
293+
onActivated: (index) => page.noteEditPitchCurveDisplayMode = index
294+
}
295+
296+
RowLayout {
297+
Layout.columnSpan: 3
298+
Layout.fillWidth: true
299+
Layout.leftMargin: 22
300+
enabled: page.noteEditPitchCurveDisplayMode === EditorPreference.PCDM_Automatic
301+
302+
Label {
303+
text: qsTr("Automatic display zoom threshold")
304+
TextMatcherItem on text { matcher: page.matcher }
305+
}
306+
Slider {
307+
Layout.fillWidth: true
308+
from: Math.log2(page.minAutoPitchCurveDisplayPixelDensityThreshold)
309+
to: Math.log2(page.maxAutoPitchCurveDisplayPixelDensityThreshold)
310+
value: Math.log2(page.autoPitchCurveDisplayPixelDensityThreshold)
311+
onMoved: page.autoPitchCurveDisplayPixelDensityThreshold = Math.pow(2, value)
312+
ThemedItem.sliderTrackStartType: SVS.TS_Begin
313+
ThemedItem.doubleClickResetValue: Math.log2(page.defaultAutoPitchCurveDisplayPixelDensityThreshold)
314+
ThemedItem.onDoubleClickReset: moved()
315+
}
316+
}
317+
275318
Label {
276319
text: qsTr("Short note threshold")
277320
TextMatcherItem on text { matcher: page.matcher }

0 commit comments

Comments
 (0)