2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * demo.c: sample application to display VU meter-like output of level
6 * Thomas Vander Stichele <thomas at apestaart dot org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
31 /* global array for the scale widgets, we'll assume stereo */
33 GtkWidget *scale[2][3];
36 level_callback (GstElement * element, gdouble time, gint channel,
37 gdouble rms, gdouble peak, gdouble decay)
41 label = g_strdup_printf ("%.3f", time);
42 gtk_label_set (GTK_LABEL (elapsed), label);
44 gtk_range_set_value (GTK_RANGE (scale[channel][0]), rms);
45 gtk_range_set_value (GTK_RANGE (scale[channel][1]), peak);
46 gtk_range_set_value (GTK_RANGE (scale[channel][2]), decay);
52 GstElement *pipeline = GST_ELEMENT (data);
55 if (gst_bin_iterate (GST_BIN (pipeline)))
66 GtkWidget *label, *hbox;
69 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
70 g_signal_connect (window, "destroy", gtk_main_quit, NULL);
72 vbox = gtk_vbox_new (TRUE, 0);
73 gtk_container_add (GTK_CONTAINER (window), vbox);
76 hbox = gtk_hbox_new (TRUE, 0);
77 label = gtk_label_new ("Elapsed");
78 elapsed = gtk_label_new ("0.000");
79 gtk_container_add (GTK_CONTAINER (hbox), label);
80 gtk_container_add (GTK_CONTAINER (hbox), elapsed);
81 gtk_container_add (GTK_CONTAINER (vbox), hbox);
83 for (c = 0; c < 2; ++c) {
85 hbox = gtk_hbox_new (TRUE, 0);
86 label = gtk_label_new ("RMS");
87 gtk_container_add (GTK_CONTAINER (hbox), label);
88 scale[c][0] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2);
89 gtk_widget_set_size_request (scale[c][0], 100, -1);
90 gtk_container_add (GTK_CONTAINER (hbox), scale[c][0]);
91 gtk_container_add (GTK_CONTAINER (vbox), hbox);
93 hbox = gtk_hbox_new (TRUE, 0);
94 label = gtk_label_new ("peak");
95 gtk_container_add (GTK_CONTAINER (hbox), label);
96 scale[c][1] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2);
97 gtk_widget_set_size_request (scale[c][1], 100, -1);
98 gtk_container_add (GTK_CONTAINER (hbox), scale[c][1]);
99 gtk_container_add (GTK_CONTAINER (vbox), hbox);
101 hbox = gtk_hbox_new (TRUE, 0);
102 label = gtk_label_new ("decaying peek");
103 gtk_container_add (GTK_CONTAINER (hbox), label);
104 scale[c][2] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2);
105 gtk_widget_set_size_request (scale[c][2], 100, -1);
106 gtk_container_add (GTK_CONTAINER (hbox), scale[c][2]);
107 gtk_container_add (GTK_CONTAINER (vbox), hbox);
110 gtk_widget_show_all (GTK_WIDGET (window));
114 main (int argc, char *argv[])
117 GstElement *pipeline = NULL;
118 GError *error = NULL;
121 gst_init (&argc, &argv);
122 gtk_init (&argc, &argv);
124 pipeline = gst_parse_launchv ((const gchar **) &argv[1], &error);
126 g_print ("pipeline could not be constructed: %s\n", error->message);
127 g_print ("Please give a complete pipeline with a 'level' element.\n");
128 g_print ("Example: sinesrc ! level ! %s\n", DEFAULT_AUDIOSINK);
129 g_error_free (error);
133 level = gst_bin_get_by_name (GST_BIN (pipeline), "level0");
135 g_print ("Please give a pipeline with a 'level' element in it\n");
139 g_object_set (level, "signal", TRUE, NULL);
140 g_signal_connect (level, "level", G_CALLBACK (level_callback), NULL);
146 /* connect level signal */
148 /* go to main loop */
149 gst_element_set_state (pipeline, GST_STATE_PLAYING);
150 g_idle_add (idler, pipeline);