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: Polynomial [+12dB], v1.1.0
29
30 slider1: 71.54 <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^6 + c^3;
39 m *= 2.0;
40
41 @sample
42 spl0 *= m;
43 spl1 *= m;
44
45
Graphics...
47 @gfx 256 256
48 gfx_setfont(1, "Arial", 10);
49 gfx_a = 1;
50
51 gfx_r = gfx_g = gfx_b = 0.1;
52 gfx_line(0, 0, gfx_w, 0, 0.5); // outline our GUI box
53 gfx_line(0, 0, 0, gfx_h, 0.5);
54 gfx_line(gfx_w-1, 0, gfx_w-1, gfx_h, 0.5);
55 gfx_line(0, gfx_h-2, gfx_w, gfx_h-2, 0.5);
56
57 x_step = gfx_w / 10;
58 y_step = gfx_h / 10;
59
60 i = 1;
61 loop(9, // y-axiis
62 x = i*x_step;
63 gfx_line(x, y_step, x, y_step*8, 0.5);
64 i += 1;
65 );
66
67 gfx_x = x_step - 2;
68 gfx_y = gfx_h - 2*y_step + 9;
69 gfx_drawchar($'0');
70 gfx_drawchar($'m');
71 gfx_drawchar($'m');
72
73 gfx_x = 3*x_step - 7;
74 gfx_y = gfx_h - 2*y_step + 9;
75 gfx_drawchar($'2');
76 gfx_drawchar($'5');
77 gfx_drawchar($'m');
78 gfx_drawchar($'m');
79
80 gfx_x = 5*x_step - 7;
81 gfx_y = gfx_h - 2*y_step + 9;
82 gfx_drawchar($'5');
83 gfx_drawchar($'0');
84 gfx_drawchar($'m');
85 gfx_drawchar($'m');
86
87 gfx_x = 7*x_step - 7;
88 gfx_y = gfx_h - 2*y_step + 9;
89 gfx_drawchar($'7');
90 gfx_drawchar($'5');
91 gfx_drawchar($'m');
92 gfx_drawchar($'m');
93
94 gfx_x = 9*x_step - 12;
95 gfx_y = gfx_h - 2*y_step + 9;
96 gfx_drawchar($'1');
97 gfx_drawchar($'0');
98 gfx_drawchar($'0');
99 gfx_drawchar($'m');
100 gfx_drawchar($'m');
101
102 i = 1;
103 loop(8, // x-axiis
104 y = i*y_step;
105 gfx_line(x_step-2, y, x_step*9, y, 0.5);
106 i += 1;
107 );
108
109 gfx_x = x_step - 36;
110 gfx_y = y_step - 6;
111 gfx_drawchar($'+');
112 gfx_drawchar($'1');
113 gfx_drawchar($'2');
114 gfx_drawchar($'d');
115 gfx_drawchar($'B');
116
117 gfx_x = x_step - 32;
118 gfx_y = 2*y_step - 7;
119 gfx_drawchar($' ');
120 gfx_drawchar($'0');
121 gfx_drawchar($' ');
122 gfx_drawchar($'d');
123 gfx_drawchar($'B');
124
125 gfx_x = x_step - 36;
126 gfx_y = 3*y_step - 7;
127 gfx_drawchar($'-');
128 gfx_drawchar($'1');
129 gfx_drawchar($'2');
130 gfx_drawchar($'d');
131 gfx_drawchar($'B');
132
133 gfx_x = x_step - 36;
134 gfx_y = 4*y_step - 7;
135 gfx_drawchar($'-');
136 gfx_drawchar($'2');
137 gfx_drawchar($'4');
138 gfx_drawchar($'d');
139 gfx_drawchar($'B');
140
141 gfx_x = x_step - 36;
142 gfx_y = 5*y_step - 7;
143 gfx_drawchar($'-');
144 gfx_drawchar($'3');
145 gfx_drawchar($'6');
146 gfx_drawchar($'d');
147 gfx_drawchar($'B');
148
149 gfx_x = x_step - 36;
150 gfx_y = 6*y_step - 7;
151 gfx_drawchar($'-');
152 gfx_drawchar($'4');
153 gfx_drawchar($'8');
154 gfx_drawchar($'d');
155 gfx_drawchar($'B');
156
157 gfx_x = x_step - 36;
158 gfx_y = 7*y_step - 7;
159 gfx_drawchar($'-');
160 gfx_drawchar($'6');
161 gfx_drawchar($'0');
162 gfx_drawchar($'d');
163 gfx_drawchar($'B');
164
165 gfx_x = x_step - 36;
166 gfx_y = 8*y_step - 8;
167 gfx_drawchar($'-');
168 gfx_drawchar($'7');
169 gfx_drawchar($'2');
170 gfx_drawchar($'d');
171 gfx_drawchar($'B');
172
173 gfx_r = gfx_g = 0.2;
174 gfx_b = 0.9;
175 m1 = m/3.981071705534972;
176 dB = 20 * log10(m1);
177 dB *= -1;
178 dB > 83 ? dB = 84;
179 m == 0? dB = 84;
180 y = y_step*dB/12 + y_step;
181 gfx_rect(x_step+2, y, x_step*8-3, 2, 0.5); // horizontal line
182 gfx_rect(x_step+slider1/100*x_step*8, y_step+2, 1, y_step*7-3, 0.5); // vertical line
183 gfx_rect(x_step+slider1/100*x_step*8-3, y-2, 6, 6, 0.5); // hilite box
184 gfx_x = gfx_w*.9+8;
185 gfx_y = y-6;
186 sprintf(str, "%.1fdB", -dB+12);
187 gfx_drawstr(str);
188 gfx_x = x_step+slider1/100*x_step*8-3;
189 gfx_y = y_step - 17;
190 sprintf(str, "%.1fmm", slider1);
191 gfx_drawstr(str);
192
193 gfx_g = 0.1;
194 gfx_b = gfx_r = 0.9;
195 RES = 100; // min = 8
196 x_step1 = x_step * 8/RES;
197
198 i = 1;
199 loop(RES, //8, // main curve
200 x = i*x_step1;
201 c=(i-1)/RES;
202 m1 = c^6 + c^3;
203 m1 /= 2.0;
204 dB = -20 * log10(m1); dB > 83 ? dB = 84;
205 i == 1? dB = 84;
206 y = y_step*dB/12 + y_step;
207
208 c=(i)/RES;
209 m2 = c^6 + c^3;
210 m2 /= 2.0;
211 dB1 = -20 * log10(m2);
212 dB1 > 83 ? dB1 = 84;
213 i == 1 ? dB = 84;
214 y1 = y_step*dB1/12 + y_step;
215
216 gfx_line(x_step+x-x_step1, y, x_step+x, y1, 0.5);
217 i += 1;
218 );
219
220 gfx_setfont(1, "Arial", 12); // main title
221 gfx_r = gfx_g = gfx_b = 0.0;
222 gfx_x = x_step;
223 gfx_y = gfx_h - y_step + 3;
224 gfx_drawstr("Polynomial Fader: Gain (dB) - vs - Fader Travel (mm)");
225
226 // mouse
227 mouse_cap == 1 ? (
228 xx = mouse_x;
229 xx > gfx_w * 0.1 ? (
230 xx < gfx_w * 0.9 ? (
231 yy = mouse_y;
232 yy > gfx_h * 0.1 ? (
233 yy < gfx_h * 0.8 ? (
234 slider1 = 100 * (xx - gfx_w*.1) / (gfx_w*.9 - gfx_w*.1);
235 slider1 < 0.3 ? slider1 = floor(slider1);
236 slider1 > 99.7 ? slider1 = ceil(slider1);
237 slider1 = floor(slider1*10);
238 slider1 /= 10;
239 sliderchange(slider1);
240 slider_automate(slider1);
241 c = slider1/100;
242 m = c^6 + c^3;
243 m *= 2.0;
244 )
245 );
246 );
247 );
248 );
249
250