changeset 211:9b360ee8636e

move patchdata into show/, pull out curve.py from curvecalc, more networking.py unification
author drewp@bigasterisk.com
date Sun, 10 Apr 2005 21:34:10 +0000
parents f41004d5a507
children a65a1634fce4
files bin/curvecalc light9/Patch.py light9/networking.py light9/patchdata.py show/dance2004/patchdata.py
diffstat 5 files changed, 67 insertions(+), 349 deletions(-) [+]
line wrap: on
line diff
--- a/bin/curvecalc	Sun Apr 10 20:54:14 2005 +0000
+++ b/bin/curvecalc	Sun Apr 10 21:34:10 2005 +0000
@@ -14,301 +14,14 @@
 from twisted.web.xmlrpc import Proxy
 
 import run_local
-from light9 import Submaster, dmxclient
+from light9 import Submaster, dmxclient, networking
 from light9.TLUtility import make_attributes_from_args
 from light9.zoomcontrol import Zoomcontrol
+from light9.curve import Curve, Curveview, Curveset, Curvesetview
 
 sys.path.append("../../semprini")
 from lengther import wavelength # for measuring duration of .wav
 
-class Curve:
-    """curve does not know its name. see Curveset"""
-    points = None # x-sorted list of (x,y)
-    def __init__(self):
-        self.points = [(0,0),(10,0)]
-
-    def load(self,filename):
-        self.points[:]=[]
-        for line in file(filename):
-            self.points.append(tuple([float(a) for a in line.split()]))
-        self.points.sort()
-        dispatcher.send("points changed",sender=self)
-
-    def save(self,filename):
-        if filename.endswith('-music') or filename.endswith('_music'):
-            print "not saving music track"
-            return
-        f = file(filename,'w')
-        for p in self.points:
-            f.write("%s %s\n" % p)
-        f.close()
-
-    def eval(self,t):
-        i = bisect_left(self.points,(t,None))-1
-
-        if self.points[i][0]>t:
-            return self.points[i][1]
-        if i>=len(self.points)-1:
-            return self.points[i][1]
-
-        p1,p2 = self.points[i],self.points[i+1]
-        frac = (t-p1[0])/(p2[0]-p1[0])
-        y = p1[1]+(p2[1]-p1[1])*frac
-        return y
-
-    def insert_pt(self,new_pt):
-        i = bisect(self.points,(new_pt[0],None))
-        self.points.insert(i,new_pt)
-    __call__=eval
-
-class Curveview(tk.Canvas):
-    def __init__(self,master,curve,**kw):
-        self.curve=curve
-        self._time = 0
-        tk.Canvas.__init__(self,master,width=10,height=10,
-                           relief='sunken',bd=1,
-                           closeenough=5,takefocus=1, **kw)
-        self.selected_points=[] # idx of points being dragged
-        self.update()
-        # self.bind("<Enter>",self.focus)
-        dispatcher.connect(self.input_time,"input time")
-        dispatcher.connect(self.update,"zoom changed")
-        dispatcher.connect(self.update,"points changed",sender=self.curve)
-        self.bind("<Configure>",self.update)
-        for x in range(1, 6):
-            def add_kb_marker_point(evt, x=x):
-                print "add_kb_marker_point", evt
-                self.add_point((self.current_time(), (x - 1) / 4.0))
-
-            self.bind("<Key-%s>" % x, add_kb_marker_point)
-
-
-        for butnum,factor in (5, 1.5),(4, 1/1.5):
-            self.bind("<ButtonPress-%s>"%butnum,
-                      lambda ev,factor=factor:
-                      dispatcher.send("zoom about mouse",
-                                      t=self.world_from_screen(ev.x,0)[0],
-                                      factor=factor))
-        self.bind("<Key-Escape>",lambda ev:
-                  dispatcher.send("see time",
-                                  t=self.current_time()))
-    def current_time(self):
-        return self._time
-
-    def screen_from_world(self,p):
-        start,end = self.zoom
-        ht = self.winfo_height()
-        return (p[0]-start)/(end-start)*self.winfo_width(), (ht-5)-p[1]*(ht-10)
-    def world_from_screen(self,x,y):
-        start,end = self.zoom
-        ht = self.winfo_height()
-        return x/self.winfo_width()*(end-start)+start, ((ht-5)-y)/(ht-10)
-    
-    def input_time(self,val):
-        t=val
-        pts = self.screen_from_world((val,0))+self.screen_from_world((val,1))
-        self.delete('timecursor')
-        self.create_line(*pts,**dict(width=2,fill='red',tags=('timecursor',)))
-        self._time = t
-    def update(self,*args):
-
-        self.zoom = dispatcher.send("zoom area")[0][1]
-        cp = self.curve.points
-
-        visible_x = (self.world_from_screen(0,0)[0],
-                     self.world_from_screen(self.winfo_width(),0)[0])
-
-        visleftidx = max(0,bisect_left(cp,(visible_x[0],None))-1)
-        visrightidx = min(len(cp)-1,bisect_left(cp,(visible_x[1],None))+1)
-                             
-        visible_points = cp[visleftidx:visrightidx+1]
-        visible_idxs = range(visleftidx,visrightidx+1)
-        
-        self.delete('curve')
-
-        self._draw_markers(visible_x)
-        
-        self._draw_line(visible_idxs,visible_points)
-        
-        self.dots = {} # idx : canvas rectangle
-
-        if len(visible_points)<50:
-            self._draw_handle_points(visible_idxs,visible_points)
-
-    def _draw_markers(self,visible_x):
-        mark = self._draw_one_marker
-
-        mark(0,"0")
-        t1,t2=visible_x
-        if t2-t1<30:
-            for t in range(int(t1),int(t2)+1):
-                mark(t,str(t))
-        mark(-4,"-4")
-
-        endtimes = dispatcher.send("get max time")
-        if endtimes:
-            endtime = endtimes[0][1]
-            mark(endtime,"end %.1f"%endtime)
-            mark(endtime+10,"post %.1f"%(endtime+10))
-        
-    def _draw_one_marker(self,t,label):
-        x = self.screen_from_world((t,0))[0]
-        self.create_line(x,self.winfo_height(),x,self.winfo_height()-20,
-                         tags=('curve',))
-        self.create_text(x,self.winfo_height()-20,text=label,anchor='s',
-                         tags=('curve',))
-
-
-    def _draw_line(self,visible_idxs,visible_points):
-        linepts=[]
-        step=1
-        linewidth=2
-        if len(visible_points)>800:
-            step = int(len(visible_points)/800)
-            linewidth=1
-        for p in visible_points[::step]:
-            linepts.extend(self.screen_from_world(p))
-        if len(linepts)<4:
-            return
-        line = self.create_line(*linepts,**dict(width=linewidth,tags='curve'))
-
-        # canvas doesnt have keyboard focus, so i can't easily change the
-        # cursor when ctrl is pressed
-        #        def curs(ev):
-        #            print ev.state
-        #        self.bind("<KeyPress>",curs)
-        #        self.bind("<KeyRelease-Control_L>",lambda ev: curs(0))
-        self.tag_bind(line,"<Control-ButtonPress-1>",self.newpointatmouse)
-
-
-    def _draw_handle_points(self,visible_idxs,visible_points):
-        for i,p in zip(visible_idxs,visible_points):
-            rad=3
-            worldp = p
-            p = self.screen_from_world(p)
-            dot = self.create_rectangle(p[0]-rad,p[1]-rad,p[0]+rad,p[1]+rad,
-                                        outline='black',fill='blue',
-                                        tags=('curve','point', 'handle%d' % i))
-            if worldp[1] == 0:
-                rad += 3
-                dot2 = self.create_oval(p[0]-rad,p[1]-rad,
-                                             p[0]+rad,p[1]+rad,
-                                             outline='darkgreen',
-                                             tags=('curve','point', 'handle%d' % i))
-            self.tag_bind('handle%d' % i,"<ButtonPress-1>",
-                          lambda ev,i=i: self.dotpress(ev,i))
-            self.bind("<Motion>",
-                      lambda ev,i=i: self.dotmotion(ev,i))
-            self.bind("<ButtonRelease-1>",
-                      lambda ev,i=i: self.dotrelease(ev,i))
-            self.dots[i]=dot
-
-        self.highlight_selected_dots()
-        
-
-    def newpointatmouse(self, ev):
-        p = self.world_from_screen(ev.x,ev.y)
-        x, y = p
-        y = max(0, y)
-        y = min(1, y)
-        p = x, y
-        self.add_point(p)
-
-    def add_point(self, p):
-        self.unselect()
-        self.curve.insert_pt(p)
-        self.update()
-
-    def highlight_selected_dots(self):
-        for i,d in self.dots.items():
-            if i in self.selected_points:
-                self.itemconfigure(d,fill='red')
-            else:
-                self.itemconfigure(d,fill='blue')
-        
-    def dotpress(self,ev,dotidx):
-        self.selected_points=[dotidx]
-        self.highlight_selected_dots()
-
-    def dotmotion(self,ev,dotidx):
-        cp = self.curve.points
-        moved=0
-        for idx in self.selected_points:
-            x,y = self.world_from_screen(ev.x,ev.y)
-            y = max(0,min(1,y))
-            if idx>0 and x<=cp[idx-1][0]:
-                continue
-            if idx<len(cp)-1 and x>=cp[idx+1][0]:
-                continue
-            moved=1
-            cp[idx] = (x,y)
-        if moved:
-            self.update()
-    def unselect(self):
-        self.selected_points=[]
-        self.highlight_selected_dots()
-        
-    def dotrelease(self,ev,dotidx):
-        self.unselect()
-        
-class Curveset:
-    curves = None # curvename : curve
-    def __init__(self):
-        self.curves = {}
-    def load(self,basename):
-        """find all files that look like basename-curvename and add
-        curves with their contents"""
-        for filename in glob.glob("%s-*"%basename):
-            curvename = filename[filename.find('-')+1:]
-            c=Curve()
-            c.load(filename)
-            curvename = curvename.replace('-','_')
-            self.add_curve(curvename,c)            
-    def save(self,basename):
-        """writes a file for each curve with a name
-        like basename-curvename"""
-        for name,cur in self.curves.items():
-            cur.save("%s-%s" % (basename,name))
-    def add_curve(self,name,curve):
-        self.curves[name] = curve
-        dispatcher.send("add_curve",sender=self,name=name)
-    def globalsdict(self):
-        return self.curves.copy()
-    def new_curve(self,name):
-        if name=="":
-            print "no name given"
-            return
-        while name in self.curves:
-           name=name+"-1"
-
-        self.add_curve(name,Curve())
-
-
-class Curvesetview(tk.Frame):
-    curves = None # curvename : Curveview
-    def __init__(self,master,curveset,**kw):
-        self.curves = {}
-        self.curveset = curveset
-        tk.Frame.__init__(self,master,**kw)
-        
-        f = tk.Frame(self,relief='raised',bd=1)
-        f.pack(side='top',fill='x')
-        tk.Button(f,text="new curve named:",
-                  command=lambda: self.curveset.new_curve(self.newcurvename.get())).pack(side='left')
-        self.newcurvename = tk.StringVar()
-        tk.Entry(f,textvariable=self.newcurvename).pack(side='left',
-                                                        fill='x',exp=1)
-        
-        
-        dispatcher.connect(self.add_curve,"add_curve",sender=self.curveset)
-    def add_curve(self,name):
-        f = tk.Frame(self,relief='raised',bd=1)
-        f.pack(side='top',fill='both',exp=1)
-        tk.Label(f,text="curve %r"%name,width=15).pack(side='left')
-        cv = Curveview(f,self.curveset.curves[name])
-        cv.pack(side='right',fill='both',exp=1)
-        self.curves[name] = cv
-
 class Music:
     def __init__(self):
         self.player=None # xmlrpc Proxy to player
@@ -317,7 +30,7 @@
     def current_time(self):
         """return deferred which gets called with the current time"""
         if self.player is None:
-            self.player = Proxy("http://miles:8040")
+            self.player = Proxy(networking.musicUrl())
 #            d = self.player.callRemote("songlength")
 #            d.addCallback(lambda l: dispatcher.send("max time",maxtime=l))
 #            d = self.player.callRemote("songname")
--- a/light9/Patch.py	Sun Apr 10 20:54:14 2005 +0000
+++ b/light9/Patch.py	Sun Apr 10 21:34:10 2005 +0000
@@ -1,3 +1,5 @@
+import os
+
 def resolve_name(channelname):
     "Ensure that we're talking about the primary name of the light."
     return get_channel_name(get_dmx_channel(channelname))
@@ -26,10 +28,11 @@
 
 def reload_data():
     global patch, reverse_patch
-    import light9.patchdata
 
-    reload(light9.patchdata)
-    loadedpatch = light9.patchdata.patch
+    loc = {}
+    execfile(os.path.join(os.getenv("LIGHT9_SHOW"),"patchdata.py"), loc)
+    
+    loadedpatch = loc['patch']
     patch = {}
     reverse_patch = {}
     for k, v in loadedpatch.items():
--- a/light9/networking.py	Sun Apr 10 20:54:14 2005 +0000
+++ b/light9/networking.py	Sun Apr 10 21:34:10 2005 +0000
@@ -9,3 +9,5 @@
 def dmxServerPort():
     return 8030
     
+def musicUrl():
+    return "http://localhost:8040"
--- a/light9/patchdata.py	Sun Apr 10 20:54:14 2005 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-patch = {
-    
-    ('side l','sidepost1') : 45, # posts
-    ('side r','sidepost2') : 46,
-    
-    ('god',) : 6,
-    
-    'house': 68,
-    ('ramp1','dolly-ramp-l','b11',): 54, # left bank over house
-    ('main-l-blue', 'b12',): 53,
-    ('ramp2', 'b13',): 52,
-    ('main-lc-fill', 'b14',): 51,
-    ('main-c1', 'b15',): 50,
-    ('main-r-red','b16',): 49,
-    ('ramp6','b21',): 55, # mid bank
-    ('ramp5','b22',): 56,
-    ('ramp0-stairs','b23',): 57,
-    ('main-c2', 'b24',): 58,
-    ('ramp9-stairs', 'stairs-r', 'b25',): 59,
-    ('ramp3', 'b26',): 60,
-    ('ramp4', 'b31',): 61, # right bank
-    ('main-l-red', 'b32',): 62,
-    ('main-c3', 'b33',): 63,
-    ('main-r-blue', 'b34',): 64,
-    ('ramp8', 'dolly-ramp-r', 'b35',) : 65,
-    ('ramp7', 'b36',): 66,
-
-    'oran1':21,    'oran2':25,    'oran3':29,    'oran4':33,
-    'gree1':22,    'gree2':26,    'gree3':30,    'gree4':34,
-    'blue1':23,    'blue2':27,    'blue3':31,    'blue4':35,
-    'red1' :24,    'red2' :28,    'red3' :32,    'red4' :36,
-
-    # hello dolly
-    'f1' : 1,
-    'f1.5' : 3,
-    'f2' : 4,
-    'f3' : 5,
-    'f4' : 7,
-    'f5' : 8,
-    'diag' : 9,
-    'f6' : 10,
-    'diag-back' : 11,
-    'f7' : 12,
-
-    'downfill-left' : 13,
-    'downfill-right' : 14,
-    'l-scp' : 40,
-    'r-scp' : 37,
-    'upstairs above' : 39,
-    'upstairs front' : 15,
-    'storefill' : 17,
-    'dayback' : 41,
-    'judge' : 19,
-    ('c-scp', 'c-scoop') : 38,
-    'candles' : 42,
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/show/dance2004/patchdata.py	Sun Apr 10 21:34:10 2005 +0000
@@ -0,0 +1,56 @@
+patch = {
+    
+    ('side l','sidepost1') : 45, # posts
+    ('side r','sidepost2') : 46,
+    
+    ('god',) : 6,
+    
+    'house': 68,
+    ('ramp1','dolly-ramp-l','b11',): 54, # left bank over house
+    ('main-l-blue', 'b12',): 53,
+    ('ramp2', 'b13',): 52,
+    ('main-lc-fill', 'b14',): 51,
+    ('main-c1', 'b15',): 50,
+    ('main-r-red','b16',): 49,
+    ('ramp6','b21',): 55, # mid bank
+    ('ramp5','b22',): 56,
+    ('ramp0-stairs','b23',): 57,
+    ('main-c2', 'b24',): 58,
+    ('ramp9-stairs', 'stairs-r', 'b25',): 59,
+    ('ramp3', 'b26',): 60,
+    ('ramp4', 'b31',): 61, # right bank
+    ('main-l-red', 'b32',): 62,
+    ('main-c3', 'b33',): 63,
+    ('main-r-blue', 'b34',): 64,
+    ('ramp8', 'dolly-ramp-r', 'b35',) : 65,
+    ('ramp7', 'b36',): 66,
+
+    'oran1':21,    'oran2':25,    'oran3':29,    'oran4':33,
+    'gree1':22,    'gree2':26,    'gree3':30,    'gree4':34,
+    'blue1':23,    'blue2':27,    'blue3':31,    'blue4':35,
+    'red1' :24,    'red2' :28,    'red3' :32,    'red4' :36,
+
+    # hello dolly
+    'f1' : 1,
+    'f1.5' : 3,
+    'f2' : 4,
+    'f3' : 5,
+    'f4' : 7,
+    'f5' : 8,
+    'diag' : 9,
+    'f6' : 10,
+    'diag-back' : 11,
+    'f7' : 12,
+
+    'downfill-left' : 13,
+    'downfill-right' : 14,
+    'l-scp' : 40,
+    'r-scp' : 37,
+    'upstairs above' : 39,
+    'upstairs front' : 15,
+    'storefill' : 17,
+    'dayback' : 41,
+    'judge' : 19,
+    ('c-scp', 'c-scoop') : 38,
+    'candles' : 42,
+}