Changeset - 7771f37252da
[Not reviewed]
default
0 4 1
Drew Perttula - 18 years ago 2007-06-12 07:12:32
drewp@bigasterisk.com
curvecalc persistence, wavecurve -a option
5 files changed with 132 insertions and 30 deletions:
0 comments (0 inline, 0 general)
bin/ascoltami
Show inline comments
 
@@ -9,12 +9,27 @@ features and limitations:
 

	
 
  xmlrpc interface for:
 
    getting the current time in the playing song
 
    requesting what song is playing
 
    saying what song should play
 

	
 

	
 
setup:
 

	
 
get mpd root path correct
 

	
 
run mpd that's been modified to give precise times:
 
  dash(pts/21):/my/dl/modified/mpd% src/mpd --no-daemon
 

	
 
tell it to scan
 
  mpc update
 
  (mpc listall   to check)
 
  
 
run ascoltami
 

	
 

	
 
todo:
 

	
 

	
 
"""
 

	
 
from __future__ import division,nested_scopes
bin/curvecalc
Show inline comments
 
@@ -17,20 +17,21 @@ try:
 
    from dispatch import dispatcher
 
except ImportError:
 
    import louie as dispatcher 
 
from twisted.internet import reactor,tksupport
 
import twisted
 
from twisted.web.xmlrpc import Proxy
 
from rdflib import Literal, URIRef
 
from rdflib import Literal, URIRef, RDF
 
from rdflib.Graph import Graph
 
import logging
 
log = logging.getLogger()
 
logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s")
 
log.setLevel(logging.DEBUG)
 

	
 
import run_local
 
from light9 import Submaster, dmxclient, networking, showconfig
 
from light9 import Submaster, dmxclient, networking, showconfig, prof
 
from light9.TLUtility import make_attributes_from_args, dict_subset
 
from light9.zoomcontrol import Zoomcontrol
 
from light9.curve import Curve, Curveview, Curveset, Curvesetview
 
from light9.wavelength import wavelength
 
from light9.uihelpers import toplevelat
 
from light9.namespaces import L9
 
@@ -254,19 +255,12 @@ def create_status_lines(master):
 
        l = tk.Label(master,anchor='w',justify='left')
 
        l.pack(side='top',fill='x')
 
        dispatcher.connect(lambda val,l=l,sn=signame,tf=textfilter:
 
                           l.config(text=sn+": "+tf(val)),
 
                           signame,weak=0)
 

	
 
def savesubterms(filename,subterms):
 
    s=""
 
    for st in subterms:
 
        s=s+"%s %s\n" % (st.submaster.name, st.subexpr.expr)
 
    
 
    file(filename,'w').write(s)
 

	
 
class SubtermSetView(tk.Frame):
 
    def __init__(self, master, *args, **kw):
 
        tk.Frame.__init__(self, master, *args, **kw)
 
        self.cur_row = 0
 
        self.cur_col = 0
 
        self.ncols = 2
 
@@ -281,13 +275,13 @@ class SubtermSetView(tk.Frame):
 

	
 
def add_one_subterm(graph, sub, curveset, subterms, root, ssv, expr=None):
 
    subname = graph.label(sub)
 
    if expr is None:
 
        expr = '%s(t)' % subname
 

	
 
    term = Subterm(Submaster.Submaster(sub), Subexpr(curveset,expr))
 
    term = Subterm(Submaster.Submaster(graph=graph, sub=sub), Subexpr(curveset,expr))
 
    subterms.append(term)
 

	
 
    stv=Subtermview(ssv,term)
 
    # stv.pack(side='top',fill='x')
 

	
 
    ssv.add_subtermview(stv)
 
@@ -311,19 +305,38 @@ def sub_commands_tk(master, curveset, su
 
    entry = tk.Entry(f, textvariable=newname)
 
    entry.pack(side='left', fill='x', exp=1)
 
    entry.bind("<Key-Return>", lambda evt: add_cmd())
 

	
 
    return f
 

	
 
def savesubterms(filename,subterms):
 
    raise NotImplementedError
 
    s=""
 
    for st in subterms:
 
        s=s+"%s %s\n" % (st.submaster.name, st.subexpr.expr)
 
    
 
    file(filename,'w').write(s)
 

	
 
def createSubtermGraph(song, subterms):
 
    """rdf graph describing the subterms, readable by add_subterms_for_song"""
 
    graph = Graph()
 
    for subterm in subterms:
 
        uri = URIRef(song + "/subterm/" + subterm.submaster.name)
 
        graph.add((song, L9['subterm'], uri))
 
        graph.add((uri, RDF.type, L9['Subterm']))
 
        graph.add((uri, L9['sub'], L9['sub/%s' % subterm.submaster.name]))
 
        graph.add((uri, L9['expression'], Literal(subterm.subexpr.expr)))
 
    return graph
 

	
 
def add_subterms_for_song(graph, song, curveset, subterms, root, ssv):
 
    for st in graph.objects(song, L9['subterm']):
 
        add_one_subterm(graph, graph.value(st, L9['sub']), curveset, subterms,
 
                        root, ssv, graph.value(st, L9['expression']))
 

	
 
def songFilename(uri):
 
    return uri.split('/')[-1]
 
def graphPathForSubterms(song):
 
    return showconfig.subtermsForSong(showconfig.songFilenameFromURI(song)) + ".n3"
 

	
 
#######################################################################
 
root=tk.Tk()
 
root.tk_setPalette("gray50")
 
toplevelat("curvecalc",root)
 
root.tk_focusFollowsMouse()
 
@@ -353,26 +366,33 @@ graph = showconfig.getGraph()
 
root.title("Curvemaster 3000MX - %s" % graph.label(song))
 

	
 
musicfilename = showconfig.songOnDisk(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(), songFilename(song)))
 
curveset.load(basename=os.path.join(showconfig.curvesDir(), showconfig.songFilenameFromURI(song)))
 

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

	
 
add_subterms_for_song(graph, song, curveset, subterms, root, ssv)
 
try:
 
    g = Graph()
 
    g.parse(graphPathForSubterms(song), format='n3')
 
    add_subterms_for_song(g, song, curveset, subterms, root, ssv)
 
except OSError, e:
 
    print e
 

	
 
log.debug("output")
 
out = Output(subterms, music)
 

	
 
def savekey(*args):
 
    print "saving",song
 
    savesubterms(showconfig.subtermsForSong(songFilename(song)), subterms)
 
    curveset.save(basename=os.path.join(showconfig.curvesDir(), songFilename(song)))
 
    g = createSubtermGraph(song, subterms)
 
    g.serialize(graphPathForSubterms(song), format="nt")
 

	
 
    curveset.save(basename=os.path.join(showconfig.curvesDir(), showconfig.songFilenameFromURI(song)))
 
    print "saved"
 
    
 
root.bind("<Control-Key-s>",savekey)
 
root.bind("<Control-Key-r>", lambda evt: dispatcher.send('reload all subs'))
 

	
 
create_status_lines(root)
 
@@ -388,12 +408,8 @@ for helpline in ["Bindings: C-s save sub
 

	
 
root.bind("<Control-Key-q>",lambda ev: reactor.stop)
 
root.bind("<Destroy>",lambda ev: reactor.stop)
 
root.protocol('WM_DELETE_WINDOW', reactor.stop)
 
tksupport.install(root,ms=20)
 
log.debug("run")
 
if 0:
 
    sys.path.append("/home/drewp/projects/cuisine/pour")
 
    from utils import runstats
 
    runstats("reactor.run()")
 
else:
 
    reactor.run()
 
prof.run(reactor.run, profile=False)
 

	
bin/wavecurve
Show inline comments
 
#!/usr/bin/env python
 
import os, sys, optparse
 
import run_local
 
from light9.wavepoints import simp
 

	
 
parser = optparse.OptionParser(usage="%prog inputSong.wav outputCurve")
 

	
 
def createCurve(inpath, outpath, t):
 
    print "reading %s, writing %s" % (inpath, outpath)
 
    points = simp(inpath, seconds_per_average=t)
 

	
 
    f = file(outpath, 'w')
 
    for time_val in points:
 
        print >>f, "%s %s" % time_val
 
    
 

	
 

	
 
parser = optparse.OptionParser(usage="""%prog inputSong.wav outputCurve
 

	
 
You probably just want -a
 

	
 
""")
 
parser.add_option("-t",type="float",default=.01,
 
                  help="seconds per sample (default .01, .07 is smooth)")
 
parser.add_option("-a", action="store_true",
 
                  help="make standard curves for all songs")
 
options,args = parser.parse_args()
 

	
 
inpath,outpath = args
 

	
 
points = simp(inpath, seconds_per_average=options.t)
 

	
 
f = file(outpath, 'w')
 
for time_val in points:
 
    print >>f, "%s %s" % time_val
 
if options.a:
 
    from light9 import showconfig
 
    from light9.namespaces import L9
 
    from rdflib import RDF
 
    graph = showconfig.getGraph()
 
    for song in graph.subjects(RDF.type, L9['Song']):
 
        inpath = showconfig.songOnDisk(song)
 
        for curveName, t in [('music', .01),
 
                             ('smooth_music', .07)]:
 
            outpath = showconfig.curvesDir() + "/%s-%s" % (
 
                showconfig.songFilenameFromURI(song), curveName)
 
            createCurve(inpath, outpath, t)
 
else:
 
    inpath,outpath = args
 
    createCurve(inpath, outpath, options.t)
light9/prof.py
Show inline comments
 
new file 100644
 
import hotshot, hotshot.stats
 
import sys, traceback
 

	
 
def run(main, profile=False):
 
    if not profile:
 
        main()
 
        return
 
    
 
    p = hotshot.Profile("/tmp/pro")
 
    p.runcall(main)
 
    p.close()
 
    hotshot.stats.load("/tmp/pro").sort_stats('time').print_stats()
 
    
 
def watchPoint(filename, lineno, event="call"):
 
    """whenever we hit this line, print a stack trace. event='call'
 
    for lines that are function definitions, like what a profiler
 
    gives you.
 

	
 
    Switch to 'line' to match lines inside functions. Execution speed
 
    will be much slower."""
 
    seenTraces = {} # trace contents : count
 
    def trace(frame, ev, arg):
 
        if ev == event:
 
            if (frame.f_code.co_filename, frame.f_lineno) == (filename, lineno):
 
                stack = ''.join(traceback.format_stack(frame))
 
                if stack not in seenTraces:
 
                    print "watchPoint hit"
 
                    print stack
 
                    seenTraces[stack] = 1
 
                else:
 
                    seenTraces[stack] += 1
 

	
 
        return trace
 
    sys.settrace(trace)
 

	
 
    # atexit, print the frequencies?
light9/showconfig.py
Show inline comments
 
@@ -63,17 +63,26 @@ def songInMpd(song):
 

	
 
def songOnDisk(song):
 
    graph = getGraph()
 
    songFullPath = path.join(root(), graph.value(song, L9['showPath']))
 
    return songFullPath
 

	
 
def songFilenameFromURI(uri):
 
    """
 
    'http://light9.bigasterisk.com/show/dance2007/song8' -> 'song8'
 

	
 
    everything that uses this should be deprecated for real URIs
 
    everywhere"""
 
    assert isinstance(uri, URIRef)
 
    return uri.split('/')[-1]
 

	
 
def curvesDir():
 
    return path.join(root(),"curves")
 

	
 
def songFilename(song):
 
    return path.join(musicDir(),"%s.wav" % song)
 
    return path.join(root(), "music", "%s.wav" % song)
 

	
 
def subtermsForSong(song):
 
    return path.join(root(),"subterms",song)
 

	
 
def subFile(subname):
 
    return path.join(root(),"subs",subname)
0 comments (0 inline, 0 general)