|
From: Tapio V. <aa...@us...> - 2011-01-19 14:35:17
|
Module: editor
Branch: master
Commit: 9583a36d256423687624e1cc250f75eeb093b583
Author: Tapio Vierros <tap...@gm...>
Date: Wed Jan 19 16:31:44 2011 +0200
Initial implementation of music position indicator / seeking handle.
Seeking works, but position needs interpolation for this to be usable.
(Time updates are signaled too slowly, at about 500ms at minimum.)
---
editorapp.cc | 6 ++--
notegraphwidget.cc | 68 ++++++++++++++++++++++++++++++++++++++++++++++-----
notegraphwidget.hh | 18 ++++++++++++-
notelabel.cc | 2 +-
4 files changed, 81 insertions(+), 13 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 6c1bae9..073049e 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -64,11 +64,12 @@ EditorApp::EditorApp(QWidget *parent): QMainWindow(parent), projectFileName(), h
// Audio stuff
player = new Phonon::MediaObject(this);
audioOutput = new Phonon::AudioOutput(this);
- player->setTickInterval(500);
+ player->setTickInterval(100);
Phonon::createPath(player, audioOutput);
// Audio signals
connect(player, SIGNAL(tick(qint64)), this, SLOT(audioTick(qint64)));
connect(player, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged()));
+ connect(noteGraph, SIGNAL(seek(qint64)), player, SLOT(seek(qint64)));
}
void EditorApp::operationDone(const Operation &op)
@@ -457,8 +458,7 @@ void EditorApp::metaDataChanged()
void EditorApp::audioTick(qint64 time)
{
- // TODO: Update a cursor in NoteGraphWidget
- // (the cursor needs to be first implemented)
+ if (noteGraph) noteGraph->updateMusicPos(time);
}
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 6f0ddb4..4c189ec 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -16,7 +16,7 @@ namespace {
}
NoteGraphWidget::NoteGraphWidget(QWidget *parent)
- : QLabel(parent), m_panHotSpot(), m_selectedNote(), m_selectedAction(NONE), m_actionHappened(), m_pitch()
+ : QLabel(parent), m_panHotSpot(), m_selectedNote(), m_selectedAction(NONE), m_seeking(), m_actionHappened(), m_pitch(), m_seekHandle(this)
{
// FIXME: Temporary hack to make testing quicker
analyzeMusic("music.ogg");
@@ -186,16 +186,30 @@ void NoteGraphWidget::updateNotes()
}
}
+void NoteGraphWidget::updateMusicPos(qint64 time)
+{
+ int x = s2px(time / 1000.0) - m_seekHandle.width() / 2;
+ m_seekHandle.move(x, 0);
+}
+
void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
{
NoteLabel *child = qobject_cast<NoteLabel*>(childAt(event->pos()));
if (!child) {
- // Left click empty area = pan
- if (event->button() == Qt::LeftButton)
+ SeekHandle *seekh = qobject_cast<SeekHandle*>(childAt(event->pos()));
+ if (!seekh) {
+ // Left click empty area = pan
+ if (event->button() == Qt::LeftButton)
+ m_panHotSpot = event->pos();
+ // Right click empty area = deselect
+ if (event->button() == Qt::RightButton)
+ selectNote(NULL);
+ } else {
+ // Seeking
+ m_seeking = true;
m_panHotSpot = event->pos();
- // Right click empty area = deselect
- if (event->button() == Qt::RightButton)
- selectNote(NULL);
+ setCursor(QCursor(Qt::SizeHorCursor));
+ }
return;
}
if (child->isHidden()) return;
@@ -263,6 +277,7 @@ void NoteGraphWidget::mouseReleaseEvent(QMouseEvent *event)
}
m_actionHappened = false;
m_panHotSpot = QPoint();
+ m_seeking = false;
setCursor(QCursor());
updateNotes();
}
@@ -302,8 +317,15 @@ 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()));
+ }
// Pan
- if (!m_panHotSpot.isNull()) {
+ else if (!m_panHotSpot.isNull()) {
setCursor(QCursor(Qt::ClosedHandCursor));
QScrollArea *scrollArea = NULL;
if (parentWidget())
@@ -422,6 +444,38 @@ double NoteGraphWidget::px2s(int px) const { return m_pitch->px2time(px); }
int NoteGraphWidget::n2px(int note) const { return m_pitch->note2px(note); }
int NoteGraphWidget::px2n(int px) const { return m_pitch->px2note(px); }
+
+
+SeekHandle::SeekHandle(QWidget *parent)
+ : QLabel(parent)
+{
+ // FIXME: height from notegraph
+ QImage image(8, 768, QImage::Format_ARGB32_Premultiplied);
+ image.fill(qRgba(0, 0, 0, 0));
+ QLinearGradient gradient(0, 0, image.width()-1, 0);
+ gradient.setColorAt(0.0, QColor(255,255,0,50));
+ gradient.setColorAt(0.5, QColor(255,255,0,200));
+ gradient.setColorAt(1.0, QColor(255,255,0,50));
+
+ QPainter painter;
+ painter.begin(&image);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setBrush(gradient);
+ painter.drawRect(QRect(0, 0, image.width(), image.height()));
+
+ setPixmap(QPixmap::fromImage(image));
+
+ setStatusTip(tr("Seek by dragging"));
+}
+
+void SeekHandle::mouseMoveEvent(QMouseEvent *event)
+{
+ setCursor(QCursor(Qt::SizeHorCursor));
+ event->ignore();
+}
+
+
+
void FloatingGap::addNote(NoteLabel* n)
{
notes.push_back(n);
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index ffc2f92..e4ab11a 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -10,6 +10,16 @@
class NoteLabel;
typedef QList<NoteLabel*> NoteLabels;
+
+class SeekHandle: public QLabel
+{
+ Q_OBJECT
+public:
+ SeekHandle(QWidget *parent = 0);
+ void mouseMoveEvent(QMouseEvent *event);
+};
+
+
class NoteGraphWidget: public QLabel
{
Q_OBJECT
@@ -23,8 +33,9 @@ public:
void setLyrics(const VocalTrack &track);
void analyzeMusic(QString filepath);
void updateNotes();
+ void updateMusicPos(qint64 time);
- void selectNote(NoteLabel* note);
+ void selectNote(NoteLabel *note);
NoteLabel* selectedNote() const { return m_selectedNote; }
int getNoteLabelId(NoteLabel* note) const;
@@ -41,12 +52,13 @@ public:
signals:
void updateNoteInfo(NoteLabel*);
void operationDone(const Operation&);
+ void seek(qint64 time);
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event);
- void mouseDoubleClickEvent(QMouseEvent * event);
+ void mouseDoubleClickEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent * event);
void keyPressEvent(QKeyEvent *event);
@@ -57,9 +69,11 @@ private:
QPoint m_panHotSpot;
NoteLabel* m_selectedNote;
enum NoteAction { NONE, RESIZE, MOVE } m_selectedAction;
+ bool m_seeking;
bool m_actionHappened;
NoteLabels m_notes;
QScopedPointer<PitchVis> m_pitch;
+ SeekHandle m_seekHandle;
};
diff --git a/notelabel.cc b/notelabel.cc
index 7a7ff05..599722e 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -77,7 +77,7 @@ void NoteLabel::createPixmap(QSize size)
setPixmap(QPixmap::fromImage(image));
- setStatusTip(QString("Lyric: ") + lyric());
+ setStatusTip(tr("Lyric: ") + lyric());
updateNote();
}
|