llfloatervoicedevicesettings.cpp

Go to the documentation of this file.
00001 
00033 #include "llviewerprecompiledheaders.h"
00034 
00035 #include "llfloatervoicedevicesettings.h"
00036 
00037 // Viewer includes
00038 #include "llagent.h"
00039 #include "llbutton.h"
00040 #include "llcombobox.h"
00041 #include "llfocusmgr.h"
00042 #include "lliconctrl.h"
00043 #include "llprefsvoice.h"
00044 #include "llsliderctrl.h"
00045 #include "llviewercontrol.h"
00046 #include "llvoiceclient.h"
00047 #include "llimpanel.h"
00048 
00049 // Library includes (after viewer)
00050 #include "lluictrlfactory.h"
00051 
00052 
00053 LLPanelVoiceDeviceSettings::LLPanelVoiceDeviceSettings()
00054 {
00055         mCtrlInputDevices = NULL;
00056         mCtrlOutputDevices = NULL;
00057         mInputDevice = gSavedSettings.getString("VoiceInputAudioDevice");
00058         mOutputDevice = gSavedSettings.getString("VoiceOutputAudioDevice");
00059         mDevicesUpdated = FALSE;
00060 
00061         // grab "live" mic volume level
00062         mMicVolume = gSavedSettings.getF32("AudioLevelMic");
00063 
00064         // ask for new device enumeration
00065         // now do this in onOpen() instead...
00066         //gVoiceClient->refreshDeviceLists();
00067 }
00068 
00069 LLPanelVoiceDeviceSettings::~LLPanelVoiceDeviceSettings()
00070 {
00071 }
00072 
00073 BOOL LLPanelVoiceDeviceSettings::postBuild()
00074 {
00075         LLSlider* volume_slider = getChild<LLSlider>("mic_volume_slider");
00076         // set mic volume tuning slider based on last mic volume setting
00077         volume_slider->setValue(mMicVolume);
00078 
00079         childSetCommitCallback("voice_input_device", onCommitInputDevice, this);
00080         childSetCommitCallback("voice_output_device", onCommitOutputDevice, this);
00081         
00082         return TRUE;
00083 }
00084 
00085 void LLPanelVoiceDeviceSettings::draw()
00086 {
00087         // let user know that volume indicator is not yet available
00088         childSetVisible("wait_text", !gVoiceClient->inTuningMode());
00089 
00090         LLPanel::draw();
00091 
00092         F32 voice_power = gVoiceClient->tuningGetEnergy();
00093         S32 discrete_power = 0;
00094 
00095         if (!gVoiceClient->inTuningMode())
00096         {
00097                 discrete_power = 0;
00098         }
00099         else
00100         {
00101                 discrete_power = llmin(4, llfloor((voice_power / LLVoiceClient::OVERDRIVEN_POWER_LEVEL) * 4.f));
00102         }
00103         
00104         if (gVoiceClient->inTuningMode())
00105         {
00106                 for(S32 power_bar_idx = 0; power_bar_idx < 5; power_bar_idx++)
00107                 {
00108                         LLString view_name = llformat("%s%d", "bar", power_bar_idx);
00109                         LLView* bar_view = getChild<LLView>(view_name);
00110                         if (bar_view)
00111                         {
00112                                 if (power_bar_idx < discrete_power)
00113                                 {
00114                                         LLColor4 color = (power_bar_idx >= 3) ? gSavedSettings.getColor4("OverdrivenColor") : gSavedSettings.getColor4("SpeakingColor");
00115                                         gl_rect_2d(bar_view->getRect(), color, TRUE);
00116                                 }
00117                                 gl_rect_2d(bar_view->getRect(), LLColor4::grey, FALSE);
00118                         }
00119                 }
00120         }
00121 }
00122 
00123 void LLPanelVoiceDeviceSettings::apply()
00124 {
00125         std::string s;
00126         if(mCtrlInputDevices)
00127         {
00128                 s = mCtrlInputDevices->getSimple();
00129                 gSavedSettings.setString("VoiceInputAudioDevice", s);
00130         }
00131 
00132         if(mCtrlOutputDevices)
00133         {
00134                 s = mCtrlOutputDevices->getSimple();
00135                 gSavedSettings.setString("VoiceOutputAudioDevice", s);
00136         }
00137 
00138         // assume we are being destroyed by closing our embedding window
00139         gSavedSettings.setF32("AudioLevelMic", mMicVolume);
00140 }
00141 
00142 void LLPanelVoiceDeviceSettings::cancel()
00143 {
00144         gSavedSettings.setString("VoiceInputAudioDevice", mInputDevice);
00145         gSavedSettings.setString("VoiceOutputAudioDevice", mOutputDevice);
00146 
00147         if(mCtrlInputDevices)
00148                 mCtrlInputDevices->setSimple(mInputDevice);
00149 
00150         if(mCtrlOutputDevices)
00151                 mCtrlOutputDevices->setSimple(mOutputDevice);
00152 }
00153 
00154 void LLPanelVoiceDeviceSettings::refresh()
00155 {
00156         //grab current volume
00157         LLSlider* volume_slider = getChild<LLSlider>("mic_volume_slider");
00158         // set mic volume tuning slider based on last mic volume setting
00159         mMicVolume = (F32)volume_slider->getValue().asReal();
00160         gVoiceClient->tuningSetMicVolume(mMicVolume);
00161 
00162         // Fill in popup menus
00163         mCtrlInputDevices = getChild<LLComboBox>("voice_input_device");
00164         mCtrlOutputDevices = getChild<LLComboBox>("voice_output_device");
00165 
00166         if(!gVoiceClient->deviceSettingsAvailable())
00167         {
00168                 // The combo boxes are disabled, since we can't get the device settings from the daemon just now.
00169                 // Put the currently set default (ONLY) in the box, and select it.
00170                 if(mCtrlInputDevices)
00171                 {
00172                         mCtrlInputDevices->removeall();
00173                         mCtrlInputDevices->add( mInputDevice, ADD_BOTTOM );
00174                         mCtrlInputDevices->setSimple(mInputDevice);
00175                 }
00176                 if(mCtrlOutputDevices)
00177                 {
00178                         mCtrlOutputDevices->removeall();
00179                         mCtrlOutputDevices->add( mOutputDevice, ADD_BOTTOM );
00180                         mCtrlOutputDevices->setSimple(mOutputDevice);
00181                 }
00182         }
00183         else if (!mDevicesUpdated)
00184         {
00185                 LLVoiceClient::deviceList *devices;
00186                 
00187                 LLVoiceClient::deviceList::iterator iter;
00188                 
00189                 if(mCtrlInputDevices)
00190                 {
00191                         mCtrlInputDevices->removeall();
00192                         mCtrlInputDevices->add( getString("default_text"), ADD_BOTTOM );
00193 
00194                         devices = gVoiceClient->getCaptureDevices();
00195                         for(iter=devices->begin(); iter != devices->end(); iter++)
00196                         {
00197                                 mCtrlInputDevices->add( *iter, ADD_BOTTOM );
00198                         }
00199 
00200                         if(!mCtrlInputDevices->setSimple(mInputDevice))
00201                         {
00202                                 mCtrlInputDevices->setSimple(getString("default_text"));
00203                         }
00204                 }
00205                 
00206                 if(mCtrlOutputDevices)
00207                 {
00208                         mCtrlOutputDevices->removeall();
00209                         mCtrlOutputDevices->add( getString("default_text"), ADD_BOTTOM );
00210 
00211                         devices = gVoiceClient->getRenderDevices();
00212                         for(iter=devices->begin(); iter != devices->end(); iter++)
00213                         {
00214                                 mCtrlOutputDevices->add( *iter, ADD_BOTTOM );
00215                         }
00216 
00217                         if(!mCtrlOutputDevices->setSimple(mOutputDevice))
00218                         {
00219                                 mCtrlOutputDevices->setSimple(getString("default_text"));
00220                         }
00221                 }
00222                 mDevicesUpdated = TRUE;
00223         }       
00224 }
00225 
00226 void LLPanelVoiceDeviceSettings::onOpen()
00227 {
00228         mInputDevice = gSavedSettings.getString("VoiceInputAudioDevice");
00229         mOutputDevice = gSavedSettings.getString("VoiceOutputAudioDevice");
00230         mMicVolume = gSavedSettings.getF32("AudioLevelMic");
00231         mDevicesUpdated = FALSE;
00232 
00233         // ask for new device enumeration
00234         gVoiceClient->refreshDeviceLists();
00235 
00236         // put voice client in "tuning" mode
00237         gVoiceClient->tuningStart();
00238         LLVoiceChannel::suspend();
00239 }
00240 
00241 void LLPanelVoiceDeviceSettings::onClose(bool app_quitting)
00242 {
00243         gVoiceClient->tuningStop();
00244         LLVoiceChannel::resume();
00245 }
00246 
00247 // static
00248 void LLPanelVoiceDeviceSettings::onCommitInputDevice(LLUICtrl* ctrl, void* user_data)
00249 {
00250         gSavedSettings.setString("VoiceInputAudioDevice", ctrl->getValue().asString());
00251 }
00252 
00253 // static
00254 void LLPanelVoiceDeviceSettings::onCommitOutputDevice(LLUICtrl* ctrl, void* user_data)
00255 {
00256         gSavedSettings.setString("VoiceOutputAudioDevice", ctrl->getValue().asString());
00257 }
00258 
00259 //
00260 // LLFloaterVoiceDeviceSettings
00261 //
00262 
00263 LLFloaterVoiceDeviceSettings::LLFloaterVoiceDeviceSettings(const LLSD& seed) : LLFloater("floater_device_settings"), mDevicePanel(NULL)
00264 {
00265         mFactoryMap["device_settings"] = LLCallbackMap(createPanelVoiceDeviceSettings, this);
00266         // do not automatically open singleton floaters (as result of getInstance())
00267         BOOL no_open = FALSE;
00268         LLUICtrlFactory::getInstance()->buildFloater(this, "floater_device_settings.xml", &mFactoryMap, no_open);
00269         center();
00270 }
00271 
00272 void LLFloaterVoiceDeviceSettings::onOpen()
00273 {
00274         if(mDevicePanel)
00275         {
00276                 mDevicePanel->onOpen();
00277         }
00278 
00279         LLFloater::onOpen();
00280 }
00281 
00282 void LLFloaterVoiceDeviceSettings::onClose(bool app_quitting)
00283 {
00284         if(mDevicePanel)
00285         {
00286                 mDevicePanel->onClose(app_quitting);
00287         }
00288 
00289         setVisible(FALSE);
00290 }
00291 
00292 void LLFloaterVoiceDeviceSettings::apply()
00293 {
00294         if (mDevicePanel)
00295         {
00296                 mDevicePanel->apply();
00297         }
00298 }
00299 
00300 void LLFloaterVoiceDeviceSettings::cancel()
00301 {
00302         if (mDevicePanel)
00303         {
00304                 mDevicePanel->cancel();
00305         }
00306 }
00307 
00308 void LLFloaterVoiceDeviceSettings::draw()
00309 {
00310         if (mDevicePanel)
00311         {
00312                 mDevicePanel->refresh();
00313         }
00314         LLFloater::draw();
00315 }
00316 
00317 // static
00318 void* LLFloaterVoiceDeviceSettings::createPanelVoiceDeviceSettings(void* user_data)
00319 {
00320         LLFloaterVoiceDeviceSettings* floaterp = (LLFloaterVoiceDeviceSettings*)user_data;
00321         floaterp->mDevicePanel = new LLPanelVoiceDeviceSettings();
00322         return floaterp->mDevicePanel;
00323 }

Generated on Fri May 16 08:33:34 2008 for SecondLife by  doxygen 1.5.5