|
From: Tapio V. <aa...@us...> - 2011-01-31 08:54:10
|
Module: editor
Branch: master
Commit: 6c8acf1592ac6e8fa15e7b54154f7de0d8d6f172
Author: Tapio Vierros <tap...@gm...>
Date: Mon Jan 31 10:48:38 2011 +0200
Draw only the visible portion of pitch visualization (initial version).
---
notegraphwidget.cc | 11 ++++++++++-
pitchvis.cc | 6 +++++-
pitchvis.hh | 2 +-
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index e897beb..0211b47 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -141,11 +141,20 @@ void NoteGraphWidget::timerEvent(QTimerEvent*)
QMutexLocker locker(&m_pitch->mutex);
emit analyzeProgress(m_pitch->getXValue(), width());
if (m_pitch->newDataAvailable()) update();
+ if (m_pitch->isFinished()) killTimer(m_analyzeTimer);
}
}
void NoteGraphWidget::paintEvent(QPaintEvent*) {
- if (m_pitch) m_pitch->paint(this);
+ QScrollArea *scrollArea = NULL;
+ int x1 = 0, x2 = 0;
+ if (parentWidget())
+ scrollArea = qobject_cast<QScrollArea*>(parentWidget()->parent());
+ if (scrollArea && scrollArea->horizontalScrollBar()) {
+ x1 = scrollArea->horizontalScrollBar()->value();
+ x2 = x1 + 2000; // FIXME: Need to figure out the real viewport width from somewhere
+ }
+ if (m_pitch) m_pitch->paint(this, x1, x2);
}
int NoteGraphWidget::getNoteLabelId(NoteLabel* note) const
diff --git a/pitchvis.cc b/pitchvis.cc
index 071daa5..41c7c86 100644
--- a/pitchvis.cc
+++ b/pitchvis.cc
@@ -81,7 +81,7 @@ void PitchVis::run()
curX = width();
}
-void PitchVis::paint(QPaintDevice* widget) {
+void PitchVis::paint(QPaintDevice* widget, int x1, int x2) {
QMutexLocker locker(&mutex);
QPainter painter;
painter.begin(widget);
@@ -92,6 +92,10 @@ void PitchVis::paint(QPaintDevice* widget) {
PitchVis::Paths const& paths = getPaths();
for (PitchVis::Paths::const_iterator it = paths.begin(), itend = paths.end(); it != itend; ++it) {
int oldx, oldy;
+ // Only render paths in view
+ if (time2px(it->back().time) < x1) continue;
+ else if (time2px(it->front().time) > x2) break;
+ // Iterate through the path points
for (PitchPath::const_iterator it2 = it->begin(), it2end = it->end(); it2 != it2end; ++it2) {
int x = time2px(it2->time);
int y = note2px(it2->note);
diff --git a/pitchvis.hh b/pitchvis.hh
index c317da6..ff24bfb 100644
--- a/pitchvis.hh
+++ b/pitchvis.hh
@@ -28,7 +28,7 @@ public:
void run(); // Thread runs here
void stop() { cancelled = true; }
- void paint(QPaintDevice* widget);
+ void paint(QPaintDevice* widget, int x1, int x2);
Paths const& getPaths() { moreAvailable = false; return paths; }
bool newDataAvailable() const { return moreAvailable; }
int getXValue() const { return curX; }
|