|
From: Tapio V. <aa...@us...> - 2011-10-11 20:01:32
|
Author: Tapio Vierros <tap...@gm...>
Date: Tue Oct 4 22:38:21 2011 +0300
Experimental multiple PitchVis support for NoteGraphWidget (not yet used).
---
notegraphwidget.cc | 40 +++++++++++++++++++++++-----------------
notegraphwidget.hh | 13 +++++++------
pitchvis.cc | 7 ++++---
pitchvis.hh | 5 +++--
4 files changed, 37 insertions(+), 28 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index ad4d4ea..a4357af 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -31,7 +31,7 @@ namespace {
NoteGraphWidget::NoteGraphWidget(QWidget *parent)
: NoteLabelManager(parent), m_mouseHotSpot(), m_seeking(), m_actionHappened(),
- m_pitch(), m_seekHandle(this), m_nextNotePixmap(), m_notePixmapTimer(), m_analyzeTimer(), m_playbackTimer(), m_playbackPos(), m_pixmap(), m_pixmapPos()
+ 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 + "; }");
@@ -144,10 +144,10 @@ void NoteGraphWidget::scrollToFirstNote()
}
}
-void NoteGraphWidget::analyzeMusic(QString filepath)
+void NoteGraphWidget::analyzeMusic(QString filepath, int visId)
{
- m_pitch.reset(new PitchVis(filepath, this));
- connect(m_pitch.data(), SIGNAL(renderedImage(QImage,QPoint)), this, SLOT(updatePixmap(QImage,QPoint)));
+ m_pitch[visId].reset(new PitchVis(filepath, this));
+ connect(m_pitch[visId].data(), SIGNAL(renderedImage(QImage,QPoint,int)), this, SLOT(updatePixmap(QImage,QPoint,int)));
m_analyzeTimer = startTimer(100);
}
@@ -158,13 +158,14 @@ void NoteGraphWidget::timerEvent(QTimerEvent* event)
m_playbackPos += m_playbackInterval.restart();
updateMusicPos(m_playbackPos);
- } else if (event->timerId() == m_analyzeTimer && m_pitch) {
+ // FIXME: Only considers first pitchvis
+ } else if (event->timerId() == m_analyzeTimer && m_pitch[0]) {
// PitchVis stuff
double progress, duration;
{
- QMutexLocker locker(&m_pitch->mutex);
- progress = m_pitch->getProgress();
- duration = m_pitch->getDuration();
+ QMutexLocker locker(&m_pitch[0]->mutex);
+ progress = m_pitch[0]->getProgress();
+ duration = m_pitch[0]->getDuration();
}
emit analyzeProgress(1000 * progress, 1000); // Update progress bar
m_duration = std::max(m_duration, duration);
@@ -208,8 +209,10 @@ void NoteGraphWidget::paintEvent(QPaintEvent*)
QPainter painter(this);
// PitchVis pixmap
- if (!m_pixmap.isNull())
- painter.drawPixmap(m_pixmapPos, m_pixmap);
+ for (int i = 0; i < MaxPitchVis; ++i) {
+ if (!m_pixmap[i].isNull())
+ painter.drawPixmap(m_pixmapPos[i], m_pixmap[i]);
+ }
// Octave lines
QPen pen; pen.setWidth(1); pen.setColor(QColor("#666"));
@@ -226,12 +229,12 @@ void NoteGraphWidget::paintEvent(QPaintEvent*)
}
}
-void NoteGraphWidget::updatePixmap(const QImage &image, const QPoint &position)
+void NoteGraphWidget::updatePixmap(const QImage &image, const QPoint &position, int visId)
{
// PitchVis sends its renderings here, let's save & draw them
// This gets actually called in our own thread by our own event loop (queued connection)
- m_pixmap = QPixmap::fromImage(image);
- m_pixmapPos = position;
+ m_pixmap[visId] = QPixmap::fromImage(image);
+ m_pixmapPos[visId] = position;
update();
}
@@ -239,12 +242,13 @@ void NoteGraphWidget::updatePitch()
{
// Called whenever pitch needs updating
// Note that the scrollbar change signals are connected here, so no need to call this from everywhere
- if (!m_pitch) return;
+ if (!m_pitch[0]) 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());
+ for (int i = 0; i < MaxPitchVis; ++i)
+ if (m_pitch[i]) m_pitch[i]->paint(x1, 0, x2, height());
}
void NoteGraphWidget::updateNotes(bool leftToRight)
@@ -287,7 +291,8 @@ void NoteGraphWidget::updateNotes(bool leftToRight)
n2.begin = pos;
n2.end = pos + len;
// Try to find optimal pitch
- if (m_pitch) n2.note = m_pitch->guessNote(pos, pos + len + step, 24);
+ // TODO: Use info also from other pitchvis
+ if (m_pitch[0]) n2.note = m_pitch[0]->guessNote(pos, pos + len + step, 24);
// Calculate starting time for the next note
pos += (len + step) * (leftToRight ? 1 : -1);
// Update NoteLabel geometry
@@ -337,7 +342,8 @@ void NoteGraphWidget::timeCurrent()
double begin = px2s(m_seekHandle.curx());
double end = px2s(m_seekHandle.curx() + selectedNote()->width());
int n = selectedNote()->note().note;
- if (m_pitch) n = m_pitch->guessNote(begin, end, n);
+ // TODO: Use info also from other pitchvis
+ if (m_pitch[0]) n = m_pitch[0]->guessNote(begin, end, n);
op << getNoteLabelId(selectedNote()) << begin << end << n;
doOperation(op);
}
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index 6b770ca..7818c82 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -102,6 +102,7 @@ protected:
};
+const int MaxPitchVis = 2;
class NoteGraphWidget: public NoteLabelManager
{
@@ -115,7 +116,7 @@ public:
void setLyrics(QString lyrics);
void setLyrics(const VocalTrack &track);
- void analyzeMusic(QString filepath);
+ void analyzeMusic(QString filepath, int visId = 0);
void updateNotes(bool leftToRight = true);
void updateMusicPos(qint64 time, bool smoothing = true);
@@ -132,9 +133,9 @@ public slots:
void timeSyllable();
void timeSentence();
void setSeekHandleWrapToViewport(bool state) { m_seekHandle.wrapToViewport = state; }
- void updatePixmap(const QImage &image, const QPoint &position);
+ void updatePixmap(const QImage &image, const QPoint &position, int visId);
void updatePitch();
- void abortPitch() { if (m_pitch) m_pitch->cancel(); }
+ void abortPitch() { for (int i = 0; i < MaxPitchVis; ++i) if (m_pitch[i]) m_pitch[i]->cancel(); }
void scrollToFirstNote();
void startNotePixmapUpdates(); ///< Starts creating pixmaps for NoteLabels
@@ -162,7 +163,7 @@ private:
QPoint m_mouseHotSpot;
bool m_seeking;
bool m_actionHappened;
- QScopedPointer<PitchVis> m_pitch;
+ QScopedPointer<PitchVis> m_pitch[MaxPitchVis];
SeekHandle m_seekHandle;
int m_nextNotePixmap;
int m_notePixmapTimer;
@@ -170,8 +171,8 @@ private:
int m_playbackTimer;
QElapsedTimer m_playbackInterval;
qint64 m_playbackPos;
- QPixmap m_pixmap;
- QPoint m_pixmapPos;
+ QPixmap m_pixmap[MaxPitchVis];
+ QPoint m_pixmapPos[MaxPitchVis];
};
diff --git a/pitchvis.cc b/pitchvis.cc
index 8383f49..6c795fb 100644
--- a/pitchvis.cc
+++ b/pitchvis.cc
@@ -11,8 +11,9 @@
#include <QLabel>
#include <QSettings>
-PitchVis::PitchVis(QString const& filename, QWidget *parent)
- : QThread(parent), mutex(), fileName(filename), duration(), moreAvailable(), quit(), cancelled(), restart(), m_x1(), m_y1(), m_x2(), m_y2(), condition()
+PitchVis::PitchVis(QString const& filename, QWidget *parent, int visId)
+ : QThread(parent), mutex(), fileName(filename), duration(), moreAvailable(), quit(),
+ cancelled(), restart(), m_x1(), m_y1(), m_x2(), m_y2(), m_visId(visId), condition()
{
start(); // Launch the thread
}
@@ -175,7 +176,7 @@ void PitchVis::renderer() {
// Send the image
// This is actually delivered by the reciever's event loop thread, and not called directly from here
- emit renderedImage(image, QPoint(x1, y1));
+ emit renderedImage(image, QPoint(x1, y1), m_visId);
mutex.lock();
// If nothing to do, sleep here
diff --git a/pitchvis.hh b/pitchvis.hh
index 7b83028..a029f4d 100644
--- a/pitchvis.hh
+++ b/pitchvis.hh
@@ -32,7 +32,7 @@ public:
typedef std::vector<PitchPath> Paths;
QMutex mutex;
- PitchVis(QString const& filename, QWidget *parent = NULL);
+ PitchVis(QString const& filename, QWidget *parent = NULL, int visId = 0);
~PitchVis() { stop(); wait(); }
void stop();
@@ -44,7 +44,7 @@ public:
int guessNote(double begin, double end, int initial);
signals:
- void renderedImage(const QImage &image, const QPoint &position);
+ void renderedImage(const QImage &image, const QPoint &position, int visId);
protected:
void run(); // Thread runs here
@@ -64,5 +64,6 @@ private:
bool restart; ///< Should we start the rendering again?
QWaitCondition condition;
int m_x1, m_y1, m_x2, m_y2;
+ int m_visId;
};
|