_console.py 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442
  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
  315. , self.__base, self.__clock_curr, self.run, self._exec_id )
  316. def next(self,clock=None):
  317. if type(clock) is float or type(clock) is int:#not None:
  318. self.__clock_curr = clock
  319. d = (self.__clock_curr - self.__clock_old)
  320. #print()
  321. #print("A",d)
  322. m1 = ( speed_master.val(self.__master_id)) # global speed-master
  323. #print("B {:0.4}".format(m1))
  324. m2 = ( exec_speed_master.val(self._exec_id)) # exec start by 0
  325. #print("C {:0.4}".format(m2))
  326. shift = 0
  327. m = (m1 * m2) -1
  328. shift += d * m
  329. #print("D",shift)
  330. self.__clock_delta += shift
  331. #print(self.__clock_delta )
  332. self.__clock_old = self.__clock_curr
  333. t = self.__clock_curr
  334. t += self.__clock_delta
  335. t *= self.__speed / 60
  336. offset2 = self.__offset
  337. offset2 *= exec_offset_master.val(self._exec_id)
  338. #t += self.__offset / 100 #255 #1024 #255
  339. t += offset2 / 100
  340. t += self.__start / 1024 #255
  341. #t = t*speed_master.val(self.__master_id)
  342. tw = t%1
  343. count = t//1
  344. t = t * (100/self.__width)
  345. if tw > self.__width/100:
  346. t = 1
  347. self.__angel = t%1*360
  348. t = t%1
  349. rad = math.radians(self.__angel)
  350. v=0
  351. out = 0
  352. base = 0
  353. size = self.__size
  354. if self.__base == "+": # add
  355. base = size/2
  356. elif self.__base == "-": # sub
  357. base = size/2*-1
  358. if self.__xtype == "sinus":
  359. v = math.sin( rad )
  360. v/=2
  361. elif self.__xtype == "cosinus":
  362. v = math.cos( rad )
  363. if self.__base == "+": # add
  364. size *= -1
  365. v/=2
  366. elif self.__xtype == "rnd":
  367. #base = 0
  368. if self.__angel > 90 and self.__angel <=270:
  369. v=1
  370. else:
  371. v=0
  372. #if count != self.count and v: # % 2 == 0:#!= self.count:
  373. # #self.__offset = random.randint(0,1024)# /1024
  374. # self.__master._shuffle()
  375. if count != self.count and v == 0: # and v: # % 2 == 0:#!= self.count:
  376. self.__master.next(self)#,count)
  377. #self.__master.next(self)#,count)
  378. self.__offset = self.__master.get(self,count)
  379. base = 0
  380. if self.__base == "-": # sub
  381. if self.__invert:
  382. v = 1-v
  383. #base = -size
  384. size *=-1
  385. v *=-1
  386. elif self.__base == "+": # sub
  387. if self.__invert:
  388. v = v-1
  389. else:
  390. v = (t%1-0.5)
  391. elif self.__xtype == "on":
  392. #base = 0
  393. if self.__angel > 90 and self.__angel <=270:
  394. v=1
  395. else:
  396. v=0
  397. base = 0
  398. if self.__base == "-": # sub
  399. if self.__invert:
  400. v = 1-v
  401. #base = -size
  402. size *=-1
  403. v *=-1
  404. elif self.__base == "+": # sub
  405. if self.__invert:
  406. v = v-1
  407. else:
  408. v = (t%1-0.5)
  409. elif self.__xtype == "ramp" or self.__xtype == "ramp":
  410. v = (t%1)
  411. base = 0
  412. if self.__base == "-": # sub
  413. if self.__invert:
  414. v = 1-v
  415. #base = -size
  416. size *=-1
  417. v *=-1
  418. elif self.__base == "+": # sub
  419. if self.__invert:
  420. v = v-1
  421. else:
  422. v = (t%1-0.5)
  423. elif self.__xtype == "ramp2" or self.__xtype == "bump2":
  424. v = (t%1)
  425. v = 1-v
  426. if v == 1:
  427. v=0
  428. base = 0
  429. if self.__base == "-": # sub
  430. if self.__invert:
  431. v = 1-v
  432. #base = -size
  433. size *=-1
  434. v *=-1
  435. elif self.__base == "+": # sub
  436. if self.__invert:
  437. v = v-1
  438. else:
  439. v = (t%1-0.5)
  440. elif self.__xtype == "fade":
  441. x = t * 2
  442. if x > 1:
  443. x = 2-x
  444. x -= 0.5
  445. v = x*2
  446. #base /= 2
  447. #base *=2
  448. if self.__base == "+": # add
  449. pass#base /= 2
  450. else:
  451. v *= -1
  452. v/=2
  453. if self.__invert:
  454. v *=-1
  455. #if self.__fade_in_master < 255:
  456. # self.__fade_in_master += v*size
  457. out = v *size +base
  458. self.out = out
  459. self.count = count
  460. out = out * size_master.val(self.__master_id) # master
  461. out = out * exec_size_master.val(self._exec_id) # master
  462. #* (self.__fade_in_master /255.)
  463. return out
  464. class DMXCH(object):
  465. def __init__(self,dmx=-1):
  466. self._base_value = 0
  467. self._fade = None
  468. self._fx = [None,None] # None
  469. self._fx_value = 0
  470. self._dmx = dmx
  471. self._dmx_fine = 0
  472. self._fix_id = 0
  473. self._v_master_id=0
  474. self._flash = None
  475. self._flash_fx = None
  476. self._flash_fx_value = 0
  477. self._last_val = None
  478. self._exec_ids = [None,None,None,None] # go, go-fx, flash, flash-fx
  479. #self.next(clock)
  480. #print("init",self)
  481. def fade(self,target,ftime=0,clock=0,delay=0):
  482. if target != self._base_value:
  483. try:
  484. target = float(target)
  485. self._fade = Fade(self._base_value,target,ftime=ftime,clock=clock,delay=delay)
  486. #self._fade.next()
  487. #self._fade.next()
  488. except Exception as e:
  489. print( "Except:fade",e,target,ftime,clock)
  490. self.next(clock)
  491. #print("init fade",self)
  492. def fx(self,xtype="sinus",size=40,speed=40,invert=0,width=100,start=0,offset=0,base="", clock=0,master=None):
  493. #print("DMXCH.fx",[self,xtype,size,speed,start,offset,base, clock])
  494. self._fx[0] = self._fx[1]
  495. if str(xtype).lower() == "off":
  496. fx_value = self._fx_value
  497. if fx_value != 0:
  498. cprint("???????______ FX OFF AS FADE",fx_value,0,255)
  499. self._fx[1] = Fade(fx_value,0,ftime=0.5,clock=clock)
  500. else:
  501. self._fx[1] = None
  502. self._fx_value = 0
  503. else:
  504. self._fx[1] = FX(xtype=xtype,size=size,speed=speed,invert=invert
  505. ,width=width,start=start,offset=offset,base=base
  506. ,clock=clock,master=master,master_id=1)
  507. self._fx[1].exec_id(self._exec_ids[1])
  508. self.next(clock)
  509. #print("init fx",self)
  510. def flash(self,target,ftime=0,clock=0,delay=0):
  511. if str(target).lower() == "off":
  512. self._flash = None
  513. else:#elif target != self._base_value:
  514. try:
  515. target = float(target)
  516. self._flash = Fade(self._last_val,target,ftime=ftime,clock=clock,delay=delay)
  517. except Exception as e:
  518. print( "Except:flash",target,ftime,clock,__name__,e,)
  519. self.next(clock)
  520. #print("init flush",self)
  521. def flash_fx(self,xtype="sinus",size=40,speed=40,invert=0,width=100,start=0,offset=0,base="",clock=0,master=None):
  522. if str(xtype).lower() == "off":
  523. fx_value = self._fx_value
  524. self._flash_fx = None
  525. self._flash_fx_value = 0
  526. else:
  527. self._flash_fx = FX(xtype=xtype,size=size,speed=speed,invert=invert
  528. ,width=width,start=start,offset=offset,base=base
  529. ,clock=clock,master=master,master_id=0)
  530. self._flash_fx.exec_id(self._exec_ids[3])
  531. self.next(clock)
  532. #print("init flash_fx",self)
  533. def fx_ctl(self,cmd=""): #start,stop,off
  534. pass
  535. def __str__(self):
  536. return self.__repr__()
  537. def exec_ids(self,_id=None):
  538. #if type(_id) is not type(None):
  539. # #self._exec_id = _id
  540. # #print("set exec_id",_id)
  541. return self._exec_ids
  542. def __repr__(self):
  543. v = self._last_val
  544. if type(self._last_val) in [int,float]:
  545. v = round(self._last_val,2)
  546. return "<BUFFER DMX:{} FINE:{} VAL:{} EXEC:{}\n fd:{}\n fx:{}\n fx_flash:{}\n".format(
  547. self._dmx,self._dmx_fine
  548. ,v,str(self._exec_ids)
  549. ,self._fade
  550. ,self._fx
  551. ,self._flash_fx)
  552. def fade_ctl(self,cmd=""): #start,stop,backw,fwd,bounce
  553. pass
  554. def next(self,clock=0):
  555. try:
  556. self._next(clock)
  557. except Exception as e:
  558. cprint("Exception DMXCH.next()" ,e)
  559. out = self._last_val
  560. return out
  561. def _next(self,clock=0):
  562. value = self._base_value
  563. #if self._dmx == 1024:
  564. # print(self)
  565. if self._last_val is None:
  566. self._last_val = value
  567. fx_value = self._fx_value
  568. if self._flash is not None:
  569. value = self._flash.next(clock)
  570. #flicker bug ?!
  571. value = self._flash.next(clock)
  572. fx_value = 0
  573. elif self._fade is not None:#is Fade:# is Fade:
  574. self._base_value = self._fade.next(clock)
  575. self._base_value = self._fade.next(clock) #flicker bug ?!
  576. value = self._base_value
  577. if self._flash_fx is not None:# is FX:
  578. fx_value = self._flash_fx.next(clock)
  579. else:
  580. self._fx_value = 0
  581. if self._fx[-1] is not None and self._flash is None:# is FX:
  582. self._fx_value += self._fx[-1].next(clock)
  583. fx_value = self._fx_value
  584. self._last_val = value + fx_value
  585. #self._last_val *= v_master.val(self._fix_id)
  586. if self._v_master_id in V_MASTER:
  587. vm = V_MASTER[self._v_master_id].next(clock)
  588. #print("V_MASTER is ", V_MASTER[self._v_master_id])
  589. vm = vm/256
  590. self._last_val *= vm # v_master.val(self._v_master_id)
  591. #out = self._last_val * htp_master.master_by_dmx(self._dmx)
  592. out = self._last_val
  593. return out
  594. V_MASTER = {} #DMXCH
  595. Bdmx = []
  596. for i in range(512*7+1):
  597. Bdmx.append( DMXCH(i) )
  598. #print(type(dmx[i]))
  599. _id = 1
  600. def split_cmd(data):
  601. if "cmd" in data:
  602. cmd = data["cmd"]
  603. #print("cmd",cmd)
  604. if "," in cmd:
  605. cmds = cmd.split(",")
  606. else:
  607. cmds = [cmd]
  608. return cmds
  609. class VDMX():
  610. """functional implementation as class for namespace encapsulation
  611. """
  612. def __init__(self):
  613. self.data = OrderedDict()
  614. self.data[4] = {"DMX":[21,22,23],"VALUE":255, "LIMIT":255} #,"DMXCH":DMXCH("V4")}
  615. for k,v in self.data.items():
  616. pass
  617. #dmxch = v["DMXCH"]
  618. #dmxch.fade(10,0)
  619. #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):
  620. def _list_by_dmx(self,_dmx=0):
  621. data = OrderedDict()
  622. for i,link in self.data.items(): # enumerate(self.data):
  623. if _dmx in link["DMX"]:
  624. #print( "_list_by_dmx",i,link)
  625. data[i] = link
  626. return data
  627. def dmx_by_id(self,_id=0):
  628. #print("dmx by master-id:",_id)
  629. if _id in self.data:
  630. for i,link in self.data[_id].items():
  631. #print("dmx_by_id", i,link)
  632. return (i,link)
  633. return 0,{}
  634. def by_dmx(self,clock,dmx):
  635. #print("master of dmx:",dmx)
  636. val=0
  637. flag = 0
  638. data = self._list_by_dmx(dmx)
  639. for i,row in data.items():
  640. if "DMXCH" not in row:
  641. row["DMXCH"] = DMXCH("V{}".format(i))
  642. row["DMXCH"].fade(255,0)
  643. v = row["DMXCH"].next(clock)
  644. #row["DMXCH"].fade(200,20)
  645. if v >= val:
  646. val = v
  647. flag = 1
  648. out = 1.
  649. if val > 255:
  650. val = 255
  651. if flag:
  652. out = val/255.
  653. else:
  654. out = 1.
  655. return out
  656. vdmx = VDMX()
  657. class HTP_MASTER():
  658. """functional implementation as class for namespace encapsulation
  659. """
  660. def __init__(self):
  661. self.data = OrderedDict()
  662. #self.data[1] = {"DMX":[1,2,3],"VALUE":80, "LIMIT":255}
  663. #self.data[2] = {"DMX":[12,13,22],"VALUE":70, "LIMIT":255}
  664. #self.data[3] = {"DMX":[22,23,24],"VALUE":99, "LIMIT":255}
  665. self.data[4] = {"DMX":[22,23,24],"VALUE":99, "LIMIT":255,"DMXCH":DMXCH(4)}
  666. def _list_by_dmx(self,_dmx=0):
  667. data = OrderedDict()
  668. for i,link in self.data.items(): # enumerate(self.data):
  669. if _dmx in link["DMX"]:
  670. #print( "_list_by_dmx",i,link)
  671. data[i] = link
  672. return data
  673. def dmx_by_id(self,_id=0):
  674. #print("dmx by master-id:",_id)
  675. if _id in self.data:
  676. for i,link in self.data[_id].items():
  677. #print("dmx_by_id", i,link)
  678. return (i,link)
  679. return 0,{}
  680. def val_by_dmx(self,dmx=0):
  681. #print("master of dmx:",dmx)
  682. val=0
  683. flag = 0
  684. data = self._list_by_dmx(dmx)
  685. for i,link in data.items():
  686. #print("master_by_dmx", i,link)
  687. if link["VALUE"] > val:
  688. #print("master_by_dmx", i,link)
  689. val = link["VALUE"]
  690. flag=1
  691. out = 1.
  692. if flag:
  693. out = val/255.
  694. return out
  695. htp_master = HTP_MASTER()
  696. #htp_master.data[_id] = {"DMX":[1,2,3],"VALUE":80, "LIMIT":255,"DMXCH":DMXCH()}
  697. class Main():
  698. def __init__(self):
  699. #artnet = ANN.ArtNetNode(to="127.0.0.1",port=6555,univ=12)
  700. #artnet = ANN.ArtNetNode(to="127.0.0.1",port=6555,univ=0)
  701. #artnet = ANN.ArtNetNode(to="2.0.0.255",univ=0)
  702. #artnet = ANN.ArtNetNode(to="10.10.10.255",univ=1)
  703. self.artnet = {}
  704. #self.artnet["0"] = ANN.ArtNetNode(to="10.10.10.255",univ=0)
  705. #self.artnet["0"].dmx[512-1] = 10
  706. #self.artnet["1"] = ANN.ArtNetNode(to="10.10.10.255",univ=1)
  707. #self.artnet["1"].dmx[512-1] = 11
  708. self.fx = {} # key is dmx address
  709. self.lock = thread.allocate_lock()
  710. def loop(self):
  711. #dmx[205] = 255 #205 BLUE
  712. #self.artnet.send()
  713. xx = [0]*512
  714. #artnet = self.artnet["0"]
  715. #artnet.dmx = xx# [:] #dmx #[0]*512
  716. ii = 0
  717. old_univ = -1
  718. xx = [0]*512
  719. for ii,dmxch in enumerate(Bdmx):
  720. i = ii%512
  721. univ = ii//512
  722. if str(univ) not in self.artnet:
  723. print("add uiv",univ)
  724. self.artnet[str(univ)] = ANN.ArtNetNode(to="10.10.10.255",univ=univ)
  725. #self.artnet[str(univ)].dmx[512-1] = 100+univ
  726. if univ != old_univ:
  727. old_univ = univ
  728. #print("UNIV",ii/512)
  729. try:
  730. artnet.next()
  731. except:pass
  732. artnet = self.artnet[str(univ)]
  733. artnet.dmx = [0]*512
  734. fps_start = time.time()
  735. fps = 0
  736. while 1:
  737. self.lock.acquire_lock()
  738. t = clock.time()
  739. ii = 0
  740. old_univ = -1
  741. xx = [0]*512
  742. for ii,dmxch in enumerate(Bdmx):
  743. i = ii%512
  744. univ = ii//512
  745. if str(univ) not in self.artnet:
  746. print("add uiv",univ)
  747. self.artnet[str(univ)] = ANN.ArtNetNode(to="10.10.10.255",univ=univ)
  748. #self.artnet[str(univ)].dmx[512-1] = 100+univ
  749. if univ != old_univ:
  750. old_univ = univ
  751. #print("UNIV",ii/512)
  752. try:
  753. artnet.next()
  754. except:pass
  755. artnet = self.artnet[str(univ)]
  756. #artnet.dmx = xx
  757. old_univ = -1
  758. xx = [0]*512
  759. for ii,dmxch in enumerate(Bdmx):
  760. i = ii%512
  761. univ = ii//512
  762. if univ != old_univ:
  763. old_univ = univ
  764. artnet = self.artnet[str(univ)]
  765. xx = artnet.dmx
  766. v = dmxch.next(t)
  767. vv = vdmx.by_dmx(clock=i,dmx=ii+1)
  768. try:
  769. v = v*vv # disable v-master
  770. except Exception as e:
  771. cprint("Exception v*vv",[v,vv],e)
  772. continue
  773. xx[i] = int(v)
  774. old_univ = -1
  775. xx = [0]*512
  776. for ii,dmxch in enumerate(Bdmx): #fine loop
  777. i = ii%512
  778. univ = ii//512
  779. if univ != old_univ:
  780. artnet = self.artnet[str(univ)]
  781. xx = artnet.dmx# = xx
  782. v = dmxch.next(t)
  783. vv = vdmx.by_dmx(clock=i,dmx=ii+1)
  784. try:
  785. v = v*vv # disable v-master
  786. except Exception as e:
  787. cprint("Exception v*vv",[v,vv],e)
  788. continue
  789. #xx[i] = int(v)
  790. dmx_fine = dmxch._dmx_fine
  791. if dmx_fine > 0:
  792. vf = int(v%1*255)
  793. #print(dmx_fine,end=" ")
  794. dmx_fine = dmx_fine%512
  795. #print(dmx_fine,end=" ")
  796. #print(int(v),end=" ")
  797. #print(vf,end=" ")
  798. #print()
  799. #univ = ii//512
  800. try:
  801. #xx[dmx_fine+1] = 9# int(v%1*255)
  802. if v >= 255:
  803. xx[dmx_fine-1] = 255
  804. elif v < 0:
  805. xx[dmx_fine-1] = 0
  806. else:
  807. xx[dmx_fine-1] = int(v%1*255)
  808. except Exception as e:
  809. print("E dmx_fine",e,dmx_fine)
  810. try:
  811. artnet.next()
  812. except:pass
  813. self.lock.release_lock()
  814. #self.lock.acquire_lock()
  815. #time.sleep(1/35)
  816. fps += 1
  817. stop_fps = 50
  818. time.sleep(1/60)
  819. if fps >= stop_fps:
  820. fps_t = time.time()
  821. #print(int((fps_t-fps_start)*1000),"ms")
  822. print(round(stop_fps/(fps_t-fps_start),2),"core/fps")
  823. fps = 0
  824. fps_start = time.time()
  825. time.sleep(1/60)
  826. main = Main()
  827. if __run_main:
  828. #thread.start_new_thread(artnet_loop,())
  829. thread.start_new_thread(main.loop,())
  830. def _init_action(row):#Bdmx,out,DMX):
  831. Admx = row["DMXCH"]
  832. if row["fx"]:
  833. x = row["fx"]
  834. Admx.fx(xtype=x["xtype"]
  835. ,size=x["size"]
  836. ,speed=x["speed"]
  837. ,invert=x["invert"]
  838. ,width=x["width"]
  839. ,start=x["start"]
  840. ,offset=x["offset"]
  841. ,base=x["base"]
  842. ,clock=x["clock"]
  843. ,master=x["master"])
  844. if row["flash_fx"]:
  845. x = row["flash_fx"]
  846. Admx.flash_fx(xtype=x["xtype"]
  847. ,size=x["size"]
  848. ,speed=x["speed"]
  849. ,invert=x["invert"]
  850. ,width=x["width"]
  851. ,start=x["start"]
  852. ,offset=x["offset"]
  853. ,base=x["base"]
  854. ,clock=x["clock"]
  855. ,master=x["master"])
  856. if row["flash"]:
  857. x = row["flash"]
  858. Admx.flash(target=x["target"]
  859. ,ftime=x["ftime"]
  860. ,clock=x["clock"]
  861. ,delay=x["delay"])
  862. if row["fade"]:
  863. x = row["fade"]
  864. Admx.fade(target=x["target"]
  865. ,ftime=x["ftime"]
  866. ,clock=x["clock"]
  867. ,delay=x["delay"])
  868. def set_dmx_fine_ch(Admx,dmx_fine_nr):
  869. try:
  870. if int(dmx_fine_nr) > 0:
  871. Admx._dmx_fine = int(dmx_fine_nr)
  872. except Exception as e:
  873. cprint(x,color="red")
  874. cprint("except 3455",e,color="red")
  875. def _parse_cmds(cmds,clock=0,master_fx=None):
  876. c=clock
  877. out = {}
  878. for x in cmds:
  879. Admx = DMXCH() #dummy
  880. _fix_id=0
  881. _attr = ""
  882. if "CMD" in x:
  883. print("CMD:",x)
  884. if "EXEC-SPEED-MASTER" == x["CMD"]:
  885. exec_speed_master.val(x["NR"],x["VALUE"])
  886. if "EXEC-SIZE-MASTER" == x["CMD"]:
  887. exec_size_master.val(x["NR"],x["VALUE"])
  888. if "EXEC-OFFSET-MASTER" == x["CMD"]:
  889. exec_offset_master.val(x["NR"],x["VALUE"])
  890. if "SPEED-MASTER" == x["CMD"]:
  891. speed_master.val(x["NR"],x["VALUE"])
  892. if "SIZE-MASTER" == x["CMD"]:
  893. size_master.val(x["NR"],x["VALUE"])
  894. else:
  895. #print("x",x)
  896. if "DMX" in x:
  897. DMX = int(x["DMX"])
  898. else:
  899. continue
  900. if "VALUE" in x:
  901. v = x["VALUE"]
  902. else:
  903. continue
  904. _inc = 0
  905. _fix_id = 0
  906. _val = -1
  907. _clock = 0
  908. exec_id = None
  909. if "VALUE" in x:
  910. _val = x["VALUE"]
  911. if "INC" in x:
  912. _inc = x["INC"]
  913. if "FIX" in x:
  914. _fix_id = x["FIX"]
  915. if "clock" in x:
  916. _clock=x["clock"]
  917. if "ATTR" in x:
  918. _attr = x["ATTR"]
  919. if DMX <= 0: # VIRTUAL
  920. DMX = "FIX"+str(_fix_id)
  921. ok = 0
  922. if "ATTR" in x:
  923. _attr = x["ATTR"]
  924. if "DIM" == x["ATTR"]:
  925. if _fix_id not in V_MASTER:
  926. V_MASTER[_fix_id] = DMXCH()
  927. #print("_val",_val)
  928. #V_MASTER[_fix_id].fade(_val,ftime=0,clock=0,delay=0)
  929. #print(" V-MASTER",_fix_id,_val,_inc)
  930. ok = 1
  931. if _fix_id in V_MASTER:
  932. Admx = V_MASTER[_fix_id]
  933. if not ok:
  934. continue
  935. else:
  936. if DMX < len(Bdmx):
  937. Admx = Bdmx[DMX-1]
  938. else:
  939. print("DMX ADDRESS too BIG",DMX)
  940. continue
  941. if "DMX-FINE" in x and DMX > 0:
  942. set_dmx_fine_ch(Admx, x["DMX-FINE"])
  943. #print("-")
  944. if "EXEC" in x:
  945. exec_id = x["EXEC"]
  946. if "ATTR" in x:
  947. _attr = x["ATTR"]
  948. if "FIX" in x:
  949. _fix_id = x["FIX"]
  950. fx=""
  951. fx2={}
  952. ftime=0
  953. delay=0
  954. if "FX" in x:
  955. fx = x["FX"]
  956. if "FX2" in x:
  957. fx2 = x["FX2"]
  958. if "FADE" in x:
  959. ftime = x["FADE"]
  960. if "DELAY" in x:
  961. delay = x["DELAY"]
  962. #print("DO",[exec_id],x)
  963. # ids = [401,402,304,103]
  964. # exec-id, exec-fx-id, flush-id, flush-fx-id
  965. if v != "off":
  966. if "FLASH" in x:
  967. ids = Admx.exec_ids()
  968. if type(v) is int:
  969. ids[2] = exec_id
  970. if fx2:
  971. ids[3] = exec_id
  972. #print(" ",[ids, exec_id],"FL")
  973. else: # GO or ON
  974. ids = Admx.exec_ids()
  975. if type(v) is int:
  976. ids[0] = exec_id
  977. if fx2:
  978. ids[1] = exec_id
  979. #print(" ",[ids, exec_id],"GO")
  980. if v == "off":
  981. if "FLASH" in x:
  982. ids = Admx.exec_ids()
  983. stop = 0
  984. #print(" ",[ids, exec_id])
  985. if ids[2] != exec_id:
  986. stop = 1
  987. else:
  988. ids[2] = None
  989. if fx2:
  990. if ids[3] != exec_id:
  991. stop = 1
  992. else:
  993. ids[3] = None
  994. stop = 0
  995. if stop:
  996. # this FLASH cmd OFF/RELEASE is not valid anymore
  997. continue
  998. #aprint("OK")
  999. #ids = Admx.exec_ids()
  1000. #print("OK ",[ids, exec_id])
  1001. #Bdmx[DMX].exec_id(exec_id)
  1002. out[DMX] = {"flash":{},"fade":{},"fx":{},"flash_fx":{},"fix_id":_fix_id,"attr":_attr,"DMXCH":Admx}
  1003. if v is not None:
  1004. if "FLASH" in x:
  1005. out[DMX]["flash"] = {"target":v,"ftime":ftime, "clock":c,"delay":delay,"DMXCH":Admx}
  1006. else:
  1007. out[DMX]["fade"] = {"target":v,"ftime":ftime, "clock":c,"delay":delay,"DMXCH":Admx}
  1008. if type(fx2) is dict and fx2:
  1009. xtype="fade"
  1010. size = 10
  1011. speed = 10
  1012. start = 0
  1013. offset= 0
  1014. width=100
  1015. invert=0
  1016. base = "-"
  1017. if "TYPE" in fx2:
  1018. xtype = fx2["TYPE"]
  1019. if "SIZE" in fx2:
  1020. size = fx2["SIZE"]
  1021. if "SPEED" in fx2:
  1022. speed = fx2["SPEED"]
  1023. if "OFFSET" in fx2:
  1024. offset = fx2["OFFSET"]
  1025. if "BASE" in fx2:
  1026. base = fx2["BASE"]
  1027. if "INVERT" in fx2:
  1028. invert = fx2["INVERT"]
  1029. if "WIDTH" in fx2:
  1030. width = fx2["WIDTH"]
  1031. if "off" == x["VALUE"]: #fix fx flash off
  1032. xtype= "off"
  1033. if "alloff" == xtype.lower():
  1034. for dmxch in Bdmx:
  1035. if dmxch is not None:
  1036. dmxch.flash_fx(xtype="off",clock=c)
  1037. dmxch.fx(xtype="off",clock=c)
  1038. for j in V_MASTER:
  1039. dmxch = V_MASTER[j]
  1040. if j is not None:
  1041. dmxch.flash_fx(xtype="off",clock=c)
  1042. dmxch.fx(xtype="off",clock=c)
  1043. if "FLASH" in x:
  1044. out[DMX]["flash_fx"] = {"xtype":xtype,"size":size,"speed":speed,
  1045. "invert":invert,"width":width,"start":start
  1046. ,"offset":offset,"base":base,"clock":c,"master":master_fx}
  1047. else:
  1048. out[DMX]["fx"] = {"xtype":xtype,"size":size,"speed":speed
  1049. ,"invert":invert,"width":width,"start":start
  1050. ,"offset":offset,"base":base,"clock":c,"master":master_fx}
  1051. elif type(fx) is str and fx:
  1052. # old fx like sinus:200:12:244
  1053. ccm = str(DMX+1)+":"+fx
  1054. print("fx",ccm)
  1055. if "FLASH" in x:
  1056. CB({"cmd":"fxf"+ccm})
  1057. else:
  1058. CB({"cmd":"fx"+ccm})
  1059. return out
  1060. import hashlib
  1061. JCB_GLOB_BUF = {}
  1062. def JCB(data,sock=None): #json client input
  1063. t_start = time.time()
  1064. s = time.time()
  1065. e = time.time()
  1066. print("JCB TIME:","{:0.02f}".format(e-s),int(e*100)/100)
  1067. #print("-->-",data)
  1068. jdatas = []
  1069. l2 = 0
  1070. for line in data:
  1071. data2 = json.loads(line)
  1072. l2 += len(data2)
  1073. #print("line:",line)
  1074. jdatas.append(data2) #["CMD"])
  1075. print("INPUT JCB =>",len(data),":",l2)
  1076. c = clock.time()
  1077. c = float(c)
  1078. ftime = 0
  1079. delay = 0
  1080. for cmds in jdatas:
  1081. line = json.dumps(cmds)
  1082. #md5 = hashlib.md5.hexdigest(line)
  1083. master_fx = MASTER_FX()
  1084. if not cmds:
  1085. continue
  1086. try:
  1087. out = _parse_cmds(cmds,clock=c,master_fx=master_fx)
  1088. #cprint("-","{:0.04} sec.".format(time.time()-t_start),color="yellow")
  1089. # ------- ----------------------------------------------------
  1090. except Exception as e:
  1091. cprint("EXCEPTION JCB",e,color="red")
  1092. cprint("----",str(cmds)[:150],"...",color="red")
  1093. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1094. raise e
  1095. if out:
  1096. try:
  1097. try: # second loop to sync-start all dmxch's
  1098. main.lock.acquire_lock()
  1099. for _id in out:
  1100. row = out[_id]
  1101. #print("_id",_id)
  1102. Admx = row["DMXCH"]
  1103. #print("Admx",Admx)
  1104. if row["fix_id"]:
  1105. _fix_id = row["fix_id"]
  1106. Admx._fix_id = _fix_id
  1107. if "attr" in row:
  1108. if row["attr"] in ["RED","GREEN","BLUE","WHITE","AMBER"]: #CYAN,MAGENTA,YELLOW
  1109. Admx._v_master_id = _fix_id
  1110. #print("SET V_MASTER",row)
  1111. _init_action(row)
  1112. e = time.time()
  1113. print(" sub-JCB TIME:","{:0.02f}".format(e-s),int(e*100)/100)
  1114. finally:
  1115. main.lock.release_lock()
  1116. #time.sleep(1/30)
  1117. except Exception as e:
  1118. cprint("EXCEPTION JCB",e,color="red")
  1119. cprint("----",str(cmds)[:150],"...",color="red")
  1120. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1121. raise e
  1122. #cprint(" ","{:0.04} sec.".format(time.time()-t_start),color="yellow")
  1123. e = time.time()
  1124. print("JCB TIME:","{:0.02f}".format(e-s),int(e*100)/100)
  1125. time.sleep(1/60)
  1126. def CB(data): # raw/text client input
  1127. #print("CB",data)
  1128. cmds = split_cmd(data)
  1129. c = clock.time()
  1130. c = float(c)
  1131. ftime = 0
  1132. delay = 0
  1133. for xcmd in cmds:
  1134. if xcmd:
  1135. cprint("CB",xcmd,end=" ")
  1136. pass
  1137. else:
  1138. continue
  1139. if xcmd.startswith("fxf"):
  1140. xxcmd=xcmd[3:].split(":")
  1141. #print("fxf:",xxcmd)
  1142. if "alloff" == xxcmd[1].lower():
  1143. for i in Bdmx:
  1144. if i is not None:
  1145. i.flash_fx(xtype="off",clock=c)
  1146. for i in V_MASTER:
  1147. if i is not None:
  1148. i.flash_fx(xtype="off",clock=c)
  1149. l = xxcmd
  1150. try:
  1151. xtype=""
  1152. size=40
  1153. speed=100
  1154. start=0
  1155. offset=0
  1156. base=""
  1157. k=int(l[0])-1
  1158. xtype=l[1]
  1159. if len(l) >= 3:
  1160. try:size=int(l[2])
  1161. except:pass
  1162. if len(l) >= 4:
  1163. try:speed=int(l[3])
  1164. except:pass
  1165. if len(l) >= 5:
  1166. try:start=int(l[4])
  1167. except:pass
  1168. if len(l) >= 6:
  1169. try:offset=int(l[5])
  1170. except:pass
  1171. if len(l) >= 7:
  1172. try:base=l[6]
  1173. except:pass
  1174. if len(Bdmx) > k:
  1175. #Bdmx[k].fade(target=v,ftime=t, clock=c)
  1176. Bdmx[k].flash_fx(xtype=xtype,size=size,speed=speed,start=start,offset=offset,base=base,clock=c)
  1177. except Exception as e:
  1178. print("EXCEPTION IN FX",e)
  1179. print("Error on line {}".format(sys.exc_info()[-1].tb_lineno))
  1180. elif xcmd.startswith("fx"):
  1181. xxcmd=xcmd[2:].split(":")
  1182. print("DMX:",xxcmd)
  1183. if len(xxcmd) < 2:
  1184. print("xxcmd err",xxcmd,xcmd)
  1185. continue
  1186. if "alloff" == xxcmd[1].lower():
  1187. for i in Bdmx:
  1188. i.fx(xtype="off",clock=c)
  1189. l = xxcmd
  1190. try:
  1191. xtype=""
  1192. size=40
  1193. speed=100
  1194. start=0
  1195. offset=0
  1196. base=""
  1197. k=int(l[0])-1
  1198. xtype=l[1]
  1199. if len(l) >= 3:
  1200. try:size=int(l[2])
  1201. except:pass
  1202. if len(l) >= 4:
  1203. try:speed=int(l[3])
  1204. except:pass
  1205. if len(l) >= 5:
  1206. try:start=int(l[4])
  1207. except:pass
  1208. if len(l) >= 6:
  1209. try:offset=int(l[5])
  1210. except:pass
  1211. if len(l) >= 7:
  1212. try:base=l[6]
  1213. except:pass
  1214. if len(Bdmx) > k:
  1215. #Bdmx[k].fade(target=v,ftime=t, clock=c)
  1216. Bdmx[k].fx(xtype=xtype,size=size,speed=speed,start=start,offset=offset,base=base,clock=c)
  1217. except Exception as e:
  1218. print("EXCEPTION IN FX",xcmd,e)
  1219. print("Error on line {}".format(sys.exc_info()[-1].tb_lineno))
  1220. if __run_main:
  1221. s = chat.Server(cb=JCB)
  1222. while 1:
  1223. s.poll()
  1224. time.sleep(0.001)