llpreviewsound.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "audioengine.h"
00035 #include "llagent.h"          // gAgent
00036 #include "llbutton.h"
00037 #include "llinventory.h"
00038 #include "llinventoryview.h"
00039 #include "lllineeditor.h"
00040 #include "llpreviewsound.h"
00041 #include "llresmgr.h"
00042 #include "llviewercontrol.h"
00043 #include "llviewermessage.h"  // send_guid_sound_trigger
00044 #include "llvieweruictrlfactory.h"
00045 
00046 extern LLAudioEngine* gAudiop;
00047 extern LLAgent gAgent;
00048 
00049 const F32 SOUND_GAIN = 1.0f;
00050 
00051 LLPreviewSound::LLPreviewSound(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_uuid, const LLUUID& object_uuid)       :
00052         LLPreview( name, rect, title, item_uuid, object_uuid)
00053 {
00054         
00055         gUICtrlFactory->buildFloater(this,"floater_preview_sound.xml");
00056 
00057         childSetAction("Sound play btn",&LLPreviewSound::playSound,this);
00058         childSetAction("Sound audition btn",&LLPreviewSound::auditionSound,this);
00059 
00060         LLButton* button = LLUICtrlFactory::getButtonByName(this, "Sound play btn");
00061         button->setSoundFlags(LLView::SILENT);
00062         
00063         button = LLUICtrlFactory::getButtonByName(this, "Sound audition btn");
00064         button->setSoundFlags(LLView::SILENT);
00065 
00066         const LLInventoryItem* item = getItem();
00067         
00068         childSetCommitCallback("desc", LLPreview::onText, this);
00069         childSetText("desc", item->getDescription());
00070         childSetPrevalidate("desc", &LLLineEditor::prevalidatePrintableNotPipe);        
00071         
00072         // preload the sound
00073         if(item && gAudiop)
00074         {
00075                 gAudiop->preloadSound(item->getAssetUUID());
00076         }
00077         
00078         setTitle(title);
00079 
00080         if (!getHost())
00081         {
00082                 LLRect curRect = getRect();
00083                 translate(rect.mLeft - curRect.mLeft, rect.mTop - curRect.mTop);
00084         }
00085 
00086 }
00087 
00088 // static
00089 void LLPreviewSound::playSound( void *userdata )
00090 {
00091         LLPreviewSound* self = (LLPreviewSound*) userdata;
00092         const LLInventoryItem *item = self->getItem();
00093 
00094         if(item && gAudiop)
00095         {
00096                 send_sound_trigger(item->getAssetUUID(), SOUND_GAIN);
00097         }
00098 }
00099 
00100 // static
00101 void LLPreviewSound::auditionSound( void *userdata )
00102 {
00103         LLPreviewSound* self = (LLPreviewSound*) userdata;
00104         const LLInventoryItem *item = self->getItem();
00105 
00106         if(item && gAudiop)
00107         {
00108                 LLVector3d lpos_global = gAgent.getPositionGlobal();
00109                 F32 volume = SOUND_GAIN * gSavedSettings.getF32("AudioLevelSFX");
00110                 gAudiop->triggerSound(item->getAssetUUID(), gAgent.getID(), volume, lpos_global);
00111         }
00112 }

Generated on Thu Jul 1 06:09:02 2010 for Second Life Viewer by  doxygen 1.4.7