1
0

r_sscope.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #define M_PI 3.14159265358979323846
  25. #include <windows.h>
  26. #include <commctrl.h>
  27. #include <math.h>
  28. #include "r_defs.h"
  29. #include "resource.h"
  30. #include "avs_eelif.h"
  31. #if 0//syntax highlighting
  32. #include "richedit.h"
  33. #endif
  34. #include "timing.h"
  35. #include "../Agave/Language/api_language.h"
  36. #define C_THISCLASS C_SScopeClass
  37. #define MOD_NAME "Render / SuperScope"
  38. class C_THISCLASS : public C_RBASE {
  39. protected:
  40. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  41. public:
  42. C_THISCLASS();
  43. virtual ~C_THISCLASS();
  44. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  45. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_RENDER_SUPERSCOPE,desc,128):desc); }
  46. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  47. virtual void load_config(unsigned char *data, int len);
  48. virtual int save_config(unsigned char *data);
  49. RString effect_exp[4];
  50. int which_ch;
  51. int num_colors;
  52. int colors[16];
  53. int mode;
  54. int color_pos;
  55. NSEEL_VMCTX AVS_EEL_CONTEXTNAME;
  56. double *var_b, *var_x, *var_y, *var_i, *var_n, *var_v, *var_w, *var_h, *var_red, *var_green, *var_blue;
  57. double *var_skip, *var_linesize, *var_drawmode;
  58. int inited;
  59. NSEEL_CODEHANDLE codehandle[4];
  60. int need_recompile;
  61. CRITICAL_SECTION rcs;
  62. };
  63. #define PUT_INT(y) data[pos]=(y)&255; data[pos+1]=(y>>8)&255; data[pos+2]=(y>>16)&255; data[pos+3]=(y>>24)&255
  64. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  65. void C_THISCLASS::load_config(unsigned char *data, int len)
  66. {
  67. int pos=0;
  68. int x=0;
  69. if (data[pos] == 1)
  70. {
  71. pos++;
  72. load_string(effect_exp[0],data,pos,len);
  73. load_string(effect_exp[1],data,pos,len);
  74. load_string(effect_exp[2],data,pos,len);
  75. load_string(effect_exp[3],data,pos,len);
  76. }
  77. else
  78. {
  79. char buf[1025];
  80. if (len-pos >= 1024)
  81. {
  82. memcpy(buf,data+pos,1024);
  83. pos+=1024;
  84. buf[1024]=0;
  85. effect_exp[3].assign(buf+768);
  86. buf[768]=0;
  87. effect_exp[2].assign(buf+512);
  88. buf[512]=0;
  89. effect_exp[1].assign(buf+256);
  90. buf[256]=0;
  91. effect_exp[0].assign(buf);
  92. }
  93. }
  94. if (len-pos >= 4) { which_ch=GET_INT(); pos+=4; }
  95. if (len-pos >= 4) { num_colors=GET_INT(); pos+=4; }
  96. if (num_colors <= 16) while (len-pos >= 4 && x < num_colors) { colors[x++]=GET_INT(); pos+=4; }
  97. else num_colors=0;
  98. if (len-pos >= 4) { mode=GET_INT(); pos+=4; }
  99. need_recompile=1;
  100. }
  101. int C_THISCLASS::save_config(unsigned char *data)
  102. {
  103. int x=0;
  104. int pos=0;
  105. data[pos++]=1;
  106. save_string(data,pos,effect_exp[0]);
  107. save_string(data,pos,effect_exp[1]);
  108. save_string(data,pos,effect_exp[2]);
  109. save_string(data,pos,effect_exp[3]);
  110. PUT_INT(which_ch); pos+=4;
  111. PUT_INT(num_colors); pos+=4;
  112. while (x < num_colors) { PUT_INT(colors[x]); x++; pos+=4; }
  113. PUT_INT(mode); pos+=4;
  114. return pos;
  115. }
  116. C_THISCLASS::C_THISCLASS()
  117. {
  118. InitializeCriticalSection(&rcs);
  119. AVS_EEL_INITINST();
  120. #ifdef LASER
  121. mode=1;
  122. #else
  123. mode=0;
  124. #endif
  125. need_recompile=1;
  126. which_ch=2;
  127. num_colors=1;
  128. memset(colors,0,sizeof(colors));
  129. colors[0]=RGB(255,255,255);
  130. color_pos=0;
  131. memset(codehandle,0,sizeof(codehandle));
  132. #ifdef LASER
  133. effect_exp[0].assign("d=i+v*0.2; r=t+i*$PI*4; x=cos(r)*d; y=sin(r)*d");
  134. effect_exp[1].assign("t=t-0.05");
  135. effect_exp[2].assign("");
  136. effect_exp[3].assign("n=100");
  137. #else
  138. effect_exp[0].assign("d=i+v*0.2; r=t+i*$PI*4; x=cos(r)*d; y=sin(r)*d");
  139. effect_exp[1].assign("t=t-0.05");
  140. effect_exp[2].assign("");
  141. effect_exp[3].assign("n=800");
  142. #endif
  143. var_n=0;
  144. }
  145. C_THISCLASS::~C_THISCLASS()
  146. {
  147. int x;
  148. for (x = 0; x < 4; x ++)
  149. {
  150. freeCode(codehandle[x]);
  151. codehandle[x]=0;
  152. }
  153. AVS_EEL_QUITINST();
  154. DeleteCriticalSection(&rcs);
  155. }
  156. static __inline int makeint(double t)
  157. {
  158. if (t <= 0.0) return 0;
  159. if (t >= 1.0) return 255;
  160. return (int)(t*255.0);
  161. }
  162. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  163. {
  164. if (need_recompile)
  165. {
  166. EnterCriticalSection(&rcs);
  167. if (!var_n || g_reset_vars_on_recompile)
  168. {
  169. clearVars();
  170. var_n = registerVar("n");
  171. var_b = registerVar("b");
  172. var_x = registerVar("x");
  173. var_y = registerVar("y");
  174. var_i = registerVar("i");
  175. var_v = registerVar("v");
  176. var_w = registerVar("w");
  177. var_h = registerVar("h");
  178. var_red = registerVar("red");
  179. var_green = registerVar("green");
  180. var_blue = registerVar("blue");
  181. var_linesize = registerVar("linesize");
  182. var_skip = registerVar("skip");
  183. var_drawmode = registerVar("drawmode");
  184. *var_n=100.0;
  185. inited=0;
  186. }
  187. need_recompile=0;
  188. int x;
  189. for (x = 0; x < 4; x ++)
  190. {
  191. freeCode(codehandle[x]);
  192. codehandle[x]=compileCode(effect_exp[x].get());
  193. }
  194. LeaveCriticalSection(&rcs);
  195. }
  196. if (isBeat&0x80000000) return 0;
  197. if (!num_colors) return 0;
  198. int x;
  199. int current_color;
  200. unsigned char *fa_data;
  201. char center_channel[576];
  202. int ws=(which_ch&4)?1:0;
  203. int xorv=(ws*128)^128;
  204. if ((which_ch&3) >=2)
  205. {
  206. for (x = 0; x < 576; x ++) center_channel[x]=visdata[ws^1][0][x]/2+visdata[ws^1][1][x]/2;
  207. fa_data=(unsigned char *)center_channel;
  208. }
  209. else fa_data=(unsigned char *)&visdata[ws^1][which_ch&3][0];
  210. color_pos++;
  211. if (color_pos >= num_colors * 64) color_pos=0;
  212. {
  213. int p=color_pos/64;
  214. int r=color_pos&63;
  215. int c1,c2;
  216. int r1,r2,r3;
  217. c1=colors[p];
  218. if (p+1 < num_colors)
  219. c2=colors[p+1];
  220. else c2=colors[0];
  221. r1=(((c1&255)*(63-r))+((c2&255)*r))/64;
  222. r2=((((c1>>8)&255)*(63-r))+(((c2>>8)&255)*r))/64;
  223. r3=((((c1>>16)&255)*(63-r))+(((c2>>16)&255)*r))/64;
  224. current_color=r1|(r2<<8)|(r3<<16);
  225. }
  226. *var_h=h;
  227. *var_w=w;
  228. *var_b=isBeat?1.0:0.0;
  229. *var_blue=(current_color&0xff)/255.0;
  230. *var_green=((current_color>>8)&0xff)/255.0;
  231. *var_red=((current_color>>16)&0xff)/255.0;
  232. *var_skip=0.0;
  233. *var_linesize = (double) ((g_line_blend_mode&0xff0000)>>16);
  234. *var_drawmode = mode ? 1.0 : 0.0;
  235. if (codehandle[3] && !inited) { executeCode(codehandle[3],visdata); inited=1; }
  236. executeCode(codehandle[1],visdata);
  237. if (isBeat) executeCode(codehandle[2],visdata);
  238. if (codehandle[0])
  239. {
  240. int candraw=0,lx=0,ly=0;
  241. #ifdef LASER
  242. double dlx=0.0,dly=0.0;
  243. #endif
  244. int a;
  245. int l=(int)*var_n;
  246. if (l > 128*1024) l = 128*1024;
  247. for (a = 0; a < l; a ++)
  248. {
  249. int x,y;
  250. double r=(a*576.0)/l;
  251. double s1=r-(int)r;
  252. double yr=(fa_data[(int)r]^xorv)*(1.0f-s1)+(fa_data[(int)r+1]^xorv)*(s1);
  253. *var_v = yr/128.0 - 1.0;
  254. *var_i = (double)a/(double)(l-1);
  255. *var_skip=0.0;
  256. executeCode(codehandle[0],visdata);
  257. x=(int)((*var_x+1.0)*w*0.5);
  258. y=(int)((*var_y+1.0)*h*0.5);
  259. if (*var_skip < 0.00001)
  260. {
  261. int thiscolor=makeint(*var_blue)|(makeint(*var_green)<<8)|(makeint(*var_red)<<16);
  262. if (*var_drawmode < 0.00001)
  263. {
  264. if (y >= 0 && y < h && x >= 0 && x < w)
  265. {
  266. #ifdef LASER
  267. laser_drawpoint((float)*var_x,(float)*var_y,thiscolor);
  268. #else
  269. BLEND_LINE(framebuffer+x+y*w,thiscolor);
  270. #endif
  271. }
  272. }
  273. else
  274. {
  275. if (candraw)
  276. {
  277. #ifdef LASER
  278. LineType l;
  279. l.color=thiscolor;
  280. l.mode=0;
  281. l.x1=(float)*var_x;
  282. l.y1=(float)*var_y;
  283. l.x2=(float)dlx;
  284. l.y2=(float)dly;
  285. g_laser_linelist->AddLine(&l);
  286. #else
  287. if ((thiscolor&0xffffff) || (g_line_blend_mode&0xff)!=1)
  288. {
  289. line(framebuffer,lx,ly,x,y,w,h,thiscolor,(int) (*var_linesize+0.5));
  290. }
  291. #endif
  292. } // candraw
  293. } // line
  294. } // skip
  295. candraw=1;
  296. lx=x;
  297. ly=y;
  298. #ifdef LASER
  299. dlx=*var_x;
  300. dly=*var_y;
  301. #endif
  302. }
  303. }
  304. return 0;
  305. }
  306. C_RBASE *R_SScope(char *desc)
  307. {
  308. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  309. return (C_RBASE *) new C_THISCLASS();
  310. }
  311. typedef struct
  312. {
  313. int name;
  314. char *init;
  315. char *point;
  316. char *frame;
  317. char *beat;
  318. } presetType;
  319. static presetType presets[]=
  320. {
  321. #ifdef LASER
  322. {"Laser - Bouncing Line","n=8;xp=0;yp=0;d=0.5;r=0;xps=0; yps=0; dtr=0.1; bv=1; gv=1; rv=1;","x=xp+d*cos(r)*sign(i-0.5); y=yp+d*sin(r)*sign(i-0.5);","r=r+dtr; xp=xp*0.99+xps*0.01; yp=yp*0.99+yps*0.01; red=rv; green=gv; blue=bv;","xps=(rand(100)-50)/50; yps=(rand(100)-50)/50; dtr=-dtr; rv=rand(100)/100; gv=rand(100)/100; bv=rand(100)/100;"},
  323. {"Laser - BeatFlex Scope","n=5; tv=0; dtv=0; tvs=1.0;","x=(i-0.5)*2; y=-sin(i*$PI)*tv+v*0.2;","tv=tv*0.97+tvs*0.03;","tvs=-sign(tvs);"},
  324. {"Laser - Pulsing Box","n=5;r=$PI/4;","x=cos(i*$PI*2+r); y=sin(i*$PI*2+r); red=rv; green=gv; blue=bv;","rv=rv*0.93; gv=gv*0.93; bv=bv*0.93;","bv=blue; gv=green;rv=red;"},
  325. #else
  326. {IDS_SPIRAL,"n=800","d=i+v*0.2; r=t+i*$PI*4; x=cos(r)*d; y=sin(r)*d","t=t-0.05",""},
  327. {IDS_3D_SCOPE_DISH, "n=200","iz=1.3+sin(r+i*$PI*2)*(v+0.5)*0.88; ix=cos(r+i*$PI*2)*(v+0.5)*.88; iy=-0.3+abs(cos(v*$PI)); x=ix/iz;y=iy/iz;","",""},
  328. {IDS_ROTATING_BOW_THING,"n=80;t=0.0;","r=i*$PI*2; d=sin(r*3)+v*0.5; x=cos(t+r)*d; y=sin(t-r)*d","t=t+0.01",""},
  329. {IDS_VERTICAL_BOUNCING_SCOPE,"n=100; t=0; tv=0.1;dt=1;","x=t+v*pow(sin(i*$PI),2); y=i*2-1.0;","t=t*0.9+tv*0.1","tv=((rand(50.0)/50.0))*dt; dt=-dt;"},
  330. {IDS_SPIRAL_GRAPH_FUN,"n=100;t=0;","r=i*$PI*128+t; x=cos(r/64)*0.7+sin(r)*0.3; y=sin(r/64)*0.7+cos(r)*0.3","t=t+0.01;","n=80+rand(120.0)"},
  331. {IDS_ALTERNATING_DIAGONAL_SCOPE,"n=64; t=1;","sc=0.4*sin(i*$PI); x=2*(i-0.5-v*sc)*t; y=2*(i-0.5+v*sc);","","t=-t;"},
  332. {IDS_VIBRATING_WORM,"n=w; dt=0.01; t=0; sc=1;","x=cos(2*i+t)*0.9*(v*0.5+0.5); y=sin(i*2+t)*0.9*(v*0.5+0.5);","t=t+dt;dt=0.9*dt+0.001; t=if(above(t,$PI*2),t-$PI*2,t);","dt=sc;sc=-sc;"},
  333. {IDS_WANDERING_SIMPLE,"n=800;xa=-0.5;ya=0.0;xb=-0.0;yb=0.75;c=200;f=0;\r\nnxa=(rand(100)-50)*.02;nya=(rand(100)-50)*.02;\r\nnxb=(rand(100)-50)*.02;nyb=(rand(100)-50)*.02;","//primary render\r\nx=(ex*i)+xa;\r\ny=(ey*i)+ya;\r\n\r\n//volume offset\r\nx=x+ ( cos(r) * v * dv);\r\ny=y+ ( sin(r) * v * dv);\r\n\r\n//color values\r\nred=i;\r\ngreen=(1-i);\r\nblue=abs(v*6);","f=f+1;\r\nt=1-((cos((f*3.1415)/c)+1)*.5);\r\nxa=((nxa-lxa)*t)+lxa;\r\nya=((nya-lya)*t)+lya;\r\nxb=((nxb-lxb)*t)+lxb;\r\nyb=((nyb-lyb)*t)+lyb;\r\nex=(xb-xa);\r\ney=(yb-ya);\r\nd=sqrt(sqr(ex)+sqr(ey));\r\nr=atan(ey/ex)+(3.1415/2);\r\ndv=d*2","c=f;\r\nf=0;\r\nlxa=nxa;\r\nlya=nya;\r\nlxb=nxb;\r\nlyb=nyb;\r\nnxa=(rand(100)-50)*.02;\r\nnya=(rand(100)-50)*.02;\r\nnxb=(rand(100)-50)*.02;\r\nnyb=(rand(100)-50)*.02"},
  334. {IDS_FLITTERBUG,"n=180;t=0.0;lx=0;ly=0;vx=rand(200)-100;vy=rand(200)-100;cf=.97;c=200;f=0","x=nx;y=ny;\r\nr=i*3.14159*2; d=(sin(r*5*(1-s))+i*0.5)*(.3-s);\r\ntx=(t*(1-(s*(i-.5))));\r\nx=x+cos(tx+r)*d; y=y+sin(t-y)*d;\r\nred=abs(x-nx)*5;\r\ngreen=abs(y-ny)*5;\r\nblue=1-s-red-green;","f=f+1;t=(f*2*3.1415)/c;\r\nvx=(vx-(lx*.1))*cf;\r\nvy=(vy-(ly*.1))*cf;\r\nlx=lx+vx;ly=ly+vy;\r\nnx=lx*.001;ny=ly*.001;\r\ns=abs(nx*ny)","c=f;f=0;\r\nvx=vx+rand(600)-300;vy=vy+rand(600)-300"},
  335. {IDS_SPIROSTAR,"n=20;t=0;f=0;c=200;mn=10;dv=2;dn=0","r=if(b,0,((i*dv)*3.14159*128)+(t/2));\r\nx=cos(r)*sz;\r\ny=sin(r)*sz;","f=f+1;t=(f*3.1415*2)/c;\r\nsz=abs(sin(t-3.1415));\r\ndv=if(below(n,12),(n/2)-1,\r\n if(equal(12,n),3,\r\n if(equal(14,n),6,\r\n if(below(n,20),2,4))))","bb = bb + 1;\r\nbeatdiv = 8;\r\nc=if(equal(bb%beatdiv,0),f,c);\r\nf=if(equal(bb%beatdiv,0),0,f);\r\ng=if(equal(bb%beatdiv,0),g+1,g);\r\nn=if(equal(bb%beatdiv,0),(abs((g%17)-8) *2)+4,n);"},
  336. {IDS_EXPLODING_DAISY,"n = 380 + rand(200) ; k = 0.0; l = 0.0; m = ( rand( 10 ) + 2 ) * .5; c = 0; f = 0","r=(i*3.14159*2)+(a * 3.1415);\r\nd=sin(r*m)*.3;\r\nx=cos(k+r)*d*2;y=( (sin(k-r)*d) + ( sin(l*(i-.5) ) ) ) * .7;\r\nred=abs(x);\r\ngreen=abs(y);\r\nblue=d","a = a + 0.002 ; k = k + 0.04 ; l = l + 0.03","bb = bb + 1;\r\nbeatdiv = 16;\r\nn=if(equal(bb%beatdiv,0),380 + rand(200),n);\r\nt=if(equal(bb%beatdiv,0),0.0,t);\r\na=if(equal(bb%beatdiv,0),0.0,a);\r\nk=if(equal(bb%beatdiv,0),0.0,k);\r\nl=if(equal(bb%beatdiv,0),0.0,l);\r\nm=if(equal(bb%beatdiv,0),(( rand( 100 ) + 2 ) * .1) + 2,m);"},
  337. {IDS_SWIRLIE_DOTS,"n=45;t=rand(100);u=rand(100)","di = ( i - .5) * 2;\r\nx = di;sin(u*di) * .4;\r\ny = cos(u*di) * .6;\r\nx = x + ( cos(t) * .05 );\r\ny = y + ( sin(t) * .05 );","t = t + .15; u = u + .05","bb = bb + 1;\r\nbeatdiv = 16;\r\nn = if(equal(bb%beatdiv,0),30 + rand( 30 ),n);"},
  338. {IDS_SWEEP,"n=180;lsv=100;sv=200;ssv=200;c=200;f=0","sv=(sv*abs(cos(lsv)))+(lsv*abs(cos(sv)));\r\nfv=fv+(sin(sv)*dv);\r\nd=i; r=t+(fv * sin(t) * .3)*3.14159*4;\r\nx=cos(r)*d;\r\ny=sin(r)*d;\r\nred=i;\r\ngreen=abs(sin(r))-(red*.15);\r\nblue=fv","f=f+1;t=(f*2*3.1415)/c;\r\nlsv=slsv;sv=ssv;fv=0","bb = bb + 1;\r\nbeatdiv = 8;\r\nc=if(equal(bb%beatdiv,0),f,c);\r\nf=if(equal(bb%beatdiv,0),0,f);\r\ndv=if(equal(bb%beatdiv,0),((rand(100)*.01) * .1) + .02,dv);\r\nn=if(equal(bb%beatdiv,0),80+rand(100),n);\r\nssv=if(equal(bb%beatdiv,0),rand(200)+100,ssv);\r\nslsv=if(equal(bb%beatdiv,0),rand(200)+100,slsv);"},
  339. {IDS_WHIPLASH_SPIRAL,"n=80;c=200;f=0","d=i;\r\nr=t+i*3.14159*4;\r\nsdt=sin(dt+(i*3.1415*2));\r\ncdt=cos(dt+(i*3.1415*2));\r\nx=(cos(r)*d) + (sdt * .6 * sin(t) );\r\ny=(sin(r)*d) + ( cdt *.6 * sin(t) );\r\nblue=abs(x);\r\ngreen=abs(y);\r\nred=cos(dt*4)","t=t-0.05;f=f+1;dt=(f*2*3.1415)/c","bb = bb + 1;\r\nbeatdiv = 8;\r\nc=if(equal(bb%beatdiv,0),f,c);\r\nf=if(equal(bb%beatdiv,0),0,f);"},
  340. #endif
  341. };
  342. static C_THISCLASS *g_this;
  343. BOOL CALLBACK C_THISCLASS::g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  344. {
  345. static int isstart;
  346. switch (uMsg)
  347. {
  348. case WM_INITDIALOG:
  349. isstart=1;
  350. #if 0//syntax highlighting
  351. SendDlgItemMessage(hwndDlg,IDC_EDIT1,EM_SETEVENTMASK,0,ENM_CHANGE);
  352. SendDlgItemMessage(hwndDlg,IDC_EDIT2,EM_SETEVENTMASK,0,ENM_CHANGE);
  353. SendDlgItemMessage(hwndDlg,IDC_EDIT3,EM_SETEVENTMASK,0,ENM_CHANGE);
  354. SendDlgItemMessage(hwndDlg,IDC_EDIT4,EM_SETEVENTMASK,0,ENM_CHANGE);
  355. #endif
  356. SetDlgItemInt(hwndDlg,IDC_NUMCOL,g_this->num_colors,FALSE);
  357. SetDlgItemText(hwndDlg,IDC_EDIT1,g_this->effect_exp[0].get());
  358. SetDlgItemText(hwndDlg,IDC_EDIT2,g_this->effect_exp[1].get());
  359. SetDlgItemText(hwndDlg,IDC_EDIT3,g_this->effect_exp[2].get());
  360. SetDlgItemText(hwndDlg,IDC_EDIT4,g_this->effect_exp[3].get());
  361. #if 0//syntax highlighting
  362. doAVSEvalHighLight(hwndDlg,IDC_EDIT1,g_this->effect_exp[0].get());
  363. doAVSEvalHighLight(hwndDlg,IDC_EDIT2,g_this->effect_exp[1].get());
  364. doAVSEvalHighLight(hwndDlg,IDC_EDIT3,g_this->effect_exp[2].get());
  365. doAVSEvalHighLight(hwndDlg,IDC_EDIT4,g_this->effect_exp[3].get());
  366. #endif
  367. CheckDlgButton(hwndDlg,g_this->mode?IDC_LINES:IDC_DOT,BST_CHECKED);
  368. if ((g_this->which_ch&3)==0)
  369. CheckDlgButton(hwndDlg,IDC_LEFTCH,BST_CHECKED);
  370. else if ((g_this->which_ch&3)==1)
  371. CheckDlgButton(hwndDlg,IDC_RIGHTCH,BST_CHECKED);
  372. else
  373. CheckDlgButton(hwndDlg,IDC_MIDCH,BST_CHECKED);
  374. if (g_this->which_ch&4)
  375. CheckDlgButton(hwndDlg,IDC_SPEC,BST_CHECKED);
  376. else
  377. CheckDlgButton(hwndDlg,IDC_WAVE,BST_CHECKED);
  378. isstart=0;
  379. return 1;
  380. case WM_DRAWITEM:
  381. {
  382. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  383. if (di->CtlID == IDC_DEFCOL && g_this->num_colors>0)
  384. {
  385. int x;
  386. int w=di->rcItem.right-di->rcItem.left;
  387. int l=0,nl;
  388. for (x = 0; x < g_this->num_colors; x ++)
  389. {
  390. int color=g_this->colors[x];
  391. nl = (w*(x+1))/g_this->num_colors;
  392. color = ((color>>16)&0xff)|(color&0xff00)|((color<<16)&0xff0000);
  393. HPEN hPen,hOldPen;
  394. HBRUSH hBrush,hOldBrush;
  395. LOGBRUSH lb={(COLORREF)BS_SOLID,(COLORREF)color,(COLORREF)0};
  396. hPen = (HPEN)CreatePen(PS_SOLID,0,color);
  397. hBrush = CreateBrushIndirect(&lb);
  398. hOldPen=(HPEN)SelectObject(di->hDC,hPen);
  399. hOldBrush=(HBRUSH)SelectObject(di->hDC,hBrush);
  400. Rectangle(di->hDC,di->rcItem.left+l,di->rcItem.top,di->rcItem.left+nl,di->rcItem.bottom);
  401. SelectObject(di->hDC,hOldPen);
  402. SelectObject(di->hDC,hOldBrush);
  403. DeleteObject(hBrush);
  404. DeleteObject(hPen);
  405. l=nl;
  406. }
  407. }
  408. }
  409. return 0;
  410. case WM_COMMAND:
  411. if (!isstart)
  412. {
  413. if ((LOWORD(wParam) == IDC_EDIT1||LOWORD(wParam) == IDC_EDIT2||LOWORD(wParam) == IDC_EDIT3||LOWORD(wParam) == IDC_EDIT4) && HIWORD(wParam) == EN_CHANGE)
  414. {
  415. EnterCriticalSection(&g_this->rcs);
  416. g_this->effect_exp[0].get_from_dlgitem(hwndDlg,IDC_EDIT1);
  417. g_this->effect_exp[1].get_from_dlgitem(hwndDlg,IDC_EDIT2);
  418. g_this->effect_exp[2].get_from_dlgitem(hwndDlg,IDC_EDIT3);
  419. g_this->effect_exp[3].get_from_dlgitem(hwndDlg,IDC_EDIT4);
  420. g_this->need_recompile=1;
  421. if (LOWORD(wParam) == IDC_EDIT4) g_this->inited = 0;
  422. LeaveCriticalSection(&g_this->rcs);
  423. #if 0//syntax highlighting
  424. if (LOWORD(wParam) == IDC_EDIT1)
  425. doAVSEvalHighLight(hwndDlg,IDC_EDIT1,g_this->effect_exp[0].get());
  426. if (LOWORD(wParam) == IDC_EDIT2)
  427. doAVSEvalHighLight(hwndDlg,IDC_EDIT2,g_this->effect_exp[1].get());
  428. if (LOWORD(wParam) == IDC_EDIT3)
  429. doAVSEvalHighLight(hwndDlg,IDC_EDIT3,g_this->effect_exp[2].get());
  430. if (LOWORD(wParam) == IDC_EDIT4)
  431. doAVSEvalHighLight(hwndDlg,IDC_EDIT4,g_this->effect_exp[3].get());
  432. #endif
  433. }
  434. if (LOWORD(wParam) == IDC_DOT || LOWORD(wParam) == IDC_LINES)
  435. {
  436. g_this->mode=IsDlgButtonChecked(hwndDlg,IDC_LINES)?1:0;
  437. }
  438. if (LOWORD(wParam) == IDC_WAVE || LOWORD(wParam) == IDC_SPEC)
  439. {
  440. if (IsDlgButtonChecked(hwndDlg,IDC_WAVE)) g_this->which_ch&=~4;
  441. else g_this->which_ch|=4;
  442. }
  443. if (LOWORD(wParam) == IDC_LEFTCH || LOWORD(wParam) == IDC_RIGHTCH || LOWORD(wParam)==IDC_MIDCH)
  444. {
  445. g_this->which_ch&=~3;
  446. if (IsDlgButtonChecked(hwndDlg,IDC_LEFTCH));
  447. else if (IsDlgButtonChecked(hwndDlg,IDC_RIGHTCH)) g_this->which_ch|=1;
  448. else g_this->which_ch|=2;
  449. }
  450. }
  451. if (LOWORD(wParam) == IDC_BUTTON2)
  452. {
  453. /*
  454. char text[4096];
  455. WASABI_API_LNGSTRING_BUF(IDS_SUPERSCOPE,text,4096);
  456. int titlelen = lstrlen(text)+1;
  457. lstrcpyn(text+titlelen,GetTextResource(IDR_SUPERSCOPE),4095-titlelen);
  458. */
  459. char *text="Superscope\0"
  460. "Superscope tutorial:\r\n\n"
  461. // "But for now, here is the old text:\r\n"
  462. "You can specify expressions that run on Init, Frame, and on Beat.\r\n"
  463. " 'n' specifies the number of points to render (set this in Init, Beat, or Frame).\r\n"
  464. "For the 'Per Point' expression (which happens 'n' times per frame), use:\r\n"
  465. " 'x' and 'y' are the coordinates to draw to (-1..1)\r\n"
  466. " 'i' is the position of the scope (0..1)\r\n"
  467. " 'v' is the value at that point (-1..1).\r\n"
  468. " 'b' is 1 if beat, 0 if not.\r\n"
  469. " 'red', 'green' and 'blue' are all (0..1) and can be modified\r\n"
  470. " 'linesize' can be set from 1.0 to 255.0\r\n"
  471. " 'skip' can be set to >0 to skip drawing the current item\r\n"
  472. " 'drawmode' can be set to > 0 for lines, <= 0 for points\r\n"
  473. " 'w' and 'h' are the width and height of the screen, in pixels.\r\n"
  474. // " Anybody want to send me better text to put here? Please :)\r\n"
  475. ;
  476. compilerfunctionlist(hwndDlg,text);
  477. }
  478. if (LOWORD(wParam) == IDC_BUTTON1)
  479. {
  480. RECT r;
  481. HMENU hMenu;
  482. MENUITEMINFO i={sizeof(i),};
  483. hMenu=CreatePopupMenu();
  484. int x;
  485. for (x = 0; x < sizeof(presets)/sizeof(presets[0]); x ++)
  486. {
  487. i.fMask=MIIM_TYPE|MIIM_DATA|MIIM_ID;
  488. i.fType=MFT_STRING;
  489. i.wID = x+16;
  490. i.dwTypeData=WASABI_API_LNGSTRING(presets[x].name);
  491. i.cch=strlen(i.dwTypeData);
  492. InsertMenuItem(hMenu,x,TRUE,&i);
  493. }
  494. GetWindowRect(GetDlgItem(hwndDlg,IDC_BUTTON1),&r);
  495. x=TrackPopupMenu(hMenu,TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON|TPM_LEFTBUTTON|TPM_NONOTIFY,r.right,r.top,0,hwndDlg,NULL);
  496. if (x >= 16 && x < 16+sizeof(presets)/sizeof(presets[0]))
  497. {
  498. SetDlgItemText(hwndDlg,IDC_EDIT1,presets[x-16].point);
  499. SetDlgItemText(hwndDlg,IDC_EDIT2,presets[x-16].frame);
  500. SetDlgItemText(hwndDlg,IDC_EDIT3,presets[x-16].beat);
  501. SetDlgItemText(hwndDlg,IDC_EDIT4,presets[x-16].init);
  502. SendMessage(hwndDlg,WM_COMMAND,MAKEWPARAM(IDC_EDIT4,EN_CHANGE),0);
  503. }
  504. DestroyMenu(hMenu);
  505. }
  506. if (LOWORD(wParam) == IDC_NUMCOL)
  507. {
  508. int p;
  509. BOOL tr=FALSE;
  510. p=GetDlgItemInt(hwndDlg,IDC_NUMCOL,&tr,FALSE);
  511. if (tr)
  512. {
  513. if (p > 16) p = 16;
  514. g_this->num_colors=p;
  515. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  516. }
  517. }
  518. if (LOWORD(wParam) == IDC_DEFCOL)
  519. {
  520. int wc=-1,w,h;
  521. POINT p;
  522. RECT r;
  523. GetCursorPos(&p);
  524. GetWindowRect(GetDlgItem(hwndDlg,IDC_DEFCOL),&r);
  525. p.x -= r.left;
  526. p.y -= r.top;
  527. w=r.right-r.left;
  528. h=r.bottom-r.top;
  529. if (p.x >= 0 && p.x < w && p.y >= 0 && p.y < h)
  530. {
  531. wc = (p.x*g_this->num_colors)/w;
  532. }
  533. if (wc>=0)
  534. {
  535. GR_SelectColor(hwndDlg,g_this->colors+wc);
  536. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  537. }
  538. }
  539. return 0;
  540. }
  541. return 0;
  542. }
  543. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  544. {
  545. g_this = this;
  546. return WASABI_API_CREATEDIALOG(IDD_CFG_SSCOPE,hwndParent,g_DlgProc);
  547. }