vpu_live4.py 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654
  1. #!/usr/bin/python3
  2. import math
  3. import random
  4. import time
  5. import os
  6. import sys
  7. import traceback
  8. import gc
  9. HOME = os.getenv('HOME')
  10. import _thread as thread
  11. from optparse import OptionParser
  12. ...
  13. parser = OptionParser()
  14. parser.add_option("-m", "--mode", dest="mode",
  15. help="pixel mode pix,x,y --mode 40,10,8") #, metavar="FILE")
  16. parser.add_option("-X", "--XX", dest="XX", #default=1,
  17. help="x-split") #, metavar="FILE")
  18. parser.add_option("-x", "--xx", dest="xsplit", #default=1,
  19. help="x-split") #, metavar="FILE")
  20. parser.add_option("-y", "--yy", dest="ysplit",#default=1,
  21. help="y-split") #, metavar="FILE")
  22. parser.add_option("", "--start-univ", dest="start_univ",default=2,
  23. help="set start-univers default=2") #, metavar="FILE")
  24. parser.add_option("", "--gobo-ch", dest="gobo_ch",default=0,
  25. help="gobo ch univ on 1") #, metavar="FILE")
  26. parser.add_option("", "--gobo-ch2", dest="gobo_ch2",default=0,
  27. help="gobo ch univ on 1") #, metavar="FILE")
  28. #os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,164)
  29. parser.add_option("", "--win-pos", dest="win_pos",default="200,164",
  30. help="SDL_VIDEO_WINDOW_POS --win-pos=200,164") #, metavar="FILE")
  31. parser.add_option("", "--pixel-mapping", dest="pixel_mapping",default=0,
  32. help="pixel_mapping file/on --pixel-mapping=_x") #, metavar="FILE")
  33. parser.add_option("", "--dual-vpu", dest="dual_vpu",default=0,
  34. help=" --dual-vpu=1/0") #, metavar="FILE")
  35. parser.add_option("", "--grid-a1-idim", dest="grid_a1_idim",default=0,
  36. help=" grid_a1_idim") #, metavar="FILE")
  37. parser.add_option("", "--grid-a2-idim", dest="grid_a2_idim",default=0,
  38. help=" grid_a2_idim") #, metavar="FILE")
  39. parser.add_option("", "--countdown", dest="countdown",#default=1,
  40. help="enable countdown") #, metavar="FILE")
  41. parser.add_option("", "--videoplayer", dest="videoplayer",#default=1,
  42. help="enable videoplayer") #, metavar="FILE")
  43. parser.add_option("", "--title", dest="title",default="SCREEN",
  44. help="set title") #, metavar="FILE")
  45. (options, args) = parser.parse_args()
  46. import numpy
  47. for o in dir(options):
  48. if "_" in o:
  49. continue
  50. print(o,options.__getattribute__(o))
  51. START = time.time()
  52. # ===== ARTNET DMX =========
  53. import memcache
  54. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  55. def read_index():
  56. ips=mc.get("index")#cmd)
  57. if ips is None:
  58. ips = {}
  59. return ips
  60. def select_ip(ips, univ=2): # artnet univ
  61. _univ = ":{}".format(univ)
  62. for ip in ips: #high priority
  63. if "2.0.0" in ip and _univ in ip:
  64. return ip
  65. for ip in ips:
  66. if "ltp-out" in ip and _univ in ip:
  67. return ip
  68. FUNC = 0
  69. COUNTER = []
  70. if options.countdown:
  71. cdmx_start = options.countdown.split(",")
  72. for cdmx in cdmx_start:
  73. try:
  74. cdmx = int(cdmx)
  75. _tmp={"DMX":cdmx,"DIM":0,"PAN":127,"TILT":127
  76. ,"CONTROL":0,"SEC":10
  77. ,"RED":255,"GREEN":255,"BLUE":255
  78. ,"_time":time.time(),"_RUN":0,"_pause":0,"_start":0
  79. ,"_SEC":">{}<".format(cdmx)
  80. }
  81. COUNTER.append(_tmp)
  82. except Exception as e:
  83. print("EXCEPTION COUNTER INIT ",cdmx)
  84. def read_dmx(ip):
  85. r = ""
  86. if ip:
  87. #t = int(math.sin(time.time() - s)*10)
  88. r = mc.get(ip) #"2.0.0.13:2")
  89. rr = [0]*512
  90. for i,v in enumerate(r):
  91. try: #cleanup ltp-out to int
  92. v = int(v)
  93. rr[i] = v
  94. except:pass
  95. r = rr
  96. if not r:
  97. c = 0
  98. #time.sleep(0.1)
  99. r = [0] *512
  100. for i in range(12*8+1):
  101. dmx = i*4
  102. #print(dmx)
  103. r[dmx:dmx+4] = [255,10,10,40]
  104. return r
  105. # ===== ARTNET DMX =========
  106. PLAYLIST = []
  107. try:
  108. PLAYLIST = open_playlist()
  109. except:pass
  110. #import json
  111. #import pickle
  112. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  113. from tool.video_capture import scan_capture #as scan_capture
  114. class Vopen():
  115. def __init__(self,dmx=None,_id=None):
  116. global PLAYLIST
  117. self._id = _id
  118. self.fpath = HOME+'/Downloads/'
  119. self.fpath = HOME+'/LibreLight/video/'
  120. self.fname = '' #'bbb_sunflower_480x320.mp4'
  121. #self.fname = 'no-video.mp4'
  122. try:
  123. self.fname = PLAYLIST[0]
  124. except Exception as e:
  125. print("Exception set video from PLAYLIST 5543:",e)
  126. self.restart_t = time.time()
  127. self.fps = 0
  128. self.scale = 50 #%
  129. self.angle = 0 #%
  130. self.dmx=dmx
  131. if self._id >= 250:
  132. self.fname = "cam_"
  133. self.dim = 0
  134. self.x = 0
  135. self.y = 0
  136. self.init_count = 0
  137. self.cap = None
  138. self.shape = [200,200]
  139. self.img = None
  140. self.success = 1
  141. self.cv2 = None
  142. self._run = 0
  143. self.end = 0
  144. self._video_nr = 0
  145. self._stop = 0 # fix buffer-overflow ... ?? opencv
  146. self.shape_x = 370
  147. self.shape_y = 235
  148. try:
  149. global cv2
  150. self.cv2 = cv2
  151. except:
  152. pass
  153. self.init()
  154. def __repr__(self):
  155. sizeof = int(sys.getsizeof(self.buffer)/8)
  156. return "< id:{} buf:{} run:{} fps:{} scale:{} name:{} {}kb>".format(
  157. id(self),len(self.buffer),self._run,self.fps,self.scale
  158. ,self.fname,sizeof
  159. )
  160. def restart(self):
  161. print(self,"reset()")
  162. self.pos = 0
  163. self.restart_t = time.time()
  164. def init(self):
  165. print("---- ---- Vopen.init()",[self.fname,self._video_nr])
  166. print(PLAYLIST)
  167. self.time = 0
  168. self.t_delta = 0
  169. self.t_last = time.time()
  170. self.im = None
  171. self.pos = 0
  172. self.buffer = []
  173. self._init()
  174. self.init_count = 1
  175. def select_video(self,dmx_value):
  176. try:
  177. dmx_value = int(dmx_value/10)
  178. if self._video_nr != dmx_value:
  179. self._video_nr = dmx_value
  180. if self._video_nr >= 25:
  181. self.fname = "cam_"
  182. self.init()
  183. elif self._video_nr < len(PLAYLIST):
  184. self.fname = str(PLAYLIST[self._video_nr])
  185. self.init()
  186. except Exception as e:
  187. print("Vopen.select_video()",dmx_value,e)
  188. def close_cap():
  189. print(dir(self.Rcap)) # = self.cv2.VideoCapture(self.fpath+self.fname)
  190. def _cam_cfg_new(self,fn):
  191. #fn = HOME+'/LibreLight/video_in.txt'
  192. txt = [
  193. "# Example",
  194. "d0 w640 h480 # PAL",
  195. "d0 w800 h600 # SVGA",
  196. "d0 w960 h540 # 540p",
  197. "d0 w1024 h768 # XGA <---",
  198. "d0 w1280 h720 # 720p",
  199. "d0 w1440 h900 # WSXGA+",
  200. "d0 w1600 h900 # WSXGA - Laptop 16:9",
  201. "d0 w1920 h1080 # HD 1080p",
  202. "",
  203. "# config",
  204. "d0 w1024 h768 # XGA",
  205. ]
  206. f = open(fn ,"w")
  207. f.write("\n".join(txt))
  208. f.close()
  209. def _cam_cfg(self):
  210. fn = HOME+'/LibreLight/video_in.txt'
  211. if not os.path.isfile(fn):
  212. self._cam_cfg_new(fn)
  213. f = open(fn ,"r")
  214. lines = f.readlines()
  215. f.close()
  216. cfg = ""
  217. for i in lines:
  218. if i.startswith("d"):
  219. cfg = i
  220. cfg = cfg.split()
  221. capture = scan_capture(name="MiraBox",serial="")
  222. if capture:
  223. print("capture",capture)
  224. try:
  225. cfg.append(capture[0][0])
  226. except Exception as e:
  227. print("except 2992",e)
  228. else:
  229. print("---- ERROR NO VIDEO CAPTURE DEV - FOUND ----")
  230. print("_cam_cfg:",len(cfg),[cfg])
  231. return cfg
  232. def _open_cam(self):
  233. # LIVE VIDEO INPUT UVC DEVICE
  234. cfg = self._cam_cfg()
  235. res = "HD"
  236. #res = "4K"
  237. #res = ""
  238. if res == "HD":
  239. # HD
  240. w = 1920
  241. h = 1080
  242. elif res == "4K":
  243. # 4K
  244. w = 3840
  245. h = 2160
  246. else:
  247. # LOW
  248. w = 1280
  249. h = 720
  250. d = 0 # VIDEO INPUT DEV
  251. for c in cfg:
  252. try:
  253. if c.startswith("d"):
  254. d = int(c[1:])
  255. if c.startswith("h"):
  256. h = int(c[1:])
  257. if c.startswith("w"):
  258. w = int(c[1:])
  259. if c.startswith("video"):
  260. d = int(c[-1])
  261. except Exception as e:
  262. print("Exception", "cam_cfg 878",e)
  263. df = "video{}".format(d)
  264. if self._stop:
  265. df += "_stop"
  266. elif os.path.exists("/dev/{}".format(df)):
  267. self.Rcap = self.cv2.VideoCapture(d)
  268. self.Rcap.set(self.cv2.CAP_PROP_FRAME_WIDTH, w)
  269. self.Rcap.set(self.cv2.CAP_PROP_FRAME_HEIGHT, h)
  270. else:
  271. #self.Rcap = None
  272. #self.end = 1
  273. df += "_error"
  274. if self.fname.startswith("cam_"):
  275. self.fname = "cam_{}".format(df)
  276. def _init(self):
  277. print(self)
  278. print("videoplayer.init()",self.fpath,self.fname)
  279. if not os.path.isfile(self.fpath+self.fname):
  280. print()
  281. print("video file does not exits !! >",self.fpath,self.fname)
  282. print()
  283. #exit()
  284. self.Rsuccess = 0
  285. if self.cv2:
  286. if self._stop:
  287. return
  288. if self.fname.startswith("cam_"):
  289. self._open_cam()
  290. else:
  291. self.Rcap = self.cv2.VideoCapture(self.fpath+self.fname, cv2.CAP_FFMPEG)
  292. #FFMPEG malloc(): unsorted double linked list corrupted ... Abgebrochen
  293. print("_init ?",self.Rcap)
  294. print("open ?" ,self.Rcap.isOpened())
  295. self.Rcap.read()
  296. #self.Rfvs = FileVideoStream(self.fpath+self.fname).start()
  297. self.Rsuccess = 1
  298. self._read()
  299. def _del(self):
  300. self._stop = 1
  301. self.buffer = [] #.append(self.img)
  302. self.Rcap.release()
  303. self.Rcap.retrieve()
  304. self.Rcap = None
  305. self.cap = None
  306. del self.Rcap #.release()
  307. gc.collect()
  308. def _read(self):
  309. success = self.Rsuccess
  310. ok = 0
  311. if success and self.fname:
  312. cap = self.Rcap
  313. #fvs = self.Rfvs
  314. _break = 0
  315. try:
  316. success, img = cap.read()
  317. if not success:
  318. self.Rcap.release()
  319. self.Rcap.retrieve()
  320. self.end = 1
  321. #j = json.dumps(self.buffer) #.append(img)
  322. #f = open("/tmp/buff")
  323. #f.write(j)
  324. #f.close()
  325. return
  326. if self.fps == 0:
  327. self.fps = cap.get(cv2.CAP_PROP_FPS)
  328. img = self.cv2.cvtColor(img, self.cv2.COLOR_BGR2RGB)
  329. if self.fname.startswith("cam_"):
  330. pass
  331. #img = self.rescale_frame2(img, 1200)
  332. else:
  333. #img = self.rescale_frame2(img, 200)
  334. #img = self.rescale_frame2(img, 1200)
  335. # store frame into buffer list
  336. if self.fname.startswith("cam_"):
  337. self.buffer = [ img ]
  338. else:
  339. self.buffer.append(img)
  340. ok = 1
  341. if len(self.buffer) % 100 == 0:
  342. _id = str(self.__repr__)[-5:-1]
  343. print(_id,"video read",self.dmx,len(self.buffer),self.fname,"fps",self.fps,self.dim)
  344. except Exception as e:
  345. print("Excetpion","_init",self,e,end="")
  346. self.success = 1
  347. return ok
  348. def read(self):
  349. pass
  350. def prev(self):
  351. self.pos -= 1
  352. if self.pos < 0:
  353. self.pos = len(self.buffer)-1
  354. if self.pos >= len(self.buffer):
  355. self.pos = len(self.buffer)-1
  356. self.im = self.buffer[int(self.pos)]
  357. def rotateImage(self,image, angle):
  358. if angle in [0,360]:
  359. pass#return image
  360. try:
  361. #print("EE",image.shape)
  362. #print("EE",dir(image))
  363. shape = list(image.shape[1::-1])
  364. bg_shape = shape[:]
  365. delta_x = 0 # + nach rechts
  366. delta_y = 0 # + nach unten
  367. r = []
  368. r.extend(list(range(0-3,0+3)))
  369. r.extend(list(range(180-3,180+3)))
  370. r.extend(list(range(360-3,360+3)))
  371. r2 = []
  372. r2.extend(list(range(90-3,90+3)))
  373. r2.extend(list(range(270-3,270+3)))
  374. if angle in r:
  375. pass
  376. elif 0:#angle in r2:
  377. bg_shape = bg_shape[::-1]
  378. delta_y = -65 #shape[1]/2 # # + nach unten
  379. delta_x = 30 #shape[1]/2 # # + nach unten
  380. delta_y -= bg_shape[1]/2 - 20
  381. delta_x = bg_shape[0]/2 - 10
  382. pass
  383. else:
  384. if shape[0] > shape[1]:
  385. # landscape video
  386. bg_shape = (shape[0],shape[0])
  387. delta_y = (shape[0]-shape[1])/2
  388. else:
  389. # portrait video
  390. bg_shape = (shape[1],shape[1])
  391. delta_x = (shape[1]-shape[0])/2
  392. center = (shape[0]/2+delta_x,shape[1]/2+delta_y)
  393. image = self.moveImage(image,x=delta_x,y=delta_y,shape=bg_shape)
  394. bg_shape = tuple(bg_shape) # exception ... if angle 0 no tuple !!!
  395. rot_mat = self.cv2.getRotationMatrix2D(center,angle,1.0)
  396. frame = self.cv2.warpAffine(image, rot_mat, bg_shape ) #,flags=self.cv2.INTER_LINEAR)
  397. return frame
  398. except Exception as e:
  399. raise(e)
  400. def moveImage(self,img,x=0,y=0,shape=None):
  401. # Creating a translation matrix
  402. np = numpy
  403. translation_matrix = np.float32([ [1,0,x], [0,1,y] ])
  404. if shape is None:
  405. num_cols,num_rows = img.shape[1::-1]
  406. else:
  407. num_cols,num_rows = shape #[1::-1]
  408. # Image translation
  409. frame = self.cv2.warpAffine(img, translation_matrix, (num_cols,num_rows))
  410. return frame
  411. def rescale_frame2(self,frame, width):
  412. height = int(frame.shape[0]/frame.shape[1] * width )
  413. dim = (width, height)
  414. return self.cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
  415. def rescale_frame(self,frame, percent=75):
  416. width = int(frame.shape[1] * percent/ 100)
  417. height = int(frame.shape[0] * percent/ 100)
  418. dim = (width, height)
  419. return self.cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
  420. def pause(self):
  421. #print("pause",self.t_last)
  422. t = time.time()
  423. self.t_delta = 0
  424. self.t_last = t
  425. def next_frame(self):
  426. #return 0
  427. if self._run and len(self.buffer) > 30:
  428. t = time.time()
  429. self.t_delta = t-self.t_last
  430. self.pos += self.t_delta*self.fps
  431. self.t_last = t
  432. else:
  433. self.pause()
  434. if self.restart_t > time.time()-0.5:
  435. # prevent flickerung by reset
  436. #self.pause()
  437. self.pos = 5
  438. pass
  439. # restart at the end
  440. if int(self.pos) >= len(self.buffer)-1:
  441. self.pos = 0
  442. self.img = None
  443. if self.buffer:
  444. self._img = self.buffer[int(self.pos)]
  445. self.img = self._img
  446. def next(self):
  447. try:
  448. self.next_frame()
  449. if self.img is None:
  450. return
  451. self.img = self.rescale_frame(self.img, percent=self.scale)
  452. # rotate frame BUG: x,y offset ??? !!!
  453. self.img = self.rotateImage(self.img, self.angle)
  454. self.shape = self.img.shape[1::-1]
  455. if len(self.buffer) % 100 == 0:
  456. _id = str(self.__repr__)[-5:-1]
  457. print("next",_id)
  458. # add DIMER to videplayer
  459. self.cv2.normalize(self.img, self.img, 0, self.dim, self.cv2.NORM_MINMAX)
  460. img = self.img
  461. if img is None:
  462. return
  463. self.im = None
  464. self.im = pygame.image.frombuffer(img.tobytes(), self.shape, "RGB")
  465. #self.next_frame()
  466. except AttributeError as e:
  467. time.sleep(.05)
  468. #if self.init_count % 100 == 0:
  469. print("except 776",e)
  470. #self.init()
  471. except Exception as e:
  472. print("except 756",e)
  473. print(traceback.format_exc())
  474. print(sys.exc_info()[2])
  475. print()
  476. def draw(self,wn=None):
  477. if self.dim <= 1:
  478. return
  479. if self.scale < 255*.05:
  480. self.scale = 255*0.05
  481. # draw video background box
  482. __xw = int(self.shape_x*self.scale/255)
  483. __yw = int(self.shape_y*self.scale/255)
  484. #xx ,yy = (370,235)
  485. xx = self.shape_x #= xx
  486. yy = self.shape_y #= yy
  487. try:
  488. xx ,yy = self.im.get_size()[:2]
  489. self.shape_x = xx
  490. self.shape_y = yy
  491. except AttributeError as e:
  492. pass
  493. xx = int(xx*self.scale/255)
  494. yy = int(yy*self.scale/255)
  495. __xw = int(xx) #*self.scale/255)
  496. __yw = int(yy) #*self.scale/255)
  497. yellow = [105,50,0]
  498. yellow[0] = int(yellow[0]*self.dim/255)
  499. yellow[1] = int(yellow[1]*self.dim/255)
  500. yellow[2] = int(yellow[2]*self.dim/255)
  501. if self.fname.startswith("cam_"):
  502. pass
  503. elif 1: #corner left up
  504. p1 = [self.x+2,self.y+2]
  505. p2 = [self.x+__xw-4,self.y+__yw-4]
  506. p3 = [self.x+__xw-4,self.y+2]
  507. p4 = [self.x+2,self.y+__yw-4]
  508. p1 = [self.x,self.y]
  509. p2 = [self.x+__xw,self.y+__yw]
  510. p3 = [self.x+__xw,self.y]
  511. p4 = [self.x,self.y+__yw]
  512. hx=int(xx/2)
  513. hy=int(yy/2)
  514. p1 = [self.x-hx,self.y-hy]
  515. p2 = [self.x+__xw-hx,self.y+__yw-hy]
  516. p3 = [self.x+__xw-hx,self.y-hy]
  517. p4 = [self.x-hx,self.y+__yw-hy]
  518. pygame.draw.rect(wn,yellow ,[p1[0] ,p1[1] ,__xw ,__yw])
  519. pygame.draw.rect(wn,[25,20,20],[p1[0]+1,p1[1]+1,__xw-2,__yw-2])
  520. pygame.draw.line(wn,yellow ,p1 ,p2)
  521. pygame.draw.line(wn,yellow ,p3 ,p4)
  522. if 0: #corner right down
  523. pygame.draw.rect(wn,yellow,[self.x-__xw,self.y-__yw,__xw,__yw])
  524. pygame.draw.rect(wn,[25,20,20],[self.x+1-__xw,self.y+1-__yw,__xw-2,__yw-2])
  525. pygame.draw.line(wn,yellow,[self.x+2-__xw,self.y+2-__yw],[self.x+__xw-4-__xw,self.y+__yw-4-__yw])
  526. pygame.draw.line(wn,yellow,[self.x+__xw-4-__xw,self.y+2-__yw],[self.x+2-__xw,self.y+__yw-4-__yw])
  527. pz = 0
  528. if self.success and wn and self.im: # is not None:
  529. xx ,yy = self.im.get_size()[:2]
  530. if self.fname.startswith("cam_"):
  531. #wn.blit(self.im, (int(self.x-xx/2), int(self.y))) # corner center-top
  532. #wn.blit(self.im, (int(self.x-xx/2), int(self.y-yy))) # corner center-bottom
  533. wn.blit(self.im, (int(self.x-xx/2), int(self.y-yy))) # corner center-bottom
  534. else:
  535. wn.blit(self.im, (int(self.x-xx/2), int(self.y-yy/2)))
  536. def overlay(self,wn=None,mode="x"):
  537. # overlay
  538. pygame.draw.rect(wn,[255,200,0],[5,MAIN_SIZE[1]-(self._id+1)*35,300,28])
  539. font15 = pygame.font.SysFont("freemonobold",17)
  540. pz = 0
  541. if self.end:
  542. rgb = [ 100,255,100]
  543. else:
  544. rgb = [255,100,0]
  545. pygame.draw.rect(wn,rgb,[220,MAIN_SIZE[1]-(self._id+1)*35,80,13])
  546. _line = "error no _line"
  547. _line ="FPS:{} F:{:05} von {:05} sec:{:0.02f} von {:0.02f}"
  548. if self.fps == 0: # check if div zerro
  549. _line = _line.format(self.fps,int(self.pos),len(self.buffer),(-1),pz )
  550. else:
  551. pz = (len(self.buffer)/self.fps)
  552. _line = _line.format(self.fps,int(self.pos),len(self.buffer),(self.pos/self.fps),pz )
  553. fr = font15.render(_line ,1, (0,0,0))
  554. wn.blit(fr,(10,MAIN_SIZE[1]-(self._id+1)*35))
  555. if self._run:
  556. mode = "run"
  557. else:
  558. mode = "pause"
  559. fr = font15.render(" {} {} >:{} ".format(self._id+1,self._video_nr,mode) ,1, (0,0,0))
  560. wn.blit(fr,(3,MAIN_SIZE[1]-(self._id+1)*35+15))
  561. fr = font15.render("{}".format(self.fname) ,1, (0,0,0))
  562. wn.blit(fr,(70,MAIN_SIZE[1]-(self._id+1)*35+15))
  563. Vopen = Vopen
  564. VIDEO = []
  565. videoplayer=[]
  566. cv2 = None
  567. FileVideoStream = None
  568. _vid = 0
  569. if type(options.videoplayer) is str:
  570. try:
  571. import cv2
  572. except Exception as e:
  573. print("Except Import:",e)
  574. try:
  575. # faster video reading ... ???
  576. from imutils.video import FileVideoStream
  577. except Exception as e:
  578. print("Except Import:",e)
  579. max_videoplayer = 4
  580. dmx_start = options.videoplayer.split(",")
  581. for cdmx in dmx_start:
  582. if len(videoplayer) > max_videoplayer:
  583. print("-- videoplayer max count {} !! break".format(max_videoplayer))
  584. break
  585. print("-- videoplayer dmx:",cdmx)
  586. try:
  587. cdmx = int(cdmx)
  588. videoplayer.append( Vopen(cdmx,_id=_vid) )
  589. _vid += 1
  590. _tmp = {"DMX":cdmx,"DIM":0,"PAN":127,"TILT":127
  591. ,"CONTROL":0,"SEC":10,"VIDEO":"3"
  592. ,"RED":255,"GREEN":255,"BLUE":255
  593. ,"_time":time.time()
  594. ,"_RUN":0,"_SEC":">{}<".format(cdmx)
  595. }
  596. VIDEO.append(_tmp)
  597. except Exception as e:
  598. print("EXCEPTION COUNTER INIT ",cdmx)
  599. def loop_videoplayer():
  600. while 1:
  601. _videoplayer = videoplayer[:]
  602. #print(".")
  603. ok = 0
  604. for i in _videoplayer: #.append( Vopen(cdmx,_id=_vid) )
  605. try:
  606. r = i._read() # read next frame from file
  607. if r:
  608. ok = 1
  609. except Exception as e:
  610. print("EXCEPTION loop_videoplayer ",e)
  611. if ok == 0:
  612. time.sleep(0.1)
  613. else:
  614. time.sleep(0.005)
  615. thread.start_new_thread(loop_videoplayer,())
  616. # ===== ======
  617. #self.fname = PLAYLIST[0]
  618. videoplayer2 = []
  619. def loop2_videoplayer():
  620. while 1:
  621. print()
  622. print()
  623. print()
  624. for i,v in enumerate(PLAYLIST):
  625. try:
  626. video1 = videoplayer2[i]
  627. video1.select_video(i)
  628. except:
  629. vi = Vopen(181,1)
  630. videoplayer2.append( vi )
  631. _videoplayer = videoplayer2[:]
  632. ok = 0
  633. j =0
  634. for i in _videoplayer: #.append( Vopen(cdmx,_id=_vid) )
  635. try:
  636. r = i._read() # read next frame from file
  637. if r:
  638. print(j,len(videoplayer2),i,len(i.buffer))
  639. ok = 1
  640. except Exception as e:
  641. print("EXCEPTION loop2_videoplayer ",e)
  642. time.sleep(0.002)
  643. j += 1
  644. p = 16
  645. block = [p,p]
  646. _x = 8
  647. _y = 8
  648. #HD = "0"
  649. if options.mode:
  650. try:
  651. HD = options.mode
  652. p,_x,_y = HD.split(",")
  653. _x = int(_x)
  654. _y = int(_y)
  655. p = int(p)
  656. block = [p,p]
  657. except Exception as e:
  658. print( "Exc",options.mode,e)
  659. # PARSE COMMANDLINE ARGUMENTS
  660. CFG_IN = {"name":"CFG_IN","x1":40,"y1":60,"x2":300,"y2":300 ,"w":300,"h":300}
  661. CFG_OUT = {"name":"CFG_OUT","x1":40,"y1":60,"x2":300,"y2":300 ,"w":300,"h":300,"on":0}
  662. #CFG_OUT2 = {"name":"CFG_OUT2","x1":p*8+142,"y1":60,"x2":300,"y2":300 ,"w":300,"h":300,"on":0}
  663. CFG_OUT2 = {"name":"CFG_OUT2","x1":p*8+(16*2)+8,"y1":60,"x2":300,"y2":300 ,"w":300,"h":300,"on":0}
  664. CFG_BLOCK = {"name":"CFG_BLOCK","size":16,"h-split":2,"v-split":2,"h-count":8,"v-count":8}
  665. if _x < 1:
  666. _x = 1
  667. if _y < 1:
  668. _y = 1
  669. CFG_BLOCK["h-count"] = _x
  670. CFG_BLOCK["v-count"] = _y # int(8*8/_x) #/_x+0.5) #_y
  671. CFG_BLOCK["size"] = p
  672. print( [options.xsplit])
  673. print( [options.ysplit])
  674. try:
  675. if options.xsplit:
  676. CFG_BLOCK["h-split"] = int(options.xsplit)
  677. if options.ysplit:
  678. CFG_BLOCK["v-split"] = int(options.ysplit)
  679. except Exception as e:
  680. print( "Exc",options.mode,e)
  681. print("HD",CFG_BLOCK["h-split"],CFG_BLOCK["v-split"])
  682. print("xy",_x,_y)
  683. print("++++++++++++++++++", p,_x,_y)
  684. _x2 = _x
  685. try:
  686. if options.XX:
  687. pass#_x2 = int(options.XX)
  688. except Exception as e:
  689. print( "Exc",options.mode,e)
  690. print("_x2 , -X",_x2)
  691. # ===== GUI =========
  692. import pygame
  693. import pygame.gfxdraw
  694. import pygame.font
  695. clock = pygame.time.Clock()
  696. os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,164)
  697. if options.win_pos:
  698. if "," in options.win_pos:
  699. win_pos = options.win_pos.split(",")
  700. try:
  701. WIN_POS = '%i,%i' % (int(win_pos[0]),int(win_pos[1]) )
  702. os.environ['SDL_VIDEO_WINDOW_POS'] = WIN_POS
  703. except Excetpion as e:
  704. print("win_pos",win_pos,e)
  705. os.environ['SDL_VIDEO_CENTERED'] = '0'
  706. pg = pygame
  707. pygame.init()
  708. pygame.mixer.quit()
  709. f = pygame.font.get_fonts()
  710. for i in f:
  711. if "mono" in i.lower():
  712. print(i)
  713. font = pygame.font.SysFont("freemonobold",22)
  714. font10 = pygame.font.SysFont("freemonobold",10)
  715. font12 = pygame.font.SysFont("freemonobold",12)
  716. font12l = pygame.font.SysFont("freemono",12)
  717. font15 = pygame.font.SysFont("freemonobold",15)
  718. font40 = pygame.font.SysFont("freemonobold",40)
  719. font80 = pygame.font.SysFont("freemonobold",70)
  720. #font = pygame.font.SysFont(None,30)
  721. fr = font.render("hallo" ,1, (200,0,255))
  722. def clean_path(path):
  723. _path = path[:]
  724. _path = _path.replace("/","-")
  725. _path = _path.replace(".","-")
  726. _path = _path.replace("\"","-")
  727. _path = _path.replace("'","-")
  728. return _path
  729. PIXEL_MAPPING = 0
  730. vpu_wall_conf_file = HOME+"/LibreLight/vpu_wall_conf.csv"
  731. grid_file = "/tmp/vpu_grid_hd.csv"
  732. text_file = HOME+"/LibreLight/vpu_text_hd.csv"
  733. play_list = "/tmp/vpu_playlist_hd.csv"
  734. play_list = HOME+"/LibreLight/video/" #.format(path)
  735. pm_wy = 0
  736. if options.pixel_mapping:
  737. PIXEL_MAPPING = 1
  738. CFG_OUT["on"] = 1
  739. path = options.pixel_mapping
  740. path = clean_path(path)
  741. grid_file = HOME+"/LibreLight/vpu_grid_hd{}.csv".format(path)
  742. if options.dual_vpu:
  743. grid_file = HOME+"/LibreLight/vpu_grid_dual{}.csv".format(path)
  744. text_file = HOME+"/LibreLight/vpu_text_hd{}.csv".format(path)
  745. play_list = HOME+"/LibreLight/vpu_playlist_hd{}.csv".format(path)
  746. play_list = HOME+"/LibreLight/video/" #.format(path)
  747. #_x = 8
  748. #_y = 8
  749. if options.dual_vpu:
  750. CFG_OUT2["on"] = 1
  751. print(" ",[options.pixel_mapping],"grid_file",grid_file)
  752. #grid_file = HOME+"/LibreLight/vpu_grid_hd.csv"
  753. MAIN_SIZE=(600,500)
  754. try:
  755. if _x < 8 and PIXEL_MAPPING >= 1:
  756. wx = 30+30+block[0] * 8
  757. CFG_IN["w"] = CFG_BLOCK["size"] * 8
  758. else:
  759. wx = 30+30+block[0] * _x
  760. wy = 40+40+block[1] * _y
  761. if type(options.videoplayer) is str:
  762. wy += 150 # video playlist
  763. MAIN_SIZE=(wx,wy)
  764. if PIXEL_MAPPING >= 1:
  765. pm_wy = 11*p #+ p*3
  766. CFG_IN["y1"] += 11*p
  767. if options.dual_vpu:
  768. if wx < p*16+155:
  769. wx = p*16+155
  770. MAIN_SIZE=(wx,wy+pm_wy)
  771. except Exception as e:
  772. print("Exception:",e)
  773. CFG_IN["w"] = CFG_BLOCK["size"] * CFG_BLOCK["h-count"]
  774. CFG_IN["h"] = CFG_BLOCK["size"] * CFG_BLOCK["v-count"]
  775. CFG_OUT["w"] = CFG_BLOCK["size"] * 8
  776. CFG_OUT["h"] = CFG_BLOCK["size"] * 8
  777. CFG_OUT2["w"] = CFG_BLOCK["size"] * 8
  778. CFG_OUT2["h"] = CFG_BLOCK["size"] * 8
  779. def CFG_CALC_P(CFG):
  780. CFG["x2"] = CFG["x1"]+CFG["w"]
  781. CFG["y2"] = CFG["y1"]+CFG["h"]
  782. CFG["p1"] = [CFG["x1"] ,CFG["y1"]]
  783. CFG["p2"] = [CFG["x2"] ,CFG["y2"]]
  784. print("CFG",CFG)
  785. # ?
  786. #CFG_IN["w"] = int(CFG_BLOCK["v-count"]-2) * CFG_BLOCK["size"]
  787. CFG_CALC_P(CFG_IN)
  788. CFG_CALC_P(CFG_OUT)
  789. CFG_CALC_P(CFG_OUT2)
  790. print("CFG_BLOCK",CFG_BLOCK)
  791. print()
  792. print()
  793. print()
  794. print()
  795. print()
  796. window = pygame.display.set_mode(MAIN_SIZE,pg.RESIZABLE)#,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  797. pg.display.set_caption('LibreLight VPU-{}'.format(options.title))
  798. class Fix():
  799. def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
  800. #print("Fix",_id)
  801. self._id = _id
  802. self.dmx = (_id-1) * ch +1 #dmx
  803. self.univ = univ
  804. self.ch = ch
  805. self.pos = pos
  806. self.rgb = [0,0,0]
  807. self.block = block #[10,10]
  808. self.x = pos[0]
  809. self.y = pos[1]
  810. self._x = 0
  811. self._y = 0
  812. self.strobo = time.time()
  813. self.bmp = 250
  814. self.sub_fix = []
  815. sub_block =[block[0]/CFG_BLOCK["h-split"],block[1]/CFG_BLOCK["v-split"]]
  816. if _id <= 0: #exit
  817. return
  818. spalte = (_id-1)%_y +1
  819. zeile = int((_id-1)/_x2) #+1
  820. add_row = _x*CFG_BLOCK["h-split"]*CFG_BLOCK["v-split"]
  821. #zeile 1
  822. sid = (_id-1)*2 + zeile*CFG_BLOCK["h-split"]*_x2
  823. sid = sid+1
  824. sub_pos= [pos[0]*block[0],pos[1]*block[1]]
  825. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  826. self.sub_fix.append(sub_fix)
  827. sid = sid+1
  828. sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]]
  829. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  830. self.sub_fix.append(sub_fix)
  831. #zeile 2
  832. sid = (_id-1)*2+1 + _x2*CFG_BLOCK["h-split"] + zeile*CFG_BLOCK["h-split"]*_x2 # int(add_row)
  833. sub_pos= [pos[0]*block[0],pos[1]*block[1]+block[1]/2]
  834. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  835. self.sub_fix.append(sub_fix)
  836. #sid = sid+1
  837. sid = sid+1
  838. sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]+block[1]/2]
  839. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  840. self.sub_fix.append(sub_fix)
  841. def __repr__(self):
  842. return "<Fix: {} {} {} {}>".format(id(self),self.x,self.y,self.dmx)
  843. def calc(self,data):
  844. _rgb = [0,255,0]
  845. return _rgb
  846. def sub_calc(self,data):
  847. _rgb = [0,255,0]
  848. for sub_fix in self.sub_fix:
  849. sub_fix.block = self.block[:]
  850. _rgb = sub_fix.dmx_calc(data)
  851. return _rgb
  852. def _calc(self,a,b):
  853. A = (self.pos[0])*self.block[0]
  854. B = (self.pos[1])*self.block[1]
  855. C = self.block[0]-a
  856. D = self.block[1]-b
  857. return A,B,C,D
  858. def POS(self,x=None,y=None,a=0,b=0):
  859. if type(x) is int:
  860. self._x=x
  861. if type(y) is int:
  862. self._y=y
  863. A,B,C,D = self._calc(a,b)
  864. return [self._x+A,self._y+B,C,D]
  865. def XXXsubPOS(self,x=0,y=0,a=0,b=0):
  866. __out = []
  867. for sub_fix in self.sub_fix:
  868. __out.append( sub_fix.POS(x,y,a,b) )
  869. return __out
  870. class SubFix():
  871. def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
  872. #print("Fix",_id)
  873. self._id = _id
  874. self.dmx = (_id-1) * ch +1 #dmx
  875. self.univ = univ
  876. self.ch = ch
  877. self.pos = pos
  878. self.rgb = [0,0,40]
  879. self.block = block #[10,10]
  880. self.x = pos[0]
  881. self.y = pos[1]
  882. self._x = 0
  883. self._y = 0
  884. self.strobo = time.time()
  885. self.bmp = 250
  886. def dmx_calc(self,data):
  887. #return [130,30,20]
  888. dmx_sub = [30]*10
  889. dmx = self.dmx -1
  890. _dmx_sub = []
  891. if self.dmx >= 0:
  892. dmx = rDMX(self.univ,self.dmx)-1
  893. if dmx+self.ch < len(data):
  894. _dmx_sub = data[dmx:dmx+self.ch]
  895. if _dmx_sub:
  896. dmx_sub = _dmx_sub
  897. dim = dmx_sub[0]/255
  898. r = dmx_sub[1]*dim
  899. g = dmx_sub[2]*dim
  900. b = dmx_sub[3]*dim
  901. r = int(r)
  902. g = int(g)
  903. b = int(b)
  904. self.rgb = [r,g,b]
  905. return self.rgb
  906. def _calc(self,a,b):
  907. A = (self.pos[0]) #+self.block[0]
  908. B = (self.pos[1]) #+self.block[1]
  909. C = self.block[0]-a
  910. D = self.block[1]-b
  911. return A,B,C,D
  912. def POS(self,x=None,y=None,a=0,b=0):
  913. if type(x) is int:
  914. self._x=x
  915. if type(y) is int:
  916. self._y=y
  917. A,B,C,D = self._calc(a,b)
  918. #if NR:
  919. # C-=1
  920. # D-=1
  921. return [int(self._x+A),int(self._y+B),int(C),int(D)]
  922. class POINTER():
  923. def __init__(self):
  924. self.pos = [0,0,0,0]
  925. self.on = 0
  926. self.rgb = [0,100,10]
  927. self._x = 0
  928. self._y = 0
  929. self.x = 0
  930. self.y = 0
  931. self.fix = Fix(0 ,[999,999],[16,16],0,0,0)
  932. def row_move(self,x,y):
  933. self._x = x
  934. self._y = y
  935. def move(self,pos):
  936. self.pos = pos
  937. self.on = 1
  938. def cross(self,x,y):
  939. self.x = x
  940. self.y = y
  941. def draw(self,x,y):
  942. pos = self.pos[:]
  943. #print("draw",x,y,pos)
  944. pos[0] += x
  945. pos[1] += y
  946. fix_x= self.fix.x
  947. fix_y= self.fix.y +y
  948. if 0:# self.on:
  949. pygame.draw.rect(window,self.rgb,pos)
  950. # mouse grid posision
  951. fr = font15.render("{}/{}".format(fix_x+1,fix_y) ,1, (200,200,200))
  952. _nr = fix_y * _x + fix_x +1
  953. fr = font15.render("{:02}".format(_nr ) ,1, (200,200,200))
  954. window.blit(fr,(pos[0]+2,pos[1]+2 ))
  955. window.blit(fr,(130,1))
  956. if 1:# lupe / looking-glass / lens
  957. __t = 60
  958. rgb=[255,0,0]
  959. pos=[400,400,160,160]
  960. draw_box_frame(window,rgb,pos,offset=1)
  961. r_sub = grab(x=self._x-__t/2,y=self._y-__t/2,w=__t,h=__t)
  962. if r_sub:
  963. r_sub = pygame.transform.scale(r_sub,(160,160))
  964. if r_sub: # target
  965. window.blit(r_sub, (400,400))
  966. #pos=[400+40,400+40,80,80]
  967. pos=[400+80,400+80,80,80]
  968. draw_box_frame(window,rgb,pos,offset=3)
  969. draw_box_frame(window,rgb,pos,offset=2)
  970. draw_box_frame(window,rgb,pos,offset=0)
  971. draw_box_frame(window,rgb,pos,offset=1)
  972. # fix pos
  973. #txt=str(pos) #"[0, 0, 0, 0]"
  974. #fr = font15.render(txt ,1, (200,200,200))
  975. #window.blit(fr,(10,1))
  976. # pointer
  977. fr = font15.render("X:{:03}".format(self._x) ,1, (200,200,200))
  978. window.blit(fr,(10,30))
  979. fr = font15.render("Y:{:03}".format(self._y) ,1, (200,200,200))
  980. window.blit(fr,(10,40))
  981. if 1: #self._x > 30 and self._y > 230:
  982. #from_x_min = 40 #320
  983. #from_y_min = 236
  984. # pointer
  985. _x = self._x-40
  986. _y = self._y-236
  987. rgb = [200,200,200]
  988. if _x < 0:
  989. rgb = [200,0,0]
  990. fr = font80.render("X:{:03}".format(_x) ,1, rgb)
  991. window.blit(fr,(200,400))
  992. rgb = [200,200,200]
  993. if _y < 0:
  994. rgb = [200,0,0]
  995. fr = font80.render("Y:{:03}".format(_y) ,1, rgb)
  996. window.blit(fr,(200,450))
  997. p=110
  998. # crosshair
  999. self.rgb = [0,0,200]
  1000. pygame.draw.line(window,self.rgb, (self.x-p,self.y) , (self.x-2,self.y),2 )
  1001. pygame.draw.line(window,self.rgb, (self.x,self.y-p) , (self.x,self.y-2),2 )
  1002. self.rgb = [0,200,0]
  1003. pygame.draw.line(window,self.rgb, (self.x+2,self.y) , (self.x+p,self.y),2 )
  1004. pygame.draw.line(window,self.rgb, (self.x,self.y+2) , (self.x,self.y+p),2 )
  1005. self.rgb = [200,0,0]
  1006. pointer = POINTER()
  1007. NR = 0
  1008. running = True
  1009. def event():
  1010. global NR,running
  1011. for event in pygame.event.get():
  1012. #print(event.dict)
  1013. _button = None
  1014. if "button" in event.dict:
  1015. _button = event.dict["button"]
  1016. _state = None
  1017. if "state" in event.dict:
  1018. _state = event.state
  1019. _key = None
  1020. if "key" in event.dict:
  1021. _key = event.key
  1022. _pos = None
  1023. if "pos" in event.dict:
  1024. _pos = event.pos
  1025. _type = None
  1026. if "type" in event.dict:
  1027. _type = event.type
  1028. _type = event.type
  1029. _mod = None
  1030. if "mod" in event.dict:
  1031. _mod = event.mod
  1032. if 0:
  1033. print( " ")
  1034. print( "{:.02f}".format( time.time() - START ))
  1035. print("button -",_button,end="\t| ")
  1036. #print("state -",_state)
  1037. print("pos -",_pos)
  1038. print("type -",_type, end="\t| ")
  1039. print("key -",_key)
  1040. print("mod -",_mod)
  1041. try:
  1042. if _type in [5,1025]:
  1043. if _button == 1:
  1044. NR += 1
  1045. if NR > 1:
  1046. NR = 0
  1047. if _button == 3:
  1048. NR -= 1
  1049. if NR < 0:
  1050. NR = 1
  1051. if _pos:
  1052. posA = _pos
  1053. fix = find_pix(_pos[0]-40,_pos[1]-60+pm_wy)
  1054. if fix:
  1055. #pos = fix.POS(40,60+pm_wy)
  1056. pos = fix.POS() #(CFG_IN["x1"],CFG_IN["y1"])#0,0) #+pm_wy)
  1057. rgb = [0,0,0]
  1058. pointer.move(pos)
  1059. pointer.fix = fix
  1060. else:
  1061. pointer.on = 0
  1062. pointer.row_move(_pos[0],_pos[1])
  1063. pointer.cross(_pos[0],_pos[1])
  1064. if event.type == pygame.VIDEORESIZE:
  1065. window = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)
  1066. except Exception as e:
  1067. print(e)
  1068. if event.type==pygame.QUIT:
  1069. print("QUIT")
  1070. running=False
  1071. #time.sleep(1)
  1072. sys.exit()
  1073. fps = 0
  1074. fps2 = 0
  1075. frame = 0
  1076. frame2 = 0
  1077. frame_t = time.time()
  1078. frame2_t = time.time()
  1079. IP = "yyy"
  1080. vplay1=0
  1081. vplay2=0
  1082. if options.videoplayer:
  1083. try:
  1084. t=options.videoplayer.split(",")
  1085. vplay1=t[0]
  1086. vplay2=t[1]
  1087. except:pass
  1088. def draw_overlay():
  1089. global fps,fps2
  1090. # oben
  1091. pygame.draw.rect(window,[0,0,50],[0,0,MAIN_SIZE[0],57]) # background
  1092. pygame.draw.rect(window,[0,0,50],[0,215,MAIN_SIZE[0],15]) # background
  1093. # links
  1094. pygame.draw.rect(window,[0,0,50],[0,50,35,400]) # background
  1095. # mitte
  1096. pygame.draw.rect(window,[0,0,50],[0,398,MAIN_SIZE[0],98]) # background
  1097. # unten
  1098. pygame.draw.rect(window,[0,0,50],[330,398+98,MAIN_SIZE[0],98]) # background
  1099. fr = font15.render("DMX-FPS: {}".format(fps) ,1, (200,0,255))
  1100. window.blit(fr,(10,2))
  1101. fr = font15.render("GUI-FPS : {}".format(fps2) ,1, (200,0,255))
  1102. window.blit(fr,(10,12))
  1103. #fr = font15.render("ip:{}".format(IP) ,1, (200,0,255))
  1104. #window.blit(fr,(100,2))
  1105. fr = font15.render("start-uni: {:}.xx dRGB".format(options.start_univ) ,1, (200,0,255))
  1106. window.blit(fr,(90,2))
  1107. fr = font15.render("a1_idim: 1.{:}".format(options.grid_a1_idim) ,1, (200,0,255))
  1108. window.blit(fr,(90,12))
  1109. fr = font15.render("a2_idim: 1.{:}".format(options.grid_a2_idim) ,1, (200,0,255))
  1110. window.blit(fr,(90,22))
  1111. fr = font15.render("gobo_ch1: 1.{:}".format(options.gobo_ch) ,1, (200,0,255))
  1112. window.blit(fr,(180,12))
  1113. fr = font15.render("gobo_ch2: 1.{:}".format(options.gobo_ch2) ,1, (200,0,255))
  1114. window.blit(fr,(180,22))
  1115. fr = font15.render("v-play1: 1.{:}".format(vplay1) ,1, (200,0,255))
  1116. window.blit(fr,(270,12))
  1117. fr = font15.render("v-play2: 1.{:}".format(vplay2) ,1, (200,0,255))
  1118. window.blit(fr,(270,22))
  1119. try:
  1120. global pointer
  1121. # pointer
  1122. fr = font15.render("X:{:03}".format(pointer._x) ,1, (200,200,200))
  1123. window.blit(fr,(10,30))
  1124. fr = font15.render("Y:{:03}".format(pointer._y) ,1, (200,200,200))
  1125. window.blit(fr,(10,40))
  1126. except Exception as e:
  1127. print("Overlay err:",e)
  1128. def draw_box_frame(window,rgb,pos,offset=0):
  1129. p1 = [pos[0],pos[1]]
  1130. p2 = [pos[0]+pos[2],pos[1]+pos[3]]
  1131. o = offset
  1132. _p1 = [p1[0]-o,p1[1]-o]
  1133. _p2 = [p1[0]-o,p2[1]+o]
  1134. pygame.draw.line(window,rgb,_p1,_p2) # left
  1135. _p1 = [p2[0]+o,p2[1]+o]
  1136. pygame.draw.line(window,rgb,_p1,_p2) # bottom
  1137. _p2 = [p2[0]+o,p1[1]-o]
  1138. pygame.draw.line(window,rgb,_p1,_p2) # right
  1139. _p1 = [p1[0]-o,p1[1]-o]
  1140. pygame.draw.line(window,rgb,_p1,_p2) # top
  1141. def draw_frame(window,rgb,p1,p2,offset=0):
  1142. o = offset
  1143. _p1 = [p1[0]-o,p1[1]-o]
  1144. _p2 = [p1[0]-o,p2[1]+o]
  1145. #pygame.draw.line(window,rgb,_p1,_p2) # left
  1146. _p1 = [p2[0]+o,p2[1]+o]
  1147. pygame.draw.line(window,rgb,_p1,_p2) # bottom
  1148. _p2 = [p2[0]+o,p1[1]-o]
  1149. #pygame.draw.line(window,rgb,_p1,_p2) # right
  1150. _p1 = [p1[0]-o,p1[1]-o]
  1151. pygame.draw.line(window,rgb,_p1,_p2) # top
  1152. def calc_fps():
  1153. global fps,frame,frame_t
  1154. t = time.time()
  1155. if frame_t+1 < t:
  1156. fps = frame #frame_t- t #frame
  1157. frame = 1
  1158. frame_t = time.time()
  1159. def calc_fps2():
  1160. global fps2,frame2,frame2_t
  1161. t = time.time()
  1162. if frame2_t+0.1 < t:
  1163. fps2 = frame2*10 #frame_t- t #frame
  1164. frame2 = 1
  1165. frame2_t = t #time.time()
  1166. TEXT_BLOCK = []
  1167. def _create_text_block():
  1168. print("======== CREATE NEW TEXT FILE !!",text_file)
  1169. f = open(text_file,"w")
  1170. for i in range(10):
  1171. f.write("TEXT {}\n".format(i+1))
  1172. f.close()
  1173. def open_text_block():
  1174. print("======== OPEN TEXT FILE !!",text_file)
  1175. _lines = []
  1176. try:
  1177. f = open(text_file,"r")
  1178. _lines = f.readlines()
  1179. f.close()
  1180. except FileNotFoundError as e:
  1181. print("TEXT",e)
  1182. _create_text_block()
  1183. if len(_lines) <= 0:
  1184. _create_text_block()
  1185. lines = []
  1186. for l in _lines:
  1187. #print(">> ",l.strip())
  1188. lines.append(l.strip())
  1189. if len(lines) <= 10:
  1190. for i in range(10-len(lines)):
  1191. lines.append("LINE ERROR")
  1192. return lines
  1193. TEXT_BLOCK = open_text_block()
  1194. TEXT_BLOCK_TIME = time.time()
  1195. # video playlist
  1196. PLAYLIST = []
  1197. def open_playlist():
  1198. print("======== OPEN PLAYLIST DIR !!",play_list)
  1199. if not os.path.isdir(play_list):
  1200. os.system("mkdir -p {}".format(play_list))
  1201. _lines = os.listdir(play_list)
  1202. _lines.sort()
  1203. lines = ['']*25
  1204. i=0
  1205. for l in _lines:
  1206. l = l.strip()
  1207. if "_" in l:
  1208. ll = l.split("_",1)
  1209. print(">> ",ll)
  1210. try:
  1211. lll = int(ll[0])
  1212. lines[lll] = l
  1213. except:pass
  1214. if len(lines) <= 10:
  1215. for i in range(10-len(lines)):
  1216. lines.append("")#"LINE ERROR")
  1217. return lines
  1218. PLAYLIST_TIME = time.time()
  1219. PLAYLIST = open_playlist()
  1220. # ===== GUI =========
  1221. def draw_circle(surface,color, pos, radius):
  1222. x,y=pos
  1223. pygame.gfxdraw.aacircle(surface, int(x), int(y), radius-1, color)
  1224. pygame.gfxdraw.filled_circle(surface, int(x), int(y), radius-1, color)
  1225. def rDMX(univ,dmx):
  1226. return univ*512+dmx
  1227. def generate_grid(mapping=0):
  1228. _log = []
  1229. #if PIXEL_MAPPING:
  1230. # log = open(grid_file,"w")
  1231. head = "i,univ,dmx,x,y,ch\n"
  1232. head = "i,univ,dmx,ch\n"
  1233. head = "univ,dmx,x,y,ch\n"
  1234. head = "nr,id,info\n"
  1235. print("csv:",head)
  1236. _log.append(head)
  1237. dmx = 1-1
  1238. ch = 4
  1239. y=0
  1240. x=0
  1241. for i in range((_y)*(_x)):
  1242. #if x > _x and i%_x == 0:
  1243. if x > 8 and i%8 == 0:
  1244. #print("--> -->")
  1245. x=0
  1246. y+=1
  1247. _univ = int(dmx/512)
  1248. _dmx = dmx - (_univ)*512
  1249. pos=[x,y]
  1250. line="{},{},x\n".format(i+1,i+1)
  1251. _log.append(line)
  1252. dmx += ch
  1253. x+=1
  1254. if mapping and PIXEL_MAPPING:
  1255. print("CREATE NEW PIXELMAP FILE !!",grid_file)
  1256. log = open(grid_file,"w")
  1257. log.writelines(_log)
  1258. log.close()
  1259. return _log[:] #GRID
  1260. def init_grid(mapping=0,_x=4,_y=4,_xp=0,_yp=0,start=0,name="init_gird"):
  1261. if mapping and PIXEL_MAPPING:
  1262. try:
  1263. log = open(grid_file,"r")
  1264. except:
  1265. generate_grid(mapping=mapping)
  1266. log = open(grid_file,"r")
  1267. lines = log.readlines()
  1268. else:
  1269. lines = generate_grid()
  1270. GRID = []
  1271. y=0
  1272. x=0
  1273. print("CSV header",[lines[0]],[PIXEL_MAPPING,"len:",len(lines),"start:",start,name])
  1274. for i,line in enumerate(lines[1+start:]): #exclude first line
  1275. #print("rcsv",[line])
  1276. line = line.strip()
  1277. line = line.split(",") # csv
  1278. if i >= _x and i%_x == 0:
  1279. x=0
  1280. y+=1
  1281. if y >= _y:
  1282. break
  1283. _id = int(line[1])
  1284. pos = [x+_xp,y+_yp]
  1285. f = Fix(_id,pos,block) #pos,univ,dmx,ch)
  1286. GRID.append(f)
  1287. x+=1
  1288. return GRID
  1289. def find_pix(x,y):
  1290. global GRID
  1291. for fix in GRID:
  1292. X = 0
  1293. Y = 0
  1294. pos = fix.POS()
  1295. if x > pos[0] and x < pos[0]+pos[2]:
  1296. X = 1
  1297. if y > pos[1] and y < pos[1]+pos[3]:
  1298. Y = 1
  1299. if X and Y:
  1300. return fix
  1301. GRID = []
  1302. GRID_A = []
  1303. NR = 0
  1304. START_UNIV=2
  1305. if options.start_univ:
  1306. try:
  1307. START_UNIV=int(options.start_univ)
  1308. except Exception as e:
  1309. print("Exception START UNIV",e)
  1310. gobo_ch=1
  1311. if options.gobo_ch:
  1312. try:
  1313. gobo_ch=int(options.gobo_ch)
  1314. except Exception as e:
  1315. print("Exception gobo_ch",e)
  1316. if gobo_ch <= 0:
  1317. gobo_ch = 1
  1318. def draw_box(pos1,pos2,color=[128,128,128],text=1):
  1319. color = [200,0,0,127]
  1320. if text:
  1321. fr = font15.render("A" ,1, (200,200,200))
  1322. window.blit(fr,pos1)
  1323. fr = font15.render("B" ,1, (200,200,200))
  1324. window.blit(fr,[pos2[0]-10,pos2[1]-10])
  1325. # h unten
  1326. _pos1 = [pos1[0],pos2[1]]
  1327. _pos2 = [pos2[0],pos2[1]]
  1328. pygame.draw.aaline(window,color,_pos1,_pos2,1)
  1329. color = [255,255,0,127]
  1330. # h rechts
  1331. _pos1 = [pos2[0],pos1[1]]
  1332. _pos2 = [pos2[0],pos2[1]]
  1333. pygame.draw.aaline(window,color,_pos1,_pos2,1)
  1334. color = [0,200,0,127]
  1335. # h links
  1336. _pos1 = [pos1[0],pos1[1]]
  1337. _pos2 = [pos1[0],pos2[1]]
  1338. pygame.draw.aaline(window,color,_pos1,_pos2,1)
  1339. color = [0,0,200,127]
  1340. # h oben
  1341. _pos1 = [pos1[0],pos1[1]]
  1342. _pos2 = [pos2[0],pos1[1]]
  1343. pygame.draw.aaline(window,color,_pos1,_pos2,1)
  1344. def grab(x=55,y=55,w=60,h=60):
  1345. crop = None
  1346. rect = pygame.Rect(x, y, w, h)
  1347. try:
  1348. sub = window.subsurface(rect)
  1349. crop = pygame.Surface((w,h))
  1350. crop.blit(sub, (0,0))
  1351. except ValueError as e:
  1352. pass
  1353. return crop
  1354. vpu_wall_txt="""---,quelle,,---,ziel,---,---
  1355. out,x,y,ang,row,col,info
  1356. Wall1,0,0,0,1,1,
  1357. Wall1,0,0,0,2,2,
  1358. Wall1,0,0,0,3,3,
  1359. Wall1,0,0,0,4,4,
  1360. Wall1,0,0,0,5,5,
  1361. Wall1,0,0,0,6,6,
  1362. Wall1,0,0,0,7,7,
  1363. ,,,,,,
  1364. Wall2,0,0,0,4,1,----
  1365. Wall2,0,0,0,5,2,
  1366. Wall2,4,4,0,6,3,
  1367. Wall2,0,0,0,7,4,
  1368. Wall2,0,0,0,8,5,
  1369. Wall2,0,0,0,9,6,
  1370. ,,,,,,
  1371. ,,,,,,
  1372. Wall3,64,48,0,12,1,----
  1373. Wall3,64,64,0,12,2,
  1374. Wall3,64,80,0,12,3,
  1375. Wall3,64,96,0,12,4,
  1376. Wall3,64,112,0,12,5,
  1377. Wall3,64,128,0,12,6,"""
  1378. def create_vpu_wall_conf():
  1379. f=open(vpu_wall_conf_file,"w")
  1380. f.write(vpu_wall_txt)
  1381. f.close()
  1382. print("CREATE VPU CONFIG !")
  1383. wall_data = []
  1384. _last_wall_config_time = time.time()
  1385. def read_wall_pix(init=0):
  1386. global _last_wall_config_time
  1387. global wall_data, NR
  1388. grid = []
  1389. #if not NR and init==0:
  1390. # return
  1391. ok = 0
  1392. if init:
  1393. ok = 1
  1394. if NR:
  1395. if time.time()-_last_wall_config_time > 3:
  1396. ok = 1
  1397. else:
  1398. if time.time()-_last_wall_config_time > 10:
  1399. ok = 1
  1400. if not ok:
  1401. return
  1402. _last_wall_config_time = time.time()
  1403. if not os.path.isfile(vpu_wall_conf_file):
  1404. create_vpu_wall_conf()
  1405. f=open(vpu_wall_conf_file,"r")
  1406. lines = f.readlines()
  1407. for i,line in enumerate(lines):
  1408. line = line.strip()
  1409. if not line:
  1410. continue
  1411. line = line.split(",")
  1412. if not line[0]:
  1413. continue
  1414. #print(i,line)
  1415. if len(line) >= 3:
  1416. _l = []
  1417. for i in line:
  1418. try:
  1419. _l.append(int(i))
  1420. except Exception as e:
  1421. _l.append(i)
  1422. grid.append(_l)
  1423. for i,v in enumerate(grid):
  1424. print(i,v)
  1425. wall_data = grid
  1426. read_wall_pix(init=1)
  1427. def reshape2(GRID,GRID_OUT,_x,_y,name="GRID_Z"):
  1428. _w = 16
  1429. _h = 16
  1430. from_x_min = 40 #320
  1431. from_y_min = 236
  1432. target_x = 40 # min
  1433. target_y = 60 # min
  1434. ang=0
  1435. #read_block_pix()
  1436. read_wall_pix()
  1437. _wall_data = wall_data[:]
  1438. for i,_wall in enumerate(_wall_data):
  1439. #print(_wall)
  1440. if len(_wall) <=6:
  1441. continue
  1442. try:
  1443. if type(_wall[1]) is str:
  1444. continue
  1445. if type(_wall[2]) is str:
  1446. continue
  1447. if type(_wall[3]) is str:
  1448. continue
  1449. if type(_wall[4]) is str:
  1450. continue
  1451. if type(_wall[5]) is str:
  1452. continue
  1453. from_x=from_x_min+_wall[1]#*_w
  1454. from_y=from_y_min+_wall[2]#*_h
  1455. _a= _wall[3]
  1456. ang=0
  1457. if _a < 0:
  1458. ang=0
  1459. elif _a > 0 and _a <= 90:
  1460. ang = 90
  1461. elif _a > 90 and _a <= 180:
  1462. ang = 180
  1463. elif _a > 180 and _a <= 270:
  1464. ang = 270
  1465. target_x=40+(_wall[4]-1)*_w
  1466. target_y=60+(_wall[5]-1)*_h
  1467. sub = grab(from_x,from_y,_w,_h)
  1468. #draw_box_frame(window,[0,40,0],[from_x+x,from_y+y,_w,_h])
  1469. if sub:
  1470. sub = pygame.transform.rotate(sub,ang)
  1471. window.blit(sub,(target_x,target_y))
  1472. except Exception as e:
  1473. print(" ",_wall)
  1474. print("WALL err:",e)
  1475. def reshape(GRID,GRID_OUT,_x,_y,name="GRID_Z"):
  1476. """reshape LED-WALL Block/Pixel mapping"""
  1477. if PIXEL_MAPPING <= 0:
  1478. return None
  1479. x = _x
  1480. y = _y
  1481. i = 0
  1482. counter = 0
  1483. z=0
  1484. x_min = 99999
  1485. x_max = 0
  1486. y_min = 99999
  1487. y_max = 0
  1488. pos= [0,0]
  1489. pos[0] = _x+p*3 #+10
  1490. pos[1] = p*8+65 #-10 #_y+p*8+80
  1491. tmp_font = pygame.font.SysFont("freemonobold",int(p*0.8))
  1492. #fr = tmp_font.render("OUTPUT: "+str(name) ,1, (255,255,255))
  1493. #fr_r = fr.get_rect(center=(int(wx/2),int(0+pm_wy-p*0-10)))
  1494. #window.blit(fr,pos)
  1495. fr = tmp_font.render("INPUT" ,1, (255,255,255))
  1496. fr_r = fr.get_rect(center=(int(wx/2),int(60+pm_wy-p/2)))
  1497. window.blit(fr,fr_r)
  1498. j = 0
  1499. for fix in GRID_OUT:
  1500. if j >= 64:
  1501. break
  1502. j+=1
  1503. ii = i
  1504. #pos = fix.POS(40,60)
  1505. pos = fix.POS() #(0,0)
  1506. rgb = fix.rgb
  1507. pos[0]+=_x
  1508. pos[1]+=_y
  1509. # green
  1510. pygame.draw.rect(window,[0,40,0],pos)
  1511. xposs = [] #None #pos[:]
  1512. for fix2 in GRID:
  1513. if fix._id == fix2._id:
  1514. #_xposs = fix2.POS(40,60)
  1515. #_xposs = fix2.POS(0,0)#_x,_y)
  1516. _xposs = fix2.POS() #(CFG_IN["x1"],CFG_IN["y1"])
  1517. xposs.append( _xposs) #fix2.POS(40,60) )
  1518. # ToDo
  1519. #sub = grab(10,10,60,60)
  1520. #sub = pygame.transform.rotate(sub,90)
  1521. #wn.blit(sub, (500,10))
  1522. for xpos in xposs:
  1523. #sub = grab(xpos[0],xpos[1]+pm_wy,xpos[2],xpos[3])
  1524. sub = grab(xpos[0],xpos[1],xpos[2],xpos[3])
  1525. if NR:
  1526. pygame.draw.rect(window,[255,0,255],xpos,1) # frame on grab area
  1527. if sub:
  1528. window.blit(sub, (pos[0]+z,pos[1]+z))
  1529. else:
  1530. # red
  1531. pygame.draw.rect(window,[40,0,0],pos) #[x+pos[0]+2+z,y+pos[1]+2+z-pm_wy,12,9])
  1532. if xpos[0] < x_min:
  1533. x_min = xpos[0]
  1534. if xpos[0] > x_max:
  1535. x_max += xpos[2]
  1536. if xpos[1] < y_min:
  1537. y_min = xpos[1]
  1538. if xpos[1] > x_max:
  1539. y_max += xpos[3]
  1540. # DRAW FIX NUMBER on TOP
  1541. #apos = fix.POS(40,60)#+pm_wy)
  1542. apos = fix.POS() #0,0)#+pm_wy)
  1543. apos[0]+=_x
  1544. apos[1]+=_y
  1545. argb = fix.rgb
  1546. # overwrite number overlay
  1547. if NR:
  1548. pygame.draw.rect(window,[20,20,20],[apos[0],apos[1],12,8])
  1549. fix_id = fix._id
  1550. if fix_id > 8*8:
  1551. fix_id -= 8*8
  1552. if NR:# == 2: # sub fix_nr
  1553. if fix_id != i+1:
  1554. fr = font12.render("{:02}".format(fix._id) ,1, (255,255,0))
  1555. window.blit(fr,(apos[0],apos[1]))
  1556. else:
  1557. fr = font12.render("{:02}".format(fix._id) ,1, (100,100,255))
  1558. window.blit(fr,(apos[0],apos[1]))
  1559. i += 1
  1560. #print("--#")
  1561. # frame box
  1562. pos1= [x+x_min,y+x_min]
  1563. pos2= [x_max+x_min,y_min+y_max]
  1564. class Timer():
  1565. def __init__(self,start=120):
  1566. self.start = start
  1567. self.timer = self.start
  1568. self.timer_t = time.time()
  1569. def reset(self):
  1570. self.timer = self.start
  1571. def get(self):
  1572. self.timer -= time.time()-self.timer_t
  1573. self.timer_t = time.time()
  1574. if self.timer <= 0:
  1575. self.reset()
  1576. return self.timer
  1577. def reload_grid():
  1578. print("==== reload_grid")
  1579. global GRID
  1580. global GRID_A
  1581. try:
  1582. GRID = init_grid(_x=_x,_y=_y,name="GRID") #init_gird()
  1583. GRID_A = init_grid(_x=8,_y=16,mapping=1,name="GRID_A") #init_gird()
  1584. except Exception as e:
  1585. print("Except: grid re init",e)
  1586. VPU_TEXT = []
  1587. def load_vpu_text(nr=0):
  1588. txt = "NONE"
  1589. if len(VPU_TEXT) > nr:
  1590. txt = VPU_TEXT[0]
  1591. return txt
  1592. import string
  1593. def draw_kachel_nr(): #GRID,_x=0,_y=0):
  1594. if not NR:
  1595. return
  1596. n = 0
  1597. _max_row = 40
  1598. _y=0
  1599. for i in range(8): # ROW / ZEILEN -> ->
  1600. _x=0
  1601. for j in range(30): # COLUMS / SPALTEN | |
  1602. pygame.draw.rect(window,[10,20,10],[40+_x+2,60+_y+2,14,9]) #background
  1603. _j=j #string.ascii_uppercase[j]
  1604. fr = font12.render("{}:{}".format(_j+1,i+1) ,1, (200,200,55))
  1605. window.blit(fr,(40+_x+2,60+_y+2))
  1606. #fr = font12.render("{}".format(_j) ,1, (200,200,55))
  1607. #window.blit(fr,(40+_x+2,60+_y+2))
  1608. #fr = font12.render(":{}".format(i+1) ,1, (200,200,55))
  1609. #window.blit(fr,(40+_x+2+6,60+_y+2))
  1610. _x+=16 # pix
  1611. _y +=16 # pix
  1612. grid_counter = time.time()
  1613. def draw_counter(COUNTER):
  1614. for count in COUNTER:
  1615. cpan = 0
  1616. ctilt = 0
  1617. cr=255
  1618. cg=255
  1619. cb=255
  1620. csize=10
  1621. cdim=0
  1622. k = "DIM"
  1623. if k in count:
  1624. cdim = int(count[k])
  1625. k = "RED"
  1626. if k in count:
  1627. cr = int(count[k])
  1628. k = "GREEN"
  1629. if k in count:
  1630. cg = int(count[k])
  1631. k = "BLUE"
  1632. if k in count:
  1633. cb = int(count[k])
  1634. k = "SIZE"
  1635. if k in count:
  1636. csize = int(count[k]) #/60*p)
  1637. if csize < 5:
  1638. csize = 5
  1639. k = "PAN"
  1640. if k in count:
  1641. cpan = int(count[k])/255*(block[0] *(_x))
  1642. #cpan = int(cpan * 1.2)
  1643. cpan = int(cpan)
  1644. k = "TILT"
  1645. if k in count:
  1646. ctilt = int(count[k])/255*(block[1] *(_y))
  1647. #ctilt = int(cpan * 1.2)
  1648. ctilt = int(ctilt)
  1649. ddim = cdim/255
  1650. if "DIM" in count and count["DIM"] > 0:
  1651. tmp_font = pygame.font.SysFont("freemonobold",int(p/100*csize))
  1652. rgb =(int(cr*ddim),int(cg*ddim),int(cb*ddim),cdim)
  1653. _sec = count["_SEC"]
  1654. try:
  1655. _sec = int(count["_SEC"])
  1656. except:
  1657. pass
  1658. if type(_sec) is int:
  1659. #print(_sec)
  1660. if _sec <= 60:
  1661. fr = tmp_font.render("{:0}".format(_sec) ,1, rgb)
  1662. else:
  1663. _xx = time.strftime("%M:%S",time.localtime(_sec))
  1664. #print("_xx",_xx)
  1665. fr = tmp_font.render("{}".format(_xx) ,1, rgb)
  1666. else:
  1667. fr = tmp_font.render("{}".format((count["_SEC"])) ,1, rgb)
  1668. fr_r = fr.get_rect(center=(40+cpan-(block[0]),60+ctilt+pm_wy))
  1669. pygame.draw.rect(window,[0,0,0],fr_r)
  1670. window.blit(fr,fr_r)
  1671. class FADE():
  1672. def __init__(self,sec):
  1673. self.start = time.time()
  1674. self.sec = sec
  1675. self.val
  1676. def next(self):
  1677. pass
  1678. def draw_video(VIDEO):
  1679. global videplayer
  1680. i = 0
  1681. # set DMX-VALUE to videoplayer Object
  1682. for count in VIDEO:
  1683. cpan = 0
  1684. ctilt = 0
  1685. cr=255
  1686. cg=255
  1687. cb=255
  1688. csize=10
  1689. cang=0
  1690. cdim=0
  1691. video1 = videoplayer[i]
  1692. k = "VIDEO"
  1693. if k in count:
  1694. #video1.select_video(count[k])
  1695. play_nr = int(count[k]/10)
  1696. if play_nr != video1._video_nr:
  1697. print( "+ + + + + + + + + + +", play_nr , video1._video_nr ,str(video1))
  1698. _vid = video1._id
  1699. _cdmx = video1.dmx
  1700. del_video1 = video1
  1701. video1 = Vopen(cdmx,_id=_vid)
  1702. video1.select_video(count[k])
  1703. videoplayer[i] = video1
  1704. del_video1._del()
  1705. del del_video1
  1706. k = "DIM"
  1707. if k in count:
  1708. cdim = int(count[k])
  1709. video1.dim = cdim
  1710. #if i == 0:
  1711. # print(i,cdim)
  1712. k = "ANG"
  1713. if k in count:
  1714. cang = int(count[k])
  1715. k = "SIZE"
  1716. if k in count:
  1717. csize = int(count[k]/16*p)
  1718. if csize < 5:
  1719. csize = 5
  1720. k = "PAN"
  1721. cpan_max = block[0] *(_x) #+block[0]
  1722. if k in count:
  1723. if 0:#video1.fname.startswith("cam_"):
  1724. cpan = int(count[k]) #/ 255*cpan_max
  1725. else:
  1726. cpan = int(count[k]) / 255*cpan_max
  1727. cpan = int(cpan)
  1728. k = "TILT"
  1729. ctilt_max = block[1] *(_y) #+block[1]
  1730. if k in count:
  1731. ctilt = int(count[k]) / 255*ctilt_max
  1732. ctilt = int(ctilt)
  1733. k = "_reset"
  1734. if k in count:
  1735. if count[k]:
  1736. count[k] = 0
  1737. video1.restart()
  1738. k = "_RUN"
  1739. if k in count:
  1740. video1._run = count[k]
  1741. video1.pos
  1742. #video1.x=40+0+cpan
  1743. #video1.y=60+0+pm_wy+ctilt
  1744. video1.x=CFG_IN["x1"]+cpan
  1745. video1.y=CFG_IN["y1"]+ctilt
  1746. video1.scale = int((csize))
  1747. video1.angle = int(360-(cang))
  1748. if cdim:
  1749. video1.next()
  1750. i += 1
  1751. # draw
  1752. i=0
  1753. for count in VIDEO:
  1754. video1 = videoplayer[i]
  1755. video1.draw(window) #,x=0,y=0)
  1756. i+=1
  1757. i=0
  1758. for count in VIDEO:
  1759. video1 = videoplayer[i]
  1760. video1.overlay(window,"run")
  1761. i += 1
  1762. def counter_dmx(COUNTER,dataA):
  1763. for count in COUNTER:
  1764. cDMX=count["DMX"]-1
  1765. try:
  1766. count["DIM"] = dataA[cDMX]
  1767. count["PAN"] = dataA[cDMX+1]
  1768. count["TILT"] = dataA[cDMX+2]
  1769. count["CONTROL"] = dataA[cDMX+3]
  1770. count["SIZE"] = dataA[cDMX+4]
  1771. count["SEC"] = dataA[cDMX+5]
  1772. count["RED"] = dataA[cDMX+6]
  1773. count["GREEN"] = dataA[cDMX+7]
  1774. count["BLUE"] = dataA[cDMX+8]
  1775. if count["CONTROL"] >= 10 and count["CONTROL"] < 20: # RESET COUNTER
  1776. count["_RUN"] = 0
  1777. count["_pause"] = 0
  1778. count["_time"] = time.time()
  1779. count["_start"] = int(count["SEC"])
  1780. count["_SEC"] = int(count["_start"])
  1781. if count["CONTROL"] >= 20 and count["CONTROL"] < 30: # PAUSE COUNTER
  1782. count["_RUN"] = 0
  1783. if count["CONTROL"] >= 30 and count["CONTROL"] < 40: # PLAY COUNTER
  1784. count["_RUN"] = 1
  1785. if count["_RUN"]:
  1786. try:
  1787. if count["_pause"] > 0:
  1788. count["_time"] += time.time()-count["_pause"]
  1789. count["_pause"] = 0
  1790. count["_SEC"] = int(count["_start"] - (time.time() - count["_time"]))
  1791. except Exception as e:
  1792. pass
  1793. else:
  1794. if count["_pause"] == 0:
  1795. count["_pause"] = time.time()
  1796. if type(count["_SEC"]) is int:
  1797. if count["_SEC"] < 0:
  1798. count["_SEC"] = 0
  1799. for ti in range(10):
  1800. #print(ti,(ti+6)*10)
  1801. if count["CONTROL"] >= (ti+6)*10 and count["CONTROL"] < (ti+7)*10:
  1802. count["_SEC"] = "----" #text 1
  1803. try:
  1804. count["_SEC"] = TEXT_BLOCK[ti]
  1805. except Exception as e:
  1806. pass
  1807. if count["CONTROL"] >= 250 and count["CONTROL"] < 256:
  1808. count["_SEC"] = "DMX:{}-{}".format(cDMX+1,cDMX+8+1)
  1809. except Exception as e:
  1810. print("EXC FUNC",e,count)
  1811. #print(count)
  1812. def video_dmx(VIDEO,dataA):
  1813. for count in VIDEO:
  1814. cDMX=count["DMX"]-1
  1815. try:
  1816. count["DIM"] = dataA[cDMX]
  1817. count["PAN"] = dataA[cDMX+1]
  1818. count["TILT"] = dataA[cDMX+2]
  1819. count["CONTROL"] = dataA[cDMX+3]
  1820. if count["CONTROL"] >= 10 and count["CONTROL"] < 20:
  1821. count["_reset"] = 1
  1822. if count["CONTROL"] >= 20 and count["CONTROL"] < 30:
  1823. if count["_RUN"] == 1:
  1824. print( "_RUN:0",count["DMX"]-1)
  1825. count["_RUN"] = 0
  1826. if count["CONTROL"] >= 30 and count["CONTROL"] < 40:
  1827. if count["_RUN"] == 0:
  1828. print( "_RUN:1",count["DMX"]-1)
  1829. count["_RUN"] = 1
  1830. count["SIZE"] = dataA[cDMX+4]#*2
  1831. count["SEC"] = dataA[cDMX+5]
  1832. #count["RED"] = dataA[cDMX+6]
  1833. count["VIDEO"] = dataA[cDMX+6]
  1834. #count["GREEN"] = dataA[cDMX+7]
  1835. count["ANG"] = (int(dataA[cDMX+7])/255*360)
  1836. #count["BLUE"] = dataA[cDMX+8]
  1837. except Exception as e:
  1838. print("VIDEOPLAYER EXCEPT FUNC",e,count)
  1839. #print(count)
  1840. def read_dmx_data(ip,ips):
  1841. ip = select_ip(ips,univ=START_UNIV)
  1842. IP = ip
  1843. data = read_dmx(ip)
  1844. ip = select_ip(ips,univ=START_UNIV+1)
  1845. data3 = read_dmx(ip)
  1846. data.extend(data3)
  1847. ip = select_ip(ips,univ=START_UNIV+2)
  1848. data3 = read_dmx(ip)
  1849. data.extend(data3)
  1850. ip = select_ip(ips,univ=START_UNIV+3)
  1851. data3 = read_dmx(ip)
  1852. data.extend(data3)
  1853. if options.dual_vpu:
  1854. ip = select_ip(ips,univ=START_UNIV+4)
  1855. data3 = read_dmx(ip)
  1856. data.extend(data3)
  1857. ip = select_ip(ips,univ=START_UNIV+5)
  1858. data3 = read_dmx(ip)
  1859. data.extend(data3)
  1860. return data
  1861. def set_pos(GRID,_x=0,_y=0):
  1862. for fix in GRID:
  1863. pos = fix.POS(_x,_y)#40,60+pm_wy)
  1864. for subfix in fix.sub_fix:
  1865. #subfix.dmc_calc(data)
  1866. spos = subfix.POS(_x,_y)
  1867. def draw_gobo(GRID,data,_x=0,_y=0):
  1868. i = 0
  1869. dmx = 1
  1870. h = 1
  1871. v = 1
  1872. for fix in GRID:
  1873. rgb = fix.rgb
  1874. pos = fix.POS() #CFG_IN["x1"],CFG_IN["y1"])
  1875. pygame.draw.rect(window,rgb,pos)
  1876. # DRAW SUB-FIXTURE
  1877. j = 0
  1878. for subfix in fix.sub_fix:#calc(data):
  1879. subfix.dmx_calc(data)
  1880. spos = subfix.POS() #_x,_y)#+pm_wy)
  1881. srgb = subfix.rgb
  1882. if FUNC > 10 and FUNC <= 20: # big dot
  1883. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1884. elif FUNC > 20 and FUNC <= 30:#small dot
  1885. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1886. elif FUNC > 30 and FUNC <= 40:#donut
  1887. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1888. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1889. elif FUNC > 40 and FUNC <= 50: # rec with hole
  1890. pygame.draw.rect(window,srgb,spos)
  1891. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1892. elif FUNC > 50 and FUNC <= 60: # rec with big hole
  1893. pygame.draw.rect(window,srgb,spos)
  1894. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1895. elif FUNC > 60 and FUNC <= 70: # rec with donat
  1896. pygame.draw.rect(window,srgb,spos)
  1897. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  1898. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1899. elif FUNC > 70 and FUNC <= 80: # rec boarder
  1900. pygame.draw.rect(window,srgb,[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1901. elif FUNC > 80 and FUNC <= 90: # rec big boarder
  1902. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1903. elif FUNC > 90 and FUNC <= 100: # rec thin line
  1904. pygame.draw.rect(window,srgb,spos)
  1905. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1906. elif FUNC > 100 and FUNC <= 110: # rec big line
  1907. pygame.draw.rect(window,srgb,spos)
  1908. pygame.draw.rect(window,[0,0,0],[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1909. elif FUNC > 110 and FUNC <= 120: # rec with dot
  1910. pygame.draw.rect(window,srgb,spos)
  1911. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  1912. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1913. elif FUNC > 120 and FUNC <= 130: # rec inline
  1914. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  1915. pygame.draw.rect(window,[0,0,0],[spos[0]+3,spos[1]+3,spos[2]-6,spos[3]-6])
  1916. elif FUNC > 130 and FUNC <= 140: # 3 dot (heart)
  1917. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)+2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1918. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)-2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  1919. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)+2),int(spos[3]/3.5))
  1920. else:
  1921. pygame.draw.rect(window,srgb,spos)
  1922. i += 1
  1923. def grid_label(GRID,_x=0,_y=0):
  1924. for fix in GRID:
  1925. #pos = fix.POS(_x,_y)
  1926. pos = fix.POS() #CFG_IN["x1"],CFG_IN["y1"])
  1927. rgb = fix.rgb
  1928. # draw row/col grid number
  1929. if pos[0] == 0:
  1930. fr = font12.render("{}".format(pos[1]+1) ,1, (200,200,200))
  1931. window.blit(fr,(10,pos[1]+3 ))
  1932. if pos[1] == 0:
  1933. fr = font12.render("{}".format(pos[0]+1) ,1, (200,200,200))
  1934. window.blit(fr,(pos[0]+2,35 ))
  1935. #pygame.draw.rect(window,rgb,pos)
  1936. def grid_sub_label(GRID,_x=0,_y=0):
  1937. h = 1
  1938. v = 1
  1939. for fix in GRID:
  1940. j = 0
  1941. #pos = fix.POS(_x,_y)
  1942. pos = fix.POS() #CFG_IN["x1"],CFG_IN["y1"])
  1943. for subfix in fix.sub_fix:
  1944. subfix.dmx_calc(data)
  1945. spos = subfix.POS() #(_x,_y)
  1946. srgb = subfix.rgb
  1947. # draw row/col grid number
  1948. if subfix.pos[0] == 0:
  1949. fr = font12.render("{}".format(v ) ,1, (200,200,200))
  1950. window.blit(fr,(25,spos[1] ))
  1951. v += 1
  1952. if subfix.pos[1] == 0:
  1953. fr = font12.render("{}".format(1) ,1, (200,200,200))
  1954. fr = font12.render("{}".format(h ) ,1, (200,200,200))
  1955. h+=1
  1956. window.blit(fr,(spos[0],50 ))
  1957. if p >= 40:
  1958. if NR:
  1959. fr = font15.render("{:02}".format(subfix._id) ,1, (250,200,5))
  1960. window.blit(fr,(spos[0]+2,spos[1]+10))
  1961. j += 1
  1962. def frame_area():
  1963. rgb = [255,255,0]
  1964. CFG = CFG_IN
  1965. p1 = CFG_IN["p1"]
  1966. p2 = CFG_IN["p2"]
  1967. draw_frame(window,rgb,p1,p2,offset=2)
  1968. rgb = [255,0,0]
  1969. #draw_frame(window,rgb,p1,p2,offset=4)
  1970. if CFG_OUT["on"]:
  1971. rgb = [255,0,0]
  1972. p1 = CFG_OUT["p1"]
  1973. p2 = CFG_OUT["p2"]
  1974. #pygame.draw.line(window,rgb,p1,p2)
  1975. draw_frame(window,rgb,p1,p2,offset=3)
  1976. if CFG_OUT2["on"]:
  1977. rgb = [255,0,0]
  1978. p1 = CFG_OUT2["p1"]
  1979. p2 = CFG_OUT2["p2"]
  1980. #pygame.draw.line(window,rgb,p1,p2)
  1981. draw_frame(window,rgb,p1,p2,offset=3)
  1982. ips=[]
  1983. dataA=[]
  1984. data=[]
  1985. def dmx_raw():
  1986. global frame
  1987. frame += 1
  1988. global ips,dataA,data
  1989. ips = read_index()
  1990. # ----
  1991. ip = select_ip(ips,univ=1) # univ 1 gobo
  1992. dataA = read_dmx(ip)
  1993. # ----
  1994. data = read_dmx_data(ip,ips)
  1995. if options.countdown:
  1996. counter_dmx(COUNTER,dataA)
  1997. if len(VIDEO) > 0:
  1998. video_dmx(VIDEO,dataA)
  1999. return ips,dataA,data
  2000. def dmx_loop():
  2001. while 1:
  2002. dmx_raw()
  2003. time.sleep(1/40) # fast high cpu
  2004. #time.sleep(1/25)
  2005. dmx_raw()
  2006. thread.start_new_thread(dmx_loop,())
  2007. def draw_output_label(CFG,value,name="GRID_XX"):
  2008. dim_raw = value
  2009. # GRID_A1_DIM_LABEL
  2010. fr = font15.render("Output:"+name,1, (255,255,255))
  2011. fr_r = fr.get_rect(center=(int(wx/2),int(0+pm_wy-p*0-10)))
  2012. window.blit(fr,(CFG["x1"],CFG["y2"]+5))
  2013. fr = font15.render("inv-dim: "+str(dim_raw) ,1, (255,255,255))
  2014. fr_r = fr.get_rect(center=(int(wx/2),int(0+pm_wy-p*0-10)))
  2015. window.blit(fr,(CFG["x1"],CFG["y2"]+15))
  2016. def GRID_DIM(dim,x,y):
  2017. try:
  2018. dim = int(grid_dim_v)
  2019. if dim > 255:
  2020. dim = 255
  2021. if dim <=0:
  2022. dim = 0
  2023. except:pass
  2024. dim_raw = dim*-1
  2025. s = pygame.Surface((p*8,p*8)) # the size of your rect
  2026. s.set_alpha(dim) # alpha level
  2027. s.fill((0,0,0)) # this fills the entire surface
  2028. window.blit(s, (x,y))
  2029. def GRID_A1_DIM():
  2030. # GRID_A1 DIM
  2031. if options.grid_a1_idim:
  2032. CFG=CFG_OUT
  2033. grid_dim_ch = int(options.grid_a1_idim)
  2034. grid_dim_v = dataA[grid_dim_ch-1]
  2035. dim=255
  2036. dim=grid_dim_v
  2037. dim=120
  2038. GRID_DIM(dim,x=CFG["x1"],y=CFG["y2"]-p*8)
  2039. draw_output_label(CFG,dim,name="GRID_A1_DIM")
  2040. def GRID_A2_DIM():
  2041. # GRID_A2 DIM
  2042. if options.grid_a2_idim:
  2043. CFG=CFG_OUT2
  2044. grid_dim_ch = int(options.grid_a2_idim)
  2045. grid_dim_v = dataA[grid_dim_ch-1]
  2046. dim=255
  2047. try:
  2048. dim = int(grid_dim_v)
  2049. if dim > 255:
  2050. dim = 255
  2051. if dim <=0:
  2052. dim = 0
  2053. except:pass
  2054. dim_raw = dim*-1
  2055. s = pygame.Surface((p*8,p*8)) # the size of your rect
  2056. s.set_alpha(dim) # alpha level
  2057. s.fill((0,0,0)) # this fills the entire surface
  2058. window.blit(s, (CFG["x1"],CFG["y2"]-p*8))
  2059. draw_output_label(CFG,dim_raw,name="GRID_A2_DIM")
  2060. t1 = Timer(143)
  2061. time.sleep(0.33)
  2062. t2 = Timer(11)
  2063. count_tilt = 0
  2064. def main():
  2065. global IP
  2066. global GRID
  2067. global GRID_A
  2068. global FUNC
  2069. global count_tilt
  2070. global TEXT_BLOCK
  2071. global TEXT_BLOCK_TIME
  2072. global PLAYLIST
  2073. global PLAYLIST_TIME
  2074. global dataA
  2075. global frame2
  2076. global runnung
  2077. reload_grid()
  2078. s=time.time()
  2079. r = ""
  2080. IP = "xx"
  2081. while running:
  2082. if TEXT_BLOCK_TIME+5 < time.time():
  2083. TEXT_BLOCK = open_text_block()
  2084. TEXT_BLOCK_TIME = time.time()
  2085. if PLAYLIST_TIME+6 < time.time():
  2086. PLAYLIST = open_playlist()
  2087. PLAYLIST_TIME = time.time()
  2088. pygame.display.flip()
  2089. set_pos(GRID,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2090. #set_pos(GRID,600,600)#_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2091. event()
  2092. window.fill((10,0,30))
  2093. calc_fps()
  2094. calc_fps2()
  2095. #draw_overlay()
  2096. # GRID loop
  2097. try:
  2098. FUNC = dataA[gobo_ch-1]
  2099. FUNC2 = FUNC
  2100. except Exception as e:
  2101. print("EXC FUNC",e)
  2102. #if int(time.time()) % 2: # BLINK
  2103. #set_gobo_pos(GRID,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2104. draw_gobo(GRID,data) #,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2105. #if int(time.time()) % 2: # BLINK
  2106. grid_label(GRID,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2107. #grid_sub_label(GRID) #,_x=CFG_IN["x1"],_y=CFG_IN["y1"])
  2108. if VIDEO:
  2109. draw_video(VIDEO)
  2110. if options.countdown:
  2111. draw_counter(COUNTER)
  2112. pygame.draw.rect(window,[5,5,5],[0,60,MAIN_SIZE[0],p*9]) # background
  2113. draw_overlay()
  2114. pointer.draw(0,pm_wy) #wy
  2115. spos = [0,0,0,0]
  2116. if PIXEL_MAPPING >= 1:
  2117. #try:
  2118. if options.dual_vpu:
  2119. GRID_X = GRID_A[8*8:]
  2120. xx = p*8
  2121. #reshape(GRID,GRID_X,CFG_OUT2["x1"],CFG_OUT2["y1"]-p*8,name="GRID_A2") #start pos
  2122. #except Exception as e:
  2123. # print("Exception 23123",e)
  2124. reshape2(GRID,GRID_A,CFG_OUT["x1"],CFG_OUT["y1"],name="GRID_A1") #start pos
  2125. #reshape(GRID,GRID_A,CFG_OUT["x1"],CFG_OUT["y1"],name="GRID_A1") #start pos
  2126. else:
  2127. pass #reshape(GRID,GRID_A,spos[0]+spos[2]+20,10) #start pos
  2128. frame_area()
  2129. # OUTPUT -> MAPING
  2130. draw_kachel_nr()
  2131. GRID_A1_DIM()
  2132. GRID_A2_DIM()
  2133. draw_overlay()
  2134. pointer.draw(0,pm_wy) #wy
  2135. pygame.display.flip()
  2136. clock.tick(25)
  2137. if 'SDL_VIDEO_WINDOW_POS' in os.environ:
  2138. del os.environ['SDL_VIDEO_WINDOW_POS'] #= '%i,%i' % (200,164)
  2139. frame2 += 1
  2140. if __name__ == "__main__":
  2141. main()