MovieSceneAkAudioRTPCTemplate.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "MovieSceneAkAudioRTPCTemplate.h"
  16. #include "AkAudioDevice.h"
  17. #include "MovieSceneAkAudioRTPCSection.h"
  18. #include "MovieSceneExecutionToken.h"
  19. #include "IMovieScenePlayer.h"
  20. FMovieSceneAkAudioRTPCSectionData::FMovieSceneAkAudioRTPCSectionData(const UMovieSceneAkAudioRTPCSection& Section)
  21. : RTPCName(Section.GetRTPCName())
  22. , RTPCChannel(Section.GetChannel())
  23. {
  24. }
  25. struct FAkAudioRTPCEvaluationData : IPersistentEvaluationData
  26. {
  27. TSharedPtr<FMovieSceneAkAudioRTPCSectionData> SectionData;
  28. };
  29. struct FAkAudioRTPCExecutionToken : IMovieSceneExecutionToken
  30. {
  31. virtual void Execute(const FMovieSceneContext& Context, const FMovieSceneEvaluationOperand& Operand, FPersistentEvaluationData& PersistentData, IMovieScenePlayer& Player) override
  32. {
  33. auto AudioDevice = FAkAudioDevice::Get();
  34. if (!AudioDevice)
  35. {
  36. return;
  37. }
  38. TSharedPtr<FMovieSceneAkAudioRTPCSectionData> SectionData = PersistentData.GetSectionData<FAkAudioRTPCEvaluationData>().SectionData;
  39. if (SectionData.IsValid())
  40. {
  41. auto RTPCNameString = *(SectionData->RTPCName);
  42. float Value;
  43. SectionData->RTPCChannel.Evaluate(Context.GetTime(), Value);
  44. if (Operand.ObjectBindingID.IsValid())
  45. { // Object binding audio track
  46. for (auto ObjectPtr : Player.FindBoundObjects(Operand))
  47. {
  48. auto Object = ObjectPtr.Get();
  49. if (Object)
  50. {
  51. auto Actor = CastChecked<AActor>(Object);
  52. if (Actor)
  53. {
  54. AudioDevice->SetRTPCValue(RTPCNameString, Value, 0, Actor);
  55. }
  56. }
  57. }
  58. }
  59. else
  60. { // Master audio track
  61. AudioDevice->SetRTPCValue(RTPCNameString, Value, 0, nullptr);
  62. }
  63. }
  64. }
  65. };
  66. FMovieSceneAkAudioRTPCTemplate::FMovieSceneAkAudioRTPCTemplate(const UMovieSceneAkAudioRTPCSection& InSection)
  67. : Section(&InSection)
  68. {
  69. if (!Section->GetRTPCName().Len())
  70. {
  71. Section = nullptr;
  72. }
  73. }
  74. void FMovieSceneAkAudioRTPCTemplate::Evaluate(const FMovieSceneEvaluationOperand& Operand, const FMovieSceneContext& Context, const FPersistentEvaluationData& PersistentData, FMovieSceneExecutionTokens& ExecutionTokens) const
  75. {
  76. ExecutionTokens.Add(FAkAudioRTPCExecutionToken());
  77. }
  78. void FMovieSceneAkAudioRTPCTemplate::Setup(FPersistentEvaluationData& PersistentData, IMovieScenePlayer& Player) const
  79. {
  80. if (Section != nullptr)
  81. {
  82. PersistentData.AddSectionData<FAkAudioRTPCEvaluationData>().SectionData = MakeShareable(new FMovieSceneAkAudioRTPCSectionData(*Section));
  83. }
  84. }