/* valac --pkg gstreamer-0.10 --pkg gtk+-2.0 balance-test-case.vala */
/* video should freeze after some brightness change, try moving the slider quicly */

using GLib;
using Gtk;
using Gst;

public class BalanceScale : Window {
	private Pipeline pipeline;
	private Element src;
	private Element csp1;
	private Element bal;
	private Element csp2;
	private Element sink;
	private HScale scale;

	private void setup_pipeline () {
		pipeline = new Pipeline ("mypipe");
		src = ElementFactory.make ("videotestsrc", "mysrc");
		csp1 = ElementFactory.make ("ffmpegcolorspace", "mycsp1");
		bal = ElementFactory.make ("videobalance", "mybal");
		csp2 = ElementFactory.make ("ffmpegcolorspace", "mycsp2");
		sink = ElementFactory.make ("xvimagesink", "mysink");

		pipeline.add_many (src, csp1, bal, csp2, sink);
		src.link_many (csp1, bal, csp2, sink);
		pipeline.set_state (State.PLAYING);
	}

	private void on_value_changed (Gtk.Range range) {
		var adj = range.get_adjustment ();
		message ("new brightness: %f", adj.value);
		this.bal.set ("brightness", adj.value);
	}

	private void setup_widgets () {
		scale = new HScale.with_range (-1.0, 1.0, 0.1);
		scale.value_changed.connect (on_value_changed);
		this.add (scale);
	}

	public BalanceScale () {
		setup_widgets ();
		setup_pipeline ();
	}

	public static int main (string[] args)
	{
		Gst.init (ref args);
		Gtk.init (ref args);

		var app = new BalanceScale ();
		app.set_default_size (400, -1);
		app.show_all ();

		Gtk.main();

		return 0;
	}
}