vpu_live.py 44 KB

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