beatvisualization.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include <lib/std.mi>
  2. #include "attribs.m"
  3. Function setObjects();
  4. Global Group frameGroup,beatdisplay;
  5. Global Layer beatOverlay,DisplayRight,DisplayRightOverlay,DisplaySongtickerBG,VisOverlay;
  6. Global Timer refreshEQ;
  7. Global AnimatedLayer beatbarLeft,beatbarRight;
  8. Global int lastBeatLeft,lastBeatRight;
  9. Global Button Toggler,Toggler2;
  10. Global Int dobeat2;
  11. System.onScriptLoaded() {
  12. initAttribs();
  13. frameGroup = getScriptGroup();
  14. beatdisplay = frameGroup.findObject("player.normal.display.beatvisualization");
  15. beatOverlay = frameGroup.findObject("beatdisplayoverlay");
  16. beatbarLeft = frameGroup.findObject("beatleft");
  17. beatbarRight = frameGroup.findObject("beatright");
  18. Toggler = frameGroup.findObject("beatvisualization");
  19. Toggler2 = frameGroup.findObject("beatvisualization2");
  20. DisplayRight = frameGroup.findObject("display.right");
  21. DisplayRightOverlay = frameGroup.findObject("display.right.overlay2");
  22. DisplaySongtickerBG = frameGroup.findObject("display.st.right");
  23. VisOverlay = frameGroup.findObject("visualization.overlay");
  24. lastBeatLeft = 0;
  25. lastBeatRight = 0;
  26. refreshEQ = new Timer;
  27. refreshEQ.setDelay(10);
  28. }
  29. System.onscriptunloading() {
  30. delete refreshEQ;
  31. }
  32. setObjects() {
  33. int group_width = frameGroup.getWidth();
  34. if ( group_width % 2 !=0 ) {
  35. DisplayRight.setXmlParam("image","player.display.right");
  36. DisplayRightOverlay.setXmlParam("image","player.display.right");
  37. DisplaySongtickerBG.setXmlParam("image","player.display.songticker.bg.right");
  38. VisOverlay.setXmlParam("image","player.visualization.overlay");
  39. } else {
  40. DisplayRight.setXmlParam("image","player.display.right2");
  41. DisplayRightOverlay.setXmlParam("image","player.display.right2");
  42. DisplaySongtickerBG.setXmlParam("image","player.display.songticker.bg.right2");
  43. VisOverlay.setXmlParam("image","player.visualization.overlay2");
  44. }
  45. if ( group_width > 480 ) {
  46. int newXpos = (group_width-60)/2;
  47. beatdisplay.setXmlParam("x", IntegerToString(newXpos));
  48. beatdisplay.show();
  49. if ( beatvisualization_attrib.getData()=="1" ) {
  50. refreshEQ.stop();
  51. refreshEQ.start();
  52. } else {
  53. refreshEQ.stop();
  54. beatbarLeft.gotoframe(0);
  55. beatbarRight.gotoframe(0);
  56. }
  57. } else {
  58. beatdisplay.hide();
  59. refreshEQ.stop();
  60. }
  61. }
  62. frameGroup.onResize(int x, int y, int w, int h) {
  63. setObjects();
  64. }
  65. refreshEQ.onTimer() {
  66. int beatLeft= System.getLeftVuMeter();
  67. int beatRight= System.getRightVuMeter();
  68. int frameLeft=beatLeft/16;
  69. int frameRight=beatRight/16;
  70. if (frameLeft>14) frameLeft=14;
  71. if (frameRight>14) frameRight=14;
  72. if (frameLeft<lastBeatLeft) {
  73. frameLeft=lastBeatLeft-1;
  74. if (frameLeft<0) frameLeft=0;
  75. }
  76. if (frameRight<lastBeatRight) {
  77. frameRight=lastBeatRight-1;
  78. if (frameRight<0) frameRight=0;
  79. }
  80. lastBeatLeft=frameLeft;
  81. lastBeatRight=frameRight;
  82. beatbarLeft.gotoframe(frameLeft);
  83. beatbarRight.gotoframe(frameRight);
  84. }
  85. beatvisualization_attrib.onDataChanged() {
  86. setObjects();
  87. }
  88. System.onKeyDown(String key) {
  89. if (key == "shift+ctrl+alt") {
  90. dobeat2 = 1;
  91. complete;
  92. } else dobeat2 = 0;
  93. }
  94. Toggler.onLeftClick() {
  95. if ( beatvisualization_attrib.getData()=="1" ) {
  96. beatvisualization_attrib.setData("0");
  97. } else {
  98. beatvisualization_attrib.setData("1");
  99. }
  100. }
  101. Toggler2.onActivate(boolean on) {
  102. if (!dobeat2) { Toggler.leftClick(); return; }
  103. refreshEQ.stop();
  104. if (on) {
  105. beatbarLeft.setXMLParam("image","player.display.beat.left2");
  106. beatbarRight.setXMLParam("image","player.display.beat.right2");
  107. beatOverlay.hide();
  108. } else {
  109. beatbarLeft.setXMLParam("image","player.display.beat.left");
  110. beatbarRight.setXMLParam("image","player.display.beat.right");
  111. beatOverlay.show();
  112. }
  113. setObjects();
  114. }