ATLControlsModel.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #pragma once
  9. #include <AudioControl.h>
  10. #include <AzCore/std/string/string_view.h>
  11. namespace AudioControls
  12. {
  13. //-------------------------------------------------------------------------------------------//
  14. // available levels where the controls can be stored
  15. struct SControlScope
  16. {
  17. SControlScope() = default;
  18. SControlScope(const AZStd::string& _name, bool _bOnlyLocal)
  19. : name(_name)
  20. , bOnlyLocal(_bOnlyLocal)
  21. {}
  22. AZStd::string name;
  23. // if true, there is a level in the game audio
  24. // data that doesn't exist in the global list
  25. // of levels for your project
  26. bool bOnlyLocal;
  27. };
  28. //-------------------------------------------------------------------------------------------//
  29. struct IATLControlModelListener
  30. {
  31. virtual ~IATLControlModelListener() = default;
  32. virtual void OnControlAdded([[maybe_unused]] CATLControl* control) {}
  33. virtual void OnControlModified([[maybe_unused]] CATLControl* control) {}
  34. virtual void OnControlRemoved([[maybe_unused]] CATLControl* control) {}
  35. virtual void OnConnectionAdded([[maybe_unused]] CATLControl* control, [[maybe_unused]] IAudioSystemControl* middlewareControl) {}
  36. virtual void OnConnectionRemoved([[maybe_unused]] CATLControl* control, [[maybe_unused]] IAudioSystemControl* middlewareControl) {}
  37. };
  38. //-------------------------------------------------------------------------------------------//
  39. class CATLControlsModel
  40. {
  41. friend class IUndoControlOperation;
  42. friend class CUndoControlModified;
  43. friend class CATLControl;
  44. public:
  45. CATLControlsModel();
  46. ~CATLControlsModel();
  47. void Clear();
  48. CATLControl* CreateControl(const AZStd::string& controlName, EACEControlType type, CATLControl* parent = nullptr);
  49. void RemoveControl(CID id);
  50. CATLControl* GetControlByID(CID id) const;
  51. CATLControl* FindControl(const AZStd::string_view controlName, EACEControlType type, const AZStd::string_view scope, CATLControl* parent = nullptr) const;
  52. // Scope
  53. void AddScope(AZStd::string scopeName, bool localOnly = false);
  54. void ClearScopes();
  55. size_t GetScopeCount() const;
  56. SControlScope GetScopeAt(size_t index) const;
  57. bool ScopeExists(AZStd::string scopeName) const;
  58. // Helper functions
  59. bool IsNameValid(const AZStd::string_view name, EACEControlType type, const AZStd::string_view scope, const CATLControl* const parent = nullptr) const;
  60. AZStd::string GenerateUniqueName(const AZStd::string_view rootName, EACEControlType type, const AZStd::string_view scope, const CATLControl* const parent = nullptr) const;
  61. void ClearAllConnections();
  62. void ReloadAllConnections();
  63. void AddListener(IATLControlModelListener* modelListener);
  64. void RemoveListener(IATLControlModelListener* modelListener);
  65. void SetSuppressMessages(bool suppressMessages);
  66. bool IsTypeDirty(EACEControlType type);
  67. bool IsDirty();
  68. void ClearDirtyFlags();
  69. private:
  70. void OnControlAdded(CATLControl* control);
  71. void OnControlModified(CATLControl* control);
  72. void OnConnectionAdded(CATLControl* control, IAudioSystemControl* middlewareControl);
  73. void OnConnectionRemoved(CATLControl* control, IAudioSystemControl* middlewareControl);
  74. void OnControlRemoved(CATLControl* control);
  75. CID GenerateUniqueId() { return ++m_nextId; }
  76. AZStd::shared_ptr<CATLControl> TakeControl(CID nID);
  77. void InsertControl(AZStd::shared_ptr<CATLControl> control);
  78. static CID m_nextId;
  79. AZStd::vector<AZStd::shared_ptr<CATLControl>> m_controls;
  80. AZStd::vector<SControlScope> m_scopes;
  81. AZStd::vector<IATLControlModelListener*> m_listeners;
  82. bool m_suppressMessages;
  83. bool m_isControlTypeModified[eACET_NUM_TYPES];
  84. };
  85. } // namespace AudioControls