feat: filter type input

This commit is contained in:
2023-09-10 01:02:22 +04:00
parent 576cf8e3b5
commit de37b814bf
10 changed files with 73 additions and 6 deletions

View File

@@ -10,4 +10,5 @@ class BandPassFilter : public Filter {
BandPassFilter(float freq, float res, float q);
BandPassFilter(/* args */);
~BandPassFilter();
bool IsSameFilterType(FilterType type) override { return type == BandPass; };
};

View File

@@ -1,6 +1,12 @@
#pragma once
#include "Effect.h"
enum FilterType {
LowPass,
BandPass,
HighPass
};
class Filter : public Effect {
protected:
float m_freq; // cutoff frequency
@@ -16,7 +22,7 @@ class Filter : public Effect {
public:
Filter(/* args */);
~Filter();
virtual ~Filter();
void Trigger() override;
void Release() override;
float Process(float in);
@@ -25,4 +31,5 @@ class Filter : public Effect {
float GetFreq() { return m_freq; }
float GetRes() { return m_q; }
float GetPeakGain() { return m_norm; }
virtual bool IsSameFilterType(FilterType type){ return false; };
};

25
inc/FilterFactory.h Normal file
View 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;
}
};

View File

@@ -10,4 +10,5 @@ class HighPassFilter : public Filter {
HighPassFilter(Filter* filter);
HighPassFilter(float freq, float res, float q);
~HighPassFilter();
bool IsSameFilterType(FilterType type) override { return type == HighPass; };
};

View File

@@ -11,4 +11,5 @@ class LowPassFilter : public Filter {
LowPassFilter(Filter* filter);
LowPassFilter(float freq, float res, float q);
~LowPassFilter();
bool IsSameFilterType(FilterType type) override { return type == LowPass; };
};

View File

@@ -21,7 +21,7 @@ class Renderer {
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,
float draw_filter_panel(Synth& synth, FilterGuiState& gui_filter,
const Rectangle& panel_bounds);
public:

View File

@@ -35,4 +35,5 @@ class Synth {
const bool& GetIsNoteTriggered() { return is_note_triggered; }
ADSR* GetADSR() { return (ADSR*)m_effects[0]; }
Filter* GetFilter() { return (Filter*)m_effects[1]; }
void SetFilter(FilterType type);
};

View File

@@ -2,6 +2,7 @@
#include "OscillatorType.h"
#include "raygui.h"
#include <vector>
#include "Filter.h"
struct OscillatorGuiState {
float volume;
@@ -20,8 +21,9 @@ struct ADSRGuiState {
struct FilterGuiState {
float freq;
float res;
//todo: type
float res; //todo: res
FilterType type;
bool is_dropdown_open;
};
struct SynthGuiState {