MovieSceneAkAudioRTPCSection.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "MovieSceneAkAudioRTPCSection.h"
  16. #include "AkAudioDevice.h"
  17. #include "AkCustomVersion.h"
  18. #include "MovieSceneAkAudioRTPCTemplate.h"
  19. #include "Channels/MovieSceneChannelProxy.h"
  20. #include "Channels/MovieSceneChannelEditorData.h"
  21. #include "MovieScene.h"
  22. UMovieSceneAkAudioRTPCSection::UMovieSceneAkAudioRTPCSection(const FObjectInitializer& Init)
  23. : Super(Init)
  24. {
  25. FMovieSceneChannelProxyData Channels;
  26. #if WITH_EDITOR
  27. FMovieSceneChannelMetaData Metadata;
  28. Metadata.SetIdentifiers("RTPC", NSLOCTEXT("MovieSceneAkAudioRTPCSectionEditorData", "RTPC", "RTPC"));
  29. Channels.Add(RTPCChannel, Metadata, TMovieSceneExternalValue<float>());
  30. #else
  31. Channels.Add(RTPCChannel);
  32. #endif
  33. // Populate the channel proxy - if any of our channels were ever reallocated, we'd need to repopulate the proxy,
  34. // but since ours are all value member types, we only need to populate in the constructor
  35. ChannelProxy = MakeShared<FMovieSceneChannelProxy>(MoveTemp(Channels));
  36. }
  37. #if !UE_4_26_OR_LATER
  38. FMovieSceneEvalTemplatePtr UMovieSceneAkAudioRTPCSection::GenerateTemplate() const
  39. {
  40. return FMovieSceneAkAudioRTPCTemplate(*this);
  41. }
  42. #endif
  43. float UMovieSceneAkAudioRTPCSection::GetStartTime() const
  44. {
  45. FFrameRate FrameRate = GetTypedOuter<UMovieScene>()->GetTickResolution();
  46. return (float)FrameRate.AsSeconds(GetRange().GetLowerBoundValue());
  47. }
  48. float UMovieSceneAkAudioRTPCSection::GetEndTime() const
  49. {
  50. FFrameRate FrameRate = GetTypedOuter<UMovieScene>()->GetTickResolution();
  51. return (float)FrameRate.AsSeconds(GetRange().GetUpperBoundValue());
  52. }
  53. void UMovieSceneAkAudioRTPCSection::PostLoad()
  54. {
  55. Super::PostLoad();
  56. const int32 AkVersion = GetLinkerCustomVersion(FAkCustomVersion::GUID);
  57. if (AkVersion < FAkCustomVersion::NewRTPCTrackDataContainer)
  58. {
  59. if (FloatCurve.GetDefaultValue() != MAX_flt)
  60. {
  61. RTPCChannel.SetDefault(FloatCurve.GetDefaultValue());
  62. }
  63. RTPCChannel.PreInfinityExtrap = FloatCurve.PreInfinityExtrap;
  64. RTPCChannel.PostInfinityExtrap = FloatCurve.PostInfinityExtrap;
  65. TArray<FFrameNumber> Times;
  66. TArray<FMovieSceneFloatValue> Values;
  67. Times.Reserve(FloatCurve.GetNumKeys());
  68. Values.Reserve(FloatCurve.GetNumKeys());
  69. const FFrameRate LegacyFrameRate = GetLegacyConversionFrameRate();
  70. const float Interval = LegacyFrameRate.AsInterval();
  71. int32 Index = 0;
  72. for (auto It = FloatCurve.GetKeyIterator(); It; ++It)
  73. {
  74. const FRichCurveKey& Key = *It;
  75. FFrameNumber KeyTime = UpgradeLegacyMovieSceneTime(nullptr, LegacyFrameRate, It->Time);
  76. FMovieSceneFloatValue NewValue;
  77. NewValue.Value = Key.Value;
  78. NewValue.InterpMode = Key.InterpMode;
  79. NewValue.TangentMode = Key.TangentMode;
  80. NewValue.Tangent.ArriveTangent = Key.ArriveTangent * Interval;
  81. NewValue.Tangent.LeaveTangent = Key.LeaveTangent * Interval;
  82. ConvertInsertAndSort<FMovieSceneFloatValue>(Index++, KeyTime, NewValue, Times, Values);
  83. }
  84. RTPCChannel.Set(Times, Values);
  85. return;
  86. }
  87. FloatChannelSerializationHelper.ToFloatChannel(RTPCChannel);
  88. }
  89. void UMovieSceneAkAudioRTPCSection::Serialize(FArchive& Ar)
  90. {
  91. FloatChannelSerializationHelper = RTPCChannel;
  92. Ar.UsingCustomVersion(FAkCustomVersion::GUID);
  93. Super::Serialize(Ar);
  94. }
  95. #if WITH_EDITOR
  96. void UMovieSceneAkAudioRTPCSection::PreEditChange(FProperty* PropertyAboutToChange)
  97. {
  98. PreviousName = Name;
  99. }
  100. void UMovieSceneAkAudioRTPCSection::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
  101. {
  102. const FName PropertyName = (PropertyChangedEvent.Property != nullptr) ? PropertyChangedEvent.Property->GetFName() : NAME_None;
  103. if (PropertyName == GET_MEMBER_NAME_CHECKED(UMovieSceneAkAudioRTPCSection, Name))
  104. {
  105. if (!IsRTPCNameValid())
  106. {
  107. Name = PreviousName;
  108. }
  109. }
  110. Super::PostEditChangeProperty(PropertyChangedEvent);
  111. }
  112. bool UMovieSceneAkAudioRTPCSection::IsRTPCNameValid()
  113. {
  114. return !Name.IsEmpty();
  115. }
  116. #endif