diff --git a/spectrogramplot.cpp b/spectrogramplot.cpp index 8ec4396..5f50c20 100644 --- a/spectrogramplot.cpp +++ b/spectrogramplot.cpp @@ -31,7 +31,7 @@ #include "util.h" -SpectrogramPlot::SpectrogramPlot(std::shared_ptr>> src) : Plot(src), inputSource(src), fftSize(512), tuner(this) +SpectrogramPlot::SpectrogramPlot(std::shared_ptr>> src) : Plot(src), inputSource(src), fftSize(512), tuner(fftSize, this) { setFFTSize(fftSize); zoomLevel = 1; @@ -284,8 +284,11 @@ void SpectrogramPlot::setFFTSize(int size) } setHeight(fftSize); - tuner.setDeviation( tuner.deviation() * sizeScale ); - tuner.setCentre( tuner.centre() * sizeScale ); + auto dev = tuner.deviation(); + auto centre = tuner.centre(); + tuner.setHeight(fftSize); + tuner.setDeviation( dev * sizeScale ); + tuner.setCentre( centre * sizeScale ); } void SpectrogramPlot::setPowerMax(int power) diff --git a/tuner.cpp b/tuner.cpp index 90880e2..e278d2c 100644 --- a/tuner.cpp +++ b/tuner.cpp @@ -20,7 +20,7 @@ #include #include "tuner.h" -Tuner::Tuner(QObject * parent) : QObject::QObject(parent) +Tuner::Tuner(int height, QObject * parent) : height(height), QObject::QObject(parent) { minCursor = new Cursor(Qt::Horizontal, Qt::SizeVerCursor, this); cfCursor = new Cursor(Qt::Horizontal, Qt::SizeAllCursor, this); @@ -102,6 +102,11 @@ void Tuner::setDeviation(int dev) updateCursors(); } +void Tuner::setHeight(int height) +{ + this->height = height; +} + void Tuner::updateCursors() { minCursor->setPos(cfCursor->pos() - _deviation); diff --git a/tuner.h b/tuner.h index 5ed9254..0a5286b 100644 --- a/tuner.h +++ b/tuner.h @@ -31,25 +31,27 @@ class Tuner : public QObject Q_OBJECT public: - Tuner(QObject * parent); + Tuner(int height, QObject * parent); int centre(); int deviation(); bool mouseEvent(QEvent::Type, QMouseEvent event); void paintFront(QPainter &painter, QRect &rect, range_t sampleRange); void setCentre(int centre); void setDeviation(int dev); + void setHeight(int height); public slots: - void cursorMoved(); + void cursorMoved(); signals: - void tunerMoved(); + void tunerMoved(); private: - void updateCursors(); + void updateCursors(); - Cursor *minCursor; - Cursor *cfCursor; - Cursor *maxCursor; - int _deviation; + Cursor *minCursor; + Cursor *cfCursor; + Cursor *maxCursor; + int _deviation; + int height; };