|
From: Lasse Kärkkäi. <tr...@us...> - 2011-01-10 20:52:13
|
Module: editor
Branch: master
Commit: 587bde90590dbfdf76333740e63b99e8ec8756f8
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Jan 10 21:51:58 2011 +0100
Pitch data rendering
---
notegraphwidget.cc | 14 ++++++++++++--
notegraphwidget.hh | 4 ++--
pitchvis.cc | 2 +-
pitchvis.hh | 2 +-
4 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 9c9f66d..53178c1 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -9,8 +9,18 @@
const int NoteGraphWidget::noteYStep = 40;
NoteGraphWidget::NoteGraphWidget(QWidget *parent)
- : QWidget(parent), m_panHotSpot(), m_selectedNote(), m_selectedAction(NONE), m_pitch("music.raw")
+ : QLabel(parent), m_panHotSpot(), m_selectedNote(), m_selectedAction(NONE), m_pitch("music.raw")
{
+ unsigned width = m_pitch.width(), height = m_pitch.height;
+ QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
+ unsigned* rgba = reinterpret_cast<unsigned*>(image.bits());
+ for (unsigned x = 0; x < width; ++x) {
+ for (unsigned y = 0; y < height; ++y) {
+ rgba[y * width + x] = m_pitch(x, y).rgba();
+ }
+ }
+ setPixmap(QPixmap::fromImage(image));
+
setFocusPolicy(Qt::StrongFocus);
setWhatsThis(tr("Note graph that displays the song notes and allows you to manipulate them."));
setLyrics(tr("Please add music file and lyrics text."));
@@ -55,9 +65,9 @@ void NoteGraphWidget::setLyrics(QString lyrics)
ts >> word;
if (!word.isEmpty()) {
NoteLabel *wordLabel = new NoteLabel(word, this, QPoint(x, y));
+ last = wordLabel;
x += wordLabel->width() + gap;
if (!first) first = wordLabel;
- last = wordLabel;
}
}
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index d15d84f..4da3ac7 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -1,13 +1,13 @@
#pragma once
#include "pitchvis.hh"
-#include <QWidget>
+#include <QLabel>
#include <list>
class NoteLabel;
typedef std::list<NoteLabel*> NoteLabels;
-class NoteGraphWidget: public QWidget
+class NoteGraphWidget: public QLabel
{
Q_OBJECT
diff --git a/pitchvis.cc b/pitchvis.cc
index f1e746f..9cc39f5 100644
--- a/pitchvis.cc
+++ b/pitchvis.cc
@@ -24,7 +24,7 @@ PitchVis::PitchVis(std::string const& filename): height(512) {
std::vector<float> data;
try { readVec(filename, data); } catch(std::exception& e) { std::cerr << e.what() << std::endl; return; }
unsigned step = 1024;
- unsigned width = data.size() / step / height;
+ unsigned width = data.size() / step;
img.resize(width * height);
Analyzer analyzer(44100, "");
MusicalScale scale;
diff --git a/pitchvis.hh b/pitchvis.hh
index 05a5c58..1d86873 100644
--- a/pitchvis.hh
+++ b/pitchvis.hh
@@ -20,9 +20,9 @@ struct Pixel {
};
class PitchVis {
- std::size_t height;
std::vector<Pixel> img;
public:
+ const std::size_t height;
Pixel& operator()(std::size_t x, std::size_t y) { return img[x * height + y]; }
std::size_t width() const { return img.size() / height; }
PitchVis(std::string const& filename);
|