|
From: Tapio V. <aa...@us...> - 2011-02-24 19:56:55
|
Author: Tapio Vierros <tap...@gm...>
Date: Thu Feb 24 21:40:32 2011 +0200
More NoteLabel pixmap creation based optimizations - really fast now.
---
busydialog.hh | 10 ++++++----
editorapp.cc | 1 +
notegraphwidget.cc | 31 +++++++++++++++++++++++++++----
notegraphwidget.hh | 4 ++++
notelabel.cc | 3 +--
notelabel.hh | 2 +-
notelabelmanager.cc | 3 ++-
7 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/busydialog.hh b/busydialog.hh
index 6d2d5c1..b007c1b 100644
--- a/busydialog.hh
+++ b/busydialog.hh
@@ -18,11 +18,13 @@ public:
timer.start();
}
void operator()() {
- if (count == 0 && isVisible()) // Let's not process events all the time
- QApplication::processEvents();
- count = (count + 1) % interval;
// Only show the dialog after certainamount of time
- if (isHidden() && timer.elapsed() > 1500) open();
+ if (isHidden() && timer.elapsed() > 3000) open();
+ if (isVisible()) {
+ if (count == 0) // Let's not process events all the time
+ QApplication::processEvents();
+ count = (count + 1) % interval;
+ }
}
protected:
void closeEvent(QCloseEvent* event) { event->ignore(); }
diff --git a/editorapp.cc b/editorapp.cc
index eb42c71..6ebedd9 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -221,6 +221,7 @@ void EditorApp::doOpStack()
}
noteGraph->updateNotes();
+ noteGraph->startNotePixmapUpdates();
if (!newMusic.isEmpty()) setMusic(newMusic);
updateMenuStates();
}
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 68dba06..76d4aff 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -32,7 +32,7 @@ namespace {
NoteGraphWidget::NoteGraphWidget(QWidget *parent)
: NoteLabelManager(parent), m_mouseHotSpot(), m_seeking(), m_actionHappened(),
- m_pitch(), m_seekHandle(this), m_analyzeTimer(), m_playbackTimer(), m_playbackPos(), m_pixmap(), m_pixmapPos()
+ m_pitch(), m_seekHandle(this), m_nextNotePixmap(), m_notePixmapTimer(), m_analyzeTimer(), m_playbackTimer(), m_playbackPos(), m_pixmap(), m_pixmapPos()
{
setProperty("darkBackground", true);
setStyleSheet("QLabel[darkBackground=\"true\"] { background: " + BGColor + "; }");
@@ -76,7 +76,7 @@ void NoteGraphWidget::setLyrics(QString lyrics)
if (!word.isEmpty()) {
Note note(word); note.end = NoteLabel::default_length; note.note = 24;
if (sentenceStart) note.lineBreak = true;
- doOperation(opFromNote(note, m_notes.size(), !firstNote));
+ doOperation(opFromNote(note, m_notes.size(), !firstNote), Operation::NO_UPDATE);
firstNote = false;
sentenceStart = false;
}
@@ -96,7 +96,7 @@ void NoteGraphWidget::setLyrics(const VocalTrack &track)
const Notes ¬es = track.notes;
for (Notes::const_iterator it = notes.begin(); it != notes.end(); ++it) {
if (it->type == Note::SLEEP) continue;
- doOperation(opFromNote(*it, m_notes.size(), false));
+ doOperation(opFromNote(*it, m_notes.size(), false), Operation::NO_UPDATE);
busy();
}
@@ -130,6 +130,9 @@ void NoteGraphWidget::finalizeNewLyrics()
// Scroll to show the first note
scrollToFirstNote();
+
+ // Start creating pixmaps for notes
+ startNotePixmapUpdates();
}
void NoteGraphWidget::scrollToFirstNote()
@@ -171,10 +174,30 @@ void NoteGraphWidget::timerEvent(QTimerEvent* event)
killTimer(m_analyzeTimer);
updatePitch();
}
+ } else if (event->timerId() == m_notePixmapTimer) {
+ // Here we create a pixmap for a NoteLabel
+ if (m_nextNotePixmap >= m_notes.size()) {
+ killTimer(m_notePixmapTimer);
+ m_notePixmapTimer = 0;
+ m_nextNotePixmap = 0;
+ return;
+ }
+ // Loop until a pixmap-to-create is found
+ while (m_nextNotePixmap < m_notes.size() && !m_notes[m_nextNotePixmap]->createPixmap())
+ ++m_nextNotePixmap;
+ ++m_nextNotePixmap;
}
}
-void NoteGraphWidget::paintEvent(QPaintEvent*) {
+void NoteGraphWidget::startNotePixmapUpdates()
+{
+ // With 0-delay, note pixmaps are created whenever there is not events to process
+ if (!m_notePixmapTimer) m_notePixmapTimer = startTimer(0);
+ m_nextNotePixmap = 0;
+}
+
+void NoteGraphWidget::paintEvent(QPaintEvent*)
+{
setFixedSize(s2px(m_duration), height());
// Find out the viewport
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index cb6b458..14c37e0 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -36,6 +36,7 @@ public:
NoteLabelManager(QWidget *parent = 0);
virtual void updateNotes(bool leftToRight = true) {}
+ virtual void startNotePixmapUpdates() {}
void clearNotes();
void selectNote(NoteLabel *note, bool clearPrevious = true);
@@ -134,6 +135,7 @@ public slots:
void updatePitch();
void abortPitch() { if (m_pitch) m_pitch->cancel(); }
void scrollToFirstNote();
+ void startNotePixmapUpdates();
signals:
void analyzeProgress(int, int);
@@ -161,6 +163,8 @@ private:
bool m_actionHappened;
QScopedPointer<PitchVis> m_pitch;
SeekHandle m_seekHandle;
+ int m_nextNotePixmap;
+ int m_notePixmapTimer;
int m_analyzeTimer;
int m_playbackTimer;
QElapsedTimer m_playbackInterval;
diff --git a/notelabel.cc b/notelabel.cc
index 74657d9..5c4701b 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -21,8 +21,7 @@ NoteLabel::NoteLabel(const Note ¬e, QWidget *parent, bool floating)
{
updateLabel();
setMouseTracking(true);
- // Deferred graphics generation (to make creation quick as object might also be deleted quickly)
- QTimer::singleShot(render_delay, this, SLOT(createPixmap()));
+ hide();
}
void NoteLabel::updatePixmap()
diff --git a/notelabel.hh b/notelabel.hh
index ab14763..21eec62 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -45,7 +45,7 @@ public:
bool operator<(const NoteLabel &rhs) const { return m_note.begin < rhs.note().begin; }
public slots:
- void createPixmap() { show(); updatePixmap(); }
+ bool createPixmap() { if (isVisible()) return false; show(); updatePixmap(); return true; }
void updatePixmap();
protected:
diff --git a/notelabelmanager.cc b/notelabelmanager.cc
index 4bf3ed3..8562c49 100644
--- a/notelabelmanager.cc
+++ b/notelabelmanager.cc
@@ -162,7 +162,7 @@ void NoteLabelManager::createNote(double time)
int nlvl = (id > 0) ? m_notes[id-1]->note().note : 24;
QTextStream ts(&text, QIODevice::ReadOnly);
- // Loop throguh all words
+ // Loop through all words
while (!ts.atEnd()) {
QString word;
ts >> word;
@@ -180,6 +180,7 @@ void NoteLabelManager::createNote(double time)
++id;
}
}
+ startNotePixmapUpdates();
}
}
|