Skip to content

Commit 4c180d3

Browse files
Give applets space to draw.
1 parent 363854b commit 4c180d3

4 files changed

Lines changed: 61 additions & 19 deletions

File tree

src/AppHost.hpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
using namespace daisy;
1212

1313
enum App { VCO, VCA, NOISE, NUM_ITEMS };
14-
const int SCREEN_WIDTH = 128;
14+
const int SCREEN_WIDTH = 100;//128;
15+
const int S_WIDTH = 36; //(SCREEN_WIDTH / 2);
1516

1617
static uint32_t DSY_QSPI_BSS buff[BUFF_SIZE];
1718
//static uint32_t __attribute__((section(".dtcmram_bss"))) outbuff[BUFF_SIZE];
@@ -29,9 +30,13 @@ class AppHost {
2930
int position;
3031
App app;
3132
Applet *gen;
33+
int dr[S_WIDTH * S_WIDTH];
3234
AppHost() {
3335
position = 0;
3436
app = App::VCO;
37+
for (int i = 0; i < S_WIDTH * S_WIDTH; i++) {
38+
dr[i] = 0;
39+
}
3540
}
3641

3742
void Init(float sample_rate) {
@@ -53,15 +58,26 @@ class AppHost {
5358

5459
void draw(DaisyPatch patch, int selected) {
5560
int draw_width = SCREEN_WIDTH / NUM_APPLETS;
56-
61+
int left_offset = position * draw_width;
5762
if (selected == position) {
58-
for (int x = position * draw_width; x < (position + 1) * draw_width; x++) {
59-
patch.display.DrawPixel(x, 30, true);
63+
for (int x = left_offset; x < (position + 1) * draw_width; x++) {
64+
patch.display.DrawPixel(x, 12, true);
6065
}
6166
}
6267
const char *names[App::NUM_ITEMS] =
6368
{ "FM VCO", "VCA", "NOISE" };
64-
writeString(patch, position * draw_width, 18, names[app]);
69+
writeString(patch, position * draw_width, 2, names[app]);
70+
gen->Draw(dr, S_WIDTH, S_WIDTH);
71+
for (int x = 0; x < S_WIDTH; x++) {
72+
for (int y = 0; y < S_WIDTH; y++) {
73+
if (dr[S_WIDTH * y + x] == 1) {
74+
patch.display.DrawPixel(x + left_offset, y + 20, true);
75+
} else {
76+
patch.display.DrawPixel(x + left_offset, y + 20, false);
77+
}
78+
}
79+
}
80+
//delete dr;
6581
}
6682
};
6783

src/Applet.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ float* Amp::Process(float in_l, float in_r) {
1919
return out;
2020
}
2121

22+
void Amp::Draw(int *out, int width, int height) {
23+
for (int x = 0; x < width; x++) {
24+
for (int y = 0; y < height; y++) {
25+
out [y * width + x] = 0;
26+
if (x > 0 && x < width / 2 && y > (height - amp_l * height)) {
27+
out[y * width + x] = 1;
28+
}
29+
30+
if (x > width / 2 && y > (height - amp_r * height)) {
31+
out[y * width + x] = 1;
32+
}
33+
}
34+
}
35+
}
36+
2237
// NOISE
2338
// ----------------------
2439
Noise::Noise(float sample_rate) {
@@ -37,6 +52,14 @@ float* Noise::Process(float in_l, float in_r) {
3752
return out;
3853
}
3954

55+
void Noise::Draw(int *out, int width, int height) {
56+
for (int x = 0; x < width; x++) {
57+
for (int y = 0; y < height; y++) {
58+
out [y * width + x] = 0;
59+
}
60+
}
61+
}
62+
4063
// OSC
4164
// ----------------------
4265
Osc::Osc(float sample_rate) {
@@ -72,3 +95,11 @@ float* Osc::Process(float in_l, float in_r) {
7295
out[1] = osc_two->Process();
7396
return out;
7497
}
98+
99+
void Osc::Draw(int *out, int width, int height) {
100+
for (int x = 0; x < width; x++) {
101+
for (int y = 0; y < height; y++) {
102+
out [y * width + x] = 0;
103+
}
104+
}
105+
}

src/Applet.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1+
#include "daisy_patch.h"
2+
13
#include <random>
24
#include <math.h>
35
#include "Generator.hpp"
46

7+
using namespace daisy;
8+
59
class Applet {
610
public:
711
virtual ~Applet() {};
812
virtual void Control(float f_l, float f_r) = 0;
913
virtual float* Process(float f_l, float f_r) = 0;
14+
virtual void Draw(int *d, int width, int height) = 0;
1015
};
1116

1217
class Amp: public Applet {
1318
public:
1419
Amp(float sample_rate);
1520
void Control(float in_l, float in_r);
1621
float* Process(float in, float in_r);
22+
void Draw(int *d, int width, int height);
1723
private:
1824
float amp_l, amp_r;
1925
};
@@ -23,6 +29,7 @@ class Noise: public Applet {
2329
Noise(float sample_rate);
2430
void Control(float in_l, float in_r);
2531
float* Process(float in_l, float in_r);
32+
void Draw(int *d, int width, int height);
2633
private:
2734
float amp_;
2835
};
@@ -37,6 +44,7 @@ class Osc: public Applet {
3744
~Osc();
3845
void Control(float in_l, float in_r);
3946
float* Process(float in_l, float in_r);
47+
void Draw(int *d, int width, int height);
4048
private:
4149
float car_freq_, mod_freq_, mod_index_;
4250
Oscillator *osc_one;

src/Olearia.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#include "daisy_patch.h"
2-
#include <string>
3-
#include <cstring>
42
#include <math.h>
53

64
// local includes
@@ -34,11 +32,6 @@ void UpdateControls() {
3432
}
3533

3634
if (patch.encoder.Pressed()) {
37-
// save?
38-
if (patch.encoder.TimeHeldMs() > 2000.0f && patch.encoder.TimeHeldMs() < 2010.0f) {
39-
//writeModes();
40-
// disabled for now
41-
}
4235
// encoder
4336
selected = (selected + patch.encoder.Increment()) % NUM_APPLETS;
4437
if (selected < 0) {
@@ -67,21 +60,15 @@ static void AudioThrough(float **in, float **out, size_t size) {
6760
for (int a = 0; a < NUM_APPLETS; a++) {
6861
apphost[a]->gen->Control(controls[2 * a], controls[2 * a + 1]);
6962
for (size_t i = 0; i < size; i++) {
70-
float *o;
71-
o = apphost[a]->gen->Process(in[2 * a][i], in[2 * a + 1][i]);
63+
float *o = apphost[a]->gen->Process(in[2 * a][i], in[2 * a + 1][i]);
7264
out[2 * a][i] = o[0];
7365
out[2 * a + 1][i] = o[1];
74-
//out[2 * a + 1][i] = applets[a].gen->Process();
7566
}
7667
}
7768
}
7869

7970
void UpdateOled() {
8071
patch.display.Fill(false);
81-
//writeString(patch, 0, 0, "olearia");
82-
for (int i = 0; i < 128; i++) {
83-
patch.display.DrawPixel(i, 10, true);
84-
}
8572
for (int i = 0; i < NUM_APPLETS; i++) {
8673
apphost[i]->draw(patch, selected);
8774
}

0 commit comments

Comments
 (0)