vpu_live.py 45 KB

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