diff --git a/ChangeLog b/ChangeLog index f5eb532..4512b36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2012-02-15 Bernard Victor Delvaux +2013-02-26 Bernard Victor Delvaux + Version : Spectrum3d-2.4.0 : + * gstreamer.c : spectrum3d can now be compiled against gstreamer-1.0 or gstreamer-0.10; + * record.c and typesource.c : length of a audio file depending on its recorded (a timer is run when recording) or preexisting origin (a pipeline is created and its length is measured); there was a bug with this in Spectrum3d-2.4.0; + +2013-02-15 Bernard Victor Delvaux Version : Spectrum3d-2.3.0 : * general changes : some deprecated functions have been replaced in Gtk3; * general changes : new main icon; diff --git a/README b/README index 6f09091..6d2aee0 100644 --- a/README +++ b/README @@ -14,7 +14,7 @@ FOR UBUNTU from 10.10 : All dependencies are available in the Ubuntu repositorie - gcc, pkg-config, automake; - libgtk-2.0-dev or libgtk-3.0-dev; - - libgstreamer0.10-dev; + - libgstreamer0.10-dev or libgstreamer1.0-dev; For DISPLAY (OpenGL extension): SDL is used by default; GtkGlExt can be used instead and its version should match the GTK version (GTKGLEXT1 for GTK2, GTKGLEXT3 for GTK3); however, GTKGLEXT3 is still in development; the development version should be installed then (see later); the display of harmonics itself will look exactly the same regardless of the library that is used. - EITHER : lidsdl1.2-dev; this should be the default choice; - OR : libgtkglext1-dev for Gtk2 or libgtkglext for Gtk3 (this version is in developpment and should be compiled from source (see documentation) but is already supported in Spectrum3d); note that GtkGlExt version should match Gtk version; diff --git a/configure b/configure index 20c33c5..0245c15 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for Spectrum3d 2.3.0. +# Generated by GNU Autoconf 2.69 for Spectrum3d 2.4.0. # # Report bugs to . # @@ -580,8 +580,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='Spectrum3d' PACKAGE_TARNAME='spectrum3d' -PACKAGE_VERSION='2.3.0' -PACKAGE_STRING='Spectrum3d 2.3.0' +PACKAGE_VERSION='2.4.0' +PACKAGE_STRING='Spectrum3d 2.4.0' PACKAGE_BUGREPORT='nadaeck@hotmail.com' PACKAGE_URL='spectrum3d.sourceforge.net' @@ -1300,7 +1300,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures Spectrum3d 2.3.0 to adapt to many kinds of systems. +\`configure' configures Spectrum3d 2.4.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1366,7 +1366,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of Spectrum3d 2.3.0:";; + short | recursive ) echo "Configuration of Spectrum3d 2.4.0:";; esac cat <<\_ACEOF @@ -1484,7 +1484,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -Spectrum3d configure 2.3.0 +Spectrum3d configure 2.4.0 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1853,7 +1853,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by Spectrum3d $as_me 2.3.0, which was +It was created by Spectrum3d $as_me 2.4.0, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2670,7 +2670,7 @@ fi # Define the identity of the package. PACKAGE='spectrum3d' - VERSION='2.3.0' + VERSION='2.4.0' cat >>confdefs.h <<_ACEOF @@ -3857,6 +3857,7 @@ jack=1 geis=1 gtk=0 gtkglext=0 +gstreamer=0 # Check and link for GTK3 @@ -4457,7 +4458,150 @@ else fi -# Check and link for GSTREAMER-0.10 +# Check and link for GSTREAMER : version 1.0 is searched by default, then version 0.10 is searched + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GSTREAMER" >&5 +$as_echo_n "checking for GSTREAMER... " >&6; } + +if test -n "$GSTREAMER_CFLAGS"; then + pkg_cv_GSTREAMER_CFLAGS="$GSTREAMER_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gstreamer-1.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "gstreamer-1.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GSTREAMER_CFLAGS=`$PKG_CONFIG --cflags "gstreamer-1.0" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$GSTREAMER_LIBS"; then + pkg_cv_GSTREAMER_LIBS="$GSTREAMER_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gstreamer-1.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "gstreamer-1.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GSTREAMER_LIBS=`$PKG_CONFIG --libs "gstreamer-1.0" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + GSTREAMER_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "gstreamer-1.0" 2>&1` + else + GSTREAMER_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "gstreamer-1.0" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$GSTREAMER_PKG_ERRORS" >&5 + + + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GSTREAMER" >&5 +$as_echo_n "checking for GSTREAMER... " >&6; } + +if test -n "$GSTREAMER_CFLAGS"; then + pkg_cv_GSTREAMER_CFLAGS="$GSTREAMER_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gstreamer-0.10\""; } >&5 + ($PKG_CONFIG --exists --print-errors "gstreamer-0.10") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GSTREAMER_CFLAGS=`$PKG_CONFIG --cflags "gstreamer-0.10" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$GSTREAMER_LIBS"; then + pkg_cv_GSTREAMER_LIBS="$GSTREAMER_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gstreamer-0.10\""; } >&5 + ($PKG_CONFIG --exists --print-errors "gstreamer-0.10") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GSTREAMER_LIBS=`$PKG_CONFIG --libs "gstreamer-0.10" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + GSTREAMER_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "gstreamer-0.10" 2>&1` + else + GSTREAMER_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "gstreamer-0.10" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$GSTREAMER_PKG_ERRORS" >&5 + + as_fn_error $? "Gstreamer library (libgstreamer-0.10 or libgstreamer-1.0) is required" "$LINENO" 5 +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + as_fn_error $? "Gstreamer library (libgstreamer-0.10 or libgstreamer-1.0) is required" "$LINENO" 5 +else + GSTREAMER_CFLAGS=$pkg_cv_GSTREAMER_CFLAGS + GSTREAMER_LIBS=$pkg_cv_GSTREAMER_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + + gstreamer=0 + CFLAGS="$CFLAGS $GSTREAMER_CFLAGS" + LIBS="$LIBS $GSTREAMER_LIBS" + +$as_echo "#define GSTREAMER0 1" >>confdefs.h + + +fi + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + pkg_failed=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GSTREAMER" >&5 @@ -4517,19 +4661,38 @@ fi # Put the nasty error message in config.log where it belongs echo "$GSTREAMER_PKG_ERRORS" >&5 - as_fn_error $? "GSTREAMER (gstreamer-0.10) library (libgstreamer) is required" "$LINENO" 5 + as_fn_error $? "Gstreamer library (libgstreamer-0.10 or libgstreamer-1.0) is required" "$LINENO" 5 elif test $pkg_failed = untried; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - as_fn_error $? "GSTREAMER (gstreamer-0.10) library (libgstreamer) is required" "$LINENO" 5 + as_fn_error $? "Gstreamer library (libgstreamer-0.10 or libgstreamer-1.0) is required" "$LINENO" 5 +else + GSTREAMER_CFLAGS=$pkg_cv_GSTREAMER_CFLAGS + GSTREAMER_LIBS=$pkg_cv_GSTREAMER_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + + gstreamer=0 + CFLAGS="$CFLAGS $GSTREAMER_CFLAGS" + LIBS="$LIBS $GSTREAMER_LIBS" + +$as_echo "#define GSTREAMER0 1" >>confdefs.h + + +fi + else GSTREAMER_CFLAGS=$pkg_cv_GSTREAMER_CFLAGS GSTREAMER_LIBS=$pkg_cv_GSTREAMER_LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } - CFLAGS="$CFLAGS $GSTREAMER_CFLAGS" - LIBS="$LIBS $GSTREAMER_LIBS" + gstreamer=1 + CFLAGS="$CFLAGS $GSTREAMER_CFLAGS" + LIBS="$LIBS $GSTREAMER_LIBS" + +$as_echo "#define GSTREAMER1 1" >>confdefs.h + fi @@ -5697,7 +5860,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by Spectrum3d $as_me 2.3.0, which was +This file was extended by Spectrum3d $as_me 2.4.0, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5764,7 +5927,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -Spectrum3d config.status 2.3.0 +Spectrum3d config.status 2.4.0 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -6639,6 +6802,13 @@ $as_echo "$as_me: If you want to use gtkglext, its version should match the gtk $as_echo { $as_echo "$as_me:${as_lineno-$LINENO}: ******************************************" >&5 $as_echo "$as_me: ******************************************" >&6;} +if test "$gstreamer" == "1"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: * Gstreamer version ...............1.0 *" >&5 +$as_echo "$as_me: * Gstreamer version ...............1.0 *" >&6;} +else + { $as_echo "$as_me:${as_lineno-$LINENO}: * Gstreamer version ..............0.10 *" >&5 +$as_echo "$as_me: * Gstreamer version ..............0.10 *" >&6;} +fi if test "$gtk" == "2"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: * GTK version .................GTK-2.0 *" >&5 $as_echo "$as_me: * GTK version .................GTK-2.0 *" >&6;} diff --git a/configure.ac b/configure.ac index 31dd1c1..b869175 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ ############### INITIALIZE EVERYTHING ###################### AC_INIT([Spectrum3d], - [2.3.0], + [2.4.0], [nadaeck@hotmail.com], [spectrum3d], [spectrum3d.sourceforge.net]) @@ -43,6 +43,7 @@ jack=1 geis=1 gtk=0 gtkglext=0 +gstreamer=0 # Check and link for GTK3 AS_IF([test "x$enable_gtk3" != "xno" && test "x$enable_gtk2" != "xyes"], [ @@ -90,11 +91,20 @@ AC_CHECK_LIB([GL], [glClear], [], AC_CHECK_LIB([GLU], [gluBeginCurve], [], [AC_MSG_ERROR([OpenGL(GLU) library is required for this program])]) -# Check and link for GSTREAMER-0.10 -PKG_CHECK_MODULES([GSTREAMER], [gstreamer-0.10], [ - CFLAGS="$CFLAGS $GSTREAMER_CFLAGS" - LIBS="$LIBS $GSTREAMER_LIBS" - ], [AC_MSG_ERROR([GSTREAMER (gstreamer-0.10) library (libgstreamer) is required])]) +# Check and link for GSTREAMER : version 1.0 is searched by default, then version 0.10 is searched +PKG_CHECK_MODULES([GSTREAMER], [gstreamer-1.0], [ + gstreamer=1 + CFLAGS="$CFLAGS $GSTREAMER_CFLAGS" + LIBS="$LIBS $GSTREAMER_LIBS" + AC_DEFINE([GSTREAMER1], [1], [Define to 1 if you have the `Gstreamer-1.0' library]) + ], [ + PKG_CHECK_MODULES([GSTREAMER], [gstreamer-0.10], [ + gstreamer=0 + CFLAGS="$CFLAGS $GSTREAMER_CFLAGS" + LIBS="$LIBS $GSTREAMER_LIBS" + AC_DEFINE([GSTREAMER0], [1], [Define to 1 if you have the `Gstreamer-0.10' library]) + ], [AC_MSG_ERROR([Gstreamer library (libgstreamer-0.10 or libgstreamer-1.0) is required])]) + ]) # Check and link for JACK (if jacklib is present and if this option is not disabled) AS_IF([test "x$enable_jack" != "xno"], [ @@ -137,6 +147,9 @@ AS_ECHO() AC_MSG_NOTICE([If you want to use gtkglext, its version should match the gtk version (gtkglext-1.0 for gtk-2.0, gtkglext-3.0 for gtk-3.0)]) AS_ECHO() AC_MSG_NOTICE([ ******************************************]) +AS_IF([test "$gstreamer" == "1"], + [AC_MSG_NOTICE([ * Gstreamer version ...............1.0 *])], + [AC_MSG_NOTICE([ * Gstreamer version ..............0.10 *])]) AS_IF([test "$gtk" == "2"], [AC_MSG_NOTICE([ * GTK version .................GTK-2.0 *])], [AC_MSG_NOTICE([ * GTK version .................GTK-3.0 *])]) diff --git a/src/config.h.in b/src/config.h.in index 058c742..db94373 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -1,5 +1,11 @@ /* src/config.h.in. Generated from configure.ac by autoheader. */ +/* Define to 1 if you have the `Gstreamer-0.10' library */ +#undef GSTREAMER0 + +/* Define to 1 if you have the `Gstreamer-1.0' library */ +#undef GSTREAMER1 + /* Define to 1 if you have the `GTK2' library */ #undef GTK2 diff --git a/src/equalizer.c b/src/equalizer.c index e83f5e9..2248a44 100644 --- a/src/equalizer.c +++ b/src/equalizer.c @@ -30,7 +30,11 @@ gboolean activateFilter; GtkWidget *widgetF[10], *widgetB[10], *widgetG[10], *spinBPlowerValue, *spinBPupperValue; +#ifdef GSTREAMER1 +GObject *band, *band2, *band3; +#elif defined GSTREAMER0 GstObject *band, *band2, *band3; +#endif gdouble freq; gdouble bw; gdouble gain; @@ -48,7 +52,8 @@ on_gain_changed (GtkRange * range, gpointer user_data) // change gain of equaliz GstObject *band = GST_OBJECT (user_data); gdouble value = gtk_range_get_value (range); - g_object_set (band, "gain", value, NULL); + g_object_set (G_OBJECT(band), "gain", value, NULL); + //g_object_unref (G_OBJECT (band)); } static void @@ -57,7 +62,8 @@ on_gain_changed2 (GtkRange * range, gpointer user_data) // change gain of equali GstObject *band = GST_OBJECT (user_data); gdouble value = gtk_range_get_value (range); - g_object_set (band, "gain", value, NULL); + g_object_set (G_OBJECT(band), "gain", value, NULL); + //g_object_unref (G_OBJECT (band)); } static void @@ -66,7 +72,8 @@ on_gain_changed3 (GtkRange * range, gpointer user_data) // change gain of equali GstObject *band = GST_OBJECT (user_data); gdouble value = gtk_range_get_value (range); - g_object_set (band, "gain", value, NULL); + g_object_set (G_OBJECT(band), "gain", value, NULL); + //g_object_unref (G_OBJECT (band)); } static void @@ -75,7 +82,8 @@ on_bandwidth_changed (GtkRange * range, gpointer user_data) // change bandwidth GstObject *band = GST_OBJECT (user_data); gdouble value = gtk_range_get_value (range); - g_object_set (band, "bandwidth", value, NULL); + g_object_set (G_OBJECT(band), "bandwidth", value, NULL); + //g_object_unref (G_OBJECT (band)); } static void @@ -84,7 +92,8 @@ on_bandwidth_changed2 (GtkRange * range, gpointer user_data) // change bandwidth GstObject *band = GST_OBJECT (user_data); gdouble value = gtk_range_get_value (range); - g_object_set (band, "bandwidth", value, NULL); + g_object_set (G_OBJECT(band), "bandwidth", value, NULL); + //g_object_unref (G_OBJECT (band)); } static void @@ -93,9 +102,11 @@ on_bandwidth_changed3 (GtkRange * range, gpointer user_data) // change bandwidth GstObject *band = GST_OBJECT (user_data); gdouble value = gtk_range_get_value (range); - g_object_set (band, "bandwidth", value, NULL); + g_object_set (G_OBJECT(band), "bandwidth", value, NULL); + //g_object_unref (G_OBJECT (band)); } + /* control frequency */ static void on_freq_changed (GtkRange * range, gpointer user_data) // change frequency range of equalizer @@ -107,7 +118,8 @@ on_freq_changed (GtkRange * range, gpointer user_data) // change frequency range gchar *label = g_strdup_printf ("%d Hz", (int) (value + 0.5)); gtk_frame_set_label (GTK_FRAME (parent_parent), label); g_free (label); - g_object_set (band, "freq", value, NULL); + g_object_set (G_OBJECT(band), "freq", value, NULL); + //g_object_unref (G_OBJECT (band)); } static void @@ -120,7 +132,8 @@ on_freq_changed2 (GtkRange * range, gpointer user_data) // change frequency rang gchar *label = g_strdup_printf ("%d Hz", (int) (value + 0.5)); gtk_frame_set_label (GTK_FRAME (parent_parent), label); g_free (label); - g_object_set (band, "freq", value, NULL); + g_object_set (G_OBJECT(band), "freq", value, NULL); + //g_object_unref (G_OBJECT (band)); } static void @@ -133,7 +146,8 @@ on_freq_changed3 (GtkRange * range, gpointer user_data) // change frequency rang gchar *label = g_strdup_printf ("%d Hz", (int) (value + 0.5)); gtk_frame_set_label (GTK_FRAME (parent_parent), label); g_free (label); - g_object_set (band, "freq", value, NULL); + g_object_set (G_OBJECT(band), "freq", value, NULL); + //g_object_unref (G_OBJECT (band)); } void getBand(){ diff --git a/src/events.c b/src/events.c index a32f667..c71a51c 100644 --- a/src/events.c +++ b/src/events.c @@ -24,10 +24,6 @@ #include "config.h" -/*#ifdef HAVE_LIBSDL - #include -#endif*/ - #include "spectrum3d.h" #include "events.h" @@ -301,207 +297,6 @@ gboolean on_key_release (GtkWidget *window, GdkEventKey *event, Spectrum3dGui *s return FALSE; } -/* -#ifdef HAVE_LIBSDL -gboolean sdl_event(Spectrum3dGui *spectrum3dGui) -{ - Uint8 mouseState, *keystate; - SDL_Event event; - int MouseX,MouseY; - - printf("sdl event?\n"); - - while (SDL_PollEvent(&event)){ - switch (event.type) - { - case SDL_VIDEORESIZE: - configure_SDL_gl_window(event.resize.w, event.resize.h); - spectrum3d.width = event.resize.w; - spectrum3d.height = event.resize.h; - newEvent = TRUE; - break; - case SDL_MOUSEMOTION: - mouseState = SDL_GetMouseState(NULL, NULL); - if (SDL_GetRelativeMouseState(&MouseX,&MouseY)){ - if (mouseState == 1){ - if ( MouseX < 100 && MouseX > -100 ) { - if (MouseX > 0) { - AngleH += 1.2; - } - else if (MouseX < 0) { - AngleH-= 1.2; - } - } - if (MouseY < 100 && MouseY > -100 ) { - if (MouseY > 0) { - AngleV += 1.6; - } - else if (MouseY < 0) { - AngleV -= 1.6; - } - } - } - else if (mouseState == 4){ - if ( MouseX < 100 && MouseX > -100 ) { - if (MouseX > 0) { - X+=0.02; - } - else if (MouseX < 0) { - X-=0.02; - } - } - if (MouseY < 100 && MouseY > -100 ) { - if (MouseY > 0) { - Y-=0.02; - } - else if (MouseY < 0) { - Y+=0.02; - } - } - } - newEvent = TRUE; - } - - break; - case SDL_BUTTON_WHEELDOWN : - if (SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(3)){ - if (event.button.button == SDL_BUTTON_WHEELUP){ - Z +=0.02; - } - if (event.button.button == SDL_BUTTON_WHEELDOWN){ - Z -=0.02; - } - newEvent = TRUE; - } - else if (SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)){ - if (event.button.button == SDL_BUTTON_WHEELUP){ - AngleZ +=0.4; - } - if (event.button.button == SDL_BUTTON_WHEELDOWN){ - AngleZ -=0.4; - } - newEvent = TRUE; - } - break; - case SDL_QUIT: - quit_spectrum3d(); - break; - case SDL_KEYDOWN: - keystate = SDL_GetKeyState(NULL); - if ( (keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL]) && (keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT]) && keystate[SDLK_UP] ) { - Z -= 0.02; - newEvent = TRUE; - } - else if ( (keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL]) && (keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT]) && keystate[SDLK_DOWN] ) { - Z += 0.02; - newEvent = TRUE; - } - else if ( (keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT]) && keystate[SDLK_UP] ) { - AngleZ += 0.4; - newEvent = TRUE; - } - else if ( (keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT]) && keystate[SDLK_DOWN] ) { - AngleZ -= 0.4; - newEvent = TRUE; - } - else if ( (keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL]) && keystate[SDLK_UP] ) { - Y += 0.02; - newEvent = TRUE; - } - else if ( (keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL]) && keystate[SDLK_DOWN] ) { - Y -= 0.02; - newEvent = TRUE; - } - else if ( (keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL]) && keystate[SDLK_RIGHT] ) { - X += 0.02; - newEvent = TRUE; - } - else if ( (keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL]) && keystate[SDLK_LEFT] ) { - X -= 0.02; - newEvent = TRUE; - } - else if ( keystate[SDLK_q] && ( keystate[SDLK_RIGHT] || keystate[SDLK_UP]) ) { - Xpointer += (x / bandsNumber); - Ypointer += (y_2d / bandsNumber); - newEvent = TRUE; - } - else if ( keystate[SDLK_q] && ( keystate[SDLK_LEFT] || keystate[SDLK_DOWN]) ) { - Xpointer -= (x / bandsNumber); - Ypointer -= (y_2d / bandsNumber); - newEvent = TRUE; - } - else if ( keystate[SDLK_a] && ( keystate[SDLK_RIGHT] || keystate[SDLK_UP]) ) { - Xpointer += (x / bandsNumber) * 10; - Ypointer += (y_2d / bandsNumber) * 10; - newEvent = TRUE; - } - else if ( keystate[SDLK_a] && ( keystate[SDLK_LEFT] || keystate[SDLK_DOWN]) ) { - Xpointer -= (x / bandsNumber) * 10; - Ypointer -= (y_2d / bandsNumber) * 10; - newEvent = TRUE; - } - else if ( keystate[SDLK_g] && keystate[SDLK_UP]) { - gtk_scale_button_set_value( GTK_SCALE_BUTTON(spectrum3dGui->scaleGain), (gtk_scale_button_get_value(GTK_SCALE_BUTTON(spectrum3dGui->scaleGain)) + 0.01) ); - } - else if ( keystate[SDLK_g] && keystate[SDLK_DOWN]) { - gtk_scale_button_set_value( GTK_SCALE_BUTTON(spectrum3dGui->scaleGain), (gtk_scale_button_get_value(GTK_SCALE_BUTTON(spectrum3dGui->scaleGain)) - 0.01) ); - } - else if ( keystate[SDLK_UP] ) { - AngleV += 0.8; - newEvent = TRUE; - } - else if ( keystate[SDLK_DOWN] ) { - AngleV -= 0.8; - newEvent = TRUE; - } - else if ( keystate[SDLK_RIGHT] ) { - AngleH += 0.8; - newEvent = TRUE; - } - else if ( keystate[SDLK_LEFT] ) { - AngleH -= 0.8; - newEvent = TRUE; - } - else if ( keystate[SDLK_SPACE] ) { - playFromSource(NULL, NULL); - } - else if ( keystate[SDLK_d] ) { - if (viewType == THREE_D){ - gtk_menu_item_activate(GTK_MENU_ITEM(spectrum3dGui->radio2D)); - } - else { - gtk_menu_item_activate(GTK_MENU_ITEM(spectrum3dGui->radio3D)); - } - } - else if ( keystate[SDLK_f] ) { - gtk_menu_item_activate(GTK_MENU_ITEM(spectrum3dGui->radio3Dflat)); - } - else if ( keystate[SDLK_t] ) { - gtk_menu_item_activate(GTK_MENU_ITEM(spectrum3dGui->checkMenuText)); - } - else if ( keystate[SDLK_l] ) { - gtk_menu_item_activate(GTK_MENU_ITEM(spectrum3dGui->checkMenuLines)); - } - else if ( keystate[SDLK_p] ) { - gtk_menu_item_activate(GTK_MENU_ITEM(spectrum3dGui->checkMenuPointer)); - } - else if ( keystate[SDLK_r] ) { - gtk_menu_item_activate(GTK_MENU_ITEM(spectrum3dGui->reset)); - } - else if ( keystate[SDLK_o] ) { - gtk_menu_item_activate(GTK_MENU_ITEM(spectrum3dGui->front)); - } - else if ( keystate[SDLK_ESCAPE] ) { - on_stop(); - } - default: - break; - } - } - return TRUE; -} -#endif -*/ diff --git a/src/gstreamer.c b/src/gstreamer.c index 06ae422..6338e5f 100644 --- a/src/gstreamer.c +++ b/src/gstreamer.c @@ -35,6 +35,8 @@ const GValue *magni, *magnitudes; gdouble freqTestSound = 440; GstElement *srcTestSound; static GstTaskPool *pool; +GTimer *timer = NULL; +gdouble elapsed_time = 0; #define NBANDS 10 @@ -117,6 +119,7 @@ sync_bus_handler (GstBus * bus, GstMessage * message, GstElement * bin) /* Gstreamer message handler */ gboolean message_handler (GstBus * bus, GstMessage * message, gpointer data) { + //printf("Elapsed time = %f sec\n", g_timer_elapsed (timer, NULL)); int ii = 0; //printf("message = %d\n", message->type); @@ -170,8 +173,14 @@ static gboolean cb_print_position (GstElement *pipeline){ gchar positionLabel[50]; //gchar shortPos[7], shortLen[7]; GstFormat fmt = GST_FORMAT_TIME; +#ifdef GSTREAMER1 + if (gst_element_query_position (pipeline, fmt, &pos) + && gst_element_query_duration (pipeline, fmt, &len)) +#elif defined GSTREAMER0 if (gst_element_query_position (pipeline, &fmt, &pos) - && gst_element_query_duration (pipeline, &fmt, &len)) { + && gst_element_query_duration (pipeline, &fmt, &len)) +#endif + { gdouble setPos = ((gdouble)pos)/((gdouble)len) * 100; /* pScaleSeek has to be updated with the new time value, but the callback (that updates the time values when pScaleSeek has been changed) doesn't have to be activated; the callback to the 'on_seek' function while moving pScaleSeek has to be blocked */ g_signal_handlers_block_by_func(G_OBJECT(scaleSeek), G_CALLBACK(on_seek), NULL); @@ -253,6 +262,8 @@ if (playing){ setPlayButtonIcon(); if (source == MICRO){ gst_element_set_state (pipeline, GST_STATE_PAUSED); + g_timer_stop (timer); + printf("pause timer\n"); } else if (source == SOUND_FILE){ gst_element_set_state (playbin, GST_STATE_PAUSED); @@ -263,6 +274,7 @@ if (playing){ setPlayButtonIcon(); if (source == MICRO){ gst_element_set_state (pipeline, GST_STATE_PLAYING); + g_timer_continue (timer); } else if (source == SOUND_FILE){ gst_element_set_state (playbin, GST_STATE_PLAYING); @@ -366,7 +378,11 @@ else if (playing == 0) { } } else if (source == SOUND_FILE) { +#ifdef GSTREAMER1 + playbin = gst_element_factory_make ("playbin", NULL); +#elif defined GSTREAMER0 playbin = gst_element_factory_make ("playbin2", NULL); +#endif g_assert (playbin); g_object_set (G_OBJECT (playbin), "uri", g_filename_to_uri(selected_file, NULL, NULL), NULL); } @@ -438,23 +454,37 @@ else if (playing == 0) { gst_bin_add_many (GST_BIN (pipeline), equalizer, equalizer2, equalizer3, audioconvert2, BP_BRfilter, audioconvert3, spectrum, flacenc, sink, NULL); /* link elements */ - caps = gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, AUDIOFREQ, NULL); +#ifdef GSTREAMER1 + caps = gst_caps_new_simple ("audio/x-raw", "rate", G_TYPE_INT, AUDIOFREQ, NULL); +#elif defined GSTREAMER0 + caps = gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, AUDIOFREQ, NULL); +#endif if (source == MICRO){ if (jack) { if (!gst_element_link (src, equalizer)) { - fprintf (stderr, "can't link elements 1\n"); + fprintf (stderr, "can't link elements \n"); exit (1); } } else { - if (!gst_element_link_filtered (src, equalizer, caps)) { +#ifdef GSTREAMER1 + if (!gst_element_link (src, equalizer)) +#elif defined GSTREAMER0 + if (!gst_element_link_filtered (src, equalizer, caps)) +#endif + { fprintf (stderr, "can't link elements 1\n"); exit (1); } } } else if (source == SOUND_FILE){ - if (!gst_element_link_filtered (audioconvert, equalizer, caps)){ +#ifdef GSTREAMER1 + if (!gst_element_link (audioconvert, equalizer)) +#elif defined GSTREAMER0 + if (!gst_element_link_filtered (audioconvert, equalizer, caps)) +#endif + { fprintf (stderr, "can't link elements 2\n"); exit (1); } @@ -499,13 +529,18 @@ else if (playing == 0) { /* if realtime is enabled */ if (spectrum3d.realtime && jack == FALSE) { busRT = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); +#ifdef GSTREAMER1 + gst_bus_set_sync_handler (busRT, (GstBusSyncHandler) sync_bus_handler, pipeline, NULL); +#elif defined GSTREAMER0 gst_bus_set_sync_handler (busRT, (GstBusSyncHandler) sync_bus_handler, pipeline); +#endif gst_object_unref (busRT); } /* set state to PLAYING and start main loop */ if (source == MICRO) { ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); + timer = g_timer_new (); } else if (source == SOUND_FILE) { gst_element_set_state (playbin, GST_STATE_PLAYING); @@ -521,6 +556,9 @@ else if (playing == 0) { /* stop playing */ if (source == MICRO) { gst_element_set_state (pipeline, GST_STATE_NULL); + if (timer != NULL) g_timer_continue(timer); + g_timer_stop (timer); + printf("Elapsed time = %f sec\n", g_timer_elapsed (timer, NULL)); } else if (source == SOUND_FILE) { g_source_remove(timeoutPrintPosition); diff --git a/src/main.c b/src/main.c index e4a9589..07ffd77 100644 --- a/src/main.c +++ b/src/main.c @@ -156,7 +156,6 @@ gtk_container_add(GTK_CONTAINER(window), spectrum3dGui->drawing_area); g_signal_connect (window, "motion-notify-event", G_CALLBACK (on_mouse_motion), NULL); g_signal_connect (window, "scroll-event", G_CALLBACK (on_mouse_scroll), NULL); g_signal_connect (G_OBJECT (spectrum3dGui->drawing_area), "configure_event", G_CALLBACK (configure_event), NULL); - //SDL_EnableKeyRepeat(10, 10); gtk_widget_show_all(window); } @@ -164,7 +163,15 @@ gtk_container_add(GTK_CONTAINER(window), spectrum3dGui->drawing_area); int main(int argc, char *argv[]) { printf("%s \nPlease report any bug to %s\n", PACKAGE_STRING, PACKAGE_BUGREPORT); - + //printf("number of arg = %d, argv = %s\n", argc, argv[1]); + /*printf("argc = %d\n", argc); + if (argv[1] != NULL) { + if (strstr (argv[1],"debug") != NULL) { + debug = TRUE; + printf("debug = TRUE\n"); + } + } + DEBUG("debug is true\n");*/ gchar *filename; int i = 0; gint initialWindowHeight = 170; @@ -173,6 +180,7 @@ int main(int argc, char *argv[]) GdkColor color; Spectrum3dGui spectrum3dGui; GSList *radio_menu_group; + GError **error; #if defined (GTKGLEXT3) || defined (GTKGLEXT1) GdkGLConfig *glconfig; @@ -214,7 +222,7 @@ int main(int argc, char *argv[]) gtk_widget_realize(spectrum3dGui.mainWindow); gtk_window_set_title(GTK_WINDOW(spectrum3dGui.mainWindow), PACKAGE_NAME); filename = g_build_filename (G_DIR_SEPARATOR_S, DATADIR, "icons", "spectrum3d.png", NULL); - gtk_window_set_icon(GTK_WINDOW(spectrum3dGui.mainWindow), create_pixbuf(filename)); + gtk_window_set_icon(GTK_WINDOW(spectrum3dGui.mainWindow), gdk_pixbuf_new_from_file (filename, error)); g_signal_connect (G_OBJECT (spectrum3dGui.mainWindow), "destroy", G_CALLBACK (quit_spectrum3d), NULL); #ifdef GTK3 diff --git a/src/record.c b/src/record.c index 7277869..ad4c416 100644 --- a/src/record.c +++ b/src/record.c @@ -79,7 +79,7 @@ void record_window() { analyse_rt = FALSE; selected_file = g_build_filename (tmpPath, NULL); printf("tmpPath is %s\n", selected_file); - load_audio_file(); + load_audio_file("rec"); break; case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_NONE: diff --git a/src/record.h b/src/record.h index 82a118f..8c1e517 100644 --- a/src/record.h +++ b/src/record.h @@ -36,7 +36,7 @@ void playFromSource(GtkWidget *widget, gpointer *data); void on_stop(); void setPlayButtonIcon (GtkWidget *widget, gpointer data); void error_message_window(gchar *message); -void load_audio_file(); +void load_audio_file(gchar *fileType); #endif diff --git a/src/spectrum3d.h b/src/spectrum3d.h index 0a03b89..7f86922 100644 --- a/src/spectrum3d.h +++ b/src/spectrum3d.h @@ -2,6 +2,9 @@ #ifndef DEFINE_SPECTRUM3D #define DEFINE_SPECTRUM3D +gboolean debug; +#define DEBUG(...) if(debug == TRUE) printf(__VA_ARGS__); + /* Spectrum3dGui structure declares elements that are part the the Gtk GUI of Spectrum3D and have to be passed to another function */ typedef struct { diff --git a/src/typesource.c b/src/typesource.c index b4c5b05..f57dc7e 100644 --- a/src/typesource.c +++ b/src/typesource.c @@ -26,9 +26,10 @@ #include "spectrum3d.h" #include "typesource.h" -int lenght = 0; +int length = 0; GtkWidget *progressWindow; GMainLoop *load_loop; +GTimer *timer; /* Quit everything except GTK GUI */ void set_source_to_none(){ @@ -147,7 +148,7 @@ void select_audio_file() printf("Uri of selected_file = %s\n", g_filename_to_uri(selected_file, NULL, NULL)); //typefind_pipeline(); // this send to a function that finds type; FIXME : this has to be implemented and generate error message if type is not audio if (analyse_rt == FALSE){ - load_audio_file(); + load_audio_file("file"); } break; case GTK_RESPONSE_CANCEL: @@ -159,15 +160,21 @@ void select_audio_file() } /* Get the lenght of the pipeline */ -gboolean get_pipeline_lenght (GstElement *pipeline) +gboolean get_pipeline_length (GstElement *pipelineLength) { printf("get_pipeline_length\n"); gboolean result = TRUE; + gint64 leng; GstFormat fmt = GST_FORMAT_TIME; - if (gst_element_query_duration (pipeline, &fmt, &len)) { - lenght = (int)GST_TIME_AS_SECONDS(len); - printf("lenght = %d seconds\n", lenght); - if (lenght > 0 && lenght < 36000) { +#ifdef GSTREAMER1 + if (gst_element_query_duration (pipelineLength, fmt, &leng)) +#elif defined GSTREAMER0 + if (gst_element_query_duration (pipelineLength, &fmt, &leng)) +#endif + { + length = (int)GST_TIME_AS_SECONDS(leng); + printf("length of stream = %d seconds\n", length); + if (length > 0 && length < 36000) { g_main_loop_quit (load_loop); result = FALSE; } @@ -178,8 +185,14 @@ gboolean get_pipeline_lenght (GstElement *pipeline) /* Print the progression in a progress bar when loading audio file */ gboolean update_progress_bar(GtkWidget *progress) { GstFormat fmt = GST_FORMAT_TIME; +#ifdef GSTREAMER1 + if (gst_element_query_position (pipeline, fmt, &pos) + && gst_element_query_duration (pipeline, fmt, &len)) +#elif defined GSTREAMER0 if (gst_element_query_position (pipeline, &fmt, &pos) - && gst_element_query_duration (pipeline, &fmt, &len)) { + && gst_element_query_duration (pipeline, &fmt, &len)) +#endif + { gdouble setPos = ((gdouble)pos)/((gdouble)len); //printf("setPos = %f\n", setPos); if (setPos >= 0 && setPos <= 1) { @@ -203,7 +216,7 @@ void show_progression() { progressWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_modal (GTK_WINDOW(progressWindow), TRUE); gtk_window_set_title(GTK_WINDOW(progressWindow), "Loading file"); - gtk_window_set_default_size(GTK_WINDOW(progressWindow), 320, 180); + gtk_window_set_default_size(GTK_WINDOW(progressWindow), 320, 100); gtk_container_set_border_width(GTK_CONTAINER(progressWindow), 4); g_signal_connect(G_OBJECT(progressWindow), "delete-event", G_CALLBACK(on_stop), NULL); @@ -223,17 +236,17 @@ void show_progression() { #endif gtk_box_pack_start(GTK_BOX(vbox), progress, TRUE, FALSE, 0); button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, TRUE, 0); gtk_widget_show_all(progressWindow); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_stop), NULL); g_timeout_add (200, (GSourceFunc) update_progress_bar, progress); } -/* Load the audio file : get its lenght, allocate memory for it, analyse the spectrum and display it */ -void load_audio_file(){ - printf("load audio file\n"); - GstElement *playbin; +/* Load the audio file : get its lenght, allocate memory for it, analyse the spectrum and display it; 'fileType' depends on the type of type sent : either a file recorded with spectrum3d, or a preexisting file ('file') */ +void load_audio_file(gchar *fileType){ + DEBUG("load audio file : %s\n", fileType); + GstElement *playbin, *pipelineLength; if (selected_file == NULL){ error_message_window("No file was selected.\nPlease select an audio file."); @@ -241,23 +254,31 @@ void load_audio_file(){ } loading = TRUE; // loading is set to TRUE; it will be set to FALSE again when the audio file hab been loaded; - // (re)initialize frame_number_counter - frame_number_counter = 0; + frame_number_counter = 0; // (re)initialize frame_number_counter - /* get lenght of the file; a 'playbin' pipeline is created with the file and its length is retrieved */ - load_loop = g_main_loop_new(NULL, FALSE); - playbin = gst_element_factory_make ("playbin", NULL); - g_assert (playbin); - g_object_set (G_OBJECT (playbin), "uri", g_filename_to_uri(selected_file, NULL, NULL), NULL); - GstFormat fmt = GST_FORMAT_TIME; - if (gst_element_query_duration (playbin, &fmt, &len)) { - lenght = (int)GST_TIME_AS_SECONDS(len); - printf("lenght = %d seconds\n", lenght); + /* get lenght of the file : if the file is recorded by spectrum3d ('fileType' == "rec"), the timer length will be used; if a preexisting file is loaded ('fileType' == "file"), a 'playbin' pipeline is created with the file and its length is retrieved */ + if (g_strcmp0(fileType, "rec") == 0) { + length = (int)(g_timer_elapsed (timer, NULL)); + } + else if (g_strcmp0(fileType, "file") == 0) { + load_loop = g_main_loop_new(NULL, FALSE); + #ifdef GSTREAMER1 + playbin = gst_element_factory_make ("playbin", NULL); + #elif defined GSTREAMER0 + playbin = gst_element_factory_make ("playbin2", NULL); + #endif + g_assert (playbin); + g_object_set (G_OBJECT (playbin), "uri", g_filename_to_uri(selected_file, NULL, NULL), NULL); + g_timeout_add (200, (GSourceFunc) get_pipeline_length, playbin); + gst_element_set_state (playbin, GST_STATE_PAUSED); + g_main_loop_run (load_loop); + gst_element_set_state (playbin, GST_STATE_NULL); } /* Calculate time interval between frames according to the lenght of the file; we will use a number of 'frames' = 200 to have everything displayed on the same screen */ - spectrum3d.interval_loaded = (lenght * 1000) / spectrum3d.frames; + DEBUG("fileType is '%s'; length = %d \n", fileType, length); + spectrum3d.interval_loaded = (length * 1000) / spectrum3d.frames; /* Get spectral data */ show_progression(); @@ -266,7 +287,7 @@ void load_audio_file(){ printf("Audio file is loaded\n"); loading = FALSE; newEvent = TRUE; -} +} /* Source buttons that behave almost like radio buttons; the typseSource is chosen; everything is stopped with the call to set_source_to_none, then the typeSource is chosen, even if the typeSource remains the same */ void change_source_button (GtkWidget *widget, Spectrum3dGui *spectrum3dGui){ diff --git a/src/typesource.h b/src/typesource.h index 19626fc..2ad387a 100644 --- a/src/typesource.h +++ b/src/typesource.h @@ -3,10 +3,11 @@ #define DEFINE_TYPESOURCE gboolean analyse_rt, loading, newEvent; -gchar *selected_file; +gchar *selected_file, *tmpPath; int spect_bands, frame_number_counter, playing, numberOfFrames; gint64 len, pos; GstElement *pipeline; +GMainLoop *loop; GLfloat spec_data[405][11030]; typedef enum TypeSource TypeSource;