From cc11cfe63a5b551d6f6bd3d81266016f814ae0d8 Mon Sep 17 00:00:00 2001 From: Blitblank Date: Fri, 26 Dec 2025 18:42:14 -0600 Subject: [PATCH] cleanup envelope parameter mappings --- CMakeLists.txt | 5 +++++ src/synth/AudioEngine.cpp | 2 ++ src/synth/AudioEngine.h | 2 ++ src/synth/Envelope.h | 2 +- src/synth/Synth.cpp | 6 ++++++ src/synth/Synth.h | 8 +++++-- src/ui/MainWindow.cpp | 12 +++++++---- src/ui/MainWindow.ui | 21 ++++++++++++++++++- .../EnvelopeGenerator/EnvelopeGenerator.h | 1 + 9 files changed, 51 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 12e2a38..a80c7a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,8 @@ qt_add_executable(metabolus src/synth/Envelope.h src/synth/Synth.cpp src/synth/Synth.h + src/synth/SynthBuffer.cpp + src/synth/SynthBuffer.h resources/resources.qrc src/ui/widgets/SmartSlider/SmartSlider.cpp src/ui/widgets/SmartSlider/SmartSlider.h @@ -64,6 +66,9 @@ qt_add_executable(metabolus src/ui/widgets/EnvelopeGenerator/EnvelopeGenerator.cpp src/ui/widgets/EnvelopeGenerator/EnvelopeGenerator.h src/ui/widgets/EnvelopeGenerator/EnvelopeGenerator.ui + src/ui/widgets/Scope/Scope.cpp + src/ui/widgets/Scope/Scope.h + src/ui/widgets/Scope/Scope.ui ) set_target_properties(metabolus PROPERTIES AUTOUIC ON) diff --git a/src/synth/AudioEngine.cpp b/src/synth/AudioEngine.cpp index f3dfd87..2a284a3 100644 --- a/src/synth/AudioEngine.cpp +++ b/src/synth/AudioEngine.cpp @@ -11,6 +11,8 @@ AudioEngine::AudioEngine() : synth_(params_) { // TODO: get audio configurations synth_.setSampleRate(sampleRate_); + synth_.setScopeBuffer(&scope_); + } AudioEngine::~AudioEngine() { diff --git a/src/synth/AudioEngine.h b/src/synth/AudioEngine.h index 22cc184..82ae17e 100644 --- a/src/synth/AudioEngine.h +++ b/src/synth/AudioEngine.h @@ -23,6 +23,7 @@ public: // getters ParameterStore* parameters() { return ¶ms_; } NoteQueue& noteQueue() { return noteQueue_; } + ScopeBuffer& scopeBuffer() { return scope_; } private: @@ -35,6 +36,7 @@ private: ParameterStore params_; // stores the control parameters NoteQueue noteQueue_; // stores note events for passing between threads Synth synth_; // generates audio + ScopeBuffer scope_ { 1024 }; // stores audio samples for visualization RtAudio audio_; // audio device // TODO: id like a yml config file or something for these diff --git a/src/synth/Envelope.h b/src/synth/Envelope.h index 0815672..df1e77b 100644 --- a/src/synth/Envelope.h +++ b/src/synth/Envelope.h @@ -32,7 +32,7 @@ public: void noteOn(); void noteOff(); - // return current level + // calculates and returns envelope level. must only be called once per sample float process(); // determine if a note is playing or not diff --git a/src/synth/Synth.cpp b/src/synth/Synth.cpp index 3d0e244..9176c51 100644 --- a/src/synth/Synth.cpp +++ b/src/synth/Synth.cpp @@ -99,6 +99,12 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) { out[2*i] = sampleOut; // left out[2*i+1] = sampleOut; // right + // write to scope buffer + if (scope_) { + scope_->push(sampleOut); // visualization tap + // set trigger info here too + } + // sampling business phase_ += phaseInc; if (phase_ > 2.0f * M_PI) phase_ -= 2.0f * M_PI; diff --git a/src/synth/Synth.h b/src/synth/Synth.h index 0fe44b1..da4fd9e 100644 --- a/src/synth/Synth.h +++ b/src/synth/Synth.h @@ -4,6 +4,7 @@ #include "../ParameterStore.h" #include "../NoteQueue.h" #include "Envelope.h" +#include "ScopeBuffer.h" #include #include @@ -28,8 +29,9 @@ public: // handles note events void handleNoteEvent(const NoteEvent& event); - // sample rate setter + // setters void setSampleRate(uint32_t sampleRate) { sampleRate_ = sampleRate; } + void setScopeBuffer(ScopeBuffer* scope) { scope_ = scope; } private: @@ -60,7 +62,9 @@ private: std::vector heldNotes_; // envelopes !! - // TODO: set these parameters via sliders Envelope gainEnvelope_; + // for the scope + ScopeBuffer* scope_ = nullptr; + }; diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 3b4d9dc..f965e50 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -11,16 +11,16 @@ MainWindow::MainWindow(QWidget *parent) : audio_(new AudioEngine()), keyboard_(audio_->noteQueue()) { - // Initialize UI + // initialize ui ui_->setupUi(this); setFocusPolicy(Qt::StrongFocus); + // connect scope + ui_->scopeWidget->setScopeBuffer(&audioEngine_->scopeBuffer()); + // Connect buttons to slots connect(ui_->buttonReset, &QPushButton::clicked, this, &MainWindow::onResetClicked); - // synth business - audio_->start(); - // connect envelopeGenerator ui_->envelopeOsc1Volume->init(EnvelopeId::Osc1Volume); connect(ui_->envelopeOsc1Volume, &EnvelopeGenerator::envelopeChanged, @@ -28,6 +28,10 @@ MainWindow::MainWindow(QWidget *parent) : audio_->parameters()->set(EnvelopeId::Osc1Volume, a, d, s, r); }); // this should be easy enough to put into a for each envelopeGenerator loop + + // synth business + audio_->start(); + } MainWindow::~MainWindow() { diff --git a/src/ui/MainWindow.ui b/src/ui/MainWindow.ui index 4faadb0..446f821 100644 --- a/src/ui/MainWindow.ui +++ b/src/ui/MainWindow.ui @@ -7,7 +7,7 @@ 0 0 800 - 600 + 800 @@ -51,6 +51,19 @@ true + + + + 200 + 540 + 400 + 200 + + + + true + + @@ -60,6 +73,12 @@
EnvelopeGenerator/EnvelopeGenerator.h
1 + + Scope + QWidget +
Scope/Scope.h
+ 1 +
diff --git a/src/ui/widgets/EnvelopeGenerator/EnvelopeGenerator.h b/src/ui/widgets/EnvelopeGenerator/EnvelopeGenerator.h index 3fc14f8..33af889 100644 --- a/src/ui/widgets/EnvelopeGenerator/EnvelopeGenerator.h +++ b/src/ui/widgets/EnvelopeGenerator/EnvelopeGenerator.h @@ -16,6 +16,7 @@ public: explicit EnvelopeGenerator(QWidget* parent = nullptr); ~EnvelopeGenerator(); + // connects signals, sets parameters to the defaults defined in paramStore void init(EnvelopeId id); // setters