|
From: Tapio V. <aa...@us...> - 2011-02-09 09:44:29
|
Module: editor
Branch: master
Commit: bb68d9647afb4bcb686fc164e7652f3645f789eb
Author: Tapio Vierros <tap...@gm...>
Date: Wed Feb 9 11:28:29 2011 +0200
Fix high "idle" cpu usage in new rendering code.
---
editorapp.cc | 5 +++-
notegraphwidget.cc | 54 +++++++++++++++++++++++++++++++++------------------
notegraphwidget.hh | 3 ++
3 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 8a5f6cd..f096ba8 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -1,4 +1,5 @@
#include <QProgressBar>
+#include <QScrollBar>
#include <QMessageBox>
#include <QFileDialog>
#include <QDesktopServices>
@@ -85,9 +86,11 @@ void EditorApp::setupNoteGraph()
QList<int> ss; ss.push_back(700); ss.push_back(300); // Proportions, not pixels
ui.splitter->setSizes(ss);
- // Custom signals/slots
+ // Signals/slots
connect(noteGraph, SIGNAL(operationDone(const Operation&)), this, SLOT(operationDone(const Operation&)));
connect(noteGraph, SIGNAL(updateNoteInfo(NoteLabel*)), this, SLOT(updateNoteInfo(NoteLabel*)));
+ connect(ui.noteGraphScroller->horizontalScrollBar(), SIGNAL(valueChanged(int)), noteGraph, SLOT(updatePitch()));
+ connect(ui.noteGraphScroller->verticalScrollBar(), SIGNAL(valueChanged(int)), noteGraph, SLOT(updatePitch()));
connect(ui.cmdTimeSentence, SIGNAL(pressed()), noteGraph, SLOT(timeSentence()));
connect(ui.cmdSkipSentence, SIGNAL(pressed()), noteGraph, SLOT(selectNextSentenceStart()));
connect(ui.chkGrabSeekHandle, SIGNAL(toggled(bool)), noteGraph, SLOT(setSeekHandleWrapToViewport(bool)));
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 8032152..141e5d4 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -112,6 +112,22 @@ void NoteGraphWidget::finalizeNewLyrics()
updateNotes();
}
+void NoteGraphWidget::calcViewport(int &x1, int &y1, int &x2, int &y2) const
+{
+ QScrollArea *scrollArea = NULL;
+ x1 = 0, x2 = 0, y1 = 0, y2 = 0;
+ if (parentWidget())
+ scrollArea = qobject_cast<QScrollArea*>(parentWidget()->parent());
+ if (scrollArea) {
+ if (scrollArea->horizontalScrollBar())
+ x1 = scrollArea->horizontalScrollBar()->value();
+ x2 = x1 + scrollArea->width();
+ if (scrollArea->verticalScrollBar())
+ y1 = scrollArea->verticalScrollBar()->value();
+ y2 = y1 + scrollArea->height();
+ }
+}
+
void NoteGraphWidget::analyzeMusic(QString filepath)
{
m_pitch.reset(new PitchVis(filepath, this));
@@ -129,37 +145,27 @@ void NoteGraphWidget::timerEvent(QTimerEvent* event)
} else if (event->timerId() == m_analyzeTimer && m_pitch) {
// PitchVis stuff
double progress, duration;
- bool needUpdate;
{
QMutexLocker locker(&m_pitch->mutex);
progress = m_pitch->getProgress();
duration = m_pitch->getDuration();
- needUpdate = m_pitch->newDataAvailable() || duration != m_duration;
}
emit analyzeProgress(1000 * progress, 1000); // Update progress bar
- if (needUpdate) {
- m_duration = std::max(m_duration, duration);
- update();
+ m_duration = std::max(m_duration, duration);
+ // Analyzing has ended?
+ if (progress == 1.0) {
+ killTimer(m_analyzeTimer);
+ updatePitch();
}
- if (progress == 1) killTimer(m_analyzeTimer);
}
}
void NoteGraphWidget::paintEvent(QPaintEvent*) {
setFixedSize(s2px(m_duration), height());
- // Find out the horizontal viewport
- 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 + scrollArea->width();
- }
-
- // Ask for a new render
- if (m_pitch) m_pitch->paint(x1, 0, x2, height());
+ // Find out the viewport
+ int x1, y1, x2, y2;
+ calcViewport(x1, y1, x2, y2);
QPainter painter;
painter.begin(this);
@@ -185,6 +191,16 @@ void NoteGraphWidget::updatePixmap(const QImage &image, const QPoint &position)
update();
}
+void NoteGraphWidget::updatePitch()
+{
+ if (!m_pitch) return;
+ // Find out the viewport
+ int x1, y1, x2, y2;
+ calcViewport(x1, y1, x2, y2);
+ // Ask for a new render
+ m_pitch->paint(x1, 0, x2, height());
+}
+
void NoteGraphWidget::updateNotes(bool leftToRight)
{
// Here happens the magic that adjusts the floating
@@ -245,7 +261,7 @@ void NoteGraphWidget::updateMusicPos(qint64 time, bool smoothing)
killTimer(m_playbackTimer);
m_seekHandle.move(x, 0);
if (smoothing)
- m_playbackTimer = startTimer(17); // Hope for 60 fps
+ m_playbackTimer = startTimer(20); // Hope for 50 fps
m_playbackInterval.restart();
}
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index 8c22ca6..9fa9c2c 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -116,6 +116,7 @@ public slots:
void timeSentence();
void setSeekHandleWrapToViewport(bool state) { m_seekHandle.wrapToViewport = state; }
void updatePixmap(const QImage &image, const QPoint &position);
+ void updatePitch();
signals:
void analyzeProgress(int, int);
@@ -130,10 +131,12 @@ protected:
void keyPressEvent(QKeyEvent *event);
void timerEvent(QTimerEvent *event);
void paintEvent(QPaintEvent*);
+ void resizeEvent(QResizeEvent *) { updatePitch(); }
private:
void finalizeNewLyrics();
void timeCurrent();
+ void calcViewport(int &x1, int &y1, int &x2, int &y2) const;
QPoint m_panHotSpot;
bool m_seeking;
|