diff --git a/src/droplets/ad_droplet.cpp b/src/droplets/ad_droplet.cpp index 9b5d6f9..94538d7 100644 --- a/src/droplets/ad_droplet.cpp +++ b/src/droplets/ad_droplet.cpp @@ -219,3 +219,5 @@ void ADDroplet::UpdateStateCallback() { delete title_graph; CreateTitleGraph(); } + +void ADDroplet::SetControls() {} diff --git a/src/droplets/ad_droplet.h b/src/droplets/ad_droplet.h index 0bf7d96..77785d8 100644 --- a/src/droplets/ad_droplet.h +++ b/src/droplets/ad_droplet.h @@ -155,6 +155,11 @@ public: * Runs when droplet state is updated. */ void UpdateStateCallback(); + + /* + * Set up the controls for the droplet. + */ + void SetControls(); }; #endif // DROPLETS_AD_DROPLET_H_ diff --git a/src/droplets/droplet.cpp b/src/droplets/droplet.cpp index 7ef2f31..18e5d6f 100644 --- a/src/droplets/droplet.cpp +++ b/src/droplets/droplet.cpp @@ -55,6 +55,7 @@ void Droplet::UpdateState(DropletState m_state) { chn_min = 2; screen_min = SSD1309_WIDTH / 2; } + SetControls(); UpdateStateCallback(); } diff --git a/src/droplets/droplet.h b/src/droplets/droplet.h index c74bfb2..0e53e25 100644 --- a/src/droplets/droplet.h +++ b/src/droplets/droplet.h @@ -66,6 +66,11 @@ public: */ virtual void UpdateStateCallback() {} + /* + * Set up the controls for the droplet. + */ + virtual void SetControls() {} + /* * Returns patch. * diff --git a/src/droplets/ladder_filter_droplet.cpp b/src/droplets/ladder_filter_droplet.cpp new file mode 100644 index 0000000..8eed93c --- /dev/null +++ b/src/droplets/ladder_filter_droplet.cpp @@ -0,0 +1,47 @@ +#include "ladder_filter_droplet.h" + +LadderFilterDroplet::LadderFilterDroplet(DaisyPatch* m_patch, + DropletState m_state, + float sample_rate) : + Droplet(m_patch, + m_state) { + filter.Init(sample_rate); + + SetControls(); +} + +void LadderFilterDroplet::Control() {} + +void LadderFilterDroplet::Process(AudioHandle::InputBuffer in, + AudioHandle::OutputBuffer out, + size_t size) { + freq = freq_ctrl.Process(); + res = res_ctrl.Process(); + filter.SetFreq(freq); + filter.SetRes(res); + for (size_t i = 0; i < size; i++) { + for (size_t chn = GetChannelMin(); chn < GetChannelMax(); chn++) { + out[chn][i] = filter.Process(in[chn][i]); + } + } +} + +void LadderFilterDroplet::Draw() { + DrawName("Ladder"); +} + +void LadderFilterDroplet::UpdateStateCallback() {} + +void LadderFilterDroplet::SetControls() { + if (GetState() == DropletState::kRight) { + freq_ctrl.Init(Patch()->controls[Patch()->CTRL_3], + 0.0, 10000.0f, Parameter::LINEAR); + res_ctrl.Init(Patch()->controls[Patch()->CTRL_4], + 0.0, 0.75f, Parameter::LINEAR); + } else { + freq_ctrl.Init(Patch()->controls[Patch()->CTRL_1], + 0.0, 10000.0f, Parameter::LINEAR); + res_ctrl.Init(Patch()->controls[Patch()->CTRL_2], + 0.0, 0.75f, Parameter::LINEAR); + } +} diff --git a/src/droplets/ladder_filter_droplet.h b/src/droplets/ladder_filter_droplet.h new file mode 100644 index 0000000..03f5b61 --- /dev/null +++ b/src/droplets/ladder_filter_droplet.h @@ -0,0 +1,61 @@ +#pragma once + +#ifndef DROPLETS_LADDER_FILTER_DROPLET_H_ +#define DROPLETS_LADDER_FILTER_DROPLET_H_ + +#include "daisysp.h" +#include "daisy_patch.h" + +#include "droplet.h" +#include "../util.h" + +class LadderFilterDroplet: public Droplet { +private: + MoogLadder filter; + Parameter freq_ctrl, res_ctrl; + float freq, res; +public: + /* + * Constructor for a droplet. + * + * @param m_patch pointer to patch + * @param m_state droplet position + * @param sample_rate audio sample rate + */ + LadderFilterDroplet(DaisyPatch* m_patch, + DropletState m_state, + float sample_rate); + + /* + * Processes user controls and inputs. + */ + void Control(); + + /* + * Processes audio input and outputs. + * + * @param in the audio inputs for the patch + * @param out the audio outputs for the patch + * @param size the number of inputs and outputs + */ + void Process(AudioHandle::InputBuffer in, + AudioHandle::OutputBuffer out, + size_t size); + + /* + * Processes information to be shown on the display. + */ + void Draw(); + + /* + * Runs when droplet state is updated. + */ + void UpdateStateCallback(); + + /* + * Set up the controls for the droplet. + */ + void SetControls(); +}; + +#endif // DROPLETS_LADDER_FILTER_DROPLET_H_ diff --git a/src/droplets/lfo_droplet.cpp b/src/droplets/lfo_droplet.cpp index 586c16b..ee9c995 100644 --- a/src/droplets/lfo_droplet.cpp +++ b/src/droplets/lfo_droplet.cpp @@ -108,7 +108,6 @@ void LFODroplet::Draw() { void LFODroplet::UpdateStateCallback() { delete title_graph; CreateTitleGraph(); - SetControls(); } void LFODroplet::SetControls() { diff --git a/src/droplets/noise_droplet.cpp b/src/droplets/noise_droplet.cpp index c0b64b6..4b54af5 100644 --- a/src/droplets/noise_droplet.cpp +++ b/src/droplets/noise_droplet.cpp @@ -28,3 +28,5 @@ void NoiseDroplet::Draw() { } void NoiseDroplet::UpdateStateCallback() {} + +void NoiseDroplet::SetControls() {} diff --git a/src/droplets/noise_droplet.h b/src/droplets/noise_droplet.h index 6d8fb9c..133e34d 100644 --- a/src/droplets/noise_droplet.h +++ b/src/droplets/noise_droplet.h @@ -46,6 +46,11 @@ public: * Runs when droplet state is updated. */ void UpdateStateCallback(); + + /* + * Set up the controls for the droplet. + */ + void SetControls(); }; #endif // DROPLETS_NOISE_DROPLET_H_ diff --git a/src/droplets/template_droplet.cpp b/src/droplets/template_droplet.cpp index 489de46..ae5b435 100644 --- a/src/droplets/template_droplet.cpp +++ b/src/droplets/template_droplet.cpp @@ -1,7 +1,8 @@ #include "template_droplet.h" TemplateDroplet::TemplateDroplet(DaisyPatch* m_patch, - DropletState m_state) : + DropletState m_state, + float sample_rate) : Droplet(m_patch, m_state) { } @@ -9,8 +10,8 @@ TemplateDroplet::TemplateDroplet(DaisyPatch* m_patch, void TemplateDroplet::Control() {} void TemplateDroplet::Process(AudioHandle::InputBuffer in, - AudioHandle::OutputBuffer out, - size_t size) { + AudioHandle::OutputBuffer out, + size_t size) { } void TemplateDroplet::Draw() { diff --git a/src/droplets/template_droplet.h b/src/droplets/template_droplet.h index 8c608d0..a325b0d 100644 --- a/src/droplets/template_droplet.h +++ b/src/droplets/template_droplet.h @@ -17,8 +17,11 @@ public: * * @param m_patch pointer to patch * @param m_state droplet position + * @param sample_rate audio sample rate */ - TemplateDroplet(DaisyPatch*, DropletState); + TemplateDroplet(DaisyPatch* m_patch, + DropletState m_state, + float sample_rate); /* * Processes user controls and inputs. @@ -45,6 +48,11 @@ public: * Runs when droplet state is updated. */ void UpdateStateCallback(); + + /* + * Set up the controls for the droplet. + */ + void SetControls(); }; #endif // DROPLETS_TEMPLATE_DROPLET_H_ diff --git a/src/main.cpp b/src/main.cpp index a7d7c89..43bbc99 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -134,6 +134,10 @@ Droplet* GetDroplet(DropletState state, return new ADDroplet(&patch, state, sample_rate); + case MenuState::kLadderFilter: + return new LadderFilterDroplet(&patch, + state, + sample_rate); case MenuState::kLFO: return new LFODroplet(&patch, state, diff --git a/src/main.h b/src/main.h index 180ab8a..92847fb 100644 --- a/src/main.h +++ b/src/main.h @@ -13,6 +13,7 @@ #include "droplets/droplet.h" #include "droplets/droplet_manager.h" #include "droplets/ad_droplet.h" +#include "droplets/ladder_filter_droplet.h" #include "droplets/lfo_droplet.h" #include "droplets/mixer_droplet.h" #include "droplets/noise_droplet.h" diff --git a/src/menu.cpp b/src/menu.cpp index a205a16..885624e 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -10,6 +10,7 @@ Menu::Menu(DaisyPatch* m_patch, head = new MenuItem(MenuState::kSplit, "Split"); head->AddItemEnd(new MenuItem(MenuState::kChange, "")); head->AddItemEnd(new MenuItem(MenuState::kAD, "AD")); + head->AddItemEnd(new MenuItem(MenuState::kLadderFilter, "Ladder Filter")); head->AddItemEnd(new MenuItem(MenuState::kLFO, "LFO")); head->AddItemEnd(new MenuItem(MenuState::kMixer, "Mixer")); head->AddItemEnd(new MenuItem(MenuState::kNoise, "Noise")); diff --git a/src/menu_item.h b/src/menu_item.h index 5204ae5..761b1bf 100644 --- a/src/menu_item.h +++ b/src/menu_item.h @@ -5,7 +5,8 @@ #include -enum class MenuState {kSplit, kChange, kAD, kLFO, kMixer, kNoise, kVCA, kVCO}; +enum class MenuState {kSplit, kChange, kAD, kLadderFilter, + kLFO, kMixer, kNoise, kVCA, kVCO}; class MenuItem { private: