llpreviewsound.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @file llpreviewsound.cpp
  3. * @brief LLPreviewSound class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llpreviewsound.h"
  34. #include "llaudioengine.h"
  35. #include "llbutton.h"
  36. #include "lllineeditor.h"
  37. #include "lluictrlfactory.h"
  38. #include "llagent.h"
  39. #include "llviewercontrol.h"
  40. #include "llviewermessage.h" // send_sound_trigger()
  41. constexpr F32 SOUND_GAIN = 1.f;
  42. //static
  43. S32 LLPreviewSound::sPreviewSoundCount = 0;
  44. LLPreviewSound::LLPreviewSound(const std::string& name, const LLRect& rect,
  45. const std::string& title,
  46. const LLUUID& item_uuid,
  47. const LLUUID& object_uuid)
  48. : LLPreview(name, rect, title, item_uuid, object_uuid)
  49. {
  50. ++sPreviewSoundCount;
  51. LLUICtrlFactory::getInstance()->buildFloater(this,
  52. "floater_preview_sound.xml");
  53. childSetAction("Sound play btn", playSound, this);
  54. childSetAction("Sound audition btn", auditionSound, this);
  55. LLButton* button = getChild<LLButton>("Sound play btn");
  56. button->setSoundFlags(LLView::SILENT);
  57. button = getChild<LLButton>("Sound audition btn");
  58. button->setSoundFlags(LLView::SILENT);
  59. childSetCommitCallback("desc", LLPreview::onText, this);
  60. childSetPrevalidate("desc", &LLLineEditor::prevalidatePrintableNotPipe);
  61. const LLInventoryItem* item = getItem();
  62. if (item) // May be null (e.g. during prim contents fetches)...
  63. {
  64. childSetText("desc", item->getDescription());
  65. if (gAudiop)
  66. {
  67. // preload the sound
  68. gAudiop->preloadSound(item->getAssetUUID());
  69. }
  70. }
  71. else
  72. {
  73. childSetText("desc", std::string("(loading...)"));
  74. }
  75. setTitle(title);
  76. if (!getHost())
  77. {
  78. LLRect curRect = getRect();
  79. translate(rect.mLeft - curRect.mLeft, rect.mTop - curRect.mTop);
  80. }
  81. }
  82. LLPreviewSound::~LLPreviewSound()
  83. {
  84. --sPreviewSoundCount;
  85. }
  86. // static
  87. void LLPreviewSound::playSound(void* userdata)
  88. {
  89. LLPreviewSound* self = (LLPreviewSound*)userdata;
  90. if (self)
  91. {
  92. const LLInventoryItem* item = self->getItem();
  93. if (item && gAudiop)
  94. {
  95. send_sound_trigger(item->getAssetUUID(), SOUND_GAIN);
  96. }
  97. }
  98. }
  99. // static
  100. void LLPreviewSound::auditionSound(void* userdata)
  101. {
  102. LLPreviewSound* self = (LLPreviewSound*)userdata;
  103. if (self)
  104. {
  105. const LLInventoryItem* item = self->getItem();
  106. if (item && gAudiop)
  107. {
  108. gAudiop->triggerSound(item->getAssetUUID(), gAgentID, SOUND_GAIN,
  109. LLAudioEngine::AUDIO_TYPE_SFX);
  110. }
  111. }
  112. }