From c46480ed6a1679d96e761bf2142d49141c4beae1 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Sat, 7 Sep 2019 20:01:43 +0200 Subject: [PATCH] Added debug controls for afterglow and lightspeed again --- mainwindow.cpp | 40 +++++++++++++++++++++++++++++++--------- mainwindow.ui | 32 +++++++++++++++++++------------- osciwidget.cpp | 15 +++++++++++++-- osciwidget.h | 18 +++++++++++------- 4 files changed, 74 insertions(+), 31 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index e6d0d3c..d595c9f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,11 +2,10 @@ #include "ui_mainwindow.h" // Qt includes -#include -#include -#include -#include #include +#include +#include +#include #include // local includes @@ -43,13 +42,13 @@ MainWindow::MainWindow(QWidget *parent) : // setting up menu File connect(m_ui->actionStart, &QAction::triggered, this, &MainWindow::start); connect(m_ui->actionStop, &QAction::triggered, this, &MainWindow::stop); - m_ui->action_Quit->setShortcut(QKeySequence::Quit); + m_ui->actionQuit->setShortcut(QKeySequence::Quit); // setting up menu Devices for (const auto &device : m_audioDevices) { auto name = device.deviceName(); - const auto action = m_ui->menu_Device->addAction(name); + const auto action = m_ui->menuDevice->addAction(name); action->setCheckable(true); m_deviceGroup.addAction(action); @@ -61,7 +60,7 @@ MainWindow::MainWindow(QWidget *parent) : // setting up menu Samplerates for (const auto samplerate : samplerates) { - auto action = m_ui->menu_Samplerate->addAction(tr("%0").arg(samplerate)); + auto action = m_ui->menuSamplerate->addAction(tr("%0").arg(samplerate)); action->setCheckable(true); m_samplerateGroup.addAction(action); } @@ -71,7 +70,7 @@ MainWindow::MainWindow(QWidget *parent) : // setting up menu Refreshrates for (const auto refreshrate : refreshrates) { - auto action = m_ui->menu_Refreshrate->addAction(tr("%0FPS").arg(refreshrate)); + auto action = m_ui->menuRefreshrate->addAction(tr("%0FPS").arg(refreshrate)); action->setCheckable(true); m_refreshrateGroup.addAction(action); } @@ -87,7 +86,7 @@ MainWindow::MainWindow(QWidget *parent) : // setting up menu Zoom for (const auto zoomlevel : zoomlevels) { - auto action = m_ui->menu_Zoom->addAction(tr("%0%").arg(zoomlevel)); + auto action = m_ui->menuZoom->addAction(tr("%0%").arg(zoomlevel)); action->setCheckable(true); m_zoomlevelsGroup.addAction(action); } @@ -100,6 +99,29 @@ MainWindow::MainWindow(QWidget *parent) : connect(&m_zoomlevelsGroup, &QActionGroup::triggered, this, &MainWindow::zoomChanged); + //setting up menu Debug + { + auto widgetAction = new QWidgetAction(this); + auto widget = new QWidget; + auto layout = new QFormLayout(widget); + { + auto input = new QSpinBox; + input->setRange(0, 255); + input->setValue(m_ui->widget->afterglow()); + connect(input, qOverload(&QSpinBox::valueChanged), m_ui->widget, &OsciWidget::setAfterglow); + layout->addRow(tr("Afterglow:"), input); + } + { + auto input = new QSpinBox; + input->setRange(0, 255); + input->setValue(m_ui->widget->lightspeed()); + connect(input, qOverload(&QSpinBox::valueChanged), m_ui->widget, &OsciWidget::setLightspeed); + layout->addRow(tr("Lightspeed:"), input); + } + widgetAction->setDefaultWidget(widget); + m_ui->menuDebug->addAction(widgetAction); + } + // autostart if (m_audioDevices.isEmpty()) { diff --git a/mainwindow.ui b/mainwindow.ui index f083690..b6343a5 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -23,43 +23,49 @@ 20 - + &File - + - + &Device - + &Samplerate - + &Refreshrate - + &Zoom - - - - - + + + Debug + + + + + + + + - + &Quit @@ -86,7 +92,7 @@ - action_Quit + actionQuit triggered() MainWindow close() diff --git a/osciwidget.cpp b/osciwidget.cpp index 8d18efc..4a7f1ce 100644 --- a/osciwidget.cpp +++ b/osciwidget.cpp @@ -14,6 +14,11 @@ OsciWidget::OsciWidget(QWidget *parent) : m_statsTimer.start(); } +int OsciWidget::lightspeed() const +{ + return std::cbrt(m_lightspeed) * 20.f; +} + void OsciWidget::setFps(int fps) { killTimer(m_redrawTimerId); @@ -23,6 +28,12 @@ void OsciWidget::setFps(int fps) m_redrawTimerId = startTimer(1000/m_fps); } +void OsciWidget::setLightspeed(int lightspeed) { + const auto temp = (float(lightspeed)/20.f); + m_lightspeed = temp*temp*temp; + qDebug() << m_lightspeed; +} + void OsciWidget::renderSamples(const SamplePair *begin, const SamplePair *end) { m_callbacksCounter++; @@ -52,7 +63,7 @@ void OsciWidget::paintEvent(QPaintEvent *event) // darkening last frame painter.setCompositionMode(QPainter::CompositionMode_Multiply); painter.setPen({}); - painter.setBrush(QColor(150,150,150 )); + painter.setBrush(QColor(m_afterglow, m_afterglow, m_afterglow)); painter.drawRect(m_pixmap.rect()); // drawing new lines ontop @@ -80,7 +91,7 @@ void OsciWidget::paintEvent(QPaintEvent *event) const QLineF line(m_lastPoint, p); - painter.setOpacity(std::min(1.0, 1. / ((line.length() * 75) + 1))); + painter.setOpacity(std::min(1.0, 1. / ((line.length() * m_lightspeed) + 1))); painter.drawLine(pointToCoordinates(m_lastPoint), pointToCoordinates(p)); diff --git a/osciwidget.h b/osciwidget.h index 26bd932..c8ec2f7 100644 --- a/osciwidget.h +++ b/osciwidget.h @@ -21,6 +21,8 @@ public: float factor() const { return m_factor; } int fps() const { return m_fps; } + int afterglow() const { return m_afterglow; } + int lightspeed() const; signals: void statusUpdate(const QString &status); @@ -28,6 +30,8 @@ signals: public slots: void setFactor(float factor) { m_factor = factor; } void setFps(int fps); + void setAfterglow(int afterglow) { m_afterglow = afterglow; } + void setLightspeed(int lightspeed); void renderSamples(const SamplePair *begin, const SamplePair *end); @@ -36,17 +40,17 @@ protected: void timerEvent(QTimerEvent *event) override; private: - float m_factor{2.f}; - + int m_redrawTimerId; QPointF m_lastPoint; + float m_factor{2.f}; + int m_fps{15}, m_afterglow{175}; + float m_lightspeed{35.f}; + + std::vector m_buffer; + int m_frameCounter{0}, m_callbacksCounter{0}; QElapsedTimer m_statsTimer; - int m_fps{15}; - int m_redrawTimerId; - - std::vector m_buffer; - QPixmap m_pixmap; };