BT_OSCcontroller.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. function sendCommand(command)
  2. {
  3. local.send("/eos/cmd", command+"#");
  4. }
  5. function getCommandTarget(target, id, startID, endID)
  6. {
  7. var globalStart = local.parameters.startChannel.get();
  8. if(target == "one") return "Chan "+(globalStart+id);
  9. if(target == "range") return "Chan "+(globalStart+startID)+" Thru "+(globalStart+endID);
  10. if(target == "all") return "Group "+globalStart;
  11. }
  12. function getColorMessage(color, showRest)
  13. {
  14. var r = parseInt(color[0]*100);
  15. var g = parseInt(color[1]*100);
  16. var b = parseInt(color[2]*100);
  17. if(r < 10) r = "0"+r;
  18. if(g < 10) g = "0"+g;
  19. if(b < 10) b = "0"+b;
  20. return "Red @ "+r+" Green @ "+g+" Blue @ "+b+(showRest?" Cyan @ 0 Amber @ 0 Indigo @ 0 White @ 0":"");
  21. }
  22. function valueCallback(target, id, startID, endID, value)
  23. {
  24. var v = parseInt(value*100);
  25. if(v < 10) v = "0"+v;
  26. var cmd = getCommandTarget(target, id, startID, endID)+" @ "+v;
  27. sendCommand(cmd);
  28. }
  29. function colorCallback(target, id, startID, endID, color)
  30. {
  31. var cmd = getCommandTarget(target, id, startID, endID);
  32. var colCmd = getColorMessage(color);
  33. sendCommand(cmd+" "+colCmd);
  34. }
  35. function blackOutCallback(target, propID, startID, endID)
  36. {
  37. var cmd = getCommandTarget(target, id, startID, endID);
  38. var colCmd = getColorMessage(color, true);
  39. sendCommand(cmd+" "+colCmd);
  40. cmd = getCommandTarget(target, id, startID, endID)+" @ 0";
  41. sendCommand(cmd);
  42. }
  43. //Advanced functions
  44. function gradientCallback(startID, endID, color1, color2)
  45. {
  46. if(startID == endID)
  47. {
  48. colorCallback("one",startID,0,0,color1);
  49. return;
  50. }
  51. var r1 = color1[0];
  52. var g1 = color1[1];
  53. var b1 = color1[2];
  54. var r2 = color2[0];
  55. var g2 = color2[1];
  56. var b2 = color2[2];
  57. var minID = Math.min(startID, endID);
  58. var maxID = Math.max(startID, endID);
  59. for(var i=minID;i<=maxID;i++)
  60. {
  61. var p = (i-minID)*1.0/(maxID-minID);
  62. var r = (r1+(r2-r1)*p);
  63. var g = (g1+(g2-g1)*p);
  64. var b = (b1+(b2-b1)*p);
  65. var cmd = getCommandTarget("one",i);
  66. var colorCmd = getColorMessage([r,g,b]);
  67. sendCommand(cmd+" "+colorCmd);
  68. }
  69. }
  70. function pointCallback(startID, endID, position, size, fade, color)
  71. {
  72. var r = color[0];
  73. var g = color[1];
  74. var b = color[2];
  75. for(var i=startID;i<=endID;i++)
  76. {
  77. var p = (i-startID)*1.0/(endID-startID);
  78. var cmd = getCommandTarget("one",i);
  79. var colorCmd;
  80. if(Math.abs(position-p) < size)
  81. {
  82. var fac = Math.min(Math.max(1-Math.abs((p-position)*fade*3/size),0),1);
  83. colorCmd = getColorMessage([r*fac, g*fac, b*fac]);
  84. }else
  85. {
  86. colorCmd = getColorMessage([0,0,0]);
  87. }
  88. sendCommand(cmd+" "+colorCmd);
  89. }
  90. }