changeset 765:f852fcae4951

when music isn't playing, vidref follows the time your mouse is hovering over in curvecalc Ignore-this: c4f4237ae822ac6f72bfee6687b20238
author drewp@bigasterisk.com
date Sat, 16 Jun 2012 02:57:49 +0000
parents 0300715a365f
children 08962051d516
files light9/vidref/main.py light9/vidref/replay.py
diffstat 2 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/light9/vidref/main.py	Sat Jun 16 02:54:21 2012 +0000
+++ b/light9/vidref/main.py	Sat Jun 16 02:57:49 2012 +0000
@@ -8,7 +8,7 @@
 """
 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
@@ -16,6 +16,7 @@
 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()
 
@@ -37,6 +38,7 @@
         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()
@@ -50,13 +52,19 @@
         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
@@ -73,7 +81,7 @@
 
     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):
@@ -116,6 +124,7 @@
 
         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))
--- a/light9/vidref/replay.py	Sat Jun 16 02:54:21 2012 +0000
+++ b/light9/vidref/replay.py	Sat Jun 16 02:57:49 2012 +0000
@@ -174,8 +174,9 @@
 
         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