Skip to content

Commit 19a8d99

Browse files
committed
Update viewport positioning of piano roll
1 parent 2ee7af4 commit 19a8d99

4 files changed

Lines changed: 32 additions & 39 deletions

File tree

‎src/plugins/visualeditor/core/ArrangementPanelInterface.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <visualeditor/ProjectViewModelContext.h>
4141
#include <visualeditor/internal/ArrangementAddOn.h>
4242
#include <visualeditor/internal/EditorPreference.h>
43+
#include <visualeditor/internal/PianoRollAddOn.h>
4344

4445
namespace VisualEditor {
4546

@@ -98,6 +99,7 @@ namespace VisualEditor {
9899
const double viewLength = editArea->width() / pianoRollPixelDensity;
99100
pianoRollPanelInterface->timeViewModel()->setStart(
100101
boundedTimeViewStart(singingClip, boundedClickPosition - viewLength / 2.0, viewLength));
102+
Internal::PianoRollAddOn::adjustVerticalViewForEditingClip(pianoRollPanelInterface, viewLength, editArea->height(), true);
101103
} else {
102104
// TODO
103105
}

‎src/plugins/visualeditor/core/PianoRollPanelInterface.cpp‎

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,16 @@
1717

1818
#include <ScopicFlowCore/ClavierInteractionController.h>
1919
#include <ScopicFlowCore/ClavierViewModel.h>
20-
#include <ScopicFlowCore/ClipViewModel.h>
2120
#include <ScopicFlowCore/LabelSequenceInteractionController.h>
2221
#include <ScopicFlowCore/NoteEditLayerInteractionController.h>
23-
#include <ScopicFlowCore/NoteViewModel.h>
2422
#include <ScopicFlowCore/ParameterEditorInteractionController.h>
2523
#include <ScopicFlowCore/PhonemeSequenceInteractionController.h>
2624
#include <ScopicFlowCore/RangeIndicatorInteractionController.h>
27-
#include <ScopicFlowCore/RangeSequenceViewModel.h>
2825
#include <ScopicFlowCore/ScrollBehaviorViewModel.h>
2926
#include <ScopicFlowCore/TimeLayoutViewModel.h>
3027
#include <ScopicFlowCore/TimeManipulator.h>
3128
#include <ScopicFlowCore/TimeViewModel.h>
3229
#include <ScopicFlowCore/TimelineInteractionController.h>
33-
#include <ScopicFlowCore/private/SliceableViewModelManipulatorInterface_p.h>
3430

3531
#include <dspxmodelORM/Clip.h>
3632
#include <dspxmodelORM/ClipSequence.h>
@@ -415,46 +411,31 @@ namespace VisualEditor {
415411

416412
void PianoRollPanelInterfacePrivate::prepareVerticalPageTurn(double start, double length) {
417413
verticalPageTurn.reset();
418-
if (!Internal::EditorPreference::pianoRollAutoPageVerticalAdjustment())
414+
if (!editingClip || !Internal::EditorPreference::pianoRollAutoPageVerticalAdjustment())
419415
return;
420416

421417
auto editArea = pianoRollView->property("centerEditArea").value<QQuickItem *>();
422418
const VerticalView current{clavierViewModel->start(), clavierViewModel->pixelDensity()};
423419
if (!editArea || editArea->height() <= 0 || current.pixelDensity <= 0 || length <= 0)
424420
return;
425421

426-
auto context = ProjectViewModelContext::of(windowHandle);
427-
auto editingTrack = editingClip && editingClip->clipSequence() ? editingClip->clipSequence()->track() : nullptr;
422+
const double clipPosition = editingClip->position();
423+
const double visibleStart = std::max(start, clipPosition);
424+
const double visibleEnd = std::min(start + length, clipPosition + editingClip->clipLength());
425+
if (visibleStart >= visibleEnd)
426+
return;
427+
428+
const double offset = static_cast<double>(editingClip->clipStart()) - clipPosition;
429+
const int first = static_cast<int>(std::floor(visibleStart + offset));
430+
const int last = static_cast<int>(std::ceil(visibleEnd + offset));
431+
const auto pageNotes = editingClip->notes()->slice(first, last - first);
428432
int minKey = 128;
429433
int maxKey = -1;
430-
for (int row = 0; row < trackOverlaySelectorModel->rowCount(); ++row) {
431-
auto item = qobject_cast<Internal::TrackOverlaySelectorItem *>(trackOverlaySelectorModel->index(row, 0).data().value<QObject *>());
432-
if (!item || (!item->overlayVisible() && item->track() != editingTrack))
433-
continue;
434-
435-
auto clips = context->getSingingClipPerTrackSequenceViewModel(item->track());
436-
if (!clips)
434+
for (auto note : pageNotes) {
435+
if (note->length() <= 0)
437436
continue;
438-
const auto clipItems = clips->items();
439-
for (auto clipItem : clipItems) {
440-
auto clip = qobject_cast<sflow::ClipViewModel *>(clipItem);
441-
auto notes = clip ? clip->associatedNoteSequence() : nullptr;
442-
auto sliceable = notes ? notes->property("iSliceable").value<sflow::SliceableViewModelManipulatorInterface *>() : nullptr;
443-
if (!sliceable)
444-
continue;
445-
446-
const double offset = static_cast<double>(clip->clipStart()) - clip->position();
447-
const int first = static_cast<int>(std::floor(start + offset));
448-
const int last = static_cast<int>(std::ceil(start + length + offset));
449-
const auto pageNotes = sliceable->slice(first, last - first);
450-
for (auto noteItem : pageNotes) {
451-
auto note = qobject_cast<sflow::NoteViewModel *>(noteItem);
452-
if (!note)
453-
continue;
454-
minKey = std::min(minKey, note->key());
455-
maxKey = std::max(maxKey, note->key());
456-
}
457-
}
437+
minKey = std::min(minKey, note->keyNumber());
438+
maxKey = std::max(maxKey, note->keyNumber());
458439
}
459440
if (maxKey < minKey)
460441
return;
@@ -789,6 +770,7 @@ namespace VisualEditor {
789770
Q_D(PianoRollPanelInterface);
790771
if (d->editingClip == clip)
791772
return;
773+
d->verticalPageTurn.reset();
792774
disconnect(d->editingClipConnection);
793775
d->editingClipConnection = {};
794776
d->editingClip = clip;

‎src/plugins/visualeditor/internal/addon/PianoRollAddOn.cpp‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,19 @@ namespace VisualEditor::Internal {
323323
resetTimeViewStart();
324324
}
325325

326+
adjustVerticalViewForEditingClip(panelInterface, viewLength, editArea->height(), false);
327+
}
328+
329+
void PianoRollAddOn::adjustVerticalViewForEditingClip(PianoRollPanelInterface *panelInterface, double viewLength, double viewHeight, bool centerEvenIfVisible) {
330+
auto clip = panelInterface->editingClip();
326331
auto clavierViewModel = panelInterface->clavierViewModel();
327-
if (editArea->height() <= 0 || clavierViewModel->pixelDensity() <= 0)
332+
if (!clip || viewHeight <= 0 || clavierViewModel->pixelDensity() <= 0)
328333
return;
329334

330-
const double visibleStart = std::max(timeViewModel->start(), clipStart);
331-
const double visibleEnd = std::min(timeViewModel->start() + viewLength, clipEnd);
335+
const double clipStart = clip->position();
336+
const double viewStart = panelInterface->timeViewModel()->start();
337+
const double visibleStart = std::max(viewStart, clipStart);
338+
const double visibleEnd = std::min(viewStart + viewLength, clipStart + clip->clipLength());
332339
if (visibleStart >= visibleEnd)
333340
return;
334341

@@ -347,9 +354,9 @@ namespace VisualEditor::Internal {
347354
if (maxKey < minKey)
348355
return;
349356

350-
const double viewKeyCount = editArea->height() / clavierViewModel->pixelDensity();
357+
const double viewKeyCount = viewHeight / clavierViewModel->pixelDensity();
351358
const double currentStart = clavierViewModel->start();
352-
if (maxKey + 1.0 <= currentStart && minKey >= currentStart - viewKeyCount)
359+
if (!centerEvenIfVisible && maxKey + 1.0 <= currentStart && minKey >= currentStart - viewKeyCount)
353360
return;
354361
clavierViewModel->setStart(centeredClavierViewStart(minKey, maxKey, viewKeyCount));
355362
}

‎src/plugins/visualeditor/internal/addon/PianoRollAddOn.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace VisualEditor::Internal {
5858
Q_INVOKABLE void editTrack(dspx::Track *track);
5959
Q_INVOKABLE void editClip(dspx::SingingClip *clip);
6060

61+
static void adjustVerticalViewForEditingClip(PianoRollPanelInterface *panelInterface, double viewLength, double viewHeight, bool centerEvenIfVisible);
62+
6163
bool eventFilter(QObject *watched, QEvent *event) override;
6264

6365
bool altPressed() const;

0 commit comments

Comments
 (0)