feat: filter type input
This commit is contained in:
@@ -10,4 +10,5 @@ class BandPassFilter : public Filter {
|
|||||||
BandPassFilter(float freq, float res, float q);
|
BandPassFilter(float freq, float res, float q);
|
||||||
BandPassFilter(/* args */);
|
BandPassFilter(/* args */);
|
||||||
~BandPassFilter();
|
~BandPassFilter();
|
||||||
|
bool IsSameFilterType(FilterType type) override { return type == BandPass; };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Effect.h"
|
#include "Effect.h"
|
||||||
|
|
||||||
|
enum FilterType {
|
||||||
|
LowPass,
|
||||||
|
BandPass,
|
||||||
|
HighPass
|
||||||
|
};
|
||||||
|
|
||||||
class Filter : public Effect {
|
class Filter : public Effect {
|
||||||
protected:
|
protected:
|
||||||
float m_freq; // cutoff frequency
|
float m_freq; // cutoff frequency
|
||||||
@@ -16,7 +22,7 @@ class Filter : public Effect {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Filter(/* args */);
|
Filter(/* args */);
|
||||||
~Filter();
|
virtual ~Filter();
|
||||||
void Trigger() override;
|
void Trigger() override;
|
||||||
void Release() override;
|
void Release() override;
|
||||||
float Process(float in);
|
float Process(float in);
|
||||||
@@ -25,4 +31,5 @@ class Filter : public Effect {
|
|||||||
float GetFreq() { return m_freq; }
|
float GetFreq() { return m_freq; }
|
||||||
float GetRes() { return m_q; }
|
float GetRes() { return m_q; }
|
||||||
float GetPeakGain() { return m_norm; }
|
float GetPeakGain() { return m_norm; }
|
||||||
|
virtual bool IsSameFilterType(FilterType type){ return false; };
|
||||||
};
|
};
|
||||||
|
|||||||
25
inc/FilterFactory.h
Normal file
25
inc/FilterFactory.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Filter.h"
|
||||||
|
#include "LowPassFilter.h"
|
||||||
|
#include "BandPassFilter.h"
|
||||||
|
#include "HighPassFilter.h"
|
||||||
|
|
||||||
|
struct FilterFactory {
|
||||||
|
static Filter* CreateFilter(Filter* oldFilter, FilterType newType) {
|
||||||
|
Filter* newFilter;
|
||||||
|
switch (newType) {
|
||||||
|
case LowPass:
|
||||||
|
newFilter = new LowPassFilter(oldFilter);
|
||||||
|
break;
|
||||||
|
case BandPass:
|
||||||
|
newFilter = new BandPassFilter(oldFilter);
|
||||||
|
break;
|
||||||
|
case HighPass:
|
||||||
|
newFilter = new HighPassFilter(oldFilter);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return newFilter;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -10,4 +10,5 @@ class HighPassFilter : public Filter {
|
|||||||
HighPassFilter(Filter* filter);
|
HighPassFilter(Filter* filter);
|
||||||
HighPassFilter(float freq, float res, float q);
|
HighPassFilter(float freq, float res, float q);
|
||||||
~HighPassFilter();
|
~HighPassFilter();
|
||||||
|
bool IsSameFilterType(FilterType type) override { return type == HighPass; };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,4 +11,5 @@ class LowPassFilter : public Filter {
|
|||||||
LowPassFilter(Filter* filter);
|
LowPassFilter(Filter* filter);
|
||||||
LowPassFilter(float freq, float res, float q);
|
LowPassFilter(float freq, float res, float q);
|
||||||
~LowPassFilter();
|
~LowPassFilter();
|
||||||
|
bool IsSameFilterType(FilterType type) override { return type == LowPass; };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Renderer {
|
|||||||
void draw_adsr_panel(ADSR* adsr, ADSRGuiState& gui_adsr,
|
void draw_adsr_panel(ADSR* adsr, ADSRGuiState& gui_adsr,
|
||||||
const Rectangle& panel_bounds, float panel_y_offset);
|
const Rectangle& panel_bounds, float panel_y_offset);
|
||||||
void draw_second_panel(Rectangle& bounds);
|
void draw_second_panel(Rectangle& bounds);
|
||||||
float draw_filter_panel(Filter* filter, FilterGuiState& gui_filter,
|
float draw_filter_panel(Synth& synth, FilterGuiState& gui_filter,
|
||||||
const Rectangle& panel_bounds);
|
const Rectangle& panel_bounds);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -35,4 +35,5 @@ class Synth {
|
|||||||
const bool& GetIsNoteTriggered() { return is_note_triggered; }
|
const bool& GetIsNoteTriggered() { return is_note_triggered; }
|
||||||
ADSR* GetADSR() { return (ADSR*)m_effects[0]; }
|
ADSR* GetADSR() { return (ADSR*)m_effects[0]; }
|
||||||
Filter* GetFilter() { return (Filter*)m_effects[1]; }
|
Filter* GetFilter() { return (Filter*)m_effects[1]; }
|
||||||
|
void SetFilter(FilterType type);
|
||||||
};
|
};
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "OscillatorType.h"
|
#include "OscillatorType.h"
|
||||||
#include "raygui.h"
|
#include "raygui.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "Filter.h"
|
||||||
|
|
||||||
struct OscillatorGuiState {
|
struct OscillatorGuiState {
|
||||||
float volume;
|
float volume;
|
||||||
@@ -20,8 +21,9 @@ struct ADSRGuiState {
|
|||||||
|
|
||||||
struct FilterGuiState {
|
struct FilterGuiState {
|
||||||
float freq;
|
float freq;
|
||||||
float res;
|
float res; //todo: res
|
||||||
//todo: type
|
FilterType type;
|
||||||
|
bool is_dropdown_open;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SynthGuiState {
|
struct SynthGuiState {
|
||||||
|
|||||||
@@ -190,8 +190,10 @@ void Renderer::draw_second_panel(Rectangle& bounds) {
|
|||||||
GuiPanel(bounds, "");
|
GuiPanel(bounds, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
float Renderer::draw_filter_panel(Filter* filter, FilterGuiState& gui_filter,
|
float Renderer::draw_filter_panel(Synth& synth, FilterGuiState& gui_filter,
|
||||||
const Rectangle& panel_bounds) {
|
const Rectangle& panel_bounds) {
|
||||||
|
#define FILTER_TYPE_OPTIONS "LP;BP;HP"
|
||||||
|
Filter* filter = synth.GetFilter();
|
||||||
float panel_y_offset = 0;
|
float panel_y_offset = 0;
|
||||||
|
|
||||||
// Draw Filter Panel
|
// Draw Filter Panel
|
||||||
@@ -228,6 +230,24 @@ float Renderer::draw_filter_panel(Filter* filter, FilterGuiState& gui_filter,
|
|||||||
el_rect.y += el_rect.height + el_spacing;
|
el_rect.y += el_rect.height + el_spacing;
|
||||||
|
|
||||||
// todo: filter type
|
// todo: filter type
|
||||||
|
// Shape select
|
||||||
|
int shape_index = (int)(gui_filter.type);
|
||||||
|
bool is_dropdown_click =
|
||||||
|
GuiDropdownBox(el_rect, FILTER_TYPE_OPTIONS,
|
||||||
|
&shape_index, gui_filter.is_dropdown_open);
|
||||||
|
|
||||||
|
if (is_dropdown_click) {
|
||||||
|
write_log("Dropdown clicked!\n");
|
||||||
|
gui_filter.is_dropdown_open = !gui_filter.is_dropdown_open;
|
||||||
|
gui_filter.type = (FilterType)(shape_index);
|
||||||
|
// APPLY STATE TO REAL SYNTH
|
||||||
|
if (!filter->IsSameFilterType(gui_filter.type)) {
|
||||||
|
synth.SetFilter(gui_filter.type);
|
||||||
|
}
|
||||||
|
//filter.SetType(ui_osc->waveshape);
|
||||||
|
}
|
||||||
|
// if (gui_filter.is_dropdown_open)
|
||||||
|
// break;
|
||||||
|
|
||||||
// apply values to real one
|
// apply values to real one
|
||||||
// todo: thrid (order) parameter
|
// todo: thrid (order) parameter
|
||||||
@@ -254,5 +274,5 @@ void Renderer::draw_ui(Synth& synth, SynthGuiState& synth_gui) {
|
|||||||
draw_oscillators_shape_inputs(oscillators, gui_oscillators);
|
draw_oscillators_shape_inputs(oscillators, gui_oscillators);
|
||||||
|
|
||||||
draw_second_panel(panel_bounds);
|
draw_second_panel(panel_bounds);
|
||||||
draw_filter_panel(synth.GetFilter(), synth_gui.filter, panel_bounds);
|
draw_filter_panel(synth, synth_gui.filter, panel_bounds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "OscillatorType.h"
|
#include "OscillatorType.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "LowPassFilter.h"
|
#include "LowPassFilter.h"
|
||||||
|
#include "FilterFactory.h"
|
||||||
|
|
||||||
Synth::Synth(/* args */) {
|
Synth::Synth(/* args */) {
|
||||||
m_lfo = new Oscillator(OscillatorType::Sine, 5.f, VOLUME);
|
m_lfo = new Oscillator(OscillatorType::Sine, 5.f, VOLUME);
|
||||||
@@ -70,6 +71,7 @@ void Synth::Trigger(Note input) {
|
|||||||
trigger_note_on_effects();
|
trigger_note_on_effects();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: fix this
|
||||||
void Synth::apply_filter_lfo() {
|
void Synth::apply_filter_lfo() {
|
||||||
float dt = m_lfo->Process();
|
float dt = m_lfo->Process();
|
||||||
Filter* filter = (Filter*)m_effects[1];
|
Filter* filter = (Filter*)m_effects[1];
|
||||||
@@ -93,3 +95,10 @@ void Synth::Release() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Synth::AddEffect(Effect* fx) { m_effects.push_back(fx); }
|
void Synth::AddEffect(Effect* fx) { m_effects.push_back(fx); }
|
||||||
|
|
||||||
|
void Synth::SetFilter(FilterType type) {
|
||||||
|
Filter* oldFilter = this->GetFilter();
|
||||||
|
Filter* newFilter = FilterFactory::CreateFilter(oldFilter, type);
|
||||||
|
delete oldFilter;
|
||||||
|
m_effects[1] = newFilter;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user