|
From: Tapio V. <aa...@us...> - 2011-01-20 09:29:53
|
Module: editor
Branch: master
Commit: 64406d22d541dde789cba496a7049a270e3da753
Author: Tapio Vierros <tap...@gm...>
Date: Thu Jan 20 11:28:52 2011 +0200
Move pitch pixmap applying to pitchvis.
This is preparation for threading.
---
notegraphwidget.cc | 18 ------------------
pitchvis.cc | 26 +++++++++++++++++++++++++-
2 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index c2e91b7..97a07e3 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -110,24 +110,6 @@ void NoteGraphWidget::finalizeNewLyrics()
void NoteGraphWidget::analyzeMusic(QString filepath)
{
m_pitch.reset(new PitchVis(filepath.toStdString(), this));
- unsigned width = m_pitch->width(), height = m_pitch->height;
- QProgressDialog progress(tr("Rendering pitch data..."), tr("&Abort"), 0, width, this);
- progress.setWindowModality(Qt::WindowModal);
-
- QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
- unsigned* rgba = reinterpret_cast<unsigned*>(image.bits());
- for (unsigned x = 0; x < width; ++x) {
- progress.setValue(x);
- if (progress.wasCanceled()) break;
-
- for (unsigned y = 0; y < height; ++y) {
- rgba[y * width + x] = m_pitch->pixel(x, y).rgba();
- }
- }
- setPixmap(QPixmap::fromImage(image));
- progress.setValue(width);
-
- setFixedSize(width, height);
}
int NoteGraphWidget::getNoteLabelId(NoteLabel* note) const
diff --git a/pitchvis.cc b/pitchvis.cc
index 5bcca18..2e68940 100644
--- a/pitchvis.cc
+++ b/pitchvis.cc
@@ -6,6 +6,7 @@
#include <iostream>
#include <stdexcept>
#include <QProgressDialog>
+#include <QLabel>
/** Read the entire file into a vector of some type.
The file needs to be in the machine-native endianess. **/
@@ -39,7 +40,7 @@ PitchVis::PitchVis(std::string const& filename, QWidget *parent): QWidget(parent
progress.setLabelText(tr("Analyzing pitch data..."));
for (unsigned x = 0; x < width; ++x) {
progress.setValue(x);
- if (progress.wasCanceled()) return;
+ if (progress.wasCanceled()) break;
// Get decoded samples from ffmpeg
std::vector<float> data(step*2);
@@ -79,6 +80,29 @@ PitchVis::PitchVis(std::string const& filename, QWidget *parent): QWidget(parent
}
}
progress.setValue(width);
+
+ QProgressDialog progress2(tr("Rendering pitch data..."), tr("&Abort"), 0, 1, this);
+ progress2.setWindowModality(Qt::WindowModal);
+
+ QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
+ unsigned* rgba = reinterpret_cast<unsigned*>(image.bits());
+ for (unsigned x = 0; x < width; ++x) {
+ progress2.setValue(x);
+ if (progress2.wasCanceled()) break;
+
+ for (unsigned y = 0; y < height; ++y) {
+ rgba[y * width + x] = pixel(x, y).rgba();
+ }
+ }
+
+ progress2.setLabelText(tr("Applying image..."));
+ QLabel *ngw = qobject_cast<QLabel*>(parent);
+ if (ngw) {
+ ngw->setPixmap(QPixmap::fromImage(image));
+ ngw->setFixedSize(width, height);
+ }
+
+ progress2.setValue(width);
}
unsigned PitchVis::freq2px(double freq) const { return note2px(scale.getNote(freq)); }
|