Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/abstractsamplesource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
void AbstractSampleSource::subscribe(Subscriber *subscriber)
{
subscribers.insert(subscriber);
emit subscribersChanged();
}

void AbstractSampleSource::invalidate()
Expand All @@ -39,4 +40,5 @@ int AbstractSampleSource::subscriberCount()
void AbstractSampleSource::unsubscribe(Subscriber *subscriber)
{
subscribers.erase(subscriber);
}
emit subscribersChanged();
}
7 changes: 6 additions & 1 deletion src/abstractsamplesource.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
#include <memory>
#include <set>
#include <typeindex>
#include <QObject>
#include "subscriber.h"

class AbstractSampleSource
class AbstractSampleSource : public QObject
{
Q_OBJECT

public:
virtual ~AbstractSampleSource() {};
Expand All @@ -35,6 +37,9 @@ class AbstractSampleSource
int subscriberCount();
void unsubscribe(Subscriber *subscriber);

signals:
void subscribersChanged();

protected:
virtual void invalidate();

Expand Down
3 changes: 3 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ MainWindow::MainWindow()
connect(dock->annosCheckBox, &QCheckBox::stateChanged, dock, &SpectrogramControls::enableAnnotations);
connect(dock->commentsCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableAnnotationCommentsTooltips);
connect(dock->cursorSymbolsSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), plots, &PlotView::setCursorSegments);
connect(dock, static_cast<void (SpectrogramControls::*)(double)>(&SpectrogramControls::tunerCenterSet), plots, &PlotView::setTunerCenter);
connect(dock, static_cast<void (SpectrogramControls::*)(double)>(&SpectrogramControls::tunerDeviationSet), plots, &PlotView::setTunerDeviation);

// Connect dock outputs
connect(plots, &PlotView::timeSelectionChanged, dock, &SpectrogramControls::timeSelectionChanged);
connect(plots, &PlotView::plotTunerChanged, dock, &SpectrogramControls::tunerChanged);
connect(plots, &PlotView::zoomIn, dock, &SpectrogramControls::zoomIn);
connect(plots, &PlotView::zoomOut, dock, &SpectrogramControls::zoomOut);

Expand Down
16 changes: 16 additions & 0 deletions src/plotview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0})

spectrogramPlot = new SpectrogramPlot(std::shared_ptr<SampleSource<std::complex<float>>>(mainSampleSource));
auto tunerOutput = std::dynamic_pointer_cast<SampleSource<std::complex<float>>>(spectrogramPlot->output());
connect(spectrogramPlot, &SpectrogramPlot::tunerChanged, this, &PlotView::tunerChanged);

enableScales(true);

Expand Down Expand Up @@ -200,6 +201,11 @@ void PlotView::cursorsMoved()
viewport()->update();
}

void PlotView::tunerChanged(double center, double deviation, bool enabled)
{
emit plotTunerChanged(center, deviation, enabled);
}

void PlotView::emitTimeSelection()
{
size_t sampleCount = selectedSamples.length();
Expand Down Expand Up @@ -429,6 +435,16 @@ void PlotView::setCursorSegments(int segments)
emitTimeSelection();
}

void PlotView::setTunerCenter(double center) {
if (spectrogramPlot != nullptr)
spectrogramPlot->setTunerCenter(center);
}

void PlotView::setTunerDeviation(double deviation) {
if (spectrogramPlot != nullptr)
spectrogramPlot->setTunerDeviation(deviation);
}

void PlotView::setFFTAndZoom(int size, int zoom)
{
auto oldSamplesPerColumn = samplesPerColumn();
Expand Down
4 changes: 4 additions & 0 deletions src/plotview.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ class PlotView : public QGraphicsView, Subscriber

signals:
void timeSelectionChanged(float time);
void plotTunerChanged(double center, double deviation, bool enabled);
void zoomIn();
void zoomOut();

public slots:
void cursorsMoved();
void tunerChanged(double center, double deviation, bool enabled);
void enableCursors(bool enabled);
void enableScales(bool enabled);
void enableAnnotations(bool enabled);
void enableAnnotationCommentsTooltips(bool enabled);
void invalidateEvent() override;
void repaint();
void setCursorSegments(int segments);
void setTunerCenter(double center);
void setTunerDeviation(double deviation);
void setFFTAndZoom(int fftSize, int zoomLevel);
void setPowerMin(int power);
void setPowerMax(int power);
Expand Down
40 changes: 40 additions & 0 deletions src/spectrogramcontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent
scalesCheckBox->setCheckState(Qt::Checked);
layout->addRow(new QLabel(tr("Scales:")), scalesCheckBox);

tunerCenter = new QLineEdit();
double_validator = new QDoubleValidator(this);
double_validator->setBottom(0.0);
tunerCenter->setValidator(double_validator);
layout->addRow(new QLabel(tr("Tuner center:")), tunerCenter);

tunerDeviation = new QLineEdit();
double_validator = new QDoubleValidator(this);
double_validator->setBottom(0.0);
tunerDeviation->setValidator(double_validator);
layout->addRow(new QLabel(tr("Tuner deviation:")), tunerDeviation);

// Time selection settings
layout->addRow(new QLabel()); // TODO: find a better way to add an empty row?
layout->addRow(new QLabel(tr("<b>Time selection</b>")));
Expand Down Expand Up @@ -111,6 +123,8 @@ SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent
connect(cursorsCheckBox, &QCheckBox::stateChanged, this, &SpectrogramControls::cursorsStateChanged);
connect(powerMinSlider, &QSlider::valueChanged, this, &SpectrogramControls::powerMinChanged);
connect(powerMaxSlider, &QSlider::valueChanged, this, &SpectrogramControls::powerMaxChanged);
connect(tunerCenter, &QLineEdit::returnPressed, this, static_cast<void (SpectrogramControls::*)()>(&SpectrogramControls::tunerCenterSet));
connect(tunerDeviation, &QLineEdit::returnPressed, this, static_cast<void (SpectrogramControls::*)()>(&SpectrogramControls::tunerDeviationSet));
}

void SpectrogramControls::clearCursorLabels()
Expand Down Expand Up @@ -181,6 +195,18 @@ void SpectrogramControls::powerMaxChanged(int value)
settings.setValue("PowerMax", value);
}

void SpectrogramControls::tunerCenterSet()
{
auto center = tunerCenter->text().toDouble();
emit tunerCenterSet(center);
}

void SpectrogramControls::tunerDeviationSet()
{
auto deviation = tunerDeviation->text().toDouble();
emit tunerDeviationSet(deviation);
}

void SpectrogramControls::fileOpenButtonClicked()
{
QSettings settings;
Expand Down Expand Up @@ -229,6 +255,20 @@ void SpectrogramControls::timeSelectionChanged(float time)
}
}

void SpectrogramControls::tunerChanged(double center, double deviation, bool enabled)
{
if (enabled) {
tunerCenter->setText(QString::number((int)center));
tunerDeviation->setText(QString::number((int)deviation));
} else {
tunerCenter->setText("");
tunerDeviation->setText("");
}

tunerCenter->setEnabled(enabled);
tunerDeviation->setEnabled(enabled);
}

void SpectrogramControls::zoomIn()
{
zoomLevelSlider->setValue(zoomLevelSlider->value() + 1);
Expand Down
7 changes: 7 additions & 0 deletions src/spectrogramcontrols.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ class SpectrogramControls : public QDockWidget
signals:
void fftOrZoomChanged(int fftSize, int zoomLevel);
void openFile(QString fileName);
void tunerCenterSet(double center);
void tunerDeviationSet(double deviation);

public slots:
void timeSelectionChanged(float time);
void tunerChanged(double center, double deviation, bool enabled);
void zoomIn();
void zoomOut();
void enableAnnotations(bool enabled);
Expand All @@ -53,6 +56,8 @@ private slots:
void powerMaxChanged(int value);
void fileOpenButtonClicked();
void cursorsStateChanged(int state);
void tunerCenterSet();
void tunerDeviationSet();

private:
QWidget *widget;
Expand All @@ -63,6 +68,8 @@ private slots:
public:
QPushButton *fileOpenButton;
QLineEdit *sampleRate;
QLineEdit *tunerCenter;
QLineEdit *tunerDeviation;
QSlider *fftSizeSlider;
QSlider *zoomLevelSlider;
QSlider *powerMaxSlider;
Expand Down
35 changes: 35 additions & 0 deletions src/spectrogramplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SpectrogramPlot::SpectrogramPlot(std::shared_ptr<SampleSource<std::complex<float

tunerTransform = std::make_shared<TunerTransform>(src);
connect(&tuner, &Tuner::tunerMoved, this, &SpectrogramPlot::tunerMoved);
connect(tunerTransform.get(), &TunerTransform::subscribersChanged, this, &SpectrogramPlot::tunerMoved);
}

void SpectrogramPlot::invalidateEvent()
Expand Down Expand Up @@ -379,6 +380,30 @@ void SpectrogramPlot::setFFTSize(int size)
tuner.setCentre( centre * sizeScale );
}

void SpectrogramPlot::setTunerCenter(double abs_center)
{
double k;
if (inputSource->realSignal())
k = sampleRate / 2;
else
k = sampleRate;

int center = tuner.height() * (1 - abs_center / k);
tuner.setCentre(center);
}

void SpectrogramPlot::setTunerDeviation(double abs_deviation)
{
double k;
if (inputSource->realSignal())
k = sampleRate / 2;
else
k = sampleRate;

int deviation = tuner.height() * abs_deviation / k;
tuner.setDeviation(deviation);
}

void SpectrogramPlot::setPowerMax(int power)
{
powerMax = power;
Expand Down Expand Up @@ -432,6 +457,16 @@ void SpectrogramPlot::tunerMoved()
QPixmapCache::clear();

emit repaint();

double k;
if (inputSource->realSignal())
k = sampleRate / 2;
else
k = sampleRate;

double abs_center = k * (1 - (double)tuner.centre() / tuner.height());
double abs_deviation = k * (double)tuner.deviation() / tuner.height();
emit tunerChanged(abs_center, abs_deviation, tunerEnabled());
}

uint qHash(const TileCacheKey &key, uint seed)
Expand Down
5 changes: 5 additions & 0 deletions src/spectrogramplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ class SpectrogramPlot : public Plot
bool isAnnotationsEnabled();
QString *mouseAnnotationComment(const QMouseEvent *event);

signals:
void tunerChanged(double center, double deviation, bool enabled);

public slots:
void setFFTSize(int size);
void setTunerCenter(double center);
void setTunerDeviation(double deviation);
void setPowerMax(int power);
void setPowerMin(int power);
void setZoomLevel(int zoom);
Expand Down
14 changes: 9 additions & 5 deletions src/tuner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <cstdlib>
#include "tuner.h"

Tuner::Tuner(int height, QObject * parent) : height(height), 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);
Expand All @@ -44,14 +44,14 @@ void Tuner::cursorMoved()
Cursor *sender = static_cast<Cursor*>(QObject::sender());
if (sender != cfCursor) {
// Limit cursor positions to within plot
auto posRange = range_t<int>{0, height};
auto posRange = range_t<int>{0, _height};
sender->setPos(posRange.clip(sender->pos()));

// Limit deviation range to half of total BW (either side of centre)
auto deviationRange = range_t<int>{2, height / 2};
auto deviationRange = range_t<int>{2, _height / 2};
_deviation = deviationRange.clip(std::abs(sender->pos() - cfCursor->pos()));
} else {
auto cfRange = range_t<int>{_deviation, height - _deviation};
auto cfRange = range_t<int>{_deviation, _height - _deviation};
sender->setPos(cfRange.clip(sender->pos()));
}

Expand Down Expand Up @@ -113,7 +113,11 @@ void Tuner::setDeviation(int dev)

void Tuner::setHeight(int height)
{
this->height = height;
_height = height;
}

int Tuner::height() {
return _height;
}

void Tuner::updateCursors()
Expand Down
3 changes: 2 additions & 1 deletion src/tuner.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Tuner : public QObject
Tuner(int height, QObject * parent);
int centre();
int deviation();
int height();
bool mouseEvent(QEvent::Type, QMouseEvent event);
void paintFront(QPainter &painter, QRect &rect, range_t<size_t> sampleRange);
void setCentre(int centre);
Expand All @@ -53,5 +54,5 @@ public slots:
Cursor *cfCursor;
Cursor *maxCursor;
int _deviation;
int height;
int _height;
};