X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Ftuner.c;h=ec8d194786d1cfe06a0fb9167abe71f723162031;hb=HEAD;hp=b7dce3a5127296e1209a26761bd37083991b534b;hpb=7cc5114ad693e5500384993bd5e92910ba0c63b3;p=tunertool diff --git a/src/tuner.c b/src/tuner.c index b7dce3a..ec8d194 100644 --- a/src/tuner.c +++ b/src/tuner.c @@ -1,6 +1,7 @@ /* vim: set sts=2 sw=2 et: */ /* Tuner * Copyright (C) 2006 Josep Torra + * 2008-2009 Jari Tenhunen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,17 +24,16 @@ #include "config.h" #endif -#define TUNER_VERSION "0.4" - #ifdef HILDON #include #include #include +#include #include #define OSSO_PACKAGE "tuner-tool" -#define OSSO_VERSION TUNER_VERSION +#define OSSO_VERSION VERSION #endif /* ifdef HILDON */ @@ -58,6 +58,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 +102,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,9 +325,17 @@ 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, gint frequency) +update_frequency (AppData * appdata, gfloat frequency) { gchar *buffer; gint i, j; @@ -348,11 +358,13 @@ update_frequency (AppData * appdata, gint frequency) gtk_label_set_text (GTK_LABEL (appdata->targetFrequency), buffer); g_free (buffer); - buffer = g_strdup_printf ("Played frequency is %d Hz", frequency); + buffer = g_strdup_printf ("Played frequency is %.2f Hz", 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 */ @@ -364,9 +376,9 @@ message_handler (GstBus * bus, GstMessage * message, gpointer data) const gchar *name = gst_structure_get_name (s); if (strcmp (name, "pitch") == 0) { - gint frequency; + gfloat frequency; - frequency = g_value_get_int (gst_structure_get_value (s, "frequency")); + frequency = g_value_get_float (gst_structure_get_value (s, "frequency")); if (frequency != 0) update_frequency (data, frequency); } @@ -485,15 +497,17 @@ stop_pipelines (gpointer user_data) return FALSE; } +#ifdef FAKE_FREQUENCY static gboolean fake_frequency (gpointer user_data) { AppData * appdata = (AppData *) user_data; - update_frequency (appdata, 440); + update_frequency (appdata, 440.0); return TRUE; } +#endif #ifdef MAEMO static void @@ -649,7 +663,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 +674,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 +751,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 +899,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 ();