Added some debugging tools to the preview assets.
This commit is contained in:
@@ -43,6 +43,15 @@
|
||||
#include "llviewercontrol.h"
|
||||
#include "llviewermessage.h" // send_guid_sound_trigger
|
||||
#include "lluictrlfactory.h"
|
||||
// <edit>
|
||||
#include "llvoavatar.h"
|
||||
#include "llchat.h"
|
||||
#include "llfloaterchat.h"
|
||||
#include "llviewerwindow.h" // for alert
|
||||
#include "llfilepicker.h"
|
||||
// for ambient play:
|
||||
#include "llviewerregion.h"
|
||||
// </edit>
|
||||
|
||||
extern LLAudioEngine* gAudiop;
|
||||
extern LLAgent gAgent;
|
||||
@@ -57,6 +66,10 @@ LLPreviewSound::LLPreviewSound(const std::string& name, const LLRect& rect, cons
|
||||
|
||||
childSetAction("Sound play btn",&LLPreviewSound::playSound,this);
|
||||
childSetAction("Sound audition btn",&LLPreviewSound::auditionSound,this);
|
||||
// <edit>
|
||||
childSetAction("Sound copy uuid btn", &LLPreviewSound::copyUUID, this);
|
||||
childSetAction("Play ambient btn", &LLPreviewSound::playAmbient, this);
|
||||
// </edit>
|
||||
|
||||
LLButton* button = getChild<LLButton>("Sound play btn");
|
||||
button->setSoundFlags(LLView::SILENT);
|
||||
@@ -74,6 +87,13 @@ LLPreviewSound::LLPreviewSound(const std::string& name, const LLRect& rect, cons
|
||||
if(item && gAudiop)
|
||||
{
|
||||
gAudiop->preloadSound(item->getAssetUUID());
|
||||
// <edit>
|
||||
// that thing above doesn't actually start a sound transfer, so I will do it
|
||||
//LLAudioSource *asp = new LLAudioSource(gAgent.getID(), gAgent.getID(), F32(1.0f), LLAudioEngine::AUDIO_TYPE_UI);
|
||||
LLAudioSource *asp = gAgent.getAvatarObject()->getAudioSource(gAgent.getID());
|
||||
LLAudioData *datap = gAudiop->getAudioData(item->getAssetUUID());
|
||||
asp->addAudioData(datap, FALSE);
|
||||
// </edit>
|
||||
}
|
||||
|
||||
setTitle(title);
|
||||
@@ -110,3 +130,228 @@ void LLPreviewSound::auditionSound( void *userdata )
|
||||
gAudiop->triggerSound(item->getAssetUUID(), gAgent.getID(), SOUND_GAIN, LLAudioEngine::AUDIO_TYPE_UI, lpos_global);
|
||||
}
|
||||
}
|
||||
|
||||
// <edit>
|
||||
void LLPreviewSound::playAmbient( void* userdata )
|
||||
{
|
||||
LLPreviewSound* self = (LLPreviewSound*) userdata;
|
||||
const LLInventoryItem *item = self->getItem();
|
||||
|
||||
if(item && gAudiop)
|
||||
{
|
||||
int gain = 0.01f;
|
||||
for(int i = 0; i < 2; i++)
|
||||
{
|
||||
gMessageSystem->newMessageFast(_PREHASH_SoundTrigger);
|
||||
gMessageSystem->nextBlockFast(_PREHASH_SoundData);
|
||||
gMessageSystem->addUUIDFast(_PREHASH_SoundID, LLUUID(item->getAssetUUID()));
|
||||
gMessageSystem->addUUIDFast(_PREHASH_OwnerID, LLUUID::null);
|
||||
gMessageSystem->addUUIDFast(_PREHASH_ObjectID, LLUUID::null);
|
||||
gMessageSystem->addUUIDFast(_PREHASH_ParentID, LLUUID::null);
|
||||
gMessageSystem->addU64Fast(_PREHASH_Handle, gAgent.getRegion()->getHandle());
|
||||
LLVector3d pos = -from_region_handle(gAgent.getRegion()->getHandle());
|
||||
gMessageSystem->addVector3Fast(_PREHASH_Position, (LLVector3)pos);
|
||||
gMessageSystem->addF32Fast(_PREHASH_Gain, gain);
|
||||
|
||||
gMessageSystem->sendReliable(gAgent.getRegionHost());
|
||||
|
||||
gain = 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
// <edit>
|
||||
/*
|
||||
struct LLSaveInfo
|
||||
{
|
||||
LLSaveInfo(const LLUUID& item_id, const LLUUID& object_id, const std::string& desc,
|
||||
const LLTransactionID tid)
|
||||
: mItemUUID(item_id), mObjectUUID(object_id), mDesc(desc), mTransactionID(tid)
|
||||
{
|
||||
}
|
||||
|
||||
LLUUID mItemUUID;
|
||||
LLUUID mObjectUUID;
|
||||
std::string mDesc;
|
||||
LLTransactionID mTransactionID;
|
||||
};
|
||||
|
||||
// static
|
||||
void LLPreviewSound::makeCopy( void *userdata )
|
||||
{
|
||||
LLPreviewSound* self = (LLPreviewSound*) userdata;
|
||||
const LLInventoryItem *item = self->getItem();
|
||||
|
||||
if(item && gAudiop)
|
||||
{
|
||||
// Find out if asset data is ready
|
||||
// I might be able to get rid of this
|
||||
if(!gAssetStorage->hasLocalAsset(item->getAssetUUID(), LLAssetType::AT_SOUND))
|
||||
{
|
||||
LLChat chat("Sound isn't downloaded yet, please try again in a moment.");
|
||||
LLFloaterChat::addChat(chat);
|
||||
return;
|
||||
}
|
||||
|
||||
gAssetStorage->getAssetData(item->getAssetUUID(), LLAssetType::AT_SOUND, LLPreviewSound::gotAssetForCopy, self, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void LLPreviewSound::gotAssetForCopy(LLVFS *vfs,
|
||||
const LLUUID& asset_uuid,
|
||||
LLAssetType::EType type,
|
||||
void* user_data, S32 status, LLExtStat ext_status)
|
||||
{
|
||||
LLPreviewSound* self = (LLPreviewSound*) user_data;
|
||||
//const LLInventoryItem *item = self->getItem();
|
||||
|
||||
LLVFile file(vfs, asset_uuid, type, LLVFile::READ);
|
||||
S32 size = file.getSize();
|
||||
|
||||
char* buffer = new char[size];
|
||||
if (buffer == NULL)
|
||||
{
|
||||
llerrs << "Memory Allocation Failed" << llendl;
|
||||
return;
|
||||
}
|
||||
|
||||
file.read((U8*)buffer, size);
|
||||
|
||||
// Write it back out...
|
||||
|
||||
LLTransactionID tid;
|
||||
LLAssetID asset_id;
|
||||
tid.generate();
|
||||
asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
|
||||
|
||||
LLVFile ofile(gVFS, asset_id, LLAssetType::AT_SOUND, LLVFile::APPEND);
|
||||
|
||||
ofile.setMaxSize(size);
|
||||
ofile.write((U8*)buffer, size);
|
||||
|
||||
// Upload that asset to the database
|
||||
LLSaveInfo* info = new LLSaveInfo(self->mItemUUID, self->mObjectUUID, "sound", tid);
|
||||
gAssetStorage->storeAssetData(tid, LLAssetType::AT_SOUND, onSaveCopyComplete, info, FALSE);
|
||||
}
|
||||
|
||||
// static
|
||||
void LLPreviewSound::onSaveCopyComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status)
|
||||
{
|
||||
LLSaveInfo* info = (LLSaveInfo*)user_data;
|
||||
|
||||
if (status == 0)
|
||||
{
|
||||
std::string item_name = "New Sound";
|
||||
std::string item_desc = "";
|
||||
// Saving into user inventory
|
||||
LLViewerInventoryItem* item;
|
||||
item = (LLViewerInventoryItem*)gInventory.getItem(info->mItemUUID);
|
||||
if(item)
|
||||
{
|
||||
item_name = item->getName();
|
||||
item_desc = item->getDescription();
|
||||
}
|
||||
gMessageSystem->newMessageFast(_PREHASH_CreateInventoryItem);
|
||||
gMessageSystem->nextBlockFast(_PREHASH_AgentData);
|
||||
gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
|
||||
gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
|
||||
gMessageSystem->nextBlockFast(_PREHASH_InventoryBlock);
|
||||
gMessageSystem->addU32Fast(_PREHASH_CallbackID, 0);
|
||||
gMessageSystem->addUUIDFast(_PREHASH_FolderID, LLUUID::null);
|
||||
gMessageSystem->addUUIDFast(_PREHASH_TransactionID, info->mTransactionID);
|
||||
gMessageSystem->addU32Fast(_PREHASH_NextOwnerMask, 2147483647);
|
||||
gMessageSystem->addS8Fast(_PREHASH_Type, 1);
|
||||
gMessageSystem->addS8Fast(_PREHASH_InvType, 1);
|
||||
gMessageSystem->addU8Fast(_PREHASH_WearableType, 0);
|
||||
gMessageSystem->addStringFast(_PREHASH_Name, item_name);
|
||||
gMessageSystem->addStringFast(_PREHASH_Description, item_desc);
|
||||
gMessageSystem->sendReliable(gAgent.getRegionHost());
|
||||
}
|
||||
else
|
||||
{
|
||||
llwarns << "Problem saving sound: " << status << llendl;
|
||||
LLStringUtil::format_map_t args;
|
||||
args["[REASON]"] = std::string(LLAssetStorage::getErrorString(status));
|
||||
gViewerWindow->alertXml("CannotUploadReason",args);
|
||||
}
|
||||
}
|
||||
*/
|
||||
// static
|
||||
void LLPreviewSound::copyUUID( void *userdata )
|
||||
{
|
||||
LLPreviewSound* self = (LLPreviewSound*) userdata;
|
||||
const LLInventoryItem *item = self->getItem();
|
||||
|
||||
if(item )
|
||||
{
|
||||
gViewerWindow->mWindow->copyTextToClipboard(utf8str_to_wstring(item->getAssetUUID().asString()));
|
||||
}
|
||||
}
|
||||
// </edit>
|
||||
|
||||
// <edit>
|
||||
// virtual
|
||||
BOOL LLPreviewSound::canSaveAs() const
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// virtual
|
||||
void LLPreviewSound::saveAs()
|
||||
{
|
||||
const LLInventoryItem *item = getItem();
|
||||
|
||||
if(item)
|
||||
{
|
||||
gAssetStorage->getAssetData(item->getAssetUUID(), LLAssetType::AT_SOUND, LLPreviewSound::gotAssetForSave, this, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void LLPreviewSound::gotAssetForSave(LLVFS *vfs,
|
||||
const LLUUID& asset_uuid,
|
||||
LLAssetType::EType type,
|
||||
void* user_data, S32 status, LLExtStat ext_status)
|
||||
{
|
||||
LLPreviewSound* self = (LLPreviewSound*) user_data;
|
||||
//const LLInventoryItem *item = self->getItem();
|
||||
|
||||
LLVFile file(vfs, asset_uuid, type, LLVFile::READ);
|
||||
S32 size = file.getSize();
|
||||
|
||||
char* buffer = new char[size];
|
||||
if (buffer == NULL)
|
||||
{
|
||||
llerrs << "Memory Allocation Failed" << llendl;
|
||||
return;
|
||||
}
|
||||
|
||||
file.read((U8*)buffer, size);
|
||||
|
||||
// Write it back out...
|
||||
|
||||
LLFilePicker& file_picker = LLFilePicker::instance();
|
||||
if( !file_picker.getSaveFile( LLFilePicker::FFSAVE_OGG, LLDir::getScrubbedFileName(self->getItem()->getName())) )
|
||||
{
|
||||
// User canceled or we failed to acquire save file.
|
||||
return;
|
||||
}
|
||||
// remember the user-approved/edited file name.
|
||||
std::string filename = file_picker.getFirstFile();
|
||||
|
||||
std::ofstream export_file(filename.c_str(), std::ofstream::binary);
|
||||
export_file.write(buffer, size);
|
||||
export_file.close();
|
||||
}
|
||||
|
||||
// virtual
|
||||
LLUUID LLPreviewSound::getItemID()
|
||||
{
|
||||
const LLViewerInventoryItem* item = getItem();
|
||||
if(item)
|
||||
{
|
||||
return item->getUUID();
|
||||
}
|
||||
return LLUUID::null;
|
||||
}
|
||||
// </edit>
|
||||
|
||||
Reference in New Issue
Block a user