vpu_live.py 45 KB

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