vpu_live4.py 70 KB

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