Skip to content

Commit 4085b57

Browse files
committed
Support scale highlighting
1 parent aa145fe commit 4085b57

File tree

11 files changed

+155
-4
lines changed

11 files changed

+155
-4
lines changed

src/libs/3rdparty/svscraft

src/plugins/coreplugin/internal/colorscheme/ColorSchemeCollection.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ namespace Core::Internal {
6767
{"levelMeterColor", QVariant::fromValue(QColor(0x111112))},
6868
{"editAreaPrimaryColor", QVariant::fromValue(QColor(0x333740))},
6969
{"editAreaSecondaryColor", QVariant::fromValue(QColor(0x444954))},
70+
{"editAreaPrimaryHighlightColor", QVariant::fromValue(QColor(0x5566ff))},
71+
{"editAreaSecondaryHighlightColor", QVariant::fromValue(QColor(0x7d8aff))}, // TODO
7072
{"playheadPrimaryColor", QVariant::fromValue(QColor(0xcc4455))},
7173
{"playheadSecondaryColor", QVariant::fromValue(QColor::fromRgba(0x7fcc4455))},
7274
{"cursorIndicatorColor", QVariant::fromValue(QColor::fromRgba(0xbf00bfff))},
@@ -139,6 +141,8 @@ namespace Core::Internal {
139141
{"levelMeterColor", QVariant::fromValue(QColor(0x111112))},
140142
{"editAreaPrimaryColor", QVariant::fromValue(QColor(0x333740))},
141143
{"editAreaSecondaryColor", QVariant::fromValue(QColor(0x444954))},
144+
{"editAreaPrimaryHighlightColor", QVariant::fromValue(QColor(0x333740))},
145+
{"editAreaSecondaryHighlightColor", QVariant::fromValue(QColor(0x444954))},
142146
{"playheadPrimaryColor", QVariant::fromValue(QColor(0xcc4455))},
143147
{"playheadSecondaryColor", QVariant::fromValue(QColor::fromRgba(0x7fcc4455))},
144148
{"cursorIndicatorColor", QVariant::fromValue(QColor::fromRgba(0x7f5566ff))},
@@ -211,6 +215,8 @@ namespace Core::Internal {
211215
{"levelMeterColor", QVariant::fromValue(QColor::fromRgb(0x111112))},
212216
{"editAreaPrimaryColor", QVariant::fromValue(QColor::fromRgb(0x292c33))},
213217
{"editAreaSecondaryColor", QVariant::fromValue(QColor::fromRgb(0x535966))},
218+
{"editAreaPrimaryHighlightColor", QVariant::fromValue(QColor::fromRgb(0x292c33))},
219+
{"editAreaSecondaryHighlightColor", QVariant::fromValue(QColor::fromRgb(0x535966))},
214220
{"playheadPrimaryColor", QVariant::fromValue(QColor::fromRgb(0xcc293c))},
215221
{"playheadSecondaryColor", QVariant::fromValue(QColor::fromRgba(0x7fcc293c))},
216222
{"cursorIndicatorColor", QVariant::fromValue(QColor::fromRgba(0xbf00ff55))},
@@ -497,6 +503,8 @@ namespace Core::Internal {
497503
palette->setProperty("levelMeterColor", m_unsavedPreset.value("levelMeterColor"));
498504
palette->setProperty("editAreaPrimaryColor", m_unsavedPreset.value("editAreaPrimaryColor"));
499505
palette->setProperty("editAreaSecondaryColor", m_unsavedPreset.value("editAreaSecondaryColor"));
506+
palette->setProperty("editAreaPrimaryHighlightColor", m_unsavedPreset.value("editAreaPrimaryHighlightColor"));
507+
palette->setProperty("editAreaSecondaryHighlightColor", m_unsavedPreset.value("editAreaSecondaryHighlightColor"));
500508
palette->setProperty("playheadPrimaryColor", m_unsavedPreset.value("playheadPrimaryColor"));
501509
palette->setProperty("playheadSecondaryColor", m_unsavedPreset.value("playheadSecondaryColor"));
502510
palette->setProperty("cursorIndicatorColor", m_unsavedPreset.value("cursorIndicatorColor"));

src/plugins/coreplugin/qml/controls/MusicPitchPropertyEditorField.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ AbstractPropertyEditorField {
1717
KeySignatureAtSpecifiedPositionHelper {
1818
id: keySignatureAtSpecifiedPositionHelper
1919
position: d.positionHint !== -1 ? d.positionHint : (d.windowHandle?.projectTimeline.position ?? 0)
20-
keySignatureSequence: d.windowHandle?.projectDocumentContext.document.model.timeline.keySignatures
20+
keySignatureSequence: d.windowHandle?.projectDocumentContext.document.model.timeline.keySignatures ?? null
2121
}
2222
FormGroup {
2323
Layout.fillWidth: true

src/plugins/coreplugin/qml/propertyeditors/NotePitchPropertyEditor.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PropertyEditorGroupBox {
2424
label: qsTr("Pitch")
2525
from: 0
2626
to: 127
27-
positionHint: groupBox.propertyMapper?.pos === undefined ? -1 : groupBox.propertyMapper.pos
27+
positionHint: groupBox.propertyMapper?.pos === undefined ? -1 : (groupBox.propertyMapper.pos + (groupBox.windowHandle?.projectDocumentContext.document.selectionModel.noteSelectionModel.noteSequenceWithSelectedItems?.singingClip.time.start ?? 0))
2828
transactionName: qsTr("Editing pitch")
2929
}
3030

src/plugins/coreplugin/qml/settings/ColorSchemePage.qml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@ Item {
496496
name: "editAreaSecondaryColor"
497497
text: qsTr("Edit area secondary background color")
498498
}
499+
ListElement {
500+
name: "editAreaPrimaryHighlightColor"
501+
text: qsTr("Edit area primary highlight background color")
502+
}
503+
ListElement {
504+
name: "editAreaSecondaryHighlightColor"
505+
text: qsTr("Edit area secondary highlight background color")
506+
}
499507
ListElement {
500508
name: "playheadPrimaryColor"
501509
text: qsTr("Playhead primary color")

src/plugins/visualeditor/core/ProjectViewModelContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ namespace VisualEditor {
136136
return d->keySignatureData->keySignatureSequenceViewModel;
137137
}
138138

139+
sflow::RangeSequenceViewModel *ProjectViewModelContext::scaleHighlightSequenceViewModel() const {
140+
Q_D(const ProjectViewModelContext);
141+
return d->keySignatureData->scaleHighlightSequenceViewModel;
142+
}
143+
139144
sflow::PointSequenceViewModel *ProjectViewModelContext::labelSequenceViewModel() const {
140145
Q_D(const ProjectViewModelContext);
141146
return d->labelData->labelSequenceViewModel;

src/plugins/visualeditor/core/ProjectViewModelContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace VisualEditor {
5858
Q_PROPERTY(sflow::SelectionController *tempoSelectionController READ tempoSelectionController CONSTANT)
5959
Q_PROPERTY(sflow::PointSequenceViewModel *keySignatureSequenceViewModel READ keySignatureSequenceViewModel CONSTANT)
6060
Q_PROPERTY(sflow::SelectionController *keySignatureSelectionController READ keySignatureSelectionController CONSTANT)
61+
Q_PROPERTY(sflow::RangeSequenceViewModel *scaleHighlightSequenceViewModel READ scaleHighlightSequenceViewModel CONSTANT)
6162
Q_PROPERTY(sflow::PointSequenceViewModel *labelSequenceViewModel READ labelSequenceViewModel CONSTANT)
6263
Q_PROPERTY(sflow::SelectionController *labelSelectionController READ labelSelectionController CONSTANT)
6364
Q_PROPERTY(sflow::RangeSequenceViewModel *clipSequenceViewModel READ clipSequenceViewModel CONSTANT)
@@ -79,6 +80,7 @@ namespace VisualEditor {
7980
sflow::PlaybackViewModel *playbackViewModel() const;
8081
sflow::PointSequenceViewModel *tempoSequenceViewModel() const;
8182
sflow::PointSequenceViewModel *keySignatureSequenceViewModel() const;
83+
sflow::RangeSequenceViewModel *scaleHighlightSequenceViewModel() const;
8284
sflow::PointSequenceViewModel *labelSequenceViewModel() const;
8385
sflow::RangeSequenceViewModel *clipSequenceViewModel() const;
8486
sflow::ListViewModel *trackListViewModel() const;

src/plugins/visualeditor/core/viewmodelbinding/KeySignatureViewModelContextData.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <ScopicFlowCore/LabelSequenceInteractionController.h>
1414
#include <ScopicFlowCore/LabelViewModel.h>
1515
#include <ScopicFlowCore/PointSequenceViewModel.h>
16+
#include <ScopicFlowCore/RangeSequenceViewModel.h>
17+
#include <ScopicFlowCore/ScaleHighlightViewModel.h>
1618
#include <ScopicFlowCore/TimeManipulator.h>
1719
#include <ScopicFlowCore/TimeViewModel.h>
1820
#include <ScopicFlowCore/TimeLayoutViewModel.h>
@@ -133,20 +135,25 @@ namespace VisualEditor {
133135
keySignatureSequenceViewModel = new sflow::PointSequenceViewModel(q);
134136
keySignatureSelectionController = new KeySignatureSelectionController(q);
135137

138+
scaleHighlightSequenceViewModel = new sflow::RangeSequenceViewModel(q);
139+
136140
initStateMachine();
137141
}
138142

139143
void KeySignatureViewModelContextData::bindKeySignatureSequenceViewModel() {
140144
Q_Q(ProjectViewModelContext);
141145
connect(keySignatureSequence, &dspx::KeySignatureSequence::itemInserted, keySignatureSequenceViewModel, [=, this](dspx::KeySignature *item) {
142146
bindKeySignatureDocumentItem(item);
147+
bindScaleHighlightDocumentItem(item);
143148
});
144149
connect(keySignatureSequence, &dspx::KeySignatureSequence::itemRemoved, keySignatureSequenceViewModel, [=, this](dspx::KeySignature *item) {
145150
unbindKeySignatureDocumentItem(item);
151+
unbindScaleHighlightDocumentItem(item);
146152
});
147153
// For key signature sequence, item will never be inserted or removed from view
148154
for (auto item : keySignatureSequence->asRange()) {
149155
bindKeySignatureDocumentItem(item);
156+
bindScaleHighlightDocumentItem(item);
150157
}
151158
connect(keySignatureSelectionModel, &dspx::KeySignatureSelectionModel::itemSelected, this, [=, this](dspx::KeySignature *item, bool selected) {
152159
qCDebug(lcKeySignatureViewModelContextData) << "KeySignature item selected" << item << selected;
@@ -338,4 +345,111 @@ namespace VisualEditor {
338345
scenario.modifyExistingKeySignatureAt(viewItem->position());
339346
}
340347

348+
void KeySignatureViewModelContextData::bindScaleHighlightDocumentItem(dspx::KeySignature *item) {
349+
if (keySignatureScaleHighlightViewItemMap.contains(item)) {
350+
return;
351+
}
352+
auto viewItem = new sflow::ScaleHighlightViewModel(scaleHighlightSequenceViewModel);
353+
keySignatureScaleHighlightViewItemMap.insert(item, viewItem);
354+
qCDebug(lcKeySignatureViewModelContextData) << "KeySignature scale highlight item inserted" << item << viewItem;
355+
356+
// Store the current nextItem to track disconnections
357+
QPointer<dspx::KeySignature> currentNextItem = item->nextItem();
358+
359+
// Connect pos signal
360+
connect(item, &dspx::KeySignature::posChanged, viewItem, [=, this] {
361+
qCDebug(lcKeySignatureViewModelContextData) << "KeySignature scale highlight pos updated" << item << item->pos();
362+
updateScaleHighlightViewItem(item);
363+
});
364+
365+
// Connect nextItem signal and handle nextItem's pos signal
366+
connect(item, &dspx::KeySignature::nextItemChanged, viewItem, [=, this] () mutable {
367+
qCDebug(lcKeySignatureViewModelContextData) << "KeySignature nextItem changed" << item << item->nextItem();
368+
369+
// Disconnect previous nextItem's pos signal if any
370+
if (currentNextItem) {
371+
disconnect(currentNextItem, &dspx::KeySignature::posChanged, viewItem, nullptr);
372+
}
373+
374+
// Update current nextItem
375+
currentNextItem = item->nextItem();
376+
377+
// Connect new nextItem's pos signal if exists
378+
if (currentNextItem) {
379+
connect(currentNextItem, &dspx::KeySignature::posChanged, viewItem, [=, this] {
380+
qCDebug(lcKeySignatureViewModelContextData) << "KeySignature nextItem pos updated" << currentNextItem << currentNextItem->pos();
381+
updateScaleHighlightViewItem(item);
382+
});
383+
}
384+
385+
updateScaleHighlightViewItem(item);
386+
});
387+
388+
// Connect mode and tonality signals
389+
connect(item, &dspx::KeySignature::modeChanged, viewItem, [=, this] {
390+
qCDebug(lcKeySignatureViewModelContextData) << "KeySignature scale highlight mode updated" << item << item->mode();
391+
updateScaleHighlightViewItem(item);
392+
});
393+
394+
connect(item, &dspx::KeySignature::tonalityChanged, viewItem, [=, this] {
395+
qCDebug(lcKeySignatureViewModelContextData) << "KeySignature scale highlight tonality updated" << item << item->tonality();
396+
updateScaleHighlightViewItem(item);
397+
});
398+
399+
// Connect current nextItem's pos signal if exists
400+
if (currentNextItem) {
401+
connect(currentNextItem, &dspx::KeySignature::posChanged, viewItem, [=, this] {
402+
qCDebug(lcKeySignatureViewModelContextData) << "KeySignature nextItem pos updated" << currentNextItem << currentNextItem->pos();
403+
updateScaleHighlightViewItem(item);
404+
});
405+
}
406+
407+
// Initialize values
408+
updateScaleHighlightViewItem(item);
409+
410+
scaleHighlightSequenceViewModel->insertItem(viewItem);
411+
}
412+
413+
void KeySignatureViewModelContextData::unbindScaleHighlightDocumentItem(dspx::KeySignature *item) {
414+
if (!keySignatureScaleHighlightViewItemMap.contains(item)) {
415+
return;
416+
}
417+
auto viewItem = keySignatureScaleHighlightViewItemMap.take(item);
418+
qCDebug(lcKeySignatureViewModelContextData) << "KeySignature scale highlight item removed" << item << viewItem;
419+
420+
disconnect(item, nullptr, viewItem, nullptr);
421+
422+
// Disconnect nextItem's pos signal if any
423+
if (auto nextItem = item->nextItem()) {
424+
disconnect(nextItem, nullptr, viewItem, nullptr);
425+
}
426+
427+
scaleHighlightSequenceViewModel->removeItem(viewItem);
428+
429+
viewItem->deleteLater();
430+
}
431+
432+
void KeySignatureViewModelContextData::updateScaleHighlightViewItem(dspx::KeySignature *item) {
433+
auto viewItem = keySignatureScaleHighlightViewItemMap.value(item);
434+
if (!viewItem) {
435+
return;
436+
}
437+
438+
// Calculate position
439+
viewItem->setPosition(item->pos());
440+
441+
// Calculate length
442+
int length;
443+
if (auto nextItem = item->nextItem()) {
444+
length = nextItem->pos() - item->pos();
445+
} else {
446+
length = 1073741824; // Default length when no next item
447+
}
448+
viewItem->setLength(length);
449+
450+
// Calculate cMask using MusicMode::translateMask
451+
int cMask = SVS::MusicMode(item->mode()).translateMask(item->tonality(), 0);
452+
viewItem->setCMask(cMask);
453+
}
454+
341455
}

src/plugins/visualeditor/core/viewmodelbinding/KeySignatureViewModelContextData_p.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace sflow {
2121
class LabelSequenceInteractionController;
2222
class LabelViewModel;
2323
class PointSequenceViewModel;
24+
class RangeSequenceViewModel;
25+
class ScaleHighlightViewModel;
2426
}
2527

2628
namespace Core {
@@ -45,7 +47,10 @@ namespace VisualEditor {
4547
sflow::PointSequenceViewModel *keySignatureSequenceViewModel;
4648
KeySignatureSelectionController *keySignatureSelectionController;
4749

50+
sflow::RangeSequenceViewModel *scaleHighlightSequenceViewModel;
51+
4852
QHash<dspx::KeySignature *, sflow::LabelViewModel *> keySignatureViewItemMap;
53+
QHash<dspx::KeySignature *, sflow::ScaleHighlightViewModel *> keySignatureScaleHighlightViewItemMap;
4954
QHash<sflow::LabelViewModel *, dspx::KeySignature *> keySignatureDocumentItemMap;
5055
QSet<sflow::LabelViewModel *> transactionalUpdatedKeySignatures;
5156

@@ -64,6 +69,9 @@ namespace VisualEditor {
6469
void bindKeySignatureSequenceViewModel();
6570
void bindKeySignatureDocumentItem(dspx::KeySignature *item);
6671
void unbindKeySignatureDocumentItem(dspx::KeySignature *item);
72+
void bindScaleHighlightDocumentItem(dspx::KeySignature *item);
73+
void unbindScaleHighlightDocumentItem(dspx::KeySignature *item);
74+
void updateScaleHighlightViewItem(dspx::KeySignature *item);
6775
sflow::LabelSequenceInteractionController *createController(QObject *parent);
6876

6977
void onMovePendingStateEntered();

0 commit comments

Comments
 (0)