mirror of
				https://github.com/AquaMorph/Droplets.git
				synced 2025-10-30 16:13:20 +00:00 
			
		
		
		
	Basic title animtion for VCO
This commit is contained in:
		| @@ -22,3 +22,15 @@ void Droplet::UpdateState(DropletState m_state) { | |||||||
|     screen_min = SSD1309_WIDTH / 2; |     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; | ||||||
|  | } | ||||||
|   | |||||||
| @@ -14,6 +14,9 @@ using namespace daisy; | |||||||
| enum class DropletState {kFull, kLeft, kRight}; | enum class DropletState {kFull, kLeft, kRight}; | ||||||
|  |  | ||||||
| class Droplet { | class Droplet { | ||||||
|  | private: | ||||||
|  |   unsigned int count = 0; | ||||||
|  |   unsigned int animation_rate = 1; | ||||||
| public: | public: | ||||||
|   DaisyPatch* patch; |   DaisyPatch* patch; | ||||||
|   DropletState state; |   DropletState state; | ||||||
| @@ -22,7 +25,7 @@ public: | |||||||
|   virtual void Control()=0; |   virtual void Control()=0; | ||||||
|   virtual void Process(float**, float**, size_t)=0; |   virtual void Process(float**, float**, size_t)=0; | ||||||
|   virtual void Draw()=0; |   virtual void Draw()=0; | ||||||
|   const int kTitleHeight = 8; |   const int kTitleHeight = 7; | ||||||
|   int screen_min; |   int screen_min; | ||||||
|   int screen_max; |   int screen_max; | ||||||
|   size_t chn_min = 0; |   size_t chn_min = 0; | ||||||
| @@ -30,6 +33,9 @@ public: | |||||||
|   void DrawName(daisy::DaisyPatch*, |   void DrawName(daisy::DaisyPatch*, | ||||||
| 		std::string); | 		std::string); | ||||||
|   void UpdateState(DropletState); |   void UpdateState(DropletState); | ||||||
|  |   unsigned int animation_count = 0; | ||||||
|  |   void AnimationInc(); | ||||||
|  |   void SetAnimationRate(int); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #endif // CASCADE_DROPLETS_DROPLET_H_ | #endif // CASCADE_DROPLETS_DROPLET_H_ | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ VCODroplet::VCODroplet(DaisyPatch* m_patch, | |||||||
|   Droplet(m_patch, |   Droplet(m_patch, | ||||||
| 	  m_state){ | 	  m_state){ | ||||||
|   int num_waves = Oscillator::WAVE_LAST; |   int num_waves = Oscillator::WAVE_LAST; | ||||||
|  |   SetAnimationRate(10); | ||||||
|   osc.Init(sample_rate); |   osc.Init(sample_rate); | ||||||
|   freqctrl.Init(patch->controls[patch->CTRL_1], 10.0, |   freqctrl.Init(patch->controls[patch->CTRL_1], 10.0, | ||||||
| 		110.0f, Parameter::LINEAR); | 		110.0f, Parameter::LINEAR); | ||||||
| @@ -45,9 +46,31 @@ void VCODroplet::Process(float** in, float** out, size_t size) { | |||||||
| } | } | ||||||
|  |  | ||||||
| void VCODroplet::Draw() { | 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, |   WriteString(*patch, 0, 54, Font_6x8, | ||||||
| 	      WaveToString(wavectrl.Process())); | 	      WaveToString(wavectrl.Process())); | ||||||
|  |   DrawName(patch, "VCO"); | ||||||
|  |   AnimationInc(); | ||||||
| } | } | ||||||
|  |  | ||||||
| std::string VCODroplet::WaveToString(uint8_t wf) { | std::string VCODroplet::WaveToString(uint8_t wf) { | ||||||
|   | |||||||
| @@ -3,6 +3,8 @@ | |||||||
| #ifndef CASCADE_DROPLETS_VCO_DROPLET_H_ | #ifndef CASCADE_DROPLETS_VCO_DROPLET_H_ | ||||||
| #define CASCADE_DROPLETS_VCO_DROPLET_H_ | #define CASCADE_DROPLETS_VCO_DROPLET_H_ | ||||||
|  |  | ||||||
|  | #include <cmath> | ||||||
|  |  | ||||||
| #include "daisysp.h" | #include "daisysp.h" | ||||||
| #include "daisy_patch.h" | #include "daisy_patch.h" | ||||||
|  |  | ||||||
| @@ -17,6 +19,7 @@ private: | |||||||
|   Oscillator osc; |   Oscillator osc; | ||||||
|   Parameter freqctrl, wavectrl, ampctrl, finectrl; |   Parameter freqctrl, wavectrl, ampctrl, finectrl; | ||||||
|   std::string WaveToString(uint8_t); |   std::string WaveToString(uint8_t); | ||||||
|  |   const double pi = std::acos(-1); | ||||||
| public: | public: | ||||||
|   VCODroplet(DaisyPatch*, DropletState, float); |   VCODroplet(DaisyPatch*, DropletState, float); | ||||||
|   void Control(); |   void Control(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user