Integrate flite into aoview directly. Fix great circle computation.
[fw/altos] / aoview / aoview_voice.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #include "aoview.h"
19
20 #if HAVE_FLITE
21 #include <stdarg.h>
22
23 FILE    *aoview_flite;
24
25 void aoview_voice_open(void)
26 {
27         if (!aoview_flite)
28                 aoview_flite = aoview_flite_start();
29 }
30
31 void aoview_voice_close(void)
32 {
33         if (aoview_flite) {
34                 aoview_flite_stop();
35                 aoview_flite = NULL;
36         }
37 }
38
39 void aoview_voice_speak(char *format, ...)
40 {
41         va_list ap;
42
43         if (aoview_flite) {
44                 va_start(ap, format);
45                 vfprintf(aoview_flite, format, ap);
46                 fflush(aoview_flite);
47                 va_end(ap);
48         }
49 }
50
51 #else
52 void aoview_voice_open(void)
53 {
54 }
55
56 void aoview_voice_close(void)
57 {
58 }
59
60 void aoview_voice_speak(char *format, ...)
61 {
62 }
63 #endif
64
65
66 static GtkCheckMenuItem *voice_enable;
67
68 #define ALTOS_VOICE_PATH        "/apps/aoview/voice"
69
70 static void
71 aoview_voice_enable(GtkWidget *widget, gpointer data)
72 {
73         gboolean        enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
74         GError          *error;
75         GConfClient     *gconf_client;
76
77         if (enabled) {
78                 aoview_voice_open();
79                 aoview_voice_speak("enable voice\n");
80         } else {
81                 aoview_voice_speak("disable voice\n");
82                 aoview_voice_close();
83         }
84         gconf_client = gconf_client_get_default();
85         gconf_client_set_bool(gconf_client,
86                               ALTOS_VOICE_PATH,
87                               enabled,
88                               &error);
89 }
90
91 void
92 aoview_voice_init(GladeXML *xml)
93 {
94         gboolean        enabled;
95         GConfClient     *gconf_client;
96
97         voice_enable = GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "voice_enable"));
98         assert(voice_enable);
99
100         gconf_client = gconf_client_get_default();
101         enabled = TRUE;
102         if (gconf_client)
103         {
104                 GError  *error;
105
106                 error = NULL;
107                 enabled = gconf_client_get_bool(gconf_client,
108                                                 ALTOS_VOICE_PATH,
109                                                 &error);
110                 if (error)
111                         enabled = TRUE;
112         }
113         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(voice_enable), enabled);
114         if (enabled)
115                 aoview_voice_open();
116
117         g_signal_connect(G_OBJECT(voice_enable), "toggled",
118                          G_CALLBACK(aoview_voice_enable),
119                          voice_enable);
120 }