PageRenderTime 404ms CodeModel.GetById 221ms app.highlight 8ms RepoModel.GetById 174ms app.codeStats 0ms

/indra/newview/llpreviewsound.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 99 lines | 56 code | 15 blank | 28 comment | 6 complexity | 2a79e821ca51c274815ff41c3cb1a72c MD5 | raw file
 1/** 
 2 * @file llpreviewsound.cpp
 3 * @brief LLPreviewSound class implementation
 4 *
 5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#include "llviewerprecompiledheaders.h"
28
29#include "llaudioengine.h"
30#include "llagent.h"          // gAgent
31#include "llbutton.h"
32#include "llinventory.h"
33#include "lllineeditor.h"
34#include "llpreviewsound.h"
35#include "llresmgr.h"
36#include "llviewercontrol.h"
37#include "llviewermessage.h"  // send_guid_sound_trigger
38#include "lluictrlfactory.h"
39
40extern LLAudioEngine* gAudiop;
41extern LLAgent gAgent;
42
43const F32 SOUND_GAIN = 1.0f;
44
45LLPreviewSound::LLPreviewSound(const LLSD& key)
46  : LLPreview( key )
47{
48}
49
50// virtual
51BOOL	LLPreviewSound::postBuild()
52{
53	const LLInventoryItem* item = getItem();
54	if (item)
55	{
56		getChild<LLUICtrl>("desc")->setValue(item->getDescription());
57		if (gAudiop)
58			gAudiop->preloadSound(item->getAssetUUID()); // preload the sound
59	}
60	
61	childSetAction("Sound play btn",&LLPreviewSound::playSound,this);
62	childSetAction("Sound audition btn",&LLPreviewSound::auditionSound,this);
63
64	LLButton* button = getChild<LLButton>("Sound play btn");
65	button->setSoundFlags(LLView::SILENT);
66	
67	button = getChild<LLButton>("Sound audition btn");
68	button->setSoundFlags(LLView::SILENT);
69
70	childSetCommitCallback("desc", LLPreview::onText, this);
71	getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);	
72
73	return LLPreview::postBuild();
74}
75
76// static
77void LLPreviewSound::playSound( void *userdata )
78{
79	LLPreviewSound* self = (LLPreviewSound*) userdata;
80	const LLInventoryItem *item = self->getItem();
81
82	if(item && gAudiop)
83	{
84		send_sound_trigger(item->getAssetUUID(), SOUND_GAIN);
85	}
86}
87
88// static
89void LLPreviewSound::auditionSound( void *userdata )
90{
91	LLPreviewSound* self = (LLPreviewSound*) userdata;
92	const LLInventoryItem *item = self->getItem();
93
94	if(item && gAudiop)
95	{
96		LLVector3d lpos_global = gAgent.getPositionGlobal();
97		gAudiop->triggerSound(item->getAssetUUID(), gAgent.getID(), SOUND_GAIN, LLAudioEngine::AUDIO_TYPE_UI, lpos_global);
98	}
99}