123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <AudioControl.h>
- #include <ACETypes.h>
- #include <ATLControlsModel.h>
- #include <AudioControlsEditorPlugin.h>
- #include <AudioControlsEditorUndo.h>
- #include <IAudioSystemControl.h>
- #include <ImplementationManager.h>
- namespace AudioControls
- {
- //-------------------------------------------------------------------------------------------//
- CATLControl::CATLControl(const AZStd::string& controlName, CID id, EACEControlType type, CATLControlsModel* atlControlsModel)
- : m_name(controlName)
- , m_id(id)
- , m_type(type)
- , m_atlControlsModel(atlControlsModel)
- {
- }
- //-------------------------------------------------------------------------------------------//
- CATLControl::~CATLControl()
- {
- // Same as ClearConnections but without signalling that 'this' control is being modified...
- if (CAudioControlsEditorPlugin::GetImplementationManager())
- {
- if (IAudioSystemEditor* audioSystemImpl = CAudioControlsEditorPlugin::GetImplementationManager()->GetImplementation())
- {
- for (auto& connectionPtr : m_connectedControls)
- {
- if (IAudioSystemControl* middlewareControl = audioSystemImpl->GetControl(connectionPtr->GetID()))
- {
- audioSystemImpl->ConnectionRemoved(middlewareControl);
- SignalConnectionRemoved(middlewareControl);
- }
- }
- }
- }
- m_connectedControls.clear();
- }
- //-------------------------------------------------------------------------------------------//
- CID CATLControl::GetId() const
- {
- return m_id;
- }
- //-------------------------------------------------------------------------------------------//
- EACEControlType CATLControl::GetType() const
- {
- return m_type;
- }
- //-------------------------------------------------------------------------------------------//
- AZStd::string CATLControl::GetName() const
- {
- return m_name;
- }
- //-------------------------------------------------------------------------------------------//
- CATLControl* CATLControl::GetParent() const
- {
- return m_parent;
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::SetId(CID id)
- {
- if (id != m_id)
- {
- SignalControlAboutToBeModified();
- m_id = id;
- SignalControlModified();
- }
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::SetType(EACEControlType type)
- {
- if (type != m_type)
- {
- SignalControlAboutToBeModified();
- m_type = type;
- SignalControlModified();
- }
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::SetName(const AZStd::string_view name)
- {
- if (name != m_name)
- {
- SignalControlAboutToBeModified();
- m_name = name;
- SignalControlModified();
- }
- }
- //-------------------------------------------------------------------------------------------//
- AZStd::string CATLControl::GetScope() const
- {
- return m_scope;
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::SetScope(const AZStd::string_view scope)
- {
- if (m_scope != scope)
- {
- SignalControlAboutToBeModified();
- m_scope = scope;
- SignalControlModified();
- }
- }
- //-------------------------------------------------------------------------------------------//
- bool CATLControl::HasScope() const
- {
- return !m_scope.empty();
- }
- //-------------------------------------------------------------------------------------------//
- bool CATLControl::IsAutoLoad() const
- {
- return m_isAutoLoad;
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::SetAutoLoad(bool isAutoLoad)
- {
- if (isAutoLoad != m_isAutoLoad)
- {
- SignalControlAboutToBeModified();
- m_isAutoLoad = isAutoLoad;
- SignalControlModified();
- }
- }
- //-------------------------------------------------------------------------------------------//
- size_t CATLControl::ConnectionCount() const
- {
- return m_connectedControls.size();
- }
- //-------------------------------------------------------------------------------------------//
- TConnectionPtr CATLControl::GetConnectionAt(size_t index) const
- {
- return (index < m_connectedControls.size() ? m_connectedControls[index] : nullptr);
- }
- //-------------------------------------------------------------------------------------------//
- TConnectionPtr CATLControl::GetConnection(CID id) const
- {
- if (id != ACE_INVALID_CID)
- {
- for (const TConnectionPtr& connection : m_connectedControls)
- {
- if (connection && connection->GetID() == id)
- {
- return connection;
- }
- }
- }
- return nullptr;
- }
- //-------------------------------------------------------------------------------------------//
- TConnectionPtr CATLControl::GetConnection(IAudioSystemControl* middlewareControl) const
- {
- return GetConnection(middlewareControl->GetId());
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::AddConnection(TConnectionPtr connection)
- {
- if (connection)
- {
- SignalControlAboutToBeModified();
- m_connectedControls.push_back(connection);
- if (IAudioSystemEditor* audioSystemImpl = CAudioControlsEditorPlugin::GetImplementationManager()->GetImplementation())
- {
- if (IAudioSystemControl* middlewareControl = audioSystemImpl->GetControl(connection->GetID()))
- {
- SignalConnectionAdded(middlewareControl);
- }
- }
- SignalControlModified();
- }
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::RemoveConnection(TConnectionPtr connection)
- {
- if (connection)
- {
- auto it = AZStd::find(m_connectedControls.begin(), m_connectedControls.end(), connection);
- if (it != m_connectedControls.end())
- {
- SignalControlAboutToBeModified();
- m_connectedControls.erase(it);
- if (IAudioSystemEditor* audioSystemImpl = CAudioControlsEditorPlugin::GetImplementationManager()->GetImplementation())
- {
- if (IAudioSystemControl* middlewareControl = audioSystemImpl->GetControl(connection->GetID()))
- {
- SignalConnectionRemoved(middlewareControl);
- }
- }
- SignalControlModified();
- }
- }
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::ClearConnections()
- {
- SignalControlAboutToBeModified();
- if (IAudioSystemEditor* audioSystemImpl = CAudioControlsEditorPlugin::GetImplementationManager()->GetImplementation())
- {
- for (auto& connectionPtr : m_connectedControls)
- {
- if (IAudioSystemControl* middlewareControl = audioSystemImpl->GetControl(connectionPtr->GetID()))
- {
- audioSystemImpl->ConnectionRemoved(middlewareControl);
- SignalConnectionRemoved(middlewareControl);
- }
- }
- }
- m_connectedControls.clear();
- SignalControlModified();
- }
- //-------------------------------------------------------------------------------------------//
- bool CATLControl::IsFullyConnected() const
- {
- bool isConnected = ConnectionCount() > 0;
- // Switches have no connections. Their child Switch_States do.
- if (m_type == eACET_SWITCH)
- {
- isConnected = true;
- for (auto& childPtr : m_children)
- {
- if (!childPtr->IsFullyConnected())
- {
- isConnected = false;
- break;
- }
- }
- }
- else
- {
- if (IAudioSystemEditor* audioSystemImpl = CAudioControlsEditorPlugin::GetImplementationManager()->GetImplementation())
- {
- for (auto& connectionPtr : m_connectedControls)
- {
- if (IAudioSystemControl* middlewareControl = audioSystemImpl->GetControl(connectionPtr->GetID()))
- {
- if (!middlewareControl->IsConnected() || middlewareControl->IsPlaceholder())
- {
- isConnected = false;
- break;
- }
- }
- }
- }
- }
- return isConnected;
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::RemoveConnection(IAudioSystemControl* middlewareControl)
- {
- if (middlewareControl)
- {
- const CID id = middlewareControl->GetId();
- auto it = m_connectedControls.begin();
- auto end = m_connectedControls.end();
- for (; it != end; ++it)
- {
- if ((*it)->GetID() == id)
- {
- SignalControlAboutToBeModified();
- m_connectedControls.erase(it);
- SignalConnectionRemoved(middlewareControl);
- SignalControlModified();
- return;
- }
- }
- }
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::SignalControlModified()
- {
- if (m_atlControlsModel)
- {
- m_atlControlsModel->OnControlModified(this);
- }
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::SignalControlAboutToBeModified()
- {
- if (!CUndo::IsSuspended())
- {
- CUndo undo("ATL Control Modified");
- CUndo::Record(new CUndoControlModified(GetId()));
- }
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::SignalConnectionAdded(IAudioSystemControl* middlewareControl)
- {
- if (m_atlControlsModel)
- {
- m_atlControlsModel->OnConnectionAdded(this, middlewareControl);
- }
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::SignalConnectionRemoved(IAudioSystemControl* middlewareControl)
- {
- if (m_atlControlsModel)
- {
- m_atlControlsModel->OnConnectionRemoved(this, middlewareControl);
- }
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::ReloadConnections()
- {
- if (IAudioSystemEditor* audioSystemImpl = CAudioControlsEditorPlugin::GetImplementationManager()->GetImplementation())
- {
- for (auto& connectionNode : m_connectionNodes)
- {
- if (TConnectionPtr connection = audioSystemImpl->CreateConnectionFromXMLNode(connectionNode.m_xmlNode, m_type))
- {
- AddConnection(connection);
- connectionNode.m_isValid = true;
- }
- else
- {
- connectionNode.m_isValid = false;
- }
- }
- }
- }
- //-------------------------------------------------------------------------------------------//
- void CATLControl::SetParent(CATLControl* parent)
- {
- m_parent = parent;
- if (m_parent)
- {
- SetScope(m_parent->GetScope());
- }
- }
- bool CATLControl::SwitchStateConnectionCheck(IAudioSystemControl* middlewareControl)
- {
- if (IAudioSystemEditor* audioSystemImpl = CAudioControlsEditorPlugin::GetImplementationManager()->GetImplementation())
- {
- CID parentID = middlewareControl->GetParent()->GetId();
- EACEControlType compatibleType = audioSystemImpl->ImplTypeToATLType(middlewareControl->GetType());
- if (compatibleType == EACEControlType::eACET_SWITCH_STATE && m_type == EACEControlType::eACET_SWITCH)
- {
- for (auto& child : m_children)
- {
- for (int j = 0; child && j < child->ConnectionCount(); ++j)
- {
- TConnectionPtr tmpConnection = child->GetConnectionAt(j);
- if (tmpConnection)
- {
- IAudioSystemControl* tmpMiddlewareControl = audioSystemImpl->GetControl(tmpConnection->GetID());
- EACEControlType controlType = audioSystemImpl->ImplTypeToATLType(tmpMiddlewareControl->GetType());
- if (tmpMiddlewareControl && controlType == EACEControlType::eACET_SWITCH_STATE)
- {
- if (parentID != ACE_INVALID_CID && tmpMiddlewareControl->GetParent()->GetId() != parentID)
- {
- return false;
- }
- }
- }
- }
- }
- }
- }
- return true;
- }
- } // namespace AudioControls
|