sa.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. #include <precomp.h>
  2. #include <api/wnd/popup.h>
  3. #include <api/script/script.h>
  4. #include <api/script/scriptmgr.h>
  5. #include <math.h>
  6. #include <api/skin/skinparse.h>
  7. #include "sa.h"
  8. #include <api/core/api_core.h>
  9. #include <tataki/canvas/bltcanvas.h>
  10. #include "resource.h"
  11. #include "../Agave/Language/api_language.h"
  12. const wchar_t visXuiStr[] = L"Vis"; // This is the xml tag
  13. char visXuiSvcName[] = "Vis xui object"; // this is the name of the xuiservice
  14. // {9149C445-3C30-4e04-8433-5A518ED0FDDE}
  15. const GUID uioptions_guid =
  16. { 0x9149c445, 0x3c30, 0x4e04, { 0x84, 0x33, 0x5a, 0x51, 0x8e, 0xd0, 0xfd, 0xde } };
  17. unsigned char ppal[] = {
  18. #ifdef CLASSIC
  19. 0,0,0, // color 0 = black
  20. 75,72,80, // color 1 = grey for dots
  21. 255,55,16, // color 2 = top of spec
  22. 255,55,16, // 3
  23. 255,80,0, // 4
  24. 255,80,0, // 5
  25. 239,112,0, // 6
  26. 239,112,0, // 7
  27. 255,168,32, // 8
  28. 255,168,32, // 9
  29. 176,255,47, // 10
  30. 176,255,47, // 11
  31. 47,239,0, // 12
  32. 47,239,0, // 13
  33. 48,160,0, // 14
  34. 48,160,0, // 15
  35. 32,128,0, // 16
  36. 32,128,0, // 17 = bottom of spec
  37. 255,255,255, // 18 = osc 1
  38. 214,214,222, // 19 = osc 2 (slightly dimmer)
  39. 181,189,189, // 20 = osc 3
  40. 160,170,175, // 21 = osc 4
  41. 148,156,165, // 22 = osc 4
  42. 150, 150, 150, // 23 = analyzer peak dots
  43. #else
  44. 0,0,0, // color 0 = black
  45. 24,33,41, // color 1 = grey for dots
  46. 239,49,16, // color 2 = top of spec
  47. 206,41,16, // 3
  48. 214,90,0, // 4
  49. 214,102,0, // 5
  50. 214,115,0, // 6
  51. 198,123,8, // 7
  52. 222,165,24, // 8
  53. 214,181,33, // 9
  54. 189,222,41, // 10
  55. 148,222,33, // 11
  56. 41,206,16, // 12
  57. 50,190,16, // 13
  58. 57,181,16, // 14
  59. 49,156,8, // 15
  60. 41,148,0, // 16
  61. 24,132,8, // 17
  62. 255,255,255, // 18 = osc 1
  63. 214,214,222, // 19 = osc 2 (slightly dimmer)
  64. 181,189,189, // 20 = osc 3
  65. 160,170,175, // 21 = osc 4
  66. 148,156,165, // 22 = osc 4
  67. 150, 150, 150, // 23 = analyzer peak
  68. #endif
  69. };
  70. #define CHANNEL_LEFT 1
  71. #define CHANNEL_RIGHT 2
  72. XMLParamPair SAWnd::params[] = {
  73. {SA_SETCOLORALLBANDS, L"COLORALLBANDS"},
  74. {SA_SETCOLORBAND1, L"COLORBAND1"},
  75. {SA_SETCOLORBAND2, L"COLORBAND2"},
  76. {SA_SETCOLORBAND3, L"COLORBAND3"},
  77. {SA_SETCOLORBAND4, L"COLORBAND4"},
  78. {SA_SETCOLORBAND5, L"COLORBAND5"},
  79. {SA_SETCOLORBAND6, L"COLORBAND6"},
  80. {SA_SETCOLORBAND7, L"COLORBAND7"},
  81. {SA_SETCOLORBAND8, L"COLORBAND8"},
  82. {SA_SETCOLORBAND9, L"COLORBAND9"},
  83. {SA_SETCOLORBAND10, L"COLORBAND10"},
  84. {SA_SETCOLORBAND11, L"COLORBAND11"},
  85. {SA_SETCOLORBAND12, L"COLORBAND12"},
  86. {SA_SETCOLORBAND13, L"COLORBAND13"},
  87. {SA_SETCOLORBAND14, L"COLORBAND14"},
  88. {SA_SETCOLORBAND15, L"COLORBAND15"},
  89. {SA_SETCOLORBAND16, L"COLORBAND16"},
  90. {SA_SETCOLORBANDPEAK, L"COLORBANDPEAK"},
  91. {SA_SETCOLORALLOSC, L"COLORALLOSC"},
  92. {SA_SETCOLOROSC1, L"COLOROSC1"},
  93. {SA_SETCOLOROSC2, L"COLOROSC2"},
  94. {SA_SETCOLOROSC3, L"COLOROSC3"},
  95. {SA_SETCOLOROSC4, L"COLOROSC4"},
  96. {SA_SETCOLOROSC5, L"COLOROSC5"},
  97. {SA_SETCHANNEL, L"CHANNEL"},
  98. {SA_SETFLIPH, L"FLIPH"},
  99. {SA_SETFLIPV, L"FLIPV"},
  100. {SA_SETMODE, L"MODE"},
  101. {SA_SETGAMMA, L"GAMMAGROUP"},
  102. {SA_SETFALLOFF, L"FALLOFF"},
  103. {SA_SETPEAKFALLOFF, L"PEAKFALLOFF"},
  104. {SA_SETBANDWIDTH, L"BANDWIDTH"},
  105. {SA_FPS, L"FPS"},
  106. {SA_COLORING, L"COLORING"},
  107. {SA_PEAKS, L"PEAKS"},
  108. {SA_OSCDRAWSTYLE, L"OSCSTYLE"},
  109. };
  110. SAWnd::SAWnd()
  111. {
  112. filtergroup = SA_PARENT::getFiltersGroup();
  113. getScriptObject()->vcpu_setInterface(visGuid, (void *)static_cast<SAWnd *>(this));
  114. getScriptObject()->vcpu_setClassName(L"Vis");
  115. getScriptObject()->vcpu_setController(visController);
  116. char *p = (char *)&ppal;
  117. for (int i=0;i<72;i++) {
  118. palette[i] = ((*p)<<16) + ((*(p+1))<<8) + *(p+2);
  119. p += 3;
  120. }
  121. setRealtime(1);
  122. startQuickPaint();
  123. config_sa=-1; // default value
  124. #ifdef WASABI_COMPILE_CONFIG
  125. {
  126. CfgItem *ci=WASABI_API_CONFIG->config_getCfgItemByGuid(uioptions_guid);
  127. if(ci) {
  128. config_sa=ci->getDataAsInt(L"Spectrum analyzer mode");
  129. viewer_addViewItem(ci->getDependencyPtr());
  130. }
  131. }
  132. saveconfsa=0;
  133. #endif
  134. flip_v = 0;
  135. flip_h = 0;
  136. channel = CHANNEL_LEFT | CHANNEL_RIGHT;
  137. off = 0;
  138. config_safalloff=2;
  139. config_sa_peak_falloff=1;
  140. config_safire=4;
  141. config_sa_peaks=1;
  142. memset(bx, 0, sizeof(bx));
  143. memset(t_bx, 0, sizeof(t_bx));
  144. memset(t_vx, 0, sizeof(t_vx));
  145. xuihandle = newXuiHandle();
  146. CreateXMLParameters(xuihandle);
  147. }
  148. void SAWnd::CreateXMLParameters(int master_handle)
  149. {
  150. //SA_PARENT::CreateXMLParameters(master_handle);
  151. int numParams = sizeof(params) / sizeof(params[0]);
  152. hintNumberOfParams(xuihandle, numParams);
  153. for (int i = 0;i < numParams;i++)
  154. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  155. }
  156. int SAWnd::onInit() {
  157. SA_PARENT::onInit();
  158. #ifdef WASABI_COMPILE_CONFIG
  159. if(config_sa==-1) {
  160. Layout *pl=getGuiObject()->guiobject_getParentLayout();
  161. if (pl->getParentContainer()) {
  162. confsaname.printf(L"%s/%s/%s/config_sa",WASABI_API_SKIN->getSkinName(),pl->getParentContainer()->getName(),pl->getName());
  163. config_sa=WASABI_API_CONFIG->getIntPrivate(confsaname,1);
  164. saveconfsa=1;
  165. }
  166. }
  167. #endif
  168. return 1;
  169. }
  170. SAWnd::~SAWnd()
  171. {
  172. #ifdef WASABI_COMPILE_CONFIG
  173. if(saveconfsa)
  174. WASABI_API_CONFIG->setIntPrivate(confsaname,config_sa);
  175. #endif
  176. }
  177. int SAWnd::setXuiParam(int _xuihandle, int attrid, const wchar_t *pname, const wchar_t *str) {
  178. if (_xuihandle != xuihandle) return SA_PARENT::setXuiParam(_xuihandle, attrid, pname, str);
  179. switch (attrid) {
  180. case SA_SETCOLORALLBANDS:
  181. setBandColor(-1, SkinParser::parseColor(str));
  182. break;
  183. case SA_SETCOLORBAND1:
  184. setBandColor(15, SkinParser::parseColor(str));
  185. break;
  186. case SA_SETCOLORBAND2:
  187. setBandColor(14, SkinParser::parseColor(str));
  188. break;
  189. case SA_SETCOLORBAND3:
  190. setBandColor(13, SkinParser::parseColor(str));
  191. break;
  192. case SA_SETCOLORBAND4:
  193. setBandColor(12, SkinParser::parseColor(str));
  194. break;
  195. case SA_SETCOLORBAND5:
  196. setBandColor(11, SkinParser::parseColor(str));
  197. break;
  198. case SA_SETCOLORBAND6:
  199. setBandColor(10, SkinParser::parseColor(str));
  200. break;
  201. case SA_SETCOLORBAND7:
  202. setBandColor(9, SkinParser::parseColor(str));
  203. break;
  204. case SA_SETCOLORBAND8:
  205. setBandColor(8, SkinParser::parseColor(str));
  206. break;
  207. case SA_SETCOLORBAND9:
  208. setBandColor(7, SkinParser::parseColor(str));
  209. break;
  210. case SA_SETCOLORBAND10:
  211. setBandColor(6, SkinParser::parseColor(str));
  212. break;
  213. case SA_SETCOLORBAND11:
  214. setBandColor(5, SkinParser::parseColor(str));
  215. break;
  216. case SA_SETCOLORBAND12:
  217. setBandColor(4, SkinParser::parseColor(str));
  218. break;
  219. case SA_SETCOLORBAND13:
  220. setBandColor(3, SkinParser::parseColor(str));
  221. break;
  222. case SA_SETCOLORBAND14:
  223. setBandColor(2, SkinParser::parseColor(str));
  224. break;
  225. case SA_SETCOLORBAND15:
  226. setBandColor(1, SkinParser::parseColor(str));
  227. break;
  228. case SA_SETCOLORBAND16:
  229. setBandColor(0, SkinParser::parseColor(str));
  230. break;
  231. case SA_SETCOLORBANDPEAK:
  232. setPeakColor(SkinParser::parseColor(str));
  233. break;
  234. case SA_SETCOLORALLOSC:
  235. setOscColor(-1, SkinParser::parseColor(str));
  236. break;
  237. case SA_SETCOLOROSC1:
  238. setOscColor(0, SkinParser::parseColor(str));
  239. break;
  240. case SA_SETCOLOROSC2:
  241. setOscColor(1, SkinParser::parseColor(str));
  242. break;
  243. case SA_SETCOLOROSC3:
  244. setOscColor(2, SkinParser::parseColor(str));
  245. break;
  246. case SA_SETCOLOROSC4:
  247. setOscColor(3, SkinParser::parseColor(str));
  248. break;
  249. case SA_SETCOLOROSC5:
  250. setOscColor(4, SkinParser::parseColor(str));
  251. break;
  252. case SA_SETCHANNEL:
  253. setChannel(WTOI(str));
  254. break;
  255. case SA_SETFLIPH:
  256. setFlipH(WTOI(str));
  257. break;
  258. case SA_SETFLIPV:
  259. setFlipV(WTOI(str));
  260. break;
  261. case SA_SETMODE:
  262. setMode(WTOI(str));
  263. break;
  264. case SA_SETGAMMA:
  265. filtergroup = str;
  266. break;
  267. case SA_SETFALLOFF:
  268. config_safalloff = WTOI(str);
  269. break;
  270. case SA_SETPEAKFALLOFF:
  271. config_sa_peak_falloff=WTOI(str);
  272. break;
  273. case SA_SETBANDWIDTH:
  274. if (WCSCASEEQLSAFE(str, L"wide"))
  275. config_safire &= (~32);
  276. else if (WCSCASEEQLSAFE(str, L"thin"))
  277. config_safire |= 32;
  278. break;
  279. case SA_FPS:
  280. {
  281. int fps = WTOI(str);
  282. if (fps)
  283. setSpeed(1000/fps);
  284. }
  285. break;
  286. case SA_COLORING:
  287. if (WCSCASEEQLSAFE(str, L"fire"))
  288. config_safire = (config_safire&~3) | 1;
  289. else if (WCSCASEEQLSAFE(str, L"normal"))
  290. config_safire = (config_safire&~3) | 0;
  291. else if (WCSCASEEQLSAFE(str, L"line"))
  292. config_safire = (config_safire&~3) | 2;
  293. break;
  294. case SA_PEAKS:
  295. if (str && WTOI(str))
  296. config_sa_peaks=1;
  297. else
  298. config_sa_peaks=0;
  299. break;
  300. case SA_OSCDRAWSTYLE:
  301. if (WCSCASEEQLSAFE(str, L"dots"))
  302. config_safire = (config_safire & ~(3<<2)) | 0;
  303. else if (WCSCASEEQLSAFE(str, L"solid"))
  304. config_safire = (config_safire & ~(3<<2)) | 4;
  305. else if (WCSCASEEQLSAFE(str, L"lines"))
  306. config_safire = (config_safire & ~(3<<2)) | 8;
  307. break;
  308. default:
  309. return 0;
  310. }
  311. return 1;
  312. }
  313. void SAWnd::setChannel(int c) {
  314. channel = c;
  315. }
  316. void SAWnd::setFlipH(int v) {
  317. if (v == flip_h) return;
  318. flip_h = v;
  319. invalidate();
  320. }
  321. void SAWnd::setFlipV(int v) {
  322. if (v == flip_v) return;
  323. flip_v = v;
  324. invalidate();
  325. }
  326. void SAWnd::setBandColor(int band, ARGB32 col) {
  327. if (band == -1) {
  328. for (int i=0;i<16;i++)
  329. palette[i+2] = RGBTOBGR(col);
  330. } else
  331. palette[band+2] = RGBTOBGR(col);
  332. }
  333. void SAWnd::setOscColor(int n, ARGB32 col) {
  334. if (n == -1) {
  335. for (int i=0;i<4;i++)
  336. palette[i+18] = RGBTOBGR(col);
  337. } else
  338. palette[n+18] = RGBTOBGR(col);
  339. }
  340. void SAWnd::setPeakColor(ARGB32 col) {
  341. palette[23] = RGBTOBGR(col);
  342. }
  343. #define SA_BLEND(c) (palette[c] | 0xFF000000) //(alpha << 24))
  344. int SAWnd::onQuickPaint(BltCanvas *bc, int w, int h, int newone) {
  345. if(!isVisible()) return 0;
  346. #ifdef WASABI_COMPILE_MEDIACORE
  347. int x;
  348. int fo[5] = {3, 6, 12, 16, 32 };
  349. float pfo[5]={1.05f,1.1f,1.2f,1.4f,1.6f};
  350. specData=(int *)bc->getBits();
  351. if (newone || !config_sa)
  352. MEMSET(specData,0,76*16*4*4);
  353. if(!config_sa) {
  354. if (!off) {
  355. off = 1;
  356. return 1;
  357. }
  358. return 0;
  359. }
  360. off = 0;
  361. char visdata[576*2*2] = {0};
  362. unsigned char *values=(unsigned char *)visdata;
  363. int ret=WASABI_API_MEDIACORE->core_getVisData(0,visdata,sizeof(visdata));
  364. if (!ret) {
  365. MEMSET(visdata,0,sizeof(visdata));
  366. } else if (ret == 75*2) {
  367. if (config_sa==2) values+=75;
  368. } else {
  369. if(config_sa==1) {
  370. register int v;
  371. for(int x=0;x<75;x++) {
  372. v=values[x]+values[576+x];
  373. v>>=4;
  374. values[x]=v;
  375. }
  376. }
  377. if (config_sa==2) {
  378. values+=576*2;
  379. register int v;
  380. register char *blah=(char *)values;
  381. for(int x=0;x<75;x++) {
  382. v=blah[x*4]+blah[576+(x*4)];
  383. v>>=4;
  384. blah[x]=v;
  385. }
  386. }
  387. }
  388. // int ws=(config_windowshade&&config_mw_open);
  389. // int s = (config_dsize&&config_mw_open)?1:0;
  390. int dbx = fo[max(min(config_safalloff,4),0)];
  391. float spfo=pfo[max(min(config_sa_peak_falloff,4),0)];
  392. MEMSET(specData,0,76*16*4*4);
  393. {
  394. {
  395. if (config_sa == 2)
  396. {
  397. int *gmem = specData;
  398. {
  399. int lv=-1;
  400. if (((config_safire>>2)&3)==0) for (x = 0; x < 75; x ++)
  401. {
  402. register int v; register char c;
  403. v = (((int) ((signed char *)values)[x])) + 8;
  404. if (v < 0) v = 0 ; if (v > 15) v = 15; c = v/2-4; if (c < 0) c = -c; c += 18;
  405. gmem[v*76*2] = SA_BLEND(c);
  406. gmem++;
  407. }
  408. else if (((config_safire>>2)&3)==1) for (x = 0; x < 75; x ++)
  409. {
  410. register int v,t; register char c;
  411. v = (((int) ((signed char *)values)[x])) + 8;
  412. if (v < 0) v = 0 ; if (v > 15) v = 15; c = v/2-4; if (c < 0) c = -c; c += 18;
  413. if (lv == -1) lv=v;
  414. t=lv;
  415. lv=v;
  416. if (v >= t) while (v >= t) gmem[v--*76*2] = SA_BLEND(c);
  417. else while (v < t) gmem[v++*76*2] = SA_BLEND(c);
  418. gmem++;
  419. }
  420. else if (((config_safire>>2)&3)==2) for (x = 0; x < 75; x ++) // solid
  421. {
  422. register int v; register char c;
  423. v = (((int) ((signed char *)values)[x])) + 8;
  424. if (v < 0) v = 0 ; if (v > 15) v = 15; c = v/2-4; if (c < 0) c = -c; c += 18;
  425. if (v > 7) while (v > 7) gmem[v--*76*2] = SA_BLEND(c);
  426. else while (v <= 7) gmem[v++*76*2] = SA_BLEND(c);
  427. gmem++;
  428. }
  429. }
  430. }
  431. else
  432. {
  433. for (x = 0; x < 75; x ++)
  434. {
  435. register int y,v,t;
  436. #ifndef CLASSIC
  437. t=x&~3;
  438. #else
  439. t=x-(x%6);
  440. #endif
  441. if (!(config_safire&32))
  442. {
  443. int a=values[t],b=values[t+1],c=values[t+2],d=values[t+3];
  444. #ifndef CLASSIC
  445. v = a+b+c+d;//-min(a,min(b,min(c,d)));
  446. v/=4;
  447. #else
  448. v = a+b+c+d+(int)values[t+4]+(int)values[t+5];//-min(a,min(b,min(c,d)));
  449. v/=6;
  450. #endif
  451. }
  452. else v = (((int)values[x]));
  453. if (v > 15) v = 15;
  454. if ((v<<4) < bx[x]) v = (bx[x]-=dbx)>>4;
  455. else bx[x] = v<<4;
  456. if (bx[x] < 0) bx[x] = 0;
  457. if (v < 0) v = 0;
  458. int *gmem = specData + 76*2*15 + x;
  459. if ((config_safire&3)==1) t = v+2;
  460. else if ((config_safire&3)==2) t=17-(v);
  461. else t = 17;
  462. if (t_bx[x] <= v*256) {
  463. t_bx[x]=v*256;
  464. t_vx[x]=3.0f;
  465. }
  466. #ifndef CLASSIC
  467. if ((config_safire&32 || (x&3)!=3))
  468. {
  469. if ((config_safire&3)!=2) for (y = 0; y < v; y ++)
  470. {
  471. *gmem = SA_BLEND(t-y);
  472. gmem -= 76*2;
  473. }
  474. else for (y = 0; y < v; y ++)
  475. {
  476. *gmem = SA_BLEND(t);
  477. gmem -= 76*2;
  478. }
  479. #else
  480. if ((config_safire&32 || (!(x&1) && (x%6) < 4)))
  481. {
  482. if ((config_safire&3)!=2) for (y = 0; y < v/2; y ++)
  483. {
  484. *gmem = SA_BLEND(t-y*2);
  485. gmem -= 76*2*2;
  486. }
  487. else for (y = 0; y < v/2; y ++)
  488. {
  489. *gmem = SA_BLEND(t);
  490. gmem -= 76*2*2;
  491. }
  492. #endif
  493. #ifndef CLASSIC
  494. if (config_sa_peaks && t_bx[x]/256 >= 0 && t_bx[x]/256 <= 15)
  495. {
  496. specData[76*2*15 - (t_bx[x]/256)*76*2 + x]=SA_BLEND(23);
  497. }
  498. #endif
  499. }
  500. t_bx[x] -= (int)t_vx[x];
  501. t_vx[x] *= spfo;
  502. if (t_bx[x] < 0) t_bx[x]=0;
  503. }
  504. }
  505. }
  506. }
  507. if (flip_v)
  508. bc->vflip(2);
  509. if (flip_h)
  510. bc->hflip(2);
  511. invalidated = 1; // rerun filter
  512. #endif //mediacore
  513. return 1;
  514. }
  515. int SAWnd::onLeftButtonDown(int x, int y) {
  516. SA_PARENT::onLeftButtonDown(x, y);
  517. if (!WASABI_API_MAKI->vcpu_getComplete()) {
  518. nextMode();
  519. #ifdef WASABI_COMPILE_CONFIG
  520. CfgItem *ci=WASABI_API_CONFIG->config_getCfgItemByGuid(uioptions_guid);
  521. if(ci) ci->setDataAsInt(L"Spectrum analyzer mode",config_sa);
  522. #endif
  523. }
  524. return 1;
  525. }
  526. void SAWnd::nextMode() {
  527. config_sa++;
  528. if(config_sa>2) config_sa=0;
  529. }
  530. void SAWnd::setMode(int mode) {
  531. config_sa=mode;
  532. if(config_sa>2) config_sa=0;
  533. }
  534. int SAWnd::getMode() {
  535. return config_sa;
  536. }
  537. int SAWnd::onRightButtonUp(int x, int y)
  538. {
  539. SA_PARENT::onRightButtonUp(x, y);
  540. PopupMenu menu (this);
  541. menu.addCommand(WASABI_API_LNGSTRINGW(IDS_NO_VISUALISATION)/*"No visualization"*/, 0, config_sa==0, FALSE);
  542. menu.addCommand(WASABI_API_LNGSTRINGW(IDS_SPECTRUM_ANALYZER)/*L"Spectrum analyzer"*/, 1, config_sa==1, FALSE);
  543. menu.addCommand(WASABI_API_LNGSTRINGW(IDS_OSCILLOSCOPE)/*L"Oscilloscope"*/, 2, config_sa==2, FALSE);
  544. clientToScreen(&x, &y);
  545. int ret = menu.popAtXY(x,y);
  546. #ifdef WASABI_COMPILE_CONFIG
  547. if(ret>=0)
  548. {
  549. config_sa=ret;
  550. CfgItem *ci=WASABI_API_CONFIG->config_getCfgItemByGuid(uioptions_guid);
  551. if(ci) ci->setDataAsInt(L"Spectrum analyzer mode",config_sa);
  552. }
  553. #endif
  554. WASABI_API_MAKI->vcpu_setComplete();
  555. return 1;
  556. }
  557. int SAWnd::getPreferences(int what) {
  558. switch (what) {
  559. case SUGGESTED_W: return 76;
  560. case SUGGESTED_H: return 16;
  561. }
  562. return SA_PARENT::getPreferences(what);
  563. }
  564. void SAWnd::getQuickPaintSize(int *w, int *h) {
  565. if (w) *w = 76*2;
  566. if (h) *h = 16*2;
  567. }
  568. void SAWnd::getQuickPaintSource(RECT *r) {
  569. ASSERT(r != NULL);
  570. r->left = 0;
  571. r->top = 0;
  572. r->right = 72;
  573. r->bottom = 16;
  574. }
  575. int SAWnd::viewer_onEvent(api_dependent *item, const GUID *classguid, int event, intptr_t param, void *ptr, size_t ptrlen) {
  576. #ifdef WASABI_COMPILE_CONFIG
  577. if(event==CfgItem::Event_ATTRIBUTE_CHANGED && ptr && STRCASEEQLSAFE((const char *)ptr, "Spectrum analyzer mode")) {
  578. CfgItem *ci=WASABI_API_CONFIG->config_getCfgItemByGuid(uioptions_guid);
  579. if(ci) config_sa=ci->getDataAsInt((const wchar_t *)ptr);
  580. }
  581. #endif
  582. return 1;
  583. }
  584. VisScriptController _visController;
  585. VisScriptController *visController = &_visController;
  586. // -- Functions table -------------------------------------
  587. function_descriptor_struct VisScriptController::exportedFunction[] = {
  588. {L"onFrame", 0, (void*)SAWnd::script_onFrame },
  589. {L"setRealtime", 1, (void*)SAWnd::script_setRealtime },
  590. {L"getRealtime", 0, (void*)SAWnd::script_getRealtime },
  591. {L"setMode", 1, (void*)SAWnd::script_vcpu_setMode},
  592. {L"getMode", 0, (void*)SAWnd::script_vcpu_getMode},
  593. {L"nextMode", 0, (void*)SAWnd::script_vcpu_nextMode},
  594. };
  595. // --------------------------------------------------------
  596. const wchar_t *VisScriptController::getClassName() {
  597. return L"Vis";
  598. }
  599. const wchar_t *VisScriptController::getAncestorClassName() {
  600. return L"GuiObject";
  601. }
  602. ScriptObject *VisScriptController::instantiate() {
  603. SAWnd *sa = new SAWnd;
  604. ASSERT(sa != NULL);
  605. return sa->getScriptObject();
  606. }
  607. void VisScriptController::destroy(ScriptObject *o) {
  608. SAWnd *sa = static_cast<SAWnd *>(o->vcpu_getInterface(visGuid));
  609. ASSERT(sa != NULL);
  610. delete sa;
  611. }
  612. void *VisScriptController::encapsulate(ScriptObject *o) {
  613. return NULL; // no encapsulation for vis yet
  614. }
  615. void VisScriptController::deencapsulate(void *o) {
  616. }
  617. int VisScriptController::getNumFunctions() {
  618. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  619. }
  620. const function_descriptor_struct *VisScriptController::getExportedFunctions() {
  621. return exportedFunction;
  622. }
  623. GUID VisScriptController::getClassGuid() {
  624. return visGuid;
  625. }
  626. // -----------------------------------------------------------------------
  627. scriptVar SAWnd::script_onFrame(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  628. SCRIPT_FUNCTION_INIT;
  629. PROCESS_HOOKS0(o, visController);
  630. SCRIPT_FUNCTION_CHECKABORTEVENT;
  631. SCRIPT_EXEC_EVENT0(o);
  632. }
  633. scriptVar SAWnd::script_setRealtime(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar s) {
  634. SCRIPT_FUNCTION_INIT
  635. ASSERT(SOM::isNumeric(&s));
  636. SAWnd *sa = static_cast<SAWnd*>(o->vcpu_getInterface(visGuid));
  637. if (sa) sa->setRealtime(SOM::makeInt(&s));
  638. RETURN_SCRIPT_VOID;
  639. }
  640. scriptVar SAWnd::script_getRealtime(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  641. SCRIPT_FUNCTION_INIT
  642. SAWnd *sa = static_cast<SAWnd*>(o->vcpu_getInterface(visGuid));
  643. if (sa) return MAKE_SCRIPT_INT(sa->getRealtime());
  644. return MAKE_SCRIPT_INT(0);
  645. }
  646. scriptVar SAWnd::script_vcpu_setMode(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar a) {
  647. SCRIPT_FUNCTION_INIT
  648. ASSERT(SOM::isNumeric(&a));
  649. SAWnd *sa = static_cast<SAWnd*>(o->vcpu_getInterface(visGuid));
  650. if (sa) sa->setMode(SOM::makeInt(&a));
  651. RETURN_SCRIPT_VOID;
  652. }
  653. scriptVar SAWnd::script_vcpu_getMode(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  654. SCRIPT_FUNCTION_INIT
  655. SAWnd *sa = static_cast<SAWnd*>(o->vcpu_getInterface(visGuid));
  656. if (sa) return MAKE_SCRIPT_INT(sa->getMode());
  657. return MAKE_SCRIPT_INT(0);
  658. }
  659. scriptVar SAWnd::script_vcpu_nextMode(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  660. SCRIPT_FUNCTION_INIT
  661. SAWnd *sa = static_cast<SAWnd*>(o->vcpu_getInterface(visGuid));
  662. if (sa) sa->nextMode();
  663. RETURN_SCRIPT_VOID;
  664. }