PluginLinks.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*******************************************************************************
  2. The content of this file includes portions of the AUDIOKINETIC Wwise Technology
  3. released in source code form as part of the SDK installer package.
  4. Commercial License Usage
  5. Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
  6. may use this file in accordance with the end user license agreement provided
  7. with the software or, alternatively, in accordance with the terms contained in a
  8. written agreement between you and Audiokinetic Inc.
  9. Apache License Usage
  10. Alternatively, this file may be used under the Apache License, Version 2.0 (the
  11. "Apache License"); you may not use this file except in compliance with the
  12. Apache License. You may obtain a copy of the Apache License at
  13. http://www.apache.org/licenses/LICENSE-2.0.
  14. Unless required by applicable law or agreed to in writing, software distributed
  15. under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  16. OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
  17. the specific language governing permissions and limitations under the License.
  18. Copyright (c) 2023 Audiokinetic Inc.
  19. *******************************************************************************/
  20. /**
  21. * \brief Wwise Authoring Plug-ins - Provides links to the related backend and frontend instances.
  22. * \file AK/Wwise/Plugin/PluginLinks.h
  23. */
  24. #pragma once
  25. #include "PluginInfoGenerator.h"
  26. /**
  27. * \brief Host API to retrieve a link to the plug-in's backend instance.
  28. *
  29. * Useful for the Frontend (GUI) when a special function must be called to get a value, or update elements.
  30. */
  31. struct ak_wwise_plugin_link_backend_v1
  32. #ifdef __cplusplus
  33. : public ak_wwise_plugin_base_interface
  34. #endif
  35. {
  36. #ifndef __cplusplus
  37. ak_wwise_plugin_base_interface m_baseInterface;
  38. #endif
  39. #ifdef __cplusplus
  40. /// Base host-provided instance to retrieve the related backend instance, as shown in the frontend.
  41. using Instance = ak_wwise_plugin_link_backend_instance_v1;
  42. ak_wwise_plugin_link_backend_v1() :
  43. ak_wwise_plugin_base_interface(AK_WWISE_PLUGIN_INTERFACE_TYPE_LINK_BACKEND, 1)
  44. {}
  45. #endif
  46. /**
  47. * \brief Retrieves a link to the plug-in's backend instance.
  48. *
  49. * \aknote The returned pointer might be modified in the frontend lifetime. For example, a plug-in that would undo
  50. * and redo a plug-in creation might return a different value. As such, you should not store the backend
  51. * pointer in a class member, but query it at every operation. \endaknote
  52. *
  53. * \param[in] in_this Current instance of this interface.
  54. * \return Base pointer of the backend instance.
  55. */
  56. ak_wwise_plugin_backend_instance* (*Get)(
  57. const ak_wwise_plugin_link_backend_instance_v1* in_this
  58. );
  59. };
  60. /**
  61. * \brief Host API to retrieve a link to the plug-in's frontend interfaces.
  62. *
  63. * Useful for the Backend when there are special properties that don't use property sets.
  64. */
  65. struct ak_wwise_plugin_link_frontend_v1
  66. #ifdef __cplusplus
  67. : public ak_wwise_plugin_base_interface
  68. #endif
  69. {
  70. #ifndef __cplusplus
  71. ak_wwise_plugin_base_interface m_baseInterface;
  72. #endif
  73. #ifdef __cplusplus
  74. /// Base host-provided instance to retrieve the related frontend instances related to the current backend.
  75. using Instance = ak_wwise_plugin_link_frontend_instance_v1;
  76. ak_wwise_plugin_link_frontend_v1() :
  77. ak_wwise_plugin_base_interface(AK_WWISE_PLUGIN_INTERFACE_TYPE_LINK_FRONTEND, 1)
  78. {}
  79. #endif
  80. /**
  81. * \brief Retrieves an array of the plug-in's frontend instances.
  82. *
  83. * \aknote The returned array is a temporary TLS pointer that is meant to be retrieved and processed immediately to
  84. * execute commands. You should not store this data. \endaknote
  85. *
  86. * \param[in] in_this Current instance of this interface.
  87. * \param[out] out_count How many frontend instances are in the array.
  88. * \return Temporary pointer to the array of frontend instances.
  89. */
  90. ak_wwise_plugin_frontend_instance** (*GetArray)(
  91. const ak_wwise_plugin_link_frontend_instance_v1* in_this,
  92. int* out_count
  93. );
  94. };
  95. #define AK_WWISE_PLUGIN_LINK_BACKEND_ID() \
  96. AK_WWISE_PLUGIN_BASE_INTERFACE_FROM_ID(AK_WWISE_PLUGIN_INTERFACE_TYPE_LINK_BACKEND, 1)
  97. #define AK_WWISE_PLUGIN_LINK_BACKEND_CTOR(/* ak_wwise_plugin_info* */ in_pluginInfo, /* void* */ in_data) \
  98. { \
  99. .m_baseInterface = AK_WWISE_PLUGIN_BASE_INTERFACE_CTOR(AK_WWISE_PLUGIN_LINK_BACKEND_ID(), in_pluginInfo, in_data) \
  100. }
  101. #define AK_WWISE_PLUGIN_LINK_FRONTEND_ID() \
  102. AK_WWISE_PLUGIN_BASE_INTERFACE_FROM_ID(AK_WWISE_PLUGIN_INTERFACE_TYPE_LINK_FRONTEND, 1)
  103. #define AK_WWISE_PLUGIN_LINK_FRONTEND_CTOR(/* ak_wwise_plugin_info* */ in_pluginInfo, /* void* */ in_data) \
  104. { \
  105. .m_baseInterface = AK_WWISE_PLUGIN_BASE_INTERFACE_CTOR(AK_WWISE_PLUGIN_LINK_FRONTEND_ID(), in_pluginInfo, in_data) \
  106. }
  107. #ifdef __cplusplus
  108. namespace AK::Wwise::Plugin
  109. {
  110. namespace V1
  111. {
  112. using CLinkBackend = ak_wwise_plugin_link_backend_v1;
  113. using CLinkFrontend = ak_wwise_plugin_link_frontend_v1;
  114. /// \copydoc ak_wwise_plugin_link_backend_v1
  115. class LinkBackend : public CBaseInstanceGlue<CLinkBackend>
  116. {
  117. public:
  118. using Interface = CLinkBackend;
  119. using Instance = CLinkBackend::Instance;
  120. /**
  121. * \brief The interface type, as requested by this plug-in.
  122. */
  123. enum : InterfaceTypeValue
  124. {
  125. /**
  126. * \brief The interface type, as requested by this plug-in.
  127. */
  128. k_interfaceType = AK_WWISE_PLUGIN_INTERFACE_TYPE_LINK_BACKEND
  129. };
  130. /**
  131. * \brief The interface version, as requested by this plug-in.
  132. */
  133. enum : InterfaceVersion
  134. {
  135. /**
  136. * \brief The interface version, as requested by this plug-in.
  137. */
  138. k_interfaceVersion = 1
  139. };
  140. /**
  141. * \brief Retrieves a link to the plug-in's backend instance.
  142. *
  143. * \aknote The returned pointer might be modified in the frontend lifetime. For example, a plug-in that would undo
  144. * and redo a plug-in creation might return a different value. As such, you should not store the backend
  145. * pointer in a class member, but query it at every operation. \endaknote
  146. *
  147. * \return Base pointer of the backend instance.
  148. */
  149. inline ak_wwise_plugin_backend_instance* Get() const
  150. {
  151. return g_cinterface->Get(this);
  152. }
  153. /**
  154. * \brief Retrieves a link to the plug-in's backend instance, casted as your C++ Backend class type.
  155. *
  156. * \aknote The returned pointer might be modified in the frontend lifetime. For example, a plug-in that would undo
  157. * and redo a plug-in creation might return a different value. As such, you should not store the backend
  158. * pointer in a class member, but query it at every operation. \endaknote
  159. *
  160. * \tparam Backend Expected type of the backend instance. An unexpected type yields to an undefined result.
  161. * \return Pointer of the backend class instance.
  162. */
  163. template<typename Backend>
  164. inline Backend* As()
  165. {
  166. return static_cast<Backend*>(Get());
  167. }
  168. };
  169. /// \copydoc ak_wwise_plugin_link_frontend_v1
  170. class LinkFrontend : public CBaseInstanceGlue<CLinkFrontend>
  171. {
  172. public:
  173. using Interface = CLinkFrontend;
  174. using Instance = CLinkFrontend::Instance;
  175. /**
  176. * \brief The interface type, as requested by this plug-in.
  177. */
  178. enum : InterfaceTypeValue
  179. {
  180. /**
  181. * \brief The interface type, as requested by this plug-in.
  182. */
  183. k_interfaceType = AK_WWISE_PLUGIN_INTERFACE_TYPE_LINK_FRONTEND
  184. };
  185. /**
  186. * \brief The interface version, as requested by this plug-in.
  187. */
  188. enum : InterfaceVersion
  189. {
  190. /**
  191. * \brief The interface version, as requested by this plug-in.
  192. */
  193. k_interfaceVersion = 1
  194. };
  195. /**
  196. * \brief Retrieves an array of the plug-in's frontend instances.
  197. *
  198. * \aknote The returned array is a temporary TLS pointer that is meant to be retrieved and processed immediately to
  199. * execute commands. You should not store this data. \endaknote
  200. *
  201. * \param[out] out_count How many frontend instances are in the array.
  202. * \return Temporary pointer to the array of frontend instances.
  203. */
  204. inline ak_wwise_plugin_frontend_instance** GetArray(int* out_count) const
  205. {
  206. return g_cinterface->GetArray(this, out_count);
  207. }
  208. /**
  209. * \brief Applies a function on each plug-in's frontend instances.
  210. *
  211. * \aknote The frontend instances passed to the function are temporary TLS pointers that are meant to be retrieved
  212. * and processed immediately to execute commands. You should not store this data. \endaknote
  213. *
  214. * \tparam Frontend Expected type of the frontend instances (optional). If no explicit type is provided, the caller
  215. * needs to manually perform the cast to the expected frontend instance type. If an explicit type is
  216. * provided, the frontend instances will automatically be casted to the provided type and then forwarded
  217. * to in_operation if the cast was successful.
  218. * \param[in] in_operation Function, functor or lambda taking a pointer of Frontend as parameter.
  219. */
  220. template<typename Frontend = ak_wwise_plugin_frontend_instance, typename Functor>
  221. inline void ForEach(Functor in_operation) const
  222. {
  223. int count = 0;
  224. auto frontends = GetArray(&count);
  225. for (int index = 0; index < count; ++index)
  226. {
  227. if constexpr (std::is_same_v<Frontend, ak_wwise_plugin_frontend_instance>)
  228. {
  229. in_operation(frontends[index]);
  230. }
  231. else if (auto* frontend = dynamic_cast<Frontend*>(frontends[index]))
  232. {
  233. in_operation(frontend);
  234. }
  235. }
  236. }
  237. };
  238. using RequestLinkBackend = RequestedHostInterface<LinkBackend>;
  239. using RequestLinkFrontend = RequestedHostInterface<LinkFrontend>;
  240. } // of namespace V1
  241. /// Latest version of the C LinkBackend interface.
  242. using CLinkBackend = V1::CLinkBackend;
  243. /// Latest version of the C++ LinkBackend interface.
  244. using LinkBackend = V1::LinkBackend;
  245. /// Latest version of the requested C++ LinkBackend interface.
  246. using RequestLinkBackend = V1::RequestLinkBackend;
  247. /// Latest version of the C LinkFrontend interface.
  248. using CLinkFrontend = V1::CLinkFrontend;
  249. /// Latest version of the C++ LinkFrontend interface.
  250. using LinkFrontend = V1::LinkFrontend;
  251. /// Latest version of the requested C++ LinkFrontend interface.
  252. using RequestLinkFrontend = V1::RequestLinkFrontend;
  253. AK_WWISE_PLUGIN_SPECIALIZE_HOST_INTERFACE(LinkBackend, backend);
  254. AK_WWISE_PLUGIN_SPECIALIZE_HOST_INTERFACE(LinkFrontend, frontend);
  255. AK_WWISE_PLUGIN_SPECIALIZE_INTERFACE_CLASS(LinkBackend);
  256. AK_WWISE_PLUGIN_SPECIALIZE_INTERFACE_VERSION(LinkBackend);
  257. AK_WWISE_PLUGIN_SPECIALIZE_INTERFACE_CLASS(LinkFrontend);
  258. AK_WWISE_PLUGIN_SPECIALIZE_INTERFACE_VERSION(LinkFrontend);
  259. } // of namespace AK::Wwise::Plugin
  260. #endif