cleanup envelope parameter mappings

This commit is contained in:
2025-12-26 18:42:14 -06:00
parent c5d0fe6091
commit cc11cfe63a
9 changed files with 51 additions and 8 deletions

View File

@@ -57,6 +57,8 @@ qt_add_executable(metabolus
src/synth/Envelope.h src/synth/Envelope.h
src/synth/Synth.cpp src/synth/Synth.cpp
src/synth/Synth.h src/synth/Synth.h
src/synth/SynthBuffer.cpp
src/synth/SynthBuffer.h
resources/resources.qrc resources/resources.qrc
src/ui/widgets/SmartSlider/SmartSlider.cpp src/ui/widgets/SmartSlider/SmartSlider.cpp
src/ui/widgets/SmartSlider/SmartSlider.h 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.cpp
src/ui/widgets/EnvelopeGenerator/EnvelopeGenerator.h src/ui/widgets/EnvelopeGenerator/EnvelopeGenerator.h
src/ui/widgets/EnvelopeGenerator/EnvelopeGenerator.ui 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) set_target_properties(metabolus PROPERTIES AUTOUIC ON)

View File

@@ -11,6 +11,8 @@ AudioEngine::AudioEngine() : synth_(params_) {
// TODO: get audio configurations // TODO: get audio configurations
synth_.setSampleRate(sampleRate_); synth_.setSampleRate(sampleRate_);
synth_.setScopeBuffer(&scope_);
} }
AudioEngine::~AudioEngine() { AudioEngine::~AudioEngine() {

View File

@@ -23,6 +23,7 @@ public:
// getters // getters
ParameterStore* parameters() { return &params_; } ParameterStore* parameters() { return &params_; }
NoteQueue& noteQueue() { return noteQueue_; } NoteQueue& noteQueue() { return noteQueue_; }
ScopeBuffer& scopeBuffer() { return scope_; }
private: private:
@@ -35,6 +36,7 @@ private:
ParameterStore params_; // stores the control parameters ParameterStore params_; // stores the control parameters
NoteQueue noteQueue_; // stores note events for passing between threads NoteQueue noteQueue_; // stores note events for passing between threads
Synth synth_; // generates audio Synth synth_; // generates audio
ScopeBuffer scope_ { 1024 }; // stores audio samples for visualization
RtAudio audio_; // audio device RtAudio audio_; // audio device
// TODO: id like a yml config file or something for these // TODO: id like a yml config file or something for these

View File

@@ -32,7 +32,7 @@ public:
void noteOn(); void noteOn();
void noteOff(); void noteOff();
// return current level // calculates and returns envelope level. must only be called once per sample
float process(); float process();
// determine if a note is playing or not // determine if a note is playing or not

View File

@@ -99,6 +99,12 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) {
out[2*i] = sampleOut; // left out[2*i] = sampleOut; // left
out[2*i+1] = sampleOut; // right out[2*i+1] = sampleOut; // right
// write to scope buffer
if (scope_) {
scope_->push(sampleOut); // visualization tap
// set trigger info here too
}
// sampling business // sampling business
phase_ += phaseInc; phase_ += phaseInc;
if (phase_ > 2.0f * M_PI) phase_ -= 2.0f * M_PI; if (phase_ > 2.0f * M_PI) phase_ -= 2.0f * M_PI;

View File

@@ -4,6 +4,7 @@
#include "../ParameterStore.h" #include "../ParameterStore.h"
#include "../NoteQueue.h" #include "../NoteQueue.h"
#include "Envelope.h" #include "Envelope.h"
#include "ScopeBuffer.h"
#include <vector> #include <vector>
#include <atomic> #include <atomic>
@@ -28,8 +29,9 @@ public:
// handles note events // handles note events
void handleNoteEvent(const NoteEvent& event); void handleNoteEvent(const NoteEvent& event);
// sample rate setter // setters
void setSampleRate(uint32_t sampleRate) { sampleRate_ = sampleRate; } void setSampleRate(uint32_t sampleRate) { sampleRate_ = sampleRate; }
void setScopeBuffer(ScopeBuffer* scope) { scope_ = scope; }
private: private:
@@ -60,7 +62,9 @@ private:
std::vector<uint8_t> heldNotes_; std::vector<uint8_t> heldNotes_;
// envelopes !! // envelopes !!
// TODO: set these parameters via sliders
Envelope gainEnvelope_; Envelope gainEnvelope_;
// for the scope
ScopeBuffer* scope_ = nullptr;
}; };

View File

@@ -11,16 +11,16 @@ MainWindow::MainWindow(QWidget *parent) :
audio_(new AudioEngine()), audio_(new AudioEngine()),
keyboard_(audio_->noteQueue()) { keyboard_(audio_->noteQueue()) {
// Initialize UI // initialize ui
ui_->setupUi(this); ui_->setupUi(this);
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
// connect scope
ui_->scopeWidget->setScopeBuffer(&audioEngine_->scopeBuffer());
// Connect buttons to slots // Connect buttons to slots
connect(ui_->buttonReset, &QPushButton::clicked, this, &MainWindow::onResetClicked); connect(ui_->buttonReset, &QPushButton::clicked, this, &MainWindow::onResetClicked);
// synth business
audio_->start();
// connect envelopeGenerator // connect envelopeGenerator
ui_->envelopeOsc1Volume->init(EnvelopeId::Osc1Volume); ui_->envelopeOsc1Volume->init(EnvelopeId::Osc1Volume);
connect(ui_->envelopeOsc1Volume, &EnvelopeGenerator::envelopeChanged, connect(ui_->envelopeOsc1Volume, &EnvelopeGenerator::envelopeChanged,
@@ -28,6 +28,10 @@ MainWindow::MainWindow(QWidget *parent) :
audio_->parameters()->set(EnvelopeId::Osc1Volume, a, d, s, r); audio_->parameters()->set(EnvelopeId::Osc1Volume, a, d, s, r);
}); });
// this should be easy enough to put into a for each envelopeGenerator loop // this should be easy enough to put into a for each envelopeGenerator loop
// synth business
audio_->start();
} }
MainWindow::~MainWindow() { MainWindow::~MainWindow() {

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>800</width>
<height>600</height> <height>800</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -51,6 +51,19 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
<widget class="Scope" name="scope" native="true">
<property name="geometry">
<rect>
<x>200</x>
<y>540</y>
<width>400</width>
<height>200</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
</widget>
</widget> </widget>
</widget> </widget>
<customwidgets> <customwidgets>
@@ -60,6 +73,12 @@
<header>EnvelopeGenerator/EnvelopeGenerator.h</header> <header>EnvelopeGenerator/EnvelopeGenerator.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>Scope</class>
<extends>QWidget</extends>
<header>Scope/Scope.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>

View File

@@ -16,6 +16,7 @@ public:
explicit EnvelopeGenerator(QWidget* parent = nullptr); explicit EnvelopeGenerator(QWidget* parent = nullptr);
~EnvelopeGenerator(); ~EnvelopeGenerator();
// connects signals, sets parameters to the defaults defined in paramStore
void init(EnvelopeId id); void init(EnvelopeId id);
// setters // setters