diff --git a/Makefile b/Makefile index 7ff305a..df277b5 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ CPP_SOURCES = src/main.cpp \ src/menu.cpp \ src/droplets/droplet.cpp \ src/droplets/noise_droplet.cpp \ - src/droplets/vco_droplet.cpp + src/droplets/vco_droplet.cpp \ + src/graphics/sprite.cpp LIBDAISY_DIR = ./lib/libDaisy DAISYSP_DIR = ./lib/daisySP diff --git a/src/droplets/droplet.cpp b/src/droplets/droplet.cpp index 85463a4..d0999e4 100644 --- a/src/droplets/droplet.cpp +++ b/src/droplets/droplet.cpp @@ -29,6 +29,9 @@ void Droplet::AnimationInc() { count = 0; } count++; + //animation_count = animation_count % animation_rate; + WriteCenteredString(*patch, (screen_min + screen_max) / 2, 40, + Font_6x8, std::to_string(animation_count)); } void Droplet::SetAnimationRate(int rate) { diff --git a/src/droplets/vco_droplet.cpp b/src/droplets/vco_droplet.cpp index f1e42c2..1c679f9 100644 --- a/src/droplets/vco_droplet.cpp +++ b/src/droplets/vco_droplet.cpp @@ -46,29 +46,15 @@ void VCODroplet::Process(float** in, float** out, size_t size) { } void VCODroplet::Draw() { - 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; - } - } - + wave->SetBlank(); 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]); - } + wave->SetPixel(i, pixel, true); } WriteString(*patch, 0, 54, Font_6x8, WaveToString(wavectrl.Process())); + wave->DrawTile(*patch, screen_min, 0, screen_max, kTitleHeight); DrawName(patch, "VCO"); AnimationInc(); } diff --git a/src/droplets/vco_droplet.h b/src/droplets/vco_droplet.h index 68f444a..7ed4b0d 100644 --- a/src/droplets/vco_droplet.h +++ b/src/droplets/vco_droplet.h @@ -10,6 +10,7 @@ #include "droplet.h" #include "../util.h" +#include "../graphics/sprite.h" using namespace daisy; using namespace daisysp; @@ -20,6 +21,8 @@ private: Parameter freqctrl, wavectrl, ampctrl, finectrl; std::string WaveToString(uint8_t); const double pi = std::acos(-1); + int sine_width = 20; + Sprite* wave = new Sprite(sine_width, kTitleHeight); public: VCODroplet(DaisyPatch*, DropletState, float); void Control(); diff --git a/src/graphics/sprite.cpp b/src/graphics/sprite.cpp new file mode 100644 index 0000000..d3c0470 --- /dev/null +++ b/src/graphics/sprite.cpp @@ -0,0 +1,64 @@ +#include "sprite.h" + +Sprite::Sprite(int m_width, int m_height) { + width = m_width; + height = m_height; + sprite = new bool*[width]; + for (int w = 0; w < width; w++) { + sprite[w] = new bool[height]; + for (int h = 0; h < height; h++) { + sprite[w][h] = false; + } + } +} + +void Sprite::SetPixel(int x, int y, bool solid) { + sprite[x][y] = solid; +} + +int Sprite::GetHeight() { + return height; +} + + +int Sprite::GetWidth() { + return width; + +} + +void Sprite::Draw(DaisyPatch patch, int x, int y) { + for (int w = 0; w < width; w++) { + for (int h = 0; h < height; h++) { + patch.display.DrawPixel(x+w, y+h, sprite[w][h]); + } + } +} + +void Sprite::DrawTile(DaisyPatch patch, + int x1, + int y1, + int x2, + int y2) { + int x_min = std::min(x1, x2); + int x_max = std::max(x1, x2); + int y_min = std::min(y1, y2); + int y_max = std::max(y1, y2); + for (int w = x_min; w < x_max; w++) { + for (int h = y_min; h < y_max; h++) { + patch.display.DrawPixel(w, h, sprite[(w-x_min) % width] + [(h-y_min) % height]); + } + } +} + +bool** Sprite::GetSprite() { + return sprite; +} + +void Sprite::SetBlank() { + for (int w = 0; w < width; w++) { + for (int h = 0; h < height; h++) { + sprite[w][h] = false; + } + } +} diff --git a/src/graphics/sprite.h b/src/graphics/sprite.h new file mode 100644 index 0000000..2b23ae7 --- /dev/null +++ b/src/graphics/sprite.h @@ -0,0 +1,25 @@ +#pragma once + +#ifndef CASCADE_GRAPHICS_SPRITE_H_ +#define CASCADE_GRAPHICS_SPRITE_H_ + +#include "daisy_patch.h" + +using namespace daisy; + +class Sprite { + private: + int width, height; + bool** sprite; + public: + Sprite(int, int); + void SetPixel(int, int, bool); + int GetHeight(); + int GetWidth(); + bool** GetSprite(); + void Draw(DaisyPatch, int, int); + void DrawTile(DaisyPatch, int, int, int, int); + void SetBlank(); +}; + +#endif // CASCADE_GRAPHICS_SPRITE_H_