vpu_live.py 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  1. import math
  2. import random
  3. import time
  4. import os
  5. import _thread as thread
  6. from optparse import OptionParser
  7. ...
  8. parser = OptionParser()
  9. parser.add_option("-m", "--mode", dest="mode",
  10. help="pixel mode pix,x,y --mode 40,10,8") #, metavar="FILE")
  11. parser.add_option("-X", "--XX", dest="XX", #default=1,
  12. help="x-split") #, metavar="FILE")
  13. parser.add_option("-x", "--xx", dest="xsplit", #default=1,
  14. help="x-split") #, metavar="FILE")
  15. parser.add_option("-y", "--yy", dest="ysplit",#default=1,
  16. help="y-split") #, metavar="FILE")
  17. parser.add_option("", "--start-univ", dest="start_univ",#default=1,
  18. help="set start-univers default=2") #, metavar="FILE")
  19. parser.add_option("", "--gobo-ch", dest="gobo_ch",#default=1,
  20. help="gobo ch univ on 1") #, metavar="FILE")
  21. #os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,164)
  22. parser.add_option("", "--win-pos", dest="win_pos",default="200,164",
  23. help="SDL_VIDEO_WINDOW_POS --win-pos=200,164") #, metavar="FILE")
  24. parser.add_option("", "--pixel-mapping", dest="pixel_mapping",default=0,
  25. help="pixel_mapping file/on --pixel-mapping=_x") #, metavar="FILE")
  26. parser.add_option("", "--countdown", dest="countdown",#default=1,
  27. help="enable countdown") #, metavar="FILE")
  28. parser.add_option("", "--videoplayer", dest="videoplayer",#default=1,
  29. help="enable videoplayer") #, metavar="FILE")
  30. #parser.add_option("-f", "--file", dest="filename",
  31. # help="write report to FILE", metavar="FILE")
  32. #parser.add_option("-q", "--quiet",
  33. # action="store_false", dest="verbose", default=True,
  34. # help="don't print status messages to stdout")
  35. (options, args) = parser.parse_args()
  36. for o in dir(options):
  37. if "_" in o:
  38. continue
  39. print(o,options.__getattribute__(o))
  40. START = time.time()
  41. # ===== ARTNET DMX =========
  42. import memcache
  43. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  44. def read_index():
  45. ips=mc.get("index")#cmd)
  46. if ips is None:
  47. ips = {}
  48. #for k,v in ips.items():
  49. # print(k,v)
  50. return ips
  51. def select_ip(ips, univ=2): # artnet univ
  52. _univ = ":{}".format(univ)
  53. for ip in ips: #high priority
  54. if "2.0.0" in ip and _univ in ip:
  55. return ip
  56. for ip in ips:
  57. if "ltp-out" in ip and _univ in ip:
  58. return ip
  59. FUNC = 0
  60. COUNTER = []
  61. if options.countdown:
  62. cdmx_start = options.countdown.split(",")
  63. for cdmx in cdmx_start:
  64. try:
  65. cdmx = int(cdmx)
  66. COUNTER.append({"DMX":cdmx,"DIM":0,"PAN":127,"TILT":127,"CONTROL":0,"SEC":10,"RED":255,"GREEN":255,"BLUE":255,"_time":time.time(),"_RUN":0,"_SEC":">{}<".format(cdmx)})
  67. except Exception as e:
  68. print("EXCEPTION COUNTER INIT ",cdmx)
  69. def read_dmx(ip):
  70. global frame
  71. r = ""
  72. if ip:
  73. #t = int(math.sin(time.time() - s)*10)
  74. r = mc.get(ip) #"2.0.0.13:2")
  75. frame += 1
  76. rr = [0]*512
  77. for i,v in enumerate(r):
  78. try: #cleanup ltp-out to int
  79. v = int(v)
  80. rr[i] = v
  81. except:pass
  82. r = rr
  83. if not r:
  84. c = 0
  85. #time.sleep(0.1)
  86. r = [0] *512
  87. for i in range(12*8+1):
  88. dmx = i*4
  89. #print(dmx)
  90. r[dmx:dmx+4] = [255,10,10,40]
  91. return r
  92. # ===== ARTNET DMX =========
  93. class Vopen():
  94. def __init__(self,dmx=None):
  95. self.fpath = '/home/user/Downloads/'
  96. self.fpath = '/home/user/LibreLight/video/'
  97. self.fname = 'bbb_sunflower_480x320.mp4'
  98. self.scale = 50 #%
  99. self.dmx=dmx
  100. self.x = 0
  101. self.y = 0
  102. self.init_count = 0
  103. self.cap = None
  104. self.shape = [200,200]
  105. self.img = None
  106. self.success = 1
  107. self.cv2 = None
  108. self._run = 0
  109. try:
  110. global cv2
  111. self.cv2 = cv2
  112. except:
  113. pass
  114. self.im = None
  115. self.pos = 0
  116. self.buffer = []
  117. self.init()
  118. def init(self):
  119. #self._init()
  120. thread.start_new_thread(self._init,())
  121. self.init_count = 1
  122. def _init(self):
  123. print(self)
  124. print("videoplayer.init()",self.fpath,self.fname)
  125. if not os.path.isfile(self.fpath+self.fname):
  126. print()
  127. print("video file does not exits !! >",self.fpath,self.fname)
  128. print()
  129. exit()
  130. if self.cv2:
  131. cap = self.cv2.VideoCapture(self.fpath+self.fname)
  132. self.cap = cap
  133. success = 1
  134. while success:
  135. try:
  136. success, self.img = self.cap.read()
  137. #self.img = self.cv2.cvtColor(self.img, self.cv2.COLOR_BGR2RGB)
  138. self.img = self.cv2.cvtColor(self.img, self.cv2.COLOR_BGR2RGB)
  139. self.img = self.rescale_frame2(self.img, 100)
  140. self.buffer.append(self.img)
  141. if len(self.buffer) % 100 == 0:
  142. _id = str(self.__repr__)[-5:-1]
  143. print(_id,"video read",self.dmx,len(self.buffer))
  144. time.sleep(0.2)
  145. time.sleep(0.005)
  146. except Exception as e:
  147. print("Excetpion","_init",self,e)
  148. self.pos = 0
  149. self.img = self.buffer[self.pos]
  150. self.success = 1
  151. def read(self):
  152. #print(self,"read()")
  153. try:
  154. if self.pos >= len(self.buffer):
  155. self.pos = len(self.buffer)-1
  156. self.img = self.buffer[self.pos]
  157. #self.img = self.cv2.cvtColor(self.img, self.cv2.COLOR_BGR2RGB)
  158. self.img = self.rescale_frame(self.img, percent=self.scale)
  159. if self._run:
  160. self.pos += 4
  161. if self.pos >= len(self.buffer):
  162. self.pos = len(self.buffer)-1
  163. #print("video.read",self.pos)
  164. self.shape = self.img.shape[1::-1]
  165. except Exception as e:
  166. print("exception 432",e)
  167. #self.init()
  168. def prev(self):
  169. self.pos -= 1
  170. if self.pos < 0:
  171. self.pos = len(self.buffer)-1
  172. if self.pos >= len(self.buffer):
  173. self.pos = len(self.buffer)-1
  174. self.im = self.buffer[self.pos]
  175. def rescale_frame2(self,frame, width):
  176. height = int(frame.shape[0]/frame.shape[1] * width )
  177. dim = (width, height)
  178. #print("rescale_frame2",dim)
  179. #sys.exit()
  180. return self.cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
  181. def rescale_frame(self,frame, percent=75):
  182. width = int(frame.shape[1] * percent/ 100)
  183. height = int(frame.shape[0] * percent/ 100)
  184. dim = (width, height)
  185. return self.cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
  186. def next(self):
  187. #print(self,"next",time.time())
  188. #self.success = 0
  189. self.read()
  190. try:
  191. if len(self.buffer) % 100 == 0:
  192. #print("video pos",self.pos)
  193. _id = str(self.__repr__)[-5:-1]
  194. print(_id,"video pos",self.dmx,self.pos,len(self.buffer))
  195. img = self.img #self.rescale_frame(self.img, percent=30)
  196. if img is None:
  197. return
  198. self.im = pygame.image.frombuffer(img.tobytes(), self.shape, "RGB")
  199. #print(type(self.im))
  200. #self.buffer.append(self.im)
  201. if self._run:
  202. self.pos += 4
  203. if self.pos > len(self.buffer):
  204. self.pos = 0
  205. # wn.blit(im, (self.x, self.y))
  206. #self.success = 1
  207. except AttributeError as e:
  208. time.sleep(.05)
  209. #if self.init_count % 100 == 0:
  210. print("except 776",e)
  211. #self.init()
  212. except Exception as e:
  213. print("except 756",e)
  214. def draw(self,wn=None):
  215. if self.success and wn and self.im: # is not None:
  216. wn.blit(self.im, (self.x, self.y))
  217. def overlay(self,wn=None,mode="x"):
  218. # overlay
  219. img_shape = [100,100]
  220. if type(self.img) is list:
  221. img_shape = self.img.shape
  222. pygame.draw.rect(wn,[255,200,0],[5+self.x-3,4+self.y-1+img_shape[0],140,20])
  223. font15 = pygame.font.SysFont("freemonobold",17)
  224. fr = font15.render(">:{}".format(mode) ,1, (0,0,0))
  225. wn.blit(fr,(3+self.x,4+self.y+img_shape[0]))
  226. fr = font15.render("FRAME:{}".format(self.pos) ,1, (0,0,0))
  227. wn.blit(fr,(45+self.x,4+self.y+img_shape[0]))
  228. VIDEO = []
  229. videoplayer=[]
  230. cv2 = None
  231. if type(options.videoplayer) is str:
  232. try:
  233. import cv2
  234. except:pass
  235. max_videoplayer = 2
  236. dmx_start = options.videoplayer.split(",")
  237. for cdmx in dmx_start:
  238. if len(videoplayer) > max_videoplayer:
  239. print("-- videoplayer max count {} !! break".format(max_videoplayer))
  240. break
  241. print("-- videoplayer dmx:",cdmx)
  242. try:
  243. cdmx = int(cdmx)
  244. videoplayer.append( Vopen(cdmx) )
  245. VIDEO.append({"DMX":cdmx,"DIM":0,"PAN":127,"TILT":127,"CONTROL":0,"SEC":10,"RED":255,"GREEN":255,"BLUE":255,"_time":time.time(),"_RUN":0,"_SEC":">{}<".format(cdmx)})
  246. except Exception as e:
  247. print("EXCEPTION COUNTER INIT ",cdmx)
  248. # ===== ======
  249. p = 16
  250. block = [p,p]
  251. _x = 8
  252. _y = 8
  253. #HD = "0"
  254. if options.mode:
  255. try:
  256. HD = options.mode
  257. p,_x,_y = HD.split(",")
  258. _x = int(_x)
  259. _y = int(_y)
  260. p = int(p)
  261. block = [p,p]
  262. except Exception as e:
  263. print( "Exc",options.mode,e)
  264. HD_x = 2
  265. HD_y = 2
  266. print( [options.xsplit])
  267. print( [options.ysplit])
  268. try:
  269. if options.xsplit:
  270. HD_x = int(options.xsplit)
  271. if options.ysplit:
  272. HD_y = int(options.ysplit)
  273. except Exception as e:
  274. print( "Exc",options.mode,e)
  275. print("HD",HD_x,HD_y)
  276. print("xy",_x,_y)
  277. print("++++++++++++++++++", p,_x,_y)
  278. _x2 = _x
  279. try:
  280. if options.XX:
  281. pass#_x2 = int(options.XX)
  282. except Exception as e:
  283. print( "Exc",options.mode,e)
  284. print("_x2 , -X",_x2)
  285. # ===== GUI =========
  286. import pygame
  287. import pygame.gfxdraw
  288. import pygame.font
  289. clock = pygame.time.Clock()
  290. os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,164)
  291. if options.win_pos:
  292. if "," in options.win_pos:
  293. win_pos = options.win_pos.split(",")
  294. try:
  295. WIN_POS = '%i,%i' % (int(win_pos[0]),int(win_pos[1]) )
  296. os.environ['SDL_VIDEO_WINDOW_POS'] = WIN_POS
  297. except Excetpion as e:
  298. print("win_pos",win_pos,e)
  299. os.environ['SDL_VIDEO_CENTERED'] = '0'
  300. pg = pygame
  301. pygame.init()
  302. pygame.mixer.quit()
  303. f = pygame.font.get_fonts()
  304. for i in f:
  305. if "mono" in i.lower():
  306. print(i)
  307. font = pygame.font.SysFont("freemonobold",22)
  308. font10 = pygame.font.SysFont("freemonobold",10)
  309. font12 = pygame.font.SysFont("freemonobold",12)
  310. font15 = pygame.font.SysFont("freemonobold",15)
  311. font40 = pygame.font.SysFont("freemonobold",40)
  312. font80 = pygame.font.SysFont("freemonobold",70)
  313. #font = pygame.font.SysFont(None,30)
  314. fr = font.render("hallo" ,1, (200,0,255))
  315. PIXEL_MAPPING = 0
  316. grid_file = "/tmp/vpu_grid_hd.csv"
  317. text_file = "/home/user/LibreLight/vpu_text_hd.csv"
  318. play_list = "/tmp/vpu_playlist_hd.csv"
  319. pm_wy = 0
  320. if options.pixel_mapping:
  321. PIXEL_MAPPING = 1
  322. path = options.pixel_mapping
  323. path = path.replace("/","-")
  324. path = path.replace(".","-")
  325. path = path.replace("\"","-")
  326. path = path.replace("'","-")
  327. grid_file = "/home/user/LibreLight/vpu_grid_hd{}.csv".format(path)
  328. text_file = "/home/user/LibreLight/vpu_text_hd{}.csv".format(path)
  329. play_list = "/home/user/LibreLight/vpu_playlist_hd{}.csv".format(path)
  330. #_x = 8
  331. #_y = 8
  332. print(" ",[options.pixel_mapping],"grid_file",grid_file)
  333. #grid_file = "/home/user/LibreLight/vpu_grid_hd.csv"
  334. main_size=(600,500)
  335. try:
  336. if _x < 8 and PIXEL_MAPPING >= 1:
  337. wx = 60+block[0] * 8
  338. else:
  339. wx = 60+block[0] * _x
  340. wy = 80+block[1] * _y
  341. main_size=(wx,wy)
  342. if PIXEL_MAPPING >= 1:
  343. pm_wy = 120+block[0] * 8
  344. main_size=(wx,wy+pm_wy)
  345. except Exception as e:
  346. print("Exception:",e)
  347. #main_size=(280,200)
  348. main_size = (main_size[0],main_size[1])
  349. window = pygame.display.set_mode(main_size,pg.RESIZABLE)#,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  350. pg.display.set_caption('LibreLight VPU-SCREEN')
  351. class Fix():
  352. def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
  353. #print("Fix",_id)
  354. self._id = _id
  355. self.dmx = (_id-1) * ch +1 #dmx
  356. self.univ = univ
  357. self.ch = ch
  358. self.pos = pos
  359. self.rgb = [0,0,0]
  360. self.block = block #[10,10]
  361. self.x = pos[0]
  362. self.y = pos[1]
  363. self.strobo = time.time()
  364. self.bmp = 250
  365. self.sub_fix = []
  366. sub_block =[block[0]/HD_x,block[1]/HD_y]
  367. if _id <= 0: #exit
  368. return
  369. spalte = (_id-1)%_y +1
  370. zeile = int((_id-1)/_x2) #+1
  371. #zeile = zeile*_x*HD_x*HD_y
  372. add_row = _x*HD_x*HD_y
  373. #zeile 1
  374. sid = (_id-1)*2 + zeile*HD_x*_x2
  375. #for i in range(1,HD_x):
  376. sid = sid+1
  377. #sid = zeile
  378. sub_pos= [pos[0]*block[0],pos[1]*block[1]]
  379. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  380. self.sub_fix.append(sub_fix)
  381. sid = sid+1
  382. #sid = zeile
  383. sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]]
  384. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  385. self.sub_fix.append(sub_fix)
  386. #zeile 2
  387. sid = (_id-1)*2+1 + _x2*HD_x + zeile*HD_x*_x2 # int(add_row)
  388. #sid = sid+1
  389. #sid = HD_x
  390. sub_pos= [pos[0]*block[0],pos[1]*block[1]+block[1]/2]
  391. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  392. self.sub_fix.append(sub_fix)
  393. #sid = sid+1
  394. sid = sid+1
  395. sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]+block[1]/2]
  396. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  397. self.sub_fix.append(sub_fix)
  398. def calc(self,data):
  399. _rgb = [0,255,0]
  400. return _rgb
  401. def sub_calc(self,data):
  402. _rgb = [0,255,0]
  403. for sub_fix in self.sub_fix:
  404. sub_fix.block = self.block[:]
  405. _rgb = sub_fix.calc(data)
  406. return _rgb
  407. def POS(self,x=0,y=0,a=0,b=0):
  408. A = (self.pos[0])*self.block[0]
  409. B = (self.pos[1])*self.block[1]
  410. C = self.block[0]-a
  411. D = self.block[1]-b
  412. return [x+A,y+B,C,D]
  413. def subPOS(self,x=0,y=0,a=0,b=0):
  414. __out = []
  415. for sub_fix in self.sub_fix:
  416. __out.append( sub_fix.POS(x,y,a,b) )
  417. return __out
  418. class SubFix():
  419. def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
  420. #print("Fix",_id)
  421. self._id = _id
  422. self.dmx = (_id-1) * ch +1 #dmx
  423. self.univ = univ
  424. self.ch = ch
  425. self.pos = pos
  426. self.rgb = [0,0,40]
  427. self.block = block #[10,10]
  428. self.x = pos[0]
  429. self.y = pos[1]
  430. self.strobo = time.time()
  431. self.bmp = 250
  432. def calc(self,data):
  433. #return [130,30,20]
  434. dmx_sub = [30]*10
  435. #print(dmx_sub)
  436. dmx = self.dmx -1
  437. _dmx_sub = []
  438. if self.dmx >= 0:
  439. dmx = rDMX(self.univ,self.dmx)-1
  440. if dmx+self.ch < len(data):
  441. _dmx_sub = data[dmx:dmx+self.ch]
  442. if _dmx_sub:
  443. dmx_sub = _dmx_sub
  444. #print(dmx_sub)
  445. dim = dmx_sub[0]/255
  446. #print("dmx",dmx,dmx_sub)
  447. r = dmx_sub[1]*dim
  448. g = dmx_sub[2]*dim
  449. b = dmx_sub[3]*dim
  450. r = int(r)
  451. g = int(g)
  452. b = int(b)
  453. self.rgb = [r,g,b]
  454. return self.rgb
  455. def POS(self,x=0,y=0,a=0,b=0):
  456. A = (self.pos[0]) #+self.block[0]
  457. B = (self.pos[1]) #+self.block[1]
  458. C = self.block[0]-a
  459. D = self.block[1]-b
  460. if NR:
  461. C-=1
  462. D-=1
  463. return [int(x+A),int(y+B),int(C),int(D)]
  464. class POINTER():
  465. def __init__(self):
  466. self.pos = [0,0,0,0]
  467. self.on = 0
  468. self.rgb = [0,100,10]
  469. self._x = 0
  470. self._y = 0
  471. self.x = 0
  472. self.y = 0
  473. self.fix = Fix(0 ,[999,999],[16,16],0,0,0)
  474. def row_move(self,x,y):
  475. self._x = x
  476. self._y = y
  477. def move(self,pos):
  478. self.pos = pos
  479. self.on = 1
  480. def cross(self,x,y):
  481. self.x = x
  482. self.y = y
  483. def draw(self,x,y):
  484. pos = self.pos[:]
  485. #print("draw",x,y,pos)
  486. pos[0] += x
  487. pos[1] += y
  488. fix_x= self.fix.x
  489. fix_y= self.fix.y +y
  490. #print("draw",x,y,pos)
  491. if self.on:
  492. pygame.draw.rect(window,self.rgb,pos)
  493. #pygame.draw.line(window,self.rgb, (pos[0],pos[1]) , (pos[0]+100,pos[1]) )
  494. # mouse grid posision
  495. fr = font15.render("{}/{}".format(fix_x+1,fix_y) ,1, (200,200,200))
  496. _nr = fix_y * _x + fix_x +1
  497. #fr = font15.render("{:02} {}/{}".format(_nr, fix_x+1,fix_y+1 ) ,1, (200,200,200))
  498. fr = font15.render("{:02}".format(_nr ) ,1, (200,200,200))
  499. window.blit(fr,(pos[0]+2,pos[1]+2 ))
  500. window.blit(fr,(130,1))
  501. # fix pos
  502. txt=str(pos) #"[0, 0, 0, 0]"
  503. fr = font15.render(txt ,1, (200,200,200))
  504. #window.blit(fr,(pos[0]+2,pos[1]+2 ))
  505. window.blit(fr,(10,1))
  506. # univers
  507. #fr = font15.render("{:02}:{:03}".format(fix.univ,fix.dmx) ,1, (200,200,200))
  508. #window.blit(fr,(300,10))
  509. # pointer
  510. fr = font15.render("X:{:03}".format(self._x) ,1, (200,200,200))
  511. window.blit(fr,(10,30))
  512. fr = font15.render("Y:{:03}".format(self._y) ,1, (200,200,200))
  513. window.blit(fr,(10,40))
  514. # crosshair
  515. self.rgb = [0,0,200]
  516. pygame.draw.line(window,self.rgb, (self.x-p,self.y) , (self.x-2,self.y),4 )
  517. pygame.draw.line(window,self.rgb, (self.x,self.y-p) , (self.x,self.y-2),4 )
  518. self.rgb = [0,200,0]
  519. pygame.draw.line(window,self.rgb, (self.x+2,self.y) , (self.x+p,self.y),4 )
  520. pygame.draw.line(window,self.rgb, (self.x,self.y+2) , (self.x,self.y+p),4 )
  521. self.rgb = [200,0,0]
  522. pointer = POINTER()
  523. NR = 0
  524. running = True
  525. def event():
  526. global NR,running
  527. for event in pygame.event.get():
  528. #print(event.dict)
  529. _button = None
  530. if "button" in event.dict:
  531. _button = event.dict["button"]
  532. _state = None
  533. if "state" in event.dict:
  534. _state = event.state
  535. _key = None
  536. if "key" in event.dict:
  537. _key = event.key
  538. _pos = None
  539. if "pos" in event.dict:
  540. _pos = event.pos
  541. _type = None
  542. if "type" in event.dict:
  543. _type = event.type
  544. _type = event.type
  545. _mod = None
  546. if "mod" in event.dict:
  547. _mod = event.mod
  548. if 0:
  549. print( " ")
  550. print( "{:.02f}".format( time.time() - START ))
  551. print("button -",_button,end="\t| ")
  552. #print("state -",_state)
  553. print("pos -",_pos)
  554. print("type -",_type, end="\t| ")
  555. print("key -",_key)
  556. print("mod -",_mod)
  557. try:
  558. if _type == 5:
  559. if _button == 1:
  560. NR += 1
  561. if NR > 1:
  562. NR = 0
  563. if _button == 3:
  564. NR -= 1
  565. if NR < 0:
  566. NR = 1
  567. if _pos:
  568. posA = _pos
  569. fix = find_pix(_pos[0]-40,_pos[1]-60+pm_wy)
  570. if fix:
  571. pos = fix.POS(40,60+pm_wy)
  572. rgb = [0,0,0]
  573. pointer.move(pos)
  574. pointer.fix = fix
  575. else:
  576. pointer.on = 0
  577. pointer.row_move(_pos[0],_pos[1])
  578. pointer.cross(_pos[0],_pos[1])
  579. if event.type == pygame.VIDEORESIZE:
  580. window = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)
  581. except Exception as e:
  582. print(e)
  583. if event.type==pygame.QUIT:
  584. running=False
  585. fps = 0
  586. frame = 0
  587. frame_t = time.time()
  588. IP = "yyy"
  589. def draw_overlay():
  590. global fps
  591. fr = font.render("FPS:{}".format(fps) ,1, (200,0,255))
  592. window.blit(fr,(10,10))
  593. fr = font.render("ip:{}".format(IP) ,1, (200,0,255))
  594. window.blit(fr,(80,10))
  595. def calc_fps():
  596. global fps,frame,frame_t
  597. t = time.time()
  598. if frame_t+1 < t:
  599. fps = frame #frame_t- t #frame
  600. frame = 1
  601. frame_t = time.time()
  602. TEXT_BLOCK = []
  603. def _create_text_block():
  604. print("======== CREATE NEW TEXT FILE !!",text_file)
  605. f = open(text_file,"w")
  606. for i in range(10):
  607. f.write("TEXT {}\n".format(i+1))
  608. f.close()
  609. def open_text_block():
  610. print("======== OPEN TEXT FILE !!",text_file)
  611. _lines = []
  612. try:
  613. f = open(text_file,"r")
  614. _lines = f.readlines()
  615. f.close()
  616. except FileNotFoundError as e:
  617. print("TEXT",e)
  618. _create_text_block()
  619. if len(_lines) <= 0:
  620. _create_text_block()
  621. lines = []
  622. for l in _lines:
  623. #print(">> ",l.strip())
  624. lines.append(l.strip())
  625. if len(lines) <= 10:
  626. for i in range(10-len(lines)):
  627. lines.append("LINE ERROR")
  628. return lines
  629. TEXT_BLOCK = open_text_block()
  630. TEXT_BLOCK_TIME = time.time()
  631. # video playlist
  632. PLAYLIST = []
  633. def _create_playlist():
  634. print("======== CREATE NEW PLAYLIST FILE !!",play_list)
  635. os.system("mkdir -p /home/user/LibreLight/video")
  636. f = open(play_list,"w")
  637. f.write("bbb_sunflower_480x320.mp4\n")
  638. for i in range(10-1):
  639. f.write("Video-file {}\n".format(i+1+1))
  640. f.close()
  641. def open_playlist():
  642. print("======== OPEN PLAYLIST FILE !!",play_list)
  643. _lines = []
  644. try:
  645. f = open(play_list,"r")
  646. _lines = f.readlines()
  647. f.close()
  648. except FileNotFoundError as e:
  649. print("TEXT",e)
  650. _create_playlist()
  651. if len(_lines) <= 0:
  652. _create_playlist()
  653. lines = []
  654. for l in _lines:
  655. print(">> ",l.strip())
  656. lines.append(l.strip())
  657. if len(lines) <= 10:
  658. for i in range(10-len(lines)):
  659. lines.append("LINE ERROR")
  660. return lines
  661. PLAYLIST_TIME = time.time()
  662. PLAYLIST = open_playlist()
  663. # ===== GUI =========
  664. #def draw_circle(surface, x, y, radius, color):
  665. def draw_circle(surface,color, pos, radius):
  666. x,y=pos
  667. pygame.gfxdraw.aacircle(surface, int(x), int(y), radius-1, color)
  668. pygame.gfxdraw.filled_circle(surface, int(x), int(y), radius-1, color)
  669. def rDMX(univ,dmx):
  670. return univ*512+dmx
  671. def generate_grid(mapping=0):
  672. _log = []
  673. #if PIXEL_MAPPING:
  674. # log = open(grid_file,"w")
  675. head = "i,univ,dmx,x,y,ch\n"
  676. head = "i,univ,dmx,ch\n"
  677. head = "univ,dmx,x,y,ch\n"
  678. head = "nr,id,info\n"
  679. print("csv:",head)
  680. #if PIXEL_MAPPING:
  681. # log.write(head)
  682. _log.append(head)
  683. dmx = 1-1
  684. ch = 4
  685. y=0
  686. x=0
  687. #for i in range((_y)*(_x)):
  688. for i in range((8)*(8)):
  689. #if x > _x and i%_x == 0:
  690. if x > 8 and i%8 == 0:
  691. #print("--> -->")
  692. x=0
  693. y+=1
  694. _univ = int(dmx/512)
  695. _dmx = dmx - (_univ)*512
  696. pos=[x,y]
  697. line="{},{},{},{},{},{}\n".format(i+1,_univ,_dmx+1,pos[0],pos[1],ch)
  698. line="{},{},{},{},{}\n".format(_univ,_dmx+1,x,y,ch)
  699. line="{},{},x\n".format(i+1,i+1)
  700. #print("wcsv:",[line])
  701. #if PIXEL_MAPPING:
  702. # log.write(line)
  703. _log.append(line)
  704. dmx += ch
  705. x+=1
  706. if mapping and PIXEL_MAPPING:
  707. print("CREATE NEW PIXELMAP FILE !!",grid_file)
  708. log = open(grid_file,"w")
  709. log.writelines(_log)
  710. log.close()
  711. return _log[:] #GRID
  712. def init_grid(mapping=0,_x=4,_y=4):
  713. if mapping and PIXEL_MAPPING:
  714. try:
  715. log = open(grid_file,"r")
  716. except:
  717. generate_grid(mapping=mapping)
  718. log = open(grid_file,"r")
  719. lines = log.readlines()
  720. else:
  721. lines = generate_grid()
  722. GRID = []
  723. y=0
  724. x=0
  725. print("CSV header",[lines[0]],[PIXEL_MAPPING])
  726. for i,line in enumerate(lines[1:]): #exclude first line
  727. #print("rcsv",[line])
  728. line = line.strip()
  729. line = line.split(",") # csv
  730. if i >= _x and i%_x == 0:
  731. x=0
  732. y+=1
  733. if y >= _y:
  734. break
  735. #i = int(line[0])
  736. _id = int(line[1])
  737. #univ = int(line[0])
  738. #dmx = int(line[1])
  739. #x = int(line[3])
  740. #y = int(line[4])
  741. #ch = int(line[4])
  742. pos = [x,y]
  743. f = Fix(_id,pos,block) #pos,univ,dmx,ch)
  744. #f.x = x
  745. #f.y = y
  746. #f.block = block
  747. GRID.append(f)
  748. x+=1
  749. #print("y, _y",y,_y)
  750. return GRID
  751. def find_pix(x,y):
  752. global GRID
  753. for fix in GRID:
  754. X = 0
  755. Y = 0
  756. pos = fix.POS()
  757. #pos = fix.POS()
  758. #pos = fix.POS(40,60-pm_wy)
  759. #pos = fix.POS(x,y+pm_wy)#40,60)
  760. if x > pos[0] and x < pos[0]+pos[2]:
  761. X = 1
  762. if y > pos[1] and y < pos[1]+pos[3]:
  763. Y = 1
  764. if X and Y:
  765. #print(pos,x,y)
  766. #print("find",X,Y)
  767. return fix
  768. GRID = []
  769. _GRID = []
  770. _GRID = init_grid(_x=8,_y=8,mapping=1) #init_gird()
  771. NR = 0
  772. START_UNIV=2
  773. if options.start_univ:
  774. try:
  775. START_UNIV=int(options.start_univ)
  776. except Exception as e:
  777. print("Exception START UNIV",e)
  778. gobo_ch=1
  779. if options.gobo_ch:
  780. try:
  781. gobo_ch=int(options.gobo_ch)
  782. except Exception as e:
  783. print("Exception gobo_ch",e)
  784. if gobo_ch <= 0:
  785. gobo_ch = 1
  786. def draw_box(pos1,pos2,color=[128,128,128],text=1):
  787. color = [200,0,0,127]
  788. if text:
  789. fr = font15.render("A" ,1, (200,200,200))
  790. window.blit(fr,pos1)
  791. fr = font15.render("B" ,1, (200,200,200))
  792. window.blit(fr,[pos2[0]-10,pos2[1]-10])
  793. # h unten
  794. _pos1 = [pos1[0],pos2[1]]
  795. _pos2 = [pos2[0],pos2[1]]
  796. pygame.draw.aaline(window,color,_pos1,_pos2,1)
  797. color = [255,255,0,127]
  798. # h rechts
  799. _pos1 = [pos2[0],pos1[1]]
  800. _pos2 = [pos2[0],pos2[1]]
  801. pygame.draw.aaline(window,color,_pos1,_pos2,1)
  802. color = [0,200,0,127]
  803. # h links
  804. _pos1 = [pos1[0],pos1[1]]
  805. _pos2 = [pos1[0],pos2[1]]
  806. pygame.draw.aaline(window,color,_pos1,_pos2,1)
  807. color = [0,0,200,127]
  808. # h oben
  809. _pos1 = [pos1[0],pos1[1]]
  810. _pos2 = [pos2[0],pos1[1]]
  811. pygame.draw.aaline(window,color,_pos1,_pos2,1)
  812. def grab(x=55,y=55,w=60,h=60):
  813. # usage
  814. # sub = grab()
  815. # window.blit(sub, (500,10))
  816. crop = None
  817. rect = pygame.Rect(x, y, w, h)
  818. try:
  819. sub = window.subsurface(rect)
  820. #pixArray = pygame.PixelArray(screen)
  821. crop = pygame.Surface((w,h))
  822. crop.blit(sub, (0,0))
  823. except ValueError as e:
  824. pass#print("exception",e,"line715")
  825. #except Exception as e:
  826. # print("exception",e,"line715")
  827. #print(rect)
  828. return crop
  829. def reshape(_x,_y):
  830. if PIXEL_MAPPING <= 0:
  831. return None
  832. global GRID
  833. global _GRID
  834. x = _x
  835. y = _y
  836. i = 0
  837. counter = 0
  838. z=0
  839. x_min = 99999
  840. x_max = 0
  841. y_min = 99999
  842. y_max = 0
  843. fr = font.render("OUTPUT MAP".format(t1.get()) ,1, (255,255,255))
  844. fr_r = fr.get_rect(center=(x+int(wx/2),y+pm_wy-5))
  845. #window.blit(fr,(x+int(wx/2),y+pm_wy))
  846. window.blit(fr,fr_r)
  847. fr = font.render("↑ ↑ ↑".format(t1.get()) ,1, (255,255,255))
  848. fr_r = fr.get_rect(center=(x+int(wx/2),y+pm_wy+15))
  849. #window.blit(fr,(x+int(wx/2),y+pm_wy))
  850. window.blit(fr,fr_r)
  851. fr = font.render("INPUT".format(t1.get()) ,1, (255,255,255))
  852. fr_r = fr.get_rect(center=(x+int(wx/2),y+pm_wy+35))
  853. #window.blit(fr,(x+int(wx/2),y+pm_wy))
  854. window.blit(fr,fr_r)
  855. j = 0
  856. for fix in _GRID:
  857. if j >= 8*8: # max output size
  858. break
  859. #if j >= _x*_y: # max input size
  860. # break
  861. j+=1
  862. ii = i
  863. #z= i # helping border offset
  864. pos = fix.POS(40,60)
  865. rgb = fix.rgb
  866. # green
  867. pygame.draw.rect(window,[0,40,0],pos)
  868. xposs = [] #None #pos[:]
  869. for fix2 in GRID:
  870. if fix._id == fix2._id:
  871. xposs.append( fix2.POS(40,60) )
  872. for xpos in xposs:
  873. sub = grab(xpos[0],xpos[1]+pm_wy,xpos[2],xpos[3])
  874. if sub:
  875. if 1:#j <= _x*_y: # max input size
  876. window.blit(sub, (x+pos[0]+z,y+pos[1]+z))
  877. else:
  878. # red
  879. pygame.draw.rect(window,[40,0,0],pos) #[x+pos[0]+2+z,y+pos[1]+2+z-pm_wy,12,9])
  880. if xpos[0] < x_min:
  881. x_min = xpos[0]
  882. if xpos[0] > x_max:
  883. x_max += xpos[2]
  884. if xpos[1] < y_min:
  885. y_min = xpos[1]
  886. if xpos[1] > x_max:
  887. y_max += xpos[3]
  888. # DRAW FIX NUMBER on TOP
  889. #apos = pos
  890. #argb = rgb
  891. apos = fix.POS(40,60+pm_wy)
  892. argb = fix.rgb
  893. # overwrite number overlay
  894. if NR:
  895. #pygame.draw.rect(window,[30,40,0],apos)
  896. pygame.draw.rect(window,[20,40,0],[x+apos[0]+2+z,y+apos[1]+2+z-pm_wy,12,9])
  897. if NR:# == 2:
  898. if fix._id != i+1:
  899. fr = font15.render("{:02}".format(fix._id) ,1, (255,255,0))
  900. window.blit(fr,(x+apos[0]+2+z,y+apos[1]+2+z-pm_wy))
  901. #print(fix._id,xposs,pos)
  902. else:
  903. fr = font15.render("{:02}".format(fix._id) ,1, (100,100,255))
  904. window.blit(fr,(x+apos[0]+2+z,y+apos[1]+2+z-pm_wy))
  905. i += 1
  906. #print("--#")
  907. # frame box
  908. #pygame.draw.box(window,[100,0,0],[x+x_min,y+x_min,x_max+x_min,y_min+y_max])
  909. pos1= [x+x_min,y+x_min]
  910. pos2= [x_max+x_min,y_min+y_max]
  911. #draw_box(pos1,pos2,text=0)
  912. class Timer():
  913. def __init__(self,start=120):
  914. self.start = start
  915. self.timer = self.start
  916. self.timer_t = time.time()
  917. def reset(self):
  918. self.timer = self.start
  919. def get(self):
  920. self.timer -= time.time()-self.timer_t
  921. self.timer_t = time.time()
  922. if self.timer <= 0:
  923. self.reset()
  924. return self.timer
  925. def reload_grid():
  926. print("==== reload_grid")
  927. global GRID
  928. global _GRID
  929. try:
  930. GRID = init_grid(_x=_x,_y=_y) #init_gird()
  931. _GRID = init_grid(_x=8,_y=8,mapping=1) #init_gird()
  932. except Exception as e:
  933. print("Except: grid re init",e)
  934. VPU_TEXT = []
  935. def load_vpu_text(nr=0):
  936. txt = "NONE"
  937. if not VPU_TEXT:
  938. pass #create VPU_TEXT_FILE
  939. if len(VPU_TEXT) > nr:
  940. txt = VPU_TEXT[0]
  941. return txt
  942. grid_counter = time.time()
  943. def draw_fix_nr(GRID):
  944. global grid_counter
  945. i=0
  946. y=0
  947. for fix in GRID:
  948. pos = fix.POS(40,60+pm_wy)
  949. rgb = fix.rgb
  950. if NR:
  951. pygame.draw.rect(window,[0,0,0],[pos[0]+2,pos[1]+2,12,9])
  952. if fix._id%_x-1 == 0: # line break border
  953. pygame.draw.line(window,[255,255,0],(pos[0],pos[1]+4),(pos[0],pos[1]+pos[3]-4),1)
  954. pygame.draw.line(window,[255,255,0],(pos[0],pos[1]+int(pos[3]/2)),(pos[0]+int(pos[2]/2),int(pos[1]+pos[3]/2)),1)
  955. if fix._id%_x == 0: # line break border
  956. pygame.draw.line(window,[255,255,255],(pos[0]+pos[2]-1,pos[1]+4),(pos[0]+pos[2]-1,pos[1]+pos[3]-4),1)
  957. pygame.draw.line(window,[255,255,255],(pos[0]+pos[2]-1,int(pos[1]+pos[3]/2)),(pos[0]+int(pos[2]/2-1),int(pos[1]+pos[3]/2)),1)
  958. if grid_counter +5 < time.time():
  959. grid_counter = time.time()
  960. reload_grid()
  961. if fix._id != i+1:
  962. fr = font15.render("{:02}".format(fix._id) ,1, (255,255,0))
  963. else:
  964. fr = font15.render("{:02}".format(fix._id) ,1, (100,100,255))
  965. window.blit(fr,(pos[0]+2,pos[1]+2))
  966. i += 1
  967. def draw_counter(COUNTER):
  968. for count in COUNTER:
  969. cpan = 0
  970. ctilt = 0
  971. cr=255
  972. cg=255
  973. cb=255
  974. csize=10
  975. cdim=0
  976. k = "DIM"
  977. if k in count:
  978. cdim = int(count[k])
  979. k = "RED"
  980. if k in count:
  981. cr = int(count[k])
  982. k = "GREEN"
  983. if k in count:
  984. cg = int(count[k])
  985. k = "BLUE"
  986. if k in count:
  987. cb = int(count[k])
  988. k = "SIZE"
  989. if k in count:
  990. csize = int(count[k])
  991. if csize < 5:
  992. csize = 5
  993. k = "PAN"
  994. if k in count:
  995. cpan = int(count[k])/255*(block[0] *(_x))
  996. cpan = int(cpan)
  997. k = "TILT"
  998. if k in count:
  999. ctilt = int(count[k])/255*(block[1] *(_y))
  1000. ctilt = int(ctilt)
  1001. ddim = cdim/255
  1002. if "DIM" in count and count["DIM"] > 0:
  1003. tmp_font = pygame.font.SysFont("freemonobold",int(block[0]/100*csize))
  1004. rgb =(int(cr*ddim),int(cg*ddim),int(cb*ddim),cdim)
  1005. _sec = count["_SEC"]
  1006. try:
  1007. _sec = int(count["_SEC"])
  1008. except:
  1009. pass
  1010. if type(_sec) is int:
  1011. #print(_sec)
  1012. if _sec <= 60:
  1013. fr = tmp_font.render("{:0}".format(_sec) ,1, rgb)
  1014. else:
  1015. _xx = time.strftime("%M:%S",time.localtime(_sec))
  1016. #print("_xx",_xx)
  1017. fr = tmp_font.render("{}".format(_xx) ,1, rgb)
  1018. else:
  1019. fr = tmp_font.render("{}".format((count["_SEC"])) ,1, rgb)
  1020. fr_r = fr.get_rect(center=(60+cpan-(block[0]),60+ctilt+pm_wy))
  1021. pygame.draw.rect(window,[0,0,0],fr_r)
  1022. window.blit(fr,fr_r)
  1023. def draw_video(VIDEO):
  1024. global videplayer
  1025. i = 0
  1026. for count in VIDEO:
  1027. cpan = 0
  1028. ctilt = 0
  1029. cr=255
  1030. cg=255
  1031. cb=255
  1032. csize=10
  1033. cdim=0
  1034. k = "DIM"
  1035. if k in count:
  1036. cdim = int(count[k])
  1037. k = "SIZE"
  1038. if k in count:
  1039. csize = int(count[k])
  1040. if csize < 5:
  1041. csize = 5
  1042. k = "PAN"
  1043. if k in count:
  1044. cpan = int(count[k])/255*(block[0] *(_x))
  1045. cpan = int(cpan)
  1046. k = "TILT"
  1047. if k in count:
  1048. ctilt = int(count[k])/255*(block[1] *(_y))
  1049. ctilt = int(ctilt)
  1050. video1 = videoplayer[i]
  1051. k = "_RUN"
  1052. if k in count:
  1053. video1._run = count[k]
  1054. video1.pos
  1055. video1.x=40+cpan
  1056. video1.y=60+pm_wy+ctilt
  1057. video1.scale = int((csize))
  1058. if cdim:
  1059. video1.next()
  1060. #video1.prev()
  1061. video1.draw(window) #,x=0,y=0)
  1062. # overlay
  1063. video1.overlay(window,"run")
  1064. i += 1
  1065. def counter_dmx(COUNTER,dataA):
  1066. for count in COUNTER:
  1067. cDMX=count["DMX"]-1
  1068. try:
  1069. count["DIM"] = dataA[cDMX]
  1070. count["PAN"] = dataA[cDMX+1]
  1071. count["TILT"] = dataA[cDMX+2]
  1072. count["CONTROL"] = dataA[cDMX+3]
  1073. if count["CONTROL"] >= 10 and count["CONTROL"] < 20:
  1074. count["_SEC"] = int(count["SEC"] - (time.time() - count["_time"]))
  1075. if count["CONTROL"] >= 20 and count["CONTROL"] < 30:
  1076. count["_RUN"] = 0
  1077. if count["CONTROL"] >= 30 and count["CONTROL"] < 40:
  1078. count["_RUN"] = 1
  1079. count["SIZE"] = dataA[cDMX+4]
  1080. count["SEC"] = dataA[cDMX+5]
  1081. if count["_RUN"]:
  1082. try:
  1083. count["_SEC"] = int(count["SEC"] - (time.time() - count["_time"]))
  1084. except Exception as e:
  1085. pass
  1086. if type(count["_SEC"]) is int:
  1087. if count["_SEC"] < 0:
  1088. count["_SEC"] = 0
  1089. for ti in range(10):
  1090. #print(ti,(ti+6)*10)
  1091. if count["CONTROL"] >= (ti+6)*10 and count["CONTROL"] < (ti+7)*10:
  1092. count["_SEC"] = "----" #text 1
  1093. try:
  1094. count["_SEC"] = TEXT_BLOCK[ti]
  1095. except Exception as e:
  1096. pass
  1097. if count["CONTROL"] >= 250 and count["CONTROL"] < 256:
  1098. count["_SEC"] = ">{}<".format(cDMX+1)
  1099. count["RED"] = dataA[cDMX+6]
  1100. count["GREEN"] = dataA[cDMX+7]
  1101. count["BLUE"] = dataA[cDMX+8]
  1102. except Exception as e:
  1103. print("EXC FUNC",e,count)
  1104. #print(count)
  1105. def video_dmx(VIDEO,dataA):
  1106. for count in VIDEO:
  1107. cDMX=count["DMX"]-1
  1108. try:
  1109. count["DIM"] = dataA[cDMX]
  1110. count["PAN"] = dataA[cDMX+1]
  1111. count["TILT"] = dataA[cDMX+2]
  1112. count["CONTROL"] = dataA[cDMX+3]
  1113. if count["CONTROL"] >= 10 and count["CONTROL"] < 20:
  1114. count["_time"] = int(time.time()*10)/10
  1115. if count["CONTROL"] >= 20 and count["CONTROL"] < 30:
  1116. if count["_RUN"] == 1:
  1117. print( "_RUN:0",count["DMX"]-1)
  1118. count["_RUN"] = 0
  1119. if count["CONTROL"] >= 30 and count["CONTROL"] < 40:
  1120. if count["_RUN"] == 0:
  1121. print( "_RUN:1",count["DMX"]-1)
  1122. count["_RUN"] = 1
  1123. count["SIZE"] = dataA[cDMX+4]
  1124. count["SEC"] = dataA[cDMX+5]
  1125. count["RED"] = dataA[cDMX+6]
  1126. count["GREEN"] = dataA[cDMX+7]
  1127. count["BLUE"] = dataA[cDMX+8]
  1128. except Exception as e:
  1129. print("VIDEOPLAYER EXCEPT FUNC",e,count)
  1130. #print(count)
  1131. def read_dmx_data(ip,ips):
  1132. ip = select_ip(ips,univ=START_UNIV)
  1133. IP = ip
  1134. data = read_dmx(ip)
  1135. ip = select_ip(ips,univ=START_UNIV+1)
  1136. data3 = read_dmx(ip)
  1137. data.extend(data3)
  1138. ip = select_ip(ips,univ=START_UNIV+2)
  1139. data3 = read_dmx(ip)
  1140. data.extend(data3)
  1141. ip = select_ip(ips,univ=START_UNIV+4)
  1142. data3 = read_dmx(ip)
  1143. data.extend(data3)
  1144. #ip = select_ip(ips,univ=START_UNIV+5)
  1145. #data3 = read_dmx(ip)
  1146. #data.extend(data3)
  1147. return data
  1148. def draw_gobo(GRID,data):
  1149. i = 0
  1150. dmx = 1
  1151. h = 1
  1152. v = 1
  1153. for fix in GRID:
  1154. pos = fix.POS(40,60+pm_wy)
  1155. rgb = fix.rgb
  1156. if 1:
  1157. # draw row/col grid number
  1158. if fix.pos[0] == 0:
  1159. fr = font12.render("{}".format(fix.pos[1]+1) ,1, (200,200,200))
  1160. window.blit(fr,(10,pos[1]+3 ))
  1161. if fix.pos[1] == 0:
  1162. fr = font12.render("{}".format(fix.pos[0]+1) ,1, (200,200,200))
  1163. window.blit(fr,(pos[0]+2,35 ))
  1164. pygame.draw.rect(window,rgb,pos)
  1165. # DRAW SUB-FIXTURE
  1166. j = 0
  1167. for subfix in fix.sub_fix:#calc(data):
  1168. subfix.calc(data)
  1169. #fix = subfix
  1170. spos = subfix.POS(40,60+pm_wy)
  1171. srgb = subfix.rgb
  1172. #print(fix.dmx,rgb,pos)
  1173. #pygame.draw.circle(window,rgb,(pos[0]+int(pos[2]/2),pos[1]+int(pos[3]/2)),int(pos[3]/2))
  1174. #FUNC = 0
  1175. if FUNC > 10 and FUNC <= 20: # big dot
  1176. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1177. elif FUNC > 20 and FUNC <= 30:#small dot
  1178. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1179. elif FUNC > 30 and FUNC <= 40:#donut
  1180. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1181. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1182. elif FUNC > 40 and FUNC <= 50: # rec with hole
  1183. pygame.draw.rect(window,srgb,spos)
  1184. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1185. elif FUNC > 50 and FUNC <= 60: # rec with big hole
  1186. pygame.draw.rect(window,srgb,spos)
  1187. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1188. elif FUNC > 60 and FUNC <= 70: # rec with donat
  1189. pygame.draw.rect(window,srgb,spos)
  1190. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1191. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1192. elif FUNC > 70 and FUNC <= 80: # rec boarder
  1193. pygame.draw.rect(window,srgb,[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1194. elif FUNC > 80 and FUNC <= 90: # rec big boarder
  1195. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1196. elif FUNC > 90 and FUNC <= 100: # rec thin line
  1197. pygame.draw.rect(window,srgb,spos)
  1198. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1199. elif FUNC > 100 and FUNC <= 110: # rec big line
  1200. pygame.draw.rect(window,srgb,spos)
  1201. pygame.draw.rect(window,[0,0,0],[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1202. elif FUNC > 110 and FUNC <= 120: # rec with dot
  1203. pygame.draw.rect(window,srgb,spos)
  1204. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1205. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1206. elif FUNC > 120 and FUNC <= 130: # rec inline
  1207. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1208. pygame.draw.rect(window,[0,0,0],[spos[0]+3,spos[1]+3,spos[2]-6,spos[3]-6])
  1209. elif FUNC > 130 and FUNC <= 140: # 3 dot (heart)
  1210. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)+2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1211. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)-2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1212. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)+2),int(spos[3]/3.5))
  1213. else:
  1214. pygame.draw.rect(window,srgb,spos)
  1215. for subfix in fix.sub_fix:#calc(data):
  1216. subfix.calc(data)
  1217. #fix = subfix
  1218. spos = subfix.POS(40,60+pm_wy)
  1219. srgb = subfix.rgb
  1220. # draw row/col grid number
  1221. if subfix.pos[0] == 0:
  1222. fr = font12.render("{}".format(v ) ,1, (200,200,200))
  1223. window.blit(fr,(25,spos[1] ))
  1224. v += 1
  1225. if subfix.pos[1] == 0:
  1226. fr = font12.render("{}".format(1) ,1, (200,200,200))
  1227. fr = font12.render("{}".format(h ) ,1, (200,200,200))
  1228. h+=1
  1229. window.blit(fr,(spos[0],50 ))
  1230. if p >= 40:
  1231. if NR:
  1232. #fr = font15.render("{:02}".format(j+1) ,1, (0,200,255))
  1233. fr = font15.render("{:02}".format(subfix._id) ,1, (250,200,5))
  1234. window.blit(fr,(spos[0]+2,spos[1]+10))
  1235. j += 1
  1236. i += 1
  1237. t1 = Timer(143)
  1238. time.sleep(0.33)
  1239. t2 = Timer(11)
  1240. count_tilt = 0
  1241. def main():
  1242. global IP
  1243. global GRID
  1244. global _GRID
  1245. global FUNC
  1246. global count_tilt
  1247. global TEXT_BLOCK
  1248. global TEXT_BLOCK_TIME
  1249. global PLAYLIST
  1250. global PLAYLIST_TIME
  1251. GRID = init_grid(_x=_x,_y=_y) #init_gird()
  1252. #GRID = init_grid(_x=8,_y=8) #init_gird()
  1253. print("GRID LEN:",len(GRID))
  1254. s=time.time()
  1255. print("run")
  1256. r = ""
  1257. IP = "xx"
  1258. while running:
  1259. if TEXT_BLOCK_TIME+5 < time.time():
  1260. TEXT_BLOCK = open_text_block()
  1261. TEXT_BLOCK_TIME = time.time()
  1262. if PLAYLIST_TIME+6 < time.time():
  1263. PLAYLIST = open_playlist()
  1264. PLAYLIST_TIME = time.time()
  1265. pygame.display.flip()
  1266. event()
  1267. window.fill((10,0,20))
  1268. calc_fps()
  1269. draw_overlay()
  1270. ips = read_index()
  1271. # ----
  1272. ip = select_ip(ips,univ=1) # univ 1 gobo
  1273. dataA = read_dmx(ip)
  1274. # ----
  1275. data = read_dmx_data(ip,ips)
  1276. if options.countdown:
  1277. counter_dmx(COUNTER,dataA)
  1278. if VIDEO:
  1279. video_dmx(VIDEO,dataA)
  1280. # GRID loop
  1281. try:
  1282. ddd = 1023 #univ 3 512
  1283. #FUNC = data[ddd]
  1284. FUNC2 = dataA[gobo_ch-1]
  1285. FUNC = FUNC2
  1286. #print("FUNC", FUNC )#:ddd+512])
  1287. #FUNC = 15
  1288. except Exception as e:
  1289. print("EXC FUNC",e)
  1290. draw_gobo(GRID,data)
  1291. # DRAW FIX NUMBER on TOP
  1292. draw_fix_nr(GRID)
  1293. #COUNTER.append({"DMX":31,"DIM":0,"PAN":127,"TILT":127,"CONTROL":0,"SEC":10,"RED":255,"GREEN":255,"BLUE":255,"_time":time.time(),"_RUN":0,"_SEC":0})
  1294. if options.countdown:
  1295. draw_counter(COUNTER)
  1296. if VIDEO:
  1297. draw_video(VIDEO)
  1298. pointer.draw(0,pm_wy) #wy
  1299. spos = [0,0,0,0]
  1300. if PIXEL_MAPPING >= 1:
  1301. reshape(0,0) #start pos
  1302. else:
  1303. reshape(spos[0]+spos[2]+20,10) #start pos
  1304. #reshape(spos[0]+spos[2]+20,10) #start pos
  1305. pygame.display.flip()
  1306. #pg.time.wait(15)
  1307. clock.tick(10)
  1308. if 'SDL_VIDEO_WINDOW_POS' in os.environ:
  1309. del os.environ['SDL_VIDEO_WINDOW_POS'] #= '%i,%i' % (200,164)
  1310. #if 'SDL_VIDEO_CENTERED' in os.environ['SDL_VIDEO_CENTERED']:
  1311. # del os.environ['SDL_VIDEO_CENTERED'] #= '0'
  1312. if __name__ == "__main__":
  1313. main()