[seed] Add 'Gst.js' with Gst.Element.prototype.link_many



commit 092057ed8d939f2f682f9b63aa9b0329e75f5344
Author: Robert Carr <racarr svn gnome org>
Date:   Wed May 13 22:59:35 2009 -0400

    Add 'Gst.js' with Gst.Element.prototype.link_many
---
 examples/n-oscillator.js |  139 +++++++++++++++++++++++-----------------------
 extensions/Gst.js        |    8 +++
 extensions/Makefile.am   |    2 +-
 3 files changed, 78 insertions(+), 71 deletions(-)

diff --git a/examples/n-oscillator.js b/examples/n-oscillator.js
index 7626802..ec0d162 100755
--- a/examples/n-oscillator.js
+++ b/examples/n-oscillator.js
@@ -11,80 +11,79 @@ var pipeline = new Gst.Pipeline({name: "test"});
 var unique_id = 0;
 
 OscillatorWidget = new GType({
-	parent: Gtk.VBox.type,
-	name: "OscillatorWidget",
-	class_init: function(klass, prototype)
+    parent: Gtk.VBox.type,
+    name: "OscillatorWidget",
+    class_init: function(klass, prototype)
+    {
+	var flags = (GObject.ParamFlags.CONSTRUCT | 
+		     GObject.ParamFlags.READABLE |
+		     GObject.ParamFlags.WRITABLE);
+	
+	var ps = GObject.param_spec_float("frequency",
+					  "Oscillator Frequency",
+					  "The frequency of the audiotestsrc.",
+					  0, 3000, 1000, flags);
+	
+	klass.c_install_property(ps);
+    },
+    init: function()
+    {
+	// Private
+	
+	var hbox = new Gtk.HBox();
+	var frequency_slider = new Gtk.VScale();
+	var volume_slider = new Gtk.VScale();
+	var button = new Gtk.ToggleButton({label: "Enabled"});
+	
+	// No actual introspection data for audiotestsrc, so can not
+	// instantiate one with a constructor, have to use element_factory,
+	// likewise for the others.
+	var audiosrc = Gst.ElementFactory.make("audiotestsrc", "source" + unique_id);
+	var audiosink = Gst.ElementFactory.make("alsasink", "sink" + unique_id);
+	var volume = Gst.ElementFactory.make("volume", "volume" + unique_id);
+	
+	unique_id++;
+	
+	var toggle_enabled = function(button, that)
 	{
-		var flags = (GObject.ParamFlags.CONSTRUCT | 
-					 GObject.ParamFlags.READABLE |
-					 GObject.ParamFlags.WRITABLE);
-		
-		var ps = GObject.param_spec_float("frequency",
-										  "Oscillator Frequency",
-										  "The frequency of the audiotestsrc.",
-										  0, 3000, 1000, flags);
-		
-		klass.c_install_property(ps);
-	},
-	init: function()
+	    pipeline.set_state(Gst.State.PLAYING);
+	    volume.volume = button.active ? volume_slider.get_value() : 0;
+	};
+	
+	var set_frequency = function(range)
 	{
-		// Private
-		
-		var hbox = new Gtk.HBox();
-		var frequency_slider = new Gtk.VScale();
-		var volume_slider = new Gtk.VScale();
-		var button = new Gtk.ToggleButton({label: "Enabled"});
-		
-		// No actual introspection data for audiotestsrc, so can not
-		// instantiate one with a constructor, have to use element_factory,
-		// likewise for the others.
-		var audiosrc = Gst.ElementFactory.make("audiotestsrc", "source" + unique_id);
-		var audiosink = Gst.ElementFactory.make("alsasink", "sink" + unique_id);
-		var volume = Gst.ElementFactory.make("volume", "volume" + unique_id);
-		
-		unique_id++;
-		
-		var toggle_enabled = function(button, that)
-		{
-			pipeline.set_state(Gst.State.PLAYING);
-			volume.volume = button.active ? volume_slider.get_value() : 0;
-		};
-		
-		var set_frequency = function(range)
-		{
-			this.frequency = audiosrc.freq = range.get_value();
-		};
+	    this.frequency = audiosrc.freq = range.get_value();
+	};
 
-		var set_volume = function(range)
-		{
-			if(button.active)
-				volume.volume = range.get_value();
-		};
-		
-		// Implementation
-		
-		frequency_slider.adjustment.upper = 3000;
-		audiosrc.freq = frequency_slider.adjustment.value = this.frequency;
-		
-		volume_slider.adjustment.upper = 10;
-		volume_slider.adjustment.value = 0.5;
-		volume.volume = 0;
-		
-		pipeline.add(audiosrc);
-		pipeline.add(audiosink);
-		pipeline.add(volume);
-		audiosrc.link(volume);
-		volume.link(audiosink);
-		
-		button.signal.toggled.connect(toggle_enabled);
-		frequency_slider.signal.value_changed.connect(set_frequency);
-		volume_slider.signal.value_changed.connect(set_volume);
+	var set_volume = function(range)
+	{
+	    if(button.active)
+		volume.volume = range.get_value();
+	};
+	
+	// Implementation
+	
+	frequency_slider.adjustment.upper = 3000;
+	audiosrc.freq = frequency_slider.adjustment.value = this.frequency;
+	
+	volume_slider.adjustment.upper = 10;
+	volume_slider.adjustment.value = 0.5;
+	volume.volume = 0;
+	
+	pipeline.add(audiosrc);
+	pipeline.add(audiosink);
+	pipeline.add(volume);
+	audiosrc.link_many(volume, audiosink);
+	
+	button.signal.toggled.connect(toggle_enabled);
+	frequency_slider.signal.value_changed.connect(set_frequency);
+	volume_slider.signal.value_changed.connect(set_volume);
 
-		hbox.pack_start(frequency_slider, true, true, 10);
-		hbox.pack_start(volume_slider, true, true, 10);
-		this.pack_start(hbox, true, true, 10);
-		this.pack_start(button, false, false, 10);
-	}
+	hbox.pack_start(frequency_slider, true, true, 10);
+	hbox.pack_start(volume_slider, true, true, 10);
+	this.pack_start(hbox, true, true, 10);
+	this.pack_start(button, false, false, 10);
+    }
 });
 
 var window = new Gtk.Window();
diff --git a/extensions/Gst.js b/extensions/Gst.js
new file mode 100644
index 0000000..a49a8e6
--- /dev/null
+++ b/extensions/Gst.js
@@ -0,0 +1,8 @@
+Gst = imports.gi.Gst;
+
+Gst.Element.prototype.link_many = function(){
+    this.link(arguments[0]);
+    for (var i = 0; i < arguments.length-1; i++){
+	arguments[i].link(arguments[i+1]);
+    }
+}
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index b3ac716..3d5d86c 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -1,4 +1,4 @@
 EXTRA_DIST= Gio.js Seed.js Gtk.js GObject.js Clutter.js
 
 extensiondir=$(datadir)/seed/extensions
-extension_DATA = Gio.js Seed.js Gtk.js GObject.js Clutter.js
+extension_DATA = Gio.js Seed.js Gtk.js GObject.js Clutter.js Gst.js



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]