/indra/newview/llfloatervoiceeffect.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 287 lines · 195 code · 42 blank · 50 comment · 29 complexity · 533f0d83854cf511be40a08f0b90d389 MD5 · raw file

  1. /**
  2. * @file llfloatervoiceeffect.cpp
  3. * @author Aimee
  4. * @brief Selection and preview of voice effect.
  5. *
  6. * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "llviewerprecompiledheaders.h"
  28. #include "llfloatervoiceeffect.h"
  29. #include "llscrolllistctrl.h"
  30. #include "lltrans.h"
  31. #include "llweb.h"
  32. LLFloaterVoiceEffect::LLFloaterVoiceEffect(const LLSD& key)
  33. : LLFloater(key)
  34. {
  35. mCommitCallbackRegistrar.add("VoiceEffect.Record", boost::bind(&LLFloaterVoiceEffect::onClickRecord, this));
  36. mCommitCallbackRegistrar.add("VoiceEffect.Play", boost::bind(&LLFloaterVoiceEffect::onClickPlay, this));
  37. mCommitCallbackRegistrar.add("VoiceEffect.Stop", boost::bind(&LLFloaterVoiceEffect::onClickStop, this));
  38. // mCommitCallbackRegistrar.add("VoiceEffect.Activate", boost::bind(&LLFloaterVoiceEffect::onClickActivate, this));
  39. }
  40. // virtual
  41. LLFloaterVoiceEffect::~LLFloaterVoiceEffect()
  42. {
  43. if(LLVoiceClient::instanceExists())
  44. {
  45. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  46. if (effect_interface)
  47. {
  48. effect_interface->removeObserver(this);
  49. }
  50. }
  51. }
  52. // virtual
  53. BOOL LLFloaterVoiceEffect::postBuild()
  54. {
  55. setDefaultBtn("record_btn");
  56. getChild<LLButton>("record_btn")->setFocus(true);
  57. getChild<LLUICtrl>("voice_morphing_link")->setTextArg("[URL]", LLTrans::getString("voice_morphing_url"));
  58. mVoiceEffectList = getChild<LLScrollListCtrl>("voice_effect_list");
  59. if (mVoiceEffectList)
  60. {
  61. mVoiceEffectList->setCommitCallback(boost::bind(&LLFloaterVoiceEffect::onClickPlay, this));
  62. // mVoiceEffectList->setDoubleClickCallback(boost::bind(&LLFloaterVoiceEffect::onClickActivate, this));
  63. }
  64. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  65. if (effect_interface)
  66. {
  67. effect_interface->addObserver(this);
  68. // Disconnect from the current voice channel ready to record a voice sample for previewing
  69. effect_interface->enablePreviewBuffer(true);
  70. }
  71. refreshEffectList();
  72. updateControls();
  73. return TRUE;
  74. }
  75. // virtual
  76. void LLFloaterVoiceEffect::onClose(bool app_quitting)
  77. {
  78. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  79. if (effect_interface)
  80. {
  81. effect_interface->enablePreviewBuffer(false);
  82. }
  83. }
  84. void LLFloaterVoiceEffect::refreshEffectList()
  85. {
  86. if (!mVoiceEffectList)
  87. {
  88. return;
  89. }
  90. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  91. if (!effect_interface)
  92. {
  93. mVoiceEffectList->setEnabled(false);
  94. return;
  95. }
  96. LL_DEBUGS("Voice")<< "Rebuilding Voice Morph list."<< LL_ENDL;
  97. // Preserve selected items and scroll position
  98. S32 scroll_pos = mVoiceEffectList->getScrollPos();
  99. uuid_vec_t selected_items;
  100. std::vector<LLScrollListItem*> items = mVoiceEffectList->getAllSelected();
  101. for(std::vector<LLScrollListItem*>::const_iterator it = items.begin(); it != items.end(); it++)
  102. {
  103. selected_items.push_back((*it)->getUUID());
  104. }
  105. mVoiceEffectList->deleteAllItems();
  106. {
  107. // Add the "No Voice Morph" entry
  108. LLSD element;
  109. element["id"] = LLUUID::null;
  110. element["columns"][NAME_COLUMN]["column"] = "name";
  111. element["columns"][NAME_COLUMN]["value"] = getString("no_voice_effect");
  112. element["columns"][NAME_COLUMN]["font"]["style"] = "BOLD";
  113. LLScrollListItem* sl_item = mVoiceEffectList->addElement(element, ADD_BOTTOM);
  114. // *HACK: Copied from llfloatergesture.cpp : ["font"]["style"] does not affect font style :(
  115. if(sl_item)
  116. {
  117. ((LLScrollListText*)sl_item->getColumn(0))->setFontStyle(LLFontGL::BOLD);
  118. }
  119. }
  120. // Add each Voice Morph template, if there are any (template list includes all usable effects)
  121. const voice_effect_list_t& template_list = effect_interface->getVoiceEffectTemplateList();
  122. if (!template_list.empty())
  123. {
  124. for (voice_effect_list_t::const_iterator it = template_list.begin(); it != template_list.end(); ++it)
  125. {
  126. const LLUUID& effect_id = it->second;
  127. std::string effect_name = getString("effect_" + it->first); // will throw an error if the effect is not listed in the XML
  128. LLSD effect_properties = effect_interface->getVoiceEffectProperties(effect_id);
  129. // Tag the active effect.
  130. if (effect_id == LLVoiceClient::instance().getVoiceEffectDefault())
  131. {
  132. effect_name += " " + getString("active_voice_effect");
  133. }
  134. // Tag available effects that are new this session
  135. if (effect_properties["is_new"].asBoolean())
  136. {
  137. effect_name += " " + getString("new_voice_effect");
  138. }
  139. LLDate expiry_date = effect_properties["expiry_date"].asDate();
  140. bool is_template_only = effect_properties["template_only"].asBoolean();
  141. std::string font_style = "NORMAL";
  142. if (!is_template_only)
  143. {
  144. font_style = "BOLD";
  145. }
  146. LLSD element;
  147. element["id"] = effect_id;
  148. element["columns"][NAME_COLUMN]["column"] = "name";
  149. element["columns"][NAME_COLUMN]["value"] = effect_name;
  150. element["columns"][NAME_COLUMN]["font"]["style"] = font_style;
  151. element["columns"][1]["column"] = "expires";
  152. if (!is_template_only)
  153. {
  154. element["columns"][DATE_COLUMN]["value"] = expiry_date;
  155. element["columns"][DATE_COLUMN]["type"] = "date";
  156. }
  157. else {
  158. element["columns"][DATE_COLUMN]["value"] = getString("unsubscribed_voice_effect");
  159. }
  160. // element["columns"][DATE_COLUMN]["font"]["style"] = "NORMAL";
  161. LLScrollListItem* sl_item = mVoiceEffectList->addElement(element, ADD_BOTTOM);
  162. // *HACK: Copied from llfloatergesture.cpp : ["font"]["style"] does not affect font style :(
  163. if(sl_item)
  164. {
  165. LLFontGL::StyleFlags style = is_template_only ? LLFontGL::NORMAL : LLFontGL::BOLD;
  166. LLScrollListText* slt = dynamic_cast<LLScrollListText*>(sl_item->getColumn(0));
  167. llassert(slt);
  168. if (slt)
  169. {
  170. slt->setFontStyle(style);
  171. }
  172. }
  173. }
  174. }
  175. // Re-select items that were selected before, and restore the scroll position
  176. for(uuid_vec_t::iterator it = selected_items.begin(); it != selected_items.end(); it++)
  177. {
  178. mVoiceEffectList->selectByID(*it);
  179. }
  180. mVoiceEffectList->setScrollPos(scroll_pos);
  181. mVoiceEffectList->setEnabled(true);
  182. }
  183. void LLFloaterVoiceEffect::updateControls()
  184. {
  185. bool recording = false;
  186. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  187. if (effect_interface)
  188. {
  189. recording = effect_interface->isPreviewRecording();
  190. }
  191. getChild<LLButton>("record_btn")->setVisible(!recording);
  192. getChild<LLButton>("record_stop_btn")->setVisible(recording);
  193. }
  194. // virtual
  195. void LLFloaterVoiceEffect::onVoiceEffectChanged(bool effect_list_updated)
  196. {
  197. if (effect_list_updated)
  198. {
  199. refreshEffectList();
  200. }
  201. updateControls();
  202. }
  203. void LLFloaterVoiceEffect::onClickRecord()
  204. {
  205. LL_DEBUGS("Voice") << "Record clicked" << LL_ENDL;
  206. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  207. if (effect_interface)
  208. {
  209. effect_interface->recordPreviewBuffer();
  210. }
  211. updateControls();
  212. }
  213. void LLFloaterVoiceEffect::onClickPlay()
  214. {
  215. LL_DEBUGS("Voice") << "Play clicked" << LL_ENDL;
  216. if (!mVoiceEffectList)
  217. {
  218. return;
  219. }
  220. const LLUUID& effect_id = mVoiceEffectList->getCurrentID();
  221. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  222. if (effect_interface)
  223. {
  224. effect_interface->playPreviewBuffer(effect_id);
  225. }
  226. updateControls();
  227. }
  228. void LLFloaterVoiceEffect::onClickStop()
  229. {
  230. LL_DEBUGS("Voice") << "Stop clicked" << LL_ENDL;
  231. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  232. if (effect_interface)
  233. {
  234. effect_interface->stopPreviewBuffer();
  235. }
  236. updateControls();
  237. }
  238. //void LLFloaterVoiceEffect::onClickActivate()
  239. //{
  240. // LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  241. // if (effect_interface && mVoiceEffectList)
  242. // {
  243. // effect_interface->setVoiceEffect(mVoiceEffectList->getCurrentID());
  244. // }
  245. //}