+2008-08-24 Jari Tenhunen <jari.tenhunen@iki.fi>
+ * src/tuner.c src/settings.h src/settings.c
+ src/Makefile.am configure.ac debian/control:
+ GConf backend for settings
+
2008-08-20 Jari Tenhunen <jari.tenhunen@iki.fi>
* src/tuner64.png src/tuner26.png:
Slightly reworked, transparent icons
AC_SUBST(HAVE_GTK)
AM_CONDITIONAL(HAVE_GTK, test "x$HAVE_GTK" = "xyes")
+dnl If we need them, we can also use the gstreamer-controller libraries
+PKG_CHECK_MODULES(GCONF,
+ gconf-2.0,
+ HAVE_GCONF=yes, HAVE_GCONF=no)
+
+dnl Give a warning if we don't have gstreamer-controller
+dnl you can turn this into an error if you need them
+if test "x$HAVE_GCONF" = "xno"; then
+ AC_MSG_ERROR(no GConf libraries found)
+fi
+
+dnl make _CFLAGS and _LIBS available
+AC_SUBST(GCONF_CFLAGS)
+AC_SUBST(GCONFL_LIBS)
+
dnl set the plugindir where plugins should be installed
if test "x${prefix}" = "x$HOME"; then
plugindir="$HOME/.gstreamer-$GST_MAJORMINOR/plugins"
Section: user/tools
Priority: optional
Maintainer: Josep Torra <jtorra@uoc.edu>
-Build-Depends: debhelper (>= 4.0.0), libhildon1-dev | hildon-libs-dev, libgtk2.0-dev, libgstreamer0.10-dev, libgstreamer-plugins-base0.10-dev, libosso-dev (>= 1)
+Build-Depends: debhelper (>= 4.0.0), libhildon1-dev | hildon-libs-dev, libgtk2.0-dev, libgstreamer0.10-dev, libgstreamer-plugins-base0.10-dev, libosso-dev (>= 1), libgconf2-dev
Standards-Version: 3.6.0
Package: tuner
libgsttonesrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
# headers we need but don't want installed
-noinst_HEADERS = gstpitch.h gsttonesrc.h kiss_fft.h _kiss_fft_guts.h
+noinst_HEADERS = gstpitch.h gsttonesrc.h kiss_fft.h _kiss_fft_guts.h settings.h
EXTRA_DIST = tuner26.png tuner40.png tuner64.png
if HAVE_GTK
demo_tuner_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS)
demo_tuner_LDFLAGS = $(GST_LIBS) $(GTK_LIBS)
-tuner_SOURCES = tuner.c
+tuner_SOURCES = tuner.c settings.c
tuner_DEPENDENCIES = $(top_builddir)/src/libgstpitch.la $(top_builddir)/src/libgsttonesrc.la
-tuner_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) $(MAEMO_CFLAGS) -D_GNU_SOURCE
-tuner_LDADD = $(GST_LIBS) $(GTK_LIBS) $(MAEMO_LIBS) $(top_builddir)/src/libgstpitch.la $(top_builddir)/src/libgsttonesrc.la
+tuner_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) $(MAEMO_CFLAGS) $(GCONF_CFLAGS) -D_GNU_SOURCE
+tuner_LDADD = $(GST_LIBS) $(GTK_LIBS) $(MAEMO_LIBS) $(GCONF_LIBS) $(top_builddir)/src/libgstpitch.la $(top_builddir)/src/libgsttonesrc.la
break;
}
+ /*
g_debug("freq %d[%d]\n", frequency, frequency_module);
+ */
GST_DEBUG_OBJECT (filter, "preparing message, frequency = %d ", frequency);
s = gst_structure_new ("pitch", "frequency", G_TYPE_INT, frequency, NULL);
--- /dev/null
+/* vim: set sts=2 sw=2 et: */
+/*
+ * Copyright (C) 2008 Jari Tenhunen <jari.tenhunen@iki.fi>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "settings.h"
+
+static GConfClient * client = NULL;
+
+static GConfClient *
+get_client ()
+{
+ if (!client)
+ client = gconf_client_get_default ();
+
+ return client;
+
+}
+
+gboolean
+settings_get_display_keepalive (gboolean default_value)
+{
+ GConfValue * value = NULL;
+ GError * err = NULL;
+ gboolean val = default_value;
+
+ value = gconf_client_get (get_client (), GCONF_KEY_DISPLAY_KEEPALIVE, &err);
+ if (err) {
+ g_error_free (err);
+ }
+
+ if (value) {
+ if (value->type == GCONF_VALUE_BOOL)
+ val = gconf_value_get_bool (value);
+
+ gconf_value_free (value);
+ }
+
+ return val;
+}
+
+gboolean
+settings_set_disp_keepalive (gboolean val)
+{
+ return gconf_client_set_bool (get_client (), GCONF_KEY_DISPLAY_KEEPALIVE, val, NULL);
+}
+
+gint
+settings_get_algorithm (gint default_value)
+{
+ GConfValue * value = NULL;
+ GError * err = NULL;
+ gint val = default_value;
+
+ value = gconf_client_get (get_client (), GCONF_KEY_ALGORITHM, &err);
+ if (err) {
+ g_error_free (err);
+ }
+
+ if (value) {
+ if (value->type == GCONF_VALUE_INT)
+ val = gconf_value_get_int (value);
+
+ gconf_value_free (value);
+ }
+
+ return val;
+}
+
+gboolean
+settings_set_algorithm (gint val)
+{
+ return gconf_client_set_int (get_client (), GCONF_KEY_ALGORITHM, val, NULL);
+}
+
+gint
+settings_get_calibration (gint default_value)
+{
+ GError * err = NULL;
+ gint val;
+
+ val = gconf_client_get_int (get_client (), GCONF_KEY_CALIBRATION, &err);
+ if (err) {
+ val = default_value;
+ g_error_free (err);
+ }
+ if (val == 0)
+ val = default_value;
+
+ return val;
+}
+
+gboolean
+settings_set_calibration (gint value)
+{
+ return gconf_client_set_int (get_client (), GCONF_KEY_CALIBRATION, value, NULL);
+}
+
+gboolean
+settings_init (GConfClientNotifyFunc func, gpointer user_data)
+{
+ gconf_client_add_dir (get_client (), GCONF_ROOT, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+ gconf_client_notify_add (get_client (), GCONF_ROOT, func, user_data, NULL, NULL);
+
+ return TRUE;
+}
--- /dev/null
+/* vim: set sts=2 sw=2 et: */
+/*
+ * Copyright (C) 2008 Jari Tenhunen <jari.tenhunen@iki.fi>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __SETTINGS_H__
+#define __SETTINGS_H__
+
+#include <gconf/gconf-client.h>
+
+#define GCONF_ROOT "/apps/tuner"
+#define GCONF_KEY_ALGORITHM GCONF_ROOT "/algorithm"
+#define GCONF_KEY_CALIBRATION GCONF_ROOT "/calibration"
+#define GCONF_KEY_DISPLAY_KEEPALIVE GCONF_ROOT "/display_keepalive"
+
+gint settings_get_algorithm (gint default_value);
+gint settings_get_calibration (gint default_value);
+gboolean settings_set_calibration (gint value);
+gboolean settings_get_display_keepalive (gboolean default_value);
+gboolean settings_init (GConfClientNotifyFunc func, gpointer user_data);
+
+#endif /* __SETTINGS_H__ */
+
#include <math.h>
#include <gst/gst.h>
#include <gtk/gtk.h>
+#include <gconf/gconf-client.h>
+
+#include "gstpitch.h"
+#include "settings.h"
#define between(x,a,b) (((x)>=(a)) && ((x)<=(b)))
GstElement *bin1;
GstElement *bin2;
GstElement *tonesrc;
+ GstElement *pitch;
guint stop_timer_id;
+
+ gboolean display_keepalive;
#ifdef MAEMO
osso_context_t *osso_context;
gpointer app;
if (value >= CALIB_MIN && value <= CALIB_MAX) {
recalculate_scale (value);
+ settings_set_calibration (value);
}
}
return FALSE;
}
+static void
+display_keepalive_stop (AppData * appdata)
+{
+ if (appdata->display_timer_id) {
+ g_source_remove (appdata->display_timer_id);
+ appdata->display_timer_id = 0;
+ }
+}
+
static gboolean
topmost_notify (GObject * object, GParamSpec * pspec, gpointer user_data)
{
set_pipeline_states (appdata, GST_STATE_PLAYING);
/* keep display on */
- if (appdata->display_timer_id == 0)
+ if (appdata->display_keepalive && appdata->display_timer_id == 0)
display_keepalive (user_data);
}
else {
/* stop pipelines fully if the app stays in the background for 30 seconds */
appdata->stop_timer_id = g_timeout_add (30000, (GSourceFunc) stop_pipelines, user_data);
/* let display dim and switch off */
- if (appdata->display_timer_id) {
- g_source_remove (appdata->display_timer_id);
- appdata->display_timer_id = 0;
- }
+ display_keepalive_stop (appdata);
}
return FALSE;
}
#endif
+static void
+settings_notify (GConfClient * client, guint cnxn_id, GConfEntry * entry, gpointer user_data)
+{
+ AppData * appdata = (AppData *) user_data;
+
+ g_debug ("%s changed", gconf_entry_get_key (entry));
+
+ if (strcmp (gconf_entry_get_key (entry), GCONF_KEY_ALGORITHM) == 0) {
+ if (gconf_entry_get_value (entry) != NULL && gconf_entry_get_value (entry)->type == GCONF_VALUE_INT) {
+ g_object_set (G_OBJECT (appdata->pitch),
+ "algorithm", gconf_value_get_int (gconf_entry_get_value (entry)),
+ NULL);
+ }
+ }
+ else if (strcmp (gconf_entry_get_key (entry), GCONF_KEY_CALIBRATION) == 0) {
+ /* TODO */
+ }
+ else if (strcmp (gconf_entry_get_key (entry), GCONF_KEY_DISPLAY_KEEPALIVE) == 0) {
+ if (gconf_entry_get_value (entry) != NULL && gconf_entry_get_value (entry)->type == GCONF_VALUE_BOOL) {
+ appdata->display_keepalive = gconf_value_get_bool (gconf_entry_get_value (entry));
+
+ if (appdata->display_keepalive && appdata->display_timer_id == 0)
+ display_keepalive (user_data);
+ else
+ display_keepalive_stop (appdata);
+ }
+ }
+ else {
+ g_warning ("unknown GConf key `%s'", gconf_entry_get_key (entry));
+ }
+}
+
int
main (int argc, char *argv[])
{
#endif
osso_hw_state_t hw_state_mask = { TRUE, FALSE, FALSE, TRUE, 0 };
#endif
+ gint calib;
- GstElement *src1, *src2, *pitch, *sink1;
+ GstElement *src1, *src2, *sink1;
GstElement *sink2;
GstBus *bus;
plugin_pitch_init (NULL);
plugin_tonesrc_init (NULL);
- recalculate_scale (CALIB_DEFAULT);
/* Init the gtk - must be called before any hildon stuff */
gtk_init (&argc, &argv);
if (osso_hw_set_event_cb (appdata->osso_context, &hw_state_mask, osso_hw_state_cb, appdata) != OSSO_OK)
g_warning ("setting osso_hw_state_cb failed!");
+ settings_init (&settings_notify, appdata);
+
+ calib = settings_get_calibration (CALIB_DEFAULT);
+ recalculate_scale (calib);
+
mainBox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (mainBox), 0);
#if defined(MAEMO1)
appdata->bin1 = gst_pipeline_new ("bin1");
src1 = gst_element_factory_make (DEFAULT_AUDIOSRC, "src1");
- pitch = gst_element_factory_make ("pitch", "pitch");
- g_object_set (G_OBJECT (pitch), "message", TRUE, "minfreq", 10,
- "maxfreq", 4000, NULL);
+ appdata->pitch = gst_element_factory_make ("pitch", "pitch");
+
+ g_object_set (G_OBJECT (appdata->pitch), "message", TRUE, "minfreq", 10,
+ "maxfreq", 4000,
+ "algorithm", settings_get_algorithm (GST_PITCH_ALGORITHM_FFT),
+ NULL);
sink1 = gst_element_factory_make ("fakesink", "sink1");
g_object_set (G_OBJECT (sink1), "silent", 1, NULL);
- gst_bin_add_many (GST_BIN (appdata->bin1), src1, pitch, sink1, NULL);
- if (!gst_element_link_many (src1, pitch, sink1, NULL)) {
+ gst_bin_add_many (GST_BIN (appdata->bin1), src1, appdata->pitch, sink1, NULL);
+ if (!gst_element_link_many (src1, appdata->pitch, sink1, NULL)) {
fprintf (stderr, "cant link elements\n");
exit (1);
}
#ifdef HILDON
calibrate = hildon_number_editor_new (CALIB_MIN, CALIB_MAX);
hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (calibrate),
- CALIB_DEFAULT);
+ calib);
/* we don't want that ugly cursor there */
gtk_container_forall (GTK_CONTAINER (calibrate),
(GtkCallback) fix_hildon_number_editor, NULL);
G_CALLBACK (calibration_changed), NULL);
#else
calibrate = gtk_spin_button_new_with_range (CALIB_MIN, CALIB_MAX, 1);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (calibrate), CALIB_DEFAULT);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (calibrate), calib);
g_signal_connect (G_OBJECT (calibrate), "value_changed",
G_CALLBACK (calibration_changed), NULL);
#endif
gtk_widget_show_all (GTK_WIDGET (mainWin));
#endif
+#if HILDON == 1
+ appdata->display_keepalive = settings_get_display_keepalive (TRUE);
+
+ if (appdata->display_keepalive)
+ display_keepalive (appdata);
+#endif
+
set_pipeline_states (appdata, GST_STATE_PLAYING);
- display_keepalive (appdata);
+
gtk_main ();
set_pipeline_states (appdata, GST_STATE_NULL);