vpu_live.py 45 KB

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