1
0

beatvisualization.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*---------------------------------------------------
  2. -----------------------------------------------------
  3. Filename: beatvisualization.m
  4. Version: 1.0
  5. Type: maki
  6. Date: 24. Sep. 2007 - 21:11
  7. Author: Martin Poehlmann aka Deimos
  8. E-Mail: [email protected]
  9. Internet: www.skinconsortium.com
  10. www.martin.deimos.de.vu
  11. Based on Winamp Modern
  12. -----------------------------------------------------
  13. ---------------------------------------------------*/
  14. #include <lib/std.mi>
  15. #include attribs/init_appearance.m
  16. Function updateObj(int w);
  17. #define CENTER_VAR CONTENTGRP
  18. Global Group contentGroup;
  19. #include <lib/com/centerlayer.m>
  20. #undef CENTER_VAR
  21. Global Group scriptGroup;
  22. Global animatedLayer beatVisL, beatVisR;
  23. Global int lastBeatLeft, lastBeatRight;
  24. Global Timer refreshVis;
  25. Global Int totalFrames;
  26. Global GuiObject SongTicker;
  27. System.onScriptLoaded ()
  28. {
  29. initAttribs_Appearance();
  30. scriptGroup = getScriptGroup();
  31. contentGroup = scriptGroup.getObject("player.display.beatvis.content");
  32. beatVisL = contentGroup.getObject("beatvisleft");
  33. beatVisR = contentGroup.getObject("beatvisright");
  34. _CONTENTGRPInit(contentGroup, scriptGroup, 1, 0);
  35. SongTicker = contentGroup.getParent().findObject("Songticker");
  36. totalFrames = beatVisR.getLength() - 1;
  37. lastBeatLeft = 0;
  38. lastBeatRight = 0;
  39. refreshVis = new Timer;
  40. refreshVis.setDelay(10);
  41. updateObj(scriptGroup.getWidth());
  42. vis_reflection_attrib.onDataChanged();
  43. }
  44. System.onScriptUnloading ()
  45. {
  46. refreshVis.stop();
  47. delete refreshVis;
  48. }
  49. scriptGroup.onResize (int x, int y, int w, int h)
  50. {
  51. updateObj(w);
  52. }
  53. updateObj (int w)
  54. {
  55. if (w > 98)
  56. {
  57. if (scriptGroup.isVisible()) return;
  58. scriptGroup.show();
  59. if (beatvis_attrib.getData() == "1") refreshVis.start();
  60. //SongTicker.sendAction("setGuiX", "", 191,0,0,0);
  61. }
  62. else
  63. {
  64. refreshVis.stop();
  65. scriptGroup.hide();
  66. //SongTicker.sendAction("restoreGuiX", "", 0,0,0,0);
  67. }
  68. }
  69. refreshVis.onTimer ()
  70. {
  71. if (beatvis_attrib.getData() == "0")
  72. {
  73. lastBeatLeft--;
  74. if (lastBeatLeft<0) lastBeatLeft=0;
  75. lastBeatRight--;
  76. if (lastBeatRight<0) lastBeatRight=0;
  77. beatVisL.gotoframe(lastBeatLeft);
  78. beatVisR.gotoframe(lastBeatRight);
  79. if (lastBeatLeft + lastBeatRight == 0)
  80. {
  81. refreshVis.stop();
  82. }
  83. return;
  84. }
  85. int beatLeft= System.getLeftVuMeter();
  86. int beatRight= System.getRightVuMeter();
  87. int frameLeft=beatLeft/(totalFrames+7);
  88. int frameRight=beatRight/(totalFrames+7);
  89. if (frameLeft>totalFrames) frameLeft=totalFrames;
  90. if (frameRight>totalFrames) frameRight=totalFrames;
  91. if (frameLeft<lastBeatLeft)
  92. {
  93. frameLeft=lastBeatLeft-1;
  94. if (frameLeft<0) frameLeft=0;
  95. }
  96. if (frameRight<lastBeatRight)
  97. {
  98. frameRight=lastBeatRight-1;
  99. if (frameRight<0) frameRight=0;
  100. }
  101. lastBeatLeft=frameLeft;
  102. lastBeatRight=frameRight;
  103. beatVisL.gotoframe(frameLeft);
  104. beatVisR.gotoframe(frameRight);
  105. }
  106. beatvis_attrib.onDataChanged ()
  107. {
  108. if (getData() == "1" )
  109. {
  110. if (scriptGroup.isVisible())
  111. {
  112. refreshVis.start();
  113. }
  114. }
  115. }
  116. vis_reflection_attrib.onDataChanged ()
  117. {
  118. if (getdata() == "1")
  119. {
  120. beatVisR.setXmlParam("image", "player.beatvis.right");
  121. beatVisL.setXmlParam("image", "player.beatvis.left");
  122. }
  123. else
  124. {
  125. beatVisR.setXmlParam("image", "player.beatvis.right.wo");
  126. beatVisL.setXmlParam("image", "player.beatvis.left.wo");
  127. }
  128. }