|
From: Tapio V. <aa...@us...> - 2011-01-20 13:20:18
|
Module: editor
Branch: master
Commit: 5f9bc04f78f9676d5f87fad8d005a7e3433c60c2
Author: Tapio Vierros <tap...@gm...>
Date: Thu Jan 20 15:19:02 2011 +0200
Super neat statusbar progressbar for analyzation progress indication.
---
editorapp.cc | 17 +++++++++++++++++
editorapp.hh | 3 +++
notegraphwidget.cc | 12 +++++++++---
notegraphwidget.hh | 1 +
pitchvis.cc | 3 ++-
pitchvis.hh | 2 ++
6 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index ad98c79..dc4f6f8 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -62,6 +62,10 @@ EditorApp::EditorApp(QWidget *parent): QMainWindow(parent), projectFileName(), h
ui.cmdPlay->setIcon(QIcon::fromTheme("media-playback-start"));
ui.cmdStop->setIcon(QIcon::fromTheme("media-playback-stop"));
+ statusbarProgress = new QProgressBar(NULL);
+ ui.statusbar->addPermanentWidget(statusbarProgress);
+ connect(noteGraph, SIGNAL(analyzeProgress(int, int)), this, SLOT(analyzeProgress(int, int)));
+
hasUnsavedChanges = false;
updateMenuStates();
@@ -146,6 +150,19 @@ void EditorApp::updateNoteInfo(NoteLabel *note)
}
}
+void EditorApp::analyzeProgress(int value, int maximum)
+{
+ if (statusbarProgress) {
+ if (value == maximum) {
+ statusbarProgress->hide();
+ } else {
+ statusbarProgress->setMaximum(maximum);
+ statusbarProgress->setValue(value);
+ statusbarProgress->show();
+ }
+ }
+}
+
void EditorApp::on_actionNew_triggered()
{
if (promptSaving()) {
diff --git a/editorapp.hh b/editorapp.hh
index 16540f8..df07a97 100644
--- a/editorapp.hh
+++ b/editorapp.hh
@@ -5,6 +5,7 @@
#include "operation.hh"
#include "song.hh"
+class QProgressBar;
class NoteLabel;
class NoteGraphWidget;
namespace Phonon {
@@ -30,6 +31,7 @@ private:
public slots:
void operationDone(const Operation &op);
void updateNoteInfo(NoteLabel *note);
+ void analyzeProgress(int value, int maximum);
void metaDataChanged();
void audioTick(qint64 time);
void playerStateChanged(Phonon::State newstate, Phonon::State olstate);
@@ -78,6 +80,7 @@ private:
QScopedPointer<Song> song;
Phonon::MediaObject *player;
Phonon::AudioOutput *audioOutput;
+ QProgressBar *statusbarProgress;
QString projectFileName;
bool hasUnsavedChanges;
};
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 3bf8c54..3314729 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -115,13 +115,19 @@ void NoteGraphWidget::finalizeNewLyrics()
void NoteGraphWidget::analyzeMusic(QString filepath)
{
m_pitch.reset(new PitchVis(filepath, this));
- m_analyzeTimer = startTimer(2000);
+ m_analyzeTimer = startTimer(1000);
}
void NoteGraphWidget::timerEvent(QTimerEvent *event)
{
- if (!m_pitch.isNull() && m_pitch->newDataAvailable()) {
- setPixmap(QPixmap::fromImage(m_pitch->getImage()));
+ (void)event;
+ if (!m_pitch.isNull()) {
+ if (m_pitch->newDataAvailable())
+ setPixmap(QPixmap::fromImage(m_pitch->getImage()));
+ if (m_pitch->isFinished()) {
+ killTimer(m_analyzeTimer);
+ emit analyzeProgress(width(), width());
+ } else emit analyzeProgress(m_pitch->getXValue(), width());
}
}
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index 7143b02..d8f861d 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -55,6 +55,7 @@ public:
signals:
void updateNoteInfo(NoteLabel*);
+ void analyzeProgress(int, int);
void operationDone(const Operation&);
void seek(qint64 time);
diff --git a/pitchvis.cc b/pitchvis.cc
index 61cfc97..55f3cb0 100644
--- a/pitchvis.cc
+++ b/pitchvis.cc
@@ -23,7 +23,7 @@ template <typename T> void readVec(std::string const& filename, std::vector<T>&
}
PitchVis::PitchVis(QString const& filename, QWidget *parent)
- : QWidget(parent), QThread(), mutex(), step(512), height(768), fileName(filename), moreAvailable()
+ : QWidget(parent), QThread(), mutex(), step(512), height(768), fileName(filename), moreAvailable(), curX()
{
start(); // Launch the thread
}
@@ -52,6 +52,7 @@ void PitchVis::run()
for (unsigned x = 0; x < width; ++x) {
if (cancelled) return;
+ curX = x;
// Get decoded samples from ffmpeg
std::vector<float> data(step*2);
diff --git a/pitchvis.hh b/pitchvis.hh
index 21ae0ca..0af29c6 100644
--- a/pitchvis.hh
+++ b/pitchvis.hh
@@ -41,6 +41,7 @@ class PitchVis: public QWidget, public QThread {
QImage image;
bool moreAvailable;
bool cancelled;
+ int curX;
QMutex mutex;
public:
const std::size_t height;
@@ -53,6 +54,7 @@ public:
QImage getImage() { QMutexLocker locker(&mutex); moreAvailable = false; return image; }
bool newDataAvailable() const { return moreAvailable; }
+ int getXValue() const { return curX; }
Pixel& pixel(std::size_t x, std::size_t y) { return img[x * height + y]; }
std::size_t width() const { return img.size() / height; }
|