|
From: Tapio V. <aa...@us...> - 2011-01-20 09:04:02
|
Module: editor
Branch: master
Commit: 70da8ed859cec6b85bdfdfed4bb5b44a2eeacaa2
Author: Tapio Vierros <tap...@gm...>
Date: Thu Jan 20 11:03:19 2011 +0200
Primitive SeekHandle movement smoothener.
---
editorapp.cc | 25 +++++++++++++++++--------
editorapp.hh | 2 ++
notegraphwidget.cc | 16 ++++++++++++++--
notegraphwidget.hh | 8 ++++++--
4 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index f2c7ecb..7fca538 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -1,5 +1,4 @@
#include <QtGui>
-#include <phonon/MediaObject>
#include <phonon/AudioOutput>
#include <iostream>
#include "editorapp.hh"
@@ -72,6 +71,7 @@ EditorApp::EditorApp(QWidget *parent): QMainWindow(parent), projectFileName(), h
Phonon::createPath(player, audioOutput);
// Audio signals
connect(player, SIGNAL(tick(qint64)), this, SLOT(audioTick(qint64)));
+ connect(player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(playerStateChanged(Phonon::State,Phonon::State)));
connect(player, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged()));
connect(noteGraph, SIGNAL(seek(qint64)), player, SLOT(seek(qint64)));
}
@@ -406,7 +406,7 @@ void EditorApp::on_actionLyricsFromClipboard_triggered()
void EditorApp::on_actionWhatsThis_triggered()
{
- QWhatsThis::enterWhatsThisMode ();
+ QWhatsThis::enterWhatsThisMode();
}
void EditorApp::on_actionAbout_triggered()
@@ -456,11 +456,6 @@ void EditorApp::metaDataChanged()
}
}
-void EditorApp::audioTick(qint64 time)
-{
- if (noteGraph) noteGraph->updateMusicPos(time);
-}
-
void EditorApp::on_cmdPlay_toggled(bool checked)
{
if (player) {
@@ -484,10 +479,24 @@ void EditorApp::on_cmdPlay_toggled(bool checked)
void EditorApp::on_cmdStop_clicked()
{
if (player) player->stop();
- if (noteGraph) noteGraph->updateMusicPos(0);
+ if (noteGraph) noteGraph->updateMusicPos(0, false);
ui.cmdPlay->setChecked(false);
}
+void EditorApp::audioTick(qint64 time)
+{
+ if (noteGraph && player)
+ noteGraph->updateMusicPos(time, (player->state() == Phonon::PlayingState ? true : false));
+}
+
+void EditorApp::playerStateChanged(Phonon::State newstate, Phonon::State oldstate)
+{
+ (void)oldstate;
+ if (newstate != Phonon::PlayingState) {
+ noteGraph->stopMusic();
+ }
+}
+
void EditorApp::on_txtTitle_editingFinished() { updateSongMeta(); }
void EditorApp::on_txtArtist_editingFinished() { updateSongMeta(); }
void EditorApp::on_txtGenre_editingFinished() { updateSongMeta(); }
diff --git a/editorapp.hh b/editorapp.hh
index 276030f..16540f8 100644
--- a/editorapp.hh
+++ b/editorapp.hh
@@ -1,5 +1,6 @@
#pragma once
+#include <phonon/MediaObject>
#include "ui_editor.h"
#include "operation.hh"
#include "song.hh"
@@ -31,6 +32,7 @@ public slots:
void updateNoteInfo(NoteLabel *note);
void metaDataChanged();
void audioTick(qint64 time);
+ void playerStateChanged(Phonon::State newstate, Phonon::State olstate);
// Automatic slots
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 4c189ec..22d2f00 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -186,10 +186,18 @@ void NoteGraphWidget::updateNotes()
}
}
-void NoteGraphWidget::updateMusicPos(qint64 time)
+void NoteGraphWidget::updateMusicPos(qint64 time, bool smoothing)
{
int x = s2px(time / 1000.0) - m_seekHandle.width() / 2;
+ m_seekHandle.killTimer(m_seekHandle.moveTimerId);
m_seekHandle.move(x, 0);
+ if (smoothing)
+ m_seekHandle.moveTimerId = m_seekHandle.startTimer(px2s(1) * 1000);
+}
+
+void NoteGraphWidget::stopMusic()
+{
+ m_seekHandle.killTimer(m_seekHandle.moveTimerId);
}
void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
@@ -320,7 +328,6 @@ void NoteGraphWidget::mouseMoveEvent(QMouseEvent *event)
// Seeking
if (m_seeking) {
QPoint diff = event->pos() - m_panHotSpot;
- std::cout << diff.x() << " " << event->pos().x() << " " << m_panHotSpot.x() << std::endl;
m_seekHandle.move(m_panHotSpot.x() + diff.x(), 0);
emit seek(1000 * px2s(m_seekHandle.x()));
}
@@ -474,6 +481,11 @@ void SeekHandle::mouseMoveEvent(QMouseEvent *event)
event->ignore();
}
+void SeekHandle::timerEvent(QTimerEvent *event)
+{
+ move(x() + 1, 0);
+}
+
void FloatingGap::addNote(NoteLabel* n)
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index e4ab11a..e100453 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -16,7 +16,10 @@ class SeekHandle: public QLabel
Q_OBJECT
public:
SeekHandle(QWidget *parent = 0);
+ int moveTimerId;
+protected:
void mouseMoveEvent(QMouseEvent *event);
+ void timerEvent(QTimerEvent *event);
};
@@ -33,7 +36,9 @@ public:
void setLyrics(const VocalTrack &track);
void analyzeMusic(QString filepath);
void updateNotes();
- void updateMusicPos(qint64 time);
+
+ void updateMusicPos(qint64 time, bool smoothing);
+ void stopMusic();
void selectNote(NoteLabel *note);
NoteLabel* selectedNote() const { return m_selectedNote; }
@@ -48,7 +53,6 @@ public:
int px2n(int px) const;
int h() const { return m_pitch->height; }
-
signals:
void updateNoteInfo(NoteLabel*);
void operationDone(const Operation&);
|