From ce3e89872e12cdd14257b5cb501faacb94ce26d7 Mon Sep 17 00:00:00 2001 From: Christian Colglazier Date: Thu, 20 Jan 2022 20:08:58 -0500 Subject: [PATCH] Graph titlebar for LFO --- src/droplets/ad_droplet.cpp | 8 +++---- src/droplets/lfo_droplet.cpp | 35 ++++++++++++++++++++++----- src/droplets/lfo_droplet.h | 46 ++++++++++++++++++++++++++++++++---- src/main.cpp | 4 ++-- 4 files changed, 77 insertions(+), 16 deletions(-) diff --git a/src/droplets/ad_droplet.cpp b/src/droplets/ad_droplet.cpp index 8861470..14c245b 100644 --- a/src/droplets/ad_droplet.cpp +++ b/src/droplets/ad_droplet.cpp @@ -117,15 +117,15 @@ ADDroplet::ADDroplet(DaisyPatch* m_patch, CreateTitleGraph(); } +ADDroplet::~ADDroplet() { + delete title_graph; +} + void ADDroplet::CreateTitleGraph() { title_graph = new Graph(GetScreenMax()-GetScreenMin(), GetTitleHeight()); } -ADDroplet::~ADDroplet() { - delete title_graph; -} - void ADDroplet::Control() { if (Patch()->encoder.Pressed()) { if (Patch()->encoder.TimeHeldMs() < 10) { diff --git a/src/droplets/lfo_droplet.cpp b/src/droplets/lfo_droplet.cpp index aa6ff8a..cb7bec2 100644 --- a/src/droplets/lfo_droplet.cpp +++ b/src/droplets/lfo_droplet.cpp @@ -16,10 +16,8 @@ void LFO::Process(DacHandle::Channel chn) { osc.SetFreq(freqCtrl.Process()); osc.SetWaveform(wave); - patch->seed.dac.WriteValue( - chn, - uint16_t((osc.Process() + 1.f) * - .5f * ampCtrl.Process() * 4095.f)); + patch->seed.dac.WriteValue(chn, + GetSignal() * ampCtrl.Process() * 4095.f); } void LFO::UpdateWave(int change) { @@ -30,11 +28,18 @@ uint8_t LFO::GetWave() { return wave; } +float LFO::GetSignal() { + return (osc.Process()+ 1.0f) /2; +} + LFODroplet::LFODroplet(DaisyPatch* m_patch, DropletState m_state, float sample_rate) : Droplet(m_patch, m_state) { + SetAnimationRate(5); + CreateTitleGraph(); + switch (GetState()) { default: case DropletState::kFull: @@ -62,7 +67,14 @@ LFODroplet::LFODroplet(DaisyPatch* m_patch, } } -LFODroplet::~LFODroplet() {} +LFODroplet::~LFODroplet() { + delete title_graph; +} + +void LFODroplet::CreateTitleGraph() { + title_graph = new Graph(GetScreenMax()-GetScreenMin(), + GetTitleHeight()); +} void LFODroplet::Control() { Patch()->ProcessAnalogControls(); @@ -104,7 +116,18 @@ void LFODroplet::Draw() { Font_6x8, WaveToString(lfo[0].GetWave())); } + + if(NeedUpdate()) { + title_graph->Update(); + } + title_graph->SetPixelPercentage(lfo[0].GetSignal()); + title_graph->Draw(Patch(), GetScreenMin(), 0); + DrawName("LFO"); + AnimationInc(); } -void LFODroplet::UpdateStateCallback() {} +void LFODroplet::UpdateStateCallback() { + delete title_graph; + CreateTitleGraph(); +} diff --git a/src/droplets/lfo_droplet.h b/src/droplets/lfo_droplet.h index d5a15a6..15fa029 100644 --- a/src/droplets/lfo_droplet.h +++ b/src/droplets/lfo_droplet.h @@ -8,6 +8,7 @@ #include "droplet.h" #include "../util.h" +#include "../graphics/graph.h" using namespace daisy; using namespace daisysp; @@ -25,21 +26,57 @@ private: float value; DaisyPatch* patch; public: + /* + * Constructor for a LFO. + * + * @param m_patch pointer to patch + * @param sample_rate audio sample rate + * @param freqKnob frequence knob + * @param ampKnob amp knob + */ void Init(DaisyPatch* m_patch, - float samplerate, + float sample_rate, AnalogControl freqKnob, AnalogControl ampKnob); + /* + * Send LFO signal to the given channel. + * + * @param chn output channel + */ void Process(DacHandle::Channel chn); + /* + * Shift the wavestate. + * + * @param change amount to shift the waveshape + */ void UpdateWave(int change); - + + /* + * Returns the current waveshape of the LFO. + * + * @return lfo waveshape + */ uint8_t GetWave(); + + /* + * Returns LFO signal from 0,0 to 1.0. + * + * @return LFO signal + */ + float GetSignal(); }; class LFODroplet: public Droplet { private: - LFO lfo[2]; + LFO lfo[2]; + Graph* title_graph; + + /* + * Create a new graph for the title bar. + */ + void CreateTitleGraph(); public: /* @@ -47,7 +84,8 @@ public: * * @param m_patch pointer to patch * @param m_state droplet position - */ + * @param sample_rate audio sample rate + */ LFODroplet(DaisyPatch* m_patch, DropletState m_state, float sample_rate); diff --git a/src/main.cpp b/src/main.cpp index b838207..ed560e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -114,11 +114,11 @@ static void AudioThrough(AudioHandle::InputBuffer in, Droplet* GetDroplet(DropletState state) { switch(selected_menu->GetState()) { - default: - case MenuState::kAD: + case MenuState::kAD: return new ADDroplet(&patch, state, sample_rate); + default: case MenuState::kLFO: return new LFODroplet(&patch, state,