Christmas cleaning
This commit is contained in:
@@ -1,118 +0,0 @@
|
||||
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include "ui_MainWindow.h"
|
||||
|
||||
#include "ParameterStore.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
audio_(new AudioEngine()),
|
||||
keyboard_(audio_->noteQueue()) {
|
||||
|
||||
ui->setupUi(this);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
// Initialize UI
|
||||
updateCounterLabel();
|
||||
|
||||
// Connect buttons to slots
|
||||
connect(ui->buttonIncrement, &QPushButton::clicked, this, &MainWindow::onIncrementClicked);
|
||||
connect(ui->buttonReset, &QPushButton::clicked, this, &MainWindow::onResetClicked);
|
||||
|
||||
// slider business
|
||||
// TODO: smart slider widget
|
||||
connect(ui->slider, &QSlider::valueChanged, this, &MainWindow::onSliderValueChanged);
|
||||
connect(ui->inputMin, &QLineEdit::editingFinished, this, &MainWindow::onMinChanged);
|
||||
connect(ui->inputMax, &QLineEdit::editingFinished, this, &MainWindow::onMaxChanged);
|
||||
connect(ui->inputStep, &QLineEdit::editingFinished, this, &MainWindow::onStepChanged);
|
||||
connect(ui->inputValue, &QLineEdit::editingFinished, this, &MainWindow::onValueChanged);
|
||||
|
||||
// synth business
|
||||
audio_->start();
|
||||
|
||||
// init defaults
|
||||
// TODO:: there's gotta be a better way
|
||||
ui->slider->setValue(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].def);
|
||||
ui->slider->setMinimum(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].min);
|
||||
ui->slider->setMaximum(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].max);
|
||||
ui->inputValue->setText(QString::number(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].def));
|
||||
ui->inputMin->setText(QString::number(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].min));
|
||||
ui->inputMax->setText(QString::number(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].max));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent* event) {
|
||||
keyboard_.handleKeyPress(event);
|
||||
}
|
||||
|
||||
void MainWindow::keyReleaseEvent(QKeyEvent* event) {
|
||||
keyboard_.handleKeyRelease(event);
|
||||
}
|
||||
|
||||
void MainWindow::onIncrementClicked() {
|
||||
counter_++;
|
||||
updateCounterLabel();
|
||||
}
|
||||
|
||||
void MainWindow::onResetClicked() {
|
||||
counter_ = 0;
|
||||
updateCounterLabel();
|
||||
}
|
||||
|
||||
void MainWindow::updateCounterLabel() {
|
||||
ui->labelCounter->setText(QString::number(counter_));
|
||||
}
|
||||
|
||||
// allows only numbers to be set
|
||||
void MainWindow::onSliderValueChanged(int value) {
|
||||
QSignalBlocker blocker(ui->inputValue);
|
||||
ui->inputValue->setText(QString::number(value));
|
||||
|
||||
// forward value so synthesizer can read
|
||||
audio_->parameters()->set(ParamId::Osc1Frequency, static_cast<float>(value));
|
||||
}
|
||||
|
||||
// allows only values within the min, max to be set by the text field
|
||||
void MainWindow::onValueChanged() {
|
||||
bool ok = false;
|
||||
int value = ui->inputValue->text().toInt(&ok);
|
||||
if(!ok) return;
|
||||
|
||||
value = qBound(ui->slider->minimum(), value, ui->slider->maximum());
|
||||
ui->slider->setValue(value);
|
||||
}
|
||||
|
||||
void MainWindow::applySliderRange() {
|
||||
bool minOk, maxOk;
|
||||
int min = ui->inputMin->text().toInt(&minOk);
|
||||
int max = ui->inputMax->text().toInt(&maxOk);
|
||||
if(!minOk || !maxOk || min > max) return;
|
||||
|
||||
ui->slider->setRange(min, max);
|
||||
|
||||
syncValueToUi(ui->slider->value());
|
||||
}
|
||||
|
||||
void MainWindow::applySliderStep() {
|
||||
bool ok;
|
||||
int step = ui->inputStep->text().toInt(&ok);
|
||||
if(!ok || step <= 0) return;
|
||||
|
||||
ui->slider->setSingleStep(step);
|
||||
ui->slider->setPageStep(step);
|
||||
}
|
||||
|
||||
void MainWindow::syncValueToUi(int value) {
|
||||
QSignalBlocker block1(ui->slider);
|
||||
QSignalBlocker block2(ui->inputValue);
|
||||
|
||||
value = qBound(ui->slider->minimum(), value, ui->slider->maximum());
|
||||
ui->slider->setValue(value);
|
||||
ui->inputValue->setText(QString::number(value));
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "ui/MainWindow.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) {
|
||||
float sineSample = std::sin(phase_);
|
||||
float squareSample = -0.707f;
|
||||
if(phase_ >= M_PI) squareSample = 0.707f;
|
||||
sampleOut = sineSample * gain;
|
||||
sampleOut = squareSample * gain;
|
||||
|
||||
// write to buffer
|
||||
out[2*i] = sampleOut; // left
|
||||
|
||||
118
src/ui/MainWindow.cpp
Normal file
118
src/ui/MainWindow.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include "ui_MainWindow.h"
|
||||
|
||||
#include "../ParameterStore.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui_(new Ui::MainWindow),
|
||||
audio_(new AudioEngine()),
|
||||
keyboard_(audio_->noteQueue()) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
// Initialize UI
|
||||
updateCounterLabel();
|
||||
|
||||
// Connect buttons to slots
|
||||
connect(ui_->buttonIncrement, &QPushButton::clicked, this, &MainWindow::onIncrementClicked);
|
||||
connect(ui_->buttonReset, &QPushButton::clicked, this, &MainWindow::onResetClicked);
|
||||
|
||||
// slider business
|
||||
// TODO: smart slider widget
|
||||
connect(ui_->slider, &QSlider::valueChanged, this, &MainWindow::onSliderValueChanged);
|
||||
connect(ui_->inputMin, &QLineEdit::editingFinished, this, &MainWindow::onMinChanged);
|
||||
connect(ui_->inputMax, &QLineEdit::editingFinished, this, &MainWindow::onMaxChanged);
|
||||
connect(ui_->inputStep, &QLineEdit::editingFinished, this, &MainWindow::onStepChanged);
|
||||
connect(ui_->inputValue, &QLineEdit::editingFinished, this, &MainWindow::onValueChanged);
|
||||
|
||||
// synth business
|
||||
audio_->start();
|
||||
|
||||
// init defaults
|
||||
// TODO:: there's gotta be a better way
|
||||
ui_->slider->setValue(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].def);
|
||||
ui_->slider->setMinimum(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].min);
|
||||
ui_->slider->setMaximum(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].max);
|
||||
ui_->inputValue->setText(QString::number(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].def));
|
||||
ui_->inputMin->setText(QString::number(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].min));
|
||||
ui_->inputMax->setText(QString::number(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Frequency)].max));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent* event) {
|
||||
keyboard_.handleKeyPress(event);
|
||||
}
|
||||
|
||||
void MainWindow::keyReleaseEvent(QKeyEvent* event) {
|
||||
keyboard_.handleKeyRelease(event);
|
||||
}
|
||||
|
||||
void MainWindow::onIncrementClicked() {
|
||||
counter_++;
|
||||
updateCounterLabel();
|
||||
}
|
||||
|
||||
void MainWindow::onResetClicked() {
|
||||
counter_ = 0;
|
||||
updateCounterLabel();
|
||||
}
|
||||
|
||||
void MainWindow::updateCounterLabel() {
|
||||
ui_->labelCounter->setText(QString::number(counter_));
|
||||
}
|
||||
|
||||
// allows only numbers to be set
|
||||
void MainWindow::onSliderValueChanged(int value) {
|
||||
QSignalBlocker blocker(ui_->inputValue);
|
||||
ui_->inputValue->setText(QString::number(value));
|
||||
|
||||
// forward value so synthesizer can read
|
||||
audio_->parameters()->set(ParamId::Osc1Frequency, static_cast<float>(value));
|
||||
}
|
||||
|
||||
// allows only values within the min, max to be set by the text field
|
||||
void MainWindow::onValueChanged() {
|
||||
bool ok = false;
|
||||
int value = ui_->inputValue->text().toInt(&ok);
|
||||
if(!ok) return;
|
||||
|
||||
value = qBound(ui_->slider->minimum(), value, ui_->slider->maximum());
|
||||
ui_->slider->setValue(value);
|
||||
}
|
||||
|
||||
void MainWindow::applySliderRange() {
|
||||
bool minOk, maxOk;
|
||||
int min = ui_->inputMin->text().toInt(&minOk);
|
||||
int max = ui_->inputMax->text().toInt(&maxOk);
|
||||
if(!minOk || !maxOk || min > max) return;
|
||||
|
||||
ui_->slider->setRange(min, max);
|
||||
|
||||
syncValueToUi(ui_->slider->value());
|
||||
}
|
||||
|
||||
void MainWindow::applySliderStep() {
|
||||
bool ok;
|
||||
int step = ui_->inputStep->text().toInt(&ok);
|
||||
if(!ok || step <= 0) return;
|
||||
|
||||
ui_->slider->setSingleStep(step);
|
||||
ui_->slider->setPageStep(step);
|
||||
}
|
||||
|
||||
void MainWindow::syncValueToUi(int value) {
|
||||
QSignalBlocker block1(ui_->slider);
|
||||
QSignalBlocker block2(ui_->inputValue);
|
||||
|
||||
value = qBound(ui_->slider->minimum(), value, ui_->slider->maximum());
|
||||
ui_->slider->setValue(value);
|
||||
ui_->inputValue->setText(QString::number(value));
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QMainWindow>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include "synth/AudioEngine.h"
|
||||
#include "../synth/AudioEngine.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
@@ -35,7 +35,7 @@ private slots:
|
||||
void onValueChanged();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
Ui::MainWindow *ui_;
|
||||
int counter_ = 0;
|
||||
|
||||
int value = 0;
|
||||
0
src/ui/SmartSlider.ui
Normal file
0
src/ui/SmartSlider.ui
Normal file
35
src/widgets/SmartSlider.cpp
Normal file
35
src/widgets/SmartSlider.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
#include "SmartSlider.h"
|
||||
|
||||
SmartSlider(QWidget* parent = nullptr) {
|
||||
|
||||
}
|
||||
|
||||
void SmartSlider::setRange(float min, float max) {
|
||||
|
||||
}
|
||||
|
||||
void SmartSlider::setStep(float step) {
|
||||
|
||||
}
|
||||
|
||||
void SmartSlider::setValue(float value) {
|
||||
|
||||
}
|
||||
|
||||
void SmartSlider::value() const;
|
||||
void SmartSlider::valueChanged(float value) {
|
||||
|
||||
}
|
||||
|
||||
void SmartSlider::onSliderChanged(int v) {
|
||||
|
||||
}
|
||||
|
||||
void SmartSlider::onSpinValueChanged(float v) {
|
||||
|
||||
}
|
||||
|
||||
void SmartSlider::onRangeChanged() {
|
||||
|
||||
}
|
||||
37
src/widgets/SmartSlider.h
Normal file
37
src/widgets/SmartSlider.h
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class SmartSlider; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class SmartSlider : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SmartSlider(QWidget* parent = nullptr);
|
||||
~SmartSlider() = default;
|
||||
|
||||
void setRange(float min, float max);
|
||||
void setStep(float step);
|
||||
void setValue(float value);
|
||||
|
||||
void value() const;
|
||||
|
||||
signals:
|
||||
void valueChanged(float value);
|
||||
|
||||
private slots:
|
||||
void onSliderChanged(int v);
|
||||
void onSpinValueChanged(float v);
|
||||
void onRangeChanged();
|
||||
|
||||
private:
|
||||
|
||||
Ui::SmartSlider* ui_;
|
||||
|
||||
int sliderResolution_ = 10000;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user