VCO title bar changes based on wave shape

This commit is contained in:
Christian Colglazier 2020-09-26 13:24:13 -04:00
parent 62497cade0
commit b04fdf7f70
5 changed files with 64 additions and 9 deletions

View File

@ -19,7 +19,7 @@ VCODroplet::VCODroplet(DaisyPatch* m_patch,
} }
VCODroplet::~VCODroplet() { VCODroplet::~VCODroplet() {
delete wave; // delete wave;
} }
void VCODroplet::Control() {} void VCODroplet::Control() {}
@ -51,10 +51,12 @@ void VCODroplet::Process(float** in, float** out, size_t size) {
void VCODroplet::Draw() { void VCODroplet::Draw() {
WriteString(*Patch(), 0, 54, Font_6x8, WriteString(*Patch(), 0, 54, Font_6x8,
WaveToString(wavectrl.Process())); WaveToString(wavectrl.Process()));
SetWaveState(wavectrl.Process());
wave->DrawTile(*Patch(), GetScreenMin(), 0, GetScreenMax(), GetTitleHeight()); wave->DrawTile(*Patch(), GetScreenMin(), 0, GetScreenMax(), GetTitleHeight());
if(NeedUpdate()) { if(NeedUpdate()) {
//wave->AdjustXShift(1); wave->AdjustXShift(1);
} }
//testWave->DrawTile(*Patch(), 0, GetTitleHeight(), 60, GetTitleHeight()+testH);
DrawName("VCO"); DrawName("VCO");
AnimationInc(); AnimationInc();
} }
@ -80,3 +82,33 @@ std::string VCODroplet::WaveToString(uint8_t wf) {
} }
return ""; 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;
}
}

View File

@ -20,9 +20,12 @@ 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);
void SetWaveState(uint8_t);
const double pi = std::acos(-1); const double pi = std::acos(-1);
int sine_width = 20; int sine_width = 21;
Wave* wave = new Wave(WaveShape::kTriangle, sine_width, GetTitleHeight()); Wave* wave = new Wave(WaveShape::kTriangle, sine_width, GetTitleHeight());
int testH = 20;
//Wave* testWave = new Wave(WaveShape::kSaw, 30, testH);
public: public:
VCODroplet(DaisyPatch*, DropletState, float); VCODroplet(DaisyPatch*, DropletState, float);
~VCODroplet(); ~VCODroplet();

View File

@ -20,7 +20,7 @@ Sprite::~Sprite() {
} }
void Sprite::AddPixel(int x, int y, bool solid) { void Sprite::AddPixel(int x, int y, bool solid) {
sprite[x][y] = solid; sprite[x][height-y-1] = solid;
} }
void Sprite::AddLine(int x1, 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++) { for (int h = 0; h < height; h++) {
patch.display.DrawPixel(x+w, y+h, patch.display.DrawPixel(x+w, y+h,
sprite[GetShiftArrayX(w)] 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 x_max = std::max(x1, x2);
int y_min = std::min(y1, y2); int y_min = std::min(y1, y2);
int y_max = std::max(y1, y2); int y_max = std::max(y1, y2);
int x, y;
for (int w = x_min; w < x_max; w++) { for (int w = x_min; w < x_max; w++) {
for (int h = y_min; h < y_max; h++) { for (int h = y_min; h < y_max; h++) {
patch.display.DrawPixel(w, h, sprite[GetShiftArrayX((w-x_min) % width)] x = GetShiftArrayX((w-x_min) % width);
[GetShiftArrayY((h-y_min+y_shift) % height)]); y = GetShiftArrayY((h-y_min) % height);
patch.display.DrawPixel(w, h, sprite[x][y]);
} }
} }
} }

View File

@ -8,10 +8,22 @@ Wave::Wave(WaveShape m_wave, int width, int height) : Sprite(width, height) {
void Wave::DrawShape() { void Wave::DrawShape() {
SetBlank(); SetBlank();
int mid = GetWidth()/2; int mid = GetWidth()/2;
int x_max = GetWidth()-1;
int y_max = GetHeight()-1;
switch(wave) { 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: case WaveShape::kTriangle:
AddLine(0, GetHeight()+1, mid, 0, true); AddLine(0, 0, mid, y_max, true);
AddLine(mid, 0, GetWidth()+1, GetHeight(), true); AddLine(mid, y_max, x_max, 0, true);
return; return;
case WaveShape::kSine: case WaveShape::kSine:
default: default:
@ -22,3 +34,8 @@ void Wave::DrawShape() {
return; return;
} }
} }
void Wave::SetWaveShape(WaveShape m_wave) {
wave = m_wave;
DrawShape();
}

View File

@ -14,6 +14,7 @@ class Wave: public Sprite {
void DrawShape(); void DrawShape();
public: public:
Wave(WaveShape, int, int); Wave(WaveShape, int, int);
void SetWaveShape(WaveShape);
}; };
#endif #endif