12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841 |
- import math
- import random
- import time
- import os
- import _thread as thread
- from optparse import OptionParser
- ...
- parser = OptionParser()
- parser.add_option("-m", "--mode", dest="mode",
- help="pixel mode pix,x,y --mode 40,10,8") #, metavar="FILE")
- parser.add_option("-X", "--XX", dest="XX", #default=1,
- help="x-split") #, metavar="FILE")
- parser.add_option("-x", "--xx", dest="xsplit", #default=1,
- help="x-split") #, metavar="FILE")
- parser.add_option("-y", "--yy", dest="ysplit",#default=1,
- help="y-split") #, metavar="FILE")
- parser.add_option("", "--start-univ", dest="start_univ",#default=1,
- help="set start-univers default=2") #, metavar="FILE")
- parser.add_option("", "--gobo-ch", dest="gobo_ch",#default=1,
- help="gobo ch univ on 1") #, metavar="FILE")
- #os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,164)
- parser.add_option("", "--win-pos", dest="win_pos",default="200,164",
- help="SDL_VIDEO_WINDOW_POS --win-pos=200,164") #, metavar="FILE")
- parser.add_option("", "--pixel-mapping", dest="pixel_mapping",default=0,
- help="pixel_mapping file/on --pixel-mapping=_x") #, metavar="FILE")
- parser.add_option("", "--countdown", dest="countdown",#default=1,
- help="enable countdown") #, metavar="FILE")
- parser.add_option("", "--videoplayer", dest="videoplayer",#default=1,
- help="enable videoplayer") #, metavar="FILE")
- #parser.add_option("-f", "--file", dest="filename",
- # help="write report to FILE", metavar="FILE")
- #parser.add_option("-q", "--quiet",
- # action="store_false", dest="verbose", default=True,
- # help="don't print status messages to stdout")
- (options, args) = parser.parse_args()
- for o in dir(options):
- if "_" in o:
- continue
- print(o,options.__getattribute__(o))
- START = time.time()
- # ===== ARTNET DMX =========
- import memcache
- mc = memcache.Client(['127.0.0.1:11211'], debug=0)
- def read_index():
- ips=mc.get("index")#cmd)
- if ips is None:
- ips = {}
- #for k,v in ips.items():
- # print(k,v)
- return ips
- def select_ip(ips, univ=2): # artnet univ
- _univ = ":{}".format(univ)
- for ip in ips: #high priority
- if "2.0.0" in ip and _univ in ip:
- return ip
- for ip in ips:
- if "ltp-out" in ip and _univ in ip:
- return ip
- FUNC = 0
- COUNTER = []
- if options.countdown:
-
- cdmx_start = options.countdown.split(",")
- for cdmx in cdmx_start:
- try:
- cdmx = int(cdmx)
- 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)})
- except Exception as e:
- print("EXCEPTION COUNTER INIT ",cdmx)
- def read_dmx(ip):
- global frame
- r = ""
- if ip:
- #t = int(math.sin(time.time() - s)*10)
- r = mc.get(ip) #"2.0.0.13:2")
- frame += 1
- rr = [0]*512
- for i,v in enumerate(r):
- try: #cleanup ltp-out to int
- v = int(v)
- rr[i] = v
- except:pass
- r = rr
- if not r:
- c = 0
- #time.sleep(0.1)
- r = [0] *512
- for i in range(12*8+1):
- dmx = i*4
- #print(dmx)
- r[dmx:dmx+4] = [255,10,10,40]
- return r
- # ===== ARTNET DMX =========
- PLAYLIST = []
- try:
- PLAYLIST = open_playlist()
- except:pass
- class Vopen():
- def __init__(self,dmx=None,_id=None):
- global PLAYLIST
- self._id = _id
- self.fpath = '/home/user/Downloads/'
- self.fpath = '/home/user/LibreLight/video/'
- self.fname = '' #'bbb_sunflower_480x320.mp4'
- #self.fname = 'no-video.mp4'
- try:
- self.fname = PLAYLIST[0]
- except Exception as e:
- print("Exception set video from PLAYLIST 5543:",e)
- self.fps = 0
- self.scale = 50 #%
- self.dmx=dmx
- self.dim = 0
- self.x = 0
- self.y = 0
- self.init_count = 0
- self.cap = None
- self.shape = [200,200]
- self.img = None
- self.success = 1
- self.cv2 = None
- self._run = 0
- self.end = 0
- self._video_nr = 0
- try:
- global cv2
- self.cv2 = cv2
- except:
- pass
- self.init()
- def init(self):
- print("---- ---- Vopen.init()",[self.fname,self._video_nr])
- print(PLAYLIST)
- self.time = 0
- self.t_delta = 0
- self.t_last = time.time()
- self.im = None
- self.pos = 0
- self.buffer = []
- self._init()
- self.init_count = 1
- def select_video(self,dmx_value):
- try:
- dmx_value = int(dmx_value/10)
- if self._video_nr != dmx_value:
- self._video_nr = dmx_value
- if self._video_nr < len(PLAYLIST):
- self.fname = str(PLAYLIST[self._video_nr])
- self.init()
- except Exception as e:
- print("Vopen.select_video()",dmx_value,e)
- def close_cap():
- print(dir(self.Rcap)) # = self.cv2.VideoCapture(self.fpath+self.fname)
- def _init(self):
- print(self)
- print("videoplayer.init()",self.fpath,self.fname)
- if not os.path.isfile(self.fpath+self.fname):
- print()
- print("video file does not exits !! >",self.fpath,self.fname)
- print()
- #exit()
-
- self.Rsuccess = 0
- if self.cv2:
- self.Rcap = self.cv2.VideoCapture(self.fpath+self.fname)
- self.Rsuccess = 1
- self._read()
- def _read(self):
- success = self.Rsuccess
- if success and self.fname:
- cap = self.Rcap
- _break = 0
- try:
- success, self.img = cap.read()
- if not success:
- self.end = 1
- return
- if self.fps == 0:
- self.fps = cap.get(cv2.CAP_PROP_FPS)
-
- self.img = self.cv2.cvtColor(self.img, self.cv2.COLOR_BGR2RGB)
- self.img = self.rescale_frame2(self.img, 200)
- #ret, self.img = self.cv2.threshold(self.img, 100, 130, self.cv2.THRESH_BINARY) # treshold
- #self.img = self.cv2.Canny(self.img, 100, 200) # kanten
-
- #M = cv2.getPerspectiveTransform(Punkte_A, Punkte_B)
- #warped = cv2.warpPerspective(Bild, m, (420,594))
-
- #self.cv2.normalize(self.img, self.img, 0, self.dim, self.cv2.NORM_MINMAX)
-
- self.buffer.append(self.img)
- if len(self.buffer) % 100 == 0:
- _id = str(self.__repr__)[-5:-1]
- print(_id,"video read",self.dmx,len(self.buffer),self.fname,"fps",self.fps,self.dim)
- except Exception as e:
- print("Excetpion","_init",self,e,end="")
- self.success = 1
- def read(self):
- if len(self.buffer) <= 0:
- return
- try:
- if self.pos >= len(self.buffer):
- self.pos = len(self.buffer)-1
- self.img = self.buffer[int(self.pos)]
- #self.img = self.cv2.cvtColor(self.img, self.cv2.COLOR_BGR2RGB)
- self.img = self.rescale_frame(self.img, percent=self.scale)
- if self._run:
- t = time.time()
- self.t_delta = t-self.t_last
- self.t_last = t
- self.pos += self.t_delta*self.fps
- else:
- t = time.time()
- self.t_delta = 0
- self.t_last = t
- if self.pos >= len(self.buffer):
- #self.pos = 0 #len(self.buffer)-1
- self.pos = len(self.buffer)-1
- #print("video.read",self.pos)
- self.shape = self.img.shape[1::-1]
- except Exception as e:
- print("exception 432",e,len(self.buffer),self.fname)
- #self.init()
- def prev(self):
- self.pos -= 1
- if self.pos < 0:
- self.pos = len(self.buffer)-1
- if self.pos >= len(self.buffer):
- self.pos = len(self.buffer)-1
- self.im = self.buffer[int(self.pos)]
- def rescale_frame2(self,frame, width):
- height = int(frame.shape[0]/frame.shape[1] * width )
- dim = (width, height)
- return self.cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
- def rescale_frame(self,frame, percent=75):
- width = int(frame.shape[1] * percent/ 100)
- height = int(frame.shape[0] * percent/ 100)
- dim = (width, height)
- return self.cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
- def next(self):
-
- self.read()
- try:
- if len(self.buffer) % 100 == 0:
- _id = str(self.__repr__)[-5:-1]
- # add DIMER to videplayer
- self.cv2.normalize(self.img, self.img, 0, self.dim, self.cv2.NORM_MINMAX)
-
- img = self.img
- if img is None:
- return
- self.im = pygame.image.frombuffer(img.tobytes(), self.shape, "RGB")
- if self._run:
- t = time.time()
- self.t_delta = t-self.t_last
- self.t_last = t
- self.pos += self.t_delta*self.fps
- else:
- t = time.time()
- self.t_delta = 0
- self.t_last = t
- if self.pos > len(self.buffer):
- self.pos = 0
- self.pos = len(self.buffer)-1
- except AttributeError as e:
- time.sleep(.05)
- #if self.init_count % 100 == 0:
- print("except 776",e)
- #self.init()
- except Exception as e:
- print("except 756",e)
- def draw(self,wn=None):
- # draw video background box
- __xw = int(370*self.scale/255)
- __yw = int(235*self.scale/255)
- yellow = [105,50,0]
- yellow[0] = int(yellow[0]*self.dim/255)
- yellow[1] = int(yellow[1]*self.dim/255)
- yellow[2] = int(yellow[2]*self.dim/255)
- #print(yellow)
- pygame.draw.rect(wn,yellow,[self.x,self.y,__xw,__yw])
- pygame.draw.rect(wn,[25,20,20],[self.x+1,self.y+1,__xw-2,__yw-2])
- pygame.draw.line(wn,yellow,[self.x+2,self.y+2],[self.x+__xw-4,self.y+__yw-4])
- pygame.draw.line(wn,yellow,[self.x+__xw-4,self.y+2],[self.x+2,self.y+__yw-4])
- pz = 0
- txt = "FPS:{} F:{:05} von {:05} sec:{:0.02f} von {:0.02f}"
- txt = txt.format(self.fps,int(self.pos),len(self.buffer),(-1),pz )
- if self.end:
- fr = font15.render(txt,1, (0,255,0))
- else:
- fr = font15.render(txt,1, (255,0,0))
- wn.blit(fr,(10,main_size[1]-(self._id+1)*35))
- if self.success and wn and self.im: # is not None:
- wn.blit(self.im, (self.x, self.y))
- def overlay(self,wn=None,mode="x"):
- # overlay
- img_shape = [100,100]
- if type(self.img) is list:
- img_shape = self.img.shape
- pygame.draw.rect(wn,[255,200,0],[5,main_size[1]-(self._id+1)*35,300,28])
- font15 = pygame.font.SysFont("freemonobold",17)
- pz = 0
- if self.end:
- rgb = [ 100,255,100]
- else:
- rgb = [255,100,0]
- pygame.draw.rect(wn,rgb,[220,main_size[1]-(self._id+1)*35,80,13])
- _line = "error no _line"
- if self.fps == 0: # check if div zerro
- _line ="FPS:{} F:{:05} von {:05} sec:{:0.02f} von {:0.02f}"
- _line = _line.format(self.fps,int(self.pos),len(self.buffer),(-1),pz )
- else:
- pz = (len(self.buffer)/self.fps)
- _line = "FPS:{} F:{:05} von {:05} sec:{:0.02f} von {:0.02f}"
- _line = _line.format(self.fps,int(self.pos),len(self.buffer),(self.pos/self.fps),pz )
- fr = font15.render(_line ,1, (0,0,0))
- wn.blit(fr,(10,main_size[1]-(self._id+1)*35))
- if self._run:
- mode = "run"
- else:
- mode = "pause"
- fr = font15.render(" {} {} >:{} ".format(self._id+1,self._video_nr,mode) ,1, (0,0,0))
- wn.blit(fr,(3,main_size[1]-(self._id+1)*35+15))
- fr = font15.render("{}".format(self.fname) ,1, (0,0,0))
- wn.blit(fr,(60,main_size[1]-(self._id+1)*35+15))
- VIDEO = []
- videoplayer=[]
- cv2 = None
- _vid = 0
- if type(options.videoplayer) is str:
- try:
- import cv2
- except:
- print("Except Import:",e)
- max_videoplayer = 4
- dmx_start = options.videoplayer.split(",")
- for cdmx in dmx_start:
- if len(videoplayer) > max_videoplayer:
- print("-- videoplayer max count {} !! break".format(max_videoplayer))
- break
- print("-- videoplayer dmx:",cdmx)
- try:
- cdmx = int(cdmx)
- videoplayer.append( Vopen(cdmx,_id=_vid) )
- _vid += 1
- VIDEO.append({"DMX":cdmx,"DIM":0,"PAN":127,"TILT":127,"CONTROL":0,"SEC":10,"VIDEO":"3","RED":255,"GREEN":255,"BLUE":255,"_time":time.time(),"_RUN":0,"_SEC":">{}<".format(cdmx)})
- except Exception as e:
- print("EXCEPTION COUNTER INIT ",cdmx)
- def loop_videoplayer():
- while 1:
- _videoplayer = videoplayer[:]
- #print(".")
- for i in _videoplayer: #.append( Vopen(cdmx,_id=_vid) )
- try:
- i._read() # read next frame from file
- except Exception as e:
- print("EXCEPTION loop_videoplayer ")
- time.sleep(0.005)
- thread.start_new_thread(loop_videoplayer,())
- # ===== ======
- p = 16
- block = [p,p]
- _x = 8
- _y = 8
- #HD = "0"
- if options.mode:
- try:
- HD = options.mode
- p,_x,_y = HD.split(",")
- _x = int(_x)
- _y = int(_y)
- p = int(p)
- block = [p,p]
- except Exception as e:
- print( "Exc",options.mode,e)
- HD_x = 2
- HD_y = 2
- print( [options.xsplit])
- print( [options.ysplit])
- try:
- if options.xsplit:
- HD_x = int(options.xsplit)
- if options.ysplit:
- HD_y = int(options.ysplit)
- except Exception as e:
- print( "Exc",options.mode,e)
- print("HD",HD_x,HD_y)
- print("xy",_x,_y)
- print("++++++++++++++++++", p,_x,_y)
- _x2 = _x
- try:
- if options.XX:
- pass#_x2 = int(options.XX)
- except Exception as e:
- print( "Exc",options.mode,e)
- print("_x2 , -X",_x2)
- # ===== GUI =========
- import pygame
- import pygame.gfxdraw
- import pygame.font
- clock = pygame.time.Clock()
- os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,164)
- if options.win_pos:
- if "," in options.win_pos:
- win_pos = options.win_pos.split(",")
- try:
- WIN_POS = '%i,%i' % (int(win_pos[0]),int(win_pos[1]) )
- os.environ['SDL_VIDEO_WINDOW_POS'] = WIN_POS
- except Excetpion as e:
- print("win_pos",win_pos,e)
- os.environ['SDL_VIDEO_CENTERED'] = '0'
- pg = pygame
- pygame.init()
- pygame.mixer.quit()
- f = pygame.font.get_fonts()
- for i in f:
- if "mono" in i.lower():
- print(i)
-
- font = pygame.font.SysFont("freemonobold",22)
- font10 = pygame.font.SysFont("freemonobold",10)
- font12 = pygame.font.SysFont("freemonobold",12)
- font15 = pygame.font.SysFont("freemonobold",15)
- font40 = pygame.font.SysFont("freemonobold",40)
- font80 = pygame.font.SysFont("freemonobold",70)
- #font = pygame.font.SysFont(None,30)
- fr = font.render("hallo" ,1, (200,0,255))
- PIXEL_MAPPING = 0
- grid_file = "/tmp/vpu_grid_hd.csv"
- text_file = "/home/user/LibreLight/vpu_text_hd.csv"
- play_list = "/tmp/vpu_playlist_hd.csv"
- pm_wy = 0
- if options.pixel_mapping:
- PIXEL_MAPPING = 1
- path = options.pixel_mapping
- path = path.replace("/","-")
- path = path.replace(".","-")
- path = path.replace("\"","-")
- path = path.replace("'","-")
- grid_file = "/home/user/LibreLight/vpu_grid_hd{}.csv".format(path)
- text_file = "/home/user/LibreLight/vpu_text_hd{}.csv".format(path)
- play_list = "/home/user/LibreLight/vpu_playlist_hd{}.csv".format(path)
- play_list = "/home/user/LibreLight/video/" #.format(path)
- #_x = 8
- #_y = 8
- print(" ",[options.pixel_mapping],"grid_file",grid_file)
- #grid_file = "/home/user/LibreLight/vpu_grid_hd.csv"
- main_size=(600,500)
- try:
- if _x < 8 and PIXEL_MAPPING >= 1:
- wx = 60+block[0] * 8
- else:
- wx = 60+block[0] * _x
- wy = 80+block[1] * _y
- #pm_wy = wy
- if type(options.videoplayer) is str:
- wy += 150 # video playlist
- main_size=(wx,wy)
- if PIXEL_MAPPING >= 1:
- pm_wy = 120+block[0] * 8
- main_size=(wx,wy+pm_wy)
- except Exception as e:
- print("Exception:",e)
- #main_size=(280,200)
- main_size = (main_size[0],main_size[1])
- window = pygame.display.set_mode(main_size,pg.RESIZABLE)#,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
- pg.display.set_caption('LibreLight VPU-SCREEN')
- class Fix():
- def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
- #print("Fix",_id)
- self._id = _id
- self.dmx = (_id-1) * ch +1 #dmx
- self.univ = univ
- self.ch = ch
- self.pos = pos
- self.rgb = [0,0,0]
- self.block = block #[10,10]
- self.x = pos[0]
- self.y = pos[1]
- self.strobo = time.time()
- self.bmp = 250
- self.sub_fix = []
-
- sub_block =[block[0]/HD_x,block[1]/HD_y]
- if _id <= 0: #exit
- return
- spalte = (_id-1)%_y +1
- zeile = int((_id-1)/_x2) #+1
- #zeile = zeile*_x*HD_x*HD_y
- add_row = _x*HD_x*HD_y
- #zeile 1
- sid = (_id-1)*2 + zeile*HD_x*_x2
- #for i in range(1,HD_x):
- sid = sid+1
- #sid = zeile
- sub_pos= [pos[0]*block[0],pos[1]*block[1]]
- sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
- self.sub_fix.append(sub_fix)
- sid = sid+1
- #sid = zeile
- sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]]
- sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
- self.sub_fix.append(sub_fix)
- #zeile 2
- sid = (_id-1)*2+1 + _x2*HD_x + zeile*HD_x*_x2 # int(add_row)
- #sid = sid+1
- #sid = HD_x
- sub_pos= [pos[0]*block[0],pos[1]*block[1]+block[1]/2]
- sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
- self.sub_fix.append(sub_fix)
- #sid = sid+1
- sid = sid+1
- sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]+block[1]/2]
- sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
- self.sub_fix.append(sub_fix)
- def calc(self,data):
- _rgb = [0,255,0]
- return _rgb
- def sub_calc(self,data):
- _rgb = [0,255,0]
- for sub_fix in self.sub_fix:
- sub_fix.block = self.block[:]
- _rgb = sub_fix.calc(data)
- return _rgb
-
-
- def POS(self,x=0,y=0,a=0,b=0):
- A = (self.pos[0])*self.block[0]
- B = (self.pos[1])*self.block[1]
- C = self.block[0]-a
- D = self.block[1]-b
- return [x+A,y+B,C,D]
- def subPOS(self,x=0,y=0,a=0,b=0):
- __out = []
- for sub_fix in self.sub_fix:
- __out.append( sub_fix.POS(x,y,a,b) )
- return __out
- class SubFix():
- def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
- #print("Fix",_id)
- self._id = _id
- self.dmx = (_id-1) * ch +1 #dmx
- self.univ = univ
- self.ch = ch
- self.pos = pos
- self.rgb = [0,0,40]
- self.block = block #[10,10]
- self.x = pos[0]
- self.y = pos[1]
- self.strobo = time.time()
- self.bmp = 250
- def calc(self,data):
- #return [130,30,20]
- dmx_sub = [30]*10
- #print(dmx_sub)
- dmx = self.dmx -1
- _dmx_sub = []
- if self.dmx >= 0:
- dmx = rDMX(self.univ,self.dmx)-1
- if dmx+self.ch < len(data):
- _dmx_sub = data[dmx:dmx+self.ch]
- if _dmx_sub:
- dmx_sub = _dmx_sub
- #print(dmx_sub)
- dim = dmx_sub[0]/255
- #print("dmx",dmx,dmx_sub)
- r = dmx_sub[1]*dim
- g = dmx_sub[2]*dim
- b = dmx_sub[3]*dim
- r = int(r)
- g = int(g)
- b = int(b)
- self.rgb = [r,g,b]
- return self.rgb
-
- def POS(self,x=0,y=0,a=0,b=0):
- A = (self.pos[0]) #+self.block[0]
- B = (self.pos[1]) #+self.block[1]
- C = self.block[0]-a
- D = self.block[1]-b
- if NR:
- C-=1
- D-=1
- return [int(x+A),int(y+B),int(C),int(D)]
- class POINTER():
- def __init__(self):
- self.pos = [0,0,0,0]
- self.on = 0
- self.rgb = [0,100,10]
- self._x = 0
- self._y = 0
- self.x = 0
- self.y = 0
- self.fix = Fix(0 ,[999,999],[16,16],0,0,0)
- def row_move(self,x,y):
- self._x = x
- self._y = y
- def move(self,pos):
- self.pos = pos
- self.on = 1
- def cross(self,x,y):
- self.x = x
- self.y = y
- def draw(self,x,y):
- pos = self.pos[:]
- #print("draw",x,y,pos)
- pos[0] += x
- pos[1] += y
- fix_x= self.fix.x
- fix_y= self.fix.y +y
- #print("draw",x,y,pos)
- if self.on:
- pygame.draw.rect(window,self.rgb,pos)
- #pygame.draw.line(window,self.rgb, (pos[0],pos[1]) , (pos[0]+100,pos[1]) )
-
- # mouse grid posision
- fr = font15.render("{}/{}".format(fix_x+1,fix_y) ,1, (200,200,200))
-
- _nr = fix_y * _x + fix_x +1
- #fr = font15.render("{:02} {}/{}".format(_nr, fix_x+1,fix_y+1 ) ,1, (200,200,200))
- fr = font15.render("{:02}".format(_nr ) ,1, (200,200,200))
- window.blit(fr,(pos[0]+2,pos[1]+2 ))
- window.blit(fr,(130,1))
- # fix pos
- txt=str(pos) #"[0, 0, 0, 0]"
- fr = font15.render(txt ,1, (200,200,200))
- #window.blit(fr,(pos[0]+2,pos[1]+2 ))
- window.blit(fr,(10,1))
- # univers
- #fr = font15.render("{:02}:{:03}".format(fix.univ,fix.dmx) ,1, (200,200,200))
- #window.blit(fr,(300,10))
-
- # pointer
- fr = font15.render("X:{:03}".format(self._x) ,1, (200,200,200))
- window.blit(fr,(10,30))
- fr = font15.render("Y:{:03}".format(self._y) ,1, (200,200,200))
- window.blit(fr,(10,40))
- # crosshair
- self.rgb = [0,0,200]
- pygame.draw.line(window,self.rgb, (self.x-p,self.y) , (self.x-2,self.y),4 )
- pygame.draw.line(window,self.rgb, (self.x,self.y-p) , (self.x,self.y-2),4 )
- self.rgb = [0,200,0]
- pygame.draw.line(window,self.rgb, (self.x+2,self.y) , (self.x+p,self.y),4 )
- pygame.draw.line(window,self.rgb, (self.x,self.y+2) , (self.x,self.y+p),4 )
- self.rgb = [200,0,0]
- pointer = POINTER()
- NR = 0
- running = True
- def event():
- global NR,running
- for event in pygame.event.get():
- #print(event.dict)
- _button = None
- if "button" in event.dict:
- _button = event.dict["button"]
- _state = None
- if "state" in event.dict:
- _state = event.state
- _key = None
- if "key" in event.dict:
- _key = event.key
- _pos = None
- if "pos" in event.dict:
- _pos = event.pos
- _type = None
- if "type" in event.dict:
- _type = event.type
- _type = event.type
- _mod = None
- if "mod" in event.dict:
- _mod = event.mod
- if 0:
- print( " ")
- print( "{:.02f}".format( time.time() - START ))
- print("button -",_button,end="\t| ")
- #print("state -",_state)
- print("pos -",_pos)
- print("type -",_type, end="\t| ")
- print("key -",_key)
- print("mod -",_mod)
- try:
- if _type == 5:
- if _button == 1:
- NR += 1
- if NR > 1:
- NR = 0
- if _button == 3:
- NR -= 1
- if NR < 0:
- NR = 1
- if _pos:
- posA = _pos
- fix = find_pix(_pos[0]-40,_pos[1]-60+pm_wy)
- if fix:
- pos = fix.POS(40,60+pm_wy)
- rgb = [0,0,0]
- pointer.move(pos)
- pointer.fix = fix
- else:
- pointer.on = 0
- pointer.row_move(_pos[0],_pos[1])
- pointer.cross(_pos[0],_pos[1])
- if event.type == pygame.VIDEORESIZE:
- window = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)
- except Exception as e:
- print(e)
- if event.type==pygame.QUIT:
- running=False
- fps = 0
- frame = 0
- frame_t = time.time()
- IP = "yyy"
- def draw_overlay():
- global fps
- fr = font.render("FPS:{}".format(fps) ,1, (200,0,255))
- window.blit(fr,(10,10))
- fr = font.render("ip:{}".format(IP) ,1, (200,0,255))
- window.blit(fr,(80,10))
- def calc_fps():
- global fps,frame,frame_t
- t = time.time()
- if frame_t+1 < t:
- fps = frame #frame_t- t #frame
- frame = 1
- frame_t = time.time()
- TEXT_BLOCK = []
- def _create_text_block():
- print("======== CREATE NEW TEXT FILE !!",text_file)
- f = open(text_file,"w")
- for i in range(10):
- f.write("TEXT {}\n".format(i+1))
- f.close()
- def open_text_block():
- print("======== OPEN TEXT FILE !!",text_file)
- _lines = []
- try:
- f = open(text_file,"r")
- _lines = f.readlines()
- f.close()
- except FileNotFoundError as e:
- print("TEXT",e)
- _create_text_block()
- if len(_lines) <= 0:
- _create_text_block()
- lines = []
- for l in _lines:
- #print(">> ",l.strip())
- lines.append(l.strip())
- if len(lines) <= 10:
- for i in range(10-len(lines)):
- lines.append("LINE ERROR")
- return lines
- TEXT_BLOCK = open_text_block()
- TEXT_BLOCK_TIME = time.time()
- # video playlist
- PLAYLIST = []
- def _create_playlist():
- print("======== CREATE NEW PLAYLIST DIR !!",play_list)
- os.system("mkdir -p /home/user/LibreLight/video")
- f = open(play_list,"w")
- f.write("bbb_sunflower_480x320.mp4\n")
- for i in range(10-1):
- f.write("Video-file {}\n".format(i+1+1))
- f.close()
- def open_playlist():
- print("======== OPEN PLAYLIST DIR !!",play_list)
- _lines = []
- try:
- #f = open(play_list,"r")
- _lines = os.listdir(play_list)
- _lines.sort()
- #_lines = f.readlines()
- #f.close()
- except FileNotFoundError as e:
- print("TEXT",e)
- pass#_create_playlist()
- if len(_lines) <= 0:
- pass#_create_playlist()
- lines = ['']*25 # first is empty
- i=0
- for l in _lines:
- #print(">> ",l.strip(),len(lines))
- l = l.strip()
- if "_" in l:
- ll = l.split("_",1)
- print(">> ",ll)
- #ll = int(ll)
- try:
- lll = int(ll[0])
- #lines.append(l.strip())
- lines[lll] = l
- except:pass
- if len(lines) <= 10:
- for i in range(10-len(lines)):
- lines.append("")#"LINE ERROR")
- return lines
- PLAYLIST_TIME = time.time()
- PLAYLIST = open_playlist()
- # ===== GUI =========
- #def draw_circle(surface, x, y, radius, color):
- def draw_circle(surface,color, pos, radius):
- x,y=pos
- pygame.gfxdraw.aacircle(surface, int(x), int(y), radius-1, color)
- pygame.gfxdraw.filled_circle(surface, int(x), int(y), radius-1, color)
- def rDMX(univ,dmx):
- return univ*512+dmx
- def generate_grid(mapping=0):
- _log = []
- #if PIXEL_MAPPING:
- # log = open(grid_file,"w")
- head = "i,univ,dmx,x,y,ch\n"
- head = "i,univ,dmx,ch\n"
- head = "univ,dmx,x,y,ch\n"
- head = "nr,id,info\n"
- print("csv:",head)
- #if PIXEL_MAPPING:
- # log.write(head)
- _log.append(head)
- dmx = 1-1
- ch = 4
- y=0
- x=0
- #for i in range((_y)*(_x)):
- for i in range((8)*(8)):
- #if x > _x and i%_x == 0:
- if x > 8 and i%8 == 0:
- #print("--> -->")
- x=0
- y+=1
-
- _univ = int(dmx/512)
- _dmx = dmx - (_univ)*512
- pos=[x,y]
- line="{},{},{},{},{},{}\n".format(i+1,_univ,_dmx+1,pos[0],pos[1],ch)
- line="{},{},{},{},{}\n".format(_univ,_dmx+1,x,y,ch)
- line="{},{},x\n".format(i+1,i+1)
- #print("wcsv:",[line])
- #if PIXEL_MAPPING:
- # log.write(line)
- _log.append(line)
- dmx += ch
- x+=1
- if mapping and PIXEL_MAPPING:
- print("CREATE NEW PIXELMAP FILE !!",grid_file)
- log = open(grid_file,"w")
- log.writelines(_log)
- log.close()
- return _log[:] #GRID
- def init_grid(mapping=0,_x=4,_y=4):
- if mapping and PIXEL_MAPPING:
- try:
- log = open(grid_file,"r")
- except:
- generate_grid(mapping=mapping)
- log = open(grid_file,"r")
- lines = log.readlines()
- else:
- lines = generate_grid()
-
- GRID = []
-
- y=0
- x=0
- print("CSV header",[lines[0]],[PIXEL_MAPPING])
- for i,line in enumerate(lines[1:]): #exclude first line
- #print("rcsv",[line])
- line = line.strip()
- line = line.split(",") # csv
- if i >= _x and i%_x == 0:
- x=0
- y+=1
- if y >= _y:
- break
- #i = int(line[0])
- _id = int(line[1])
- #univ = int(line[0])
- #dmx = int(line[1])
- #x = int(line[3])
- #y = int(line[4])
- #ch = int(line[4])
- pos = [x,y]
- f = Fix(_id,pos,block) #pos,univ,dmx,ch)
- #f.x = x
- #f.y = y
- #f.block = block
- GRID.append(f)
- x+=1
- #print("y, _y",y,_y)
- return GRID
- def find_pix(x,y):
- global GRID
- for fix in GRID:
- X = 0
- Y = 0
- pos = fix.POS()
- #pos = fix.POS()
- #pos = fix.POS(40,60-pm_wy)
- #pos = fix.POS(x,y+pm_wy)#40,60)
- if x > pos[0] and x < pos[0]+pos[2]:
- X = 1
- if y > pos[1] and y < pos[1]+pos[3]:
- Y = 1
- if X and Y:
- #print(pos,x,y)
- #print("find",X,Y)
- return fix
-
- GRID = []
- _GRID = []
- _GRID = init_grid(_x=8,_y=8,mapping=1) #init_gird()
- NR = 0
- START_UNIV=2
- if options.start_univ:
- try:
- START_UNIV=int(options.start_univ)
- except Exception as e:
- print("Exception START UNIV",e)
- gobo_ch=1
- if options.gobo_ch:
- try:
- gobo_ch=int(options.gobo_ch)
- except Exception as e:
- print("Exception gobo_ch",e)
- if gobo_ch <= 0:
- gobo_ch = 1
- def draw_box(pos1,pos2,color=[128,128,128],text=1):
- color = [200,0,0,127]
- if text:
- fr = font15.render("A" ,1, (200,200,200))
- window.blit(fr,pos1)
- fr = font15.render("B" ,1, (200,200,200))
- window.blit(fr,[pos2[0]-10,pos2[1]-10])
- # h unten
- _pos1 = [pos1[0],pos2[1]]
- _pos2 = [pos2[0],pos2[1]]
- pygame.draw.aaline(window,color,_pos1,_pos2,1)
- color = [255,255,0,127]
- # h rechts
- _pos1 = [pos2[0],pos1[1]]
- _pos2 = [pos2[0],pos2[1]]
- pygame.draw.aaline(window,color,_pos1,_pos2,1)
- color = [0,200,0,127]
- # h links
- _pos1 = [pos1[0],pos1[1]]
- _pos2 = [pos1[0],pos2[1]]
- pygame.draw.aaline(window,color,_pos1,_pos2,1)
- color = [0,0,200,127]
- # h oben
- _pos1 = [pos1[0],pos1[1]]
- _pos2 = [pos2[0],pos1[1]]
- pygame.draw.aaline(window,color,_pos1,_pos2,1)
- def grab(x=55,y=55,w=60,h=60):
- # usage
- # sub = grab()
- # window.blit(sub, (500,10))
- crop = None
- rect = pygame.Rect(x, y, w, h)
- try:
- sub = window.subsurface(rect)
- #pixArray = pygame.PixelArray(screen)
- crop = pygame.Surface((w,h))
- crop.blit(sub, (0,0))
- except ValueError as e:
- pass#print("exception",e,"line715")
- #except Exception as e:
- # print("exception",e,"line715")
- #print(rect)
-
- return crop
- def reshape(_x,_y):
- """reshape LED-WALL Block/Pixel mapping"""
- if PIXEL_MAPPING <= 0:
- return None
- global GRID
- global _GRID
- x = _x
- y = _y
- i = 0
- counter = 0
- z=0
- x_min = 99999
- x_max = 0
- y_min = 99999
- y_max = 0
- fr = font.render("OUTPUT".format(t1.get()) ,1, (255,255,255))
- fr_r = fr.get_rect(center=(x+int(wx/3),y+pm_wy-5))
- #window.blit(fr,(x+int(wx/2),y+pm_wy))
- window.blit(fr,fr_r)
- fr = font.render("↑ ↑ MAP ↑ ↑".format(t1.get()) ,1, (255,255,255))
- fr_r = fr.get_rect(center=(x+int(wx/3),y+pm_wy+15))
- #window.blit(fr,(x+int(wx/2),y+pm_wy))
- window.blit(fr,fr_r)
- fr = font.render("INPUT".format(t1.get()) ,1, (255,255,255))
- fr_r = fr.get_rect(center=(x+int(wx/3),y+pm_wy+35))
- #window.blit(fr,(x+int(wx/2),y+pm_wy))
- window.blit(fr,fr_r)
- j = 0
- for fix in _GRID:
- if j >= 8*8: # max output size
- break
- #if j >= _x*_y: # max input size
- # break
- j+=1
- ii = i
- #z= i # helping border offset
- pos = fix.POS(40,60)
- rgb = fix.rgb
- # green
- pygame.draw.rect(window,[0,40,0],pos)
- xposs = [] #None #pos[:]
- for fix2 in GRID:
- if fix._id == fix2._id:
- xposs.append( fix2.POS(40,60) )
- for xpos in xposs:
- sub = grab(xpos[0],xpos[1]+pm_wy,xpos[2],xpos[3])
- if sub:
- if 1:#j <= _x*_y: # max input size
- window.blit(sub, (x+pos[0]+z,y+pos[1]+z))
- else:
- # red
- pygame.draw.rect(window,[40,0,0],pos) #[x+pos[0]+2+z,y+pos[1]+2+z-pm_wy,12,9])
- if xpos[0] < x_min:
- x_min = xpos[0]
- if xpos[0] > x_max:
- x_max += xpos[2]
- if xpos[1] < y_min:
- y_min = xpos[1]
- if xpos[1] > x_max:
- y_max += xpos[3]
- # DRAW FIX NUMBER on TOP
- #apos = pos
- #argb = rgb
- apos = fix.POS(40,60+pm_wy)
- argb = fix.rgb
- # overwrite number overlay
- if NR:
- #pygame.draw.rect(window,[30,40,0],apos)
- pygame.draw.rect(window,[20,40,0],[x+apos[0]+2+z,y+apos[1]+2+z-pm_wy,12,9])
- if NR:# == 2:
- if fix._id != i+1:
- fr = font15.render("{:02}".format(fix._id) ,1, (255,255,0))
- window.blit(fr,(x+apos[0]+2+z,y+apos[1]+2+z-pm_wy))
- #print(fix._id,xposs,pos)
- else:
- fr = font15.render("{:02}".format(fix._id) ,1, (100,100,255))
- window.blit(fr,(x+apos[0]+2+z,y+apos[1]+2+z-pm_wy))
- i += 1
- #print("--#")
- # frame box
- #pygame.draw.box(window,[100,0,0],[x+x_min,y+x_min,x_max+x_min,y_min+y_max])
- pos1= [x+x_min,y+x_min]
- pos2= [x_max+x_min,y_min+y_max]
- #draw_box(pos1,pos2,text=0)
- class Timer():
- def __init__(self,start=120):
- self.start = start
- self.timer = self.start
- self.timer_t = time.time()
- def reset(self):
- self.timer = self.start
- def get(self):
- self.timer -= time.time()-self.timer_t
- self.timer_t = time.time()
- if self.timer <= 0:
- self.reset()
- return self.timer
- def reload_grid():
- print("==== reload_grid")
- global GRID
- global _GRID
- try:
- GRID = init_grid(_x=_x,_y=_y) #init_gird()
- _GRID = init_grid(_x=8,_y=8,mapping=1) #init_gird()
- except Exception as e:
- print("Except: grid re init",e)
- VPU_TEXT = []
- def load_vpu_text(nr=0):
- txt = "NONE"
- if not VPU_TEXT:
- pass #create VPU_TEXT_FILE
- if len(VPU_TEXT) > nr:
- txt = VPU_TEXT[0]
- return txt
- grid_counter = time.time()
- def draw_fix_nr(GRID):
- global grid_counter
- i=0
- y=0
- for fix in GRID:
- pos = fix.POS(40,60+pm_wy)
- rgb = fix.rgb
- if NR:
- pygame.draw.rect(window,[0,0,0],[pos[0]+2,pos[1]+2,12,9])
- if fix._id%_x-1 == 0: # line break border
- pygame.draw.line(window,[255,255,0],(pos[0],pos[1]+4),(pos[0],pos[1]+pos[3]-4),1)
- 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)
- if fix._id%_x == 0: # line break border
- 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)
- 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)
- if grid_counter +5 < time.time():
- grid_counter = time.time()
- reload_grid()
- if fix._id != i+1:
- fr = font15.render("{:02}".format(fix._id) ,1, (255,255,0))
- else:
- fr = font15.render("{:02}".format(fix._id) ,1, (100,100,255))
- window.blit(fr,(pos[0]+2,pos[1]+2))
- i += 1
-
- def draw_counter(COUNTER):
- for count in COUNTER:
- cpan = 0
- ctilt = 0
- cr=255
- cg=255
- cb=255
- csize=10
- cdim=0
- k = "DIM"
- if k in count:
- cdim = int(count[k])
- k = "RED"
- if k in count:
- cr = int(count[k])
- k = "GREEN"
- if k in count:
- cg = int(count[k])
- k = "BLUE"
- if k in count:
- cb = int(count[k])
- k = "SIZE"
- if k in count:
- csize = int(count[k])
- if csize < 5:
- csize = 5
- k = "PAN"
- if k in count:
- cpan = int(count[k])/255*(block[0] *(_x))
- cpan = int(cpan)
- k = "TILT"
- if k in count:
- ctilt = int(count[k])/255*(block[1] *(_y))
- ctilt = int(ctilt)
- ddim = cdim/255
- if "DIM" in count and count["DIM"] > 0:
- tmp_font = pygame.font.SysFont("freemonobold",int(block[0]/100*csize))
- rgb =(int(cr*ddim),int(cg*ddim),int(cb*ddim),cdim)
-
- _sec = count["_SEC"]
-
- try:
- _sec = int(count["_SEC"])
- except:
- pass
- if type(_sec) is int:
- #print(_sec)
- if _sec <= 60:
- fr = tmp_font.render("{:0}".format(_sec) ,1, rgb)
- else:
- _xx = time.strftime("%M:%S",time.localtime(_sec))
- #print("_xx",_xx)
- fr = tmp_font.render("{}".format(_xx) ,1, rgb)
- else:
- fr = tmp_font.render("{}".format((count["_SEC"])) ,1, rgb)
- fr_r = fr.get_rect(center=(60+cpan-(block[0]),60+ctilt+pm_wy))
- pygame.draw.rect(window,[0,0,0],fr_r)
- window.blit(fr,fr_r)
- def draw_video(VIDEO):
- global videplayer
- i = 0
- for count in VIDEO:
- cpan = 0
- ctilt = 0
- cr=255
- cg=255
- cb=255
- csize=10
- cdim=0
-
- video1 = videoplayer[i]
- k = "VIDEO"
- if k in count:
- #video1.select_video(count[k])
- play_nr = int(count[k]/10)
- if play_nr != video1._video_nr:
- print( "+ + + + + + + + + + +", play_nr , video1._video_nr ,str(video1))
- _vid = video1._id
- _cdmx = video1.dmx
- video1 = Vopen(cdmx,_id=_vid)
- video1.select_video(count[k])
- videoplayer[i] = video1
- k = "DIM"
- if k in count:
- cdim = int(count[k])
- video1.dim = cdim
- #if i == 0:
- # print(i,cdim)
- k = "SIZE"
- if k in count:
- csize = int(count[k])
- if csize < 5:
- csize = 5
- k = "PAN"
- if k in count:
- cpan = int(count[k])/255*(block[0] *(_x))
- cpan = int(cpan)
- k = "TILT"
- if k in count:
- ctilt = int(count[k])/255*(block[1] *(_y))
- ctilt = int(ctilt)
-
- k = "_reset"
- if k in count:
- if count[k]:
- count[k] = 0
- video1.pos = 0
- k = "_RUN"
- if k in count:
- video1._run = count[k]
- video1.pos
- video1.x=40+cpan
- video1.y=60+pm_wy+ctilt
- video1.scale = int((csize))
- if cdim:
- video1.next()
- i += 1
- i=0
- for count in VIDEO:
- video1 = videoplayer[i]
- if cdim:
- #video1.prev()
- video1.draw(window) #,x=0,y=0)
- i+=1
- #pm_wy = 120+block[0] * 8
- #wy = 80+block[1] * _y
- #pygame.draw.rect(window,[0,0,0],[0,pm_wy+(80+block[1]*_y)+10,800,800])
- i=0
- for count in VIDEO:
- video1 = videoplayer[i]
- if 1:#cdim:
- # overlay
- video1.overlay(window,"run")
- i += 1
- def counter_dmx(COUNTER,dataA):
- for count in COUNTER:
- cDMX=count["DMX"]-1
- try:
- count["DIM"] = dataA[cDMX]
- count["PAN"] = dataA[cDMX+1]
- count["TILT"] = dataA[cDMX+2]
- count["CONTROL"] = dataA[cDMX+3]
- if count["CONTROL"] >= 10 and count["CONTROL"] < 20:
- count["_SEC"] = int(count["SEC"] - (time.time() - count["_time"]))
- if count["CONTROL"] >= 20 and count["CONTROL"] < 30:
- count["_RUN"] = 0
- if count["CONTROL"] >= 30 and count["CONTROL"] < 40:
- count["_RUN"] = 1
- count["SIZE"] = dataA[cDMX+4]
- count["SEC"] = dataA[cDMX+5]
- if count["_RUN"]:
- try:
- count["_SEC"] = int(count["SEC"] - (time.time() - count["_time"]))
- except Exception as e:
- pass
- if type(count["_SEC"]) is int:
- if count["_SEC"] < 0:
- count["_SEC"] = 0
- for ti in range(10):
- #print(ti,(ti+6)*10)
- if count["CONTROL"] >= (ti+6)*10 and count["CONTROL"] < (ti+7)*10:
- count["_SEC"] = "----" #text 1
- try:
- count["_SEC"] = TEXT_BLOCK[ti]
- except Exception as e:
- pass
- if count["CONTROL"] >= 250 and count["CONTROL"] < 256:
- count["_SEC"] = ">{}<".format(cDMX+1)
- count["RED"] = dataA[cDMX+6]
- count["GREEN"] = dataA[cDMX+7]
- count["BLUE"] = dataA[cDMX+8]
- except Exception as e:
- print("EXC FUNC",e,count)
- #print(count)
- def video_dmx(VIDEO,dataA):
- for count in VIDEO:
- cDMX=count["DMX"]-1
- try:
- count["DIM"] = dataA[cDMX]
- count["PAN"] = dataA[cDMX+1]
- count["TILT"] = dataA[cDMX+2]
- count["CONTROL"] = dataA[cDMX+3]
- if count["CONTROL"] >= 10 and count["CONTROL"] < 20:
- count["_reset"] = 1
- if count["CONTROL"] >= 20 and count["CONTROL"] < 30:
- if count["_RUN"] == 1:
- print( "_RUN:0",count["DMX"]-1)
- count["_RUN"] = 0
- if count["CONTROL"] >= 30 and count["CONTROL"] < 40:
- if count["_RUN"] == 0:
- print( "_RUN:1",count["DMX"]-1)
- count["_RUN"] = 1
- count["SIZE"] = dataA[cDMX+4]#*2
- count["SEC"] = dataA[cDMX+5]
- count["VIDEO"] = dataA[cDMX+6]
- #count["RED"] = dataA[cDMX+6]
- #count["GREEN"] = dataA[cDMX+7]
- #count["BLUE"] = dataA[cDMX+8]
- except Exception as e:
- print("VIDEOPLAYER EXCEPT FUNC",e,count)
- #print(count)
- def read_dmx_data(ip,ips):
- ip = select_ip(ips,univ=START_UNIV)
- IP = ip
- data = read_dmx(ip)
- ip = select_ip(ips,univ=START_UNIV+1)
- data3 = read_dmx(ip)
- data.extend(data3)
- ip = select_ip(ips,univ=START_UNIV+2)
- data3 = read_dmx(ip)
- data.extend(data3)
- ip = select_ip(ips,univ=START_UNIV+4)
- data3 = read_dmx(ip)
- data.extend(data3)
- #ip = select_ip(ips,univ=START_UNIV+5)
- #data3 = read_dmx(ip)
- #data.extend(data3)
-
- return data
- def draw_gobo(GRID,data):
- i = 0
- dmx = 1
- h = 1
- v = 1
- for fix in GRID:
- pos = fix.POS(40,60+pm_wy)
- rgb = fix.rgb
- if 1:
- # draw row/col grid number
- if fix.pos[0] == 0:
- fr = font12.render("{}".format(fix.pos[1]+1) ,1, (200,200,200))
- window.blit(fr,(10,pos[1]+3 ))
- if fix.pos[1] == 0:
- fr = font12.render("{}".format(fix.pos[0]+1) ,1, (200,200,200))
- window.blit(fr,(pos[0]+2,35 ))
- pygame.draw.rect(window,rgb,pos)
- # DRAW SUB-FIXTURE
- j = 0
- for subfix in fix.sub_fix:#calc(data):
- subfix.calc(data)
- #fix = subfix
- spos = subfix.POS(40,60+pm_wy)
- srgb = subfix.rgb
- #print(fix.dmx,rgb,pos)
- #pygame.draw.circle(window,rgb,(pos[0]+int(pos[2]/2),pos[1]+int(pos[3]/2)),int(pos[3]/2))
- #FUNC = 0
- if FUNC > 10 and FUNC <= 20: # big dot
- draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
- elif FUNC > 20 and FUNC <= 30:#small dot
- draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
- elif FUNC > 30 and FUNC <= 40:#donut
- draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
- draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
- elif FUNC > 40 and FUNC <= 50: # rec with hole
- pygame.draw.rect(window,srgb,spos)
- draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
- elif FUNC > 50 and FUNC <= 60: # rec with big hole
- pygame.draw.rect(window,srgb,spos)
- draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
- elif FUNC > 60 and FUNC <= 70: # rec with donat
- pygame.draw.rect(window,srgb,spos)
- draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
- draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
- elif FUNC > 70 and FUNC <= 80: # rec boarder
- pygame.draw.rect(window,srgb,[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
- elif FUNC > 80 and FUNC <= 90: # rec big boarder
- pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
- elif FUNC > 90 and FUNC <= 100: # rec thin line
- pygame.draw.rect(window,srgb,spos)
- pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
- elif FUNC > 100 and FUNC <= 110: # rec big line
- pygame.draw.rect(window,srgb,spos)
- pygame.draw.rect(window,[0,0,0],[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
- elif FUNC > 110 and FUNC <= 120: # rec with dot
- pygame.draw.rect(window,srgb,spos)
- pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
- draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
- elif FUNC > 120 and FUNC <= 130: # rec inline
- pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
- pygame.draw.rect(window,[0,0,0],[spos[0]+3,spos[1]+3,spos[2]-6,spos[3]-6])
- elif FUNC > 130 and FUNC <= 140: # 3 dot (heart)
- draw_circle(window,srgb,(spos[0]+int(spos[2]/2)+2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
- draw_circle(window,srgb,(spos[0]+int(spos[2]/2)-2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
- draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)+2),int(spos[3]/3.5))
- else:
- pygame.draw.rect(window,srgb,spos)
- for subfix in fix.sub_fix:#calc(data):
- subfix.calc(data)
- #fix = subfix
- spos = subfix.POS(40,60+pm_wy)
- srgb = subfix.rgb
- # draw row/col grid number
- if subfix.pos[0] == 0:
- fr = font12.render("{}".format(v ) ,1, (200,200,200))
- window.blit(fr,(25,spos[1] ))
- v += 1
- if subfix.pos[1] == 0:
- fr = font12.render("{}".format(1) ,1, (200,200,200))
- fr = font12.render("{}".format(h ) ,1, (200,200,200))
- h+=1
- window.blit(fr,(spos[0],50 ))
- if p >= 40:
- if NR:
- #fr = font15.render("{:02}".format(j+1) ,1, (0,200,255))
- fr = font15.render("{:02}".format(subfix._id) ,1, (250,200,5))
- window.blit(fr,(spos[0]+2,spos[1]+10))
- j += 1
- i += 1
- ips=[]
- dataA=[]
- data=[]
- def dmx_raw():
- global ips,dataA,data
- ips = read_index()
-
- # ----
- ip = select_ip(ips,univ=1) # univ 1 gobo
- dataA = read_dmx(ip)
- # ----
- data = read_dmx_data(ip,ips)
- if options.countdown:
- counter_dmx(COUNTER,dataA)
-
- if len(VIDEO) > 0:
- video_dmx(VIDEO,dataA)
- return ips,dataA,data
- def dmx_loop():
- while 1:
- dmx_raw()
- time.sleep(0.1)
- dmx_raw()
- thread.start_new_thread(dmx_loop,())
- t1 = Timer(143)
- time.sleep(0.33)
- t2 = Timer(11)
- count_tilt = 0
- def main():
- global IP
- global GRID
- global _GRID
- global FUNC
- global count_tilt
- global TEXT_BLOCK
- global TEXT_BLOCK_TIME
- global PLAYLIST
- global PLAYLIST_TIME
- global dataA
- GRID = init_grid(_x=_x,_y=_y) #init_gird()
- #GRID = init_grid(_x=8,_y=8) #init_gird()
- print("GRID LEN:",len(GRID))
- s=time.time()
- print("run")
- r = ""
- IP = "xx"
- while running:
- if TEXT_BLOCK_TIME+5 < time.time():
- TEXT_BLOCK = open_text_block()
- TEXT_BLOCK_TIME = time.time()
- if PLAYLIST_TIME+6 < time.time():
- PLAYLIST = open_playlist()
- PLAYLIST_TIME = time.time()
- pygame.display.flip()
- event()
- window.fill((10,0,20))
- calc_fps()
- draw_overlay()
- # GRID loop
- try:
- ddd = 1023 #univ 3 512
- #FUNC = data[ddd]
- FUNC2 = dataA[gobo_ch-1]
- FUNC = FUNC2
- #print("FUNC", FUNC )#:ddd+512])
- #FUNC = 15
- except Exception as e:
- print("EXC FUNC",e)
- draw_gobo(GRID,data)
- # DRAW FIX NUMBER on TOP
- draw_fix_nr(GRID)
-
- #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})
- if options.countdown:
- draw_counter(COUNTER)
- if VIDEO:
- draw_video(VIDEO)
- pointer.draw(0,pm_wy) #wy
- spos = [0,0,0,0]
- if PIXEL_MAPPING >= 1:
- reshape(0,0) #start pos
- else:
- reshape(spos[0]+spos[2]+20,10) #start pos
- #reshape(spos[0]+spos[2]+20,10) #start pos
- pygame.display.flip()
- #pg.time.wait(15)
- #clock.tick(10)
- clock.tick(25)
- if 'SDL_VIDEO_WINDOW_POS' in os.environ:
- del os.environ['SDL_VIDEO_WINDOW_POS'] #= '%i,%i' % (200,164)
- #if 'SDL_VIDEO_CENTERED' in os.environ['SDL_VIDEO_CENTERED']:
- # del os.environ['SDL_VIDEO_CENTERED'] #= '0'
- if __name__ == "__main__":
- main()
|