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

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