Changeset - 5bfcf309e1ad
[Not reviewed]
default
0 2 0
David McClosky - 20 years ago 2005-06-17 19:57:29
dmcc@bigasterisk.com
Submaster objects listen for a signal to reload, curvecalc can broadcast it
Also, an easter egg change: "Something I shoulda done a long time ago!"
2 files changed with 16 insertions and 6 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -215,19 +215,23 @@ def add_one_subterm(subname, curveset, s
 
    # stv.pack(side='top',fill='x')
 

	
 
    ssv.add_subtermview(stv)
 

	
 
    return term
 

	
 
def subterm_adder(master, curveset, subterms, root, ssv):
 
def sub_commands_tk(master, curveset, subterms, root, ssv):
 
    f=tk.Frame(master,relief='raised',bd=1)
 
    newname = tk.StringVar()
 

	
 
    def add_cmd():
 
        add_one_subterm(newname.get(), curveset, subterms, root, ssv, '')
 

	
 
    def reload_subs():
 
        dispatcher.send('reload all subs')
 

	
 
    tk.Button(f, text="reload subs", command=reload_subs).pack(side='left')
 
    tk.Button(f,text="new subterm named:", command=add_cmd).pack(side='left')
 
    tk.Entry(f,textvariable=newname).pack(side='left',fill='x',exp=1)
 
    return f
 
    
 
#######################################################################
 
root=tk.Tk()
 
@@ -253,22 +257,23 @@ curveset = Curveset()
 
csv = Curvesetview(root,curveset)
 
csv.pack(side='top',fill='both',exp=1)
 

	
 
ssv = SubtermSetView(root)
 
ssv.pack(side='top', fill='x')
 

	
 
root.title("Curemaster 2000MX - %s" % song)
 
root.title("Curvemaster 3000MX - %s" % song)
 

	
 
musicfilename = showconfig.songFilename(song)
 
maxtime = wavelength(musicfilename)
 
dispatcher.send("max time",maxtime=maxtime)
 
dispatcher.connect(lambda: maxtime, "get max time",weak=0)
 
curveset.load(basename=os.path.join(showconfig.curvesDir(),song))
 

	
 
subterms = []
 
subterm_adder(root, curveset, subterms, root, ssv).pack(side='top',fill='x')
 
sub_commands_tk(root, curveset, subterms, root, ssv).pack(side='top',fill='x')
 

	
 
for line in file(showconfig.subtermsForSong(song)):
 
    try:
 
        subname,expr = line.strip().split(" ",1)
 
    except ValueError:
 
        subname = line.strip()
 
        expr = ""
 
@@ -282,13 +287,12 @@ out = Output(subterms)
 

	
 
def savekey(*args):
 
    print "saving",song
 
    savesubterms(showconfig.subtermsForSong(song),subterms)
 
    curveset.save(basename=os.path.join(showconfig.curvesDir(),song))
 
    print "saved"
 

	
 
    
 
root.bind("<Control-Key-s>",savekey)
 

	
 
create_status_lines(root)
 
for helpline in ["Bindings: C-s save subterms; B1 drag point; C-B1 curve add point; 1..5 add point at time; Esc see current time; S-Esc see curtime to end; Mousewheel zoom; C-p play/pause music at mouse",
 
                 "Available in functions: nsin/ncos period=amp=1; within(a,b) bef(x) aft(x) compare to time; smoove(x) cubic smoothstep; curvename(t) eval curve"]:
light9/Submaster.py
Show inline comments
 
from __future__ import division
 
import os
 
from light9.TLUtility import dict_scale, dict_max
 
from light9 import Patch, showconfig
 
import dispatch.dispatcher as dispatcher
 

	
 
class Submaster:
 
    "Contain a dictionary of levels, but you didn't need to know that"
 
    def __init__(self, name, leveldict=None, temporary=0):
 
        self.name = name
 
        self.temporary = temporary
 
        if leveldict:
 
            self.levels = leveldict
 
        else:
 
            self.levels = {}
 
            self.reload()
 
    def reload(self):
 
            self.reload(quiet=True)
 
        dispatcher.connect(self.reload, 'reload all subs')
 
    def reload(self, quiet=False):
 
        if self.temporary:
 
            return
 
        try:
 
            oldlevels = self.levels.copy()
 
            self.levels.clear()
 
            subfile = file(showconfig.subFile(self.name))
 
            for line in subfile.readlines():
 
                if not line.strip(): # if line is only whitespace
 
                    continue # "did i say newspace?"
 

	
 
@@ -27,12 +30,15 @@ class Submaster:
 
                    name, val = line.split(':')
 
                    name = name.strip()
 
                    self.levels[name] = float(val)
 
                except ValueError:
 
                    print "(%s) Error with this line: %s" % (self.name, 
 
                        line[:-1])
 

	
 
                if (not quiet) and (oldlevels != self.levels):
 
                    print "sub %s changed" % self.name
 
        except IOError:
 
            print "Can't read file for sub: %s" % self.name
 
    def save(self):
 
        if self.temporary:
 
            print "not saving temporary sub named",self.name
 
            return
0 comments (0 inline, 0 general)