PageRenderTime 648ms CodeModel.GetById 433ms app.highlight 67ms RepoModel.GetById 144ms app.codeStats 1ms

/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
 28#include "llviewerprecompiledheaders.h"
 29
 30#include "llfloatervoiceeffect.h"
 31
 32#include "llscrolllistctrl.h"
 33#include "lltrans.h"
 34#include "llweb.h"
 35
 36LLFloaterVoiceEffect::LLFloaterVoiceEffect(const LLSD& key)
 37	: LLFloater(key)
 38{
 39	mCommitCallbackRegistrar.add("VoiceEffect.Record",	boost::bind(&LLFloaterVoiceEffect::onClickRecord, this));
 40	mCommitCallbackRegistrar.add("VoiceEffect.Play",	boost::bind(&LLFloaterVoiceEffect::onClickPlay, this));
 41	mCommitCallbackRegistrar.add("VoiceEffect.Stop",	boost::bind(&LLFloaterVoiceEffect::onClickStop, this));
 42//	mCommitCallbackRegistrar.add("VoiceEffect.Activate", boost::bind(&LLFloaterVoiceEffect::onClickActivate, this));
 43}
 44
 45// virtual
 46LLFloaterVoiceEffect::~LLFloaterVoiceEffect()
 47{
 48	if(LLVoiceClient::instanceExists())
 49	{
 50		LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
 51		if (effect_interface)
 52		{
 53			effect_interface->removeObserver(this);
 54		}
 55	}
 56}
 57
 58// virtual
 59BOOL LLFloaterVoiceEffect::postBuild()
 60{
 61	setDefaultBtn("record_btn");
 62	getChild<LLButton>("record_btn")->setFocus(true);
 63	getChild<LLUICtrl>("voice_morphing_link")->setTextArg("[URL]", LLTrans::getString("voice_morphing_url"));
 64
 65	mVoiceEffectList = getChild<LLScrollListCtrl>("voice_effect_list");
 66	if (mVoiceEffectList)
 67	{
 68		mVoiceEffectList->setCommitCallback(boost::bind(&LLFloaterVoiceEffect::onClickPlay, this));
 69//		mVoiceEffectList->setDoubleClickCallback(boost::bind(&LLFloaterVoiceEffect::onClickActivate, this));
 70	}
 71
 72	LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
 73	if (effect_interface)
 74	{
 75		effect_interface->addObserver(this);
 76
 77		// Disconnect from the current voice channel ready to record a voice sample for previewing
 78		effect_interface->enablePreviewBuffer(true);
 79	}
 80
 81	refreshEffectList();
 82	updateControls();
 83
 84	return TRUE;
 85}
 86
 87// virtual
 88void LLFloaterVoiceEffect::onClose(bool app_quitting)
 89{
 90	LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
 91	if (effect_interface)
 92	{
 93		effect_interface->enablePreviewBuffer(false);
 94	}
 95}
 96
 97void LLFloaterVoiceEffect::refreshEffectList()
 98{
 99	if (!mVoiceEffectList)
100	{
101		return;
102	}
103
104	LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
105	if (!effect_interface)
106	{
107		mVoiceEffectList->setEnabled(false);
108		return;
109	}
110
111	LL_DEBUGS("Voice")<< "Rebuilding Voice Morph list."<< LL_ENDL;
112
113	// Preserve selected items and scroll position
114	S32 scroll_pos = mVoiceEffectList->getScrollPos();
115	uuid_vec_t selected_items;
116	std::vector<LLScrollListItem*> items = mVoiceEffectList->getAllSelected();
117	for(std::vector<LLScrollListItem*>::const_iterator it = items.begin(); it != items.end(); it++)
118	{
119		selected_items.push_back((*it)->getUUID());
120	}
121
122	mVoiceEffectList->deleteAllItems();
123
124	{
125		// Add the "No Voice Morph" entry
126		LLSD element;
127
128		element["id"] = LLUUID::null;
129		element["columns"][NAME_COLUMN]["column"] = "name";
130		element["columns"][NAME_COLUMN]["value"] = getString("no_voice_effect");
131		element["columns"][NAME_COLUMN]["font"]["style"] = "BOLD";
132
133		LLScrollListItem* sl_item = mVoiceEffectList->addElement(element, ADD_BOTTOM);
134		// *HACK: Copied from llfloatergesture.cpp : ["font"]["style"] does not affect font style :(
135		if(sl_item)
136		{
137			((LLScrollListText*)sl_item->getColumn(0))->setFontStyle(LLFontGL::BOLD);
138		}
139	}
140
141	// Add each Voice Morph template, if there are any (template list includes all usable effects)
142	const voice_effect_list_t& template_list = effect_interface->getVoiceEffectTemplateList();
143	if (!template_list.empty())
144	{
145		for (voice_effect_list_t::const_iterator it = template_list.begin(); it != template_list.end(); ++it)
146		{
147			const LLUUID& effect_id = it->second;
148			std::string effect_name = getString("effect_" + it->first); // will throw an error if the effect is not listed in the XML
149
150			LLSD effect_properties = effect_interface->getVoiceEffectProperties(effect_id);
151
152			// Tag the active effect.
153			if (effect_id == LLVoiceClient::instance().getVoiceEffectDefault())
154			{
155				effect_name += " " + getString("active_voice_effect");
156			}
157
158			// Tag available effects that are new this session
159			if (effect_properties["is_new"].asBoolean())
160			{
161				effect_name += " " + getString("new_voice_effect");
162			}
163
164			LLDate expiry_date = effect_properties["expiry_date"].asDate();
165			bool is_template_only = effect_properties["template_only"].asBoolean();
166
167			std::string font_style = "NORMAL";
168			if (!is_template_only)
169			{
170				font_style = "BOLD";
171			}
172
173			LLSD element;
174			element["id"] = effect_id;
175
176			element["columns"][NAME_COLUMN]["column"] = "name";
177			element["columns"][NAME_COLUMN]["value"] = effect_name;
178			element["columns"][NAME_COLUMN]["font"]["style"] = font_style;
179
180			element["columns"][1]["column"] = "expires";
181			if (!is_template_only)
182			{
183				element["columns"][DATE_COLUMN]["value"] = expiry_date;
184				element["columns"][DATE_COLUMN]["type"] = "date";
185			}
186			else {
187				element["columns"][DATE_COLUMN]["value"] = getString("unsubscribed_voice_effect");
188			}
189//			element["columns"][DATE_COLUMN]["font"]["style"] = "NORMAL";
190
191			LLScrollListItem* sl_item = mVoiceEffectList->addElement(element, ADD_BOTTOM);
192			// *HACK: Copied from llfloatergesture.cpp : ["font"]["style"] does not affect font style :(
193			if(sl_item)
194			{
195				LLFontGL::StyleFlags style = is_template_only ? LLFontGL::NORMAL : LLFontGL::BOLD;
196				LLScrollListText* slt = dynamic_cast<LLScrollListText*>(sl_item->getColumn(0));
197				llassert(slt);
198				if (slt)
199				{
200					slt->setFontStyle(style);
201				}
202			}
203		}
204	}
205
206	// Re-select items that were selected before, and restore the scroll position
207	for(uuid_vec_t::iterator it = selected_items.begin(); it != selected_items.end(); it++)
208	{
209		mVoiceEffectList->selectByID(*it);
210	}
211	mVoiceEffectList->setScrollPos(scroll_pos);
212	mVoiceEffectList->setEnabled(true);
213}
214
215void LLFloaterVoiceEffect::updateControls()
216{
217	bool recording = false;
218
219	LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
220	if (effect_interface)
221	{
222		recording = effect_interface->isPreviewRecording();
223	}
224
225	getChild<LLButton>("record_btn")->setVisible(!recording);
226	getChild<LLButton>("record_stop_btn")->setVisible(recording);
227}
228
229// virtual
230void LLFloaterVoiceEffect::onVoiceEffectChanged(bool effect_list_updated)
231{
232	if (effect_list_updated)
233	{
234		refreshEffectList();
235	}
236	updateControls();
237}
238
239void LLFloaterVoiceEffect::onClickRecord()
240{
241	LL_DEBUGS("Voice") << "Record clicked" << LL_ENDL;
242	LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
243	if (effect_interface)
244	{
245		effect_interface->recordPreviewBuffer();
246	}
247	updateControls();
248}
249
250void LLFloaterVoiceEffect::onClickPlay()
251{
252	LL_DEBUGS("Voice") << "Play clicked" << LL_ENDL;
253	if (!mVoiceEffectList)
254	{
255		return;
256	}
257
258	const LLUUID& effect_id = mVoiceEffectList->getCurrentID();
259
260	LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
261	if (effect_interface)
262	{
263		effect_interface->playPreviewBuffer(effect_id);
264	}
265	updateControls();
266}
267
268void LLFloaterVoiceEffect::onClickStop()
269{
270	LL_DEBUGS("Voice") << "Stop clicked" << LL_ENDL;
271	LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
272	if (effect_interface)
273	{
274		effect_interface->stopPreviewBuffer();
275	}
276	updateControls();
277}
278
279//void LLFloaterVoiceEffect::onClickActivate()
280//{
281//	LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
282//	if (effect_interface && mVoiceEffectList)
283//	{
284//		effect_interface->setVoiceEffect(mVoiceEffectList->getCurrentID());
285//	}
286//}
287