Advertisement
Guest User

Untitled

a guest
Oct 20th, 2024
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. //********************************************************************
  2. // Simple VU Meter - a fine freeware by chris-s
  3. // V1.1; 10-Jan-2017
  4. // Disclaimer: Use of this software is on your own risk
  5. //********************************************************************
  6.  
  7. desc:Simple VU Meter
  8. //tags: analysis vu meter
  9. //author: chris-s
  10.  
  11. // hidden sliders: remove the "-" in front of the name to activate
  12.  
  13. slider1:-18<-20,0,0.5>Ref Level
  14. slider2:-1<-20,0,0.1>Warn Level
  15. slider3:50<0,100,1}>-Response // Hidden
  16. slider4:0<0,2,1{Stereo,Mono,Mid/Side}>Mode
  17. slider5:0.0053<0,.01,0.0001>-Damping // Hidden
  18.  
  19.  
  20. // Hide side meters
  21. in_pin:none
  22. out_pin:none
  23.  
  24. /********************************************************************/
  25.  
  26. @init
  27.  
  28. ext_noinit = 1;
  29. // bg col
  30. gfx_clear = 30 + 60 * 256 + 110 * 65536;
  31.  
  32. errcnt = 0;
  33. tot_nbr_spl = 0;
  34. scnt = 0;
  35.  
  36. fact_up = 0;
  37.  
  38. offset = 0.0074;
  39.  
  40. nd_posL = nd_posR = 0;
  41. nd_posL_max = nd_posR_max = 0;
  42. nd_speedL = nd_speedR = 0;
  43.  
  44. dt = 10 / srate;
  45.  
  46. mom = 0.00042;
  47. damp = 1 - 0.0053 * (48000 / srate);
  48.  
  49. dbL = dbR = 0;
  50. overL = overR = 0;
  51.  
  52.  
  53. print = 10;
  54. print[0] = -20;
  55. print[1] = -10;
  56. print[2] = -7;
  57. print[3] = -5;
  58. print[4] = -3;
  59. print[5] = -2;
  60. print[6] = -1;
  61. print[7] = 0;
  62. print[8] = 1;
  63. print[9] = 2;
  64. print[10] = 3;
  65.  
  66.  
  67. pos = 30;
  68. pos[0] = 0;
  69. pos[1] = .1650;
  70. pos[2] = .2641;
  71. pos[3] = .3519;
  72. pos[4] = .4626;
  73. pos[5] = .5284;
  74. pos[6] = .6022;
  75. pos[7] = .6849;
  76. pos[8] = .7779;
  77. pos[9] = .8822;
  78. pos[10] = 1;
  79.  
  80. /********************************************************************/
  81.  
  82. @slider
  83.  
  84. fact_up = 10 ^ (( -slider1 - 10)/20) * 0.3785 ;
  85.  
  86. wl = slider2;
  87. mode = slider4;
  88. lim = 10 ^ (wl / 20);
  89.  
  90. mom = 0.00010 + 0.00032 * slider3^3 / 125000;
  91.  
  92. damp = 1 - slider5 * (48000 / srate);
  93.  
  94.  
  95. /********************************************************************/
  96.  
  97. @sample
  98.  
  99. tot_nbr_spl += 1;
  100.  
  101. smpL = spl0;
  102. smpR = spl1;
  103.  
  104. mode == 1 ? (
  105. smpL = (spl0 + spl1) * 0.5;
  106. smpR = smpL;
  107. );
  108.  
  109. mode >= 2 ? (
  110. smpL = (spl0 + spl1) * 0.5;
  111. smpR = (spl0 - spl1) * 0.5;
  112. );
  113.  
  114. smpL = abs(smpL);
  115. smpR = abs(smpR);
  116.  
  117.  
  118. scnt += 1;
  119.  
  120. scnt === 10 ? (
  121.  
  122. // move left needle
  123.  
  124. force = smpL * fact_up - (nd_posL * .1 + offset);
  125.  
  126. nd_speedL += force * dt / mom;
  127. nd_speedL = nd_speedL * damp;
  128. nd_posL += nd_speedL * dt;
  129. nd_posL < 0 || nd_posL > 1 ? nd_speedL = 0;
  130.  
  131. nd_posL = min(max(nd_posL,0),1);
  132. nd_posL_max = max(nd_posL_max,nd_posL);
  133.  
  134. // move right needle
  135.  
  136. force = smpR * fact_up - (nd_posR * .1 + offset);
  137.  
  138. nd_speedR += force * dt / mom;
  139. nd_speedR = nd_speedR * damp;
  140. nd_posR += nd_speedR * dt;
  141. nd_posR < 0 || nd_posR > 1 ? nd_speedR = 0;
  142.  
  143. nd_posR = min(max(nd_posR,0),1);
  144. nd_posR_max = max(nd_posR_max,nd_posR);
  145.  
  146. overL -= 10;
  147. overR -= 10;
  148.  
  149. scnt = 0;
  150.  
  151. );
  152.  
  153. smpL > lim ? overL = srate;
  154. smpR > lim ? overR = srate;
  155.  
  156.  
  157. /********************************************************************/
  158.  
  159. @gfx 480 300
  160.  
  161. (mouse_cap & 1) ? (
  162. nd_posR_max = nd_posL_max = 0;
  163. );
  164.  
  165. tot_nbr_spl_g = tot_nbr_spl;
  166.  
  167. overL_g = overL;
  168. overR_g = overR;
  169. nd_posL_g = nd_posL;
  170. nd_posR_g = nd_posR;
  171.  
  172. tot_nbr_spl_g === tot_nbr_spl ? (
  173.  
  174. dbL = (nd_posL_g * 23) - 20;
  175. dbR = (nd_posR_g * 23) - 20;
  176.  
  177. ) : (
  178. errcnt += 1; // thread collision
  179. );
  180.  
  181.  
  182.  
  183. // paint gfx
  184.  
  185. fontinit != 1 ? (
  186. gfx_setfont(1, "Arial", 14, '');
  187. gfx_setfont(2, "Arial", 20, 'b');
  188.  
  189. fontinit = 1;
  190. );
  191.  
  192. gfx_a = 1;
  193.  
  194. w1 = $pi * 16.5 / 180;
  195. w2 = $pi * 45 / 180;
  196.  
  197. xw = max(1,floor((gfx_w-30) / 2));
  198. yw = floor(xw / 1.5);
  199.  
  200. r1 = floor(yw * 0.85);
  201.  
  202.  
  203. chan = 0;
  204.  
  205. while (chan <= 1) (
  206.  
  207. xd = 10 + chan*(xw+10);
  208. mode === 1 ? xd += floor(xw/2);
  209.  
  210. yd = 10;
  211.  
  212. xa = floor(xd + xw / 2);
  213. ya = floor(yd + yw * 1.1);
  214.  
  215. // meter backgr
  216.  
  217. gfx_r=1;gfx_g=1;gfx_b=.7;
  218. gfx_rect(xd,yd,xw,yw);
  219.  
  220. // scale
  221.  
  222. gfx_r=gfx_g=gfx_b = 0; // black
  223. gfx_arc(xa, ya, r1, -45 * ($pi / 180), w2, 1);
  224.  
  225. gfx_r=.95; gfx_g=0; gfx_b = 0; // red
  226. gfx_arc(xa, ya, r1 + 1, w1, w2, 1);
  227. gfx_arc(xa, ya, r1 + 2, w1, w2, 1);
  228. gfx_arc(xa, ya, r1 + 3, w1, w2, 1);
  229. gfx_arc(xa, ya, r1 + 4, w1, w2, 1);
  230.  
  231.  
  232. gfx_setfont(1);
  233.  
  234. gfx_r=gfx_g=gfx_b = 0.2; // black
  235.  
  236. jj = 0;
  237. while ( jj <= 10 ) (
  238.  
  239. ii = print[jj];
  240.  
  241. ph = pos[jj];
  242. ph = (45 + ph*90) * $pi / 180;
  243.  
  244. cosp = cos(ph) * r1;
  245. sinp = sin(ph) * r1;
  246.  
  247. x1 = xa - cosp ;
  248. y1 = ya - sinp ;
  249.  
  250. x2 = xa - cosp * 1.1;
  251. y2 = ya - sinp * 1.1;
  252.  
  253. x3 = xa - cosp * 1.12;
  254. y3 = ya - sinp * 1.12;
  255.  
  256. gfx_x = x1;
  257. gfx_y = y1 ;
  258. gfx_lineto(x2, y2);
  259.  
  260. gfx_x = x3 - 7;
  261. gfx_y = y3 - gfx_texth;
  262.  
  263. gfx_printf("%3d", ii);
  264.  
  265. jj += 1;
  266.  
  267. jj == 8 ? ( gfx_r = 1; gfx_g = gfx_b = 0 );
  268. );
  269.  
  270.  
  271. // Peak
  272.  
  273. gfx_r=gfx_g=gfx_b = 0.0; // black
  274.  
  275. gfx_x = xd + xw * .9 - 30;
  276. gfx_y = yd + yw * .9 - 10;
  277. gfx_drawstr("PEAK");
  278.  
  279. // VU-max
  280. gfx_x = xd + 10;
  281. gfx_y = yd + yw * .9 - 10;
  282. gfx_printf("MAX %.0f", (chan == 1 ? nd_posR_max : nd_posL_max) * 23 - 20);
  283.  
  284. // VU
  285.  
  286. gfx_setfont(2); // large
  287. gfx_r=gfx_g=gfx_b = 0.0; // black
  288.  
  289. gfx_x = xa - 10;
  290. gfx_y = yd + yw * .6;
  291. gfx_drawstr("VU");
  292.  
  293.  
  294. // draw LEDs
  295.  
  296. gfx_r = .95; gfx_g = gfx_b = 0.1; // red
  297.  
  298. (chan == 0 && overL_g > 0) || (chan == 1 && overR_g > 0) ? (
  299. gfx_circle(xd + xw*0.9 + 6, yd + yw * 0.9 - 4, 4, 1, 1);
  300. );
  301.  
  302.  
  303. // draw needle
  304.  
  305. chan == 0 ? ph = dbL : ph = dbR;
  306.  
  307. ph = 45 + (ph+20)/23*90;
  308. ph = ph * ($pi / 180);
  309.  
  310. cosp = cos(ph);
  311. sinp = sin(ph);
  312.  
  313. x1 = xa - cosp * r1 * 0.15;
  314. y1 = ya - sinp * r1 * 0.15;
  315.  
  316. x2 = xa - cosp * r1 * 1.1;
  317. y2 = ya - sinp * r1 * 1.1;
  318.  
  319. gfx_r=gfx_g=gfx_b = 0.0; // black
  320.  
  321. gfx_x = x1;
  322. gfx_y = y1;
  323. gfx_lineto(x2, y2);
  324.  
  325. gfx_x = x1+1;
  326. gfx_y = y1;
  327. gfx_lineto(x2+1, y2);
  328.  
  329.  
  330. gfx_r=gfx_g=gfx_b = 0.6; // gray
  331.  
  332. gfx_x = x1+4;
  333. gfx_y = y1;
  334. gfx_lineto(x2+4, y2);
  335.  
  336.  
  337. gfx_r=.12; gfx_g=.24; gfx_b = 0.43; // blue
  338. gfx_circle(xa,ya,r1*0.16,1,0);
  339.  
  340.  
  341. gfx_r=gfx_g=gfx_b = 1; // white
  342.  
  343. gfx_x = xd;
  344. gfx_y = yd+yw+2;
  345.  
  346. chan == 0 ?
  347. gfx_drawstr("LEFT/MID") :
  348. gfx_drawstr("RIGHT/SIDE") ;
  349.  
  350. chan += 1;
  351.  
  352. mode === 1 ? chan += 1;
  353. );
  354.  
  355.  
  356.  
  357. /****************************** EOF *******************************/
  358.  
  359.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement