BCF2000.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. BCF2000 management script with 14bit precision
  3. midi inputs are stored as MSB ans LSB and update a float parameter
  4. on float parameter update, midi values are sent back to BCF (to ensure synchronisation of values)
  5. */
  6. var pan_midi_ch = script.addIntParameter("pan midi channel", "", 0);
  7. var pan_midi={channel:pan_midi_ch.get(), MSB:0, LSB:0, target:root.customVariables.unitValues.variables.pan.pan, value: script.addFloatParameter("pan", "current pan value", 0., 0, 1) };
  8. // var pan_value =
  9. var tilt_midi_ch = script.addIntParameter("tilt midi channel", "", 1);
  10. var tilt_midi={channel:tilt_midi_ch.get(), MSB:0, LSB:0, target:root.customVariables.unitValues.variables.tilt.tilt, value: script.addFloatParameter("tilt", "current tilt value", 0., 0, 1)};
  11. var zoom_midi_ch = script.addIntParameter("zoom midi channel", "", 2);
  12. var zoom_midi={channel:zoom_midi_ch.get(), MSB:0, LSB:0, target:root.customVariables.unitValues.variables.zoom.zoom, value:script.addFloatParameter("zoom", "current zoom value", 0., 0, 1) };
  13. var focus_midi_ch = script.addIntParameter("focus midi channel", "", 3);
  14. var focus_midi={channel:focus_midi_ch.get(), MSB:0, LSB:0, target:root.customVariables.unitValues.variables.focus.focus, value: script.addFloatParameter("focus", "current focus value", 0., 0, 1)};
  15. var dimmer_midi_ch = script.addIntParameter("dimmer midi channel", "", 4);
  16. var dimmer_midi={channel:dimmer_midi_ch.get(), MSB:0, LSB:0, target:root.customVariables.unitValues.variables.dimmer.dimmer, value: script.addFloatParameter("dimmer", "current dimmer value", 0., 0, 1)};
  17. var zoomCam_midi_ch = script.addIntParameter("zoomCam midi channel", "", 5);
  18. var zoomCam_midi={channel:zoomCam_midi_ch.get(), MSB:0, LSB:0, target:root.customVariables.unitValues.variables.zoomCam.zoomCam, value: script.addFloatParameter("zoomCam", "current camera zoom value", 0., 0, 1)};
  19. function init()
  20. {
  21. //myFloatParam.set(5); //The .set() function set the parameter to this value.
  22. //myColorParam.set([1,.5,1,1]); //for a color parameter, you need to pass an array with 3 (RGB) or 4 (RGBA) values.
  23. //myP2DParam.set([1.5,-5]); // for a Point2D parameter, you need to pass 2 values (XY)
  24. //myP3DParam.set([1.5,2,-3]); // for a Point3D parameter, you need to pass 3 values (XYZ)
  25. }
  26. function bits2float(MSB, LSB){
  27. Value = param.get()*16383;
  28. MSB = Math.floor(ccValue/128);
  29. // MSB=Math.round(MSB);
  30. LSB = Math.floor(ccValue % 128);
  31. // MSB=Math.round(MSB);
  32. // LSB=Math.round(LSB);
  33. script.log(MSB+ " "+ LSB);
  34. }
  35. function updateCC(cc, value){
  36. if(cc==pan_midi.channel){pan_midi.MSB = value; return pan_midi;}
  37. if(cc==pan_midi.channel+32){pan_midi.LSB = value; return pan_midi;}
  38. if(cc==tilt_midi.channel){tilt_midi.MSB = value; return tilt_midi;}
  39. if(cc==tilt_midi.channel+32){tilt_midi.LSB = value; return tilt_midi;}
  40. if(cc==zoom_midi.channel){zoom_midi.MSB = value; return zoom_midi;}
  41. if(cc==zoom_midi.channel+32){zoom_midi.LSB = value; return zoom_midi;}
  42. if(cc==focus_midi.channel){focus_midi.MSB = value; return focus_midi;}
  43. if(cc==focus_midi.channel+32){focus_midi.LSB = value; return focus_midi;}
  44. if(cc==dimmer_midi.channel){dimmer_midi.MSB = value; return dimmer_midi;}
  45. if(cc==dimmer_midi.channel+32){dimmer_midi.LSB = value; return dimmer_midi;}
  46. if(cc==zoomCam_midi.channel){zoomCam_midi.MSB = value; return zoomCam_midi;}
  47. if(cc==zoomCam_midi.channel+32){zoomCam_midi.LSB = value; return zoomCam_midi;}
  48. else return 0;
  49. }
  50. function updateFloat(channel){
  51. channel.value.set((channel.MSB*128+channel.LSB)/16383.);
  52. }
  53. function feedbackMidi(channel){
  54. channel.MSB = Math.round(Math.floor(channel.value.get()*16383. /128));
  55. channel.LSB = Math.round(Math.floor(channel.value.get()*16383. %128));
  56. script.log(channel.MSB + " " + channel.LSB);
  57. local.sendCC(1, channel.channel, channel.MSB);
  58. local.sendCC(1, channel.channel+32, channel.LSB);
  59. }
  60. // function updateAxe(axe, CC, value){
  61. // if(CC==axe.channel){
  62. // axe.MSB = value;
  63. // // root.customVariables.unitValues.variables.pan.pan.set((128*axe.MSB+axe.LSB)/16383.0);
  64. // }
  65. // if(CC==axe.channel+32){
  66. // axe.LSB = value;
  67. // // myFloatParam.set((128*MSB+LSB)/16383.0);
  68. // }
  69. // axe.target=(128*axe.MSB+axe.LSB)/16383.0;
  70. // script.log(axe.target);
  71. // }
  72. function scriptParameterChanged(param)
  73. {
  74. if (param.is(pan_midi.value) ){feedbackMidi(pan_midi);}
  75. if (param.is(tilt_midi.value) ){feedbackMidi(tilt_midi);}
  76. if (param.is(zoom_midi.value) ){feedbackMidi(zoom_midi);}
  77. if (param.is(focus_midi.value) ){feedbackMidi(focus_midi);}
  78. if (param.is(dimmer_midi.value) ){feedbackMidi(dimmer_midi);}
  79. if (param.is(zoomCam_midi.value) ){feedbackMidi(zoomCam_midi);}
  80. if (param.is(pan_midi_ch)){pan_midi.channel = pan_midi_ch.get();}
  81. if (param.is(tilt_midi_ch)){tilt_midi.channel = tilt_midi_ch.get();}
  82. if (param.is(zoom_midi_ch)){zoom_midi.channel = zoom_midi_ch.get();}
  83. if (param.is(focus_midi_ch)){focus_midi.channel = focus_midi_ch.get();}
  84. if (param.is(dimmer_midi_ch)){dimmer_midi.channel = dimmer_midi_ch.get();}
  85. if (param.is(zoomCam_midi_ch)){zoomCam_midi.channel = zoomCam_midi_ch.get();}
  86. //You can use the script.log() function to show an information inside the logger panel. To be able to actuallt see it in the logger panel, you will have to turn on "Log" on this script.
  87. // script.log("Parameter changed : "+param.name); //All parameters have "name" property
  88. // if(param.is(myTrigger)) script.log("Trigger !"); //You can check if two variables are the reference to the same parameter or object with the method .is()
  89. // else if(param.is(myEnumParam)) script.log("Label = "+param.get()+", data = "+param.getData()); //The enum parameter has a special function getData() to get the data associated to the option
  90. // else script.log("Value is "+param.get()); //All parameters have a get() method that will return their value
  91. // if (param.name == "myFloatParam"){
  92. // script.log("sending back");
  93. // var ccValue = param.get()*16383;
  94. // MSB = Math.floor(ccValue/128);
  95. // // MSB=Math.round(MSB);
  96. // LSB = Math.floor(ccValue % 128);
  97. // // MSB=Math.round(MSB);
  98. // // LSB=Math.round(LSB);
  99. // script.log(MSB+ " "+ LSB);
  100. // local.sendCC(channel, 0, MSB);
  101. // local.sendCC(channel, 32, LSB);
  102. //
  103. // }
  104. }
  105. /*
  106. This function, if you declare it, will launch a timer at 50hz, calling this method on each tick
  107. */
  108. /*
  109. function update(deltaTime)
  110. {
  111. script.log("Update : "+util.getTime()+", delta = "+deltaTime); //deltaTime is the time between now and last update() call, util.getTime() will give you a timestamp relative to either the launch time of the software, or the start of the computer.
  112. }
  113. */
  114. /* ********** MODULE SPECIFIC SCRIPTING **********************
  115. The "local" variable refers to the object containing the scripts. In this case, the local variable refers to the module.
  116. It means that you can access any control inside this module by accessing it through its address.
  117. For instance, if the module has a float value named "Density", you can access it via local.values.density
  118. Then you can retrieve its value using local.values.density.get() and change its value using local.values.density.set()
  119. */
  120. /*
  121. This function will be called each time a parameter of this module has changed, meaning a parameter or trigger inside the "Parameters" panel of this module
  122. This function only exists because the script is in a module
  123. */
  124. function moduleParameterChanged(param)
  125. {
  126. // if(param.isParameter())
  127. // {
  128. // script.log("Module parameter changed : "+param.name+" > "+param.get());
  129. // }else
  130. // {
  131. // script.log("Module parameter triggered : "+value.name);
  132. // }
  133. }
  134. /*
  135. This function will be called each time a value of this module has changed, meaning a parameter or trigger inside the "Values" panel of this module
  136. This function only exists because the script is in a module
  137. */
  138. function moduleValueChanged(value)
  139. {
  140. // if(value.isParameter())
  141. // {
  142. // script.log("Module value changed : "+value.name+" > "+value.get());
  143. // }else
  144. // {
  145. // script.log("Module value triggered : "+value.name);
  146. // }
  147. }
  148. /* ********** MIDI MODULE SPECIFIC SCRIPTING ********************* */
  149. /*
  150. MIDI Modules have specific methods that can be used to send MIDI events such as noteOn, noteOff, controlChange and sysEx messages from Script.
  151. If you want to send a MIDI event from this script, you can do the following :
  152. local.sendNoteOn(1, 12, 127); //This will send a NoteOn Event on channel 1, pitch 12, velocity 127
  153. local.sendNoteOff(1, 12); //This will send a NoteOff Event on chanenl 1, pitch 12
  154. local.sendCC(3, 20, 65); //This will send a ControlChange on channel 3, number 20, value 65
  155. local.sendSysEx(15,20,115,10); //This will send 4 bytes as a SysEx message
  156. local.sendSysEx(15,20,115,10); //This will send 4 bytes as a SysEx message
  157. */
  158. /*
  159. You can intercept MIDI Events with the functions below
  160. */
  161. function noteOnEvent(channel, pitch, velocity)
  162. {
  163. script.log("Note on received "+channel+", "+pitch+", "+velocity);
  164. }
  165. function noteOffEvent(channel, pitch, velocity)
  166. {
  167. script.log("Note off received "+channel+", "+pitch+", "+velocity);
  168. }
  169. function ccEvent(channel, number, value)
  170. {
  171. var ccChannel = updateCC(number, value); //return axe.MSB or axe.LSB
  172. if (ccChannel){updateFloat(ccChannel);}
  173. // ccChannel.set(value);
  174. // script.log("hello");
  175. // script.log("ControlChange received "+channel+", "+number+", "+value);
  176. // //feedback to BCF
  177. // // local.sendCC(channel, number, value);
  178. // if(number==pan_midi_ch){
  179. // MSB = value;
  180. // myFloatParam.set((128*MSB+LSB)/16384.0);
  181. // }
  182. // if(number==32){
  183. // LSB = value;
  184. // myFloatParam.set((128*MSB+LSB)/16384.0);
  185. // }
  186. }
  187. function sysExEvent(data)
  188. {
  189. script.log("Sysex Message received, "+data.length+" bytes :");
  190. for(var i=0; i < data.length; i++)
  191. {
  192. script.log(" > "+data[i]);
  193. }
  194. }