Graph titlebar for LFO

This commit is contained in:
Christian Colglazier 2022-01-20 20:08:58 -05:00
parent b15720944c
commit ce3e89872e
4 changed files with 77 additions and 16 deletions

View File

@ -117,15 +117,15 @@ ADDroplet::ADDroplet(DaisyPatch* m_patch,
CreateTitleGraph(); CreateTitleGraph();
} }
ADDroplet::~ADDroplet() {
delete title_graph;
}
void ADDroplet::CreateTitleGraph() { void ADDroplet::CreateTitleGraph() {
title_graph = new Graph(GetScreenMax()-GetScreenMin(), title_graph = new Graph(GetScreenMax()-GetScreenMin(),
GetTitleHeight()); GetTitleHeight());
} }
ADDroplet::~ADDroplet() {
delete title_graph;
}
void ADDroplet::Control() { void ADDroplet::Control() {
if (Patch()->encoder.Pressed()) { if (Patch()->encoder.Pressed()) {
if (Patch()->encoder.TimeHeldMs() < 10) { if (Patch()->encoder.TimeHeldMs() < 10) {

View File

@ -16,10 +16,8 @@ void LFO::Process(DacHandle::Channel chn) {
osc.SetFreq(freqCtrl.Process()); osc.SetFreq(freqCtrl.Process());
osc.SetWaveform(wave); osc.SetWaveform(wave);
patch->seed.dac.WriteValue( patch->seed.dac.WriteValue(chn,
chn, GetSignal() * ampCtrl.Process() * 4095.f);
uint16_t((osc.Process() + 1.f) *
.5f * ampCtrl.Process() * 4095.f));
} }
void LFO::UpdateWave(int change) { void LFO::UpdateWave(int change) {
@ -30,11 +28,18 @@ uint8_t LFO::GetWave() {
return wave; return wave;
} }
float LFO::GetSignal() {
return (osc.Process()+ 1.0f) /2;
}
LFODroplet::LFODroplet(DaisyPatch* m_patch, LFODroplet::LFODroplet(DaisyPatch* m_patch,
DropletState m_state, DropletState m_state,
float sample_rate) : float sample_rate) :
Droplet(m_patch, Droplet(m_patch,
m_state) { m_state) {
SetAnimationRate(5);
CreateTitleGraph();
switch (GetState()) { switch (GetState()) {
default: default:
case DropletState::kFull: 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() { void LFODroplet::Control() {
Patch()->ProcessAnalogControls(); Patch()->ProcessAnalogControls();
@ -104,7 +116,18 @@ void LFODroplet::Draw() {
Font_6x8, Font_6x8,
WaveToString(lfo[0].GetWave())); WaveToString(lfo[0].GetWave()));
} }
if(NeedUpdate()) {
title_graph->Update();
}
title_graph->SetPixelPercentage(lfo[0].GetSignal());
title_graph->Draw(Patch(), GetScreenMin(), 0);
DrawName("LFO"); DrawName("LFO");
AnimationInc();
} }
void LFODroplet::UpdateStateCallback() {} void LFODroplet::UpdateStateCallback() {
delete title_graph;
CreateTitleGraph();
}

View File

@ -8,6 +8,7 @@
#include "droplet.h" #include "droplet.h"
#include "../util.h" #include "../util.h"
#include "../graphics/graph.h"
using namespace daisy; using namespace daisy;
using namespace daisysp; using namespace daisysp;
@ -25,21 +26,57 @@ private:
float value; float value;
DaisyPatch* patch; DaisyPatch* patch;
public: 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, void Init(DaisyPatch* m_patch,
float samplerate, float sample_rate,
AnalogControl freqKnob, AnalogControl freqKnob,
AnalogControl ampKnob); AnalogControl ampKnob);
/*
* Send LFO signal to the given channel.
*
* @param chn output channel
*/
void Process(DacHandle::Channel chn); void Process(DacHandle::Channel chn);
/*
* Shift the wavestate.
*
* @param change amount to shift the waveshape
*/
void UpdateWave(int change); void UpdateWave(int change);
/*
* Returns the current waveshape of the LFO.
*
* @return lfo waveshape
*/
uint8_t GetWave(); uint8_t GetWave();
/*
* Returns LFO signal from 0,0 to 1.0.
*
* @return LFO signal
*/
float GetSignal();
}; };
class LFODroplet: public Droplet { class LFODroplet: public Droplet {
private: private:
LFO lfo[2]; LFO lfo[2];
Graph* title_graph;
/*
* Create a new graph for the title bar.
*/
void CreateTitleGraph();
public: public:
/* /*
@ -47,7 +84,8 @@ public:
* *
* @param m_patch pointer to patch * @param m_patch pointer to patch
* @param m_state droplet position * @param m_state droplet position
*/ * @param sample_rate audio sample rate
*/
LFODroplet(DaisyPatch* m_patch, LFODroplet(DaisyPatch* m_patch,
DropletState m_state, DropletState m_state,
float sample_rate); float sample_rate);

View File

@ -114,11 +114,11 @@ static void AudioThrough(AudioHandle::InputBuffer in,
Droplet* GetDroplet(DropletState state) { Droplet* GetDroplet(DropletState state) {
switch(selected_menu->GetState()) { switch(selected_menu->GetState()) {
default: case MenuState::kAD:
case MenuState::kAD:
return new ADDroplet(&patch, return new ADDroplet(&patch,
state, state,
sample_rate); sample_rate);
default:
case MenuState::kLFO: case MenuState::kLFO:
return new LFODroplet(&patch, return new LFODroplet(&patch,
state, state,