Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

437 lines
16KB

  1. //-----------------------------------------------------------------------------
  2. // Project : SDK Core
  3. //
  4. // Category : SDK Core Interfaces
  5. // Filename : pluginterfaces/base/ipluginbase.h
  6. // Created by : Steinberg, 01/2004
  7. // Description : Basic Plug-in Interfaces
  8. //
  9. //-----------------------------------------------------------------------------
  10. // This file is part of a Steinberg SDK. It is subject to the license terms
  11. // in the LICENSE file found in the top-level directory of this distribution
  12. // and at www.steinberg.net/sdklicenses.
  13. // No part of the SDK, including this file, may be copied, modified, propagated,
  14. // or distributed except according to the terms contained in the LICENSE file.
  15. //-----------------------------------------------------------------------------
  16. #pragma once
  17. #include "funknown.h"
  18. #include "fstrdefs.h"
  19. namespace Steinberg {
  20. //------------------------------------------------------------------------
  21. /** Basic interface to a Plug-in component.
  22. \ingroup pluginBase
  23. - [plug imp]
  24. - initialize/terminate the Plug-in component
  25. The host uses this interface to initialize and to terminate the Plug-in component.
  26. The context that is passed to the initialize method contains any interface to the
  27. host that the Plug-in will need to work. These interfaces can vary from category to category.
  28. A list of supported host context interfaces should be included in the documentation
  29. of a specific category. */
  30. //------------------------------------------------------------------------
  31. class IPluginBase: public FUnknown
  32. {
  33. public:
  34. //------------------------------------------------------------------------
  35. /** The host passes a number of interfaces as context to initialize the Plug-in class.
  36. @note Extensive memory allocations etc. should be performed in this method rather than in the class' constructor!
  37. If the method does NOT return kResultOk, the object is released immediately. In this case terminate is not called! */
  38. virtual tresult PLUGIN_API initialize (FUnknown* context) = 0;
  39. /** This function is called before the Plug-in is unloaded and can be used for
  40. cleanups. You have to release all references to any host application interfaces. */
  41. virtual tresult PLUGIN_API terminate () = 0;
  42. //------------------------------------------------------------------------
  43. static const FUID iid;
  44. };
  45. DECLARE_CLASS_IID (IPluginBase, 0x22888DDB, 0x156E45AE, 0x8358B348, 0x08190625)
  46. //------------------------------------------------------------------------
  47. /** Basic Information about the class factory of the Plug-in.
  48. \ingroup pluginBase
  49. */
  50. //------------------------------------------------------------------------
  51. struct PFactoryInfo
  52. {
  53. //------------------------------------------------------------------------
  54. enum FactoryFlags
  55. {
  56. kNoFlags = 0, ///< Nothing
  57. kClassesDiscardable = 1 << 0, ///< The number of exported classes can change each time the Module is loaded. If this flag is set, the host does not cache class information. This leads to a longer startup time because the host always has to load the Module to get the current class information.
  58. kLicenseCheck = 1 << 1, ///< Class IDs of components are interpreted as Syncrosoft-License (LICENCE_UID). Loaded in a Steinberg host, the module will not be loaded when the license is not valid
  59. kComponentNonDiscardable = 1 << 3, ///< Component won't be unloaded until process exit
  60. kUnicode = 1 << 4 ///< Components have entirely unicode encoded strings. (True for VST 3 Plug-ins so far)
  61. };
  62. enum
  63. {
  64. kURLSize = 256,
  65. kEmailSize = 128,
  66. kNameSize = 64
  67. };
  68. //------------------------------------------------------------------------
  69. char8 vendor[kNameSize]; ///< e.g. "Steinberg Media Technologies"
  70. char8 url[kURLSize]; ///< e.g. "http://www.steinberg.de"
  71. char8 email[kEmailSize]; ///< e.g. "info@steinberg.de"
  72. int32 flags; ///< (see above)
  73. //------------------------------------------------------------------------
  74. PFactoryInfo (const char8* _vendor, const char8* _url, const char8* _email, int32 _flags)
  75. {
  76. strncpy8 (vendor, _vendor, kNameSize);
  77. strncpy8 (url, _url, kURLSize);
  78. strncpy8 (email, _email, kEmailSize);
  79. flags = _flags;
  80. #ifdef UNICODE
  81. flags |= kUnicode;
  82. #endif
  83. }
  84. #if SMTG_CPP11
  85. constexpr PFactoryInfo () : vendor (), url (), email (), flags () {}
  86. #else
  87. PFactoryInfo () { memset (this, 0, sizeof (PFactoryInfo)); }
  88. #endif
  89. };
  90. //------------------------------------------------------------------------
  91. /** Basic Information about a class provided by the Plug-in.
  92. \ingroup pluginBase
  93. */
  94. //------------------------------------------------------------------------
  95. struct PClassInfo
  96. {
  97. //------------------------------------------------------------------------
  98. enum ClassCardinality
  99. {
  100. kManyInstances = 0x7FFFFFFF
  101. };
  102. enum
  103. {
  104. kCategorySize = 32,
  105. kNameSize = 64
  106. };
  107. //------------------------------------------------------------------------
  108. TUID cid; ///< Class ID 16 Byte class GUID
  109. int32 cardinality; ///< cardinality of the class, set to kManyInstances (see \ref ClassCardinality)
  110. char8 category[kCategorySize]; ///< class category, host uses this to categorize interfaces
  111. char8 name[kNameSize]; ///< class name, visible to the user
  112. //------------------------------------------------------------------------
  113. PClassInfo (const TUID _cid, int32 _cardinality, const char8* _category, const char8* _name)
  114. {
  115. memset (this, 0, sizeof (PClassInfo));
  116. memcpy (cid, _cid, sizeof (TUID));
  117. if (_category)
  118. strncpy8 (category, _category, kCategorySize);
  119. if (_name)
  120. strncpy8 (name, _name, kNameSize);
  121. cardinality = _cardinality;
  122. }
  123. #if SMTG_CPP11
  124. constexpr PClassInfo () : cid (), cardinality (), category (), name () {}
  125. #else
  126. PClassInfo () { memset (this, 0, sizeof (PClassInfo)); }
  127. #endif
  128. };
  129. //------------------------------------------------------------------------
  130. // IPluginFactory interface declaration
  131. //------------------------------------------------------------------------
  132. /** Class factory that any Plug-in defines for creating class instances.
  133. \ingroup pluginBase
  134. - [plug imp]
  135. From the host's point of view a Plug-in module is a factory which can create
  136. a certain kind of object(s). The interface IPluginFactory provides methods
  137. to get information about the classes exported by the Plug-in and a
  138. mechanism to create instances of these classes (that usually define the IPluginBase interface).
  139. <b> An implementation is provided in public.sdk/source/common/pluginfactory.cpp </b>
  140. \see GetPluginFactory
  141. */
  142. //------------------------------------------------------------------------
  143. class IPluginFactory : public FUnknown
  144. {
  145. public:
  146. //------------------------------------------------------------------------
  147. /** Fill a PFactoryInfo structure with information about the Plug-in vendor. */
  148. virtual tresult PLUGIN_API getFactoryInfo (PFactoryInfo* info) = 0;
  149. /** Returns the number of exported classes by this factory.
  150. If you are using the CPluginFactory implementation provided by the SDK, it returns the number of classes you registered with CPluginFactory::registerClass. */
  151. virtual int32 PLUGIN_API countClasses () = 0;
  152. /** Fill a PClassInfo structure with information about the class at the specified index. */
  153. virtual tresult PLUGIN_API getClassInfo (int32 index, PClassInfo* info) = 0;
  154. /** Create a new class instance. */
  155. virtual tresult PLUGIN_API createInstance (FIDString cid, FIDString _iid, void** obj) = 0;
  156. //------------------------------------------------------------------------
  157. static const FUID iid;
  158. };
  159. DECLARE_CLASS_IID (IPluginFactory, 0x7A4D811C, 0x52114A1F, 0xAED9D2EE, 0x0B43BF9F)
  160. //------------------------------------------------------------------------
  161. /** Version 2 of Basic Information about a class provided by the Plug-in.
  162. \ingroup pluginBase
  163. */
  164. //------------------------------------------------------------------------
  165. struct PClassInfo2
  166. {
  167. //------------------------------------------------------------------------
  168. TUID cid; ///< Class ID 16 Byte class GUID
  169. int32 cardinality; ///< cardinality of the class, set to kManyInstances (see \ref ClassCardinality)
  170. char8 category[PClassInfo::kCategorySize]; ///< class category, host uses this to categorize interfaces
  171. char8 name[PClassInfo::kNameSize]; ///< class name, visible to the user
  172. enum {
  173. kVendorSize = 64,
  174. kVersionSize = 64,
  175. kSubCategoriesSize = 128
  176. };
  177. uint32 classFlags; ///< flags used for a specific category, must be defined where category is defined
  178. char8 subCategories[kSubCategoriesSize]; ///< module specific subcategories, can be more than one, logically added by the \c OR operator
  179. char8 vendor[kVendorSize]; ///< overwrite vendor information from factory info
  180. char8 version[kVersionSize]; ///< Version string (e.g. "1.0.0.512" with Major.Minor.Subversion.Build)
  181. char8 sdkVersion[kVersionSize]; ///< SDK version used to build this class (e.g. "VST 3.0")
  182. //------------------------------------------------------------------------
  183. PClassInfo2 (const TUID _cid, int32 _cardinality, const char8* _category, const char8* _name,
  184. int32 _classFlags, const char8* _subCategories, const char8* _vendor, const char8* _version,
  185. const char8* _sdkVersion)
  186. {
  187. memset (this, 0, sizeof (PClassInfo2));
  188. memcpy (cid, _cid, sizeof (TUID));
  189. cardinality = _cardinality;
  190. if (_category)
  191. strncpy8 (category, _category, PClassInfo::kCategorySize);
  192. if (_name)
  193. strncpy8 (name, _name, PClassInfo::kNameSize);
  194. classFlags = static_cast<uint32> (_classFlags);
  195. if (_subCategories)
  196. strncpy8 (subCategories, _subCategories, kSubCategoriesSize);
  197. if (_vendor)
  198. strncpy8 (vendor, _vendor, kVendorSize);
  199. if (_version)
  200. strncpy8 (version, _version, kVersionSize);
  201. if (_sdkVersion)
  202. strncpy8 (sdkVersion, _sdkVersion, kVersionSize);
  203. }
  204. #if SMTG_CPP11
  205. constexpr PClassInfo2 ()
  206. : cid ()
  207. , cardinality ()
  208. , category ()
  209. , name ()
  210. , classFlags ()
  211. , subCategories ()
  212. , vendor ()
  213. , version ()
  214. , sdkVersion ()
  215. {
  216. }
  217. #else
  218. PClassInfo2 () { memset (this, 0, sizeof (PClassInfo2)); }
  219. #endif
  220. };
  221. //------------------------------------------------------------------------
  222. // IPluginFactory2 interface declaration
  223. //------------------------------------------------------------------------
  224. /** Version 2 of class factory supporting PClassInfo2.
  225. \ingroup pluginBase
  226. \copydoc IPluginFactory
  227. */
  228. //------------------------------------------------------------------------
  229. class IPluginFactory2 : public IPluginFactory
  230. {
  231. public:
  232. //------------------------------------------------------------------------
  233. /** Returns the class info (version 2) for a given index. */
  234. virtual tresult PLUGIN_API getClassInfo2 (int32 index, PClassInfo2* info) = 0;
  235. //------------------------------------------------------------------------
  236. static const FUID iid;
  237. };
  238. DECLARE_CLASS_IID (IPluginFactory2, 0x0007B650, 0xF24B4C0B, 0xA464EDB9, 0xF00B2ABB)
  239. //------------------------------------------------------------------------
  240. /** Unicode Version of Basic Information about a class provided by the Plug-in */
  241. //------------------------------------------------------------------------
  242. struct PClassInfoW
  243. {
  244. //------------------------------------------------------------------------
  245. TUID cid; ///< see \ref PClassInfo
  246. int32 cardinality; ///< see \ref PClassInfo
  247. char8 category[PClassInfo::kCategorySize]; ///< see \ref PClassInfo
  248. char16 name[PClassInfo::kNameSize]; ///< see \ref PClassInfo
  249. enum {
  250. kVendorSize = 64,
  251. kVersionSize = 64,
  252. kSubCategoriesSize = 128
  253. };
  254. uint32 classFlags; ///< flags used for a specific category, must be defined where category is defined
  255. char8 subCategories[kSubCategoriesSize];///< module specific subcategories, can be more than one, logically added by the \c OR operator
  256. char16 vendor[kVendorSize]; ///< overwrite vendor information from factory info
  257. char16 version[kVersionSize]; ///< Version string (e.g. "1.0.0.512" with Major.Minor.Subversion.Build)
  258. char16 sdkVersion[kVersionSize]; ///< SDK version used to build this class (e.g. "VST 3.0")
  259. //------------------------------------------------------------------------
  260. PClassInfoW (const TUID _cid, int32 _cardinality, const char8* _category, const char16* _name,
  261. int32 _classFlags, const char8* _subCategories, const char16* _vendor, const char16* _version,
  262. const char16* _sdkVersion)
  263. {
  264. memset (this, 0, sizeof (PClassInfoW));
  265. memcpy (cid, _cid, sizeof (TUID));
  266. cardinality = _cardinality;
  267. if (_category)
  268. strncpy8 (category, _category, PClassInfo::kCategorySize);
  269. if (_name)
  270. strncpy16 (name, _name, PClassInfo::kNameSize);
  271. classFlags = static_cast<uint32> (_classFlags);
  272. if (_subCategories)
  273. strncpy8 (subCategories, _subCategories, kSubCategoriesSize);
  274. if (_vendor)
  275. strncpy16 (vendor, _vendor, kVendorSize);
  276. if (_version)
  277. strncpy16 (version, _version, kVersionSize);
  278. if (_sdkVersion)
  279. strncpy16 (sdkVersion, _sdkVersion, kVersionSize);
  280. }
  281. #if SMTG_CPP11
  282. constexpr PClassInfoW ()
  283. : cid ()
  284. , cardinality ()
  285. , category ()
  286. , name ()
  287. , classFlags ()
  288. , subCategories ()
  289. , vendor ()
  290. , version ()
  291. , sdkVersion ()
  292. {
  293. }
  294. #else
  295. PClassInfoW () { memset (this, 0, sizeof (PClassInfoW)); }
  296. #endif
  297. void fromAscii (const PClassInfo2& ci2)
  298. {
  299. memcpy (cid, ci2.cid, sizeof (TUID));
  300. cardinality = ci2.cardinality;
  301. strncpy8 (category, ci2.category, PClassInfo::kCategorySize);
  302. str8ToStr16 (name, ci2.name, PClassInfo::kNameSize);
  303. classFlags = ci2.classFlags;
  304. strncpy8 (subCategories, ci2.subCategories, kSubCategoriesSize);
  305. str8ToStr16 (vendor, ci2.vendor, kVendorSize);
  306. str8ToStr16 (version, ci2.version, kVersionSize);
  307. str8ToStr16 (sdkVersion, ci2.sdkVersion, kVersionSize);
  308. }
  309. };
  310. //------------------------------------------------------------------------
  311. // IPluginFactory3 interface declaration
  312. //------------------------------------------------------------------------
  313. /** Version 3 of class factory supporting PClassInfoW.
  314. \ingroup pluginBase
  315. \copydoc IPluginFactory
  316. */
  317. //------------------------------------------------------------------------
  318. class IPluginFactory3 : public IPluginFactory2
  319. {
  320. public:
  321. //------------------------------------------------------------------------
  322. /** Returns the unicode class info for a given index. */
  323. virtual tresult PLUGIN_API getClassInfoUnicode (int32 index, PClassInfoW* info) = 0;
  324. /** Receives information about host*/
  325. virtual tresult PLUGIN_API setHostContext (FUnknown* context) = 0;
  326. //------------------------------------------------------------------------
  327. static const FUID iid;
  328. };
  329. DECLARE_CLASS_IID (IPluginFactory3, 0x4555A2AB, 0xC1234E57, 0x9B122910, 0x36878931)
  330. //------------------------------------------------------------------------
  331. } // namespace Steinberg
  332. //------------------------------------------------------------------------
  333. #define LICENCE_UID(l1, l2, l3, l4) \
  334. { \
  335. (int8)((l1 & 0xFF000000) >> 24), (int8)((l1 & 0x00FF0000) >> 16), \
  336. (int8)((l1 & 0x0000FF00) >> 8), (int8)((l1 & 0x000000FF) ), \
  337. (int8)((l2 & 0xFF000000) >> 24), (int8)((l2 & 0x00FF0000) >> 16), \
  338. (int8)((l2 & 0x0000FF00) >> 8), (int8)((l2 & 0x000000FF) ), \
  339. (int8)((l3 & 0xFF000000) >> 24), (int8)((l3 & 0x00FF0000) >> 16), \
  340. (int8)((l3 & 0x0000FF00) >> 8), (int8)((l3 & 0x000000FF) ), \
  341. (int8)((l4 & 0xFF000000) >> 24), (int8)((l4 & 0x00FF0000) >> 16), \
  342. (int8)((l4 & 0x0000FF00) >> 8), (int8)((l4 & 0x000000FF) ) \
  343. }
  344. //------------------------------------------------------------------------
  345. // GetPluginFactory
  346. //------------------------------------------------------------------------
  347. /** Plug-in entry point.
  348. \ingroup pluginBase
  349. Any Plug-in must define and export this function. \n
  350. A typical implementation of GetPluginFactory looks like this
  351. \code
  352. IPluginFactory* PLUGIN_API GetPluginFactory ()
  353. {
  354. if (!gPluginFactory)
  355. {
  356. static PFactoryInfo factoryInfo =
  357. {
  358. "My Company Name",
  359. "http://www.mywebpage.com",
  360. "mailto:myemail@address.com",
  361. PFactoryInfo::kNoFlags
  362. };
  363. gPluginFactory = new CPluginFactory (factoryInfo);
  364. static PClassInfo componentClass =
  365. {
  366. INLINE_UID (0x00000000, 0x00000000, 0x00000000, 0x00000000), // replace by a valid uid
  367. 1,
  368. "Service", // category
  369. "Name"
  370. };
  371. gPluginFactory->registerClass (&componentClass, MyComponentClass::newInstance);
  372. }
  373. else
  374. gPluginFactory->addRef ();
  375. return gPluginFactory;
  376. }
  377. \endcode
  378. \see \ref loadPlugin
  379. */
  380. //------------------------------------------------------------------------
  381. extern "C"
  382. {
  383. Steinberg::IPluginFactory* PLUGIN_API GetPluginFactory ();
  384. typedef Steinberg::IPluginFactory* (PLUGIN_API *GetFactoryProc) ();
  385. }