Changeset - f852fcae4951
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 13 years ago 2012-06-16 02:57:49
drewp@bigasterisk.com
when music isn't playing, vidref follows the time your mouse is hovering over in curvecalc
Ignore-this: c4f4237ae822ac6f72bfee6687b20238
2 files changed with 15 insertions and 5 deletions:
0 comments (0 inline, 0 general)
light9/vidref/main.py
Show inline comments
 
@@ -5,20 +5,21 @@
 
dvcam test
 
gst-launch dv1394src ! dvdemux name=d ! dvdec ! ffmpegcolorspace ! hqdn3d ! xvimagesink
 

	
 
"""
 
import pygst
 
pygst.require("0.10")
 
import gst, gobject, time, jsonlib, restkit, logging, os, traceback
 
import gst, gobject, time, json, restkit, logging, os, traceback
 
import gtk
 
from twisted.python.util import sibpath
 
import Image
 
from threading import Thread
 
from Queue import Queue
 
from light9 import networking
 
from light9.vidref.replay import ReplayViews, songDir, takeDir, framerate
 
from restkit.errors import ResourceNotFound
 

	
 
log = logging.getLogger()
 

	
 
class MusicTime(object):
 
    """
 
    fetch times from ascoltami in a background thread; return times
 
@@ -34,12 +35,13 @@ class MusicTime(object):
 
        make up times between the samples, and we'll just run off the
 
        end of a song)
 
        """
 
        self.period = period
 
        self.onChange = onChange
 
        self.musicResource = restkit.Resource(networking.musicPlayer.url)
 
        self.curveCalc = restkit.Resource(networking.curveCalc.url)
 
        t = Thread(target=self._timeUpdate)
 
        t.setDaemon(True)
 
        t.start()
 

	
 
    def getLatest(self):
 
        """
 
@@ -47,19 +49,25 @@ class MusicTime(object):
 
        """
 
        if not hasattr(self, 'position'):
 
            return {'t' : 0, 'song' : None}
 
        pos = self.position.copy()
 
        if pos['playing']:
 
            pos['t'] = pos['t'] + (time.time() - self.positionFetchTime)
 
        else:
 
            try:
 
                r = self.curveCalc.get("hoverTime")
 
            except ResourceNotFound:
 
                pass
 
            else:
 
                pos['hoverTime'] = json.loads(r.body_string())['hoverTime']
 
        return pos
 

	
 
    def _timeUpdate(self):
 
        while True:
 
            try:
 
                position = jsonlib.loads(self.musicResource.get("time").body_string(),
 
                                         use_float=True)
 
                position = json.loads(self.musicResource.get("time").body_string())
 

	
 
                # this is meant to be the time when the server gave me its
 
                # report, and I don't know if that's closer to the
 
                # beginning of my request or the end of it (or some
 
                # fraction of the way through)
 
                self.positionFetchTime = time.time()
 
@@ -70,13 +78,13 @@ class MusicTime(object):
 
                log.error(e)
 
                time.sleep(1)
 
            time.sleep(self.period)
 

	
 
    def sendTime(self, t):
 
        """request that the player go to this time"""
 
        self.musicResource.post("time", payload=jsonlib.dumps({"t" : t}),
 
        self.musicResource.post("time", payload=json.dumps({"t" : t}),
 
                                headers={"content-type" : "application/json"})
 
        
 
class VideoRecordSink(gst.Element):
 
    _sinkpadtemplate = gst.PadTemplate ("sinkpadtemplate",
 
                                        gst.PAD_SINK,
 
                                        gst.PAD_ALWAYS,
 
@@ -113,12 +121,13 @@ class VideoRecordSink(gst.Element):
 
        if not position['song']:
 
            print "no song" # todo: this prints too much when the player has no song
 
            return gst.FLOW_OK
 

	
 
        try:
 
            cap = buffer.caps[0]
 
            #print "cap", (cap['width'], cap['height'])
 
            img = Image.fromstring('RGB', (cap['width'], cap['height']),
 
                                   buffer.data)
 
            self.imagesToSave.put((position, img, buffer.timestamp))
 
        except:
 
            traceback.print_exc()
 

	
light9/vidref/replay.py
Show inline comments
 
@@ -172,13 +172,14 @@ class ReplayView(object):
 
        # done by declaring the widget dirty and then reacting to a
 
        # paint message if one comes
 

	
 
        if not self.enabled:
 
            return
 
        
 
        inPic = self.replay.findClosestFrame(position['t'] + lag)
 
        t = position.get('hoverTime', position['t'])
 
        inPic = self.replay.findClosestFrame(t + lag)
 

	
 
        if inPic == self.showingPic:
 
            return
 
        with gtk.gdk.lock:
 
            self.picWidget.set_from_file(inPic)
 
            if 0:
0 comments (0 inline, 0 general)