_console.py 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. #! /usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. This file is part of LibreLight.
  5. LibreLight is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, version 2 of the License.
  8. LibreLight is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with LibreLight. If not, see <http://www.gnu.org/licenses/>.
  14. (c) 2012 micha@librelight.de
  15. """
  16. import sys
  17. import time
  18. import json
  19. import zlib
  20. rnd_id = ""
  21. rnd_id += " Beta 22.02 "
  22. import subprocess
  23. import tool.git as git
  24. rnd_id += git.get_all()
  25. if "__file__" in dir():
  26. sys.stdout.write("\x1b]2;"+str(__file__)+" "+rnd_id+"\x07") # terminal title
  27. else:
  28. sys.stdout.write("\x1b]2;"+str("__file__")+" "+rnd_if+"\x07") # terminal title
  29. __run_main = 0
  30. if __name__ == "__main__":
  31. __run_main = 1
  32. else:
  33. import __main__
  34. print(dir())
  35. if "unittest" not in dir(__main__):
  36. __run_main = 1
  37. import time
  38. import socket
  39. import struct
  40. import sys
  41. import random
  42. import math
  43. from collections import OrderedDict
  44. import lib.zchat as chat
  45. import lib.ArtNetNode as ANN
  46. import _thread as thread
  47. #thread.start_new_thread
  48. import lib.motion as motion
  49. #idmx = [0]*512 # incremental dmx
  50. dmx = [0]*512 # absolute dmx data
  51. gcolor = 1
  52. def cprint(*text,color="blue",space=" ",end="\n"):
  53. #return 0 #disable print dbg
  54. if not gcolor:
  55. print(text)
  56. return 0
  57. if color == "green":
  58. txt = '\033[92m'
  59. elif color == "red":
  60. txt = '\033[0;31m\033[1m'
  61. elif color == "yellow":
  62. txt = '\033[93m\033[1m'
  63. elif color == "cyan":
  64. txt = '\033[96m'
  65. else:
  66. txt = '\033[94m'
  67. for t in text:
  68. txt += str(t ) +" "
  69. #HEADER = '\033[95m'
  70. #OKBLUE = '\033[94m'
  71. #OKCYAN = '\033[96m'
  72. #OKGREEN = '\033[92m'
  73. #WARNING = '\033[93m'
  74. #FAIL = '\033[91m'
  75. #ENDC = '\033[0m'
  76. #BOLD = '\033[1m'
  77. #UNDERLINE = '\033[4m'
  78. txt += '\033[0m'
  79. print(txt,end=end)
  80. #return txt
  81. def artnet_loop():
  82. #artnet = ANN.ArtNetNode(to="127.0.0.1",port=6555,univ=12)
  83. #artnet = ANN.ArtNetNode(to="127.0.0.1",port=6555,univ=0)
  84. artnet = ANN.ArtNetNode(to="10.10.10.255",univ=0)
  85. #artnet = ANN.ArtNetNode(to="2.0.0.255",univ=0)
  86. #artnet = ANN.ArtNetNode(to="10.10.10.255",univ=1)
  87. #dmx[205] = 255 #205 BLUE
  88. artnet.dmx= dmx #[0]*512
  89. artnet.send()
  90. while 1:
  91. #artnet._test_frame()
  92. artnet.next()
  93. time.sleep(0.001)
  94. class CLOCK():
  95. def __init__(self):
  96. self.__time = 0
  97. self.__start = time.time() # only for debugging
  98. self.__tick = 0.01 # incremental timer drift's on highe cpu load ?
  99. def time(self):
  100. return self.__time
  101. def get_drift(self):
  102. run_time = time.time() - self.__start
  103. tick_time = self.__time # * self.__tick
  104. print( "runtime:{:0.2f} tick_timer:{:0.2f} drift:{:0.2f}".format(run_time,tick_time,run_time-tick_time))
  105. def loop(self):
  106. while 1:
  107. self.__time +=self.__tick
  108. #if int(self.__time*100)/10. % 10 == 0:# self.__time % 2 == 0:
  109. # print( self.get_drift())
  110. #print(self.__time)
  111. #for i in range(10):
  112. time.sleep(self.__tick)
  113. class CLOCK_REAL():
  114. def __init__(self):
  115. self.__time = 0
  116. self.__start = time.time() # only for debugging
  117. self.__tick = 0.001 # incremental timer drift's on highe cpu load ?
  118. def time(self):
  119. self.__time = time.time()
  120. return self.__time
  121. def get_drift(self):
  122. run_time = time.time() - self.__start
  123. tick_time = self.__time # * self.__tick
  124. print( "runtime:{:0.2f} tick_timer:{:0.2f} drift:{:0.2f}".format(run_time,tick_time,run_time-tick_time))
  125. def loop(self):
  126. pass
  127. #clock = CLOCK()
  128. clock = CLOCK_REAL()
  129. if __run_main:
  130. thread.start_new_thread(clock.loop,())
  131. class Fade():
  132. def __init__(self,start,target,ftime,clock,delay=0):
  133. #print("init Fade ",start,target,ftime,clock)
  134. if delay < 0:
  135. delay = 0.0001
  136. if ftime <= 0:
  137. ftime = 0.0001
  138. clock += delay
  139. self.__delay = delay
  140. self.__clock = clock
  141. self.__clock_curr = clock
  142. self.__ftime = ftime
  143. self.__start = start
  144. self.__last = start
  145. self.__target = target
  146. self.run = 1
  147. #print("INIT", str(self) )
  148. def __str__(self):
  149. return self.__repr__()
  150. def __repr__(self):
  151. return "<FADE Next:{:0.2f} from:{:0.2f} to:{:0.2f} ft:{:0.2f} Clock:{:0.2f} run:{} delay:{:0.2f}>".format(
  152. self.__last, self.__start,self.__target,self.__ftime,self.__clock_curr,self.run,self.__delay )
  153. def next(self,clock=None):
  154. if self.__ftime <= 0 and self.__delay <= 0:
  155. self.__last = self.__target
  156. self.run = 0
  157. if type(clock) is float or type(clock) is int:#not None:
  158. self.__clock_curr = clock
  159. if self.__target > self.__start:
  160. if self.__last >= self.__target:
  161. self.run = 0
  162. return self.__target
  163. else:
  164. if self.__last <= self.__target:
  165. self.run = 0
  166. return self.__target
  167. current = (self.__clock - self.__clock_curr) / self.__ftime
  168. length = self.__start - self.__target
  169. self.__last = self.__start+ length*current
  170. #if self.__last < 0:
  171. # self.__last = 0
  172. #if self.__last > 255:
  173. # self.__last = 255
  174. self.run = 1
  175. return self.__last
  176. def ctl(self,cmd="",value=None): # if x-fade cmd="%" value=50
  177. # start,stop,fwd,bwd,revers
  178. pass
  179. class _MASTER():
  180. def __init__(self,name="None"):
  181. self.__data = {}
  182. self.name = name
  183. def val(self,name,value=None):
  184. _value = 100 #%
  185. name = str(name)
  186. if name not in self.__data:
  187. self.__data[name] = 100
  188. _value = self.__data[name]
  189. if value is not None:
  190. if _value != value:
  191. print(self.name,"CHANGE MASTER:",name,"from:",_value,"to:",value)
  192. self.__data[name] = value
  193. _value = self.__data[name]
  194. return _value /100.
  195. exec_size_master = _MASTER("EXEC-SIZE")
  196. exec_speed_master = _MASTER("EXEC-SPEED")
  197. exec_offset_master = _MASTER("EXEC-OFFSET")
  198. size_master = _MASTER("SIZE")
  199. speed_master = _MASTER("SPEED")
  200. exe_master = []
  201. exe_master.append({"SIZE":100,"SPEED":100,"id":12,"link-ids":[2]})
  202. class MASTER_FX():
  203. def __init__(self):
  204. #cprint(self,"MASTER_FX INIT !",color="green")
  205. self.__data = []
  206. self.__ok = []
  207. self.i=0
  208. self.old_offsets = []
  209. self.offsets = []
  210. self.count = -1
  211. self.init = 10
  212. def add(self,fx):
  213. if fx not in self.__data:
  214. #cprint(self,"ADD TO MASTER !",color="green")
  215. self.__data.append(fx)
  216. info = fx._get_info()
  217. #cprint(self,"ADD" ,info,color="green")
  218. offset = 0
  219. if "offset" in info:
  220. offset = info["offset"]
  221. self.old_offsets.append(offset)
  222. self.offsets.append(offset)
  223. if "xtype" in info:
  224. if info["xtype"] == "rnd":
  225. self._shuffle()
  226. #self.init += 1
  227. def _shuffle(self):
  228. #cprint(self,"REORDER RANDOM !",color="green")
  229. #self.init = 0
  230. #cprint(self.old_offsets)
  231. random.shuffle(self.old_offsets)
  232. #cprint(self.old_offsets)
  233. def _init(self):
  234. self._shuffle()
  235. #self.offsets = []
  236. for i,v in enumerate(self.old_offsets):
  237. offset = self.old_offsets[i]
  238. self.offsets[i] = offset
  239. self.init = 0
  240. def next(self,child):
  241. i = self.__data.index(child)
  242. offset = self.old_offsets[i]
  243. self.offsets[i] = offset
  244. return offset
  245. #for i,v in enumerate(self.old_offsets):
  246. # offset = self.old_offsets[i]
  247. # self.offsets[i] = offset
  248. def get(self,child,count):
  249. offset = 0
  250. if child not in self.__data:
  251. return offset
  252. if self.init:
  253. self._init()
  254. idx = self.__data.index(child)
  255. if (self.count != count and idx == 0 ) or self.init == 0:
  256. self.init = 1
  257. self._shuffle()
  258. #print( count)
  259. self.count=count
  260. idx = self.__data.index(child)
  261. offset = self.offsets[idx]
  262. return offset
  263. class FX():
  264. def __init__(self,xtype="sinus",size=10,speed=10,invert=0,width=100,start=0,offset=0,base="",clock=0,master=None,master_id=0):
  265. self.__xtype=xtype
  266. self.__size = size
  267. self.__start = start
  268. self.__master_id = master_id
  269. if width > 200:
  270. width = 200
  271. if width <= 0:
  272. width = 1
  273. self.__fade_in_master = 0
  274. self.__width = width
  275. self.__invert = invert
  276. self.__base = base
  277. self.__speed = speed
  278. self.__offset = offset
  279. self.__clock = clock
  280. self.__clock_curr = clock
  281. self.__clock_delta = 0
  282. self.__clock_old = self.__clock_curr
  283. self.out = 0
  284. self.old_v = -1
  285. self.run = 1
  286. self.count = -1
  287. self.__angel = self.__clock_curr*360%360
  288. if master is None:
  289. cprint(master, "MASTER_FX ERR",master,color="red")
  290. self.__master = MASTER_FX()
  291. self.__master.add(self)
  292. else:
  293. #cprint( "MASTER_FX OK",master,color="red")
  294. self.__master = master
  295. self.__master.add(self)
  296. if self.__xtype == "rnd":
  297. self.__offset = self.__master.get(self,-2)
  298. self.__offset = self.__master.next(self)#,count)
  299. self._exec_id = None
  300. self.next()
  301. #print("init FX",self)
  302. def exec_id(self,_id=None):
  303. if type(_id) is not type(None):
  304. self._exec_id = str(_id)
  305. return self._exec_id
  306. def _get_info(self):
  307. #print("self.__offset",self.__offset)
  308. return {"offset":self.__offset,"xtype":self.__xtype}
  309. #return self.next(),self.__xtype, self.__size,self.__speed,self.__angel, self.__base,self.__clock_curr,self.run
  310. def __str__(self):
  311. return self.__repr__()
  312. def __repr__(self):
  313. return "<FX Next:{:0.2f} xtype:{} Size:{:0.2f} Speed:{:0.2f} ang:{:0.2f} base:{} Clock:{:0.2f} run:{} EXEC:{}>".format(
  314. self.next(),self.__xtype, self.__size,self.__speed,self.__angel, self.__base,self.__clock_curr,self.run,self._exec_id )
  315. def next(self,clock=None):
  316. if type(clock) is float or type(clock) is int:#not None:
  317. self.__clock_curr = clock
  318. d = (self.__clock_curr - self.__clock_old)
  319. #print()
  320. #print("A",d)
  321. m1 = ( speed_master.val(self.__master_id)) # global speed-master
  322. #print("B {:0.4}".format(m1))
  323. m2 = ( exec_speed_master.val(self._exec_id)) # exec start by 0
  324. #print("C {:0.4}".format(m2))
  325. shift = 0
  326. m = (m1 * m2) -1
  327. shift += d * m
  328. #print("D",shift)
  329. self.__clock_delta += shift
  330. #print(self.__clock_delta )
  331. self.__clock_old = self.__clock_curr
  332. t = self.__clock_curr
  333. t += self.__clock_delta
  334. t *= self.__speed / 60
  335. offset2 = self.__offset
  336. offset2 *= exec_offset_master.val(self._exec_id)
  337. #t += self.__offset / 100 #255 #1024 #255
  338. t += offset2 / 100
  339. t += self.__start / 1024 #255
  340. #t = t*speed_master.val(self.__master_id)
  341. tw = t%1
  342. count = t//1
  343. t = t * (100/self.__width)
  344. if tw > self.__width/100:
  345. t = 1
  346. self.__angel = t%1*360
  347. t = t%1
  348. rad = math.radians(self.__angel)
  349. v=0
  350. out = 0
  351. base = 0
  352. size = self.__size
  353. if self.__base == "+": # add
  354. base = size/2
  355. elif self.__base == "-": # sub
  356. base = size/2*-1
  357. if self.__xtype == "sinus":
  358. v = math.sin( rad )
  359. v/=2
  360. elif self.__xtype == "cosinus":
  361. v = math.cos( rad )
  362. if self.__base == "+": # add
  363. size *= -1
  364. v/=2
  365. elif self.__xtype == "rnd":
  366. #base = 0
  367. if self.__angel > 90 and self.__angel <=270:
  368. v=1
  369. else:
  370. v=0
  371. #if count != self.count and v: # % 2 == 0:#!= self.count:
  372. # #self.__offset = random.randint(0,1024)# /1024
  373. # self.__master._shuffle()
  374. if count != self.count and v == 0: # and v: # % 2 == 0:#!= self.count:
  375. self.__master.next(self)#,count)
  376. #self.__master.next(self)#,count)
  377. self.__offset = self.__master.get(self,count)
  378. base = 0
  379. if self.__base == "-": # sub
  380. if self.__invert:
  381. v = 1-v
  382. #base = -size
  383. size *=-1
  384. v *=-1
  385. elif self.__base == "+": # sub
  386. if self.__invert:
  387. v = v-1
  388. else:
  389. v = (t%1-0.5)
  390. elif self.__xtype == "on":
  391. #base = 0
  392. if self.__angel > 90 and self.__angel <=270:
  393. v=1
  394. else:
  395. v=0
  396. base = 0
  397. if self.__base == "-": # sub
  398. if self.__invert:
  399. v = 1-v
  400. #base = -size
  401. size *=-1
  402. v *=-1
  403. elif self.__base == "+": # sub
  404. if self.__invert:
  405. v = v-1
  406. else:
  407. v = (t%1-0.5)
  408. elif self.__xtype == "ramp" or self.__xtype == "ramp":
  409. v = (t%1)
  410. base = 0
  411. if self.__base == "-": # sub
  412. if self.__invert:
  413. v = 1-v
  414. #base = -size
  415. size *=-1
  416. v *=-1
  417. elif self.__base == "+": # sub
  418. if self.__invert:
  419. v = v-1
  420. else:
  421. v = (t%1-0.5)
  422. elif self.__xtype == "ramp2" or self.__xtype == "bump2":
  423. v = (t%1)
  424. v = 1-v
  425. if v == 1:
  426. v=0
  427. base = 0
  428. if self.__base == "-": # sub
  429. if self.__invert:
  430. v = 1-v
  431. #base = -size
  432. size *=-1
  433. v *=-1
  434. elif self.__base == "+": # sub
  435. if self.__invert:
  436. v = v-1
  437. else:
  438. v = (t%1-0.5)
  439. elif self.__xtype == "fade":
  440. x = t * 2
  441. if x > 1:
  442. x = 2-x
  443. x -= 0.5
  444. v = x*2
  445. #base /= 2
  446. #base *=2
  447. if self.__base == "+": # add
  448. pass#base /= 2
  449. else:
  450. v *= -1
  451. v/=2
  452. if self.__invert:
  453. v *=-1
  454. #if self.__fade_in_master < 255:
  455. # self.__fade_in_master += v*size
  456. out = v *size +base
  457. self.out = out
  458. self.count = count
  459. out = out * size_master.val(self.__master_id) # master
  460. out = out * exec_size_master.val(self._exec_id) # master
  461. #* (self.__fade_in_master /255.)
  462. return out
  463. class DMXCH(object):
  464. def __init__(self,dmx=-1):
  465. self._base_value = 0
  466. self._fade = None
  467. self._fx = [None,None] # None
  468. self._fx_value = 0
  469. self._dmx = dmx
  470. self._dmx_fine = 0
  471. self._fix_id = 0
  472. self._v_master_id=0
  473. self._flash = None
  474. self._flash_fx = None
  475. self._flash_fx_value = 0
  476. self._last_val = None
  477. self._exec_id = None
  478. #self.next(clock)
  479. #print("init",self)
  480. def fade(self,target,ftime=0,clock=0,delay=0):
  481. if target != self._base_value:
  482. try:
  483. target = float(target)
  484. self._fade = Fade(self._base_value,target,ftime=ftime,clock=clock,delay=delay)
  485. #self._fade.next()
  486. #self._fade.next()
  487. except Exception as e:
  488. print( "Except:fade",e,target,ftime,clock)
  489. self.next(clock)
  490. #print("init fade",self)
  491. def fx(self,xtype="sinus",size=40,speed=40,invert=0,width=100,start=0,offset=0,base="", clock=0,master=None):
  492. #print("DMXCH.fx",[self,xtype,size,speed,start,offset,base, clock])
  493. self._fx[0] = self._fx[1]
  494. if str(xtype).lower() == "off":
  495. fx_value = self._fx_value
  496. if fx_value != 0:
  497. cprint("???????______ FX OFF AS FADE",fx_value,0,255)
  498. self._fx[1] = Fade(fx_value,0,ftime=0.5,clock=clock)
  499. else:
  500. self._fx[1] = None
  501. self._fx_value = 0
  502. else:
  503. self._fx[1] = FX(xtype=xtype,size=size,speed=speed,invert=invert,width=width,start=start,offset=offset,base=base,clock=clock,master=master,master_id=1)
  504. self._fx[1].exec_id(self._exec_id)
  505. self.next(clock)
  506. #print("init fx",self)
  507. def flash(self,target,ftime=0,clock=0,delay=0):
  508. if str(target).lower() == "off":
  509. self._flash = None
  510. else:#elif target != self._base_value:
  511. try:
  512. target = float(target)
  513. self._flash = Fade(self._last_val,target,ftime=ftime,clock=clock,delay=delay)
  514. except Exception as e:
  515. print( "Except:flash",target,ftime,clock,__name__,e,)
  516. self.next(clock)
  517. #print("init flush",self)
  518. def flash_fx(self,xtype="sinus",size=40,speed=40,invert=0,width=100,start=0,offset=0,base="",clock=0,master=None):
  519. if str(xtype).lower() == "off":
  520. fx_value = self._fx_value
  521. self._flash_fx = None
  522. self._flash_fx_value = 0
  523. else:
  524. self._flash_fx = FX(xtype=xtype,size=size,speed=speed,invert=invert,width=width,start=start,offset=offset,base=base,clock=clock,master=master,master_id=0)
  525. self._flash_fx.exec_id(self._exec_id)
  526. self.next(clock)
  527. #print("init flash_fx",self)
  528. def fx_ctl(self,cmd=""): #start,stop,off
  529. pass
  530. def __str__(self):
  531. return self.__repr__()
  532. def exec_id(self,_id=None):
  533. if type(_id) is not type(None):
  534. self._exec_id = _id
  535. #print("set exec_id",_id)
  536. return self._exec_id
  537. def __repr__(self):
  538. print(self._dmx,self._dmx_fine, self._last_val,self._exec_id,self._fx,self._fade)
  539. return "<BUFFER {} {} v:{} EXEC:{}> fx:[{}] fd:{}".format(self._dmx,self._dmx_fine, self._last_val,self._exec_id,self._fx,self._fade)
  540. return "<BUFFER {} {} v:{:0.2f} EXEC:{}> fx:[{}] fd:{}".format(self._dmx,self._dmx_fine, self._last_val,self._exec_id,self._fx,self._fade)
  541. def fade_ctl(self,cmd=""): #start,stop,backw,fwd,bounce
  542. pass
  543. def next(self,clock=0):
  544. try:
  545. self._next(clock)
  546. except Exception as e:
  547. cprint("Exception DMXCH.next()" ,e)
  548. out = self._last_val
  549. return out
  550. def _next(self,clock=0):
  551. value = self._base_value
  552. if self._last_val is None:
  553. self._last_val = value
  554. fx_value = self._fx_value
  555. if self._flash is not None:
  556. value = self._flash.next(clock)
  557. #flicker bug ?!
  558. value = self._flash.next(clock)
  559. fx_value = 0
  560. elif self._fade is not None:#is Fade:# is Fade:
  561. self._base_value = self._fade.next(clock)
  562. self._base_value = self._fade.next(clock) #flicker bug ?!
  563. value = self._base_value
  564. if self._flash_fx is not None:# is FX:
  565. fx_value = self._flash_fx.next(clock)
  566. else:
  567. self._fx_value = 0
  568. if self._fx[-1] is not None and self._flash is None:# is FX:
  569. self._fx_value += self._fx[-1].next(clock)
  570. fx_value = self._fx_value
  571. self._last_val = value + fx_value
  572. #self._last_val *= v_master.val(self._fix_id)
  573. if self._v_master_id in V_MASTER:
  574. vm = V_MASTER[self._v_master_id].next(clock)
  575. #print("V_MASTER is ", V_MASTER[self._v_master_id])
  576. vm = vm/256
  577. self._last_val *= vm # v_master.val(self._v_master_id)
  578. #out = self._last_val * htp_master.master_by_dmx(self._dmx)
  579. out = self._last_val
  580. return out
  581. V_MASTER = {} #DMXCH
  582. Bdmx = []
  583. for i in range(512*7+1):
  584. Bdmx.append( DMXCH(i) )
  585. #print(type(dmx[i]))
  586. _id = 1
  587. def split_cmd(data):
  588. if "cmd" in data:
  589. cmd = data["cmd"]
  590. #print("cmd",cmd)
  591. if "," in cmd:
  592. cmds = cmd.split(",")
  593. else:
  594. cmds = [cmd]
  595. return cmds
  596. class VDMX():
  597. """functional implementation as class for namespace encapsulation
  598. """
  599. def __init__(self):
  600. self.data = OrderedDict()
  601. self.data[4] = {"DMX":[21,22,23],"VALUE":255, "LIMIT":255} #,"DMXCH":DMXCH("V4")}
  602. for k,v in self.data.items():
  603. pass
  604. #dmxch = v["DMXCH"]
  605. #dmxch.fade(10,0)
  606. #dmxch.fx(size=200,speed=200,base="-") #self,xtype="sinus",size=40,speed=40,invert=0,width=100,start=0,offset=0,base="", clock=0,master=None):
  607. def _list_by_dmx(self,_dmx=0):
  608. data = OrderedDict()
  609. for i,link in self.data.items(): # enumerate(self.data):
  610. if _dmx in link["DMX"]:
  611. #print( "_list_by_dmx",i,link)
  612. data[i] = link
  613. return data
  614. def dmx_by_id(self,_id=0):
  615. #print("dmx by master-id:",_id)
  616. if _id in self.data:
  617. for i,link in self.data[_id].items():
  618. #print("dmx_by_id", i,link)
  619. return (i,link)
  620. return 0,{}
  621. def by_dmx(self,clock,dmx):
  622. #print("master of dmx:",dmx)
  623. val=0
  624. flag = 0
  625. data = self._list_by_dmx(dmx)
  626. for i,row in data.items():
  627. if "DMXCH" not in row:
  628. row["DMXCH"] = DMXCH("V{}".format(i))
  629. row["DMXCH"].fade(255,0)
  630. v = row["DMXCH"].next(clock)
  631. #row["DMXCH"].fade(200,20)
  632. if v >= val:
  633. val = v
  634. flag = 1
  635. out = 1.
  636. if val > 255:
  637. val = 255
  638. if flag:
  639. out = val/255.
  640. else:
  641. out = 1.
  642. return out
  643. vdmx = VDMX()
  644. class HTP_MASTER():
  645. """functional implementation as class for namespace encapsulation
  646. """
  647. def __init__(self):
  648. self.data = OrderedDict()
  649. #self.data[1] = {"DMX":[1,2,3],"VALUE":80, "LIMIT":255}
  650. #self.data[2] = {"DMX":[12,13,22],"VALUE":70, "LIMIT":255}
  651. #self.data[3] = {"DMX":[22,23,24],"VALUE":99, "LIMIT":255}
  652. self.data[4] = {"DMX":[22,23,24],"VALUE":99, "LIMIT":255,"DMXCH":DMXCH(4)}
  653. def _list_by_dmx(self,_dmx=0):
  654. data = OrderedDict()
  655. for i,link in self.data.items(): # enumerate(self.data):
  656. if _dmx in link["DMX"]:
  657. #print( "_list_by_dmx",i,link)
  658. data[i] = link
  659. return data
  660. def dmx_by_id(self,_id=0):
  661. #print("dmx by master-id:",_id)
  662. if _id in self.data:
  663. for i,link in self.data[_id].items():
  664. #print("dmx_by_id", i,link)
  665. return (i,link)
  666. return 0,{}
  667. def val_by_dmx(self,dmx=0):
  668. #print("master of dmx:",dmx)
  669. val=0
  670. flag = 0
  671. data = self._list_by_dmx(dmx)
  672. for i,link in data.items():
  673. #print("master_by_dmx", i,link)
  674. if link["VALUE"] > val:
  675. #print("master_by_dmx", i,link)
  676. val = link["VALUE"]
  677. flag=1
  678. out = 1.
  679. if flag:
  680. out = val/255.
  681. return out
  682. htp_master = HTP_MASTER()
  683. #htp_master.data[_id] = {"DMX":[1,2,3],"VALUE":80, "LIMIT":255,"DMXCH":DMXCH()}
  684. class Main():
  685. def __init__(self):
  686. #artnet = ANN.ArtNetNode(to="127.0.0.1",port=6555,univ=12)
  687. #artnet = ANN.ArtNetNode(to="127.0.0.1",port=6555,univ=0)
  688. #artnet = ANN.ArtNetNode(to="2.0.0.255",univ=0)
  689. #artnet = ANN.ArtNetNode(to="10.10.10.255",univ=1)
  690. self.artnet = {}
  691. #self.artnet["0"] = ANN.ArtNetNode(to="10.10.10.255",univ=0)
  692. #self.artnet["0"].dmx[512-1] = 10
  693. #self.artnet["1"] = ANN.ArtNetNode(to="10.10.10.255",univ=1)
  694. #self.artnet["1"].dmx[512-1] = 11
  695. self.fx = {} # key is dmx address
  696. self.lock = thread.allocate_lock()
  697. def loop(self):
  698. #dmx[205] = 255 #205 BLUE
  699. #self.artnet.send()
  700. xx = [0]*512
  701. #artnet = self.artnet["0"]
  702. #artnet.dmx = xx# [:] #dmx #[0]*512
  703. ii = 0
  704. old_univ = -1
  705. xx = [0]*512
  706. for ii,dmxch in enumerate(Bdmx):
  707. i = ii%512
  708. univ = ii//512
  709. if str(univ) not in self.artnet:
  710. print("add uiv",univ)
  711. self.artnet[str(univ)] = ANN.ArtNetNode(to="10.10.10.255",univ=univ)
  712. #self.artnet[str(univ)].dmx[512-1] = 100+univ
  713. if univ != old_univ:
  714. old_univ = univ
  715. #print("UNIV",ii/512)
  716. try:
  717. artnet.next()
  718. except:pass
  719. artnet = self.artnet[str(univ)]
  720. artnet.dmx = [0]*512
  721. fps_start = time.time()
  722. fps = 0
  723. while 1:
  724. self.lock.acquire_lock()
  725. t = clock.time()
  726. ii = 0
  727. old_univ = -1
  728. xx = [0]*512
  729. for ii,dmxch in enumerate(Bdmx):
  730. i = ii%512
  731. univ = ii//512
  732. if str(univ) not in self.artnet:
  733. print("add uiv",univ)
  734. self.artnet[str(univ)] = ANN.ArtNetNode(to="10.10.10.255",univ=univ)
  735. #self.artnet[str(univ)].dmx[512-1] = 100+univ
  736. if univ != old_univ:
  737. old_univ = univ
  738. #print("UNIV",ii/512)
  739. try:
  740. artnet.next()
  741. except:pass
  742. artnet = self.artnet[str(univ)]
  743. #artnet.dmx = xx
  744. old_univ = -1
  745. xx = [0]*512
  746. for ii,dmxch in enumerate(Bdmx):
  747. i = ii%512
  748. univ = ii//512
  749. if univ != old_univ:
  750. old_univ = univ
  751. artnet = self.artnet[str(univ)]
  752. xx = artnet.dmx
  753. v = dmxch.next(t)
  754. vv = vdmx.by_dmx(clock=i,dmx=ii+1)
  755. try:
  756. v = v*vv # disable v-master
  757. except Exception as e:
  758. cprint("Exception v*vv",[v,vv],e)
  759. continue
  760. xx[i] = int(v)
  761. old_univ = -1
  762. xx = [0]*512
  763. for ii,dmxch in enumerate(Bdmx): #fine loop
  764. i = ii%512
  765. univ = ii//512
  766. if univ != old_univ:
  767. artnet = self.artnet[str(univ)]
  768. xx = artnet.dmx# = xx
  769. v = dmxch.next(t)
  770. vv = vdmx.by_dmx(clock=i,dmx=ii+1)
  771. try:
  772. v = v*vv # disable v-master
  773. except Exception as e:
  774. cprint("Exception v*vv",[v,vv],e)
  775. continue
  776. #xx[i] = int(v)
  777. dmx_fine = dmxch._dmx_fine
  778. if dmx_fine > 0:
  779. vf = int(v%1*255)
  780. #print(dmx_fine,end=" ")
  781. dmx_fine = dmx_fine%512
  782. #print(dmx_fine,end=" ")
  783. #print(int(v),end=" ")
  784. #print(vf,end=" ")
  785. #print()
  786. #univ = ii//512
  787. try:
  788. #xx[dmx_fine+1] = 9# int(v%1*255)
  789. if v >= 255:
  790. xx[dmx_fine-1] = 255
  791. elif v < 0:
  792. xx[dmx_fine-1] = 0
  793. else:
  794. xx[dmx_fine-1] = int(v%1*255)
  795. except Exception as e:
  796. print("E dmx_fine",e,dmx_fine)
  797. try:
  798. artnet.next()
  799. except:pass
  800. self.lock.release_lock()
  801. #self.lock.acquire_lock()
  802. #time.sleep(1/35)
  803. fps += 1
  804. stop_fps = 50
  805. time.sleep(1/60)
  806. if fps >= stop_fps:
  807. fps_t = time.time()
  808. #print(int((fps_t-fps_start)*1000),"ms")
  809. print(round(stop_fps/(fps_t-fps_start),2),"core/fps")
  810. fps = 0
  811. fps_start = time.time()
  812. time.sleep(1/60)
  813. main = Main()
  814. if __run_main:
  815. #thread.start_new_thread(artnet_loop,())
  816. thread.start_new_thread(main.loop,())
  817. def _init_action(row):#Bdmx,out,DMX):
  818. Admx = row["DMXCH"]
  819. if row["fx"]:
  820. x = row["fx"]
  821. Admx.fx(xtype=x["xtype"]
  822. ,size=x["size"]
  823. ,speed=x["speed"]
  824. ,invert=x["invert"]
  825. ,width=x["width"]
  826. ,start=x["start"]
  827. ,offset=x["offset"]
  828. ,base=x["base"]
  829. ,clock=x["clock"]
  830. ,master=x["master"])
  831. if row["flash_fx"]:
  832. x = row["flash_fx"]
  833. Admx.flash_fx(xtype=x["xtype"]
  834. ,size=x["size"]
  835. ,speed=x["speed"]
  836. ,invert=x["invert"]
  837. ,width=x["width"]
  838. ,start=x["start"]
  839. ,offset=x["offset"]
  840. ,base=x["base"]
  841. ,clock=x["clock"]
  842. ,master=x["master"])
  843. if row["flash"]:
  844. x = row["flash"]
  845. Admx.flash(target=x["target"]
  846. ,ftime=x["ftime"]
  847. ,clock=x["clock"]
  848. ,delay=x["delay"])
  849. if row["fade"]:
  850. x = row["fade"]
  851. Admx.fade(target=x["target"]
  852. ,ftime=x["ftime"]
  853. ,clock=x["clock"]
  854. ,delay=x["delay"])
  855. def set_dmx_fine_ch(Admx,dmx_fine_nr):
  856. try:
  857. if int(dmx_fine_nr) > 0:
  858. Admx._dmx_fine = int(dmx_fine_nr)
  859. except Exception as e:
  860. cprint(x,color="red")
  861. cprint("except 3455",e,color="red")
  862. def _parse_cmds(cmds,clock=0,master_fx=None):
  863. c=clock
  864. out = {}
  865. for x in cmds:
  866. Admx = DMXCH() #dummy
  867. _fix_id=0
  868. _attr = ""
  869. if "CMD" in x:
  870. print("CMD:",x)
  871. if "EXEC-SPEED-MASTER" == x["CMD"]:
  872. exec_speed_master.val(x["NR"],x["VALUE"])
  873. if "EXEC-SIZE-MASTER" == x["CMD"]:
  874. exec_size_master.val(x["NR"],x["VALUE"])
  875. if "EXEC-OFFSET-MASTER" == x["CMD"]:
  876. exec_offset_master.val(x["NR"],x["VALUE"])
  877. if "SPEED-MASTER" == x["CMD"]:
  878. speed_master.val(x["NR"],x["VALUE"])
  879. if "SIZE-MASTER" == x["CMD"]:
  880. size_master.val(x["NR"],x["VALUE"])
  881. else:
  882. #print("x",x)
  883. if "DMX" in x:
  884. DMX = int(x["DMX"])
  885. else:
  886. continue
  887. if "VALUE" in x:
  888. v = x["VALUE"]
  889. else:
  890. continue
  891. _inc = 0
  892. _fix_id = 0
  893. _val = 0
  894. _clock = 0
  895. exec_id = None
  896. if "VALUE" in x:
  897. _val = x["VALUE"]
  898. if "INC" in x:
  899. _inc = x["INC"]
  900. if "FIX" in x:
  901. _fix_id = x["FIX"]
  902. if "clock" in x:
  903. _clock=x["clock"]
  904. if "ATTR" in x:
  905. _attr = x["ATTR"]
  906. if DMX <= 0: # VIRTUAL
  907. DMX = "FIX"+str(_fix_id)
  908. ok = 0
  909. if "ATTR" in x:
  910. _attr = x["ATTR"]
  911. if "DIM" == x["ATTR"]:
  912. if _fix_id not in V_MASTER:
  913. V_MASTER[_fix_id] = DMXCH()
  914. #print("_val",_val)
  915. #V_MASTER[_fix_id].fade(_val,ftime=0,clock=0,delay=0)
  916. #print(" V-MASTER",_fix_id,_val,_inc)
  917. ok = 1
  918. if _fix_id in V_MASTER:
  919. Admx = V_MASTER[_fix_id]
  920. if not ok:
  921. continue
  922. else:
  923. if DMX < len(Bdmx):
  924. Admx = Bdmx[DMX-1]
  925. else:
  926. print("DMX ADDRESS too BIG",DMX)
  927. continue
  928. if "DMX-FINE" in x and DMX > 0:
  929. set_dmx_fine_ch(Admx, x["DMX-FINE"])
  930. #print("-")
  931. if "EXEC" in x:
  932. exec_id = x["EXEC"]
  933. if "ATTR" in x:
  934. _attr = x["ATTR"]
  935. if "FIX" in x:
  936. _fix_id = x["FIX"]
  937. fx=""
  938. fx2={}
  939. ftime=0
  940. delay=0
  941. if "FX" in x:
  942. fx = x["FX"]
  943. if "FX2" in x:
  944. fx2 = x["FX2"]
  945. if "FADE" in x:
  946. ftime = x["FADE"]
  947. if "DELAY" in x:
  948. delay = x["DELAY"]
  949. #print("---------",[x])
  950. if "FLASH" in x:
  951. if v == "off" and Admx.exec_id() != exec_id:
  952. continue # stop
  953. #Bdmx[DMX].exec_id(exec_id)
  954. Admx.exec_id(exec_id)
  955. out[DMX] = {"flash":{},"fade":{},"fx":{},"flash_fx":{},"fix_id":_fix_id,"attr":_attr,"DMXCH":Admx}
  956. if v is not None:
  957. if "FLASH" in x:
  958. out[DMX]["flash"] = {"target":v,"ftime":ftime, "clock":c,"delay":delay,"DMXCH":Admx}
  959. else:
  960. out[DMX]["fade"] = {"target":v,"ftime":ftime, "clock":c,"delay":delay,"DMXCH":Admx}
  961. if type(fx2) is dict and fx2:
  962. xtype="fade"
  963. size = 10
  964. speed = 10
  965. start = 0
  966. offset= 0
  967. width=100
  968. invert=0
  969. base = "-"
  970. if "TYPE" in fx2:
  971. xtype = fx2["TYPE"]
  972. if "SIZE" in fx2:
  973. size = fx2["SIZE"]
  974. if "SPEED" in fx2:
  975. speed = fx2["SPEED"]
  976. if "OFFSET" in fx2:
  977. offset = fx2["OFFSET"]
  978. if "BASE" in fx2:
  979. base = fx2["BASE"]
  980. if "INVERT" in fx2:
  981. invert = fx2["INVERT"]
  982. if "WIDTH" in fx2:
  983. width = fx2["WIDTH"]
  984. if "off" == x["VALUE"]: #fix fx flash off
  985. xtype= "off"
  986. if "alloff" == xtype.lower():
  987. for dmxch in Bdmx:
  988. if dmxch is not None:
  989. dmxch.flash_fx(xtype="off",clock=c)
  990. dmxch.fx(xtype="off",clock=c)
  991. for j in V_MASTER:
  992. dmxch = V_MASTER[j]
  993. if j is not None:
  994. dmxch.flash_fx(xtype="off",clock=c)
  995. dmxch.fx(xtype="off",clock=c)
  996. if "FLASH" in x:
  997. out[DMX]["flash_fx"] = {"xtype":xtype,"size":size,"speed":speed,
  998. "invert":invert,"width":width,"start":start
  999. ,"offset":offset,"base":base,"clock":c,"master":master_fx}
  1000. else:
  1001. out[DMX]["fx"] = {"xtype":xtype,"size":size,"speed":speed
  1002. ,"invert":invert,"width":width,"start":start
  1003. ,"offset":offset,"base":base,"clock":c,"master":master_fx}
  1004. elif type(fx) is str and fx:
  1005. # old fx like sinus:200:12:244
  1006. ccm = str(DMX+1)+":"+fx
  1007. print("fx",ccm)
  1008. if "FLASH" in x:
  1009. CB({"cmd":"fxf"+ccm})
  1010. else:
  1011. CB({"cmd":"fx"+ccm})
  1012. return out
  1013. import hashlib
  1014. JCB_GLOB_BUF = {}
  1015. def JCB(data,sock=None): #json client input
  1016. t_start = time.time()
  1017. s = time.time()
  1018. e = time.time()
  1019. print("JCB TIME:","{:0.02f}".format(e-s),int(e*100)/100)
  1020. #print("-->-",data)
  1021. jdatas = []
  1022. l2 = 0
  1023. for line in data:
  1024. data2 = json.loads(line)
  1025. l2 += len(data2)
  1026. #print("line:",line)
  1027. jdatas.append(data2) #["CMD"])
  1028. print("INPUT JCB =>",len(data),":",l2)
  1029. c = clock.time()
  1030. c = float(c)
  1031. ftime = 0
  1032. delay = 0
  1033. for cmds in jdatas:
  1034. line = json.dumps(cmds)
  1035. #md5 = hashlib.md5.hexdigest(line)
  1036. master_fx = MASTER_FX()
  1037. if not cmds:
  1038. continue
  1039. try:
  1040. out = _parse_cmds(cmds,clock=c,master_fx=master_fx)
  1041. #cprint("-","{:0.04} sec.".format(time.time()-t_start),color="yellow")
  1042. # ------- ----------------------------------------------------
  1043. except Exception as e:
  1044. cprint("EXCEPTION JCB",e,color="red")
  1045. cprint("----",str(cmds)[:150],"...",color="red")
  1046. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1047. raise e
  1048. if out:
  1049. try:
  1050. try: # second loop to sync-start all dmxch's
  1051. main.lock.acquire_lock()
  1052. for _id in out:
  1053. row = out[_id]
  1054. #print("_id",_id)
  1055. Admx = row["DMXCH"]
  1056. #print("Admx",Admx)
  1057. if row["fix_id"]:
  1058. _fix_id = row["fix_id"]
  1059. Admx._fix_id = _fix_id
  1060. if "attr" in row:
  1061. if row["attr"] in ["RED","GREEN","BLUE","WHITE","AMBER"]: #CYAN,MAGENTA,YELLOW
  1062. Admx._v_master_id = _fix_id
  1063. #print("SET V_MASTER",row)
  1064. _init_action(row)
  1065. e = time.time()
  1066. print(" sub-JCB TIME:","{:0.02f}".format(e-s),int(e*100)/100)
  1067. finally:
  1068. main.lock.release_lock()
  1069. #time.sleep(1/30)
  1070. except Exception as e:
  1071. cprint("EXCEPTION JCB",e,color="red")
  1072. cprint("----",str(cmds)[:150],"...",color="red")
  1073. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1074. raise e
  1075. #cprint(" ","{:0.04} sec.".format(time.time()-t_start),color="yellow")
  1076. e = time.time()
  1077. print("JCB TIME:","{:0.02f}".format(e-s),int(e*100)/100)
  1078. time.sleep(1/60)
  1079. def CB(data): # raw/text client input
  1080. #print("CB",data)
  1081. cmds = split_cmd(data)
  1082. c = clock.time()
  1083. c = float(c)
  1084. ftime = 0
  1085. delay = 0
  1086. for xcmd in cmds:
  1087. if xcmd:
  1088. cprint("CB",xcmd,end=" ")
  1089. pass
  1090. else:
  1091. continue
  1092. if xcmd.startswith("fxf"):
  1093. xxcmd=xcmd[3:].split(":")
  1094. #print("fxf:",xxcmd)
  1095. if "alloff" == xxcmd[1].lower():
  1096. for i in Bdmx:
  1097. if i is not None:
  1098. i.flash_fx(xtype="off",clock=c)
  1099. for i in V_MASTER:
  1100. if i is not None:
  1101. i.flash_fx(xtype="off",clock=c)
  1102. l = xxcmd
  1103. try:
  1104. xtype=""
  1105. size=40
  1106. speed=100
  1107. start=0
  1108. offset=0
  1109. base=""
  1110. k=int(l[0])-1
  1111. xtype=l[1]
  1112. if len(l) >= 3:
  1113. try:size=int(l[2])
  1114. except:pass
  1115. if len(l) >= 4:
  1116. try:speed=int(l[3])
  1117. except:pass
  1118. if len(l) >= 5:
  1119. try:start=int(l[4])
  1120. except:pass
  1121. if len(l) >= 6:
  1122. try:offset=int(l[5])
  1123. except:pass
  1124. if len(l) >= 7:
  1125. try:base=l[6]
  1126. except:pass
  1127. if len(Bdmx) > k:
  1128. #Bdmx[k].fade(target=v,ftime=t, clock=c)
  1129. Bdmx[k].flash_fx(xtype=xtype,size=size,speed=speed,start=start,offset=offset,base=base,clock=c)
  1130. except Exception as e:
  1131. print("EXCEPTION IN FX",e)
  1132. print("Error on line {}".format(sys.exc_info()[-1].tb_lineno))
  1133. elif xcmd.startswith("fx"):
  1134. xxcmd=xcmd[2:].split(":")
  1135. print("DMX:",xxcmd)
  1136. if len(xxcmd) < 2:
  1137. print("xxcmd err",xxcmd,xcmd)
  1138. continue
  1139. if "alloff" == xxcmd[1].lower():
  1140. for i in Bdmx:
  1141. i.fx(xtype="off",clock=c)
  1142. l = xxcmd
  1143. try:
  1144. xtype=""
  1145. size=40
  1146. speed=100
  1147. start=0
  1148. offset=0
  1149. base=""
  1150. k=int(l[0])-1
  1151. xtype=l[1]
  1152. if len(l) >= 3:
  1153. try:size=int(l[2])
  1154. except:pass
  1155. if len(l) >= 4:
  1156. try:speed=int(l[3])
  1157. except:pass
  1158. if len(l) >= 5:
  1159. try:start=int(l[4])
  1160. except:pass
  1161. if len(l) >= 6:
  1162. try:offset=int(l[5])
  1163. except:pass
  1164. if len(l) >= 7:
  1165. try:base=l[6]
  1166. except:pass
  1167. if len(Bdmx) > k:
  1168. #Bdmx[k].fade(target=v,ftime=t, clock=c)
  1169. Bdmx[k].fx(xtype=xtype,size=size,speed=speed,start=start,offset=offset,base=base,clock=c)
  1170. except Exception as e:
  1171. print("EXCEPTION IN FX",xcmd,e)
  1172. print("Error on line {}".format(sys.exc_info()[-1].tb_lineno))
  1173. if __run_main:
  1174. s = chat.Server(cb=JCB)
  1175. while 1:
  1176. s.poll()
  1177. time.sleep(0.001)