PS-80 GrandComp Analyzer 1.2
Loading...
Searching...
No Matches
widget.h
Go to the documentation of this file.
1/****************************************************************************
2** Original work Copyright (C) 2016 The Qt Company Ltd.
3** Modified work Copyright (c) 2026 Patrik Källback
4**
5** @file widget.h
6** @brief Main controller and UI interface for the PS-80 GrandComp Analyzer.
7** * This class manages the user interaction, signal visualization, and
8** high-level orchestration of the audio analysis algorithms.
9** @author Patrik Källback
10** @version 1.2
11** @license SPDX-License-Identifier: MIT (for modifications)
12** @date 2026-02-17
13****************************************************************************/
14
15#ifndef WIDGET_H
16#define WIDGET_H
17
18#include <QAudioOutput>
19#include <QMouseEvent>
20#include <QPaintEvent>
21#include <QWidget>
22#include "audio_config.h"
23#include "xyseriesiodevice.h"
24#include <vector>
25
26QT_BEGIN_NAMESPACE
27namespace Ui {
28class Widget;
29}
30QT_END_NAMESPACE
31
38class Widget : public QWidget
39{
40 Q_OBJECT
41
42public:
44 explicit Widget(QWidget *parent = nullptr);
45
47 virtual ~Widget();
48
49 // Disable copy for UI controller to maintain unique ownership
50 Widget(const Widget &) = delete;
51 Widget &operator=(const Widget &) = delete;
52
53private slots:
59 void onComboBoxFreqCurrentTextChanged(const QString &text);
61
69
80
81protected:
83 void paintEvent(QPaintEvent *event) override;
84
86 void mousePressEvent(QMouseEvent *event) override;
87
88private:
91 void drawWavFileContents(QPainter *painter, QWidget *target, const std::vector<float> &data);
92 void drawWaveformContents(QPainter *painter, QWidget *target, const std::vector<float> &data);
94
97
99 void setupAudio();
100
102 void loadWavFile(const QString &fileName);
103
105 void updateButtonStates(); // Hjälpmetod för att styra Enabled/Disabled
106
110 void normalizeCapturedCycle(std::vector<float> &capturedCycle);
111
113 void waveformBackup(const int centerSample);
114
116 void copyWaveform(std::vector<float> &dest, const std::vector<float> &source);
117
121 void stretchWaveform(std::vector<float> &dest,
122 const std::vector<float> &source,
123 const int waveformeLen);
124
126 void flipTimeWaveform(std::vector<float> &dest);
127
129 void flipPhaseWaveform(std::vector<float> &dest);
131
132private:
133 Ui::Widget *ui;
134 Qt::CheckState m_stateFloatingClip = Qt::CheckState::Unchecked;
135
136 // --- PS-80 "GrandComp" Audio Engine ---
137 QAudioOutput *m_audioOutput{nullptr};
139
141 QString m_folderPath{""};
142
143 // --- Data Buffers ---
144 std::vector<float> m_fullWavData;
145 std::vector<float> m_capturedCycle;
146 std::vector<float> m_copiedCapturedCycle;
147
153};
154
155#endif // WIDGET_H
The primary application window and signal processing controller.
Definition widget.h:39
void onBrowseFolderButtonClicked()
Slot: Handles the folder selection for waveform exports (the "Photo Shoot").
Definition widget.cpp:229
bool m_isWaveformFlipPhase
Definition widget.h:150
void onMoveLeftButtonClicked()
Slot: Shifts the waveform data to the left within the viewing window.
Definition widget.cpp:401
Ui::Widget * ui
Definition widget.h:133
void waveformBackup(const int centerSample)
Creates a safety backup of the currently selected waveform segment.
Definition widget.cpp:1124
void drawWavFileContents(QPainter *painter, QWidget *target, const std::vector< float > &data)
Renders the macro view of the entire WAV file.
Definition widget.cpp:753
void onMoveRightButtonClicked()
Slot: Shifts the waveform data to the right within the viewing window.
Definition widget.cpp:458
QAudioOutput * m_audioOutput
Definition widget.h:137
void onOpenButtonClicked()
Slot: Handles the 'Open' button click event.
Definition widget.cpp:139
void setupAudio()
Initializes the Qt Audio output stack and the custom XYSeriesIODevice.
Definition widget.cpp:930
void copyWaveform(std::vector< float > &dest, const std::vector< float > &source)
Copies waveform data between buffers.
Definition widget.cpp:1149
void drawWaveformContents(QPainter *painter, QWidget *target, const std::vector< float > &data)
Renders the detailed micro-view of the captured waveform cycle.
Definition widget.cpp:855
void loadWavFile(const QString &fileName)
Loads raw PCM data from a WAV file into m_fullWavData.
Definition widget.cpp:965
void onStretchButtonClicked()
Slot: Stretches the waveform by reducing the source window length.
Definition widget.cpp:515
void onFlipPhaseButtonClicked()
Slot: Toggles the temporal mirroring (Y-axis) of the captured waveform.
Definition widget.cpp:653
void onPlayClipButtonClicked()
Slot: Initiates playback of the captured single-cycle waveform.
Definition widget.cpp:334
void onSaveButtonClicked()
Slot: Exports the currently captured waveform cycle to a CSV file.
Definition widget.cpp:169
Widget & operator=(const Widget &)=delete
void onShrinkedButtonClicked()
Slot: Shrinks the waveform by increasing the source window length.
Definition widget.cpp:571
void mousePressEvent(QMouseEvent *event) override
Handles sample-precise selection within the waveform view.
Definition widget.cpp:708
void onFlipTimeButtonClicked()
Slot: Toggles the temporal mirroring (X-axis) of the captured waveform.
Definition widget.cpp:627
void normalizeCapturedCycle(std::vector< float > &capturedCycle)
Peak-normalization algorithm. Scales the captured segment to utilize the full dynamic range [-1....
Definition widget.cpp:1070
bool m_isWaveformFlipTime
Definition widget.h:149
int m_lastClickSample
Definition widget.h:140
float m_audioFreq
Definition widget.h:151
void onPauseClipButtonClicked()
Slot: Halts the single-cycle waveform oscillator.
Definition widget.cpp:375
void onFloatingClipButtonClicked()
Slot: Toggles the sub-sample precision mode (Floating Clip).
Definition widget.cpp:389
std::vector< float > m_copiedCapturedCycle
Definition widget.h:146
virtual ~Widget()
Virtual destructor for clean resource management.
Definition widget.cpp:121
void stretchWaveform(std::vector< float > &dest, const std::vector< float > &source, const int waveformeLen)
Mathematical resampling of the waveform. Maps the source segment into the target m_waveformLen using ...
Definition widget.cpp:1183
void onComboBoxFreqCurrentTextChanged(const QString &text)
Slot: Updates the synthesis frequency based on UI selection.
Definition widget.cpp:272
QString m_folderPath
Definition widget.h:141
Widget(QWidget *parent=nullptr)
Initializes the UI and prepares the XYSeriesIODevice.
Definition widget.cpp:33
XYSeriesIODevice * m_device
Definition widget.h:138
void onPauseWavButtonClicked()
Slot: Suspends audio playback by halting signal progression.
Definition widget.cpp:319
void paintEvent(QPaintEvent *event) override
Renders the waveform visualizations and playheads.
Definition widget.cpp:681
std::vector< float > m_fullWavData
Definition widget.h:144
std::vector< float > m_capturedCycle
Definition widget.h:145
void flipPhaseWaveform(std::vector< float > &dest)
Reverses the phase of the current captured cycle.
Definition widget.cpp:1272
void updateButtonStates()
Manages the enabled/disabled state of UI elements based on engine state.
Definition widget.cpp:1029
void flipTimeWaveform(std::vector< float > &dest)
Reverses the time of the current captured cycle.
Definition widget.cpp:1254
Widget(const Widget &)=delete
int m_waveformLen
Definition widget.h:148
Qt::CheckState m_stateFloatingClip
Definition widget.h:134
void onPlayWavButtonClicked()
Slot: Initiates full WAV file playback.
Definition widget.cpp:292
A specialized I/O device that bridges raw signal data to the audio hardware.
Definition xyseriesiodevice.h:34
constexpr int WAVESHAPE_LEN
The fixed buffer length for a single-cycle waveform (e.g., for wavetable synthesis).
Definition audio_config.h:27
constexpr float DEFAULT_FREQ
The reference frequency (A1) used for precise cycle extraction.
Definition audio_config.h:36
Definition widget.h:27