vpu_live.py 40 KB

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