summaryrefslogtreecommitdiffstats
path: root/gst/spectrum
diff options
context:
space:
mode:
authorStefan Kost <ensonic@users.sourceforge.net>2007-09-18 13:55:06 +0000
committerStefan Kost <ensonic@users.sourceforge.net>2007-09-18 13:55:06 +0000
commitc364c7d630e8a2bb8c11c84a19897431bbfce902 (patch)
tree88a2daeeceda6dc12d7453a79f9d2794fa0a5114 /gst/spectrum
parent4bc97d6319145ab13eb6557b74eafebcc845535f (diff)
downloadgst-plugins-bad-c364c7d630e8a2bb8c11c84a19897431bbfce902.tar.gz
gst-plugins-bad-c364c7d630e8a2bb8c11c84a19897431bbfce902.tar.bz2
gst-plugins-bad-c364c7d630e8a2bb8c11c84a19897431bbfce902.zip
gst/spectrum/: Handling window resize.
Original commit message from CVS: * gst/spectrum/demo-audiotest.c: * gst/spectrum/demo-osssrc.c: Handling window resize.
Diffstat (limited to 'gst/spectrum')
-rw-r--r--gst/spectrum/demo-audiotest.c50
-rw-r--r--gst/spectrum/demo-osssrc.c43
2 files changed, 64 insertions, 29 deletions
diff --git a/gst/spectrum/demo-audiotest.c b/gst/spectrum/demo-audiotest.c
index b9f59ba5..8cc8201f 100644
--- a/gst/spectrum/demo-audiotest.c
+++ b/gst/spectrum/demo-audiotest.c
@@ -16,6 +16,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+/* TODO: add wave selection */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -28,9 +29,11 @@
#include <gtk/gtk.h>
#define DEFAULT_AUDIOSINK "alsasink"
-#define SPECT_BANDS 256
static GtkWidget *drawingarea = NULL;
+static guint spect_height = 64;
+static guint spect_bands = 256;
+static gfloat height_scale = 1.0;
static void
on_window_destroy (GtkObject * object, gpointer user_data)
@@ -49,22 +52,37 @@ on_frequency_changed (GtkRange * range, gpointer user_data)
g_object_set (machine, "freq", value, NULL);
}
+gboolean
+on_configure_event (GtkWidget * widget, GdkEventConfigure * event,
+ gpointer user_data)
+{
+ GstElement *spectrum = GST_ELEMENT (user_data);
+
+ /*GST_INFO ("%d x %d", event->width, event->height); */
+ spect_height = event->height;
+ height_scale = event->height / 64.0;
+ spect_bands = event->width;
+
+ g_object_set (G_OBJECT (spectrum), "bands", spect_bands, NULL);
+ return FALSE;
+}
+
/* draw frequency spectrum as a bunch of bars */
static void
draw_spectrum (gfloat * data)
{
gint i;
- GdkRectangle rect = { 0, 0, SPECT_BANDS, 50 };
+ GdkRectangle rect = { 0, 0, spect_bands, spect_height };
if (!drawingarea)
return;
gdk_window_begin_paint_rect (drawingarea->window, &rect);
gdk_draw_rectangle (drawingarea->window, drawingarea->style->black_gc,
- TRUE, 0, 0, SPECT_BANDS, 50);
- for (i = 0; i < SPECT_BANDS; i++) {
+ TRUE, 0, 0, spect_bands, spect_height);
+ for (i = 0; i < spect_bands; i++) {
gdk_draw_rectangle (drawingarea->window, drawingarea->style->white_gc,
- TRUE, i, 64 - data[i], 1, data[i]);
+ TRUE, i, spect_height - data[i], 1, data[i]);
}
gdk_window_end_paint (drawingarea->window);
}
@@ -78,15 +96,15 @@ message_handler (GstBus * bus, GstMessage * message, gpointer data)
const gchar *name = gst_structure_get_name (s);
if (strcmp (name, "spectrum") == 0) {
- gfloat spect[SPECT_BANDS];
+ gfloat spect[spect_bands];
const GValue *list;
const GValue *value;
guint i;
list = gst_structure_get_value (s, "magnitude");
- for (i = 0; i < SPECT_BANDS; ++i) {
+ for (i = 0; i < spect_bands; ++i) {
value = gst_value_list_get_value (list, i);
- spect[i] = g_value_get_float (value);
+ spect[i] = height_scale * g_value_get_float (value);
}
draw_spectrum (spect);
}
@@ -108,12 +126,10 @@ main (int argc, char *argv[])
bin = gst_pipeline_new ("bin");
src = gst_element_factory_make ("audiotestsrc", "src");
- /*
- g_object_set (G_OBJECT (src), "wave", 0, NULL);
- */
+ g_object_set (G_OBJECT (src), "wave", 1, NULL);
spectrum = gst_element_factory_make ("spectrum", "spectrum");
- g_object_set (G_OBJECT (spectrum), "bands", SPECT_BANDS, "threshold", -80,
+ g_object_set (G_OBJECT (spectrum), "bands", spect_bands, "threshold", -80,
"message", TRUE, NULL);
audioconvert = gst_element_factory_make ("audioconvert", "audioconvert");
@@ -122,7 +138,7 @@ main (int argc, char *argv[])
gst_bin_add_many (GST_BIN (bin), src, spectrum, audioconvert, sink, NULL);
if (!gst_element_link_many (src, spectrum, audioconvert, sink, NULL)) {
- fprintf (stderr, "cant link elements\n");
+ fprintf (stderr, "can't link elements\n");
exit (1);
}
@@ -141,11 +157,13 @@ main (int argc, char *argv[])
gtk_range_set_value (GTK_RANGE (widget), 440.0);
g_signal_connect (G_OBJECT (widget), "value-changed",
G_CALLBACK (on_frequency_changed), (gpointer) src);
- gtk_container_add (GTK_CONTAINER (vbox), widget);
+ gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
drawingarea = gtk_drawing_area_new ();
- gtk_widget_set_size_request (drawingarea, SPECT_BANDS, 64);
- gtk_container_add (GTK_CONTAINER (vbox), drawingarea);
+ gtk_widget_set_size_request (drawingarea, spect_bands, spect_height);
+ g_signal_connect (G_OBJECT (drawingarea), "configure-event",
+ G_CALLBACK (on_configure_event), (gpointer) spectrum);
+ gtk_box_pack_start (GTK_BOX (vbox), drawingarea, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (appwindow), vbox);
gtk_widget_show_all (appwindow);
diff --git a/gst/spectrum/demo-osssrc.c b/gst/spectrum/demo-osssrc.c
index 6c106b26..d0b07f33 100644
--- a/gst/spectrum/demo-osssrc.c
+++ b/gst/spectrum/demo-osssrc.c
@@ -28,9 +28,9 @@
#include <gtk/gtk.h>
#define DEFAULT_AUDIOSRC "alsasrc"
-#define SPECT_BANDS 256
-#define SPECT_WIDTH (SPECT_BANDS)
-#define SPECT_HEIGHT 64
+static guint spect_height = 64;
+static guint spect_bands = 256;
+static gfloat height_scale = 1.0;
static GtkWidget *drawingarea = NULL;
@@ -41,22 +41,37 @@ on_window_destroy (GtkObject * object, gpointer user_data)
gtk_main_quit ();
}
+gboolean
+on_configure_event (GtkWidget * widget, GdkEventConfigure * event,
+ gpointer user_data)
+{
+ GstElement *spectrum = GST_ELEMENT (user_data);
+
+ /*GST_INFO ("%d x %d", event->width, event->height); */
+ spect_height = event->height;
+ height_scale = event->height / 64.0;
+ spect_bands = event->width;
+
+ g_object_set (G_OBJECT (spectrum), "bands", spect_bands, NULL);
+ return FALSE;
+}
+
/* draw frequency spectrum as a bunch of bars */
static void
draw_spectrum (gfloat * data)
{
gint i;
- GdkRectangle rect = { 0, 0, SPECT_WIDTH, SPECT_HEIGHT };
+ GdkRectangle rect = { 0, 0, spect_bands, spect_height };
if (!drawingarea)
return;
gdk_window_begin_paint_rect (drawingarea->window, &rect);
gdk_draw_rectangle (drawingarea->window, drawingarea->style->black_gc,
- TRUE, 0, 0, SPECT_BANDS, SPECT_HEIGHT);
- for (i = 0; i < SPECT_BANDS; i++) {
+ TRUE, 0, 0, spect_bands, spect_height);
+ for (i = 0; i < spect_bands; i++) {
gdk_draw_rectangle (drawingarea->window, drawingarea->style->white_gc,
- TRUE, i, SPECT_HEIGHT - data[i], 1, data[i]);
+ TRUE, i, spect_height - data[i], 1, data[i]);
}
gdk_window_end_paint (drawingarea->window);
}
@@ -70,15 +85,15 @@ message_handler (GstBus * bus, GstMessage * message, gpointer data)
const gchar *name = gst_structure_get_name (s);
if (strcmp (name, "spectrum") == 0) {
- gfloat spect[SPECT_BANDS];
+ gfloat spect[spect_bands];
const GValue *list;
const GValue *value;
guint i;
list = gst_structure_get_value (s, "magnitude");
- for (i = 0; i < SPECT_BANDS; ++i) {
+ for (i = 0; i < spect_bands; ++i) {
value = gst_value_list_get_value (list, i);
- spect[i] = g_value_get_float (value);
+ spect[i] = height_scale * g_value_get_float (value);
}
draw_spectrum (spect);
}
@@ -102,14 +117,14 @@ main (int argc, char *argv[])
src = gst_element_factory_make (DEFAULT_AUDIOSRC, "src");
spectrum = gst_element_factory_make ("spectrum", "spectrum");
- g_object_set (G_OBJECT (spectrum), "bands", SPECT_BANDS, "threshold", -80,
+ g_object_set (G_OBJECT (spectrum), "bands", spect_bands, "threshold", -80,
"message", TRUE, NULL);
sink = gst_element_factory_make ("fakesink", "sink");
gst_bin_add_many (GST_BIN (bin), src, spectrum, sink, NULL);
if (!gst_element_link_many (src, spectrum, sink, NULL)) {
- fprintf (stderr, "cant link elements\n");
+ fprintf (stderr, "can't link elements\n");
exit (1);
}
@@ -122,7 +137,9 @@ main (int argc, char *argv[])
G_CALLBACK (on_window_destroy), NULL);
drawingarea = gtk_drawing_area_new ();
- gtk_widget_set_size_request (drawingarea, SPECT_WIDTH, SPECT_HEIGHT);
+ gtk_widget_set_size_request (drawingarea, spect_bands, spect_height);
+ g_signal_connect (G_OBJECT (drawingarea), "configure-event",
+ G_CALLBACK (on_configure_event), (gpointer) spectrum);
gtk_container_add (GTK_CONTAINER (appwindow), drawingarea);
gtk_widget_show_all (appwindow);