From b04fdf7f705d76405090a025c73774b4d50c0a49 Mon Sep 17 00:00:00 2001 From: Christian Colglazier Date: Sat, 26 Sep 2020 13:24:13 -0400 Subject: [PATCH] VCO title bar changes based on wave shape --- src/droplets/vco_droplet.cpp | 36 ++++++++++++++++++++++++++++++++++-- src/droplets/vco_droplet.h | 5 ++++- src/graphics/sprite.cpp | 10 ++++++---- src/graphics/wave.cpp | 21 +++++++++++++++++++-- src/graphics/wave.h | 1 + 5 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/droplets/vco_droplet.cpp b/src/droplets/vco_droplet.cpp index fa63d09..6f6c1a6 100644 --- a/src/droplets/vco_droplet.cpp +++ b/src/droplets/vco_droplet.cpp @@ -19,7 +19,7 @@ VCODroplet::VCODroplet(DaisyPatch* m_patch, } VCODroplet::~VCODroplet() { - delete wave; + // delete wave; } void VCODroplet::Control() {} @@ -51,10 +51,12 @@ void VCODroplet::Process(float** in, float** out, size_t size) { void VCODroplet::Draw() { WriteString(*Patch(), 0, 54, Font_6x8, WaveToString(wavectrl.Process())); + SetWaveState(wavectrl.Process()); wave->DrawTile(*Patch(), GetScreenMin(), 0, GetScreenMax(), GetTitleHeight()); if(NeedUpdate()) { - //wave->AdjustXShift(1); + wave->AdjustXShift(1); } + //testWave->DrawTile(*Patch(), 0, GetTitleHeight(), 60, GetTitleHeight()+testH); DrawName("VCO"); AnimationInc(); } @@ -80,3 +82,33 @@ std::string VCODroplet::WaveToString(uint8_t wf) { } return ""; } + +void VCODroplet::SetWaveState(uint8_t wf) { + switch(wf){ + case Oscillator::WAVE_TRI: + wave->SetWaveShape(WaveShape::kTriangle); + return; + case Oscillator::WAVE_SQUARE: + wave->SetWaveShape(WaveShape::kSquare); + return; + case Oscillator::WAVE_SIN: + wave->SetWaveShape(WaveShape::kSine); + return; + case Oscillator::WAVE_SAW: + wave->SetWaveShape(WaveShape::kSaw); + return; + case Oscillator::WAVE_RAMP: + wave->SetWaveShape(WaveShape::kRamp); + return; + case Oscillator::WAVE_POLYBLEP_TRI: + wave->SetWaveShape(WaveShape::kTriangle); + return; + case Oscillator::WAVE_POLYBLEP_SQUARE: + wave->SetWaveShape(WaveShape::kSquare); + return; + default: + case Oscillator::WAVE_POLYBLEP_SAW: + wave->SetWaveShape(WaveShape::kSaw); + return; + } +} diff --git a/src/droplets/vco_droplet.h b/src/droplets/vco_droplet.h index 41b77fe..5bf5082 100644 --- a/src/droplets/vco_droplet.h +++ b/src/droplets/vco_droplet.h @@ -20,9 +20,12 @@ private: Oscillator osc; Parameter freqctrl, wavectrl, ampctrl, finectrl; std::string WaveToString(uint8_t); + void SetWaveState(uint8_t); const double pi = std::acos(-1); - int sine_width = 20; + int sine_width = 21; Wave* wave = new Wave(WaveShape::kTriangle, sine_width, GetTitleHeight()); + int testH = 20; + //Wave* testWave = new Wave(WaveShape::kSaw, 30, testH); public: VCODroplet(DaisyPatch*, DropletState, float); ~VCODroplet(); diff --git a/src/graphics/sprite.cpp b/src/graphics/sprite.cpp index 3548a92..1afad58 100644 --- a/src/graphics/sprite.cpp +++ b/src/graphics/sprite.cpp @@ -20,7 +20,7 @@ Sprite::~Sprite() { } void Sprite::AddPixel(int x, int y, bool solid) { - sprite[x][y] = solid; + sprite[x][height-y-1] = solid; } void Sprite::AddLine(int x1, @@ -65,7 +65,7 @@ void Sprite::Draw(DaisyPatch patch, int x, int y) { for (int h = 0; h < height; h++) { patch.display.DrawPixel(x+w, y+h, sprite[GetShiftArrayX(w)] - [GetShiftArrayY(h)]); + [GetShiftArrayY(height-h)]); } } } @@ -79,10 +79,12 @@ void Sprite::DrawTile(DaisyPatch patch, int x_max = std::max(x1, x2); int y_min = std::min(y1, y2); int y_max = std::max(y1, y2); + int x, y; for (int w = x_min; w < x_max; w++) { for (int h = y_min; h < y_max; h++) { - patch.display.DrawPixel(w, h, sprite[GetShiftArrayX((w-x_min) % width)] - [GetShiftArrayY((h-y_min+y_shift) % height)]); + x = GetShiftArrayX((w-x_min) % width); + y = GetShiftArrayY((h-y_min) % height); + patch.display.DrawPixel(w, h, sprite[x][y]); } } } diff --git a/src/graphics/wave.cpp b/src/graphics/wave.cpp index f2bc3cf..cfaec25 100644 --- a/src/graphics/wave.cpp +++ b/src/graphics/wave.cpp @@ -8,10 +8,22 @@ Wave::Wave(WaveShape m_wave, int width, int height) : Sprite(width, height) { void Wave::DrawShape() { SetBlank(); int mid = GetWidth()/2; + int x_max = GetWidth()-1; + int y_max = GetHeight()-1; switch(wave) { + case WaveShape::kSaw: + AddLine(0, 0, x_max, y_max, true); + AddLine(x_max, y_max, x_max, 0, true); + return; + case WaveShape::kSquare: + AddLine(0, 0, mid, 0, true); + AddLine(mid, 0, mid, y_max, true); + AddLine(mid, y_max, x_max, y_max, true); + AddLine(GetWidth()-1, GetHeight()-1, GetWidth()-1, 0, true); + return; case WaveShape::kTriangle: - AddLine(0, GetHeight()+1, mid, 0, true); - AddLine(mid, 0, GetWidth()+1, GetHeight(), true); + AddLine(0, 0, mid, y_max, true); + AddLine(mid, y_max, x_max, 0, true); return; case WaveShape::kSine: default: @@ -22,3 +34,8 @@ void Wave::DrawShape() { return; } } + +void Wave::SetWaveShape(WaveShape m_wave) { + wave = m_wave; + DrawShape(); +} diff --git a/src/graphics/wave.h b/src/graphics/wave.h index f635f0a..96d32db 100644 --- a/src/graphics/wave.h +++ b/src/graphics/wave.h @@ -14,6 +14,7 @@ class Wave: public Sprite { void DrawShape(); public: Wave(WaveShape, int, int); + void SetWaveShape(WaveShape); }; #endif