You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.3 KiB
C++
97 lines
3.3 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include "AudioRtpcComponent.h"
|
|
|
|
#include <ISystem.h>
|
|
|
|
#include <LmbrCentral/Audio/AudioProxyComponentBus.h>
|
|
|
|
#include <AzCore/Component/Entity.h>
|
|
#include <AzCore/Debug/Trace.h>
|
|
#include <AzCore/RTTI/BehaviorContext.h>
|
|
#include <AzCore/Serialization/SerializeContext.h>
|
|
|
|
|
|
namespace LmbrCentral
|
|
{
|
|
void AudioRtpcComponent::Reflect(AZ::ReflectContext* context)
|
|
{
|
|
auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
|
if (serializeContext)
|
|
{
|
|
serializeContext->Class<AudioRtpcComponent, AZ::Component>()
|
|
->Version(1)
|
|
->Field("Rtpc Name", &AudioRtpcComponent::m_defaultRtpcName)
|
|
;
|
|
}
|
|
|
|
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
|
{
|
|
behaviorContext->EBus<AudioRtpcComponentRequestBus>("AudioRtpcComponentRequestBus")
|
|
->Event("SetValue", &AudioRtpcComponentRequestBus::Events::SetValue)
|
|
->Event("SetRtpcValue", &AudioRtpcComponentRequestBus::Events::SetRtpcValue)
|
|
;
|
|
}
|
|
}
|
|
|
|
//=========================================================================
|
|
void AudioRtpcComponent::Activate()
|
|
{
|
|
OnRtpcNameChanged();
|
|
|
|
AudioRtpcComponentRequestBus::Handler::BusConnect(GetEntityId());
|
|
}
|
|
|
|
//=========================================================================
|
|
void AudioRtpcComponent::Deactivate()
|
|
{
|
|
AudioRtpcComponentRequestBus::Handler::BusDisconnect(GetEntityId());
|
|
}
|
|
|
|
//=========================================================================
|
|
void AudioRtpcComponent::SetValue(float value)
|
|
{
|
|
if (m_defaultRtpcID != INVALID_AUDIO_CONTROL_ID)
|
|
{
|
|
AudioProxyComponentRequestBus::Event(GetEntityId(), &AudioProxyComponentRequestBus::Events::SetRtpcValue, m_defaultRtpcID, value);
|
|
}
|
|
}
|
|
|
|
//=========================================================================
|
|
AudioRtpcComponent::AudioRtpcComponent(const AZStd::string& rtpcName)
|
|
: m_defaultRtpcName(rtpcName)
|
|
{
|
|
}
|
|
|
|
//=========================================================================
|
|
void AudioRtpcComponent::SetRtpcValue(const char* rtpcName, float value)
|
|
{
|
|
if (rtpcName && rtpcName[0] != '\0')
|
|
{
|
|
Audio::TAudioControlID rtpcID = INVALID_AUDIO_CONTROL_ID;
|
|
Audio::AudioSystemRequestBus::BroadcastResult(rtpcID, &Audio::AudioSystemRequestBus::Events::GetAudioRtpcID, rtpcName);
|
|
if (rtpcID != INVALID_AUDIO_CONTROL_ID)
|
|
{
|
|
AudioProxyComponentRequestBus::Event(GetEntityId(), &AudioProxyComponentRequestBus::Events::SetRtpcValue, rtpcID, value);
|
|
}
|
|
}
|
|
}
|
|
|
|
//=========================================================================
|
|
void AudioRtpcComponent::OnRtpcNameChanged()
|
|
{
|
|
m_defaultRtpcID = INVALID_AUDIO_CONTROL_ID;
|
|
if (!m_defaultRtpcName.empty())
|
|
{
|
|
Audio::AudioSystemRequestBus::BroadcastResult(m_defaultRtpcID, &Audio::AudioSystemRequestBus::Events::GetAudioRtpcID, m_defaultRtpcName.c_str());
|
|
}
|
|
}
|
|
|
|
} // namespace LmbrCentral
|