vpu_live4.py 75 KB

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