CustomData.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 - Backend API to load and save custom data in XML format.
  22. * \file AK/Wwise/Plugin/CustomData.h
  23. */
  24. #pragma once
  25. #include "HostXml.h"
  26. #include "HostDataWriter.h"
  27. /**
  28. * \brief Backend API to load and save custom data in XML format.
  29. *
  30. * The initialization of custom-data-aware plug-ins is done using one of three mutually
  31. * exclusive possibilities:
  32. * - \b InitToDefault : Initializes a new instance using the default values
  33. * - \b InitFromInstance : Initializes a new instance using the values provided by the
  34. * original instance.
  35. * - \b InitFromWorkunit : Initializes a new instance using the values provided in the Save method.
  36. *
  37. * \aknote In order to use the XML reader and writer instance, your plug-in must request the XML
  38. * interface: ak_wwise_plugin_host_xml_v1. \endaknote
  39. */
  40. struct ak_wwise_plugin_custom_data_v1
  41. #ifdef __cplusplus
  42. : public ak_wwise_plugin_base_interface
  43. #endif
  44. {
  45. #ifndef __cplusplus
  46. ak_wwise_plugin_base_interface m_baseInterface;
  47. #endif
  48. #ifdef __cplusplus
  49. /// Base instance type for providing custom data loading and saving.
  50. using Instance = ak_wwise_plugin_custom_data_instance_v1;
  51. ak_wwise_plugin_custom_data_v1() :
  52. ak_wwise_plugin_base_interface(AK_WWISE_PLUGIN_INTERFACE_TYPE_CUSTOM_DATA, 1)
  53. {}
  54. #endif
  55. /**
  56. * \brief Initializes the plug-in's custom data to its default values.
  57. *
  58. * This method is mutually exclusive with the other Init methods.
  59. *
  60. * \param[in] in_this Current instance of this interface.
  61. */
  62. void(*InitToDefault)(
  63. struct ak_wwise_plugin_custom_data_instance_v1* in_this);
  64. /**
  65. * \brief Copy the plug-in's custom data from another instance of the same plug-in.
  66. *
  67. * This is used during copy/paste and delete for Undo purposes. The properties on
  68. * the PropertySet do not need to be copied in this method.
  69. *
  70. * This method is mutually exclusive with the other Init methods.
  71. *
  72. * \param[in] in_this Current instance of this interface (Destination).
  73. * \param[in] in_source The object that will provide the data used in initializing
  74. * this instance.
  75. * \return true if successful.
  76. */
  77. bool(*InitFromInstance)(
  78. struct ak_wwise_plugin_custom_data_instance_v1* in_this,
  79. const struct ak_wwise_plugin_custom_data_instance_v1* in_source);
  80. /**
  81. * \brief Load the custom data structure from the provided Work Unit's XML.
  82. *
  83. * This method is mutually exclusive with the other Init methods.
  84. *
  85. * \aknote In order to use the in_pReader instance, your plug-in must request the XML
  86. * interface: ak_wwise_plugin_host_xml_v1. \endaknote
  87. *
  88. * \param[in] in_this Current instance of this interface.
  89. * \param[in] in_pReader XML Reader instance.
  90. * \return true if load succeeded.
  91. */
  92. bool(*InitFromWorkunit)(
  93. struct ak_wwise_plugin_custom_data_instance_v1* in_this,
  94. struct ak_wwise_plugin_host_xml_reader_instance_v1* in_pReader);
  95. /**
  96. * \brief Save custom data structure in the provided Work Unit's XML.
  97. *
  98. * \aknote In order to use the in_pWriter instance, your plug-in must request the XML
  99. * interface: ak_wwise_plugin_host_xml_v1. \endaknote
  100. *
  101. * \param[in] in_this Current instance of this interface.
  102. * \param[in] in_pWriter XML Writer instance.
  103. * \return true if save succeeded.
  104. */
  105. bool(*Save)(
  106. struct ak_wwise_plugin_custom_data_instance_v1* in_this,
  107. struct ak_wwise_plugin_host_xml_writer_instance_v1* in_pWriter);
  108. /**
  109. * \brief OnDelete function is called when the user presses the "delete" button on a plug-in.
  110. *
  111. * This handler function should properly clean custom data and set undo/redo action properly
  112. * to allow recreation on undo.
  113. *
  114. * \param[in] in_this Current instance of this interface.
  115. */
  116. void(*OnDelete)(struct ak_wwise_plugin_custom_data_instance_v1* in_this);
  117. /**
  118. * \brief Obtains parameters that will be sent to the sound engine when Wwise is connected.
  119. *
  120. * This block should contain only data that is NOT a property defined in the plug-in xml file. The
  121. * parameter ID should be different than the ones used in the plug-in xml.
  122. *
  123. * This is used when there are Object Store, large binary data sections, or properties not usually
  124. * residing in the XML. \sa \ref AK::Wwise::Plugin::AudioPlugin::GetBankParameters for a discussion
  125. * on parameter passing to the Sound Engine.
  126. *
  127. * \aknote In order to use the in_pDataWriter instance, your plug-in must request the data writer
  128. * interface: ak_wwise_plugin_host_data_writer_v1. \endaknote
  129. *
  130. * \param[in] in_this Current instance of this interface.
  131. * \param[in] in_guidPlatform The unique ID of the queried platform
  132. * \param[in] in_idParam The plug-in defined parameter ID
  133. * \param[in] in_pDataWriter A pointer to the data writer instance being used.
  134. * \return true if the plug-in has some plug-in defined data.
  135. *
  136. * \sa
  137. * - \ref AK::Wwise::Plugin::Host::NotifyInternalDataChanged
  138. * - \ref AK::IAkPluginParam::ALL_PLUGIN_DATA_ID
  139. * - \ref AK::IAkPluginParam::SetParam
  140. */
  141. bool(*GetPluginData)(
  142. const struct ak_wwise_plugin_custom_data_instance_v1* in_this,
  143. const GUID* in_guidPlatform,
  144. AkPluginParamID in_idParam,
  145. struct ak_wwise_plugin_host_data_writer_instance_v1* in_pDataWriter);
  146. };
  147. #define AK_WWISE_PLUGIN_CUSTOM_DATA_V1_ID() \
  148. AK_WWISE_PLUGIN_BASE_INTERFACE_FROM_ID(AK_WWISE_PLUGIN_INTERFACE_TYPE_CUSTOM_DATA, 1)
  149. #define AK_WWISE_PLUGIN_CUSTOM_DATA_V1_CTOR(/* ak_wwise_plugin_info* */ in_pluginInfo, /* void* */ in_data) \
  150. { \
  151. .m_baseInterface = AK_WWISE_PLUGIN_BASE_INTERFACE_CTOR(AK_WWISE_PLUGIN_CUSTOM_DATA_V1_ID(), in_pluginInfo, in_data) \
  152. }
  153. #ifdef __cplusplus
  154. namespace AK::Wwise::Plugin
  155. {
  156. namespace V1
  157. {
  158. using CCustomData = ak_wwise_plugin_custom_data_v1;
  159. /**
  160. * \brief Backend API to load and save custom data in XML format.
  161. *
  162. * The initialization of custom-data-aware plug-ins is done using one of three mutually
  163. * exclusive possibilities:
  164. * - \b InitToDefault : Initializes a new instance using the default values
  165. * - \b InitFromInstance : Initializes a new instance using the values provided by the
  166. * original instance.
  167. * - \b InitFromWorkunit : Initializes a new instance using the values provided in the Save method.
  168. *
  169. * \aknote AK::Wwise::Plugin::The RequestXml class is automatically derived when providing
  170. * \ref CustomData in C++. \endaknote
  171. */
  172. class CustomData : public CCustomData::Instance,
  173. public AK::Wwise::Plugin::RequestXml
  174. {
  175. public:
  176. /**
  177. * \copydoc CCustomData::Instance
  178. */
  179. using Instance = CCustomData::Instance;
  180. /**
  181. * \brief The interface type, as provided by this plug-in.
  182. */
  183. enum : InterfaceTypeValue
  184. {
  185. /**
  186. * \brief The interface type, as provided by this plug-in.
  187. */
  188. k_interfaceType = AK_WWISE_PLUGIN_INTERFACE_TYPE_CUSTOM_DATA
  189. };
  190. /**
  191. * \brief The interface version, as provided by this plug-in.
  192. */
  193. enum : InterfaceVersion
  194. {
  195. /**
  196. * \brief The interface version, as provided by this plug-in.
  197. */
  198. k_interfaceVersion = 1
  199. };
  200. struct Interface : public CCustomData
  201. {
  202. using Instance = CustomData;
  203. Interface()
  204. {
  205. CCustomData::InitToDefault = [](
  206. struct ak_wwise_plugin_custom_data_instance_v1* in_this)
  207. {
  208. static_cast<Instance*>(in_this)->InitToDefault();
  209. };
  210. CCustomData::InitFromInstance = [](
  211. struct ak_wwise_plugin_custom_data_instance_v1* in_this,
  212. const struct ak_wwise_plugin_custom_data_instance_v1* in_source)
  213. {
  214. return (bool)static_cast<Instance*>(in_this)->InitFromInstance(
  215. *static_cast<const CustomData*>(in_source));
  216. };
  217. CCustomData::InitFromWorkunit = [](
  218. struct ak_wwise_plugin_custom_data_instance_v1* in_this,
  219. struct ak_wwise_plugin_host_xml_reader_instance_v1* in_pReader)
  220. {
  221. return (bool)static_cast<Instance*>(in_this)->InitFromWorkunit(
  222. *static_cast<XmlReader*>(in_pReader));
  223. };
  224. CCustomData::Save = [](
  225. struct ak_wwise_plugin_custom_data_instance_v1* in_this,
  226. struct ak_wwise_plugin_host_xml_writer_instance_v1* in_pWriter)
  227. {
  228. return (bool)static_cast<Instance*>(in_this)->Save(
  229. *static_cast<XmlWriter*>(in_pWriter));
  230. };
  231. CCustomData::OnDelete = [](
  232. struct ak_wwise_plugin_custom_data_instance_v1* in_this)
  233. {
  234. static_cast<Instance*>(in_this)->OnDelete();
  235. };
  236. CCustomData::GetPluginData = [](
  237. const struct ak_wwise_plugin_custom_data_instance_v1* in_this,
  238. const GUID* in_guidPlatform,
  239. AkPluginParamID in_idParam,
  240. struct ak_wwise_plugin_host_data_writer_instance_v1* in_pDataWriter)
  241. {
  242. return (bool)static_cast<const Instance*>(in_this)->GetPluginData(
  243. *in_guidPlatform,
  244. in_idParam,
  245. *static_cast<DataWriter*>(in_pDataWriter));
  246. };
  247. }
  248. };
  249. /**
  250. * \brief The C interface, fulfilled by your plug-in.
  251. */
  252. InterfacePtr GetInterfacePointer() {
  253. static Interface g_interface;
  254. return &g_interface;
  255. }
  256. CCustomData::Instance* GetInstancePointer() {
  257. return this;
  258. }
  259. const CCustomData::Instance* GetInstancePointer() const {
  260. return this;
  261. }
  262. CustomData() :
  263. CCustomData::Instance()
  264. {
  265. }
  266. virtual ~CustomData() {}
  267. /**
  268. * \brief Initializes the plug-in's custom data to its default values.
  269. *
  270. * This method is mutually exclusive with the other Init methods.
  271. */
  272. virtual void InitToDefault() { }
  273. /**
  274. * \brief Copy the plug-in's custom data from another instance of the same plug-in.
  275. *
  276. * This is used during copy/paste and delete for Undo purposes. The properties on
  277. * the PropertySet do not need to be copied in this method.
  278. *
  279. * This method is mutually exclusive with the other Init methods.
  280. *
  281. * \param[in] in_source The object that will provide the data used in initializing
  282. * this instance.
  283. * \return true if successful.
  284. */
  285. virtual bool InitFromInstance(const CustomData& in_source) { return true; }
  286. /**
  287. * \brief Load the custom data structure from the provided Work Unit's XML.
  288. *
  289. * This method is mutually exclusive with the other Init methods.
  290. *
  291. * \aknote In order to use the in_pReader instance, your plug-in must request the XML
  292. * interface: ak_wwise_plugin_host_xml_v1. \endaknote
  293. *
  294. * \param[in] in_reader XML Reader instance.
  295. * \return true if load succeeded.
  296. */
  297. virtual bool InitFromWorkunit(XmlReader& in_reader) { return true; }
  298. /**
  299. * \brief Save custom data structure in the provided XML.
  300. *
  301. * \aknote In order to use the in_pWriter instance, your plug-in must request the XML
  302. * interface: AK::Wwise::Plugin::RequestXml. \endaknote
  303. *
  304. * \param[in] in_writer XML Writer instance.
  305. * \return true if save succeeded.
  306. */
  307. virtual bool Save(XmlWriter& in_writer) { return true; }
  308. /**
  309. * \brief OnDelete function is called when the user presses the "delete" button on a plug-in.
  310. *
  311. * This handler function should properly clean custom data and set undo/redo action properly
  312. * to allow recreation on undo.
  313. */
  314. virtual void OnDelete() { }
  315. /**
  316. * \brief Obtains parameters that will be sent to the sound engine when Wwise is connected.
  317. *
  318. * This block should contain only data that is NOT a property defined in the plug-in xml file. The
  319. * parameter ID should be different than the ones used in the plug-in xml.
  320. *
  321. * This is used when there are Object Store, large binary data sections, or properties not usually
  322. * residing in the XML. \sa \ref AudioPlugin::GetBankParameters "GetBankParameters"
  323. * for a discussion on parameter passing to the Sound Engine.
  324. *
  325. * \aknote In order to use the in_pDataWriter instance, your plug-in must request the data writer
  326. * interface: AK::Wwise::Plugin::RequestWrite. \endaknote
  327. *
  328. * \param[in] in_guidPlatform The unique ID of the queried platform
  329. * \param[in] in_idParam The plug-in defined parameter ID
  330. * \param[in] in_dataWriter A pointer to the data writer instance being used.
  331. * \return true if the plug-in has some plug-in defined data.
  332. *
  333. * \sa
  334. * - \ref AK::Wwise::Plugin::Host::NotifyInternalDataChanged
  335. * - \ref AK::IAkPluginParam::ALL_PLUGIN_DATA_ID
  336. * - \ref AK::IAkPluginParam::SetParam
  337. */
  338. virtual bool GetPluginData(
  339. const GUID& in_guidPlatform,
  340. AkPluginParamID in_idParam,
  341. DataWriter& in_dataWriter
  342. ) const { return false; }
  343. };
  344. } // of namespace V1
  345. /// Latest version of the C CustomData interface.
  346. using CCustomData = V1::CCustomData;
  347. /// Latest version of the C++ CustomData interface.
  348. using CustomData = V1::CustomData;
  349. AK_WWISE_PLUGIN_SPECIALIZE_INTERFACE_CLASS(CustomData);
  350. AK_WWISE_PLUGIN_SPECIALIZE_INTERFACE_VERSION(CustomData);
  351. } // of namespace AK::Wwise::Plugin
  352. #endif