|
From: Tapio V. <aa...@us...> - 2011-01-10 21:46:35
|
Module: editor
Branch: master
Commit: 250ccb8e0130896eaa3d3c4892dc01fe0a5fa0d4
Author: Tapio Vierros <tap...@gm...>
Date: Mon Jan 10 23:45:58 2011 +0200
Add a progress dialog for pitch analyzation/rendering.
---
pitchvis.cc | 8 ++++++++
pitchvis.hh | 3 ++-
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/pitchvis.cc b/pitchvis.cc
index 9cc39f5..73dcef0 100644
--- a/pitchvis.cc
+++ b/pitchvis.cc
@@ -5,6 +5,7 @@
#include <fstream>
#include <iostream>
#include <stdexcept>
+#include <QProgressDialog>
/** Read the entire file into a vector of some type.
The file needs to be in the machine-native endianess. **/
@@ -28,7 +29,13 @@ PitchVis::PitchVis(std::string const& filename): height(512) {
img.resize(width * height);
Analyzer analyzer(44100, "");
MusicalScale scale;
+ QProgressDialog progress("Analyzing and rendering pitch...", "Abort", 0, width, this);
+ progress.setWindowModality(Qt::WindowModal);
+
for (unsigned x = 0; x < width; ++x) {
+ progress.setValue(x);
+ if (progress.wasCanceled()) return;
+
analyzer.input(data.begin() + x * step, data.begin() + (x + 1) * step);
analyzer.process();
Analyzer::Peaks peaks = analyzer.getPeaks();
@@ -39,5 +46,6 @@ PitchVis::PitchVis(std::string const& filename): height(512) {
if (value > 0.0) (*this)(x, y).r += 0.01 * value;
}
}
+ progress.setValue(width);
}
diff --git a/pitchvis.hh b/pitchvis.hh
index 1d86873..639deec 100644
--- a/pitchvis.hh
+++ b/pitchvis.hh
@@ -1,5 +1,6 @@
#pragma once
+#include <QWidget>
#include <string>
#include <vector>
@@ -19,7 +20,7 @@ struct Pixel {
float& operator[](unsigned idx) { return (&r)[idx]; }
};
-class PitchVis {
+class PitchVis: public QWidget {
std::vector<Pixel> img;
public:
const std::size_t height;
|