Skip to content

Commit defc471

Browse files
committed
working on arduino gui
1 parent ccd51b9 commit defc471

File tree

3 files changed

+309
-52
lines changed

3 files changed

+309
-52
lines changed

arduino/hwtest/hwtest2_guitest/SynthUI.h

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,63 @@
1313

1414
class Param {
1515
public:
16+
// construct a Param from another Param
17+
Param(Param* p) {
18+
name = p->name;
19+
val = p->val;
20+
minval = p->minval;
21+
maxval = p->maxval;
22+
fmt = p->fmt;
23+
}
24+
1625
Param(const char* aname, float aval, float aminval = 0, float amaxval = 255, const char* afmt = "%.0f") {
1726
name = aname;
1827
val = aval;
1928
minval = aminval;
2029
maxval = amaxval;
2130
fmt = afmt;
2231
}
32+
// return the 0.0-1.0 "percentage" the val is in between minval and maxval
2333
float percent() {
2434
return (val - minval) / (maxval - minval);
2535
}
36+
// set val based on the "percentage" it should be between minval and maxval
2637
void set_percent(float pct) {
2738
val = pct * (maxval - minval) + minval;
2839
}
2940

30-
const char* name;
31-
float val;
32-
float minval;
33-
float maxval;
34-
const char* fmt;
41+
const char* name; // name of param
42+
float val; // value of param, even if a byte value from 0-255
43+
float minval; // the minimum allowed value
44+
float maxval; // maximum allowed value
45+
const char* fmt; // how to format the value as a string
46+
};
47+
48+
class Patch {
49+
public:
50+
Patch(const char* aname, Param* aparams, int nparams) {
51+
snprintf(name, 20, aname);
52+
num_params = nparams;
53+
params = (Param*) malloc(sizeof(Param) * nparams);
54+
for(int i=0; i<nparams; i++ ) {
55+
params[i] = Param(aparams[i]);
56+
}
57+
}
58+
char name[20];
59+
Param* params;
60+
int num_params;
3561
};
3662

63+
3764
class SynthUI {
3865
public:
3966
SynthUI(Adafruit_GFX* adisplay) {
4067
display = adisplay;
4168
}
4269

43-
70+
/**
71+
* Print text at a given x,y, using an optionally specified font
72+
*/
4473
void print_text(int x, int y, const char* str, const GFXfont* fnt = NULL) {
4574
if (fnt != NULL) { display->setFont(fnt); }
4675
display->setTextColor(WHITE, 0);
@@ -54,19 +83,19 @@ class SynthUI {
5483
*/
5584
void draw_vertical_slider(int x, int y, float thumbpos, int w = 5, int h = 63, int thumbw = 0, int thumbh = 10) {
5685
int ypos = thumbpos * h;
57-
thumbw = (thumbw==0) ? w : thumbw; // make thumbw same width as slider if not specified
58-
display->drawRect(x, y, w, h, WHITE); // right side scroll bar
59-
display->fillRect(x, y + ypos, thumbw, thumbh, WHITE); // FIXME
86+
thumbw = (thumbw == 0) ? w : thumbw; // make thumbw same width as slider if not specified
87+
display->drawRect(x, y, w, h, WHITE);
88+
display->fillRect(x, y + ypos, thumbw, thumbh, WHITE);
6089
}
6190
/**
6291
* Draw horizontal slider with a "thumb" position identifying value
6392
* thumpos ranges 0.0-1.0
6493
*/
6594
void draw_horizontal_slider(int x, int y, float thumbpos, int w = 127, int h = 5, int thumbw = 10, int thumbh = 0) {
6695
int xpos = thumbpos * (w - thumbw);
67-
thumbh = (thumbh==0) ? h : thumbh; // make thumbh same height as slider if not specified
68-
display->drawRect(x, y - h, w, h, WHITE); // right side scroll bar
69-
display->fillRect(x + xpos, y - h, thumbw, thumbh, WHITE); // FIXME
96+
thumbh = (thumbh == 0) ? h : thumbh; // make thumbh same height as slider if not specified
97+
display->drawRect(x, y - h, w, h, WHITE);
98+
display->fillRect(x + xpos, y - h, thumbw, thumbh, WHITE);
7099
}
71100

72101

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
// Created by https://oleddisplay.squix.ch/ Consider a donation
2+
// In case of problems make sure that you are using the font file with the correct version!
3+
const uint8_t Dialog_plain_7Bitmaps[] PROGMEM = {
4+
5+
// Bitmap Data:
6+
0x00, // ' '
7+
0xA8,0x80, // '!'
8+
0xAA, // '"'
9+
0x53,0xE5,0x3E,0x60, // '#'
10+
0x4E,0xCE,0x6E,0x40, // '$'
11+
0xC9,0xA3,0xF1,0x64,0xC0, // '%'
12+
0x71,0x0E,0xAC,0x78, // '&'
13+
0xA0, // '''
14+
0x52,0x48,0x80, // '('
15+
0x89,0x25,0x00, // ')'
16+
0x4E,0x4E, // '*'
17+
0x20,0x8F,0x88,0x20, // '+'
18+
0xA0, // ','
19+
0xC0, // '-'
20+
0x80, // '.'
21+
0x49,0x49,0x00, // '/'
22+
0xEA,0xAA,0xE0, // '0'
23+
0xC4,0x44,0xE0, // '1'
24+
0xE2,0x24,0xE0, // '2'
25+
0xE2,0x42,0xE0, // '3'
26+
0x23,0x19,0xE2,0x00, // '4'
27+
0xE8,0xE2,0xE0, // '5'
28+
0x68,0xEA,0xE0, // '6'
29+
0xE2,0x24,0x40, // '7'
30+
0xEA,0x4A,0xE0, // '8'
31+
0xEA,0xE2,0xC0, // '9'
32+
0x82, // ':'
33+
0x82,0x80, // ';'
34+
0x17,0x38,0x20, // '<'
35+
0xF0,0x3C, // '='
36+
0x83,0x9D,0x00, // '>'
37+
0xE2,0x40,0x40, // '?'
38+
0x79,0x8A,0xD5,0xCC,0x0E,0x00, // '@'
39+
0x21,0xC5,0x1C,0x88, // 'A'
40+
0xF4,0xB9,0x2F,0x00, // 'B'
41+
0x74,0x21,0x07,0x00, // 'C'
42+
0xE4,0xA5,0x2E,0x00, // 'D'
43+
0xE8,0xE8,0xE0, // 'E'
44+
0xE8,0xE8,0x80, // 'F'
45+
0x74,0x2D,0x27,0x00, // 'G'
46+
0x94,0xBD,0x29,0x00, // 'H'
47+
0xAA,0x80, // 'I'
48+
0x49,0x25,0x80, // 'J'
49+
0xA6,0x31,0xCB,0x00, // 'K'
50+
0x88,0x88,0xE0, // 'L'
51+
0xDB,0x6A,0xAA,0x88, // 'M'
52+
0xD6,0xBD,0x69,0x00, // 'N'
53+
0x64,0xA5,0x26,0x00, // 'O'
54+
0xEA,0xE8,0x80, // 'P'
55+
0x64,0xA5,0x26,0x10, // 'Q'
56+
0xE5,0x31,0x4B,0x00, // 'R'
57+
0xF4,0x1C,0x2F,0x00, // 'S'
58+
0xF8,0x82,0x08,0x20, // 'T'
59+
0x94,0xA5,0x26,0x00, // 'U'
60+
0x89,0x45,0x1C,0x20, // 'V'
61+
0xB5,0x69,0xE2,0x44,0x80, // 'W'
62+
0x93,0x18,0xC9,0x00, // 'X'
63+
0xD9,0x42,0x08,0x20, // 'Y'
64+
0xF1,0x18,0x8F,0x00, // 'Z'
65+
0xD2,0x49,0x80, // '['
66+
0x92,0x24,0x80, // '\'
67+
0xC9,0x25,0x80, // ']'
68+
0x64,0x80, // '^'
69+
0xF0, // '_'
70+
0x80, // '`'
71+
0x62,0xEE, // 'a'
72+
0x88,0xEA,0xAE, // 'b'
73+
0x68,0x86, // 'c'
74+
0x22,0xEA,0xAE, // 'd'
75+
0xEE,0x8E, // 'e'
76+
0x64,0xE4,0x44, // 'f'
77+
0xEA,0xAE,0xE0, // 'g'
78+
0x88,0xEA,0xAA, // 'h'
79+
0xAA,0x80, // 'i'
80+
0x49,0x25,0x80, // 'j'
81+
0x88,0xEC,0xCE, // 'k'
82+
0xAA,0xA0, // 'l'
83+
0xFA,0xAA,0xAA, // 'm'
84+
0xEA,0xAA, // 'n'
85+
0xEA,0xAE, // 'o'
86+
0xEA,0xAE,0x80, // 'p'
87+
0xEA,0xAE,0x20, // 'q'
88+
0xD2,0x40, // 'r'
89+
0xEC,0x2E, // 's'
90+
0x9A,0x4C, // 't'
91+
0xAA,0xAE, // 'u'
92+
0x93,0x18,0xC0, // 'v'
93+
0xAB,0x65,0x14, // 'w'
94+
0xF3,0x19,0xE0, // 'x'
95+
0x93,0x18,0x8C,0x00, // 'y'
96+
0xE6,0x4E, // 'z'
97+
0x64,0x84,0x46, // '{'
98+
0xAA,0xA8, // '|'
99+
0xC4,0x24,0x4C // '}'
100+
};
101+
const GFXglyph Dialog_plain_7Glyphs[] PROGMEM = {
102+
// bitmapOffset, width, height, xAdvance, xOffset, yOffset
103+
{ 0, 2, 1, 3, 0, -1 }, // ' '
104+
{ 1, 2, 5, 4, 1, -5 }, // '!'
105+
{ 3, 4, 2, 4, 1, -5 }, // '"'
106+
{ 4, 6, 5, 7, 1, -5 }, // '#'
107+
{ 8, 4, 7, 5, 1, -6 }, // '$'
108+
{ 12, 7, 5, 8, 1, -5 }, // '%'
109+
{ 17, 6, 5, 6, 1, -5 }, // '&'
110+
{ 21, 2, 2, 3, 1, -5 }, // '''
111+
{ 22, 3, 6, 4, 1, -6 }, // '('
112+
{ 25, 3, 6, 4, 1, -6 }, // ')'
113+
{ 28, 4, 4, 5, 1, -5 }, // '*'
114+
{ 30, 6, 5, 7, 1, -5 }, // '+'
115+
{ 34, 2, 2, 3, 1, -1 }, // ','
116+
{ 35, 3, 1, 4, 1, -3 }, // '-'
117+
{ 36, 2, 1, 3, 1, -1 }, // '.'
118+
{ 37, 3, 6, 3, 0, -5 }, // '/'
119+
{ 40, 4, 5, 5, 1, -5 }, // '0'
120+
{ 43, 4, 5, 5, 1, -5 }, // '1'
121+
{ 46, 4, 5, 5, 1, -5 }, // '2'
122+
{ 49, 4, 5, 5, 1, -5 }, // '3'
123+
{ 52, 5, 5, 5, 1, -5 }, // '4'
124+
{ 56, 4, 5, 5, 1, -5 }, // '5'
125+
{ 59, 4, 5, 5, 1, -5 }, // '6'
126+
{ 62, 4, 5, 5, 1, -5 }, // '7'
127+
{ 65, 4, 5, 5, 1, -5 }, // '8'
128+
{ 68, 4, 5, 5, 1, -5 }, // '9'
129+
{ 71, 2, 4, 3, 1, -4 }, // ':'
130+
{ 72, 2, 5, 3, 1, -4 }, // ';'
131+
{ 74, 5, 4, 7, 1, -4 }, // '<'
132+
{ 77, 5, 3, 7, 1, -4 }, // '='
133+
{ 79, 5, 4, 7, 1, -4 }, // '>'
134+
{ 82, 4, 5, 5, 1, -5 }, // '?'
135+
{ 85, 7, 6, 8, 1, -5 }, // '@'
136+
{ 91, 6, 5, 6, 0, -5 }, // 'A'
137+
{ 95, 5, 5, 6, 1, -5 }, // 'B'
138+
{ 99, 5, 5, 6, 1, -5 }, // 'C'
139+
{ 103, 5, 5, 6, 1, -5 }, // 'D'
140+
{ 107, 4, 5, 5, 1, -5 }, // 'E'
141+
{ 110, 4, 5, 5, 1, -5 }, // 'F'
142+
{ 113, 5, 5, 6, 1, -5 }, // 'G'
143+
{ 117, 5, 5, 6, 1, -5 }, // 'H'
144+
{ 121, 2, 5, 3, 1, -5 }, // 'I'
145+
{ 123, 3, 6, 3, 0, -5 }, // 'J'
146+
{ 126, 5, 5, 6, 1, -5 }, // 'K'
147+
{ 130, 4, 5, 5, 1, -5 }, // 'L'
148+
{ 133, 6, 5, 7, 1, -5 }, // 'M'
149+
{ 137, 5, 5, 6, 1, -5 }, // 'N'
150+
{ 141, 5, 5, 7, 1, -5 }, // 'O'
151+
{ 145, 4, 5, 5, 1, -5 }, // 'P'
152+
{ 148, 5, 6, 7, 1, -5 }, // 'Q'
153+
{ 152, 5, 5, 6, 1, -5 }, // 'R'
154+
{ 156, 5, 5, 5, 1, -5 }, // 'S'
155+
{ 160, 6, 5, 5, 0, -5 }, // 'T'
156+
{ 164, 5, 5, 6, 1, -5 }, // 'U'
157+
{ 168, 6, 5, 6, 0, -5 }, // 'V'
158+
{ 172, 7, 5, 8, 0, -5 }, // 'W'
159+
{ 177, 5, 5, 5, 0, -5 }, // 'X'
160+
{ 181, 6, 5, 5, 0, -5 }, // 'Y'
161+
{ 185, 5, 5, 6, 1, -5 }, // 'Z'
162+
{ 189, 3, 6, 4, 1, -5 }, // '['
163+
{ 192, 3, 6, 3, 0, -5 }, // '\'
164+
{ 195, 3, 6, 4, 1, -5 }, // ']'
165+
{ 198, 5, 2, 7, 1, -5 }, // '^'
166+
{ 200, 5, 1, 5, 0, 1 }, // '_'
167+
{ 201, 3, 1, 5, 0, -6 }, // '`'
168+
{ 202, 4, 4, 5, 1, -4 }, // 'a'
169+
{ 204, 4, 6, 5, 1, -6 }, // 'b'
170+
{ 207, 4, 4, 5, 1, -4 }, // 'c'
171+
{ 209, 4, 6, 5, 1, -6 }, // 'd'
172+
{ 212, 4, 4, 5, 1, -4 }, // 'e'
173+
{ 214, 4, 6, 3, 0, -6 }, // 'f'
174+
{ 217, 4, 5, 5, 1, -4 }, // 'g'
175+
{ 220, 4, 6, 5, 1, -6 }, // 'h'
176+
{ 223, 2, 5, 3, 1, -5 }, // 'i'
177+
{ 225, 3, 6, 3, 0, -5 }, // 'j'
178+
{ 228, 4, 6, 5, 1, -6 }, // 'k'
179+
{ 231, 2, 6, 3, 1, -6 }, // 'l'
180+
{ 233, 6, 4, 8, 1, -4 }, // 'm'
181+
{ 236, 4, 4, 5, 1, -4 }, // 'n'
182+
{ 238, 4, 4, 5, 1, -4 }, // 'o'
183+
{ 240, 4, 5, 5, 1, -4 }, // 'p'
184+
{ 243, 4, 5, 5, 1, -4 }, // 'q'
185+
{ 246, 3, 4, 4, 1, -4 }, // 'r'
186+
{ 248, 4, 4, 5, 1, -4 }, // 's'
187+
{ 250, 3, 5, 4, 1, -5 }, // 't'
188+
{ 252, 4, 4, 5, 1, -4 }, // 'u'
189+
{ 254, 5, 4, 5, 0, -4 }, // 'v'
190+
{ 257, 6, 4, 7, 0, -4 }, // 'w'
191+
{ 260, 5, 4, 5, 0, -4 }, // 'x'
192+
{ 263, 5, 5, 5, 0, -4 }, // 'y'
193+
{ 267, 4, 4, 5, 1, -4 }, // 'z'
194+
{ 269, 4, 6, 5, 1, -5 }, // '{'
195+
{ 272, 2, 7, 3, 1, -5 }, // '|'
196+
{ 274, 4, 6, 5, 1, -5 } // '}'
197+
};
198+
const GFXfont Dialog_plain_7 PROGMEM = {
199+
(uint8_t *)Dialog_plain_7Bitmaps,(GFXglyph *)Dialog_plain_7Glyphs,0x20, 0x7E, 9};

0 commit comments

Comments
 (0)