AudioControlsWriter.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <AzCore/std/containers/map.h>
  10. #include <AzCore/std/containers/set.h>
  11. #include <AzCore/std/string/string_view.h>
  12. #include <ACETypes.h>
  13. #include <ATLCommon.h>
  14. #include <AudioControl.h>
  15. #include <QModelIndex>
  16. class QStandardItemModel;
  17. namespace AudioControls
  18. {
  19. class CATLControlsModel;
  20. class IAudioSystemEditor;
  21. //-------------------------------------------------------------------------------------------//
  22. struct SLibraryScope
  23. {
  24. SLibraryScope()
  25. {
  26. XmlAllocator& xmlAlloc(AudioControls::s_xmlAllocator);
  27. m_nodes[eACET_TRIGGER] = xmlAlloc.allocate_node(AZ::rapidxml::node_element, Audio::ATLXmlTags::TriggersNodeTag);
  28. m_nodes[eACET_RTPC] = xmlAlloc.allocate_node(AZ::rapidxml::node_element, Audio::ATLXmlTags::RtpcsNodeTag);
  29. m_nodes[eACET_SWITCH] = xmlAlloc.allocate_node(AZ::rapidxml::node_element, Audio::ATLXmlTags::SwitchesNodeTag);
  30. m_nodes[eACET_SWITCH_STATE] = nullptr;
  31. m_nodes[eACET_ENVIRONMENT] = xmlAlloc.allocate_node(AZ::rapidxml::node_element, Audio::ATLXmlTags::EnvironmentsNodeTag);
  32. m_nodes[eACET_PRELOAD] = xmlAlloc.allocate_node(AZ::rapidxml::node_element, Audio::ATLXmlTags::PreloadsNodeTag);
  33. }
  34. AZ::rapidxml::xml_node<char>* m_nodes[eACET_NUM_TYPES];
  35. bool m_isDirty = false;
  36. };
  37. using TLibraryStorage = AZStd::map<AZStd::string, SLibraryScope>;
  38. //-------------------------------------------------------------------------------------------//
  39. class CAudioControlsWriter
  40. {
  41. public:
  42. CAudioControlsWriter(CATLControlsModel* atlModel, QStandardItemModel* layoutModel, IAudioSystemEditor* audioSystemImpl, FilepathSet& previousLibraryPaths);
  43. private:
  44. void WriteLibrary(const AZStd::string_view libraryName, QModelIndex root);
  45. void WriteItem(QModelIndex index, const AZStd::string& path, TLibraryStorage& library, bool isParentModified);
  46. void WriteControlToXml(AZ::rapidxml::xml_node<char>* node, CATLControl* control, const AZStd::string_view path);
  47. void WriteConnectionsToXml(AZ::rapidxml::xml_node<char>* node, CATLControl* control);
  48. bool IsItemModified(QModelIndex index);
  49. bool WriteXmlToFile(const AZStd::string_view filepath, AZ::rapidxml::xml_node<char>* rootNode);
  50. void CheckOutFile(const AZStd::string_view filepath);
  51. void DeleteLibraryFile(const AZStd::string_view filepath);
  52. CATLControlsModel* m_atlModel;
  53. QStandardItemModel* m_layoutModel;
  54. IAudioSystemEditor* m_audioSystemImpl;
  55. FilepathSet m_foundLibraryPaths;
  56. };
  57. } // namespace AudioControls