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
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 CHANGE LOG:
23 v1.1.0 - added GUI
24 v1.0.1 - replaced '4' with '3.981071705534972'
25 v1.0.0 - initial release
26
27 **********************************************************************/
28
Disclaimer...
29 desc:Fader: Parallel [+12dB], v1.1.0
30
31 slider1: 74.4 <0, 100, 0.1> Position [mm]
32
33 @init
34 gfx_clear = 256*256*256-1;
35 factor = 6800.0 / 27000.0;
36 m = 1.0;
37
38 @slider
39 c = slider1 / 100.0;
40 m = 3.981071705534972 / (((1-c)/c) + ((1-c)/factor) + 1.0);
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');
72 gfx_drawchar($'m');
73
74 gfx_x = 3*x_step - 7;
75 gfx_y = gfx_h - 2*y_step + 9;
76 gfx_drawchar($'2');
77 gfx_drawchar($'5');
78 gfx_drawchar($'m');
79 gfx_drawchar($'m');
80
81 gfx_x = 5*x_step - 7;
82 gfx_y = gfx_h - 2*y_step + 9;
83 gfx_drawchar($'5');
84 gfx_drawchar($'0');
85 gfx_drawchar($'m');
86 gfx_drawchar($'m');
87
88 gfx_x = 7*x_step - 7;
89 gfx_y = gfx_h - 2*y_step + 9;
90 gfx_drawchar($'7');
91 gfx_drawchar($'5');
92 gfx_drawchar($'m');
93 gfx_drawchar($'m');
94
95 gfx_x = 9*x_step - 12;
96 gfx_y = gfx_h - 2*y_step + 9;
97 gfx_drawchar($'1');
98 gfx_drawchar($'0');
99 gfx_drawchar($'0');
100 gfx_drawchar($'m');
101 gfx_drawchar($'m');
102
103 i = 1;
104 loop(8, // x-axiis
105 y = i*y_step;
106 gfx_line(x_step-2, y, x_step*9, y, 0.5);
107 i += 1;
108 );
109
110 gfx_x = x_step - 36;
111 gfx_y = y_step - 6;
112 gfx_drawchar($'+');
113 gfx_drawchar($'1');
114 gfx_drawchar($'2');
115 gfx_drawchar($'d');
116 gfx_drawchar($'B');
117
118 gfx_x = x_step - 32;
119 gfx_y = 2*y_step - 7;
120 gfx_drawchar($' ');
121 gfx_drawchar($'0');
122 gfx_drawchar($' ');
123 gfx_drawchar($'d');
124 gfx_drawchar($'B');
125
126 gfx_x = x_step - 36;
127 gfx_y = 3*y_step - 7;
128 gfx_drawchar($'-');
129 gfx_drawchar($'1');
130 gfx_drawchar($'2');
131 gfx_drawchar($'d');
132 gfx_drawchar($'B');
133
134 gfx_x = x_step - 36;
135 gfx_y = 4*y_step - 7;
136 gfx_drawchar($'-');
137 gfx_drawchar($'2');
138 gfx_drawchar($'4');
139 gfx_drawchar($'d');
140 gfx_drawchar($'B');
141
142 gfx_x = x_step - 36;
143 gfx_y = 5*y_step - 7;
144 gfx_drawchar($'-');
145 gfx_drawchar($'3');
146 gfx_drawchar($'6');
147 gfx_drawchar($'d');
148 gfx_drawchar($'B');
149
150 gfx_x = x_step - 36;
151 gfx_y = 6*y_step - 7;
152 gfx_drawchar($'-');
153 gfx_drawchar($'4');
154 gfx_drawchar($'8');
155 gfx_drawchar($'d');
156 gfx_drawchar($'B');
157
158 gfx_x = x_step - 36;
159 gfx_y = 7*y_step - 7;
160 gfx_drawchar($'-');
161 gfx_drawchar($'6');
162 gfx_drawchar($'0');
163 gfx_drawchar($'d');
164 gfx_drawchar($'B');
165
166 gfx_x = x_step - 36;
167 gfx_y = 8*y_step - 8;
168 gfx_drawchar($'-');
169 gfx_drawchar($'7');
170 gfx_drawchar($'2');
171 gfx_drawchar($'d');
172 gfx_drawchar($'B');
173
174 gfx_r = gfx_g = 0.2;
175 gfx_b = 0.9;
176 m1 = m/3.981071705534972;
177 dB = 20 * log10(m1);
178 dB *= -1;
179 dB > 83 ? dB = 84;
180 m == 0? dB = 84;
181 y = y_step*dB/12 + y_step;
182 gfx_rect(x_step+2, y, x_step*8-3, 2, 0.5); // horizontal line
183 gfx_rect(x_step+slider1/100*x_step*8, y_step+2, 1, y_step*7-3, 0.5); // vertical line
184 gfx_rect(x_step+slider1/100*x_step*8-3, y-2, 6, 6, 0.5); // hilite box
185 gfx_x = gfx_w*.9+8;
186 gfx_y = y-6;
187 sprintf(str, "%.1fdB", -dB+12);
188 gfx_drawstr(str);
189 gfx_x = x_step+slider1/100*x_step*8-3;
190 gfx_y = y_step - 17;
191 sprintf(str, "%.1fmm", slider1);
192 gfx_drawstr(str);
193
194 gfx_g = 0.1;
195 gfx_b = gfx_r = 0.9;
196 RES = 100; // min = 8
197 x_step1 = x_step * 8/RES;
198
199 i = 1;
200 loop(RES, //8, // main curve
201 x = i*x_step1;
202 c=(i-1)/RES;
203 m1 = 1.0 / (((1-c)/c) + ((1-c)/factor) + 1.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 = 1.0 / (((1-c)/c) + ((1-c)/factor) + 1.0);
210 dB1 = -20 * log10(m2);
211 dB1 > 83 ? dB1 = 84;
212 i == 1 ? dB = 84;
213 y1 = y_step*dB1/12 + y_step;
214
215 gfx_line(x_step+x-x_step1, y, x_step+x, y1, 0.5);
216 i += 1;
217 );
218
219 gfx_setfont(1, "Arial", 12); // main title
220 gfx_r = gfx_g = gfx_b = 0.0;
221 gfx_x = x_step;
222 gfx_y = gfx_h - y_step + 3;
223 gfx_drawstr("Parallel Fader: Gain (dB) - vs - Fader Travel (mm)");
224
225 // mouse
226 mouse_cap == 1 ? (
227 xx = mouse_x;
228 xx > gfx_w * 0.1 ? (
229 xx < gfx_w * 0.9 ? (
230 yy = mouse_y;
231 yy > gfx_h * 0.1 ? (
232 yy < gfx_h * 0.8 ? (
233 slider1 = 100 * (xx - gfx_w*.1) / (gfx_w*.9 - gfx_w*.1);
234 slider1 < 0.3 ? slider1 = floor(slider1);
235 slider1 > 99.7 ? slider1 = ceil(slider1);
236 slider1 = floor(slider1*10);
237 slider1 /= 10;
238 sliderchange(slider1);
239 slider_automate(slider1);
240 c = slider1/100;
241 d = 1.0 / (((1-c)/c) + ((1-c)/factor) + 1.0);
242 m = 3.981071705534972 * d;
243 )
244 );
245 );
246 );
247 );
248
249