vpu_live.py 45 KB

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