llfloatervoicedevicesettings.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:10k
源码类别:

游戏引擎

开发平台:

C++ Builder

  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-2010, 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
  22.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23.  * 
  24.  * By copying, modifying or distributing this software, you acknowledge
  25.  * that you have read and understood your obligations described above,
  26.  * and agree to abide by those obligations.
  27.  * 
  28.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30.  * COMPLETENESS OR PERFORMANCE.
  31.  * $/LicenseInfo$
  32.  */
  33.  
  34. #include "llviewerprecompiledheaders.h"
  35. #include "llfloatervoicedevicesettings.h"
  36. // Viewer includes
  37. #include "llbutton.h"
  38. #include "llcombobox.h"
  39. #include "llfocusmgr.h"
  40. #include "lliconctrl.h"
  41. #include "llsliderctrl.h"
  42. #include "llviewercontrol.h"
  43. #include "llvoiceclient.h"
  44. #include "llvoicechannel.h"
  45. // Library includes (after viewer)
  46. #include "lluictrlfactory.h"
  47. static LLRegisterPanelClassWrapper<LLPanelVoiceDeviceSettings> t_panel_group_general("panel_voice_device_settings");
  48. LLPanelVoiceDeviceSettings::LLPanelVoiceDeviceSettings()
  49. : LLPanel()
  50. {
  51. mCtrlInputDevices = NULL;
  52. mCtrlOutputDevices = NULL;
  53. mInputDevice = gSavedSettings.getString("VoiceInputAudioDevice");
  54. mOutputDevice = gSavedSettings.getString("VoiceOutputAudioDevice");
  55. mDevicesUpdated = FALSE;
  56. // grab "live" mic volume level
  57. mMicVolume = gSavedSettings.getF32("AudioLevelMic");
  58. // ask for new device enumeration
  59. // now do this in onOpen() instead...
  60. //gVoiceClient->refreshDeviceLists();
  61. }
  62. LLPanelVoiceDeviceSettings::~LLPanelVoiceDeviceSettings()
  63. {
  64. }
  65. BOOL LLPanelVoiceDeviceSettings::postBuild()
  66. {
  67. LLSlider* volume_slider = getChild<LLSlider>("mic_volume_slider");
  68. // set mic volume tuning slider based on last mic volume setting
  69. volume_slider->setValue(mMicVolume);
  70. childSetCommitCallback("voice_input_device", onCommitInputDevice, this);
  71. childSetCommitCallback("voice_output_device", onCommitOutputDevice, this);
  72. return TRUE;
  73. }
  74. // virtual
  75. void LLPanelVoiceDeviceSettings::handleVisibilityChange ( BOOL new_visibility )
  76. {
  77. if (new_visibility)
  78. {
  79. initialize();
  80. }
  81. else
  82. {
  83. cleanup();
  84. // when closing this window, turn of visiblity control so that 
  85. // next time preferences is opened we don't suspend voice
  86. gSavedSettings.setBOOL("ShowDeviceSettings", FALSE);
  87. }
  88. }
  89. void LLPanelVoiceDeviceSettings::draw()
  90. {
  91. refresh();
  92. // let user know that volume indicator is not yet available
  93. bool is_in_tuning_mode = gVoiceClient->inTuningMode();
  94. childSetVisible("wait_text", !is_in_tuning_mode);
  95. LLPanel::draw();
  96. if (is_in_tuning_mode)
  97. {
  98. const S32 num_bars = 5;
  99. F32 voice_power = gVoiceClient->tuningGetEnergy() / LLVoiceClient::OVERDRIVEN_POWER_LEVEL;
  100. S32 discrete_power = llmin(num_bars, llfloor(voice_power * (F32)num_bars + 0.1f));
  101. for(S32 power_bar_idx = 0; power_bar_idx < num_bars; power_bar_idx++)
  102. {
  103. std::string view_name = llformat("%s%d", "bar", power_bar_idx);
  104. LLView* bar_view = getChild<LLView>(view_name);
  105. if (bar_view)
  106. {
  107. gl_rect_2d(bar_view->getRect(), LLColor4::grey, TRUE);
  108. LLColor4 color;
  109. if (power_bar_idx < discrete_power)
  110. {
  111. color = (power_bar_idx >= 3) ? LLUIColorTable::instance().getColor("OverdrivenColor") : LLUIColorTable::instance().getColor("SpeakingColor");
  112. }
  113. else
  114. {
  115. color = LLUIColorTable::instance().getColor("PanelFocusBackgroundColor");
  116. }
  117. LLRect color_rect = bar_view->getRect();
  118. color_rect.stretch(-1);
  119. gl_rect_2d(color_rect, color, TRUE);
  120. }
  121. }
  122. }
  123. }
  124. void LLPanelVoiceDeviceSettings::apply()
  125. {
  126. std::string s;
  127. if(mCtrlInputDevices)
  128. {
  129. s = mCtrlInputDevices->getSimple();
  130. gSavedSettings.setString("VoiceInputAudioDevice", s);
  131. mInputDevice = s;
  132. }
  133. if(mCtrlOutputDevices)
  134. {
  135. s = mCtrlOutputDevices->getSimple();
  136. gSavedSettings.setString("VoiceOutputAudioDevice", s);
  137. mOutputDevice = s;
  138. }
  139. // assume we are being destroyed by closing our embedding window
  140. LLSlider* volume_slider = getChild<LLSlider>("mic_volume_slider");
  141. if(volume_slider)
  142. {
  143. F32 slider_value = (F32)volume_slider->getValue().asReal();
  144. gSavedSettings.setF32("AudioLevelMic", slider_value);
  145. mMicVolume = slider_value;
  146. }
  147. }
  148. void LLPanelVoiceDeviceSettings::cancel()
  149. {
  150. gSavedSettings.setString("VoiceInputAudioDevice", mInputDevice);
  151. gSavedSettings.setString("VoiceOutputAudioDevice", mOutputDevice);
  152. if(mCtrlInputDevices)
  153. mCtrlInputDevices->setSimple(mInputDevice);
  154. if(mCtrlOutputDevices)
  155. mCtrlOutputDevices->setSimple(mOutputDevice);
  156. gSavedSettings.setF32("AudioLevelMic", mMicVolume);
  157. LLSlider* volume_slider = getChild<LLSlider>("mic_volume_slider");
  158. if(volume_slider)
  159. {
  160. volume_slider->setValue(mMicVolume);
  161. }
  162. }
  163. void LLPanelVoiceDeviceSettings::refresh()
  164. {
  165. //grab current volume
  166. LLSlider* volume_slider = getChild<LLSlider>("mic_volume_slider");
  167. // set mic volume tuning slider based on last mic volume setting
  168. F32 current_volume = (F32)volume_slider->getValue().asReal();
  169. gVoiceClient->tuningSetMicVolume(current_volume);
  170. // Fill in popup menus
  171. mCtrlInputDevices = getChild<LLComboBox>("voice_input_device");
  172. mCtrlOutputDevices = getChild<LLComboBox>("voice_output_device");
  173. if(!gVoiceClient->deviceSettingsAvailable())
  174. {
  175. // The combo boxes are disabled, since we can't get the device settings from the daemon just now.
  176. // Put the currently set default (ONLY) in the box, and select it.
  177. if(mCtrlInputDevices)
  178. {
  179. mCtrlInputDevices->removeall();
  180. mCtrlInputDevices->add( mInputDevice, ADD_BOTTOM );
  181. mCtrlInputDevices->setSimple(mInputDevice);
  182. }
  183. if(mCtrlOutputDevices)
  184. {
  185. mCtrlOutputDevices->removeall();
  186. mCtrlOutputDevices->add( mOutputDevice, ADD_BOTTOM );
  187. mCtrlOutputDevices->setSimple(mOutputDevice);
  188. }
  189. }
  190. else if (!mDevicesUpdated)
  191. {
  192. LLVoiceClient::deviceList *devices;
  193. LLVoiceClient::deviceList::iterator iter;
  194. if(mCtrlInputDevices)
  195. {
  196. mCtrlInputDevices->removeall();
  197. mCtrlInputDevices->add( getString("default_text"), ADD_BOTTOM );
  198. devices = gVoiceClient->getCaptureDevices();
  199. for(iter=devices->begin(); iter != devices->end(); iter++)
  200. {
  201. mCtrlInputDevices->add( *iter, ADD_BOTTOM );
  202. }
  203. if(!mCtrlInputDevices->setSimple(mInputDevice))
  204. {
  205. mCtrlInputDevices->setSimple(getString("default_text"));
  206. }
  207. }
  208. if(mCtrlOutputDevices)
  209. {
  210. mCtrlOutputDevices->removeall();
  211. mCtrlOutputDevices->add( getString("default_text"), ADD_BOTTOM );
  212. devices = gVoiceClient->getRenderDevices();
  213. for(iter=devices->begin(); iter != devices->end(); iter++)
  214. {
  215. mCtrlOutputDevices->add( *iter, ADD_BOTTOM );
  216. }
  217. if(!mCtrlOutputDevices->setSimple(mOutputDevice))
  218. {
  219. mCtrlOutputDevices->setSimple(getString("default_text"));
  220. }
  221. }
  222. mDevicesUpdated = TRUE;
  223. }
  224. }
  225. void LLPanelVoiceDeviceSettings::initialize()
  226. {
  227. mInputDevice = gSavedSettings.getString("VoiceInputAudioDevice");
  228. mOutputDevice = gSavedSettings.getString("VoiceOutputAudioDevice");
  229. mMicVolume = gSavedSettings.getF32("AudioLevelMic");
  230. mDevicesUpdated = FALSE;
  231. // ask for new device enumeration
  232. gVoiceClient->refreshDeviceLists();
  233. // put voice client in "tuning" mode
  234. gVoiceClient->tuningStart();
  235. LLVoiceChannel::suspend();
  236. }
  237. void LLPanelVoiceDeviceSettings::cleanup()
  238. {
  239. if (gVoiceClient)
  240. {
  241. gVoiceClient->tuningStop();
  242. }
  243. LLVoiceChannel::resume();
  244. }
  245. // static
  246. void LLPanelVoiceDeviceSettings::onCommitInputDevice(LLUICtrl* ctrl, void* user_data)
  247. {
  248. if(gVoiceClient)
  249. {
  250. gVoiceClient->setCaptureDevice(ctrl->getValue().asString());
  251. }
  252. }
  253. // static
  254. void LLPanelVoiceDeviceSettings::onCommitOutputDevice(LLUICtrl* ctrl, void* user_data)
  255. {
  256. if(gVoiceClient)
  257. {
  258. gVoiceClient->setRenderDevice(ctrl->getValue().asString());
  259. }
  260. }
  261. //
  262. // LLFloaterVoiceDeviceSettings
  263. //
  264. LLFloaterVoiceDeviceSettings::LLFloaterVoiceDeviceSettings(const LLSD& seed)
  265. : LLFloater(seed),
  266.   mDevicePanel(NULL)
  267. {
  268. mFactoryMap["device_settings"] = LLCallbackMap(createPanelVoiceDeviceSettings, this);
  269. // do not automatically open singleton floaters (as result of getInstance())
  270. // BOOL no_open = FALSE;
  271. // Called from floater reg:  LLUICtrlFactory::getInstance()->buildFloater(this, "floater_device_settings.xml", no_open);
  272. }
  273. BOOL LLFloaterVoiceDeviceSettings::postBuild()
  274. {
  275. center();
  276. return TRUE;
  277. }
  278. // virtual
  279. void LLFloaterVoiceDeviceSettings::onOpen(const LLSD& key)
  280. {
  281. if(mDevicePanel)
  282. {
  283. mDevicePanel->initialize();
  284. }
  285. }
  286. // virtual
  287. void LLFloaterVoiceDeviceSettings::onClose(bool app_settings)
  288. {
  289. if(mDevicePanel)
  290. {
  291. mDevicePanel->apply();
  292. mDevicePanel->cleanup();
  293. }
  294. }
  295. void LLFloaterVoiceDeviceSettings::apply()
  296. {
  297. if (mDevicePanel)
  298. {
  299. mDevicePanel->apply();
  300. }
  301. }
  302. void LLFloaterVoiceDeviceSettings::cancel()
  303. {
  304. if (mDevicePanel)
  305. {
  306. mDevicePanel->cancel();
  307. }
  308. }
  309. void LLFloaterVoiceDeviceSettings::draw()
  310. {
  311. if (mDevicePanel)
  312. {
  313. mDevicePanel->refresh();
  314. }
  315. LLFloater::draw();
  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. }