00 /**********************************************************************
01 Copyright (c) 2014-2016 Mark C. Erickson
02
03 Permission is hereby granted, free of charge, to any person obtaining
04 a copy of this software and associated documentation files (the
05 "Software"), to deal in the Software without restriction, including
06 without limitation the rights to use, copy, modify, merge, publish,
07 distribute, sublicense, and/or sell copies of the Software, and to
08 permit persons to whom the Software is furnished to do so, subject to
09 the following conditions:
10
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANT-
16 ABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO
17 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
20 THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 CHANGE LOG:
23 v1.1.0 - added GUI
24 v1.0.0 - initial release
25
26 **********************************************************************/
27
Disclaimer...
28 desc:Fader: Squared [+0dB], v1.1.0
29
30 slider1: 70.7 <0, 100, 0.1> Position [mm]
31
32 @init
33 gfx_clear = 256*256*256-1;
34 m = 1;
35
36 @slider
37 c = slider1 / 100.0;
38 m = c * c;
39
40 @sample
41 spl0 *= m;
42 spl1 *= m;
43
44
Graphics...
46 @gfx 256 256
47 gfx_setfont(1, "Arial", 10);
48 gfx_a = 1;
49
50 gfx_r = gfx_g = gfx_b = 0.1;
51 gfx_line(0, 0, gfx_w, 0, 0.5); // outline our GUI box
52 gfx_line(0, 0, 0, gfx_h, 0.5);
53 gfx_line(gfx_w-1, 0, gfx_w-1, gfx_h, 0.5);
54 gfx_line(0, gfx_h-2, gfx_w, gfx_h-2, 0.5);
55
56 x_step = gfx_w / 10;
57 y_step = gfx_h / 10;
58
59 i = 1;
60 loop(9, // y-axiis
61 x = i*x_step;
62 gfx_line(x, y_step, x, y_step*8, 0.5);
63 i += 1;
64 );
65
66 gfx_x = x_step - 2;
67 gfx_y = gfx_h - 2*y_step + 9;
68 gfx_drawchar($'0');
69 gfx_drawchar($'m');gfx_drawchar($'m');
70
71 gfx_x = 3*x_step - 7;
72 gfx_y = gfx_h - 2*y_step + 9;
73 gfx_drawchar($'2');
74 gfx_drawchar($'5');
75 gfx_drawchar($'m');gfx_drawchar($'m');
76
77 gfx_x = 5*x_step - 7;
78 gfx_y = gfx_h - 2*y_step + 9;
79 gfx_drawchar($'5');
80 gfx_drawchar($'0');
81 gfx_drawchar($'m');gfx_drawchar($'m');
82
83 gfx_x = 7*x_step - 7;
84 gfx_y = gfx_h - 2*y_step + 9;
85 gfx_drawchar($'7');
86 gfx_drawchar($'5');
87 gfx_drawchar($'m');gfx_drawchar($'m');
88
89 gfx_x = 9*x_step - 12;
90 gfx_y = gfx_h - 2*y_step + 9;
91 gfx_drawchar($'1');
92 gfx_drawchar($'0');
93 gfx_drawchar($'0');
94 gfx_drawchar($'m');gfx_drawchar($'m');
95
96 i = 1;
97 loop(8, // x-axiis
98 y = i*y_step;
99 gfx_line(x_step-2, y, x_step*9, y, 0.5);
100 i += 1;
101 );
102
103 gfx_x = x_step - 32;
104 gfx_y = y_step - 6;
105 gfx_drawchar($' ');
106 gfx_drawchar($'0');
107 gfx_drawchar($' ');
108 gfx_drawchar($'d');
109 gfx_drawchar($'B');
110
111 gfx_x = x_step - 36;
112 gfx_y = 2*y_step - 7;
113 gfx_drawchar($'-');
114 gfx_drawchar($'1');
115 gfx_drawchar($'2');
116 gfx_drawchar($'d');
117 gfx_drawchar($'B');
118
119 gfx_x = x_step - 36;
120 gfx_y = 3*y_step - 7;
121 gfx_drawchar($'-');
122 gfx_drawchar($'2');
123 gfx_drawchar($'4');
124 gfx_drawchar($'d');
125 gfx_drawchar($'B');
126
127 gfx_x = x_step - 36;
128 gfx_y = 4*y_step - 7;
129 gfx_drawchar($'-');
130 gfx_drawchar($'3');
131 gfx_drawchar($'6');
132 gfx_drawchar($'d');
133 gfx_drawchar($'B');
134
135 gfx_x = x_step - 36;
136 gfx_y = 5*y_step - 7;
137 gfx_drawchar($'-');
138 gfx_drawchar($'4');
139 gfx_drawchar($'8');
140 gfx_drawchar($'d');
141 gfx_drawchar($'B');
142
143 gfx_x = x_step - 36;
144 gfx_y = 6*y_step - 7;
145 gfx_drawchar($'-');
146 gfx_drawchar($'6');
147 gfx_drawchar($'0');
148 gfx_drawchar($'d');
149 gfx_drawchar($'B');
150
151 gfx_x = x_step - 36;
152 gfx_y = 7*y_step - 7;
153 gfx_drawchar($'-');
154 gfx_drawchar($'7');
155 gfx_drawchar($'2');
156 gfx_drawchar($'d');
157 gfx_drawchar($'B');
158
159 gfx_x = x_step - 36;
160 gfx_y = 8*y_step - 8;
161 gfx_drawchar($'-');
162 gfx_drawchar($'8');
163 gfx_drawchar($'4');
164 gfx_drawchar($'d');
165 gfx_drawchar($'B');
166
167 gfx_r = gfx_g = 0.1;
168 gfx_b = 0.9;
169 dB = 20 * log10(m);
170 dB *= -1;
171 dB > 83 ? dB = 84;
172 m == 0? dB = 84;
173 y = y_step*dB/12 + y_step;
174 gfx_rect(x_step+2, y, x_step*8-2, 2, 0.5); // horizontal line
175 gfx_rect(x_step+slider1/100*x_step*8, y_step+2, 1, y_step*7-2, 0.5); // vertical line
176 gfx_rect(x_step+slider1/100*x_step*8-3, y-2, 6, 6, 0.5); // hilite box
177 gfx_x = gfx_w*.9+8;
178 gfx_y = y-6;
179 sprintf(str, "%.1fdB", -dB);
180 gfx_drawstr(str);
181 gfx_x = x_step+slider1/100*x_step*8-9;
182 gfx_y = y_step - 17;
183 sprintf(str, "%.1fmm", slider1);
184 gfx_drawstr(str);
185
186 gfx_g = 0.2;
187 gfx_b = gfx_r = 0.9;
188 RES = 100; // min = 8
189 x_step1 = x_step * 8/RES;
190
191 i = 1;
192 loop(RES, //8, // main curve
193 x = i*x_step1;
194
195 c=(i-1)/RES;
196 m1 = c^2;
197 dB = -20 * log10(m1);
198 dB > 83 ? dB = 84;
199 i == 1? dB = 84;
200 y = y_step*dB/12 + y_step;
201
202 c=(i)/RES;
203 m2 = c^2;
204 dB1 = -20 * log10(m2);
205 dB1 > 83 ? dB1 = 84;
206 i == 1 ? dB = 84;
207 y1 = y_step*dB1/12 + y_step;
208
209 gfx_line(x_step+x-x_step1, y, x_step+x, y1, 0.5);
210 i += 1;
211 );
212
213 gfx_setfont(1, "Arial", 12); // main title
214 gfx_r = gfx_g = gfx_b = 0.0;
215 gfx_x = x_step;
216 gfx_y = gfx_h - y_step + 3;
217 gfx_drawstr("Squared Fader: Gain (dB) - vs - Fader Travel (mm)");
218
219 // mouse
220 mouse_cap == 1 ? (
221 xx = mouse_x;
222 xx > gfx_w * 0.1 ? (
223 xx < gfx_w * 0.9 ? (
224 yy = mouse_y;
225 yy > gfx_h * 0.1 ? (
226 yy < gfx_h * 0.8 ? (
227 slider1 = 100 * (xx - gfx_w*.1) / (gfx_w*.9 - gfx_w*.1);
228 slider1 < 0.3 ? slider1 = floor(slider1);
229 slider1 > 99.7 ? slider1 = ceil(slider1);
230 slider1 = floor(slider1*10);
231 slider1 /= 10;
232 sliderchange(slider1);
233 slider_automate(slider1);
234 c = slider1 / 100.0;
235 m = c * c;
236 )
237 );
238 );
239 );
240 );
241
242