1
0

visualizer.m 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*---------------------------------------------------
  2. -----------------------------------------------------
  3. Filename: visualizer.m
  4. Version: 1.4
  5. Type: maki
  6. Date: 07. Okt. 2007 - 19:56
  7. Author: Martin Poehlmann aka Deimos
  8. E-Mail: [email protected]
  9. Internet: www.skinconsortium.com
  10. www.martin.deimos.de.vu
  11. Note: This script handles also the timer reflection
  12. -----------------------------------------------------
  13. ---------------------------------------------------*/
  14. #include <lib/std.mi>
  15. #include attribs/init_appearance.m
  16. Function refreshVisSettings();
  17. Function setVis (int mode);
  18. Function ProcessMenuResult (int a);
  19. Global Group scriptGroup;
  20. Global Vis visualizer, visualizer_m;
  21. Global Text tmr;
  22. Global PopUpMenu visMenu;
  23. Global PopUpMenu specmenu;
  24. Global PopUpMenu oscmenu;
  25. Global PopUpMenu pksmenu;
  26. Global PopUpMenu anamenu;
  27. Global PopUpMenu stylemenu;
  28. Global Int currentMode, a_falloffspeed, p_falloffspeed, a_coloring;
  29. Global Boolean show_peaks, isShade;
  30. Global layer trigger;
  31. Global Layout thislayout;
  32. Global Container main;
  33. System.onScriptLoaded()
  34. {
  35. initAttribs_Appearance(); // init appearance attribs
  36. scriptGroup = getScriptGroup();
  37. thislayout = scriptGroup.getParentLayout();
  38. main = thislayout.getContainer();
  39. // this script runs in shade and normal layout, we store this bool to prevent some actions to recieve the shade vis.
  40. isShade = (scriptGroup.getParentlayout().getID() == "shade");
  41. visualizer = scriptGroup.findObject("main.vis");
  42. trigger = scriptGroup.findObject("main.vis.trigger");
  43. if (!isShade)
  44. {
  45. visualizer_m = scriptGroup.findObject("main.vis.mirror");
  46. vis_reflection_attrib.onDataChanged();
  47. tmr = scriptGroup.findObject("SongTime");
  48. timer_reflection_attrib.onDataChanged();
  49. }
  50. visualizer.setXmlParam("peaks", integerToString(show_peaks));
  51. visualizer.setXmlParam("peakfalloff", integerToString(p_falloffspeed));
  52. visualizer.setXmlParam("falloff", integerToString(a_falloffspeed));
  53. refreshVisSettings ();
  54. }
  55. refreshVisSettings ()
  56. {
  57. currentMode = getPrivateInt(getSkinName(), "Visualizer Mode", 1);
  58. show_peaks = getPrivateInt(getSkinName(), "Visualizer show Peaks", 1);
  59. a_falloffspeed = getPrivateInt(getSkinName(), "Visualizer analyzer falloff", 3);
  60. p_falloffspeed = getPrivateInt(getSkinName(), "Visualizer peaks falloff", 2);
  61. a_coloring = getPrivateInt(getSkinName(), "Visualizer analyzer coloring", 0);
  62. visualizer.setXmlParam("peaks", integerToString(show_peaks));
  63. visualizer.setXmlParam("peakfalloff", integerToString(p_falloffspeed));
  64. visualizer.setXmlParam("falloff", integerToString(a_falloffspeed));
  65. if (a_coloring == 0)
  66. {
  67. visualizer.setXmlParam("coloring", "Normal");
  68. if (!isShade) visualizer_m.setXmlParam("coloring", "Normal");
  69. }
  70. else if (a_coloring == 1)
  71. {
  72. visualizer.setXmlParam("coloring", "Normal");
  73. if (!isShade) visualizer_m.setXmlParam("coloring", "Normal");
  74. }
  75. else if (a_coloring == 2)
  76. {
  77. visualizer.setXmlParam("coloring", "Fire");
  78. if (!isShade) visualizer_m.setXmlParam("coloring", "Fire");
  79. }
  80. else if (a_coloring == 3)
  81. {
  82. visualizer.setXmlParam("coloring", "Line");
  83. if (!isShade) visualizer_m.setXmlParam("coloring", "Line");
  84. }
  85. if (!isShade)
  86. {
  87. visualizer_m.setXmlParam("peaks", integerToString(show_peaks));
  88. visualizer_m.setXmlParam("peakfalloff", integerToString(p_falloffspeed));
  89. visualizer_m.setXmlParam("falloff", integerToString(a_falloffspeed));
  90. }
  91. setVis (currentMode);
  92. }
  93. trigger.onLeftButtonDown (int x, int y)
  94. {
  95. if (isKeyDown(VK_ALT) && isKeyDown(VK_SHIFT) && isKeyDown(VK_CONTROL))
  96. {
  97. if (visualizer.getXmlParam("fliph") == "1")
  98. {
  99. visualizer.setXmlParam("fliph", "0");
  100. visualizer_m.setXmlParam("fliph", "0");
  101. }
  102. else
  103. {
  104. visualizer.setXmlParam("fliph", "1");
  105. visualizer_m.setXmlParam("fliph", "1");
  106. }
  107. return;
  108. }
  109. currentMode++;
  110. if (currentMode == 6)
  111. {
  112. currentMode = 0;
  113. }
  114. setVis (currentMode);
  115. complete;
  116. }
  117. trigger.onRightButtonUp (int x, int y)
  118. {
  119. visMenu = new PopUpMenu;
  120. specmenu = new PopUpMenu;
  121. oscmenu = new PopUpMenu;
  122. pksmenu = new PopUpMenu;
  123. anamenu = new PopUpMenu;
  124. stylemenu = new PopUpMenu;
  125. visMenu.addCommand("Presets:", 999, 0, 1);
  126. visMenu.addCommand("No Visualization", 100, currentMode == 0, 0);
  127. specmenu.addCommand("Thick Bands", 1, currentMode == 1, 0);
  128. specmenu.addCommand("Thin Bands", 2, currentMode == 2, 0);
  129. visMenu.addSubMenu(specmenu, "Spectrum Analyzer");
  130. oscmenu.addCommand("Solid", 3, currentMode == 3, 0);
  131. oscmenu.addCommand("Dots", 4, currentMode == 4, 0);
  132. oscmenu.addCommand("Lines", 5, currentMode == 5, 0);
  133. visMenu.addSubMenu(oscmenu, "Oscilloscope");
  134. visMenu.addSeparator();
  135. visMenu.addCommand("Options:", 102, 0, 1);
  136. visMenu.addCommand("Show Peaks", 101, show_peaks == 1, 0);
  137. pksmenu.addCommand("Slower", 200, p_falloffspeed == 0, 0);
  138. pksmenu.addCommand("Slow", 201, p_falloffspeed == 1, 0);
  139. pksmenu.addCommand("Moderate", 202, p_falloffspeed == 2, 0);
  140. pksmenu.addCommand("Fast", 203, p_falloffspeed == 3, 0);
  141. pksmenu.addCommand("Faster", 204, p_falloffspeed == 4, 0);
  142. visMenu.addSubMenu(pksmenu, "Peak Falloff Speed");
  143. anamenu.addCommand("Slower", 300, a_falloffspeed == 0, 0);
  144. anamenu.addCommand("Slow", 301, a_falloffspeed == 1, 0);
  145. anamenu.addCommand("Moderate", 302, a_falloffspeed == 2, 0);
  146. anamenu.addCommand("Fast", 303, a_falloffspeed == 3, 0);
  147. anamenu.addCommand("Faster", 304, a_falloffspeed == 4, 0);
  148. visMenu.addSubMenu(anamenu, "Analyzer Falloff Speed");
  149. stylemenu.addCommand("Normal", 400, a_coloring == 0, 0);
  150. stylemenu.addCommand("Fire", 402, a_coloring == 2, 0);
  151. stylemenu.addCommand("Line", 403, a_coloring == 3, 0);
  152. visMenu.addSubMenu(stylemenu, "Analyzer Coloring");
  153. ProcessMenuResult (visMenu.popAtMouse());
  154. delete visMenu;
  155. delete specmenu;
  156. delete oscmenu;
  157. delete pksmenu;
  158. delete anamenu;
  159. delete stylemenu;
  160. complete;
  161. }
  162. ProcessMenuResult (int a)
  163. {
  164. if (a < 1) return;
  165. if (a > 0 && a <= 6 || a == 100)
  166. {
  167. if (a == 100) a = 0;
  168. setVis(a);
  169. }
  170. else if (a == 101)
  171. {
  172. show_peaks = (show_peaks - 1) * (-1);
  173. visualizer.setXmlParam("peaks", integerToString(show_peaks));
  174. if (!isShade) visualizer_m.setXmlParam("peaks", integerToString(show_peaks));
  175. setPrivateInt(getSkinName(), "Visualizer show Peaks", show_peaks);
  176. }
  177. else if (a >= 200 && a <= 204)
  178. {
  179. p_falloffspeed = a - 200;
  180. visualizer.setXmlParam("peakfalloff", integerToString(p_falloffspeed));
  181. if (!isShade) visualizer_m.setXmlParam("peakfalloff", integerToString(p_falloffspeed));
  182. setPrivateInt(getSkinName(), "Visualizer peaks falloff", p_falloffspeed);
  183. }
  184. else if (a >= 300 && a <= 304)
  185. {
  186. a_falloffspeed = a - 300;
  187. visualizer.setXmlParam("falloff", integerToString(a_falloffspeed));
  188. if (!isShade) visualizer_m.setXmlParam("falloff", integerToString(a_falloffspeed));
  189. setPrivateInt(getSkinName(), "Visualizer analyzer falloff", a_falloffspeed);
  190. }
  191. else if (a >= 400 && a <= 403)
  192. {
  193. a_coloring = a - 400;
  194. if (a_coloring == 0)
  195. {
  196. visualizer.setXmlParam("coloring", "Normal");
  197. if (!isShade) visualizer_m.setXmlParam("coloring", "Normal");
  198. }
  199. else if (a_coloring == 1)
  200. {
  201. visualizer.setXmlParam("coloring", "Normal");
  202. if (!isShade) visualizer_m.setXmlParam("coloring", "Normal");
  203. }
  204. else if (a_coloring == 2)
  205. {
  206. visualizer.setXmlParam("coloring", "Fire");
  207. if (!isShade) visualizer_m.setXmlParam("coloring", "Fire");
  208. }
  209. else if (a_coloring == 3)
  210. {
  211. visualizer.setXmlParam("coloring", "Line");
  212. if (!isShade) visualizer_m.setXmlParam("coloring", "Line");
  213. }
  214. setPrivateInt(getSkinName(), "Visualizer analyzer coloring", a_coloring);
  215. }
  216. }
  217. setVis (int mode)
  218. {
  219. setPrivateInt(getSkinName(), "Visualizer Mode", mode);
  220. if (mode == 0)
  221. {
  222. visualizer.setMode(0);
  223. if (!isShade) visualizer_m.setMode(0);
  224. }
  225. else if (mode == 1)
  226. {
  227. visualizer.setXmlParam("bandwidth", "wide");
  228. visualizer.setMode(1);
  229. if (!isShade) visualizer_m.setXmlParam("bandwidth", "wide");
  230. if (!isShade) visualizer_m.setMode(1);
  231. }
  232. else if (mode == 2)
  233. {
  234. visualizer.setXmlParam("bandwidth", "thin");
  235. visualizer.setMode(1);
  236. if (!isShade) visualizer_m.setXmlParam("bandwidth", "thin");
  237. if (!isShade) visualizer_m.setMode(1);
  238. }
  239. else if (mode == 3)
  240. {
  241. visualizer.setXmlParam("oscstyle", "solid");
  242. visualizer.setMode(2);
  243. if (!isShade) visualizer_m.setXmlParam("oscstyle", "solid");
  244. if (!isShade) visualizer_m.setMode(2);
  245. }
  246. else if (mode == 4)
  247. {
  248. visualizer.setXmlParam("oscstyle", "dots");
  249. visualizer.setMode(2);
  250. if (!isShade) visualizer_m.setXmlParam("oscstyle", "dots");
  251. if (!isShade) visualizer_m.setMode(2);
  252. }
  253. else if (mode == 5)
  254. {
  255. visualizer.setXmlParam("oscstyle", "lines");
  256. visualizer.setMode(2);
  257. if (!isShade) visualizer_m.setXmlParam("oscstyle", "lines");
  258. if (!isShade) visualizer_m.setMode(2);
  259. }
  260. currentMode = mode;
  261. }
  262. // Set Vis reflection on/off
  263. vis_reflection_attrib.onDataChanged ()
  264. {
  265. if (isShade)
  266. {
  267. // shade visualizer doesn't have a reflection
  268. return;
  269. }
  270. if (getdata() == "1")
  271. {
  272. visualizer_m.show();
  273. }
  274. else
  275. {
  276. visualizer_m.hide();
  277. }
  278. }
  279. // Set Timer reflection on/off
  280. timer_reflection_attrib.onDataChanged ()
  281. {
  282. if (isShade)
  283. {
  284. // shade visualizer doesn't have a reflection
  285. return;
  286. }
  287. if (getdata() == "1")
  288. {
  289. tmr.setXmlParam("font", "player.bitmapfont.nums");
  290. }
  291. else
  292. {
  293. tmr.setXmlParam("font", "player.bitmapfont.nums.noreflect");
  294. }
  295. }
  296. // Sync Normal and Shade Layout
  297. main.onBeforeSwitchToLayout(Layout oldlayout, Layout newlayout)
  298. {
  299. if (newlayout != thislayout)
  300. {
  301. return;
  302. }
  303. refreshVisSettings();
  304. }