diff --git a/main.cpp b/main.cpp index b6a0e60..06bcad2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ #include +#include #include "mainwindow.h" @@ -6,6 +7,17 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); + qSetMessagePattern(QStringLiteral("%{time dd.MM.yyyy HH:mm:ss.zzz} " + "[" + "%{if-debug}D%{endif}" + "%{if-info}I%{endif}" + "%{if-warning}W%{endif}" + "%{if-critical}C%{endif}" + "%{if-fatal}F%{endif}" + "] " + "%{function}(): " + "%{message}")); + MainWindow mainWindow; mainWindow.show(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 7c2b7bc..60c299a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -30,6 +30,9 @@ MainWindow::MainWindow(QWidget *parent) } } + if (m_ui.comboBoxDevices->count()) + m_ui.comboBoxDevices->setCurrentIndex(m_audioDevices.count()-1); + for (const auto samplerate : { 44100, 48000, 96000, 192000 }) m_ui.comboBoxSamplerate->addItem(tr("%0").arg(samplerate), samplerate); @@ -48,6 +51,10 @@ MainWindow::MainWindow(QWidget *parent) connect(m_ui.spinBoxBlend, qOverload(&QSpinBox::valueChanged), m_ui.widget, &OsciWidget::setBlend); + m_ui.spinBoxGlow->setValue(m_ui.widget->glow()); + + connect(m_ui.spinBoxGlow, qOverload(&QSpinBox::valueChanged), m_ui.widget, &OsciWidget::setGlow); + auto buttonGroup = new QButtonGroup; buttonGroup->setExclusive(true); for (auto factor : { .5f, 1.f, 2.f, 4.f, 8.f }) diff --git a/mainwindow.ui b/mainwindow.ui index 6f5c674..cc07513 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -75,6 +75,16 @@ + + + + glow + + + 65535 + + + diff --git a/osciwidget.cpp b/osciwidget.cpp index 97a82d0..23652d1 100644 --- a/osciwidget.cpp +++ b/osciwidget.cpp @@ -26,12 +26,17 @@ float OsciWidget::factor() const return m_factor; } +float OsciWidget::glow() const +{ + return m_glow; +} + void OsciWidget::setFramerate(int framerate) { if (framerate == m_framerate) return; - qDebug() << "change framerate to" << framerate; + qDebug() << framerate; m_framerate = framerate; @@ -43,16 +48,23 @@ void OsciWidget::setBlend(int blend) if (blend == m_blend) return; - qDebug() << "change blend to" << blend; + qDebug() << blend; m_blend = blend; } void OsciWidget::setFactor(float factor) { + qDebug() << factor; m_factor = factor; } +void OsciWidget::setGlow(float glow) +{ + qDebug() << glow; + m_glow = glow; +} + void OsciWidget::renderSamples(const SamplePair *begin, const SamplePair *end) { QPainter painter; @@ -69,19 +81,30 @@ void OsciWidget::renderSamples(const SamplePair *begin, const SamplePair *end) for (auto i = begin; i < end; i++) { - const qreal x = (qreal(i->x) / std::numeric_limits::max() / 2 * width() / 2 * m_factor); - const qreal y = (qreal(i->y) / std::numeric_limits::max() / 2 * height() / 2 * m_factor); - const QPointF p{x, y}; + const QPointF p{ + float(i->x) / std::numeric_limits::max() / 2, + float(-i->y) / std::numeric_limits::max() / 2 + }; if (Q_LIKELY(m_lastPoint.has_value())) { - auto speed = QLineF(*m_lastPoint, p).length(); - if (speed < 1) - speed = 1; - auto brightness = 1./speed; + const QLineF line(*m_lastPoint, p); + + auto brightness = 1.f / line.length() / m_glow; + if (line.length() == 0.f || brightness > 255.f) + brightness = 255.f; painter.setOpacity(brightness); - painter.drawLine(*m_lastPoint, p); + + const auto pointToCoordinates = [this](const QPointF &point) + { + return QPoint{ + int((point.x() * width() / 2 * m_factor)), + int((point.y() * height() / 2 * m_factor)) + }; + }; + + painter.drawLine(pointToCoordinates(*m_lastPoint), pointToCoordinates(p)); } m_lastPoint = p; diff --git a/osciwidget.h b/osciwidget.h index 77a75a8..c064e07 100644 --- a/osciwidget.h +++ b/osciwidget.h @@ -24,6 +24,8 @@ public: int framerate() const; int blend() const; float factor() const; + float glow() const; + void start(); void stop(); @@ -31,6 +33,7 @@ public slots: void setFramerate(int framerate); void setBlend(int blend); void setFactor(float factor); + void setGlow(float glow); void renderSamples(const SamplePair *begin, const SamplePair *end); @@ -46,8 +49,9 @@ private: int m_timerId{-1}; int m_framerate{15}; - int m_blend{190}; + int m_blend{150}; float m_factor{4.f}; + float m_glow{512.f}; QPixmap m_pixmap;