]> git.mxchange.org Git - flightgear.git/blob - src/Sound/voice.hxx
Don't restore initial screen geometry because there is nothing in fg_os* to resize...
[flightgear.git] / src / Sound / voice.hxx
1 // speech synthesis interface subsystem
2 //
3 // Written by Melchior FRANZ, started February 2006.
4 //
5 // Copyright (C) 2006  Melchior FRANZ - mfranz@aon.at
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifndef _VOICE_HXX
24 #define _VOICE_HXX
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #include <vector>
31
32 #include <simgear/compiler.h>
33 #include <simgear/props/props.hxx>
34 #include <simgear/io/sg_socket.hxx>
35 #include <simgear/structure/subsystem_mgr.hxx>
36
37 #include <Main/fg_props.hxx>
38
39 #if defined(ENABLE_THREADS)
40 #  include <simgear/threads/SGThread.hxx>
41 #  include <simgear/threads/SGQueue.hxx>
42 #else
43 #  include <queue>
44    SG_USING_STD(queue);
45 #endif // ENABLE_THREADS
46
47 SG_USING_STD(vector);
48
49
50
51 class FGVoiceMgr : public SGSubsystem {
52 public:
53         FGVoiceMgr();
54         ~FGVoiceMgr();
55         void init(void);
56         void update(double dt);
57
58 private:
59         class FGVoice;
60
61 #if defined(ENABLE_THREADS)
62         class FGVoiceThread;
63         FGVoiceThread *_thread;
64 #endif
65
66         string _host;
67         string _port;
68         bool _enabled;
69         SGPropertyNode_ptr _pausedNode;
70         bool _paused;
71         vector<FGVoice *> _voices;
72 };
73
74
75
76 #if defined(ENABLE_THREADS)
77 class FGVoiceMgr::FGVoiceThread : public SGThread {
78 public:
79         FGVoiceThread(FGVoiceMgr *mgr) : _mgr(mgr) {}
80         void run();
81         void wake_up() { _jobs.signal(); }
82
83 private:
84         void wait_for_jobs() { SGGuard<SGMutex> g(_mutex); _jobs.wait(_mutex); }
85         SGPthreadCond _jobs;
86         SGMutex _mutex;
87         FGVoiceMgr *_mgr;
88 };
89 #endif
90
91
92
93 class FGVoiceMgr::FGVoice {
94 public:
95         FGVoice(FGVoiceMgr *, const SGPropertyNode_ptr);
96         ~FGVoice();
97         bool speak();
98         void update();
99         void setVolume(double);
100         void setPitch(double);
101         void setSpeed(double);
102         void pushMessage(string);
103
104 private:
105         class FGVoiceListener;
106         SGSocket *_sock;
107         bool _connected;
108         double _volume;
109         double _pitch;
110         double _speed;
111         SGPropertyNode_ptr _volumeNode;
112         SGPropertyNode_ptr _pitchNode;
113         SGPropertyNode_ptr _speedNode;
114         bool _festival;
115         FGVoiceMgr *_mgr;
116
117 #if defined(ENABLE_THREADS)
118         SGLockedQueue<string> _msg;
119 #else
120         queue<string> _msg;
121 #endif
122
123 };
124
125
126
127 class FGVoiceMgr::FGVoice::FGVoiceListener : public SGPropertyChangeListener {
128 public:
129         FGVoiceListener(FGVoice *voice) : _voice(voice) {}
130         void valueChanged(SGPropertyNode *node);
131
132 private:
133         FGVoice *_voice;
134 };
135
136
137 #endif // _VOICE_HXX