Debian Codegraph @

src/Sound/voice.hxx

raw symbols SCIP
1 // speech synthesis interface subsystem
2 //
3 // Written by Melchior FRANZ, started February 2006.
4 //
5 // Copyright (C) 2006 Melchior FRANZ - [email protected]
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 #pragma once
24
25 #include <vector>
26
27 #include <simgear/compiler.h>
28 #include <simgear/props/props.hxx>
29 #include <simgear/io/sg_socket.hxx>
30 #include <simgear/structure/subsystem_mgr.hxx>
31
32 #include <Main/fg_props.hxx>
33
34 #if defined(ENABLE_THREADS)
35 # include <OpenThreads/Thread>
36 # include <OpenThreads/Mutex>
37 # include <OpenThreads/ScopedLock>
38 # include <OpenThreads/Condition>
39 # include <simgear/threads/SGQueue.hxx>
40 #else
41 # include <queue>
42 #endif // ENABLE_THREADS
43
44
45 class FGVoiceMgr : public SGSubsystem
46 {
47 public:
48 FGVoiceMgr();
49 ~FGVoiceMgr();
50
51 // Subsystem API.
52 void init() override;
53 void shutdown() override;
54 void update(double dt) override;
55
56 // Subsystem identification.
57 static const char* staticSubsystemClassId() { return "voice"; }
58
59 class FGVoice;
60
61 protected:
62 friend class FGFestivalVoice;
63
64 #if defined(ENABLE_THREADS)
65 class FGVoiceThread;
66 FGVoiceThread *_thread;
67 #endif
68
69 std::string _host;
70 std::string _port;
71 bool _enabled;
72 SGPropertyNode_ptr _pausedNode;
73 bool _paused;
74 std::vector<FGVoice *> _voices;
75 };
76
77
78
79 #if defined(ENABLE_THREADS)
80 class FGVoiceMgr::FGVoiceThread : public OpenThreads::Thread
81 {
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
92 protected:
93 FGVoiceMgr *_mgr;
94 };
95 #endif
96
97
98 class FGVoiceMgr::FGVoice : public SGPropertyChangeListener
99 {
100 public:
101 FGVoice(FGVoiceMgr * mgr ) : _mgr(mgr) {}
102 virtual ~FGVoice() {}
103 virtual void speak( const std::string & msg ) = 0;
104 virtual void update(double dt) = 0;
105 void pushMessage( const std::string & m);
106 bool speak();
107
108 protected:
109 void valueChanged(SGPropertyNode *node);
110
111 FGVoiceMgr *_mgr;
112
113 #if defined(ENABLE_THREADS)
114 SGLockedQueue<std::string> _msg;
115 #else
116 std::queue<std::string> _msg;
117 #endif
118 };