vpu_live.py 56 KB

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