changeset 541:edb75a48fcb8

vidref now finds and plays back multiple takes of the current song Ignore-this: 951b6526b8e2af0e261c11d93bb1e255
author drewp@bigasterisk.com
date Sun, 13 Jun 2010 09:41:45 +0000
parents 15169d92c4b7
children cfd5d5be1b50
files bin/vidref light9/vidref/main.py light9/vidref/replay.py light9/vidref/vidref.glade
diffstat 4 files changed, 172 insertions(+), 146 deletions(-) [+]
line wrap: on
line diff
--- a/bin/vidref	Sun Jun 13 09:41:13 2010 +0000
+++ b/bin/vidref	Sun Jun 13 09:41:45 2010 +0000
@@ -6,7 +6,7 @@
 sys.path.append(".")
 from light9.vidref.main import Main
 
- # then vidref file cleanup, livevideo ui elements, input picker. find replay dirs correctly. show multiple replays. trash. reorder/pin.
+ # find replay dirs correctly. show multiple replays. trash. reorder/pin.
                 
 
 logging.basicConfig()
--- a/light9/vidref/main.py	Sun Jun 13 09:41:13 2010 +0000
+++ b/light9/vidref/main.py	Sun Jun 13 09:41:45 2010 +0000
@@ -16,7 +16,7 @@
 from threading import Thread
 from Queue import Queue
 from light9 import networking
-from light9.vidref.replay import ReplayViews
+from light9.vidref.replay import ReplayViews, songDir, takeDir
 
 log = logging.getLogger()
 
@@ -109,9 +109,7 @@
         return gst.FLOW_OK
 
     def saveImg(self, position, img, bufferTimestamp):
-        outDir = "/tmp/vidref/play-%s-%d" % (
-            position['song'].split('://')[-1].replace('/','_'),
-            position['started'])
+        outDir = takeDir(songDir(position['song']), position['started'])
         outFilename = "%s/%08.03f.jpg" % (outDir, position['t'])
         if os.path.exists(outFilename): # we're paused on one time
             return
@@ -140,7 +138,9 @@
         mainwin.connect("destroy", gtk.main_quit)
         wtree.connect_signals(self)
 
-        self.replayViews = ReplayViews(wtree.get_object("image1"))#"replayScroll"))
+        wtree.get_object("replayPanel").show()
+        rp = wtree.get_object("replayVbox")
+        self.replayViews = ReplayViews(rp)
 
         mainwin.show_all()
         self.liveVideoXid = wtree.get_object("vid3").window.xid
--- a/light9/vidref/replay.py	Sun Jun 13 09:41:13 2010 +0000
+++ b/light9/vidref/replay.py	Sun Jun 13 09:41:45 2010 +0000
@@ -2,10 +2,15 @@
 from bisect import bisect_left
 from decimal import Decimal
 
-existingDir = "/tmp/vidref/play-_my_proj_light9_show_dance2010_music_01-chorusmix.wav-1276415052"
-existingFrames = sorted([Decimal(f.split('.jpg')[0])
-                         for f in os.listdir(existingDir)])
+
+def songDir(song):
+    return "/tmp/vidref/play-%s" % song.split('://')[-1].replace('/','_')
 
+def takeDir(songDir, startTime):
+    """
+    startTime: unix seconds (str ok)
+    """
+    return os.path.join(songDir, str(int(startTime)))
 
 class ReplayViews(object):
     """
@@ -13,13 +18,12 @@
     these windows to be added
     """
     def __init__(self, parent):
-        self.out = ReplayView(parent, Replay(existingDir))
-        return
-        for x in range(1000):
-            lab = gtk.Label()
-            lab.set_text("hello")
-            parent.add_with_viewport(lab)
-    
+        # today, parent is the vbox the replay windows should appear in
+        self.parent = parent
+        self.lastSong = None
+
+        self.views = []
+     
     def update(self, position):
         """
         freshen all replay windows. We get called this about every
@@ -27,20 +31,21 @@
 
         may be responsible for making new children if we change song
         """
-        self.out.updatePic(position)
+        if position['song'] != self.lastSong:
+            self.loadViewsForSong(position['song'])
+            self.lastSong = position['song']
+        for v in self.views:
+            v.updatePic(position)
+
 
-class Replay(object):
-    """
-    model for one of the replay widgets
-    """
-    def __init__(self, sourceDir):
-        self.sourceDir = sourceDir
-
-    def findClosestFrame(self, t):
-        i = bisect_left(existingFrames, Decimal(str(t)))
-        if i >= len(existingFrames):
-            i = len(existingFrames) - 1
-        return os.path.join(existingDir, "%08.03f.jpg" % existingFrames[i])
+    def loadViewsForSong(self, song):
+        # remove previous ones
+        
+        takes = os.listdir(songDir(song))
+        for take in takes:
+            td = takeDir(songDir(song), take)
+            rv = ReplayView(self.parent, Replay(td))
+            self.views.append(rv)
 
 class ReplayView(object):
     """
@@ -48,8 +53,15 @@
     """
     def __init__(self, parent, replay):
         self.replay = replay
-#        self.loadWindwos
-        self.picWidget = parent
+
+        # this *should* be a composite widget from glade
+        img = gtk.Image()
+        img.set_size_request(320, 240)
+        parent.pack_end(img, False, False)
+        img.show()
+        self.picWidget = img
+        
+#        self.picWidget = parent.get_children()[0].get_child()
         
     def updatePic(self, position):
         inPic = self.replay.findClosestFrame(position['t']+.25)
@@ -60,3 +72,17 @@
                 self.picWidget.queue_draw_area(0,0,320,240)
                 self.picWidget.get_window().process_updates(True)
     
+class Replay(object):
+    """
+    model for one of the replay widgets
+    """
+    def __init__(self, takeDir):
+        self.takeDir = takeDir
+
+    def findClosestFrame(self, t):
+        existingFrames = sorted([Decimal(f.split('.jpg')[0])
+                                 for f in os.listdir(self.takeDir)])
+        i = bisect_left(existingFrames, Decimal(str(t)))
+        if i >= len(existingFrames):
+            i = len(existingFrames) - 1
+        return os.path.join(self.takeDir, "%08.03f.jpg" % existingFrames[i])
--- a/light9/vidref/vidref.glade	Sun Jun 13 09:41:13 2010 +0000
+++ b/light9/vidref/vidref.glade	Sun Jun 13 09:41:45 2010 +0000
@@ -3,6 +3,8 @@
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
   <object class="GtkWindow" id="MainWindow">
+    <property name="width_request">990</property>
+    <property name="height_request">709</property>
     <property name="default_width">500</property>
     <property name="default_height">500</property>
     <child>
@@ -160,123 +162,10 @@
                     <property name="visible">True</property>
                     <property name="resize_mode">queue</property>
                     <child>
-                      <object class="GtkVBox" id="vbox1">
+                      <object class="GtkVBox" id="replayVbox">
                         <property name="visible">True</property>
                         <child>
-                          <object class="GtkHandleBox" id="handlebox1">
-                            <property name="height_request">273</property>
-                            <property name="visible">True</property>
-                            <child>
-                              <object class="GtkHBox" id="hbox1">
-                                <property name="visible">True</property>
-                                <child>
-                                  <object class="GtkAspectFrame" id="aspectframe1">
-                                    <property name="width_request">320</property>
-                                    <property name="height_request">240</property>
-                                    <property name="visible">True</property>
-                                    <property name="label_xalign">0</property>
-                                    <property name="shadow_type">out</property>
-                                    <property name="ratio">1.3300000429153442</property>
-                                    <child>
-                                      <object class="GtkImage" id="image1">
-                                        <property name="width_request">320</property>
-                                        <property name="height_request">240</property>
-                                        <property name="visible">True</property>
-                                        <property name="stock">gtk-missing-image</property>
-                                      </object>
-                                    </child>
-                                  </object>
-                                  <packing>
-                                    <property name="position">0</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <object class="GtkVBox" id="vbox2">
-                                    <property name="visible">True</property>
-                                    <child>
-                                      <object class="GtkHBox" id="hbox2">
-                                        <property name="visible">True</property>
-                                        <child>
-                                          <object class="GtkLabel" id="label5">
-                                            <property name="visible">True</property>
-                                            <property name="label" translatable="yes">Started:</property>
-                                          </object>
-                                          <packing>
-                                            <property name="expand">False</property>
-                                            <property name="fill">False</property>
-                                            <property name="position">0</property>
-                                          </packing>
-                                        </child>
-                                        <child>
-                                          <object class="GtkEntry" id="entry1">
-                                            <property name="visible">True</property>
-                                            <property name="can_focus">True</property>
-                                            <property name="editable">False</property>
-                                            <property name="invisible_char">&#x25CF;</property>
-                                            <property name="width_chars">12</property>
-                                            <property name="text" translatable="yes">Sat 14:22:25</property>
-                                          </object>
-                                          <packing>
-                                            <property name="expand">False</property>
-                                            <property name="fill">False</property>
-                                            <property name="position">1</property>
-                                          </packing>
-                                        </child>
-                                      </object>
-                                      <packing>
-                                        <property name="expand">False</property>
-                                        <property name="position">0</property>
-                                      </packing>
-                                    </child>
-                                    <child>
-                                      <object class="GtkToggleButton" id="togglebutton1">
-                                        <property name="label" translatable="yes">Enabled</property>
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">True</property>
-                                        <property name="receives_default">True</property>
-                                      </object>
-                                      <packing>
-                                        <property name="expand">False</property>
-                                        <property name="position">1</property>
-                                      </packing>
-                                    </child>
-                                    <child>
-                                      <object class="GtkButton" id="button1">
-                                        <property name="label" translatable="yes">Delete</property>
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">True</property>
-                                        <property name="receives_default">True</property>
-                                        <property name="image">image2</property>
-                                      </object>
-                                      <packing>
-                                        <property name="expand">False</property>
-                                        <property name="position">2</property>
-                                      </packing>
-                                    </child>
-                                    <child>
-                                      <object class="GtkCheckButton" id="checkbutton1">
-                                        <property name="label" translatable="yes">Pin to top</property>
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">True</property>
-                                        <property name="receives_default">False</property>
-                                        <property name="draw_indicator">True</property>
-                                      </object>
-                                      <packing>
-                                        <property name="expand">False</property>
-                                        <property name="position">3</property>
-                                      </packing>
-                                    </child>
-                                  </object>
-                                  <packing>
-                                    <property name="position">1</property>
-                                  </packing>
-                                </child>
-                              </object>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="position">0</property>
-                          </packing>
+                          <placeholder/>
                         </child>
                         <child>
                           <placeholder/>
@@ -305,6 +194,117 @@
       </object>
     </child>
   </object>
+  <object class="GtkWindow" id="replayPanel">
+    <child>
+      <object class="GtkHBox" id="replayPanel2">
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkAspectFrame" id="aspectframe1">
+            <property name="width_request">320</property>
+            <property name="height_request">240</property>
+            <property name="visible">True</property>
+            <property name="label_xalign">0</property>
+            <property name="shadow_type">out</property>
+            <property name="ratio">1.3300000429153442</property>
+            <child>
+              <object class="GtkImage" id="image1">
+                <property name="width_request">320</property>
+                <property name="height_request">240</property>
+                <property name="visible">True</property>
+                <property name="stock">gtk-missing-image</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkVBox" id="vbox2">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkHBox" id="hbox2">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkLabel" id="label5">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Started:</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="entry1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="editable">False</property>
+                    <property name="invisible_char">&#x25CF;</property>
+                    <property name="width_chars">12</property>
+                    <property name="text" translatable="yes">Sat 14:22:25</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToggleButton" id="togglebutton1">
+                <property name="label" translatable="yes">Enabled</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="label" translatable="yes">Delete</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="image">image2</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="checkbutton1">
+                <property name="label" translatable="yes">Pin to top</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">3</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
   <object class="GtkImage" id="image2">
     <property name="visible">True</property>
     <property name="stock">gtk-delete</property>