Mercurial > code > home > repos > light9
changeset 642:af566766bf0b
music position slider in vidref
Ignore-this: 9483ed97a3b2c208cad2091f9de04905
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sat, 18 Jun 2011 04:22:53 +0000 |
parents | c113c759559b |
children | 42eae412571a |
files | light9/vidref/main.py light9/vidref/vidref.glade |
diffstat | 2 files changed, 209 insertions(+), 150 deletions(-) [+] |
line wrap: on
line diff
--- a/light9/vidref/main.py Fri Jun 17 08:18:37 2011 +0000 +++ b/light9/vidref/main.py Sat Jun 18 04:22:53 2011 +0000 @@ -24,15 +24,18 @@ fetch times from ascoltami in a background thread; return times upon request, adjusted to be more precise with the system clock """ - def __init__(self, period=.2): + def __init__(self, period=.2, onChange=lambda position: None): """period is the seconds between http time requests. + We call onChange with the time in seconds and the total time + The choice of period doesn't need to be tied to framerate, it's more the size of the error you can tolerate (since we 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) t = Thread(target=self._timeUpdate) t.setDaemon(True) @@ -62,10 +65,16 @@ self.positionFetchTime = time.time() self.position = position + self.onChange(position) except restkit.RequestError, e: 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}), + headers={"content-type" : "application/json"}) class VideoRecordSink(gst.Element): _sinkpadtemplate = gst.PadTemplate ("sinkpadtemplate", @@ -141,7 +150,7 @@ class Main(object): def __init__(self): - self.musicTime = MusicTime() + self.musicTime = MusicTime(onChange=self.onMusicTimeChange) wtree = gtk.Builder() wtree.add_from_file(sibpath(__file__, "vidref.glade")) mainwin = wtree.get_object("MainWindow") @@ -149,6 +158,9 @@ wtree.connect_signals(self) self.recordingTo = wtree.get_object('recordingTo') + self.musicScale = wtree.get_object("musicScale") + self.musicScale.connect("value-changed", + lambda r: self.musicTime.sendTime(r.get_value())) # wtree.get_object("replayPanel").show() # demo only rp = wtree.get_object("replayVbox") @@ -227,3 +239,7 @@ def on_liveFrameRate_value_changed(self, widget): print widget.get_value() + + def onMusicTimeChange(self, position): + self.musicScale.set_range(0, position['duration']) + self.musicScale.set_value(position['t'])
--- a/light9/vidref/vidref.glade Fri Jun 17 08:18:37 2011 +0000 +++ b/light9/vidref/vidref.glade Sat Jun 18 04:22:53 2011 +0000 @@ -1,4 +1,4 @@ -<?xml version="1.0"?> +<?xml version="1.0" encoding="UTF-8"?> <interface> <requires lib="gtk+" version="2.16"/> <!-- interface-naming-policy project-wide --> @@ -7,39 +7,170 @@ <property name="default_width">690</property> <property name="default_height">500</property> <child> - <object class="GtkHBox" id="hbox3"> + <object class="GtkVBox" id="vbox1"> <property name="visible">True</property> <child> - <object class="GtkVBox" id="vbox3"> + <object class="GtkHBox" id="hbox3"> <property name="visible">True</property> <child> - <object class="GtkFrame" id="frame1"> - <property name="width_request">336</property> - <property name="height_request">277</property> + <object class="GtkVBox" id="vbox3"> <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="shadow_type">out</property> <child> - <object class="GtkAspectFrame" id="aspectframe2"> + <object class="GtkFrame" id="frame1"> + <property name="width_request">336</property> + <property name="height_request">277</property> <property name="visible">True</property> <property name="label_xalign">0</property> - <property name="shadow_type">none</property> - <property name="ratio">1.3300000429153442</property> + <property name="shadow_type">out</property> <child> - <object class="GtkDrawingArea" id="vid3"> - <property name="width_request">320</property> - <property name="height_request">240</property> + <object class="GtkAspectFrame" id="aspectframe2"> <property name="visible">True</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <property name="ratio">1.3300000429153442</property> + <child> + <object class="GtkDrawingArea" id="vid3"> + <property name="width_request">320</property> + <property name="height_request">240</property> + <property name="visible">True</property> + </object> + </child> + </object> + </child> + <child type="label"> + <object class="GtkLabel" id="label2"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Live view</b></property> + <property name="use_markup">True</property> </object> </child> </object> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> </child> - <child type="label"> - <object class="GtkLabel" id="label2"> + <child> + <object class="GtkVBox" id="vbox4"> <property name="visible">True</property> - <property name="label" translatable="yes"><b>Live view</b></property> - <property name="use_markup">True</property> + <child> + <object class="GtkToggleButton" id="liveVideoEnabled"> + <property name="label" translatable="yes">Enabled</property> + <property name="width_request">110</property> + <property name="height_request">36</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="active">True</property> + <signal name="toggled" handler="on_liveVideoEnabled_toggled"/> + </object> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox4"> + <property name="visible">True</property> + <child> + <object class="GtkLabel" id="label1"> + <property name="width_request">75</property> + <property name="height_request">20</property> + <property name="visible">True</property> + <property name="label" translatable="yes">Frame rate:</property> + </object> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkSpinButton" id="liveFrameRate"> + <property name="width_request">52</property> + <property name="height_request">25</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">●</property> + <property name="numeric">True</property> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox5"> + <property name="visible">True</property> + <child> + <object class="GtkLabel" id="label4"> + <property name="width_request">85</property> + <property name="height_request">20</property> + <property name="visible">True</property> + <property name="label" translatable="yes">Input source:</property> + </object> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="videoSource"> + <property name="width_request">100</property> + <property name="visible">True</property> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox1"> + <property name="visible">True</property> + <child> + <object class="GtkLabel" id="label6"> + <property name="visible">True</property> + <property name="label" translatable="yes">Recording +to:</property> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkTextView" id="recordingToView"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="editable">False</property> + <property name="wrap_mode">char</property> + <property name="buffer">recordingTo</property> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="position">3</property> + </packing> + </child> + <child> + <placeholder/> + </child> </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> </child> </object> <packing> @@ -48,176 +179,88 @@ </packing> </child> <child> - <object class="GtkVBox" id="vbox4"> + <object class="GtkFrame" id="replayHalf"> + <property name="width_request">336</property> + <property name="height_request">259</property> <property name="visible">True</property> + <property name="label_xalign">0</property> + <property name="shadow_type">out</property> <child> - <object class="GtkToggleButton" id="liveVideoEnabled"> - <property name="label" translatable="yes">Enabled</property> - <property name="width_request">110</property> - <property name="height_request">36</property> + <object class="GtkScrolledWindow" id="replayScrollWin"> + <property name="width_request">571</property> + <property name="height_request">367</property> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="active">True</property> - <signal name="toggled" handler="on_liveVideoEnabled_toggled"/> - </object> - <packing> - <property name="expand">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkHBox" id="hbox4"> - <property name="visible">True</property> + <property name="hscrollbar_policy">automatic</property> + <property name="vscrollbar_policy">automatic</property> + <property name="shadow_type">out</property> <child> - <object class="GtkLabel" id="label1"> - <property name="width_request">75</property> - <property name="height_request">20</property> + <object class="GtkViewport" id="replayScroll"> <property name="visible">True</property> - <property name="label" translatable="yes">Frame rate:</property> + <property name="resize_mode">queue</property> + <child> + <object class="GtkVBox" id="replayVbox"> + <property name="visible">True</property> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + </object> + </child> </object> - <packing> - <property name="expand">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkSpinButton" id="liveFrameRate"> - <property name="width_request">52</property> - <property name="height_request">25</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="numeric">True</property> - </object> - <packing> - <property name="position">1</property> - </packing> </child> </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> </child> - <child> - <object class="GtkHBox" id="hbox5"> + <child type="label"> + <object class="GtkLabel" id="label3"> <property name="visible">True</property> - <child> - <object class="GtkLabel" id="label4"> - <property name="width_request">85</property> - <property name="height_request">20</property> - <property name="visible">True</property> - <property name="label" translatable="yes">Input source:</property> - </object> - <packing> - <property name="expand">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkComboBox" id="videoSource"> - <property name="width_request">100</property> - <property name="visible">True</property> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> + <property name="label" translatable="yes"><b>Playback 1</b></property> + <property name="use_markup">True</property> </object> - <packing> - <property name="expand">False</property> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkHBox" id="hbox1"> - <property name="visible">True</property> - <child> - <object class="GtkLabel" id="label6"> - <property name="visible">True</property> - <property name="label" translatable="yes">Recording -to:</property> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkTextView" id="recordingToView"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">False</property> - <property name="wrap_mode">char</property> - <property name="buffer">recordingTo</property> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="position">3</property> - </packing> </child> </object> <packing> - <property name="expand">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="GtkFrame" id="replayHalf"> - <property name="width_request">336</property> - <property name="height_request">259</property> + <object class="GtkFrame" id="musicPosition"> <property name="visible">True</property> <property name="label_xalign">0</property> - <property name="shadow_type">out</property> + <property name="shadow_type">none</property> <child> - <object class="GtkScrolledWindow" id="replayScrollWin"> - <property name="width_request">571</property> - <property name="height_request">367</property> + <object class="GtkAlignment" id="alignment1"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="hscrollbar_policy">automatic</property> - <property name="vscrollbar_policy">automatic</property> - <property name="shadow_type">out</property> + <property name="left_padding">12</property> <child> - <object class="GtkViewport" id="replayScroll"> + <object class="GtkHScale" id="musicScale"> <property name="visible">True</property> - <property name="resize_mode">queue</property> - <child> - <object class="GtkVBox" id="replayVbox"> - <property name="visible">True</property> - <child> - <placeholder/> - </child> - <child> - <placeholder/> - </child> - <child> - <placeholder/> - </child> - </object> - </child> + <property name="can_focus">True</property> + <property name="digits">2</property> </object> </child> </object> </child> <child type="label"> - <object class="GtkLabel" id="label3"> + <object class="GtkLabel" id="label7"> <property name="visible">True</property> - <property name="label" translatable="yes"><b>Playback 1</b></property> + <property name="label" translatable="yes"><b>Music position</b></property> <property name="use_markup">True</property> </object> </child> </object> <packing> + <property name="expand">False</property> <property name="position">1</property> </packing> </child> @@ -272,7 +315,7 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="editable">False</property> - <property name="invisible_char">●</property> + <property name="invisible_char">●</property> <property name="width_chars">12</property> <property name="text" translatable="yes">Sat 14:22:25</property> </object>