add version to about dialog
[tunertool] / src / tuner.c
index 3883260..7c1953f 100644 (file)
@@ -1,6 +1,7 @@
 /* vim: set sts=2 sw=2 et: */
 /* Tuner
  * Copyright (C) 2006 Josep Torra <j.torra@telefonica.net>
+ *               2008-2009 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
@@ -23,8 +24,6 @@
 #include "config.h"
 #endif
 
-#define TUNER_VERSION "0.4"
-
 #ifdef HILDON
 #include <hildon/hildon-defines.h>
 #include <hildon/hildon-program.h>
@@ -33,7 +32,7 @@
 #include <libosso.h>
 
 #define OSSO_PACKAGE "tuner-tool"
-#define OSSO_VERSION TUNER_VERSION
+#define OSSO_VERSION VERSION
 
 #endif /* ifdef HILDON */
 
@@ -58,6 +57,8 @@
 #define between(x,a,b) (((x)>=(a)) && ((x)<=(b)))
 
 #define MAGIC (1.059463094359f) /* 2^(1/2) */
+#define CENT (1.0005777895f) /* 1/100th of a half-tone */
+#define LOG_CENT (0.00057762265046662109f) /* ln (CENT) */
 
 extern gboolean plugin_pitch_init (GstPlugin * plugin);
 extern gboolean plugin_tonesrc_init (GstPlugin * plugin);
@@ -100,7 +101,7 @@ enum
 
 
 
-#define NUM_LEDS (66)
+#define NUM_LEDS (50)
 #define NUM_WKEYS (15) /* # of white keys in the piano keyboard */
 #define WKEY_WIDTH (45)
 
@@ -323,6 +324,14 @@ draw_leds (AppData * appdata, gint n)
   }
 }
 
+/* translate the interval (ratio of two freqs) into cents */
+gfloat
+interval2cent (gfloat freq, gfloat note)
+{
+  //return (gfloat) (log (freq / note) / log (CENT));
+  return (gfloat) (log (freq / note) / LOG_CENT);
+}
+
 /* update frequency info */
 static void
 update_frequency (AppData * appdata, gfloat frequency)
@@ -352,7 +361,9 @@ update_frequency (AppData * appdata, gfloat frequency)
   gtk_label_set_text (GTK_LABEL (appdata->currentFrequency), buffer);
   g_free (buffer);
 
-  draw_leds (appdata, (gint) roundf (min_diff));
+  /* make leds display the difference in steps of two cents */
+  diff = interval2cent (frequency, equal_tempered_scale[j].frequency);
+  draw_leds (appdata, (gint) roundf (diff / 2.0));
 }
 
 /* receive spectral data from element message */
@@ -485,6 +496,7 @@ stop_pipelines (gpointer user_data)
   return FALSE;
 }
 
+#ifdef FAKE_FREQUENCY
 static gboolean
 fake_frequency (gpointer user_data)
 {
@@ -494,6 +506,7 @@ fake_frequency (gpointer user_data)
 
   return TRUE;
 }
+#endif
 
 #ifdef MAEMO
 static void
@@ -649,7 +662,7 @@ about_activate (GtkWidget * widget, GtkWindow * main_win)
   GtkWidget *label;
   GtkWidget *dialog;
  
-  dialog = gtk_dialog_new_with_buttons("About tuner", main_win,
+  dialog = gtk_dialog_new_with_buttons("About Tuner", main_win,
       GTK_DIALOG_MODAL | 
       GTK_DIALOG_DESTROY_WITH_PARENT |
       GTK_DIALOG_NO_SEPARATOR,
@@ -660,7 +673,8 @@ about_activate (GtkWidget * widget, GtkWindow * main_win)
   vbox = gtk_vbox_new (FALSE, HILDON_MARGIN_DEFAULT);
   gtk_container_set_border_width (GTK_CONTAINER (vbox), HILDON_MARGIN_DEFAULT);
   gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
-  label = gtk_label_new ("Tuner Tool is developed by Josep Torra and Jari Tenhunen.\n"
+  label = gtk_label_new ("Version " VERSION 
+      "\nTuner Tool is developed by Josep Torra and Jari Tenhunen.\n"
       "http://n770galaxy.blogspot.com/\n");
   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 5);
 
@@ -736,7 +750,7 @@ main (int argc, char *argv[])
   gtk_init (&argc, &argv);
 
   app = HILDON_PROGRAM (hildon_program_get_instance ());
-  g_set_application_name ("Tuner Tool");
+  g_set_application_name ("Tuner");
 
   appdata->app = app;
 
@@ -884,9 +898,13 @@ main (int argc, char *argv[])
   if (appdata->display_keepalive)
     display_keepalive (appdata);
 
+  draw_leds (appdata, 0);
+
   set_pipeline_states (appdata, GST_STATE_PLAYING);
 
-  //g_timeout_add (2000, (GSourceFunc) fake_frequency, appdata);
+#ifdef FAKE_FREQUENCY
+  g_timeout_add (2000, (GSourceFunc) fake_frequency, appdata);
+#endif
 
   gtk_main ();