wip: filter gui

This commit is contained in:
2023-09-08 03:56:17 +04:00
parent 307660d83a
commit 28ceaec23a
6 changed files with 68 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
#pragma once
#include "Filter.h"
#include "ADSR.h"
#include "Synth.h"
#include "SynthGuiState.h"
@@ -19,7 +20,8 @@ class Renderer {
void draw_signal(Synth& synth, SynthGuiState& synth_gui);
void draw_adsr_panel(ADSR* adsr, ADSRGuiState& gui_adsr,
const Rectangle& panel_bounds, float panel_y_offset);
void draw_second_panel(Rectangle& bounds);
float draw_filter_panel(Filter* filter, FilterGuiState& gui_filter, const Rectangle& panel_bounds);
public:
Renderer(/* args */);
~Renderer();

View File

@@ -1,6 +1,7 @@
#pragma once
#include "ADSR.h"
#include "Filter.h"
#include "Adder.h"
#include "Effect.h"
#include "Note.h"
@@ -32,4 +33,5 @@ class Synth {
const std::vector<Oscillator*>& GetOscillators() { return m_oscillators; }
const bool& GetIsNoteTriggered() { return is_note_triggered; }
ADSR* GetADSR() { return (ADSR*)m_effects[0]; }
Filter* GetFilter() { return (Filter*)m_effects[1]; }
};

View File

@@ -18,7 +18,14 @@ struct ADSRGuiState {
float release;
};
struct FilterGuiState {
float freq;
float res;
//todo: type
};
struct SynthGuiState {
std::vector<OscillatorGuiState*> oscillators;
ADSRGuiState adsr;
FilterGuiState filter;
};

View File

@@ -1,4 +1,5 @@
#include "Filter.h"
#include "Settings.h"
Filter::Filter(/* args */) {
}
@@ -37,7 +38,7 @@ void Filter::Process(std::vector<float>& samples) {
}
void Filter::SetParameters(float freq, float res, float q) {
m_freq = freq;
m_freq = freq / SAMPLE_RATE;
m_q = res;
m_order = q;
}

View File

@@ -185,6 +185,57 @@ void Renderer::draw_adsr_panel(ADSR* adsr, ADSRGuiState& gui_adsr,
gui_adsr.release);
}
void Renderer::draw_second_panel(Rectangle& bounds) {
bounds.x += bounds.width;
GuiPanel(bounds, "");
}
float Renderer::draw_filter_panel(Filter* filter, FilterGuiState& gui_filter, const Rectangle& panel_bounds) {
float panel_y_offset = 0;
// Draw Filter Panel
const int osc_panel_width = panel_bounds.width - 20;
const int osc_panel_height = 120;
const int osc_panel_x = panel_bounds.x + 10;
const int osc_panel_y = panel_bounds.y + 50;
panel_y_offset += osc_panel_height + 5;
GuiPanel((Rectangle){(float)osc_panel_x, (float)osc_panel_y,
(float)osc_panel_width, (float)osc_panel_height},
"Filter");
const float slider_padding = 50.f;
const float el_spacing = 5.f;
Rectangle el_rect = {.x = (float)osc_panel_x + slider_padding + 30,
.y = (float)osc_panel_y + 10,
.width = (float)osc_panel_width - (slider_padding * 2),
.height = 25.f};
// Frequency slider
float freq = gui_filter.freq;
char freq_slider_label[32];
snprintf(freq_slider_label, 10, "%.1f hz", freq);
freq = GuiSlider(el_rect, freq_slider_label, "", freq, 0.0f, 16000.f);
gui_filter.freq = freq;
el_rect.y += el_rect.height + el_spacing;
// Resonance slider
float res = gui_filter.res;
char res_slider_label[32];
snprintf(res_slider_label, 7, "%.1f u", res);
res = GuiSlider(el_rect, res_slider_label, "", res, 0.0f, 1.0f);
gui_filter.res = res;
el_rect.y += el_rect.height + el_spacing;
// todo: filter type
// apply values to real one
// todo: thrid (order) parameter
// todo: why resonance changing does not work?
filter->SetParameters(gui_filter.freq, 0.707, 0);
return panel_y_offset;
}
void Renderer::draw_ui(Synth& synth, SynthGuiState& synth_gui) {
Rectangle panel_bounds = {.x = 0,
.y = 0,
@@ -200,4 +251,7 @@ void Renderer::draw_ui(Synth& synth, SynthGuiState& synth_gui) {
draw_adsr_panel(synth.GetADSR(), synth_gui.adsr, panel_bounds,
panel_y_offset);
draw_oscillators_shape_inputs(oscillators, gui_oscillators);
draw_second_panel(panel_bounds);
draw_filter_panel(synth.GetFilter(), synth_gui.filter, panel_bounds);
}

View File

@@ -1,5 +1,4 @@
#include "Synth.h"
#include "ADSR.h"
#include "KeyBoard.h"
#include "Logger.h"
#include "OscillatorType.h"