soundboard/src/soundview.cpp

57 lines
1.1 KiB
C++

#include "soundview.h"
#include "sound.h"
#include <Log.h>
#include <QResizeEvent>
SoundView::SoundView(QWidget* parent) : QGraphicsView(parent) {
setScene(&scene);
redraw();
}
SoundView::~SoundView() {
delete samples;
}
void SoundView::loadFile(const std::string& file) {
samples = Sound::instance().openFile(file);
}
void SoundView::redraw() {
//Log::debug << "redraw SoundView";
scene.clear();
scene.setBackgroundBrush(QBrush(Qt::GlobalColor::black));
scene.addRect(0, 0, width()-4, height()-4, QPen(Qt::green));
uint32_t h = scene.height()-4;
//Log::info << "scene Size: " << scene.width() << " " << scene.height() << " " << width() << " " << height();
scene.addLine(0, h/2, scene.width()-4, h/2, QPen(Qt::red));
/*
for(uint32_t x = 0; x < width(); ++x) {
float s = samples->readSample(x);
scene.addLine(x, h/2, x, s*h, QPen(Qt::white));
//Log::info << "Line: " << x << " " << h/2;
}
*/
}
void SoundView::paintEvent(QPaintEvent* event) {
QGraphicsView::paintEvent(event);
redraw();
}
void SoundView::resizeEvent(QResizeEvent* event) {
QGraphicsView::resizeEvent(event);
if(samples) {
samples->setWidth(event->size().width());
}
}