Basic title animtion for VCO

This commit is contained in:
Christian Colglazier 2020-09-20 22:00:14 -04:00
parent b356fea100
commit b992bfbdaa
4 changed files with 46 additions and 2 deletions

View File

@ -22,3 +22,15 @@ void Droplet::UpdateState(DropletState m_state) {
screen_min = SSD1309_WIDTH / 2;
}
}
void Droplet::AnimationInc() {
if (count == animation_rate) {
animation_count++;
count = 0;
}
count++;
}
void Droplet::SetAnimationRate(int rate) {
animation_rate = rate;
}

View File

@ -14,6 +14,9 @@ using namespace daisy;
enum class DropletState {kFull, kLeft, kRight};
class Droplet {
private:
unsigned int count = 0;
unsigned int animation_rate = 1;
public:
DaisyPatch* patch;
DropletState state;
@ -22,7 +25,7 @@ public:
virtual void Control()=0;
virtual void Process(float**, float**, size_t)=0;
virtual void Draw()=0;
const int kTitleHeight = 8;
const int kTitleHeight = 7;
int screen_min;
int screen_max;
size_t chn_min = 0;
@ -30,6 +33,9 @@ public:
void DrawName(daisy::DaisyPatch*,
std::string);
void UpdateState(DropletState);
unsigned int animation_count = 0;
void AnimationInc();
void SetAnimationRate(int);
};
#endif // CASCADE_DROPLETS_DROPLET_H_

View File

@ -6,6 +6,7 @@ VCODroplet::VCODroplet(DaisyPatch* m_patch,
Droplet(m_patch,
m_state){
int num_waves = Oscillator::WAVE_LAST;
SetAnimationRate(10);
osc.Init(sample_rate);
freqctrl.Init(patch->controls[patch->CTRL_1], 10.0,
110.0f, Parameter::LINEAR);
@ -45,9 +46,31 @@ void VCODroplet::Process(float** in, float** out, size_t size) {
}
void VCODroplet::Draw() {
DrawName(patch, "VCO");
int sine_width = 20;
bool sine_wave[sine_width][Droplet::kTitleHeight];
// Set blank pattern
for (int h = 0; h < kTitleHeight; h++) {
for (int w = screen_min; w < screen_max; w++) {
sine_wave[w][h] = false;
}
}
for (int i = 0; i < sine_width; i++) {
int pixel = (int) round(std::sin(2*pi*((double)(i + animation_count%sine_width)/sine_width)) * (kTitleHeight/2) + kTitleHeight/2);
sine_wave[i][pixel] = true;
}
for (int h = 0; h < kTitleHeight; h++) {
for (int w = screen_min; w < screen_max; w++) {
patch->display.DrawPixel(w, h, sine_wave[w%sine_width][h%kTitleHeight]);
}
}
WriteString(*patch, 0, 54, Font_6x8,
WaveToString(wavectrl.Process()));
DrawName(patch, "VCO");
AnimationInc();
}
std::string VCODroplet::WaveToString(uint8_t wf) {

View File

@ -3,6 +3,8 @@
#ifndef CASCADE_DROPLETS_VCO_DROPLET_H_
#define CASCADE_DROPLETS_VCO_DROPLET_H_
#include <cmath>
#include "daisysp.h"
#include "daisy_patch.h"
@ -17,6 +19,7 @@ private:
Oscillator osc;
Parameter freqctrl, wavectrl, ampctrl, finectrl;
std::string WaveToString(uint8_t);
const double pi = std::acos(-1);
public:
VCODroplet(DaisyPatch*, DropletState, float);
void Control();