AudioControlsEditorPlugin.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AudioControlsEditorPlugin.h>
  9. #include <AudioControl.h>
  10. #include <AudioControlsEditorWindow.h>
  11. #include <AudioControlsLoader.h>
  12. #include <AudioControlsWriter.h>
  13. #include <IAudioSystem.h>
  14. #include <IAudioSystemEditor.h>
  15. #include <ImplementationManager.h>
  16. #include <MathConversion.h>
  17. #include <QtViewPaneManager.h>
  18. #include <AzFramework/Components/CameraBus.h>
  19. using namespace AudioControls;
  20. CATLControlsModel CAudioControlsEditorPlugin::ms_ATLModel;
  21. QATLTreeModel CAudioControlsEditorPlugin::ms_layoutModel;
  22. FilepathSet CAudioControlsEditorPlugin::ms_currentFilenames;
  23. CImplementationManager CAudioControlsEditorPlugin::ms_implementationManager;
  24. Audio::TAudioControlID CAudioControlsEditorPlugin::ms_audioTriggerId = INVALID_AUDIO_CONTROL_ID;
  25. //-----------------------------------------------------------------------------------------------//
  26. CAudioControlsEditorPlugin::CAudioControlsEditorPlugin(IEditor* editor)
  27. {
  28. QtViewOptions options;
  29. options.canHaveMultipleInstances = true;
  30. RegisterQtViewPane<CAudioControlsEditorWindow>(editor, LyViewPane::AudioControlsEditor, LyViewPane::CategoryOther, options);
  31. ms_implementationManager.LoadImplementation();
  32. ReloadModels();
  33. ms_layoutModel.Initialize(&ms_ATLModel);
  34. }
  35. //-----------------------------------------------------------------------------------------------//
  36. CAudioControlsEditorPlugin::~CAudioControlsEditorPlugin()
  37. {
  38. Release();
  39. }
  40. //-----------------------------------------------------------------------------------------------//
  41. void CAudioControlsEditorPlugin::Release()
  42. {
  43. // clear connections before releasing the implementation since they hold pointers to data
  44. // instantiated from the implementation dll.
  45. CUndoSuspend suspendUndo;
  46. ms_ATLModel.ClearAllConnections();
  47. ms_implementationManager.Release();
  48. }
  49. //-----------------------------------------------------------------------------------------------//
  50. void CAudioControlsEditorPlugin::SaveModels()
  51. {
  52. IAudioSystemEditor* pImpl = GetAudioSystemEditorImpl();
  53. if (pImpl)
  54. {
  55. CAudioControlsWriter writer(&ms_ATLModel, &ms_layoutModel, pImpl, ms_currentFilenames);
  56. }
  57. }
  58. //-----------------------------------------------------------------------------------------------//
  59. void CAudioControlsEditorPlugin::ReloadModels()
  60. {
  61. GetIEditor()->SuspendUndo();
  62. ms_ATLModel.SetSuppressMessages(true);
  63. IAudioSystemEditor* pImpl = GetAudioSystemEditorImpl();
  64. if (pImpl)
  65. {
  66. ms_layoutModel.clear();
  67. ms_ATLModel.Clear();
  68. pImpl->Reload();
  69. CAudioControlsLoader ATLLoader(&ms_ATLModel, &ms_layoutModel, pImpl);
  70. ATLLoader.LoadAll();
  71. ms_currentFilenames = ATLLoader.GetLoadedFilenamesList();
  72. }
  73. ms_ATLModel.SetSuppressMessages(false);
  74. GetIEditor()->ResumeUndo();
  75. }
  76. //-----------------------------------------------------------------------------------------------//
  77. void CAudioControlsEditorPlugin::ReloadScopes()
  78. {
  79. IAudioSystemEditor* pImpl = GetAudioSystemEditorImpl();
  80. if (pImpl)
  81. {
  82. ms_ATLModel.ClearScopes();
  83. CAudioControlsLoader ATLLoader(&ms_ATLModel, &ms_layoutModel, pImpl);
  84. ATLLoader.LoadScopes();
  85. }
  86. }
  87. //-----------------------------------------------------------------------------------------------//
  88. CATLControlsModel* CAudioControlsEditorPlugin::GetATLModel()
  89. {
  90. return &ms_ATLModel;
  91. }
  92. //-----------------------------------------------------------------------------------------------//
  93. IAudioSystemEditor* CAudioControlsEditorPlugin::GetAudioSystemEditorImpl()
  94. {
  95. return ms_implementationManager.GetImplementation();
  96. }
  97. //-----------------------------------------------------------------------------------------------//
  98. QATLTreeModel* CAudioControlsEditorPlugin::GetControlsTree()
  99. {
  100. return &ms_layoutModel;
  101. }
  102. //-----------------------------------------------------------------------------------------------//
  103. void CAudioControlsEditorPlugin::ExecuteTrigger(const AZStd::string_view sTriggerName)
  104. {
  105. if (!sTriggerName.empty())
  106. {
  107. auto audioSystem = AZ::Interface<Audio::IAudioSystem>::Get();
  108. if (!audioSystem)
  109. {
  110. return;
  111. }
  112. StopTriggerExecution();
  113. if (ms_audioTriggerId = audioSystem->GetAudioTriggerID(sTriggerName.data());
  114. ms_audioTriggerId != INVALID_AUDIO_CONTROL_ID)
  115. {
  116. Audio::ObjectRequest::ExecuteTrigger execTrigger;
  117. execTrigger.m_triggerId = ms_audioTriggerId;
  118. audioSystem->PushRequest(AZStd::move(execTrigger));
  119. }
  120. }
  121. }
  122. //-----------------------------------------------------------------------------------------------//
  123. void CAudioControlsEditorPlugin::StopTriggerExecution()
  124. {
  125. if (ms_audioTriggerId != INVALID_AUDIO_CONTROL_ID)
  126. {
  127. if (auto audioSystem = AZ::Interface<Audio::IAudioSystem>::Get();
  128. audioSystem != nullptr)
  129. {
  130. Audio::ObjectRequest::StopTrigger stopTrigger;
  131. stopTrigger.m_triggerId = ms_audioTriggerId;
  132. audioSystem->PushRequest(AZStd::move(stopTrigger));
  133. ms_audioTriggerId = INVALID_AUDIO_CONTROL_ID;
  134. }
  135. }
  136. }
  137. //-----------------------------------------------------------------------------------------------//
  138. CImplementationManager* CAudioControlsEditorPlugin::GetImplementationManager()
  139. {
  140. return &ms_implementationManager;
  141. }