PageRenderTime 170ms CodeModel.GetById 0ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. #include "llaudioengine.h"
  28. #include "llagent.h" // gAgent
  29. #include "llbutton.h"
  30. #include "llinventory.h"
  31. #include "lllineeditor.h"
  32. #include "llpreviewsound.h"
  33. #include "llresmgr.h"
  34. #include "llviewercontrol.h"
  35. #include "llviewermessage.h" // send_guid_sound_trigger
  36. #include "lluictrlfactory.h"
  37. extern LLAudioEngine* gAudiop;
  38. extern LLAgent gAgent;
  39. const F32 SOUND_GAIN = 1.0f;
  40. LLPreviewSound::LLPreviewSound(const LLSD& key)
  41. : LLPreview( key )
  42. {
  43. }
  44. // virtual
  45. BOOL LLPreviewSound::postBuild()
  46. {
  47. const LLInventoryItem* item = getItem();
  48. if (item)
  49. {
  50. getChild<LLUICtrl>("desc")->setValue(item->getDescription());
  51. if (gAudiop)
  52. gAudiop->preloadSound(item->getAssetUUID()); // preload the sound
  53. }
  54. childSetAction("Sound play btn",&LLPreviewSound::playSound,this);
  55. childSetAction("Sound audition btn",&LLPreviewSound::auditionSound,this);
  56. LLButton* button = getChild<LLButton>("Sound play btn");
  57. button->setSoundFlags(LLView::SILENT);
  58. button = getChild<LLButton>("Sound audition btn");
  59. button->setSoundFlags(LLView::SILENT);
  60. childSetCommitCallback("desc", LLPreview::onText, this);
  61. getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
  62. return LLPreview::postBuild();
  63. }
  64. // static
  65. void LLPreviewSound::playSound( void *userdata )
  66. {
  67. LLPreviewSound* self = (LLPreviewSound*) userdata;
  68. const LLInventoryItem *item = self->getItem();
  69. if(item && gAudiop)
  70. {
  71. send_sound_trigger(item->getAssetUUID(), SOUND_GAIN);
  72. }
  73. }
  74. // static
  75. void LLPreviewSound::auditionSound( void *userdata )
  76. {
  77. LLPreviewSound* self = (LLPreviewSound*) userdata;
  78. const LLInventoryItem *item = self->getItem();
  79. if(item && gAudiop)
  80. {
  81. LLVector3d lpos_global = gAgent.getPositionGlobal();
  82. gAudiop->triggerSound(item->getAssetUUID(), gAgent.getID(), SOUND_GAIN, LLAudioEngine::AUDIO_TYPE_UI, lpos_global);
  83. }
  84. }