_console.py 44 KB

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