diff --git a/src/droplets/droplet.cpp b/src/droplets/droplet.cpp index 71a562a..85463a4 100644 --- a/src/droplets/droplet.cpp +++ b/src/droplets/droplet.cpp @@ -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; +} diff --git a/src/droplets/droplet.h b/src/droplets/droplet.h index bce38b0..f0a4635 100644 --- a/src/droplets/droplet.h +++ b/src/droplets/droplet.h @@ -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_ diff --git a/src/droplets/vco_droplet.cpp b/src/droplets/vco_droplet.cpp index c8d143e..f1e42c2 100644 --- a/src/droplets/vco_droplet.cpp +++ b/src/droplets/vco_droplet.cpp @@ -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) { diff --git a/src/droplets/vco_droplet.h b/src/droplets/vco_droplet.h index 48ede1c..68f444a 100644 --- a/src/droplets/vco_droplet.h +++ b/src/droplets/vco_droplet.h @@ -3,6 +3,8 @@ #ifndef CASCADE_DROPLETS_VCO_DROPLET_H_ #define CASCADE_DROPLETS_VCO_DROPLET_H_ +#include + #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();