Changeset - d8202a0a7fd5
[Not reviewed]
default
0 7 0
Drew Perttula - 13 years ago 2012-06-13 04:27:48
drewp@bigasterisk.com
fix up musicpad and wavecurve. ascoltami2 can now use relative paths in the config
Ignore-this: eb95f50f54f14275f1f031ccb7fbb97f
7 files changed with 14 insertions and 16 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -253,26 +253,26 @@ def main():
 

	
 
    curveset = Curveset(sliders=opts.sliders)
 
    subterms = []
 

	
 
    curveset.load(basename=os.path.join(
 
        showconfig.curvesDir(),
 
        showconfig.songFilenameFromURI(song)),
 
                  skipMusic=opts.skip_music)
 

	
 
    subtermPath = graphPathForSubterms(song)
 
    try:
 
        graph.parse(subtermPath, format='n3')
 
    except urllib2.URLError, e:
 
        if e.reason.errno != 2:
 
    except IOError, e:
 
        if e.errno != 2:
 
            raise
 
        log.info("%s not found, starting with empty graph" % subtermPath)
 
    
 
    log.debug("startup: output %s", time.time() - startTime)
 
    out = Output(subterms, music)
 

	
 
    musicfilename = showconfig.songOnDisk(song)
 
    maxtime = wavelength(musicfilename)
 
    dispatcher.connect(lambda: maxtime, "get max time", weak=False)
 

	
 
    start = Main(graph, opts, song, curveset, subterms, music)
 

	
bin/listsongs
Show inline comments
 
#!/usr/bin/python
 
#!bin/python
 

	
 
"""for completion, print the available song uris on stdout
 

	
 
in .zshrc:
 

	
 
function _songs { local expl;  _description files expl 'songs';  compadd "$expl[@]" - `${LIGHT9_SHOW}/../../bin/listsongs` }
 
compdef _songs curvecalc
 
"""
 

	
 
import run_local
 
from light9 import showconfig
 
from light9.namespaces import L9
bin/musicPad
Show inline comments
 
#!/usr/bin/python
 
#!bin/python
 
"""
 
rewrite all the songs with silence at the start and end
 
"""
 
import sys, wave, logging, os
 
sys.path.append(".")
 
from light9 import showconfig
 
from light9.namespaces import L9
 
from light9.ascoltami.playlist import Playlist
 
logging.basicConfig(level=logging.INFO)
 
log = logging.getLogger()
 

	
 
introPad = 4
 
postPad = 9 # 5 + autostop + 4
 

	
 
playlist = Playlist.fromShow(showconfig.getGraph(), showconfig.showUri())
 
# instead of taking a show uri like it should, i just convert every
 
# path i find in the graph (hoping that you only loaded statements for
 
# the current show)
 
for p in playlist.allSongPaths():
 
    log.info("read %s", p)
 
    inputWave = wave.open(p, 'r')
 

	
 
    outputDir = os.path.join(os.path.dirname(p), "pad")
 
    try:
 
        os.makedirs(outputDir)
 
    except OSError:
 
        pass # exists
 
    outputPath = os.path.join(outputDir, os.path.basename(p))
 
    outputWave = wave.open(outputPath, 'w')
 
    outputWave.setparams(inputWave.getparams())
bin/wavecurve
Show inline comments
 
#!/usr/bin/env python
 
#!bin/python
 
import optparse
 
import run_local
 
from light9.wavepoints import simp
 

	
 
def createCurve(inpath, outpath, t):
 
    print "reading %s, writing %s" % (inpath, outpath)
 
    points = simp(inpath.replace('.ogg', '.wav'), seconds_per_average=t)
 

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

	
 
@@ -22,21 +22,21 @@ parser.add_option("-a", "--all", action=
 
                  help="make standard curves for all songs")
 
options,args = parser.parse_args()
 

	
 
if options.all:
 
    from light9 import showconfig
 
    from light9.namespaces import L9
 
    from rdflib import RDF
 
    from light9.ascoltami.playlist import Playlist
 
    graph = showconfig.getGraph()
 

	
 
    playlist = Playlist.fromShow(showconfig.getGraph(), showconfig.showUri())
 
    for song in playlist.allSongs():
 
        inpath = playlist.songPath(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/ascoltami/player.py
Show inline comments
 
@@ -23,25 +23,25 @@ class Player(object):
 
        self.autoStopTime = 0
 
        self.onEOS = onEOS
 
        
 
        # before playbin2:
 
        #self.pipeline = gst.parse_launch("filesrc name=file location=%s ! wavparse name=src ! audioconvert ! alsasink name=out" % songFile)
 

	
 
        gobject.timeout_add(50, self.watchTime)
 

	
 
        bus = self.pipeline.get_bus()
 
        bus.add_signal_watch()
 

	
 
        def on_any(bus, msg):
 
            print bus, msg, msg.type
 
            #print bus, msg, msg.type
 
            if msg.type == gst.MESSAGE_EOS:
 
                if self.onEOS is not None:
 
                    self.onEOS(self.getSong())
 
        bus.connect('message', on_any)
 

	
 
        def onStreamStatus(bus, message):
 
            print "streamstatus", bus, message
 
            (statusType, _elem) = message.parse_stream_status()
 
            if statusType == gst.STREAM_STATUS_TYPE_ENTER:
 
                self.setupAutostop()
 
        bus.connect('message::stream-status', onStreamStatus)
 

	
light9/ascoltami/playlist.py
Show inline comments
 
from light9.showconfig import getSongsFromShow
 
from light9.showconfig import getSongsFromShow, songOnDisk
 
from light9.namespaces import L9
 

	
 
class NoSuchSong(ValueError):
 
    """Raised when a song is requested that doesn't exist (e.g. one
 
    after the last song in the playlist)."""
 

	
 
class Playlist(object):
 
    def __init__(self, graph, playlistUri):
 
        self.graph = graph
 
        self.songs = list(graph.items(playlistUri))
 
    def nextSong(self, currentSong):
 
        """Returns the next song in the playlist or raises NoSuchSong if 
 
@@ -16,34 +16,35 @@ class Playlist(object):
 
            currentIndex = self.songs.index(currentSong)
 
        except IndexError:
 
            raise ValueError("%r is not in the current playlist (%r)." % \
 
                (currentSong, self.playlistUri))
 

	
 
        try:
 
            nextSong = self.songs[currentIndex + 1]
 
        except IndexError:
 
            raise NoSuchSong("%r is the last item in the playlist." % \
 
                             currentSong)
 

	
 
        return nextSong
 

	
 
    def allSongs(self):
 
        """Returns a list of all song URIs in order."""
 
        return self.songs
 
    
 
    def allSongPaths(self):
 
        """Returns a list of the filesystem paths to all songs in order."""
 
        paths = []
 
        for song in self.songs:
 
            paths.append(self.songPath(song))
 
            paths.append(songOnDisk(song))
 
        return paths
 
    
 
    def songPath(self, uri):
 
        """filesystem path to a song"""
 
        p = self.graph.value(uri, L9['showPath'])
 
        assert p.startswith("file://"), p
 
        return p[len("file://"):]
 
        raise NotImplementedError("see showconfig.songOnDisk")
 
        # maybe that function should be moved to this method
 

	
 
    @classmethod
 
    def fromShow(playlistClass, graph, show):
 
        playlistUri = graph.value(show, L9['playList'])
 
        if not playlistUri:
 
            raise ValueError("%r has no l9:playList" % show)
 
        return playlistClass(graph, playlistUri)
light9/showconfig.py
Show inline comments
 
@@ -65,25 +65,25 @@ def findMpdHome():
 

	
 
def songOnDisk(song):
 
    """given a song URI, where's the on-disk file that mpd would read?"""
 
    graph = getGraph()
 
    root = graph.value(showUri(), L9['musicRoot'])
 
    if not root:
 
        raise ValueError("%s has no :musicRoot" % showUri())
 
    
 
    name = graph.value(song, L9['songFilename'])
 
    if not name:
 
        raise ValueError("Song %r has no :songFilename" % song)
 

	
 
    return path.join(root, name)
 
    return path.abspath(path.join(root, name))
 

	
 
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 getSongsFromShow(graph, show):
 
    playList = graph.value(show, L9['playList'])
0 comments (0 inline, 0 general)