fxlib.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. #/usr/bin/python3
  2. import random
  3. import sys
  4. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  5. import lib.fixlib as fixlib
  6. def cprint(*args):
  7. print(args)
  8. def process_wings(xfixtures,fx_prm):
  9. """process the wing's of selected fixtures
  10. input: [1,2,3,4,10,12,13,14]
  11. if WING = 2 return: [[1,2,3,4][14,13,12,10]]
  12. """
  13. wing_buffer = []
  14. fix_count = len(xfixtures)
  15. prm = fx_prm # ToDo: global WING for PAN/TILE !? ATTRIBUT is not availible in this moment
  16. if prm["WING"] > 1 and fix_count > 1:
  17. wing_count = fix_count // prm["WING"]
  18. number_of_fix_in_wing = fix_count // wing_count
  19. if number_of_fix_in_wing < 2:
  20. number_of_fix_in_wing = 2
  21. for i in range(number_of_fix_in_wing):
  22. j = i*wing_count
  23. wing = xfixtures[j:j+wing_count]
  24. if i%2!=0:
  25. wing = wing[::-1]
  26. cprint("wing",i,"j",j,"wing_count:",wing_count,"wing",wing)
  27. wing_buffer.append(wing)
  28. if fix_count > j+wing_count: # append Fixtures Left over
  29. wing = xfixtures[j+wing_count:]
  30. wing_buffer.append(wing)
  31. else:
  32. wing_buffer.append(xfixtures)
  33. if prm["SHUFFLE"]:
  34. _wing_buffer = []
  35. for wing in wing_buffer:
  36. wing = wing[:]
  37. random.seed(9300) # sync random
  38. random.shuffle(wing)
  39. _wing_buffer.append(wing)
  40. wing_buffer = _wing_buffer
  41. return wing_buffer
  42. def process_effect(wing_buffer,fx_prm,fx_prm_move,modes,jclient_send,master,FIXTURES,fx_name=""):
  43. jdatas = []
  44. offset = 0
  45. offset_move = 0
  46. start = fx_prm["START"]
  47. base = fx_prm["BASE"]
  48. for wi, wing in enumerate(wing_buffer):
  49. count_of_fix_in_wing = len(wing)
  50. coffset= 0 # 1024/count_of_fix_in_wing * (offset/255)
  51. coffset_move=0
  52. for fix in wing:
  53. if fix not in FIXTURES.fixtures:
  54. continue
  55. data = FIXTURES.fixtures[fix]
  56. for attr in data["ATTRIBUT"]:
  57. if attr.startswith("_"):
  58. continue
  59. if attr.endswith("-FINE"):
  60. continue
  61. jdata = {"MODE":"FX"}
  62. jdata["WING"] = wi
  63. jdata["VALUE"] = None
  64. jdata["FIX"] = fix
  65. #dmx = FIXTURES.get_dmx(fix,attr)
  66. dmx = fixlib.get_dmx(FIXTURES.fixtures,fix,attr)
  67. jdata["DMX"] = dmx
  68. #dmx_fine = FIXTURES.get_dmx(fix,attr+"-FINE")
  69. dmx_fine = fixlib.get_dmx(FIXTURES.fixtures,fix,attr+"-FINE")
  70. if dmx_fine != jdata["DMX"] and dmx > 0:
  71. jdata["DMX-FINE"] = dmx_fine
  72. jdata["ATTR"] = attr
  73. tmp_fx_prm = fx_prm
  74. coffset= round(offset,1)
  75. if attr in ["PAN","TILT"]:
  76. tmp_fx_prm = fx_prm_move
  77. coffset_move= round(offset_move,1)
  78. csize = tmp_fx_prm["SIZE"]
  79. cspeed = tmp_fx_prm["SPEED"]
  80. cstart = tmp_fx_prm["START"]
  81. cbase = tmp_fx_prm["BASE"]
  82. width = tmp_fx_prm["WIDTH"]
  83. invert = tmp_fx_prm["INVERT"]
  84. fx=""
  85. if "SIN" in fx_name:
  86. fx = "sinus"
  87. elif "FD" in fx_name:
  88. fx = "fade"
  89. elif "RND" in fx_name:
  90. fx = "rnd"
  91. elif "STATIC" in fx_name:
  92. fx = "static"
  93. elif "ON" in fx_name:
  94. fx = "on"
  95. elif "RAMP2" in fx_name:
  96. fx = "bump2"
  97. fx = "ramp2"
  98. elif "RAMP" in fx_name:
  99. fx = "ramp"
  100. elif "COS" in fx_name:
  101. fx = "cosinus"
  102. if fx:
  103. if attr in ["PAN","TILT"]:
  104. cprint("SKIP FX attr:{} fix:{} " .format(attr,fix) )
  105. continue
  106. if fx:
  107. if cspeed < 0:
  108. fx = "off"
  109. else:
  110. if ":DIM" in fx_name:
  111. base=""
  112. ffxb=fx_mo[fx_prm["MO"]]
  113. if attr == "DIM":
  114. if cspeed < 0:
  115. fx = "off"
  116. else:
  117. fx = ffxb #"fade"
  118. elif ":TILT" in fx_name:
  119. base=""
  120. if attr == "PAN":
  121. fx = "off"
  122. if attr == "TILT":
  123. if cspeed < 0:
  124. fx = "off"
  125. else:
  126. fx = "sinus"
  127. elif ":PAN" in fx_name:
  128. base=""
  129. if attr == "PAN":
  130. if cspeed < 0:
  131. fx = "off"
  132. else:
  133. fx = "cosinus"
  134. if attr == "TILT":
  135. fx = "off"
  136. elif ":CIR" in fx_name:
  137. base=""
  138. if attr == "PAN":
  139. if cspeed < 0:
  140. fx = "off"
  141. else:
  142. fx = "cosinus"
  143. if attr == "TILT":
  144. if cspeed < 0:
  145. fx = "off"
  146. else:
  147. fx = "sinus"
  148. elif ":RED" in f_name:
  149. fxon = "on"
  150. fxoff = "static" #"off"
  151. MODE = fx_modes[fx_prm["MODE"]]
  152. if "RED" in MODE:
  153. base="-"
  154. if attr == "RED":
  155. fx = fxon # ON ----
  156. #csize *=-1
  157. if attr == "GREEN":
  158. fx = "static"
  159. csize = 0
  160. if attr == "BLUE":
  161. fx = "static"
  162. csize = 0
  163. elif "GREEN" in MODE:
  164. base="-"
  165. if attr == "RED":
  166. fx = "static"
  167. csize = 0
  168. if attr == "GREEN":
  169. fx = fxon # ON ----
  170. csize *=-1
  171. if attr == "BLUE":
  172. fx = "static"
  173. csize = 0
  174. elif "BLUE" in MODE:
  175. base="-"
  176. if attr == "RED":
  177. fx = "static"
  178. csize = 0
  179. if attr == "GREEN":
  180. fx = "static"
  181. csize = 0
  182. if attr == "BLUE":
  183. fx = fxon # ON ----
  184. csize *=-1
  185. elif "YELLOW" in MODE:
  186. base="-"
  187. if attr == "RED":
  188. fx = fxon
  189. csize *=-1
  190. if attr == "GREEN":
  191. fx = fxon
  192. csize *=-1
  193. if attr == "BLUE":
  194. fx = "static"
  195. csize = 0
  196. elif "CYAN" in MODE:
  197. base="-"
  198. if attr == "RED":
  199. fx = fxoff
  200. invert *= -1
  201. csize = 0
  202. fx = fxon
  203. if attr == "GREEN":
  204. fx = fxon
  205. csize=0
  206. if attr == "BLUE":
  207. fx = fxon
  208. csize=0
  209. elif "MAG" in MODE:
  210. base="-"
  211. if attr == "RED":
  212. fx = fxon
  213. csize=0
  214. if attr == "GREEN":
  215. fx = fxoff
  216. invert *= -1
  217. csize = 0
  218. fx = fxon
  219. if attr == "BLUE":
  220. fx = fxon
  221. csize=0
  222. else:
  223. cprint("FX: unbekant",fx_modes[fx_prm["MODE"]],color="red")
  224. fxtype = fx
  225. fxtype = fx
  226. if "FX" not in data["ATTRIBUT"][attr]:
  227. data["ATTRIBUT"][attr]["FX"] =""
  228. if "FX2" not in data["ATTRIBUT"][attr]:
  229. data["ATTRIBUT"][attr]["FX2"] ={}
  230. if data["ATTRIBUT"][attr]["ACTIVE"] and fxtype:
  231. fjdata = {}
  232. if cspeed < 0.1:
  233. fjdata["TYPE"] = "off"
  234. else:
  235. fjdata["TYPE"] = fxtype
  236. fjdata["SIZE"] = round(csize,2)
  237. fjdata["SPEED"] = round(cspeed,2)
  238. fjdata["WIDTH"] = int(width)
  239. fjdata["START"] = cstart
  240. if attr in ["PAN","TILT"]:
  241. fjdata["OFFSET"]= round(coffset_move,2)
  242. else:
  243. fjdata["OFFSET"]= round(coffset,2)
  244. fjdata["INVERT"]= int(invert)
  245. fjdata["BASE"] = cbase
  246. jdata["FX2"] = fjdata
  247. data["ATTRIBUT"][attr]["FX2"] = fjdata
  248. jdatas.append(jdata)
  249. #print("GOO FX:",jdata)
  250. if fx_prm_move["OFFSET"] > 0.5: # and
  251. aoffset_move = (100/count_of_fix_in_wing) * (fx_prm_move["OFFSET"]/100)
  252. if fx_prm_move["DIR"] <= 0:
  253. offset_move -= aoffset_move
  254. else:
  255. offset_move += aoffset_move
  256. offset_move = round(offset_move,2)
  257. if fx_prm["OFFSET"] > 0.5: # and
  258. aoffset = (100/count_of_fix_in_wing) * (fx_prm["OFFSET"]/100)
  259. if fx_prm["DIR"] <= 0:
  260. offset -= aoffset
  261. else:
  262. offset += aoffset
  263. offset = round(offset,2)
  264. #exit()
  265. if jdatas and not modes.val("BLIND"):
  266. jclient_send(jdatas)
  267. master._refresh_fix()
  268. return jdatas