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