~mrp/aerodramus

c4cc605032929617ada72e2326bae640b2038e3a — Mark Penner 2 months ago 2b51f7e main
add rudimentary audio plotting functionality
6 files changed, 52 insertions(+), 23 deletions(-)

M CMakeLists.txt
M src/CMakeLists.txt
D src/ImpulseResponsePage.cpp
M src/MainWindow.cpp
A src/RTPlot.cpp
R src/{ImpulseResponsePage.h => RTPlot.h}
M CMakeLists.txt => CMakeLists.txt +1 -0
@@ 34,6 34,7 @@ find_package(Qt6 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS
find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS
    I18n
    CoreAddons
    Plotting
    WidgetsAddons
    XmlGui
)

M src/CMakeLists.txt => src/CMakeLists.txt +3 -2
@@ 1,9 1,9 @@
# SPDX-FileCopyrightText: 2023 Mark Penner <mrpenner@mailbox.org>
# SPDX-FileCopyrightText: 2024 Mark Penner <mrpenner@mailbox.org>
# SPDX-License-Identifier: BSD-2-Clause

add_executable(aerodramus-gui
    CalculatorPage.cpp
    ImpulseResponsePage.cpp
    RTPlot.cpp
    main.cpp
    MainWindow.cpp
)


@@ 23,6 23,7 @@ target_link_libraries(aerodramus-gui PRIVATE
    KF6::CoreAddons
    KF6::WidgetsAddons
    KF6::XmlGui
    KF6::Plotting
)
set_target_properties(aerodramus-gui PROPERTIES OUTPUT_NAME "aerodramus")


D src/ImpulseResponsePage.cpp => src/ImpulseResponsePage.cpp +0 -13
@@ 1,13 0,0 @@
// SPDX-FileCopyrightText: 2023 Mark Penner <mrpenner@mailbox.org>
// SPDX-License-Identifier: GPL-3.0-or-later

#include "ImpulseResponsePage.h"

#include <QLabel>

ImpulseResponsePage::ImpulseResponsePage(const QString &fileName, QWidget *parent)
    : QTabWidget::QTabWidget(parent)
{
    QLabel *name = new QLabel(fileName);
    this->addTab(name, fileName);
}

M src/MainWindow.cpp => src/MainWindow.cpp +2 -2
@@ 4,7 4,7 @@
#include "MainWindow.h"

#include "CalculatorPage.h"
#include "ImpulseResponsePage.h"
#include "RTPlot.h"
#include <KActionCollection>
#include <KLocalizedString>
#include <KStandardAction>


@@ 49,6 49,6 @@ void MainWindow::openFile()
    const QString fileNameFromDialog =
        QFileDialog::getOpenFileName(this, i18n("Open File"), QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0]);

    ImpulseResponsePage *page = new ImpulseResponsePage(fileNameFromDialog, this);
    RTPlot *page = new RTPlot(fileNameFromDialog, this);
    m_pageWidget->addPage(page, fileNameFromDialog);
}

A src/RTPlot.cpp => src/RTPlot.cpp +40 -0
@@ 0,0 1,40 @@
// SPDX-FileCopyrightText: 2024 Mark Penner <mrpenner@mailbox.org>
// SPDX-License-Identifier: GPL-3.0-or-later

#include "RTPlot.h"

#include "lib/aerodramus.h"

#include <kplotaxis.h>
#include <kplotobject.h>
#include <kplotwidget.h>

#include <QVBoxLayout>

#include <algorithm>

using namespace Qt::Literals::StringLiterals;

RTPlot::RTPlot(const QString &fileName, QWidget *parent)
    : QWidget::QWidget(parent)
{
    auto file{Aerodramus::read(fileName.toStdString())};
    auto layout{new QVBoxLayout};
    auto plot{new KPlotWidget};

    plot->setMinimumSize(400, 400);
    plot->setAntialiasing(true);
    layout->addWidget(plot);
    this->setLayout(layout);

    plot->setLimits(-10, file.sample_data.size(), *std::ranges::min_element(file.sample_data), *std::ranges::max_element(file.sample_data));
    plot->axis(KPlotWidget::BottomAxis)->setLabel(u"sample number"_s);

    auto po1 = new KPlotObject(Qt::red, KPlotObject::Lines, 2);
    for (unsigned long t = 0; t < file.sample_data.size(); ++t) {
        po1->addPoint(t, file.sample_data.at(t));
    }
    plot->addPlotObject(po1);

    plot->update();
}

R src/ImpulseResponsePage.h => src/RTPlot.h +6 -6
@@ 1,16 1,16 @@
// SPDX-FileCopyrightText: 2023 Mark Penner <mrpenner@mailbox.org>
// SPDX-FileCopyrightText: 2024 Mark Penner <mrpenner@mailbox.org>
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef IMPULSERESPONSEPAGE_H
#define IMPULSERESPONSEPAGE_H
#ifndef RTPLOT_H
#define RTPLOT_H

#include <QTabWidget>
#include <QWidget>

class ImpulseResponsePage : public QTabWidget
class RTPlot : public QWidget
{
    Q_OBJECT

public:
    ImpulseResponsePage(const QString &fileName, QWidget *parent = nullptr);
    RTPlot(const QString &fileName, QWidget *parent = nullptr);
};
#endif