فهرست منبع

add SPEED-MASTER, SIZE-MASTER ... no DMX !! ?

micha 2 سال پیش
والد
کامیت
f88f6d808e
2فایلهای تغییر یافته به همراه273 افزوده شده و 105 حذف شده
  1. 139 12
      _LibreLightDesk.py
  2. 134 93
      _console.py

+ 139 - 12
_LibreLightDesk.py

@@ -199,7 +199,14 @@ def jclient_send(data):
     jtxt = data
     jdatas = []
     for jdata in data:
-        if "DMX" in jdata:
+        if "CMD" in jdata:
+            try:
+                jdatas.append(jdata)
+            except Exception as e:
+                cprint("jclient_send, Exception DMX ",color="red")
+                cprint("",jdata,color="red")
+                cprint("-----",color="red")
+        elif "DMX" in jdata:
             try:
                 if int(jdata["DMX"]) >= 1: # ignore DMX lower one
                      jdatas.append(jdata)
@@ -3716,7 +3723,6 @@ class Presets():
 def test(a1="",a2=""):
     print([a1,a2])
 
-
 class FixtureEditor():
     def __init__(self,dmx=1):
         pass
@@ -3731,6 +3737,20 @@ class FixtureEditor():
 
         jclient_send(j)
 
+class MasterWing():
+    def __init__(self,dmx=1):
+        pass
+        self.elem=[]
+        self.dmx=dmx
+        print("init MasterWing",dmx)
+    def event(self,a1="",a2=""):
+        print([self.dmx,a1,a2])
+        jdata = {'CMD': "MASTER", 'NAME': str(a1),'VALUE':str(a2) }
+
+        j=[]
+        j.append(jdata)
+        jclient_send(j)
+
 class BufferVar():
     def __init__(self,elem):
         self.elem = elem
@@ -3741,22 +3761,26 @@ class BufferVar():
         print("change_dmx",[event,self])
 
 class ELEM_FADER():
-    def __init__(self,frame,nr,**args):
+    def __init__(self,frame,nr,cb=None,**args):
         self.frame = frame
         self.nr= nr
         self.id=nr
         self.elem = []
+        self._cb = cb
         width=11
         frameS = tk.Frame(self.frame,bg="#005",width=width)
         frameS.pack(fill=tk.Y, side=tk.LEFT)
         self.frame=frameS
 
     def event(self,a1="",a2=""):
-        print(self,"event",[self.nr,a1,a2])
-        j=[]
-        jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.nr)}
-        j.append(jdata)
-        jclient_send(j)
+        if self._cb is not None:
+            self._cb(a1,a2,nr=self.nr)
+        else:
+            print(self,"event",[self.nr,a1,a2])
+            j=[]
+            jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.nr)}
+            j.append(jdata)
+            jclient_send(j)
 
     def set_attr(self,_event=None):
         txt= self.attr["text"]
@@ -3783,15 +3807,17 @@ class ELEM_FADER():
             print("_set_attr",[self])
     def _refresh(self):
         pass
-    def pack(self,**args):
+    def pack(self,init=None,from_=255,to=0,**args):
         width=11
         r=0
         c=0
         j=0
         font8 = ("FreeSans",8)
         frameS=self.frame
-        self.b = tk.Scale(frameS,bg="lightblue", width=11,from_=255,to=0,command=self.event)
+        self.b = tk.Scale(frameS,bg="lightblue", width=11,from_=from_,to=to,command=self.event)
         self.b.pack(fill=tk.Y, side=tk.TOP)
+        if init is not None:
+            self.b.set(init)
         self.elem.append(self.b)
 
         self.b = tk.Button(frameS,bg="lightblue",text="{}".format(self.nr), width=4,command=test,font=font8 )
@@ -3825,6 +3851,101 @@ class ELEM_FADER():
         self.elem.append(self.b)
 
 
+class GUI_MasterWingLayout():
+    def __init__(self,root,data,title="tilte",width=800):
+        #xfont = tk.font.Font(family="FreeSans", size=5, weight="bold")
+        font8 = ("FreeSans",8)
+        self.dmx=1
+        self.univ=0
+        r=0
+        c=0
+        i=1
+        self.elem=[]
+        self.header=[]
+        self.data = data
+        #self.frame = tk.Frame(root,bg="black",width=width)
+        #self.frame.pack(fill=tk.BOTH, side=tk.TOP)
+
+        #self.b = tk.Label(self.frame,bg="#fff",text="Master Wing") #,font=font8 )
+        #self.b.pack(fill=None, side=tk.LEFT)
+        #self.frame = tk.Frame(root,bg="black",width=width)
+        #self.frame.pack(fill=tk.BOTH, side=tk.TOP)
+
+        #self.b = tk.Label(self.frame,bg="black",text="") # spacer
+        #self.b.pack(fill=tk.Y, side=tk.LEFT)
+
+        self.frame = tk.Frame(root,bg="magenta",width=width,border=2) # fader frame
+        self.frame.pack(fill=tk.BOTH, side=tk.TOP)
+        r=0
+        c=0
+        pb=12
+        self.pb=pb
+        for j,row in enumerate(data):
+            if c % pb == 0 or c==0:
+                h=hex(j*10)[2:].rjust(2,"0")
+                frameS = tk.Frame(self.frame,bg="#000",width=width,border=2)
+                frameS.pack(fill=tk.BOTH, side=tk.TOP)
+                p=j//pb+1
+                if p == 1:
+                    txt="SPEED-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb) 
+                else:
+                    txt="SIZE-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb) 
+                self.b = tk.Label(frameS,bg="lightblue",text=txt,width=25,font=font8 )
+                self.header.append(self.b)
+
+                self.b.pack(fill=None, side=tk.LEFT)
+                self.b = tk.Label(frameS,bg="black",text="" ,width=11,font=font8 )
+                self.b.pack(fill=tk.BOTH, side=tk.LEFT)
+
+                frameS = tk.Frame(self.frame,bg="#a000{}".format(h),width=width,border=2)
+                c=0
+            #print(frameS)
+            e= ELEM_FADER(frameS,nr=j+1,cb=self.event_cb)
+            e.pack(from_=200,to=0,init=100)
+            self.elem.append(e)
+            frameS.pack(fill=tk.X, side=tk.TOP)
+            c+=1
+            i+=1
+        self.frame.pack()
+        self._event_redraw()
+    def event_cb(self,a1="",a2="",nr=None,**args):
+        print("event_cb:",nr,a1,a2,args)
+        nr += 1
+        jdata= {"CMD":"SPEED-MASTER","NR":nr,"VALUE":int(a1)}
+        if nr > 12:
+            jdata["CMD"] = "SIZE-MASTER" 
+            jdata["NR"] = nr-12 
+        j = [jdata]
+        jclient_send(j)
+    def set_name(self,_event=None):
+        txt = self.name["text"]
+        txt = tkinter.simpledialog.askstring("FIXTURE NAME:","NAME:",initialvalue=txt)
+        self.name["text"] = "{}".format(txt)
+        print("change_dmx",[_event,self])
+
+    def event_value(self,_event=None):
+        nr=self.dmx
+        txt= self.entry_dmx["text"]
+        
+    def _event_redraw(self,_event=None):
+        nr = 0
+        print("change_dmx",[_event,self])
+        for i,btn in enumerate(self.elem):
+            btn.set_label("{} D:{}".format(i+1,nr))
+            btn.nr = nr+i
+
+        pb=self.pb
+        for j,e in enumerate(self.header):
+            p=j+1
+            #p=nr/pb
+            if p == 1:
+                txt="SPEED-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb) 
+            else:
+                txt="SIZE-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb) 
+            #txt="BANK:{} {}-{}".format(p,p*pb-pb+nr,p*pb+nr) 
+            print("---",j,txt,e)
+            e["text"] = txt
+            
 class GUI_FaderLayout():
     def __init__(self,root,data,title="tilte",width=800):
         #xfont = tk.font.Font(family="FreeSans", size=5, weight="bold")
@@ -4429,9 +4550,15 @@ if __run_main:
     for i in range(24+12):
         data.append({"text"+str(i):"test"})
     GUI_FaderLayout(w1,data)
-    #frame_fix = w1 #w.tk
-    #master.draw_fix(w1,w2)#.tk)
+    window_manager.new(w,name)
 
+    name="MASTER-WING"
+    w = GUIWindow(name,master=0,width=730,height=205,left=L1-80,top=TOP+H1-200)
+    w1 = ScrollFrame(w.tk,width=W1,height=H1)
+    data=[]
+    for i in range(12*2):
+        data.append({"MASTER"+str(i):"MASTER"})
+    GUI_MasterWingLayout(w1,data)
     window_manager.new(w,name)
 
     name="ENCODER"

+ 134 - 93
_console.py

@@ -160,6 +160,7 @@ if __run_main:
     #thread.start_new_thread(artnet_loop,())
     thread.start_new_thread(main.loop,())
 
+
 class CLOCK():
     def __init__(self):
         self.__time = 0
@@ -179,6 +180,8 @@ class CLOCK():
             #print(self.__time)
             #for i in range(10):
             time.sleep(self.__tick)
+
+
 class CLOCK_REAL():
     def __init__(self):
         self.__time = 0
@@ -251,6 +254,30 @@ class Fade():
         # start,stop,fwd,bwd,revers
         pass
 
+class _MASTER():
+    def __init__(self):
+        self.__data = {}
+    def val(self,name,value=None):
+        value = 100 #% 
+        if name in self.__data:
+            if value is not None:
+                self.__data[name] = value
+            else:
+                value = self.__data[name] 
+        return value 
+        
+class SPEED_MASTER(_MASTER):
+    def __init__(self):
+        super().__init__()
+
+class SIZE_MASTER(_MASTER):
+    def __init__(self):
+        super().__init__()
+
+
+size_master  = SIZE_MASTER()
+speed_master = SPEED_MASTER()
+
 class MASTER_FX():
     def __init__(self):
         #cprint(self,"MASTER_FX INIT !",color="green")
@@ -335,6 +362,7 @@ class FX():
             width = 200
         if width <= 0:
             width = 1
+        self.__fade_in_master = 0
         self.__width = width
         self.__invert = invert
         self.__base = base
@@ -500,17 +528,19 @@ class FX():
 
         if self.__invert:
             v *=-1
-
-        out = v *size +base
+    
+        #if self.__fade_in_master < 255:
+        #    self.__fade_in_master += v*size
+        out = v *size +base 
         self.out = out
         self.count = count
-        return out
+        return out #* (self.__fade_in_master /255.)
 
 class DMXCH(object):
     def __init__(self):
         self._base_value = 0
         self._fade  = None
-        self._fx    = None
+        self._fx    = [None,None] # None
         self._fx_value = 0
 
         self._flash    = None
@@ -528,17 +558,18 @@ class DMXCH(object):
                 print( "Except:fade",e,target,ftime,clock)
     def fx(self,xtype="sinus",size=40,speed=40,invert=0,width=100,start=0,offset=0,base="", clock=0,master=None):
         print([self,xtype,size,speed,start,offset,base, clock])
+        self._fx[0] = self._fx[1]
         if str(xtype).lower() == "off":
             fx_value = self._fx_value
             if fx_value != 0:
                 cprint("???????______ FX OFF AS FADE",fx_value,0,255)
-                self._fx = Fade(fx_value,0,ftime=0.5,clock=clock)#,delay=delay)
+                self._fx[1] = Fade(fx_value,0,ftime=0.5,clock=clock) 
             else:
-                #self._fx = Fade(self._fx_value,target=0,ftime=2,clock=clock) 
-                self._fx = None
+                self._fx[1] = None
                 self._fx_value = 0 
         else:
-            self._fx = FX(xtype=xtype,size=size,speed=speed,invert=invert,width=width,start=start,offset=offset,base=base,clock=clock,master=master)
+            self._fx[1] = FX(xtype=xtype,size=size,speed=speed,invert=invert,width=width,start=start,offset=offset,base=base,clock=clock,master=master) 
+
     def flash(self,target,ftime=0,clock=0,delay=0):
         if str(target).lower() == "off":
             self._flash = None
@@ -595,11 +626,15 @@ class DMXCH(object):
         
         if self._flash_fx is not None:# is FX:
             fx_value = self._flash_fx.next(clock)
-        elif self._fx is not None and self._flash is None:# is FX:
-            self._fx_value = self._fx.next(clock)
+        else:
+            self._fx_value = 0
+            if self._fx[-1] is not None and self._flash is None:# is FX:
+                self._fx_value += self._fx[-1].next(clock)
+            #if self._fx[0] is not None and self._flash is None:# is FX:
+            #    self._fx_value += self._fx[0].next(clock)
             fx_value = self._fx_value
 
-        self._last_val = value+fx_value
+        self._last_val = value + fx_value
         return self._last_val
 
 Bdmx = []
@@ -645,94 +680,100 @@ def JCB(data): #json client input
             for x in cmds:
                 #cprint(int(clock.time()*1000)/1000,end=" ",color="yellow")#time.time())
                 #cprint("json", x,type(x),color="yellow")#,cmds[x])
-
-                if "DMX" in x:
-                    DMX = int(x["DMX"])
-                else:continue
-                if DMX > 0:
-                    DMX -=1
-                else:continue
-
-                if "VALUE" in x:# and x["VALUE"] is not None:
-                    v = x["VALUE"]
-                else:continue
-                if "FX" in x:# and x["VALUE"] is not None:
-                    fx = x["FX"]
-                else:fx=""
-                if "FX2" in x:# and x["VALUE"] is not None:
-                    fx2 = x["FX2"]
-                else:fx2={}
-                if "FADE" in x:
-                    ftime = x["FADE"]
-                else:ftime=0
-                if "DELAY" in x:
-                    delay = x["DELAY"]
-                else:delay=0
-
-                if len(Bdmx) < DMX:
-                    continue
-                
-                if v is not None:
-                    if "FLASH" in x:
-                        #print("FLASH")
-                        Bdmx[DMX].flash(target=v,ftime=ftime, clock=c,delay=delay)
-                    else:
-                        #print("FADE")
-                        Bdmx[DMX].fade(target=v,ftime=ftime, clock=c,delay=delay)
-                
-                if type(fx2) is dict and fx2:
-
-                    #cprint("FX2",DMX,fx2,color="green")
-                    xtype="fade"
-                    size  = 10
-                    speed = 10
-                    start = 0
-                    offset= 0
-                    width=100
-                    invert=0
-                    base = "-"
-                    if "TYPE" in fx2:
-                        xtype = fx2["TYPE"]
-                    if "SIZE" in fx2:
-                        size = fx2["SIZE"]
-                    if "SPEED" in fx2:
-                        speed = fx2["SPEED"]
-                    if "OFFSET" in fx2:
-                        offset = fx2["OFFSET"]
-                    if "BASE" in fx2:
-                        base = fx2["BASE"]
-                    if "INVERT" in fx2:
-                        invert = fx2["INVERT"]
-                    if "WIDTH" in fx2:
-                        width = fx2["WIDTH"]
+                if "CMD" in x:
+                    print("CMD:",x)
+                    if "SPEED-MASTER" == x["CMD"]:
+                        speed_master.val("SPEED-{}".format(x["NR"]),x["VALUE"])
+                    if "SIZE-MASTER" == x["CMD"]:
+                        size_master.val("SIZE-{}".format(x["NR"]),x["VALUE"])
+                else:
+                    if "DMX" in x:
+                        DMX = int(x["DMX"])
+                    else:continue
+                    if DMX > 0:
+                        DMX -=1
+                    else:continue
+
+                    if "VALUE" in x:# and x["VALUE"] is not None:
+                        v = x["VALUE"]
+                    else:continue
+                    if "FX" in x:# and x["VALUE"] is not None:
+                        fx = x["FX"]
+                    else:fx=""
+                    if "FX2" in x:# and x["VALUE"] is not None:
+                        fx2 = x["FX2"]
+                    else:fx2={}
+                    if "FADE" in x:
+                        ftime = x["FADE"]
+                    else:ftime=0
+                    if "DELAY" in x:
+                        delay = x["DELAY"]
+                    else:delay=0
+
+                    if len(Bdmx) < DMX:
+                        continue
+                    
+                    if v is not None:
+                        if "FLASH" in x:
+                            #print("FLASH")
+                            Bdmx[DMX].flash(target=v,ftime=ftime, clock=c,delay=delay)
+                        else:
+                            #print("FADE")
+                            Bdmx[DMX].fade(target=v,ftime=ftime, clock=c,delay=delay)
                     
-                    if "off" == x["VALUE"]: #fix fx flash off
-                        xtype= "off"
-
-                    if "alloff" == xtype.lower():
-                        for i in Bdmx:
-                            if i is not None:
-                                i.flash_fx(xtype="off",clock=c)
-                                i.fx(xtype="off",clock=c)
-
-                    if "FLASH" in x:
-                        Bdmx[DMX].flash_fx(xtype=xtype,size=size,speed=speed,invert=invert,width=width,start=start,offset=offset,base=base,clock=c,master=master_fx)
-                    else:
-                        Bdmx[DMX].fx(xtype=xtype,size=size,speed=speed,invert=invert,width=width,start=start,offset=offset,base=base,clock=c,master=master_fx)
-
-                elif type(fx) is str and fx:  # old fx like sinus:200:12:244 
-                    ccm = str(DMX+1)+":"+fx
-                    print("fx",ccm)
-                    if "FLASH" in x:
-                        CB({"cmd":"fxf"+ccm})
-                    else:
-                        CB({"cmd":"fx"+ccm})
+                    if type(fx2) is dict and fx2:
+
+                        #cprint("FX2",DMX,fx2,color="green")
+                        xtype="fade"
+                        size  = 10
+                        speed = 10
+                        start = 0
+                        offset= 0
+                        width=100
+                        invert=0
+                        base = "-"
+                        if "TYPE" in fx2:
+                            xtype = fx2["TYPE"]
+                        if "SIZE" in fx2:
+                            size = fx2["SIZE"]
+                        if "SPEED" in fx2:
+                            speed = fx2["SPEED"]
+                        if "OFFSET" in fx2:
+                            offset = fx2["OFFSET"]
+                        if "BASE" in fx2:
+                            base = fx2["BASE"]
+                        if "INVERT" in fx2:
+                            invert = fx2["INVERT"]
+                        if "WIDTH" in fx2:
+                            width = fx2["WIDTH"]
+                        
+                        if "off" == x["VALUE"]: #fix fx flash off
+                            xtype= "off"
+
+                        if "alloff" == xtype.lower():
+                            for i in Bdmx:
+                                if i is not None:
+                                    i.flash_fx(xtype="off",clock=c)
+                                    i.fx(xtype="off",clock=c)
+
+                        if "FLASH" in x:
+                            Bdmx[DMX].flash_fx(xtype=xtype,size=size,speed=speed,invert=invert,width=width,start=start,offset=offset,base=base,clock=c,master=master_fx)
+                        else:
+                            Bdmx[DMX].fx(xtype=xtype,size=size,speed=speed,invert=invert,width=width,start=start,offset=offset,base=base,clock=c,master=master_fx)
+
+                    elif type(fx) is str and fx:  # old fx like sinus:200:12:244 
+                        ccm = str(DMX+1)+":"+fx
+                        print("fx",ccm)
+                        if "FLASH" in x:
+                            CB({"cmd":"fxf"+ccm})
+                        else:
+                            CB({"cmd":"fx"+ccm})
 
             cprint("{:0.04} sec.".format(time.time()-t_start),color="yellow")
             cprint("{:0.04} t.".format(time.time()),color="yellow")
         except Exception as e:
             cprint("EXCEPTION JCB",e,color="red")
-            cprint("----",jdata,color="red")
+            cprint("----",str(jdata)[:150],"...",color="red")
             cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
     cprint()
     cprint("{:0.04} sec.".format(time.time()-t_start),color="yellow")