|
From: Tapio V. <aa...@us...> - 2011-02-03 11:05:23
|
Module: editor
Branch: master
Commit: 134c06c83c6607e5d97d1ddefc685fb1bc2cfe25
Author: Tapio Vierros <tap...@gm...>
Date: Thu Feb 3 13:02:17 2011 +0200
SeekHandle improvements.
* Smoother
* Tiny timerEvent intervals cannot be reached on all systems - now handled
* Checkbox for disabling wrapping to viewport now works
---
editorapp.cc | 1 +
notegraphwidget.cc | 26 +++++++++++++++-----------
notegraphwidget.hh | 11 ++++++++---
3 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 7262cbb..b3b959a 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -44,6 +44,7 @@ EditorApp::EditorApp(QWidget *parent): QMainWindow(parent), gettingStarted(), pr
connect(ui.cmdTimeSentence, SIGNAL(pressed()), noteGraph, SLOT(timeSentence()));
connect(ui.cmdSkipSyllable, SIGNAL(pressed()), noteGraph, SLOT(selectNextSyllable()));
connect(ui.cmdSkipSentence, SIGNAL(pressed()), noteGraph, SLOT(selectNextSentenceStart()));
+ connect(ui.chkGrabSeekHandle, SIGNAL(toggled(bool)), noteGraph, SLOT(setSeekHandleWrapToViewport(bool)));
connect(ui.cmdMusicFile, SIGNAL(clicked()), this, SLOT(on_actionMusicFile_triggered()));
show(); // Needed in order to get real values from width()
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 37c66a8..ccd1886 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -22,7 +22,7 @@ namespace {
NoteGraphWidget::NoteGraphWidget(QWidget *parent)
: NoteLabelManager(parent), m_panHotSpot(), m_seeking(), m_actionHappened(),
- m_pitch(), m_seekHandle(this), m_duration(10.0)
+ m_pitch(), m_seekHandle(this), m_analyzeTimer(), m_playbackTimer(), m_playbackPos(), m_duration(10.0)
{
setProperty("darkBackground", true);
setStyleSheet("QLabel[darkBackground=\"true\"] { background: rgb(32, 32, 32); }");
@@ -115,9 +115,13 @@ void NoteGraphWidget::analyzeMusic(QString filepath)
m_analyzeTimer = startTimer(100);
}
-void NoteGraphWidget::timerEvent(QTimerEvent*)
+void NoteGraphWidget::timerEvent(QTimerEvent* event)
{
- if (m_pitch) {
+ if (event->timerId() == m_playbackTimer) {
+ m_playbackPos += m_playbackInterval.restart();
+ updateMusicPos(m_playbackPos);
+
+ } else if (event->timerId() == m_analyzeTimer && m_pitch) {
QMutexLocker locker(&m_pitch->mutex);
emit analyzeProgress(1000 * m_pitch->getProgress(), 1000);
if (m_pitch->newDataAvailable()) {
@@ -196,16 +200,18 @@ void NoteGraphWidget::updateNotes(bool leftToRight)
void NoteGraphWidget::updateMusicPos(qint64 time, bool smoothing)
{
- int x = s2px(time / 1000.0) - m_seekHandle.width() / 2;
- m_seekHandle.killTimer(m_seekHandle.moveTimerId);
+ m_playbackPos = time;
+ int x = s2px(m_playbackPos / 1000.0) - m_seekHandle.width() / 2;
+ killTimer(m_playbackTimer);
m_seekHandle.move(x, 0);
if (smoothing)
- m_seekHandle.moveTimerId = m_seekHandle.startTimer(std::ceil(px2s(1) * 1000));
+ m_playbackTimer = startTimer(17); // Hope for 60 fps
+ m_playbackInterval.restart();
}
void NoteGraphWidget::stopMusic()
{
- m_seekHandle.killTimer(m_seekHandle.moveTimerId);
+ killTimer(m_playbackTimer);
}
void NoteGraphWidget::seek(int x)
@@ -480,12 +486,10 @@ void SeekHandle::mouseMoveEvent(QMouseEvent *event)
event->ignore();
}
-void SeekHandle::timerEvent(QTimerEvent*)
+void SeekHandle::moveEvent(QMoveEvent*)
{
- move(x() + 1, 0);
-
// Make handle always visible in the ScrollArea
- if (parentWidget() && parentWidget()->parentWidget()) {
+ if (wrapToViewport && parentWidget() && parentWidget()->parentWidget()) {
QScrollArea *scrollArea = qobject_cast<QScrollArea*>(parentWidget()->parentWidget()->parent());
if (scrollArea) {
QScrollBar *scrollVer = scrollArea->verticalScrollBar();
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index e27ae4d..e53d1a3 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -6,6 +6,7 @@
#include <QLabel>
#include <QList>
#include <QScopedPointer>
+#include <QElapsedTimer>
class NoteLabel;
typedef QList<NoteLabel*> NoteLabels;
@@ -17,10 +18,10 @@ class SeekHandle: public QLabel
public:
SeekHandle(QWidget *parent = 0);
int curx() const { return x() + width() / 2; }
- int moveTimerId;
+ bool wrapToViewport;
protected:
void mouseMoveEvent(QMouseEvent *event);
- void timerEvent(QTimerEvent *event);
+ void moveEvent(QMoveEvent *event);
};
@@ -88,7 +89,7 @@ public:
void analyzeMusic(QString filepath);
void updateNotes(bool leftToRight = true);
- void updateMusicPos(qint64 time, bool smoothing);
+ void updateMusicPos(qint64 time, bool smoothing = true);
void stopMusic();
void seek(int x);
@@ -99,6 +100,7 @@ public:
public slots:
void timeSyllable();
void timeSentence();
+ void setSeekHandleWrapToViewport(bool state) { m_seekHandle.wrapToViewport = state; }
signals:
void analyzeProgress(int, int);
@@ -125,6 +127,9 @@ private:
QScopedPointer<PitchVis> m_pitch;
SeekHandle m_seekHandle;
int m_analyzeTimer;
+ int m_playbackTimer;
+ QElapsedTimer m_playbackInterval;
+ qint64 m_playbackPos;
double m_duration;
};
|