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.

ipluginbase.h 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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: IPluginBase
  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. struct PFactoryInfo
  51. {
  52. //------------------------------------------------------------------------
  53. enum FactoryFlags
  54. {
  55. kNoFlags = 0, ///< Nothing
  56. 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.
  57. 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
  58. kComponentNonDiscardable = 1 << 3, ///< Component will not be unloaded until process exit
  59. kUnicode = 1 << 4 ///< Components have entirely unicode encoded strings. (True for VST 3 plug-ins so far)
  60. };
  61. enum
  62. {
  63. kURLSize = 256,
  64. kEmailSize = 128,
  65. kNameSize = 64
  66. };
  67. //------------------------------------------------------------------------
  68. char8 vendor[kNameSize]; ///< e.g. "Steinberg Media Technologies"
  69. char8 url[kURLSize]; ///< e.g. "http://www.steinberg.de"
  70. char8 email[kEmailSize]; ///< e.g. "info@steinberg.de"
  71. int32 flags; ///< (see above)
  72. //------------------------------------------------------------------------
  73. PFactoryInfo (const char8* _vendor, const char8* _url, const char8* _email, int32 _flags)
  74. {
  75. strncpy8 (vendor, _vendor, kNameSize);
  76. strncpy8 (url, _url, kURLSize);
  77. strncpy8 (email, _email, kEmailSize);
  78. flags = _flags;
  79. #ifdef UNICODE
  80. flags |= kUnicode;
  81. #endif
  82. }
  83. #if SMTG_CPP11
  84. constexpr PFactoryInfo () : vendor (), url (), email (), flags () {}
  85. #else
  86. PFactoryInfo () { memset (this, 0, sizeof (PFactoryInfo)); }
  87. #endif
  88. };
  89. //------------------------------------------------------------------------
  90. /** Basic Information about a class provided by the plug-in.
  91. \ingroup pluginBase
  92. */
  93. struct PClassInfo
  94. {
  95. //------------------------------------------------------------------------
  96. enum ClassCardinality
  97. {
  98. kManyInstances = 0x7FFFFFFF
  99. };
  100. enum
  101. {
  102. kCategorySize = 32,
  103. kNameSize = 64
  104. };
  105. //------------------------------------------------------------------------
  106. TUID cid; ///< Class ID 16 Byte class GUID
  107. int32 cardinality; ///< cardinality of the class, set to kManyInstances (see \ref ClassCardinality)
  108. char8 category[kCategorySize]; ///< class category, host uses this to categorize interfaces
  109. char8 name[kNameSize]; ///< class name, visible to the user
  110. //------------------------------------------------------------------------
  111. PClassInfo (const TUID _cid, int32 _cardinality, const char8* _category, const char8* _name)
  112. {
  113. memset (this, 0, sizeof (PClassInfo));
  114. memcpy (cid, _cid, sizeof (TUID));
  115. if (_category)
  116. strncpy8 (category, _category, kCategorySize);
  117. if (_name)
  118. strncpy8 (name, _name, kNameSize);
  119. cardinality = _cardinality;
  120. }
  121. #if SMTG_CPP11
  122. constexpr PClassInfo () : cid (), cardinality (), category (), name () {}
  123. #else
  124. PClassInfo () { memset (this, 0, sizeof (PClassInfo)); }
  125. #endif
  126. };
  127. //------------------------------------------------------------------------
  128. // IPluginFactory interface declaration
  129. //------------------------------------------------------------------------
  130. /** Class factory that any plug-in defines for creating class instances: IPluginFactory
  131. \ingroup pluginBase
  132. - [plug imp]
  133. From the host's point of view a plug-in module is a factory which can create
  134. a certain kind of object(s). The interface IPluginFactory provides methods
  135. to get information about the classes exported by the plug-in and a
  136. mechanism to create instances of these classes (that usually define the IPluginBase interface).
  137. <b> An implementation is provided in public.sdk/source/common/pluginfactory.cpp </b>
  138. \see GetPluginFactory
  139. */
  140. class IPluginFactory : public FUnknown
  141. {
  142. public:
  143. //------------------------------------------------------------------------
  144. /** Fill a PFactoryInfo structure with information about the plug-in vendor. */
  145. virtual tresult PLUGIN_API getFactoryInfo (PFactoryInfo* info) = 0;
  146. /** Returns the number of exported classes by this factory.
  147. If you are using the CPluginFactory implementation provided by the SDK, it returns the number of classes you registered with CPluginFactory::registerClass. */
  148. virtual int32 PLUGIN_API countClasses () = 0;
  149. /** Fill a PClassInfo structure with information about the class at the specified index. */
  150. virtual tresult PLUGIN_API getClassInfo (int32 index, PClassInfo* info) = 0;
  151. /** Create a new class instance. */
  152. virtual tresult PLUGIN_API createInstance (FIDString cid, FIDString _iid, void** obj) = 0;
  153. //------------------------------------------------------------------------
  154. static const FUID iid;
  155. };
  156. DECLARE_CLASS_IID (IPluginFactory, 0x7A4D811C, 0x52114A1F, 0xAED9D2EE, 0x0B43BF9F)
  157. //------------------------------------------------------------------------
  158. /** Version 2 of Basic Information about a class provided by the plug-in.
  159. \ingroup pluginBase
  160. */
  161. struct PClassInfo2
  162. {
  163. //------------------------------------------------------------------------
  164. TUID cid; ///< Class ID 16 Byte class GUID
  165. int32 cardinality; ///< cardinality of the class, set to kManyInstances (see \ref PClassInfo::ClassCardinality)
  166. char8 category[PClassInfo::kCategorySize]; ///< class category, host uses this to categorize interfaces
  167. char8 name[PClassInfo::kNameSize]; ///< class name, visible to the user
  168. enum {
  169. kVendorSize = 64,
  170. kVersionSize = 64,
  171. kSubCategoriesSize = 128
  172. };
  173. uint32 classFlags; ///< flags used for a specific category, must be defined where category is defined
  174. char8 subCategories[kSubCategoriesSize]; ///< module specific subcategories, can be more than one, logically added by the \c OR operator
  175. char8 vendor[kVendorSize]; ///< overwrite vendor information from factory info
  176. char8 version[kVersionSize]; ///< Version string (e.g. "1.0.0.512" with Major.Minor.Subversion.Build)
  177. char8 sdkVersion[kVersionSize]; ///< SDK version used to build this class (e.g. "VST 3.0")
  178. //------------------------------------------------------------------------
  179. PClassInfo2 (const TUID _cid, int32 _cardinality, const char8* _category, const char8* _name,
  180. int32 _classFlags, const char8* _subCategories, const char8* _vendor, const char8* _version,
  181. const char8* _sdkVersion)
  182. {
  183. memset (this, 0, sizeof (PClassInfo2));
  184. memcpy (cid, _cid, sizeof (TUID));
  185. cardinality = _cardinality;
  186. if (_category)
  187. strncpy8 (category, _category, PClassInfo::kCategorySize);
  188. if (_name)
  189. strncpy8 (name, _name, PClassInfo::kNameSize);
  190. classFlags = static_cast<uint32> (_classFlags);
  191. if (_subCategories)
  192. strncpy8 (subCategories, _subCategories, kSubCategoriesSize);
  193. if (_vendor)
  194. strncpy8 (vendor, _vendor, kVendorSize);
  195. if (_version)
  196. strncpy8 (version, _version, kVersionSize);
  197. if (_sdkVersion)
  198. strncpy8 (sdkVersion, _sdkVersion, kVersionSize);
  199. }
  200. #if SMTG_CPP11
  201. constexpr PClassInfo2 ()
  202. : cid ()
  203. , cardinality ()
  204. , category ()
  205. , name ()
  206. , classFlags ()
  207. , subCategories ()
  208. , vendor ()
  209. , version ()
  210. , sdkVersion ()
  211. {
  212. }
  213. #else
  214. PClassInfo2 () { memset (this, 0, sizeof (PClassInfo2)); }
  215. #endif
  216. };
  217. //------------------------------------------------------------------------
  218. // IPluginFactory2 interface declaration
  219. //------------------------------------------------------------------------
  220. /** Version 2 of class factory supporting PClassInfo2: IPluginFactory2
  221. \ingroup pluginBase
  222. \copydoc IPluginFactory
  223. */
  224. class IPluginFactory2 : public IPluginFactory
  225. {
  226. public:
  227. //------------------------------------------------------------------------
  228. /** Returns the class info (version 2) for a given index. */
  229. virtual tresult PLUGIN_API getClassInfo2 (int32 index, PClassInfo2* info) = 0;
  230. //------------------------------------------------------------------------
  231. static const FUID iid;
  232. };
  233. DECLARE_CLASS_IID (IPluginFactory2, 0x0007B650, 0xF24B4C0B, 0xA464EDB9, 0xF00B2ABB)
  234. //------------------------------------------------------------------------
  235. /** Unicode Version of Basic Information about a class provided by the plug-in
  236. */
  237. struct PClassInfoW
  238. {
  239. //------------------------------------------------------------------------
  240. TUID cid; ///< see \ref PClassInfo
  241. int32 cardinality; ///< see \ref PClassInfo
  242. char8 category[PClassInfo::kCategorySize]; ///< see \ref PClassInfo
  243. char16 name[PClassInfo::kNameSize]; ///< see \ref PClassInfo
  244. enum {
  245. kVendorSize = 64,
  246. kVersionSize = 64,
  247. kSubCategoriesSize = 128
  248. };
  249. uint32 classFlags; ///< flags used for a specific category, must be defined where category is defined
  250. char8 subCategories[kSubCategoriesSize];///< module specific subcategories, can be more than one, logically added by the \c OR operator
  251. char16 vendor[kVendorSize]; ///< overwrite vendor information from factory info
  252. char16 version[kVersionSize]; ///< Version string (e.g. "1.0.0.512" with Major.Minor.Subversion.Build)
  253. char16 sdkVersion[kVersionSize]; ///< SDK version used to build this class (e.g. "VST 3.0")
  254. //------------------------------------------------------------------------
  255. PClassInfoW (const TUID _cid, int32 _cardinality, const char8* _category, const char16* _name,
  256. int32 _classFlags, const char8* _subCategories, const char16* _vendor, const char16* _version,
  257. const char16* _sdkVersion)
  258. {
  259. memset (this, 0, sizeof (PClassInfoW));
  260. memcpy (cid, _cid, sizeof (TUID));
  261. cardinality = _cardinality;
  262. if (_category)
  263. strncpy8 (category, _category, PClassInfo::kCategorySize);
  264. if (_name)
  265. strncpy16 (name, _name, PClassInfo::kNameSize);
  266. classFlags = static_cast<uint32> (_classFlags);
  267. if (_subCategories)
  268. strncpy8 (subCategories, _subCategories, kSubCategoriesSize);
  269. if (_vendor)
  270. strncpy16 (vendor, _vendor, kVendorSize);
  271. if (_version)
  272. strncpy16 (version, _version, kVersionSize);
  273. if (_sdkVersion)
  274. strncpy16 (sdkVersion, _sdkVersion, kVersionSize);
  275. }
  276. #if SMTG_CPP11
  277. constexpr PClassInfoW ()
  278. : cid ()
  279. , cardinality ()
  280. , category ()
  281. , name ()
  282. , classFlags ()
  283. , subCategories ()
  284. , vendor ()
  285. , version ()
  286. , sdkVersion ()
  287. {
  288. }
  289. #else
  290. PClassInfoW () { memset (this, 0, sizeof (PClassInfoW)); }
  291. #endif
  292. void fromAscii (const PClassInfo2& ci2)
  293. {
  294. memcpy (cid, ci2.cid, sizeof (TUID));
  295. cardinality = ci2.cardinality;
  296. strncpy8 (category, ci2.category, PClassInfo::kCategorySize);
  297. str8ToStr16 (name, ci2.name, PClassInfo::kNameSize);
  298. classFlags = ci2.classFlags;
  299. strncpy8 (subCategories, ci2.subCategories, kSubCategoriesSize);
  300. str8ToStr16 (vendor, ci2.vendor, kVendorSize);
  301. str8ToStr16 (version, ci2.version, kVersionSize);
  302. str8ToStr16 (sdkVersion, ci2.sdkVersion, kVersionSize);
  303. }
  304. };
  305. //------------------------------------------------------------------------
  306. // IPluginFactory3 interface declaration
  307. //------------------------------------------------------------------------
  308. /** Version 3 of class factory supporting PClassInfoW: IPluginFactory3
  309. \ingroup pluginBase
  310. \copydoc IPluginFactory
  311. */
  312. class IPluginFactory3 : public IPluginFactory2
  313. {
  314. public:
  315. //------------------------------------------------------------------------
  316. /** Returns the unicode class info for a given index. */
  317. virtual tresult PLUGIN_API getClassInfoUnicode (int32 index, PClassInfoW* info) = 0;
  318. /** Receives information about host*/
  319. virtual tresult PLUGIN_API setHostContext (FUnknown* context) = 0;
  320. //------------------------------------------------------------------------
  321. static const FUID iid;
  322. };
  323. DECLARE_CLASS_IID (IPluginFactory3, 0x4555A2AB, 0xC1234E57, 0x9B122910, 0x36878931)
  324. //------------------------------------------------------------------------
  325. } // namespace Steinberg
  326. //------------------------------------------------------------------------
  327. #define LICENCE_UID(l1, l2, l3, l4) \
  328. { \
  329. (int8)((l1 & 0xFF000000) >> 24), (int8)((l1 & 0x00FF0000) >> 16), \
  330. (int8)((l1 & 0x0000FF00) >> 8), (int8)((l1 & 0x000000FF) ), \
  331. (int8)((l2 & 0xFF000000) >> 24), (int8)((l2 & 0x00FF0000) >> 16), \
  332. (int8)((l2 & 0x0000FF00) >> 8), (int8)((l2 & 0x000000FF) ), \
  333. (int8)((l3 & 0xFF000000) >> 24), (int8)((l3 & 0x00FF0000) >> 16), \
  334. (int8)((l3 & 0x0000FF00) >> 8), (int8)((l3 & 0x000000FF) ), \
  335. (int8)((l4 & 0xFF000000) >> 24), (int8)((l4 & 0x00FF0000) >> 16), \
  336. (int8)((l4 & 0x0000FF00) >> 8), (int8)((l4 & 0x000000FF) ) \
  337. }
  338. //------------------------------------------------------------------------
  339. // GetPluginFactory
  340. //------------------------------------------------------------------------
  341. /** Plug-in entry point.
  342. \ingroup pluginBase
  343. Any plug-in must define and export this function. \n
  344. A typical implementation of GetPluginFactory looks like this
  345. \code{.cpp}
  346. SMTG_EXPORT_SYMBOL IPluginFactory* PLUGIN_API GetPluginFactory ()
  347. {
  348. if (!gPluginFactory)
  349. {
  350. static PFactoryInfo factoryInfo =
  351. {
  352. "My Company Name",
  353. "http://www.mywebpage.com",
  354. "mailto:myemail@address.com",
  355. PFactoryInfo::kNoFlags
  356. };
  357. gPluginFactory = new CPluginFactory (factoryInfo);
  358. static PClassInfo componentClass =
  359. {
  360. INLINE_UID (0x00000000, 0x00000000, 0x00000000, 0x00000000), // replace by a valid uid
  361. 1,
  362. "Service", // category
  363. "Name"
  364. };
  365. gPluginFactory->registerClass (&componentClass, MyComponentClass::newInstance);
  366. }
  367. else
  368. gPluginFactory->addRef ();
  369. return gPluginFactory;
  370. }
  371. \endcode
  372. \see \ref loadPlugin
  373. */
  374. extern "C"
  375. {
  376. SMTG_EXPORT_SYMBOL Steinberg::IPluginFactory* PLUGIN_API GetPluginFactory ();
  377. typedef Steinberg::IPluginFactory* (PLUGIN_API *GetFactoryProc) ();
  378. }