Skip to content

Commit b9f1a4c

Browse files
committed
Enhance TimelineView functionality and performance
- Improved scene resizing in TimelineView to dynamically expand when nearing the edge of the viewport, enhancing usability. - Updated total beats calculation in rebuildClips to be based on the time signature, ensuring accurate clip positioning and scene width adjustments.
1 parent f219ebe commit b9f1a4c

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/ui/timeline/TimelineView.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "TimelineView.h"
1+
#include "TimelineView.h"
22
#include "AutomationLaneItem.h"
33
#include "AutomationLaneHeader.h"
44
#include "AutomationPointItem.h"
@@ -266,10 +266,16 @@ TimelineView::TimelineView(EditManager* editMgr, QWidget* parent)
266266
loopOverlayItem_->setVisible(false);
267267
}
268268

269-
// Sync ruler scroll with graphics view horizontal scroll
269+
// Sync ruler scroll with graphics view horizontal scroll, and expand scene if near edge
270270
connect(graphicsView_->horizontalScrollBar(), &QScrollBar::valueChanged,
271271
this, [this](int val) {
272272
ruler_->setScrollX(val);
273+
QRectF sr = scene_->sceneRect();
274+
double viewRight = val + graphicsView_->viewport()->width();
275+
if (viewRight > sr.width() - 200.0) {
276+
double newWidth = sr.width() + 800.0;
277+
scene_->setSceneRect(0, 0, newWidth, sr.height());
278+
}
273279
});
274280

275281
// Sync track header vertical scroll with timeline vertical scroll
@@ -896,13 +902,14 @@ void TimelineView::rebuildClips()
896902
int numTracks = tracks.size();
897903
qDebug() << "[rebuildClips] numTracks:" << numTracks;
898904

899-
double totalBeats = 200.0;
905+
double beatsPerBar = editMgr_ ? editMgr_->getTimeSigNumerator() : 4;
906+
double totalBeats = beatsPerBar * 200.0;
900907
for (auto* track : tracks) {
901908
for (auto* clip : track->getClips()) {
902909
auto& ts = clip->edit.tempoSequence;
903910
auto endTime = clip->getPosition().getEnd();
904911
const double endBeat = ts.toBeats(endTime).inBeats();
905-
totalBeats = std::max(totalBeats, endBeat + 16.0);
912+
totalBeats = std::max(totalBeats, endBeat + beatsPerBar * 8.0);
906913
}
907914
}
908915
double sceneWidth = totalBeats * pixelsPerBeat_;

0 commit comments

Comments
 (0)