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();
}
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) {

View File

@ -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();
}

View File

@ -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,6 +84,7 @@ 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,

View File

@ -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,