Browse Source

update: FX-STATIC, 2D:XX , cleanup

micha 1 năm trước cách đây
mục cha
commit
c4abb2e14d
6 tập tin đã thay đổi với 123 bổ sung138 xóa
  1. 1 0
      .gitignore
  2. 13 0
      ToDo.txt
  3. 51 45
      _LibreLightDesk.py
  4. 52 90
      _console.py
  5. 5 2
      tkgui/dialog.py
  6. 1 1
      tkgui/draw.py

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 *.pyc
 __pycache__
 *.swp
+*~

+ 13 - 0
ToDo.txt

@@ -0,0 +1,13 @@
+
+- Midi Timecode
+- Artnet Timecode
+- SWAP Button
+- BTN FL FADE-IN
+
+
+difficult
+- rewrite core in ZIG (realtime)
+
+- LTC / SMPTE Timecode
+- Sound input trigger
+- TOGGLE Button 

+ 51 - 45
_LibreLightDesk.py

@@ -785,11 +785,11 @@ DELAY.val(0.2)
 
 fx_prm_move = {"SIZE":40,"SPEED":8,"OFFSET":100,"BASE":"0","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":0,"WING":2,"WIDTH":100}
 
-fx_prm      = {"SIZE":255,"SPEED":10,"OFFSET":100,"BASE":"-","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":1,"SHUFFLE":0,"WING":2,"WIDTH":25,"FX-X":1,"FX:MODE":0}
+fx_prm      = {"SIZE":255,"SPEED":10,"OFFSET":100,"BASE":"-","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":1,"SHUFFLE":0,"WING":2,"WIDTH":25,"2D-X":1,"2D:MODE":0}
 fx_x_modes    = ["spiral","left","right","up","down","left_right","up_down"]
 
 fx_modes    = ["RED","GREEN","BLUE","MAG","YELLOW","CYAN"]
-fx_mo       = ["fade","on","rnd","ramp","ramp2","cosinus","sinus"]
+fx_mo       = ["fade","on","rnd","ramp","ramp2","cosinus","sinus","static"]
 
 class FX_handler():
     def __init__():
@@ -973,6 +973,8 @@ def process_effect(wing_buffer,fx_name=""):
                     fx = "fade"
                 elif "RND" in fx_name:
                     fx = "rnd"
+                elif "STATIC" in fx_name:
+                    fx = "static"
                 elif "ON" in fx_name:
                     fx = "on"
                 elif "RAMP2" in fx_name:
@@ -1152,8 +1154,8 @@ def process_effect(wing_buffer,fx_name=""):
 
 def process_matrix(xfixtures):
     fix_count = len(xfixtures)
-    fx_x = fx_prm["FX-X"]
-    fx_mod = fx_x_modes[fx_prm["FX:MODE"]]
+    fx_x = fx_prm["2D-X"]
+    fx_mod = fx_x_modes[fx_prm["2D:MODE"]]
     cprint("----",fx_x,fx_mod)
     if fx_x > 1 and fix_count > fx_x:
         try: 
@@ -1206,41 +1208,43 @@ class Xevent_fx():
     def fx(self,event):
         cprint("Xevent.fx",self.attr,self.fix,event)
         fx2 = {}
-        if event.num == 4:
-            cprint("FX:COLOR CHANGE",fx_prm,color="red")
-            txt = "FX:RED" 
-            fx_prm["MODE"] += 1
-            if fx_prm["MODE"] >= len(fx_modes):
-                fx_prm["MODE"]=0
-            txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
-
-            master.fx.elem["FX:RED"]["text"] = txt
-        elif event.num == 5:
-            cprint("FX:COLOR CHANGE",fx_prm,color="red")
-            txt = "FX:RED" 
-            fx_prm["MODE"] -= 1
-            if fx_prm["MODE"] < 0:
-                fx_prm["MODE"]= len(fx_modes)-1
-            txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
-            master.fx.elem["FX:RED"]["text"] = txt
-
-        if event.num == 4:
-            cprint("FX-X: CHANGE",fx_prm,color="red")
-            txt = "FX-X:" 
-            fx_prm["FX:MODE"] += 1
-            if fx_prm["FX:MODE"] >= len(fx_x_modes):
-                fx_prm["FX:MODE"]=0
-            txt = "FX:MODE\n"+fx_x_modes[fx_prm["FX:MODE"]]
-
-            master.fx.elem["FX:MODE"]["text"] = txt
-        elif event.num == 5:
-            cprint("FX-X: CHANGE",fx_prm,color="red")
-            txt = "FX-X:" 
-            fx_prm["FX:MODE"] -= 1
-            if fx_prm["FX:MODE"] < 0:
-                fx_prm["FX:MODE"]= len(fx_x_modes)-1
-            txt = "FX:MODE\n"+fx_x_modes[fx_prm["FX:MODE"]]
-            master.fx.elem["FX:MODE"]["text"] = txt
+        if self.attr == "FX:RED":
+            if event.num == 4:
+                cprint("FX:COLOR CHANGE",fx_prm,color="red")
+                txt = "FX:RED" 
+                fx_prm["MODE"] += 1
+                if fx_prm["MODE"] >= len(fx_modes):
+                    fx_prm["MODE"]=0
+                txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
+
+                master.fx.elem["FX:RED"]["text"] = txt
+            elif event.num == 5:
+                cprint("FX:COLOR CHANGE",fx_prm,color="red")
+                txt = "FX:RED" 
+                fx_prm["MODE"] -= 1
+                if fx_prm["MODE"] < 0:
+                    fx_prm["MODE"]= len(fx_modes)-1
+                txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
+                master.fx.elem["FX:RED"]["text"] = txt
+
+        if self.attr.startswith("2D"):
+            if event.num == 4:
+                cprint("2D-X: CHANGE",fx_prm,color="red")
+                txt = "2D-X:" 
+                fx_prm["2D:MODE"] += 1
+                if fx_prm["2D:MODE"] >= len(fx_x_modes):
+                    fx_prm["2D:MODE"]=0
+                txt = "2D:MODE\n"+fx_x_modes[fx_prm["2D:MODE"]]
+
+                master.fx.elem["2D:MODE"]["text"] = txt
+            elif event.num == 5:
+                cprint("2D-X: CHANGE",fx_prm,color="red")
+                txt = "2D-X:" 
+                fx_prm["2D:MODE"] -= 1
+                if fx_prm["2D:MODE"] < 0:
+                    fx_prm["2D:MODE"]= len(fx_x_modes)-1
+                txt = "2D:MODE\n"+fx_x_modes[fx_prm["2D:MODE"]]
+                master.fx.elem["2D:MODE"]["text"] = txt
 
         elif event.num == 1:
             xfixtures = []
@@ -1441,9 +1445,9 @@ class Xevent_fx():
                     prm[k] =5
                 ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
                 cprint(prm)
-            elif self.attr.startswith("FX-X:"):#SIN":
+            elif self.attr.startswith("2D-X:"):#SIN":
                 #global prm
-                k = "FX-X"
+                k = "2D-X"
                 if event.num == 1:
                     prm[k] = 1
                 elif event.num == 3:
@@ -1458,7 +1462,7 @@ class Xevent_fx():
                     prm[k] =1
                     
                 txt = prm[k] 
-                ct.elem[self.attr]["text"] = "FX-X:\n{}".format(prm[k])
+                ct.elem[self.attr]["text"] = "2D-X:\n{}".format(prm[k])
                 cprint(prm)
             elif self.attr.startswith("WING:"):#SIN":
                 #global prm
@@ -1516,6 +1520,8 @@ class Xevent_fx():
                 elif event.num == 5:
                     prm[k] = "0"
                 ct.elem[self.attr]["text"] = "BASE:\n{}".format(prm[k])
+            elif self.attr.startswith("2D:"):#SIN":
+                self.fx(event)
             elif self.attr.startswith("FX:"):#SIN":
                 self.fx(event)
 
@@ -2581,10 +2587,10 @@ class MASTER():
         self.fx = Elem_Container()
         self.fx.commands =[
                 "FX:DIM","FX:RED", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
-                ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","FX-X:\n-","FX:MODE"
+                ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","2D-X:\n-","2D:MODE"
                 ]
         self.fx_generic = Elem_Container()
-        self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON"] 
+        self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","FX:STATIC"] 
 
         self.commands = Elem_Container()
         self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
@@ -5330,7 +5336,7 @@ if __run_main:
         window_manager.top(name)
 
     name="FX"
-    args = {"title":name,"master":0,"width":415,"height":297,"left":L1+10+W1,"top":TOP+302,"resize":0}
+    args = {"title":name,"master":0,"width":415,"height":297+30,"left":L1+10+W1,"top":TOP+302,"resize":1}
     geo = split_window_position(pos_list,name)
     if geo:
         args.update(geo)

+ 52 - 90
_console.py

@@ -166,6 +166,7 @@ class Fade():
         self.__start = start
         self.__last = start
         self.__target = target
+        self.abs = 0
         self.run = 1
         self.end = 0
         self.off = 0
@@ -344,13 +345,13 @@ class FX():
         self.old_v = -1
         self.run = 1
         self.count = -1
+        self.abs = 0 # ABSOLUT
         self.__angel = self.__clock_curr*360%360
         if master is None:
             cprint(master, "MASTER_FX ERR",master,color="red")
             self.__master = MASTER_FX()
             self.__master.add(self)
         else:
-            #cprint( "MASTER_FX OK",master,color="red")
             self.__master = master
             self.__master.add(self)
         if self.__xtype == "rnd":
@@ -360,7 +361,6 @@ class FX():
         self._exec_id = None
 
         self.next()
-        #print("init FX",self)
 
     def exec_id(self,_id=None):
         if type(_id) is not type(None):
@@ -368,53 +368,58 @@ class FX():
         return self._exec_id
 
     def _get_info(self):
-        #print("self.__offset",self.__offset)
         return {"offset":self.__offset,"xtype":self.__xtype}
-        #return self.next(),self.__xtype, self.__size,self.__speed,self.__angel, self.__base,self.__clock_curr,self.run 
 
     def __str__(self):
         return self.__repr__()
 
     def __repr__(self):
-        return "<FX Next:{:0.2f} xtype:{} Size:{:0.2f} Speed:{:0.2f} ang:{:0.2f} base:{} Clock:{:0.2f} run:{} EXEC:{}>".format( 
+        ABS = "INC"
+        if self.abs:
+            ABS = "ABS"
+        return "<FX Next:{:0.2f} xtype:{} Size:{:0.2f} Speed:{:0.2f} ang:{:0.2f} base:{} Clock:{:0.2f} run:{} EXEC:{} :{}>".format( 
                     self.next(), self.__xtype, self.__size, self.__speed, self.__angel
-                    , self.__base, self.__clock_curr, self.run, self._exec_id )
+                    , self.__base, self.__clock_curr, self.run, self._exec_id,ABS )
+
+    #def _calc_fx(self):
+    def _calc_fx(self,v,t,size,base):
+        base = 0
+        if self.__base == "-": # sub
+            if self.__invert:
+                v = 1-v
+                size *=-1
+            v *=-1
+        elif self.__base == "+": # sub
+            if self.__invert:
+                v = v-1
+        else:
+            v = (t%1-0.5)
 
     def next(self,clock=None):
         if type(clock) is float or type(clock) is int:#not None:
             self.__clock_curr = clock
         
         d  = (self.__clock_curr - self.__clock_old) 
-
-        #print()
-        #print("A",d)
         
         m1 = ( speed_master.val(self.__master_id)) # global speed-master
-        #print("B {:0.4}".format(m1))
-
         m2 = ( exec_speed_master.val(self._exec_id)) # exec start by 0
-        #print("C {:0.4}".format(m2))
 
         shift  = 0
         m = (m1 * m2)  -1
         shift += d * m
-        #print("D",shift)
 
         self.__clock_delta += shift
-
-        #print(self.__clock_delta )
         self.__clock_old = self.__clock_curr
-
         
         t = self.__clock_curr
         t += self.__clock_delta
         t *= self.__speed / 60 
+
         offset2 = self.__offset 
         offset2 *= exec_offset_master.val(self._exec_id) 
-        #t += self.__offset / 100 #255 #1024 #255
+
         t += offset2 / 100 
         t += self.__start  / 1024 #255
-        #t = t*speed_master.val(self.__master_id)
 
         tw = t%1
         count = t//1
@@ -426,6 +431,7 @@ class FX():
         t = t%1
         rad = math.radians(self.__angel)
 
+        self.abs = 0
         v=0
         out = 0
         base = 0
@@ -446,57 +452,30 @@ class FX():
 
             v/=2
         elif self.__xtype == "rnd":
-            #base = 0
             if self.__angel > 90 and self.__angel <=270:
                 v=1
             else:
                 v=0
-            #if count != self.count and v: # % 2 == 0:#!= self.count:
-            #    #self.__offset = random.randint(0,1024)# /1024
-            #    self.__master._shuffle()
             
             if count != self.count and v == 0: # and v: # % 2 == 0:#!= self.count:
                  self.__master.next(self)#,count)
-            #self.__master.next(self)#,count)
             self.__offset = self.__master.get(self,count)
                 
-            base = 0
-            if self.__base == "-": # sub
-                if self.__invert:
-                    v = 1-v
-                    #base = -size
-                    size *=-1
-                v *=-1
-            elif self.__base == "+": # sub
-                if self.__invert:
-                    v = v-1
-            else:
-                v = (t%1-0.5)
+            self._calc_fx(v,t,size,base)
+
         elif self.__xtype == "on":
-            #base = 0
             if self.__angel > 90 and self.__angel <=270:
                 v=1
             else:
                 v=0
-            base = 0
-            if self.__base == "-": # sub
-                if self.__invert:
-                    v = 1-v
-                    #base = -size
-                    size *=-1
-                v *=-1
-            elif self.__base == "+": # sub
-                if self.__invert:
-                    v = v-1
-            else:
-                v = (t%1-0.5)
+            self._calc_fx(v,t,size,base)
+
         elif self.__xtype == "ramp" or self.__xtype == "ramp":
             v = (t%1) 
             base = 0
             if self.__base == "-": # sub
                 if self.__invert:
                     v = 1-v
-                    #base = -size
                     size *=-1
                 v *=-1
             elif self.__base == "+": # sub
@@ -504,25 +483,21 @@ class FX():
                     v = v-1
             else:
                 v = (t%1-0.5)
+            self._calc_fx(v,t,size,base)
 
 
+        elif self.__xtype == "static":
+            self.abs = 1
+            base = size #100
+            v=0
+            size=0
+            
         elif self.__xtype == "ramp2" or self.__xtype == "bump2":
             v = (t%1) 
             v = 1-v  
             if v == 1:
                 v=0
-            base = 0
-            if self.__base == "-": # sub
-                if self.__invert:
-                    v = 1-v
-                    #base = -size
-                    size *=-1
-                v *=-1
-            elif self.__base == "+": # sub
-                if self.__invert:
-                    v = v-1
-            else:
-                v = (t%1-0.5)
+            self._calc_fx(v,t,size,base)
 
         elif self.__xtype == "fade":
             x = t * 2 
@@ -530,10 +505,8 @@ class FX():
                 x = 2-x 
             x -= 0.5
             v = x*2
-            #base /= 2
-            #base *=2 
             if self.__base == "+": # add
-                pass#base /= 2
+                pass
             else:
                 v *= -1
 
@@ -542,15 +515,12 @@ class FX():
         if self.__invert:
             v *=-1
     
-        #if self.__fade_in_master < 255:
-        #    self.__fade_in_master += v*size
         out = v *size +base 
         self.out = out
         self.count = count
 
         out = out * size_master.val(self.__master_id)  # master 
         out = out * exec_size_master.val(self._exec_id)  # master 
-        #* (self.__fade_in_master /255.)
         return out 
 
 class DMXCH(object):
@@ -571,23 +541,17 @@ class DMXCH(object):
         self._flash_fx_value = 0
         self._last_val = None
         self._exec_ids = [None,None,None,None] # go, go-fx, flash, flash-fx
-        #self.next(clock)
-        #print("init",self)
     
     def fade(self,target,ftime=0,clock=0,delay=0):
         if target != self._base_value:
             try:
                 target = float(target)
                 self._fade = Fade(self._base_value,target,ftime=ftime,clock=clock,delay=delay)
-                #self._fade.next()
-                #self._fade.next()
             except Exception as e:
                 print( "Except:fade",e,target,ftime,clock)
         self.next(clock)
-        #print("init fade",self)
 
     def fx(self,xtype="sinus",size=40,speed=40,invert=0,width=100,start=0,offset=0,base="", clock=0,master=None):
-        #print("DMXCH.fx",[self,xtype,size,speed,start,offset,base, clock])
         self._fx[0] = self._fx[1]
         if str(xtype).lower() == "off":
             fx_value = self._fx_value
@@ -604,18 +568,15 @@ class DMXCH(object):
             self._fx[1].exec_id(self._exec_ids[1])
 
         self.next(clock)
-        #print("init fx",self)
 
     def flash(self,target,ftime=0,clock=0,delay=0):
         if str(target).lower() == "off":
-            #self._flash = None
             if self._flash:
                 cur_val = self._flash.next()
-                #cur_tar = self._fade.next()
                 cur_tar = self._base_value
                 self._flash = Fade(cur_val,cur_tar,ftime=ftime,clock=clock) 
                 self._flash.off = 1
-        else:#elif target != self._base_value:
+        else:
             try:
                 target = float(target)
                 self._flash = Fade(self._last_val,target,ftime=ftime,clock=clock,delay=delay)
@@ -623,7 +584,6 @@ class DMXCH(object):
             except Exception as e:
                 print( "Except:flash",target,ftime,clock,__name__,e,)
         self.next(clock)
-        #print("init flush",self)
 
     def flash_fx(self,xtype="sinus",size=40,speed=40,invert=0,width=100,start=0,offset=0,base="",clock=0,master=None):
         if str(xtype).lower() == "off":
@@ -672,25 +632,24 @@ class DMXCH(object):
             cprint("Exception DMXCH.next()" ,e)
         out = self._last_val
         return out
+
     def _next(self,clock=0):
         value = self._base_value
-        #self._last_val = value
-        #return value
-        #if self._dmx == 1024:
-        #    print(self)
         
         if self._last_val is None:
             self._last_val = value
         fx_value = self._fx_value
+        fx_abs = 0
 
         if self._flash is not None:
             value = self._flash.next(clock)
-            #flicker bug ?!
-            value = self._flash.next(clock)
+            value = self._flash.next(clock) #flicker bug ?!
+
             if self._flash.end == 1 and self._flash.off == 1:
                 self._flash = None
             fx_value = 0
-        elif self._fade is not None:#is Fade:# is Fade:
+
+        elif self._fade is not None: # is Fade: # is Fade:
             self._base_value = self._fade.next(clock)
             self._base_value = self._fade.next(clock) #flicker bug ?!
             value = self._base_value
@@ -698,22 +657,25 @@ class DMXCH(object):
         
         if self._flash_fx is not None:# is FX:
             fx_value = self._flash_fx.next(clock)
+            fx_abs = self._flash_fx.abs
         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)
+                fx_abs = self._fx[-1].abs
             fx_value = self._fx_value
 
-        self._last_val = value + fx_value
-        #self._last_val *= v_master.val(self._fix_id)
+        if fx_abs == 1:
+            self._last_val = fx_value
+        else:
+            self._last_val = value + fx_value
+
 
         if self._v_master_id in V_MASTER:
             vm = V_MASTER[self._v_master_id].next(clock)
-            #print("V_MASTER is ", V_MASTER[self._v_master_id])
             vm = vm/256
-            self._last_val *= vm # v_master.val(self._v_master_id)
+            self._last_val *= vm 
 
-        #out = self._last_val * htp_master.master_by_dmx(self._dmx)
         out = self._last_val
         return out
 

+ 5 - 2
tkgui/dialog.py

@@ -286,10 +286,13 @@ class Dialog():
         self.e7.bind("<Key>",self._event)
         self.e7.bind("<Button>",self._event)
         self.e7.pack(side="left")
-
-        self.el2 = tk.Label(self.f2,text="",anchor="w",width=9)
+        self.el2 = tk.Label(self.f2,text="* only GO",anchor="w",width=9)
         self.el2.config(fg="#aaa")
         self.el2.pack(side="left")
+
+        #self.el2 = tk.Label(self.f2,text="",anchor="w",width=9)
+        #self.el2.config(fg="#aaa")
+        #self.el2.pack(side="left")
         self.e1 = self.e
  
 

+ 1 - 1
tkgui/draw.py

@@ -523,7 +523,7 @@ def _draw_fx(frame,c,r,gui,mode="FX"):
             b["bg"] = "grey"
         elif comm == "FX OFF":
             b["bg"] = "magenta"
-        elif comm[:3] == "FX:":
+        elif comm[:3] == "FX:" or comm[:3] == "2D:":
             b["text"] = comm
             b["bg"] = "#ffbf00"
         elif comm[:3] == "MO:":