diff options
author | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
commit | ce28e056c20bf2723f565bbf464b87781ec248a2 (patch) | |
tree | ef7b0501c4de4b631a916305cbc2a5fdc125e52d /linden/indra/newview/llfloatervoicedevicesettings.cpp | |
parent | Second Life viewer sources 1.19.1.4b (diff) | |
download | meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.zip meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.gz meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.bz2 meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.xz |
Second Life viewer sources 1.20.2
Diffstat (limited to 'linden/indra/newview/llfloatervoicedevicesettings.cpp')
-rw-r--r-- | linden/indra/newview/llfloatervoicedevicesettings.cpp | 323 |
1 files changed, 323 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloatervoicedevicesettings.cpp b/linden/indra/newview/llfloatervoicedevicesettings.cpp new file mode 100644 index 0000000..c7b9562 --- /dev/null +++ b/linden/indra/newview/llfloatervoicedevicesettings.cpp | |||
@@ -0,0 +1,323 @@ | |||
1 | /** | ||
2 | * @file llfloatervoicedevicesettings.cpp | ||
3 | * @author Richard Nelson | ||
4 | * @brief Voice communication set-up | ||
5 | * | ||
6 | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
7 | * | ||
8 | * Copyright (c) 2007-2008, Linden Research, Inc. | ||
9 | * | ||
10 | * Second Life Viewer Source Code | ||
11 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
12 | * to you under the terms of the GNU General Public License, version 2.0 | ||
13 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
14 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
15 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
16 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
17 | * | ||
18 | * There are special exceptions to the terms and conditions of the GPL as | ||
19 | * it is applied to this Source Code. View the full text of the exception | ||
20 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
21 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
22 | * | ||
23 | * By copying, modifying or distributing this software, you acknowledge | ||
24 | * that you have read and understood your obligations described above, | ||
25 | * and agree to abide by those obligations. | ||
26 | * | ||
27 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
28 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
29 | * COMPLETENESS OR PERFORMANCE. | ||
30 | * $/LicenseInfo$ | ||
31 | */ | ||
32 | |||
33 | #include "llviewerprecompiledheaders.h" | ||
34 | |||
35 | #include "llfloatervoicedevicesettings.h" | ||
36 | |||
37 | // Viewer includes | ||
38 | #include "llagent.h" | ||
39 | #include "llbutton.h" | ||
40 | #include "llcombobox.h" | ||
41 | #include "llfocusmgr.h" | ||
42 | #include "lliconctrl.h" | ||
43 | #include "llprefsvoice.h" | ||
44 | #include "llsliderctrl.h" | ||
45 | #include "llviewercontrol.h" | ||
46 | #include "llvoiceclient.h" | ||
47 | #include "llimpanel.h" | ||
48 | |||
49 | // Library includes (after viewer) | ||
50 | #include "lluictrlfactory.h" | ||
51 | |||
52 | |||
53 | LLPanelVoiceDeviceSettings::LLPanelVoiceDeviceSettings() | ||
54 | { | ||
55 | mCtrlInputDevices = NULL; | ||
56 | mCtrlOutputDevices = NULL; | ||
57 | mInputDevice = gSavedSettings.getString("VoiceInputAudioDevice"); | ||
58 | mOutputDevice = gSavedSettings.getString("VoiceOutputAudioDevice"); | ||
59 | mDevicesUpdated = FALSE; | ||
60 | |||
61 | // grab "live" mic volume level | ||
62 | mMicVolume = gSavedSettings.getF32("AudioLevelMic"); | ||
63 | |||
64 | // ask for new device enumeration | ||
65 | // now do this in onOpen() instead... | ||
66 | //gVoiceClient->refreshDeviceLists(); | ||
67 | } | ||
68 | |||
69 | LLPanelVoiceDeviceSettings::~LLPanelVoiceDeviceSettings() | ||
70 | { | ||
71 | } | ||
72 | |||
73 | BOOL LLPanelVoiceDeviceSettings::postBuild() | ||
74 | { | ||
75 | LLSlider* volume_slider = getChild<LLSlider>("mic_volume_slider"); | ||
76 | // set mic volume tuning slider based on last mic volume setting | ||
77 | volume_slider->setValue(mMicVolume); | ||
78 | |||
79 | childSetCommitCallback("voice_input_device", onCommitInputDevice, this); | ||
80 | childSetCommitCallback("voice_output_device", onCommitOutputDevice, this); | ||
81 | |||
82 | return TRUE; | ||
83 | } | ||
84 | |||
85 | void LLPanelVoiceDeviceSettings::draw() | ||
86 | { | ||
87 | // let user know that volume indicator is not yet available | ||
88 | childSetVisible("wait_text", !gVoiceClient->inTuningMode()); | ||
89 | |||
90 | LLPanel::draw(); | ||
91 | |||
92 | F32 voice_power = gVoiceClient->tuningGetEnergy(); | ||
93 | S32 discrete_power = 0; | ||
94 | |||
95 | if (!gVoiceClient->inTuningMode()) | ||
96 | { | ||
97 | discrete_power = 0; | ||
98 | } | ||
99 | else | ||
100 | { | ||
101 | discrete_power = llmin(4, llfloor((voice_power / LLVoiceClient::OVERDRIVEN_POWER_LEVEL) * 4.f)); | ||
102 | } | ||
103 | |||
104 | if (gVoiceClient->inTuningMode()) | ||
105 | { | ||
106 | for(S32 power_bar_idx = 0; power_bar_idx < 5; power_bar_idx++) | ||
107 | { | ||
108 | LLString view_name = llformat("%s%d", "bar", power_bar_idx); | ||
109 | LLView* bar_view = getChild<LLView>(view_name); | ||
110 | if (bar_view) | ||
111 | { | ||
112 | if (power_bar_idx < discrete_power) | ||
113 | { | ||
114 | LLColor4 color = (power_bar_idx >= 3) ? gSavedSettings.getColor4("OverdrivenColor") : gSavedSettings.getColor4("SpeakingColor"); | ||
115 | gl_rect_2d(bar_view->getRect(), color, TRUE); | ||
116 | } | ||
117 | gl_rect_2d(bar_view->getRect(), LLColor4::grey, FALSE); | ||
118 | } | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | |||
123 | void LLPanelVoiceDeviceSettings::apply() | ||
124 | { | ||
125 | std::string s; | ||
126 | if(mCtrlInputDevices) | ||
127 | { | ||
128 | s = mCtrlInputDevices->getSimple(); | ||
129 | gSavedSettings.setString("VoiceInputAudioDevice", s); | ||
130 | } | ||
131 | |||
132 | if(mCtrlOutputDevices) | ||
133 | { | ||
134 | s = mCtrlOutputDevices->getSimple(); | ||
135 | gSavedSettings.setString("VoiceOutputAudioDevice", s); | ||
136 | } | ||
137 | |||
138 | // assume we are being destroyed by closing our embedding window | ||
139 | gSavedSettings.setF32("AudioLevelMic", mMicVolume); | ||
140 | } | ||
141 | |||
142 | void LLPanelVoiceDeviceSettings::cancel() | ||
143 | { | ||
144 | gSavedSettings.setString("VoiceInputAudioDevice", mInputDevice); | ||
145 | gSavedSettings.setString("VoiceOutputAudioDevice", mOutputDevice); | ||
146 | |||
147 | if(mCtrlInputDevices) | ||
148 | mCtrlInputDevices->setSimple(mInputDevice); | ||
149 | |||
150 | if(mCtrlOutputDevices) | ||
151 | mCtrlOutputDevices->setSimple(mOutputDevice); | ||
152 | } | ||
153 | |||
154 | void LLPanelVoiceDeviceSettings::refresh() | ||
155 | { | ||
156 | //grab current volume | ||
157 | LLSlider* volume_slider = getChild<LLSlider>("mic_volume_slider"); | ||
158 | // set mic volume tuning slider based on last mic volume setting | ||
159 | mMicVolume = (F32)volume_slider->getValue().asReal(); | ||
160 | gVoiceClient->tuningSetMicVolume(mMicVolume); | ||
161 | |||
162 | // Fill in popup menus | ||
163 | mCtrlInputDevices = getChild<LLComboBox>("voice_input_device"); | ||
164 | mCtrlOutputDevices = getChild<LLComboBox>("voice_output_device"); | ||
165 | |||
166 | if(!gVoiceClient->deviceSettingsAvailable()) | ||
167 | { | ||
168 | // The combo boxes are disabled, since we can't get the device settings from the daemon just now. | ||
169 | // Put the currently set default (ONLY) in the box, and select it. | ||
170 | if(mCtrlInputDevices) | ||
171 | { | ||
172 | mCtrlInputDevices->removeall(); | ||
173 | mCtrlInputDevices->add( mInputDevice, ADD_BOTTOM ); | ||
174 | mCtrlInputDevices->setSimple(mInputDevice); | ||
175 | } | ||
176 | if(mCtrlOutputDevices) | ||
177 | { | ||
178 | mCtrlOutputDevices->removeall(); | ||
179 | mCtrlOutputDevices->add( mOutputDevice, ADD_BOTTOM ); | ||
180 | mCtrlOutputDevices->setSimple(mOutputDevice); | ||
181 | } | ||
182 | } | ||
183 | else if (!mDevicesUpdated) | ||
184 | { | ||
185 | LLVoiceClient::deviceList *devices; | ||
186 | |||
187 | LLVoiceClient::deviceList::iterator iter; | ||
188 | |||
189 | if(mCtrlInputDevices) | ||
190 | { | ||
191 | mCtrlInputDevices->removeall(); | ||
192 | mCtrlInputDevices->add( getString("default_text"), ADD_BOTTOM ); | ||
193 | |||
194 | devices = gVoiceClient->getCaptureDevices(); | ||
195 | for(iter=devices->begin(); iter != devices->end(); iter++) | ||
196 | { | ||
197 | mCtrlInputDevices->add( *iter, ADD_BOTTOM ); | ||
198 | } | ||
199 | |||
200 | if(!mCtrlInputDevices->setSimple(mInputDevice)) | ||
201 | { | ||
202 | mCtrlInputDevices->setSimple(getString("default_text")); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | if(mCtrlOutputDevices) | ||
207 | { | ||
208 | mCtrlOutputDevices->removeall(); | ||
209 | mCtrlOutputDevices->add( getString("default_text"), ADD_BOTTOM ); | ||
210 | |||
211 | devices = gVoiceClient->getRenderDevices(); | ||
212 | for(iter=devices->begin(); iter != devices->end(); iter++) | ||
213 | { | ||
214 | mCtrlOutputDevices->add( *iter, ADD_BOTTOM ); | ||
215 | } | ||
216 | |||
217 | if(!mCtrlOutputDevices->setSimple(mOutputDevice)) | ||
218 | { | ||
219 | mCtrlOutputDevices->setSimple(getString("default_text")); | ||
220 | } | ||
221 | } | ||
222 | mDevicesUpdated = TRUE; | ||
223 | } | ||
224 | } | ||
225 | |||
226 | void LLPanelVoiceDeviceSettings::onOpen() | ||
227 | { | ||
228 | mInputDevice = gSavedSettings.getString("VoiceInputAudioDevice"); | ||
229 | mOutputDevice = gSavedSettings.getString("VoiceOutputAudioDevice"); | ||
230 | mMicVolume = gSavedSettings.getF32("AudioLevelMic"); | ||
231 | mDevicesUpdated = FALSE; | ||
232 | |||
233 | // ask for new device enumeration | ||
234 | gVoiceClient->refreshDeviceLists(); | ||
235 | |||
236 | // put voice client in "tuning" mode | ||
237 | gVoiceClient->tuningStart(); | ||
238 | LLVoiceChannel::suspend(); | ||
239 | } | ||
240 | |||
241 | void LLPanelVoiceDeviceSettings::onClose(bool app_quitting) | ||
242 | { | ||
243 | gVoiceClient->tuningStop(); | ||
244 | LLVoiceChannel::resume(); | ||
245 | } | ||
246 | |||
247 | // static | ||
248 | void LLPanelVoiceDeviceSettings::onCommitInputDevice(LLUICtrl* ctrl, void* user_data) | ||
249 | { | ||
250 | gSavedSettings.setString("VoiceInputAudioDevice", ctrl->getValue().asString()); | ||
251 | } | ||
252 | |||
253 | // static | ||
254 | void LLPanelVoiceDeviceSettings::onCommitOutputDevice(LLUICtrl* ctrl, void* user_data) | ||
255 | { | ||
256 | gSavedSettings.setString("VoiceOutputAudioDevice", ctrl->getValue().asString()); | ||
257 | } | ||
258 | |||
259 | // | ||
260 | // LLFloaterVoiceDeviceSettings | ||
261 | // | ||
262 | |||
263 | LLFloaterVoiceDeviceSettings::LLFloaterVoiceDeviceSettings(const LLSD& seed) : LLFloater("floater_device_settings"), mDevicePanel(NULL) | ||
264 | { | ||
265 | mFactoryMap["device_settings"] = LLCallbackMap(createPanelVoiceDeviceSettings, this); | ||
266 | // do not automatically open singleton floaters (as result of getInstance()) | ||
267 | BOOL no_open = FALSE; | ||
268 | LLUICtrlFactory::getInstance()->buildFloater(this, "floater_device_settings.xml", &mFactoryMap, no_open); | ||
269 | center(); | ||
270 | } | ||
271 | |||
272 | void LLFloaterVoiceDeviceSettings::onOpen() | ||
273 | { | ||
274 | if(mDevicePanel) | ||
275 | { | ||
276 | mDevicePanel->onOpen(); | ||
277 | } | ||
278 | |||
279 | LLFloater::onOpen(); | ||
280 | } | ||
281 | |||
282 | void LLFloaterVoiceDeviceSettings::onClose(bool app_quitting) | ||
283 | { | ||
284 | if(mDevicePanel) | ||
285 | { | ||
286 | mDevicePanel->onClose(app_quitting); | ||
287 | } | ||
288 | |||
289 | setVisible(FALSE); | ||
290 | } | ||
291 | |||
292 | void LLFloaterVoiceDeviceSettings::apply() | ||
293 | { | ||
294 | if (mDevicePanel) | ||
295 | { | ||
296 | mDevicePanel->apply(); | ||
297 | } | ||
298 | } | ||
299 | |||
300 | void LLFloaterVoiceDeviceSettings::cancel() | ||
301 | { | ||
302 | if (mDevicePanel) | ||
303 | { | ||
304 | mDevicePanel->cancel(); | ||
305 | } | ||
306 | } | ||
307 | |||
308 | void LLFloaterVoiceDeviceSettings::draw() | ||
309 | { | ||
310 | if (mDevicePanel) | ||
311 | { | ||
312 | mDevicePanel->refresh(); | ||
313 | } | ||
314 | LLFloater::draw(); | ||
315 | } | ||
316 | |||
317 | // static | ||
318 | void* LLFloaterVoiceDeviceSettings::createPanelVoiceDeviceSettings(void* user_data) | ||
319 | { | ||
320 | LLFloaterVoiceDeviceSettings* floaterp = (LLFloaterVoiceDeviceSettings*)user_data; | ||
321 | floaterp->mDevicePanel = new LLPanelVoiceDeviceSettings(); | ||
322 | return floaterp->mDevicePanel; | ||
323 | } | ||