]> git.mxchange.org Git - flightgear.git/blob - src/Sound/voice.hxx
Interim windows build fix
[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 <OpenThreads/Thread>
41 #  include <OpenThreads/Mutex>
42 #  include <OpenThreads/ScopedLock>
43 #  include <OpenThreads/Condition>
44 #  include <simgear/threads/SGQueue.hxx>
45 #else
46 #  include <queue>
47 #endif // ENABLE_THREADS
48
49 using std::vector;
50
51
52
53 class FGVoiceMgr : public SGSubsystem {
54 public:
55         FGVoiceMgr();
56         ~FGVoiceMgr();
57         void init(void);
58         void shutdown();
59         void update(double dt);
60
61
62   class FGVoice;
63 protected:
64   friend class FGFestivalVoice;
65 #if defined(ENABLE_THREADS)
66         class FGVoiceThread;
67         FGVoiceThread *_thread;
68 #endif
69
70   std::string _host;
71   std::string _port;
72         bool _enabled;
73         SGPropertyNode_ptr _pausedNode;
74         bool _paused;
75   std::vector<FGVoice *> _voices;
76 };
77
78
79
80 #if defined(ENABLE_THREADS)
81 class FGVoiceMgr::FGVoiceThread : public OpenThreads::Thread {
82 public:
83         FGVoiceThread(FGVoiceMgr *mgr) : _mgr(mgr) {}
84         void run();
85         void wake_up() { _jobs.signal(); }
86
87 private:
88         void wait_for_jobs() { OpenThreads::ScopedLock<OpenThreads::Mutex> g(_mutex); _jobs.wait(&_mutex); }
89         OpenThreads::Condition _jobs;
90         OpenThreads::Mutex _mutex;
91 protected:
92         FGVoiceMgr *_mgr;
93 };
94 #endif
95
96
97 class FGVoiceMgr::FGVoice : public SGPropertyChangeListener {
98 public:
99   FGVoice(FGVoiceMgr * mgr ) : _mgr(mgr) {}
100   virtual ~FGVoice() {}
101   virtual void speak( const std::string & msg ) = 0;
102   virtual void update() = 0;
103   void pushMessage( const std::string & m);
104   bool speak();
105
106 protected:
107   void valueChanged(SGPropertyNode *node);
108
109   FGVoiceMgr *_mgr;
110
111   #if defined(ENABLE_THREADS)
112   SGLockedQueue<std::string> _msg;
113 #else
114   std::queue<std::string> _msg;
115 #endif
116
117
118 };
119
120 #endif // _VOICE_HXX